function hide_selects(){

document.getElementById("suffix").style.visibility = 'hidden';
document.getElementById("state").style.visibility = 'hidden';
}
function show_selects(){
document.getElementById("suffix").style.visibility = 'visible';
document.getElementById("state").style.visibility = 'visible';
}
function mouseover_callout(call_id){
	var mycall = call_id;

	if (mycall == "bonus"){
			document.getElementById("bonus_canvas").style.visibility = 'visible';
	}
	if (mycall == "vin"){
			document.getElementById("vin_canvas").style.visibility = 'visible';
			document.getElementById("suffix").style.visibility = "hidden";
	}
}

function mouseout_callout(call_id){
	var mycall = call_id;
	if (mycall == "bonus"){
			document.getElementById("bonus_canvas").style.visibility = 'hidden';
	}
	if (mycall =="vin"){
			document.getElementById("vin_canvas").style.visibility = 'hidden';
			if(document.getElementById("form_2").style.visibility == "visible"){	
				document.getElementById("suffix").style.visibility = "visible";
			}
	}
}


function showLayer(lyr){
	document.getElementById(lyr).style.visibility = 'visible';
}

function hideLayer(lyr){
	document.getElementById(lyr).style.visibility = 'hidden';
}

var c_name="";
function passText(id) {

	//check if it's IE
	//var isIE = (window.navigator.userAgent.indexOf("MSIE") > 0);

	var multiForm =document.getElementById("multiForm");

	var myid=id;
	if(myid=="make"){
		multiForm.make_value.value = multiForm.make.options[multiForm.make.selectedIndex].text;
	}
	if(myid=="model"){
		multiForm.model_value.value = multiForm.model.options[multiForm.model.selectedIndex].text;
	}
	if(myid=="year"){
		multiForm.year_value.value = multiForm.year.options[multiForm.year.selectedIndex].text;
	}
	
	if(myid=="color"){
		multiForm.color_value.value = multiForm.color_box.value;
	}
	if(myid=="max_mileage"){
		multiForm.mileage_value.value = multiForm.max_mileage.value;
	}
	if(myid=="max_price"){
		multiForm.price_value.value = multiForm.max_price.value;
	}
	if(myid=="language"){
		multiForm.preferred_language.value = multiForm.language.options[multiForm.language.selectedIndex].text;
	}
	if(myid=="vin"){
		multiForm.vin_value.value = multiForm.vin_box.value;
	}
	if(myid=="mileage"){
		multiForm.mileage_value.value = multiForm.current_mileage.value;
	}
	
	if(myid=="name"){
		var pre = multiForm.prefix.options[multiForm.prefix.selectedIndex].text;
		if(pre == "-- Select --"){ pre = "";}
		var first = multiForm.first_name.value;
		var MI = multiForm.M_I.value;
		var last = multiForm.last_name.value;
		var suffix = multiForm.suffix.options[multiForm.suffix.selectedIndex].text;
		if(suffix == "-- Select --"){suffix="";}
		c_name=pre+" "+first+" "+MI+" "+last+" "+suffix;
		multiForm.name.value =c_name;
	}
	
	if(myid=="address"){
		var street = multiForm.street.value;
		var cty = multiForm.city.value;
		var zipcode = multiForm.zip.value;
		var stt = multiForm.state.options[multiForm.state.selectedIndex].text;
		multiForm.address.value = street+" \n"+cty+", "+stt+" "+zipcode;
	}
	if(myid=="email"){
		multiForm.email.value = multiForm.email_box.value;
	}
	if(myid=="p_phone"){
		multiForm.primary_phone.value = multiForm.select_p_phone.options[multiForm.select_p_phone.selectedIndex].text;
		var p_phone_1 = multiForm.primary_phone_areacode.value;
		var p_phone_2 = multiForm.primary_phone_part1.value;
		var p_phone_3 = multiForm.primary_phone_part2.value;
		multiForm.primary_phone_num.value = p_phone_1+"-"+p_phone_2+"-"+p_phone_3;
		var rad_val = "AM";
		for (var i=0; i < multiForm.primary.length; i++){
			if (multiForm.primary[i].checked){
				rad_val = multiForm.primary[i].value;
			}
		}
		multiForm.primary_phone_time.value = rad_val;
	}
	if(myid=="c_comment"){
		multiForm.customer_comment.value = multiForm.comments.value;
	}
	
	if(myid=="topics"){
		showTopic();
	}

	if(myid == "transport"){
		var trans_val = "Yes";
		for (var i=0; i < multiForm.alt_transportation.length; i++){
			if (multiForm.alt_transportation[i].checked){
				trans_val = multiForm.alt_transportation[i].value;
			}
		}
		multiForm.transportation.value = trans_val;
	}
	
	if(myid == "serv_advisor"){
		multiForm.s_advisor.value = multiForm.service_advisor.value;
	}
}

