  
if (document.images) {
	rollovers = 1;
} else {
    rollovers = 0;
}
        
if (rollovers)
{

//nav_cruiseFree_ON = new Image(145,24);
//nav_cruiseFree_ON.src = "images/nav_cruiseFree_ON.gif";
//nav_cruiseFree_OFF = new Image(145,24);
//nav_cruiseFree_OFF.src = "images/nav_cruiseFree_OFF.gif";


}


function imgOn( imgName ) {
	if ( rollovers ) {
		document[imgName].src = eval( "nav_" + imgName + "_ON.src" );
	}
}

function imgOff( imgName ) {
	if ( rollovers ) {
		document[imgName].src = eval( "nav_" + imgName + "_OFF.src" );
	}
}

// check number if is positive integer
function isPosInteger(inputVal) {
	inputStr = inputVal.toString();
	for(var i=0; i<inputStr.length; i++) {
		var oneChar = inputStr.charAt(i);
		if(oneChar < "0" || oneChar > "9") {
			return false;
		}
	}
	return true;
}

// convert number to nearest whole integer
function roundNum(inputVal) {
	decStr = "";
	inputStr = inputVal.toString();
	for(var i=0; i<inputStr.length; i++) {
		var oneChar = inputStr.charAt(i);
		if((oneChar==".")||(decStr.indexOf(".")!=-1)) {
			decStr = decStr+oneChar;
		}
	}
	if(decStr>=.5) inputVal = Math.ceil(inputVal);
	if(decStr<.5) inputVal = parseInt(inputVal);
	return inputVal;
}


var isOpen;
var newWin;
var newSSLWin;

function viewImage(img,w,h) {
	var theURL='viewImage.php?img='+img+'&h='+h+'&w='+w;
	makeWin(theURL,w,h);	

}

function makeWin(URL,w,h) { 
	w=w+100;
	h=h+100;
	newWin=window.open(URL, "newWin", "width="+w+",height="+h+",status=0,toolbar=0,menubar=0,scrollbars=1,resizable=1");
		if (!newWin.opener) {
			newWin.opener = window;
		}
	newWin.focus();
}

function makeSSLWin(URL,w,h) { 
	w=w+100;
	h=h+100;
	newSSLWin=window.open("http://myautorater.com/rater/"+URL, "newSSLWin", "width="+w+",height="+h+",status=0,toolbar=0,menubar=0,scrollbars=1,resizable=1");
		if (!newSSLWin.opener) {
			newSSLWin.opener = window;
		}
	newSSLWin.focus();
}

function checkWin() {
	if(newWin) newWin.close();
	if(newSSLWin) newSSLWin.close();
}

function checkEmail(theForm) {
	if (isEmpty(theForm.subscribe.value)) {
		alert("Please enter your email address.");
		theForm.subscribe.focus();
		theForm.subscribe.select();
		return false
	}
	if ((theForm.subscribe.value.indexOf("@") == -1) || (theForm.subscribe.value.indexOf(".") == -1)) {
	 	theForm.subscribe.focus();
		theForm.subscribe.select();
		alert("Please enter a valid email address.");
		return false;
	}

}


function checkForm(theForm) {
if(theForm.useLogin.value!='true') {
// Check First Name
	if (isEmpty(theForm.first_name.value)) {
		alert("Please enter your first name.");
		theForm.first_name.focus();
		theForm.first_name.select();
		return false
	}
// Check Last Name
	if (isEmpty(theForm.last_name.value)) {
		alert("Please enter your last name.");
		theForm.last_name.focus();
		theForm.last_name.select();
		return false
	}
	
// Check email
	if (isEmpty(theForm.email.value)) {
		alert("Please enter your email address.");
		theForm.email.focus();
		theForm.email.select();
		return false
	}
	if ((theForm.email.value.indexOf("@") == -1) || (theForm.email.value.indexOf(".") == -1)) {
	 	theForm.email.focus();
		theForm.email.select();
		alert("Please enter a valid email address.");
		return false;
	}
} else {
	if (isEmpty(theForm.uselogin.value)) {
		alert("Please enter your login ID.");
		theForm.uselogin.focus();
		theForm.uselogin.select();
		return false;
	}

}
	
	return true;
}



