var car_area_selection1=null;
var car_area_selection2=null;


function highlight_car_area() {
	if(car_area_selection1) {
		extAreaOut('carimage1',car_area_selection1);
	}
	if(car_area_selection2) {
		extAreaOut('carimage2',car_area_selection2);
	}
	car_area_selection1=null;
	car_area_selection2=null;

	car_area_selection=document.getElementById('glass_style').value;
	
	if(car_area_selection=='Front Windshield') {
		car_area_selection1='frontwind';
		extAreaOver('carimage1', car_area_selection1);
	}
	else if(car_area_selection=='Back Glass') {
		car_area_selection2='backwind';
		extAreaOver('carimage2', car_area_selection2);
	}
	else if(car_area_selection=='Door Glass-Front, Passenger Side') {
		car_area_selection2='pfrontdoor';
		extAreaOver('carimage2', car_area_selection2);
	}
	else if(car_area_selection=="Door Glass-Front, Driver's Side") {
		car_area_selection1='dfrontdoor';
		extAreaOver('carimage1', car_area_selection1);
	}
	else if(car_area_selection=='Door Glass-Rear, Passenger Side') {
		car_area_selection2='preardoor';
		extAreaOver('carimage2', car_area_selection2);
	}
	else if(car_area_selection=="Door Glass-Rear, Driver's Side") {
		car_area_selection1='dreardoor';
		extAreaOver('carimage1', car_area_selection1);
	}
	else if(car_area_selection=="Quarter Glass, Passenger Side") {
		car_area_selection2='pquarter';
		extAreaOver('carimage2', car_area_selection2);
	}
	else if(car_area_selection=="Quarter Glass, Driver's Side") {
		car_area_selection1='dquarter';
		extAreaOver('carimage1', car_area_selection1);
	}
	else if(car_area_selection=="Other") {
		//Do Nothing
	}
	
}//highlight_car_area

window.onload = function() {
	cvi_map.defaultRadius = 0; //INT 0-100 (px radius)
	cvi_map.defaultOpacity = 33; //INT 0-100 (% opacity)
	cvi_map.defaultBordercolor = '#0000ff'; //STR '#000000'-'#ffffff'
	cvi_map.defaultAreacolor = '#000000'; //STR '#000000'-'#ffffff'
	cvi_map.defaultNoborder = false; //BOOLEAN
	cvi_map.defaultNofade = false; //BOOLEAN
	cvi_map.defaultShowcoords = false; //BOOLEAN
	cvi_map.defaultDelayed = false; //BOOLEAN
	cvi_map.defaultImgsrc = ''; //STR (path&file)
	cvi_map.defaultMapid = ''; //STR (id)
	cvi_map.add(document.getElementById('carimage1'),{opacity: 70, areacolor: '#0099ff', noborder: true});
	cvi_map.add(document.getElementById('carimage2'),{opacity: 70, areacolor: '#0099ff', noborder: true});
}//onload




/*---------------------------------------------------------------------------------------*/
function validateEmpty(fld,color_it) {
    var error = "";

    if (fld.value.length == 0) {
		if(color_it)
	        fld.style.background = '#FFB3B3'; 
        error = fld.title+" is Required.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;  
}

function checkEmail (strng) {
var error="";
if (strng == "") {
   error = "You didn't enter an email address.\n";
}

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
       error = "Please enter a valid email address.\n";
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
          error = "The email address contains illegal characters.\n";
       }
    }
return error;    
}


// phone number - strip out delimiters and check for 10 digits

function checkPhone (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a phone number.\n";
}

var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The phone number contains illegal characters.";
  
    }
    /*if (!(stripped.length == 10)) {
	error = "The phone number is the wrong length. Make sure you included an area code.\n";
    } */
return error;
}


// password - between 6-8 chars, uppercase, lowercase, and numeral

function checkPassword (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a password.\n";
}

    var illegalChars = /[\W_]/; // allow only letters and numbers
    
    if ((strng.length < 6) || (strng.length > 8)) {
       error = "The password is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
      error = "The password contains illegal characters.\n";
    } 
    else if (!((strng.search(/(a-z)+/)) && (strng.search(/(A-Z)+/)) && (strng.search(/(0-9)+/)))) {
       error = "The password must contain at least one uppercase letter, one lowercase letter, and one numeral.\n";
    }  
return error;    
}    


// username - 4-10 chars, uc, lc, and underscore only.

function checkUsername (strng) {
var error = "";
if (strng == "") {
   error = "You didn't enter a username.\n";
}


    var illegalChars = /\W/; // allow letters, numbers, and underscores
    if ((strng.length < 4) || (strng.length > 10)) {
       error = "The username is the wrong length.\n";
    }
    else if (illegalChars.test(strng)) {
    error = "The username contains illegal characters.\n";
    } 
return error;
}       