function nameToThank(){
	document.getElementById("thank_name").value=c_name;
}

function showTopic(){
	var chk_val="";
	for (var i=0; i < multiForm.topics.length; i++){
	   if (multiForm.topics[i].checked){
      chk_val = chk_val+"."+multiForm.topics[i].value+"\n";
      }
    }
	multiForm.topics_val.value = chk_val;
}
function passCalendar() {

	var cmonth="";
	var cday="";
	var cyear="";
	var ctime="AM";

	cday=document.getElementById("dayselect").options[document.getElementById("dayselect").selectedIndex].text;
	cmonth=document.getElementById("monthselect").options[document.getElementById("monthselect").selectedIndex].text;
	cyear=document.getElementById("yearselect").options[document.getElementById("yearselect").selectedIndex].text;


	for (var i=0; i < multiForm.calendar_time.length; i++){
	   if (multiForm.calendar_time[i].checked){
      ctime = multiForm.calendar_time[i].value;
      }
    }

	var calendar_val=". "+cmonth+" "+cday+", "+cyear+"\n"+". "+ctime;
	multiForm.appt_val.value = calendar_val;
}
	
/** user should not be able to choose date before today.*/
function validateAppt(appt)
{
	var past = new Date();
	var future = appt;
	var invalid = 0;

    var yeardif = future.getFullYear() - past.getFullYear();
    var mondif = future.getMonth() - past.getMonth();
    var datedif = future.getDate() - past.getDate();

	while(true){
	if(yeardif < 0){
		invalid = 1;
		break;
	}
	else{  //yeardif >=0
		if(mondif < 0){
			if(yeardif == 0){
				invalid = 1;
				break;
			}
		}else{ //mondif >=0
			if(datedif < 0){
				if(mondif == 0){
					invalid = 1;
					break;
				}
			}
		}
	}
	break;
	}
			
	if(invalid == 0){
		return true;
	}else{
	return false;
	}
}

/**check if customer picked a day before today, change the background color if the appt date is before today*/
function validateDate(){
		
		var multiForm =document.getElementById("multiForm");
		var e_code = 0;
		var cday=document.getElementById("dayselect").options[document.getElementById("dayselect").selectedIndex].text;
		var cmonth=document.getElementById("monthselect").options[document.getElementById("monthselect").selectedIndex].text;
		var cyear=document.getElementById("yearselect").options[document.getElementById("yearselect").selectedIndex].text;
		
		var apptdate = new Date(cday+" "+cmonth+","+cyear);
		
		var error_color = "#ffcccc";
		var normal_color = "#FFFFFF";


	while(true){
		if (cmonth == "Month" || cday == "Day" || cyear == "Year" ){
			e_code = 1;
			multiForm.dayselect.style.backgroundColor=error_color;
			multiForm.monthselect.style.backgroundColor=error_color;
			multiForm.yearselect.style.backgroundColor=error_color;
			break;
		}
		else {
			document.getElementById("dayselect").style.backgroundColor=normal_color;
			document.getElementById("monthselect").style.backgroundColor=normal_color;
			document.getElementById("yearselect").style.backgroundColor=normal_color;
			e_code = 0;
		}

		if (!validateAppt(apptdate) ){
			e_code = 1;
			multiForm.dayselect.style.backgroundColor=error_color;
			multiForm.monthselect.style.backgroundColor=error_color;
			multiForm.yearselect.style.backgroundColor=error_color;
			document.getElementById("invalid_appt").style.visibility = 'visible';
			break;
		}
		else {
			document.getElementById("dayselect").style.backgroundColor=normal_color;
			document.getElementById("monthselect").style.backgroundColor=normal_color;
			document.getElementById("yearselect").style.backgroundColor=normal_color;
			document.getElementById("invalid_appt").style.visibility = 'hidden';
			e_code = 0;
		}
		break;
	}
		
		
	if (e_code == 1){
			return false;
	}else{
		return true;
	}
		
}

