//////////////////////////////////////////////////////////////////////
//  FUNCTION: highlight                                             //
//  ARGUMENT: obj - should be called using (this) to get the        //
//              object of the current field                         //
//  PURPOSE:  Highlights the current field in focus to aid the user  //
//              in filling out the form.                            //
//////////////////////////////////////////////////////////////////////
function highlight(obj){
	obj.style.backgroundColor = "#CFE3FE";
}
//////////////////////////////////////////////////////////////////////////
//  FUNCTION:  unhighlight                                              //
//  ARGUMENTS: obj - gets the object of the current field               //
//             span - the id of the span that will be displayed if      //
//               the current field (this) is empty or not set properly  //
//  PURPOSE:   Highlights the current field in focus to aid the user    //
//              in filling out the form.                                //
//////////////////////////////////////////////////////////////////////////
function unhighlight(obj, span){
	obj.style.backgroundColor = "#FFFFFF";
	var invalid_span = span + "_invalid";
	var set_hidden = span + "_verify";
	var email_field = false;
	var req_set = false;
	if(obj.name == "adj_email_req" || obj.name == "owner_email")  email_field = true;
	if(obj.name == "insured_name_req")  document.assign_claim_form.owner_name_req.value = obj.value;
	if(span && obj.name != "POI_req[]"){ //If it is a required field, 'span' is passed holding the value of the id of the span to display
		if(obj.value == ""){
			document.getElementById(span).style.display = "inline";
			if(email_field)  document.getElementById(invalid_span).style.display = "none";
			req_set = true;
		}
		else{
			document.getElementById(span).style.display = "none";
//			if(obj.name == "adj_email_req")  document.getElementById(span).style.display = "none";
			if(email_field)  document.getElementById(invalid_span).style.display = "none";
		}

		if(email_field && !email_check(obj) && !req_set){ //email_check is a function in main.js
			if(obj.name == "adj_email_req")  document.getElementById(span).style.display = "none";
			document.getElementById(invalid_span).style.display = "inline";
		}
		else if(!req_set && span == "ymm")  document.getElementById(span).style.display = "none"; //Since this is a multiple entry line, it needs special treatment to check ALL three lines
	}
}
//////////////////////////////////////////////////////////////////////////////
//  FUNCTION:  vinDecoder                                                   //
//  ARGUMENTS: vin - gets the object of the VIN field (called using         //
//               'this' in the function call                                //
//  PURPOSE:   Sets the year field automatically if it registers a          //
//               VIN with 17 characters. Will not issue year on older VINs  //
//////////////////////////////////////////////////////////////////////////////
function vinDecoder(vin){
	yr = vin.value.substring(9,10);
	yr = yr.toUpperCase();
	set_yr = "0000";
	switch(yr){
		case "1": set_yr = "2001"; break;
		case "2": set_yr = "2002"; break;
		case "3": set_yr = "2003"; break;
		case "4": set_yr = "2004"; break;
		case "5": set_yr = "2005"; break;
		case "6": set_yr = "2006"; break;
		case "7": set_yr = "2007"; break;
		case "8": set_yr = "2008"; break;
		case "9": set_yr = "2009"; break;
		case "A": set_yr = "1980"; break;
		case "B": set_yr = "1981"; break;
		case "C": set_yr = "1982"; break;
		case "D": set_yr = "1983"; break;
		case "E": set_yr = "1984"; break;
		case "F": set_yr = "1985"; break;
		case "G": set_yr = "1986"; break;
		case "H": set_yr = "1987"; break;
		case "J": set_yr = "1988"; break;
		case "K": set_yr = "1989"; break;
		case "L": set_yr = "1990"; break;
		case "M": set_yr = "1991"; break;
		case "N": set_yr = "1992"; break;
		case "P": set_yr = "1993"; break;
		case "R": set_yr = "1994"; break;
		case "S": set_yr = "1995"; break;
		case "T": set_yr = "1996"; break;
		case "V": set_yr = "1997"; break;
		case "W": set_yr = "1998"; break;
		case "X": set_yr = "1999"; break;
		case "Y": set_yr = "2000"; break;
	}
	if(set_yr != "0000"){
		document.assign_claim_form.veh_year_req.value = set_yr;
		document.assign_claim_form.veh_make_req.focus();
	}
}
//////////////////////////////////////////////////////////////////////////////
//  FUNCTION:  formatPhone                                                  //
//  ARGUMENTS: obj - gets the object of the current field                   //
//             evt - gets the event that happened (keypress) to get the     //
//                  correct keycode associated with that event.             //
//  PURPOSE:   Formats a phone field to (###)###-####                       //
//////////////////////////////////////////////////////////////////////////////
function formatPhone(obj,evt){
	var charCode = (evt.which) ? evt.which : event.keyCode;
	var val = obj.value;
	if(digitsOnly(evt)){
		if(val.length == 0)  obj.value = "(";
		else if(val.length == 4 && charCode != 8)  obj.value += ")";
		else if(val.length == 8 && charCode != 8)  obj.value += "-";
	}
	else  obj.value = val.substring(0,val.length-1);
}
//////////////////////////////////////////////////////////////////////////////
//  FUNCTION:  digitsOnly                                                   //
//  ARGUMENTS: evt - gets the event that happened (keypress) to get the     //
//                  correct keycode associated with that event.             //
//  PURPOSE:   Allows ONLY digits (1-9) to be entered in the current field  //
//////////////////////////////////////////////////////////////////////////////
function digitsOnly(evt){
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57))  return false;
	return true;
}

function vehPropInfo(obj){
	if(obj.value == "Residential Appraisal" || obj.value == "Commercial Appraisal"){
		document.getElementById('vehInfo').style.display = "none";
		document.getElementById('propInfo').style.display = "block";
		document.assign_claim_form.veh_year_req.value = "N/A";
		document.assign_claim_form.veh_make_req.value = "N/A";
		document.assign_claim_form.veh_model_req.value = "N/A";
	}
	else{
		document.getElementById('vehInfo').style.display = "block";
		document.getElementById('propInfo').style.display = "none";
	}
}