function isEmpty(input) {
	if (input == "" || input == null) {
		return true
	}
	return false
}
	
function select(field) {
	field.focus()
	field.select()
}

function checkNum(element) {
	var digits="0123456789";
	for (i = 0; i < element.value.length; i++) {
		c = element.value.charAt(i);
		if (digits.indexOf(c) == -1) {
			return false;
			break;
		} else {
			return true;
		}
	}
}

function checkVIN(value) {
	var chars = "0123456789abcdefghijklmnopqrstuvwxyz";
	for (i=0; i < value.length; i++) {
		c = value.charAt(i).toLowerCase();
		if(chars.indexOf(c) == -1) {
			return true;
			break;
		}
	}
}

function checkMYM(form) {
	var VIN = form.vin_num.value;
	if(!VIN) {
		if(form.model_year.options[form.model_year.selectedIndex].value==0) {
			alert("You must select a model year for the vehicle.");
			form.model_year.selectedIndex=0;
			return false; 
		}
		if(form.make.options[form.make.selectedIndex].value==0) {
			alert("You must select a make for the vehicle.");
			form.make.selectedIndex=0;
			return false; 
		}
	}
	if(VIN) {
	// check for valid VIN
		if(checkVIN(VIN)) {
			alert("The VIN must contain only numbers and letters.");
			form.vin_num.select();
			form.vin_num.focus();
			return false;
		}
		if(VIN.length>17) {
			alert("The VIN you entered has too many characters.");
			form.vin_num.select();
			form.vin_num.focus();
			return false;
		}
	}
}


function setName(selectItem) {
	makeStr = selectItem.options[selectItem.selectedIndex].text;
	document.selectForm.make_name.value = makeStr;
}

function setModel(selectItem) {
	modelStr = selectItem.options[selectItem.selectedIndex].text;
	document.selectForm.model.value = modelStr;
}

function setTown(selectItem) {
	townStr = selectItem.options[selectItem.selectedIndex].text;
	document.opInfo.town.value = townStr;
}

function checkSym(form) {
	if(form.fileEmpty) {
		if(isEmpty(form.model.value)) {
			alert("Please enter the model name for the vehicle.");
			form.model.focus();
			form.model.select();
			return false;
		}
	}
	
	var symVal = form.symbol.options[form.symbol.selectedIndex].value;
	
	if(symVal==0) {
		str = "model";
		if(form.fileEmpty) str = "symbol";
		alert("You must select a "+str+" for the vehicle.");
		form.symbol.selectedIndex=0;
		return false; 
	}
	
	//if((symVal=="NA")||(symVal=="NA *H")) form.action="symCheck.php";
	if(symVal.indexOf("NA")!=-1) form.action="symCheck.php";
	//return false;
}

function checkOpInfo(form) {
	if(form.town.value=="") {
		alert("You must select a city or town of garaging.");
		return false; 
	}
	if(form.classID.options[form.classID.selectedIndex].value=="") {
		alert("You must select a rate class.");
		form.classID.selectedIndex=0;
		return false; 
	}
}

// function to format 2 digit decimal places
function format(expr,decplaces) {
	var str = ""+Math.round(eval(expr)*Math.pow(10,decplaces));
	while(str.length<=decplaces) {
		str = "0"+str;
	}
	var decpoint = str.length - decplaces;
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

function dollarize(expr) {
	return "$"+format(expr,2);
}

function changeFooter(agentID) {
	// add print Form B&D to footer
	parent.footer.location = "footerLinks.php?printBD=true&agentID="+agentID;
}