function requiredphone(){
	var multiForm =document.getElementById("multiForm");
	var pri_phone = multiForm.select_p_phone.options[multiForm.select_p_phone.selectedIndex].text;	
	var p_phone_1 = multiForm.primary_phone_areacode.value;
	var p_phone_2 = multiForm.primary_phone_part1.value;
	var p_phone_3 = multiForm.primary_phone_part2.value;
	var p_p_num = p_phone_1+p_phone_2+p_phone_3;
	while(true){
		/*
	if (pri_phone=="-- Select --"){
		alert("Please select Primary Phone type");
		multiForm.select_p_phone.style.backgroundColor="#ffcccc";
		multiForm.select_p_phone.focus();
		error_code = 1;
		break;
	}else{
		multiForm.select_p_phone.style.backgroundColor="#FFFFFF";
		error_code = 0;
	}	*/
	if (p_phone_1 == "" || p_phone_2 == "" || p_phone_3 == "" ){
		alert("Please enter Primary Phone");
		//multiForm.select_p_phone.style.backgroundColor="#ffcccc";
		multiForm.primary_phone_areacode.style.backgroundColor="#ffcccc";
		multiForm.primary_phone_part1.style.backgroundColor="#ffcccc";
		multiForm.primary_phone_part2.style.backgroundColor="#ffcccc";
		multiForm.primary_phone_areacode.focus();
		error_code = 1;
		break;
	}else{
		//multiForm.select_p_phone.style.backgroundColor="#FFFFFF";
		multiForm.primary_phone_areacode.style.backgroundColor="#FFFFFF";
		multiForm.primary_phone_part1.style.backgroundColor="#FFFFFF";
		multiForm.primary_phone_part2.style.backgroundColor="#FFFFFF";
		error_code = 0;
	}
	break;
	}
	
	if (error_code == 1){
		return false;
	}else{
		return true;
	}	
}
function requiredAppt(){
	var multiForm =document.getElementById("multiForm");
	var apptMonth = multiForm.monthselect.options[multiForm.monthselect.selectedIndex].text;
	var apptDay = multiForm.dayselect.options[multiForm.dayselect.selectedIndex].text;
	var apptYear = multiForm.yearselect.options[multiForm.yearselect.selectedIndex].text;
	var apptTime = multiForm.apptTime.value;
	//alert(apptMonth + " " +apptDay + " " +apptYear+ " " +apptTime);
	if(apptMonth=='Month' || apptDay=="Day" ||apptYear=="Year" ||apptTime==""){
		alert("Please enter your preferred appointment time.");
		return false;
	}else{
		return true;
	}
}