// non-empty textbox

function isEmpty(strng) {
var error = "";
  if (strng.length == 0) {
     error = "The mandatory text area has not been filled in.\n"
  }
return error;	  
}

// was textbox altered

function isDifferent(strng) {
var error = ""; 
  if (strng != "Can\'t touch this!") {
     error = "You altered the inviolate text area.\n";
  }
return error;
}

// exactly one radio button is chosen

function checkRadio(checkvalue) {
var error = "";
   if (!(checkvalue)) {
       error = "Please check a radio button.\n";
    }
return error;
}

// valid selector from dropdown list

function checkDropdown(choice) {
var error = "";
    if (choice == 0) {
    error = "You didn't choose an option from the drop-down list.\n";
    }    
return error;
}    


/*---------------------------------------------------------------------------------------*/



function check_form(cur_form){
	theForm=document.freeQuoteFrm;
	if(cur_form==1) {
		theForm.zip.value=theForm.zip.value.replace(/^\s+|\s+$/g, '') ;
		theForm.make.value=theForm.make.value.replace(/^\s+|\s+$/g, '') ;
		theForm.model.value=theForm.model.value.replace(/^\s+|\s+$/g, '') ;
		theForm.year.value=theForm.year.value.replace(/^\s+|\s+$/g, '') ;
		var why = "";
		why += validateEmpty(theForm.zip,1);
		why += validateEmpty(theForm.make,1);
		why += validateEmpty(theForm.model,1);
		why += validateEmpty(theForm.year,1);
		why += validateEmpty(theForm.glass_style,1);
		if (why != "")
		   return false;
		document.getElementById('form1').style.display = "none";
		document.getElementById('form2').style.display  = 'inline';
		//temp_string=document.getElementById('form2').innerHTML;
		//document.getElementById('form2').innerHTML=document.getElementById('form1').innerHTML;
		//document.getElementById('form1').innerHTML=temp_string;
		
		return false;
	}else if(cur_form==2) {
		theForm.name.value=theForm.name.value.replace(/^\s+|\s+$/g, '') ;
		theForm.phone_num.value=theForm.phone_num.value.replace(/^\s+|\s+$/g, '') ;
		theForm.email.value=theForm.email.value.replace(/^\s+|\s+$/g, '') ;
		theForm.isinsuarance.value=theForm.isinsuarance.value.replace(/^\s+|\s+$/g, '') ;
		theForm.comp_state.value=theForm.comp_state.value.replace(/^\s+|\s+$/g, '') ;
		theForm.comment.value=theForm.comment.value.replace(/^\s+|\s+$/g, '') ;
		var why = "";
		why += validateEmpty(theForm.name,1);
		why += validateEmpty(theForm.phone_num,1);
		
		if (why == "")
		   return true;
		else
			return false;
	}else if(cur_form == "Q"){
		theForm.name.value=theForm.name.value.replace(/^\s+|\s+$/g, '') ;
		theForm.phone_num.value=theForm.phone_num.value.replace(/^\s+|\s+$/g, '') ;
		theForm.email.value=theForm.email.value.replace(/^\s+|\s+$/g, '') ;
		theForm.isinsuarance.value=theForm.isinsuarance.value.replace(/^\s+|\s+$/g, '') ;
		theForm.comp_state.value=theForm.comp_state.value.replace(/^\s+|\s+$/g, '') ;
		theForm.comment.value=theForm.comment.value.replace(/^\s+|\s+$/g, '') ;
		var why = "";
		why += validateEmpty(theForm.name,1);
		why += validateEmpty(theForm.addr1,1);
		why += validateEmpty(theForm.addr2,1);
		why += validateEmpty(theForm.city,1);
		why += validateEmpty(theForm.state,1);
		why += validateEmpty(theForm.zip,1);
		why += validateEmpty(theForm.phone_num,1);
		
		if (why == "")
		   return true;
		else
			return false;
	}else if(cur_form == "O"){
		theForm.name.value=theForm.name.value.replace(/^\s+|\s+$/g, '') ;
		theForm.phone_num.value=theForm.phone_num.value.replace(/^\s+|\s+$/g, '') ;
		theForm.email.value=theForm.email.value.replace(/^\s+|\s+$/g, '') ;
		var why = "";
		why += validateEmpty(theForm.name,1);
		why += validateEmpty(theForm.addr1,1);
		why += validateEmpty(theForm.addr2,1);
		why += validateEmpty(theForm.city,1);
		why += validateEmpty(theForm.state,1);
		why += validateEmpty(theForm.zip,1);
		why += validateEmpty(theForm.phone_num,1);
		why += validateEmpty(theForm.email,1);

		if (why != "")
		   return false;
		
		return true;
	}else {
		return false;
	}
		
}
