
/* Global scripts - setting cookies, doing resizes, non ajax stuff */

function showModels(make){
	var elementText = make+'-link';
	var rownames = make + "Model";
	var models = getElementsByClassName(document, "tr", rownames);
	for (i=0,n=models.length; i<n; i++) {
		if(models[i].style.display == "none"){
			models[i].style.display = "";
			document.getElementById(elementText).innerHTML = "hide models";
		} else {
			models[i].style.display = "none";
			document.getElementById(elementText).innerHTML = "show models";
		}
	}
	window.focus();
}

function showYears(make,model,action){
	var rownames = make + model + "Years";
	var models = getElementsByClassName(document, "tr", rownames);
	for (i=0,n=models.length; i<n; i++) {
		if(action == "open"){
			models[i].style.display = "";
		} else {
			models[i].style.display = "none";
		}
	}
	window.focus();
}



function reloadPage(sURL) { 
	window.location.href = sURL + ".html";
}

function PopupPic(sPicURL) { 
  window.open( "popup.php?"+sPicURL, "","resizable=1,HEIGHT=200,WIDTH=200"); 
}

function closeEditBlock(block) {
	eval("document.getElementById('"+block+"-display').style.display='block'");
	eval("document.getElementById('"+block+"-edit').style.display='none'");
}

function openEditBlock(block) {
	eval("document.getElementById('"+block+"-display').style.display='none'");
	eval("document.getElementById('"+block+"-edit').style.display='block'");
}


function killChars(string, totype) {
	switch(totype) {
		case 'numonly':
		case 'money': // kill anything that's not a number or decimal
			return string.replace(/[^\d.]/g, '');
		break;
		
		case 'zip':
			return string.replace(/[^\d-]/g, '');
		break;

		case 'phone':
			return string.replace(/[^\d]/g, '');
		break;
		
		default:
			return string;
		break;
	}
}


function changeInputMiles() {
	var shoe = getElementsByClassName(document, "*", "desiredMiles");

	for (i=0,n=shoe.length; i<n; i++) {
		shoe[i].innerHTML = document.form1.inputDesiredMiles.value + " miles";
	}

	return false;
}


/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];      
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }   
    }
    return (arrReturnElements)
}

/* *********************************************************** 
 *	FUNCTION:	externalLinks
 *	PURPOSE: 	make external links open in new windows
 * **********************************************************/
 
function externalLinks() {
	if (document.getElementsByTagName){
		var anchors = document.getElementsByTagName("a");
		for (var i=0; i<anchors.length; i++) {
			var anchor = anchors[i];
			if (anchor.getAttribute("href") &&
				anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
		}
	}
}

if(window.addEventListener){
	window.addEventListener('load',externalLinks,false);
} else if (window.attachEvent){ 
	window.attachEvent('onload', externalLinks);
} 

/* *********************************************************** 
 *	FUNCTION:  safe
 *	PURPOSE: obscure e-mail addresses from bots
 * ********************************************************* */

function safe(text){
	var linkname = new Array;
	var linkdomain = new Array;
	var textname = new Array;
	var textdomain = new Array;
	linkname['general'] = 'm&#97;&#105;l&#116;&#111;&#58;&#105;%6e%66o';
	linkdomain['general'] = '&#64;&#115;q%75a&#100;%72%61&#112;i&#108;%6f&#116;&#105;.%63%6fm';
	textname['general'] = 'i&#110;&#102;&#111;';
	textdomain['general'] = '&#64;&#115;&#113;&#117;a&#100;&#114;&#97;&#112;&#105;lot&#105;.&#99;&#111;m';
	linkname['testimonial'] = 'ma&#105;l&#116;&#111;&#58;&#116;&#101;%73t%69%6don%69&#97;l&#115;';
	linkdomain['testimonial'] = '&#64;sq%75&#97;%64r&#97;%70%69l&#111;t%69.%63o&#109;';
	textname['testimonial'] = 't&#101;s&#116;i&#109;on&#105;&#97;l&#115;';
	textdomain['testimonial'] = '&#64;&#115;&#113;&#117;&#97;&#100;ra&#112;ilot&#105;&#46;c&#111;m';
	linkname['support'] = 'm&#97;&#105;l&#116;o:su&#112;%70&#111;&#114;&#116;';
	linkdomain['support'] = '&#64;%73&#113;uad&#114;%61p%69%6c&#111;t%69&#46;c%6fm';
	textname['support'] = 's&#117;p&#112;ort';
	textdomain['support'] = '&#64;s&#113;&#117;a&#100;&#114;&#97;pi&#108;o&#116;i.c&#111;m';

	document.write('<a href="' + linkname[text] + linkdomain[text] + '">' + textname[text] + textdomain[text] + '</a>');
}

function cancel(where){
	if(where == 'terms')
		document.location="/";
}

/**************************** 
    OPEN WINDOW FUNCTION
	Author: Todd Cawthron
	Loud Dog Corporation
*****************************/

//function open_link(url, width, height, name, location, scrollbars, resizable) {
function open_link(url, width, height) {
  // width, height, name, location and scrollbars are optional
  //
  // Pop up a new window named LoudDog with a default size of 685 x 480
  // window name of LoudDog and no location bar.


  var namenum = Math.round(Math.random() * 10000);
  if (width      == null) width=680;
  if (height     == null) height=450;
  var name="SP" + namenum;
  var location='no';
  var scrollbars='yes';
  var resizable='no';
  var opts="menubar=no,toolbar=no,scrollbars=" + scrollbars + ",resizable=" + resizable + ",fullsize=no,width="
           + width + ",height=" + height + ",location=no";

  winref=window.open(url,name,opts);
  winref.focus();
}

/* ##### simple tooltip ##### */
function toolTip(layerID){
var obj = document.getElementById(layerID);
obj.style.display = "block";
}

function closeTooltip(layerID) {
document.getElementById(layerID).style.display = "none";
}