function validateForm(){

	var multiForm =document.getElementById("multiForm");

	var pre = multiForm.prefix.options[multiForm.prefix.selectedIndex].text;
	var first = multiForm.first_name.value;
	var MI = multiForm.M_I.value;
	var last = multiForm.last_name.value;
	var street = multiForm.street.value;
	var cty = multiForm.city.value;
	var stt = multiForm.state.options[multiForm.state.selectedIndex].text;
	var zipcode = multiForm.zip.value;
	var c_email = multiForm.email_box.value;
	var pri_phone = multiForm.select_p_phone.options[multiForm.select_p_phone.selectedIndex].text;
	var error_code = 0;

	while(true){
	/**
		if (pre=="-- Select --"){
			alert("Please select Prefix");
			multiForm.prefix.style.backgroundColor="#ffcccc";
			multiForm.prefix.focus();
			error_code = 1;
			break;
		}
		else{
			multiForm.prefix.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}
	*/	
		var NameRegex = /[^a-zA-Z(\-\s?)a-zA-Z]/;

		if(first=="" || first==null || NameRegex.test(first)==true) {
			alert("Please enter valid First Name");
			multiForm.first_name.style.backgroundColor="#ffcccc";
			multiForm.first_name.focus();
			error_code = 1;
			break;
		}
		else{
			multiForm.first_name.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}
		
		if((MI != "" || MI != null) && NameRegex.test(MI)==true) {
			alert("Please enter valid Middle Initial");
			multiForm.M_I.style.backgroundColor="#ffcccc";
			multiForm.M_I.focus();
			error_code = 1;
			break;
		} else {
			multiForm.M_I.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}

		if(last=="" || last==null || NameRegex.test(last)==true) {
			alert("Please enter valid Last Name");
			multiForm.last_name.style.backgroundColor="#ffcccc";
			multiForm.last_name.focus();
			error_code = 1;
			break;
		}
		else{
			multiForm.last_name.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}
/**
		if(val(multiForm.street, "TextBox", "Please enter Street Address")==false) {
			multiForm.street.style.backgroundColor="#ffcccc";
			multiForm.street.focus();
			error_code = 1;
			break;
		}
		else{
			multiForm.street.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}
*/
//	if(cty=="" || cty==null || NameRegex.test(cty)==true) {
		if(cty.length>0 && NameRegex.test(cty)==true) {
			alert("Please enter valid City");
			multiForm.city.style.backgroundColor="#ffcccc";
			multiForm.city.focus();
			error_code = 1;
			break;
		}
		else{
			multiForm.city.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}
/**
		if (stt=="-- Select --"){
			alert("Please select State");
			multiForm.state.style.backgroundColor="#ffcccc";
			multiForm.state.focus();
			error_code = 1;
			break;
		}
		else{
			multiForm.state.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}
*/

		//if (zipcode=="" || zipcode.length != 5){
	
		if (zipcode.length>0 && zipcode.length != 5){
			alert("Please enter valid ZIP Code");
			multiForm.zip.focus();
			multiForm.zip.style.backgroundColor="#ffcccc";
			error_code = 1;
			break;
		}
		else{
			multiForm.zip.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}

		if(val(multiForm.email_box, "EmailBox", "Please enter valid Email Address")==false) {
			multiForm.email_box.style.backgroundColor="#ffcccc";
			multiForm.email_box.focus();
			error_code = 1;
			break;
		}
		else{
			multiForm.email_box.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}
		
		var p_phone_1 = multiForm.primary_phone_areacode.value;
		var p_phone_2 = multiForm.primary_phone_part1.value;
		var p_phone_3 = multiForm.primary_phone_part2.value;
		var p_p_num = p_phone_1+p_phone_2+p_phone_3;
	/**
		if (pri_phone=="-- Select --"){
			alert("Please select Primary Phone type");
			multiForm.select_p_phone.style.backgroundColor="#ffcccc";
			//multiForm.primary_phone_areacode.style.backgroundColor="#ffcccc";
			//multiForm.primary_phone_part1.style.backgroundColor="#ffcccc";
			//multiForm.primary_phone_part2.style.backgroundColor="#ffcccc";
			multiForm.select_p_phone.focus();
			error_code = 1;
			break;
		}
		else{
			multiForm.select_p_phone.style.backgroundColor="#FFFFFF";
			//multiForm.primary_phone_areacode.style.backgroundColor="#FFFFFF";
			//multiForm.primary_phone_part1.style.backgroundColor="#FFFFFF";
			//multiForm.primary_phone_part2.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}
*/	
//		if (p_phone_1 == "" || p_phone_2 == "" || p_phone_3 == "" ){
//			alert("Please enter Primary Phone");
			//multiForm.select_p_phone.style.backgroundColor="#ffcccc";
		if(p_p_num.length>0 && p_p_num.length<10){
			alert("Please enter a Valid Phone Number");
			multiForm.primary_phone_areacode.style.backgroundColor="#ffcccc";
			multiForm.primary_phone_part1.style.backgroundColor="#ffcccc";
			multiForm.primary_phone_part2.style.backgroundColor="#ffcccc";
			multiForm.primary_phone_areacode.focus();
			error_code = 1;
			break;
		}
		else{
			//multiForm.select_p_phone.style.backgroundColor="#FFFFFF";
			multiForm.primary_phone_areacode.style.backgroundColor="#FFFFFF";
			multiForm.primary_phone_part1.style.backgroundColor="#FFFFFF";
			multiForm.primary_phone_part2.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}
		
		var s_phone_1 = multiForm.secondary_phone_areacode.value;
		var s_phone_2 = multiForm.secondary_phone_part1.value;
		var s_phone_3 = multiForm.secondary_phone_part2.value;
		var s_p_num = s_phone_1+s_phone_2+s_phone_3;
		if(s_p_num.length>0 && s_p_num.length<10){
			alert("Please enter a Valid Phone Number");
			multiForm.secondary_phone_areacode.style.backgroundColor="#ffcccc";
			multiForm.secondary_phone_part1.style.backgroundColor="#ffcccc";
			multiForm.secondary_phone_part2.style.backgroundColor="#ffcccc";
			multiForm.primary_phone_areacode.focus();
			error_code = 1;
			break;
		}
		else{
			multiForm.secondary_phone_areacode.style.backgroundColor="#FFFFFF";
			multiForm.secondary_phone_part1.style.backgroundColor="#FFFFFF";
			multiForm.secondary_phone_part2.style.backgroundColor="#FFFFFF";
			error_code = 0;
		}
		
		break;
	}
	//alert(error_code);
	if (error_code == 1){
			return false;
	}else{
		return true;
	}
}

function validate_to_show(){
	if(validateForm()){
		showLayer('comments_panel'); 
		hideLayer('form_2'); 
		showLayer('header_step2'); 
		hideLayer('header_step1'); 
		hide_selects();
	}
}

/**show confirm information page in contact_us page.*/
function validate_to_show_contacts(){
	if(validateForm()){
		showLayer('confirm'); 
		hideLayer('form_2'); 
		showLayer('header_step2'); 
		hideLayer('header_step1'); 
		hide_selects();
	}
}

/**show the thank you page*/
function showThanks(){
	showLayer("thanks");
	hideLayer('header_step1'); 
	hideLayer('header_step2'); 
	hideLayer('form_1'); 
	hideLayer('form_2'); 
	hideLayer('confirm');
	hideLayer('select_topics');

}

/** allow only numbers to be entered in text box, such as phone number and zip code. */
function isNumberKey(evt){
   var charCode = (evt.which) ? evt.which : event.keyCode
   if (charCode > 31 && (charCode < 48 || charCode > 57))
	  return false;

   return true;
}




/** validate.js
* This portion has functions to validate
* individual form elements
**/
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}

function checknumbers(field)
{
	var field = field
	var valid = "0123456789."
	var ok = "yes";
	var temp;
	for (var i=0; i<field.length; i++) 
		{
			temp = "" + field.substring(i, i+1);
			if (valid.indexOf(temp) == "-1") 
			ok = "no";
		}
	if (ok == "no" || field=="") 
	{
		return false;
	}
	return true;
}

function checkradio(field) {
    var cnt = -1;
    for (var i=field.length-1; i > -1; i--) {
        if (field[i].checked) {cnt = i; i = -1;}
    }
    if (cnt > -1)
		 return true;
    else 
		return false;
}
                  

function val(field,fieldtype,alerttxt)
{
	with (field)
	{
		if (fieldtype=="TextBox")
		{
			if (value==null||value=="")
			{alert(alerttxt); focus(); return false}
			else {return true}
		}
		
		if (fieldtype=="DateBox")
		{
			if (isDate(value)==false)
				{alert(alerttxt); focus(); return false}
			else {return true}
		}	
		
		if (fieldtype=="NumberBox")
		{
			if (checknumbers(value)==false)
				{alert(alerttxt); focus(); return false}
			else {return true}
		}
		
		if (fieldtype=="PhoneBox")
		{
			if (checknumbers(value)==false || value.length<3)
				{alert("Please enter a valid 10 digits value for " + alerttxt + "!"); focus(); return false}
			else {return true}
		}	
		
		if (fieldtype=="PhoneBox2")
		{
			if (checknumbers(value)==false || value.length<4)
				{alert("Please enter a valid 10 digits value for " + alerttxt + "!"); focus(); return false}
			else {return true}
		}	
		
		if (fieldtype=="RadioBox" || fieldtype=="CheckBox")
		{
			if (checkradio(field)==false)
				{alert(alerttxt); focus(); return false}
			else {return true}
		}	
		
		if (fieldtype=="QuestionBox")
		{
			if (checkradio(field)==false)
				{alert(alerttxt); focus(); return false}
			else {return true}
		}	
		
		if (fieldtype=="CheckBoxOne")
		{
			if (field.checked==false)
				{alert(alerttxt); focus(); return false}
			else {return true}
		}	

		if (fieldtype=="EmailBox")
		{
			apos=value.indexOf("@")
			dotpos=value.lastIndexOf(".")
			if (apos<1||dotpos-apos<2) 
			  {alert(alerttxt); focus(); return false}
			else {return true}
		}		
	}
}


/* devarticles.com */
function validateEmail ( emailField, errorMsg ) {
 emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
 if( !emailpat.test( emailField.value ) ) {
  alert( errorMsg);
  emailField.focus();
  emailField.select();
  return false;
 }
 return true;
}


/**************************From modelSelector.jsp**********************************/
function SetImage(id, source)
{
	if(navigator.appVersion.indexOf("MSIE 6") != -1 || navigator.appVersion.indexOf("MSIE 5") != -1)
	{
		document.getElementById(id).innerHTML = "<div style=\"position: relative; top: -30px; left: 0px; width: 158px; height: 164px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + source + "', sizingMethod='crop')\"></div>";
		document.getElementById(id).style.background = "transparent";
	}
	else
	{
		document.getElementById(id).style.background = "url('" + source + "') center left no-repeat";
	}
}

/***********************From OwnerVehicle4.jsp************************************/
	
	//To remove the duplicates from the array
	function unique(a) {
		tmp = new Array(0);
		for(i=0;i<a.length;i++){
			if(!contains(tmp, a[i])){
	   			tmp.length+=1;
	   			tmp[tmp.length-1]=a[i];
	 		}
		}
	 	return tmp;
	}
	
	
	function contains(a, e) {
		for(j=0;j<a.length;j++){
			if(a[j]==e){
				return true;
			}
		}
		return false;
	}
	
	//function to trim the spaces
	function trim(stringToTrim) {
		return stringToTrim.replace(/^\s+|\s+$/g,"");
	}
	
	//function to add the options in select box
	function addOption(selectbox,text,value){
		var optn = document.createElement("OPTION");
		optn.text = trim(text);
		optn.value = trim(value);
		selectbox.options.add(optn);
	}
	
	//function to remove the options from the select box
	function removeAllOptions(selectbox){
		var i;
		for(i=selectbox.options.length-1;i>=0;i--){
			selectbox.remove(i);
		}
		var optn = document.createElement("OPTION");
		var text = "-- Please Select Model--";
		optn.text = trim(text);
		var val = "all";
		optn.value = trim(val);
		selectbox.options.add(optn);
	}
	
	//Function to get the Model Year
	function getModelYear(){
		var get_Year = [];
		get_Year = myArray;
		var yearOpt = [];
		for(c=0;c<get_Year.length;c++){
			yearOpt.push(get_Year[c].substring(0,get_Year[c].indexOf("$")));
		}
		var Unique_YearArray = [];
		Unique_YearArray =  unique(yearOpt); 
		Unique_YearArray = Unique_YearArray.sort(function(a,b){return b - a}) ;
		addOption(document.getElementById("year"), "Current Year", "Current Year"); 
		for(i=0;i<Unique_YearArray.length;i++){
			//alert("add: "+i+"/"+Unique_YearArray.length);
			addOption(document.getElementById("year"), Unique_YearArray[i], Unique_YearArray[i]);  
		}  
		addOption(document.getElementById("year"), "Pre-2002", "Pre-2002"); 
	}
	
	//function to get the body model
	function getModel(){
		removeAllOptions(document.getElementById("model"));
		var y1=document.getElementById("year").options[document.getElementById("year").selectedIndex].text;
		var get_Model = [];
		get_Model = myArray;
		var ModelClass = [];
		for(c=0;c<get_Model.length;c++){
			if(get_Model[c].substring(0,get_Model[c].indexOf("$")) == y1){
				var bodystyle = get_Model[c].substring(get_Model[c].indexOf("$")+1,get_Model[c].indexOf("&")).split("~")[1];
				var modelname = get_Model[c].substring(get_Model[c].lastIndexOf("$")+1,get_Model[c].length);
				if(bodystyle == "Sport Utility Vehicle"){
					bodystyle = "SUV";
				}
				if(modelname.indexOf(bodystyle)<0){
					modelname = trim(modelname)+" "+bodystyle;
				}
				ModelClass.push(modelname);
			}
		}
		var unique_modelClass = unique(ModelClass);

		for(i=0;i<unique_modelClass.length;i++){
			var modeltext = unique_modelClass[i].substring(unique_modelClass[i].indexOf("*")+1,unique_modelClass[i].length);
			addOption(document.getElementById("model"),modeltext,modeltext);
		}	
		addOption(document.getElementById("model"),"Others","Others");		
	}
	
	function XML_Loop(){
		var bstyle_count = 0;
					var classtype_count = 0;
					var delimiter = "$";
					var delimiter1 = "&";
					var delimiter2 = "~";
					var delimiter3 = "|";
					var delimiter4 = "*";					
					for (i=1;i<y.length;i++){			
						for (z=1;z<y[i].childNodes.length;z++){
							var yr1 = y[i].childNodes[0].childNodes[0].nodeValue;
							for(p=0;p<y[i].childNodes[z].childNodes.length;p++){
								for(q=0;q<y[i].childNodes[z].childNodes[p].childNodes.length;q++){
									if(y[i].childNodes[z].childNodes[p].nodeName == "body_desc"){
										var bstyle = y[i].childNodes[z].childNodes[p].childNodes[q].nodeValue;
										if (bstyle != null){
										var bstyle_notnull = bstyle;
										}
									}
								if(y[i].childNodes[z].childNodes[p].nodeName == "body_code"){
								var bcode = y[i].childNodes[z].childNodes[p].childNodes[q].nodeValue;
									if (bcode != null){
										var bcode_notnull = bcode;
									}
								}
								for(r=0;r<y[i].childNodes[z].childNodes[p].childNodes[q].childNodes.length;r++){
									if(y[i].childNodes[z].childNodes[p].childNodes[q].nodeName == "class_code"){
										var classtype = y[i].childNodes[z].childNodes[p].childNodes[q].childNodes[r].nodeValue;
										if (classtype != null){
										  var classtype_notnull = classtype;
										}
									}
									if(y[i].childNodes[z].childNodes[p].childNodes[q].nodeName == "class_desc"){
										var classdesc = y[i].childNodes[z].childNodes[p].childNodes[q].childNodes[r].nodeValue;
										if (classdesc != null){
									 		var classdesc_notnull = classdesc;
										}
									}
									for(s=0;s<y[i].childNodes[z].childNodes[p].childNodes[q].childNodes[r].childNodes.length;s++){
										if(y[i].childNodes[z].childNodes[p].childNodes[q].childNodes[r].nodeName == "model_code"){
											var model = y[i].childNodes[z].childNodes[p].childNodes[q].childNodes[r].childNodes[s].nodeValue;
											if (model != null){
												var model_notnull = model;
											}
										}
										if(y[i].childNodes[z].childNodes[p].childNodes[q].childNodes[r].nodeName == "model_desc"){
											var modeldesc = y[i].childNodes[z].childNodes[p].childNodes[q].childNodes[r].childNodes[s].nodeValue;											
											if (modeldesc != null){
												var modeldesc_notnull = modeldesc;
											}										
											myArray.push(yr1+delimiter+bcode_notnull+delimiter2+bstyle_notnull+delimiter1+classtype_notnull+delimiter3+classdesc_notnull+delimiter+model_notnull+delimiter4 + modeldesc_notnull);
										}				
									}//end for S loop
								}//end for R loop
							}//end for Q loop
						}//end for P loop
					}//end of for Z loop
				}//end for I loop
	}
	