String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

function MM_swapImgRestore() { //v3.0

  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;

}

function MM_preloadImages() { //v3.0

  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();

    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)

    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}

}

function MM_findObj(n, d) { //v4.0

  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {

    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}

  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];

  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);

  if(!x && document.getElementById) x=document.getElementById(n); return x;

}

function MM_swapImage() { //v3.0

  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)

   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}

}

function format_decimal(e) {
	n = parseFloat(e.value);
	if (!isNaN(e.value))
		e.value = n.toFixed(2);
	else
		e.value = 0.00;
}

function format_number(e) {
	n = parseFloat(e.value);
	if (isNaN(e.value)) {
	newVal = '';
		for (i=0; i<e.value.length; i++) {
			if (!isNaN(e.value.charAt(i))) 
				newVal += e.value.charAt(i);
		}
		e.value = newVal;
		return false;
	} else {
		return true;
	}
}

function GoToURL(strX) {

	if (strX == "" || strX == null || strX == "undefined") {

		return;
	}

	window.top.location.href = strX;

}

var newWin;

function newWindow(URL,args) {
	if (!newWin || newWin.closed) {
		newWin = window.open(URL,'newWin',args);
	} else {
		newWin = window.open(URL,'newWin',args);
		newWin.focus();
	}
}


var dateWin;
function getDate(e, root, date, field) {
	dateWin = window.open(root+'calendar/calendar.php?ss_date='+date+'&date='+date+'&f='+field,'newWin','top='+e.screenY+',left='+e.screenX+',width=210,height=169,resize=no,scrollbar=yes');
	dateWin.focus();
}

function pers_check() {
document.theForm.g_pers.checked = '1';
}
function pers_uncheck() {
if (!document.theForm.g_pers.checked) {
	document.theForm.est.checked = '';
	document.theForm.cft.checked = '';
	document.theForm.hcft.checked = '';
	document.theForm.gcft.checked = '';
	document.theForm.icft.checked = '';
	document.theForm.empl.checked = '';
	}
}

function est_check() {
document.theForm.g_crc.checked = '1';
}

function sd_uncheck() {
if (!document.theForm.is_servicedrive.checked) {
	document.theForm.est.checked = '';
	document.theForm.sd_dispatch.checked = '';
	document.theForm.sd_ding.checked = '';
	document.theForm.sd_hail.checked = '';
	document.theForm.sd_insurance.checked = '';
	document.theForm.sd_sell_contracts.checked = '';
	document.theForm.sd_demo_only.checked = '';
	}
}

function handleEnter (field, event) {
	var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
	if (keyCode == 13) {
		var i;
		for (i = 0; i < field.form.elements.length; i++)
			if (field == field.form.elements[i])
				break;
		i = (i + 1) % field.form.elements.length;
		field.form.elements[i].focus();
		return false;
	} 
	else
	return true;
}      

function tech_override(n) {
	if(document.theForm.override.checked == true) {
		eval('document.theForm.' + n + '.disabled=false');
		document.theForm.appcode.disabled=false;
	} else {
		eval('document.theForm.' + n + '.disabled=true');
		document.theForm.appcode.disabled=true;
	}
	return;
}

function checkSvcdrvClose() {
	if(document.theForm.override.checked == true && document.theForm.appcode.value.length < 1) {
		alert("Please enter the approval code sent to you by email.");
		document.theForm.appcode.focus();
		return;
	}
	document.theForm.submit();
}

function clearBilling(form) {
	form.b_addr1.value = '';
	form.b_addr2.value = '';
	form.b_city.value = '';
	form.b_st.selectedIndex = 0;
	form.b_zip.value = '';
}

function checkUserNew() {
	if(document.theForm.first.value.length < 1) {
		alert("Please enter a first name.");
		document.theForm.first.focus();
		return;
	} else if(document.theForm.last.value.length < 1) {
		alert("Please enter a last name.");
		document.theForm.last.focus();
		return;			
	} else if(document.theForm.bizph.value.length < 10) {
		alert("Please enter a phone number.");
		document.theForm.bizph.focus();
		return;	
	} else if(document.theForm.usesms.checked && document.theForm.cell.value.length < 10) {
		alert("Please put the text number in the cell number field.");
		document.theForm.cell.focus();
		return;	
	} else if(document.theForm.usesms.checked && (document.theForm.smsnet.value.length < 1 && document.theForm.smsaddr.value.length < 15)) {
		alert("Please choose your carrier, or enter a complete three-part address in the box:\n\nPhone\n@\nCarrier string");
		document.theForm.smsnet.focus();
		return;									
	}	
	document.theForm.submit();
}

function checkUserEdit() {
	emailRegEx = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
	if(document.theForm.bizph.value.length < 10) {
		alert("Please enter a phone number.");
		document.theForm.bizph.focus();
		return;	
	} else if(document.theForm.pref.value=='email' && (document.theForm.email.value.length < 1 || ! emailRegEx.test(document.theForm.email.value))) {
		alert("Please enter a valid email address.");
		document.theForm.email.focus();
		return;			
	} else if(document.theForm.pref.value=='fax' && document.theForm.fax.value.length < 10) {
		alert("Please enter a fax number.");
		document.theForm.fax.focus();
		return;	
	} else if(document.theForm.pdrpass.value.length < 5) {
		alert("Your password must be at least 5 characters.\nA mixture of numbers and letters is more secure.");
		document.theForm.pdrpass.focus();
		return;	
		
	}	
	document.theForm.submit();
}

function checkUSF() {
	var now = new Date();
	var y = now.getYear();
	if (navigator.appName == "Netscape") {y = y + 1900;}
	if(document.theForm.date.value.length < 10) {
		alert("Please enter the issue date.");
		document.theForm.date.focus();
		return;
	} else if(document.theForm.term.value.length < 1) {
		alert("Please select a term.");
		document.theForm.term.focus();
		return;	
	} else if(document.theForm.fname.value.length < 1) {
		alert("Please enter the customer first name.");
		document.theForm.fname.focus();
		return;	
	} else if(document.theForm.lname.value.length < 1) {
		alert("Please enter the customer last name.");
		document.theForm.lname.focus();
		return;			
	} else if(document.theForm.address.value.length < 1) {
		alert("Please enter the customer address.");
		document.theForm.address.focus();
		return;	
	} else if(document.theForm.city.value.length < 1) {
		alert("Please enter the customer city.");
		document.theForm.city.focus();
		return;	
	} else if(document.theForm.state.value.length < 1) {
		alert("Please choose the customer state.");
		document.theForm.state.focus();
		return;	
	} else if(document.theForm.zip.value.length < 1) {
		alert("Please enter the customer zipcode.");
		document.theForm.zip.focus();
		return;	
	} else if(document.theForm.make.value.length < 1) {
		alert("Please enter the vehicle make.");
		document.theForm.make.focus();
		return;	
	} else if(document.theForm.model.value.length < 1) {
		alert("Please enter the vehicle model.");
		document.theForm.model.focus();
		return;	
	} else if(document.theForm.myear.value.length < 4) {
		alert("Please enter the vehicle year.");
		document.theForm.myear.focus();
		return;					
	} else if(document.theForm.vin.value.length < 17) {
		alert("Please enter the vehicle VIN.");
		document.theForm.vin.focus();
		return;	
	} else if(! testVin(document.theForm.vin.value)) {
		alert("Vin number is invalid.");
		document.theForm.vin.focus();
		return;															
	} else if(document.theForm.odom.value.length < 1) {
		alert("Please enter the vehicle odometer reading.");
		document.theForm.odom.focus();
		return;										
	} else if(document.theForm.myear.value < y-10) {
		alert("This vehicle is too old for this contract.");
		document.theForm.myear.focus();
		return;													
	}	
	document.theForm.submit();
}

function checkNotes() {
	if(document.addnote.ctype.value.length < 1) {
		alert("Please select note type.");
		document.addnote.ctype.focus();
		return;
	} else if(document.addnote.note.value.length < 1) {
		alert("Please enter a note.");
		document.addnote.note.focus();
		return;	
	}	
	document.addnote.submit();
}

function checkTechInfo() { 
	emailRegEx = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
	if ((document.theForm.status.value == 'lead' || document.theForm.status.value == 'term') && document.theForm.active.value == 1) {
		alert("This status cannot be active.");
		document.theForm.status.focus();
		return;
	} else if(document.theForm.company.value.trim().length < 1) {	
	  if(document.theForm.first.value.trim().length < 1) { 
		alert("Please enter a first name.");
		document.theForm.first.focus();
		return;
	  }	
	  if(document.theForm.last.value.trim().length < 1) {
		alert("Please enter a last name.");
		document.theForm.last.focus(); 
		return;
	  } 						
	}  else if(document.theForm.bizph.value.length < 10 || ! testPhone(document.theForm.bizph.value)) {
		alert("Please enter a valid phone number (only).");
		document.theForm.bizph.focus();
		return;	
	} else if(document.theForm.fax && document.theForm.pref.value == 'fax' && document.theForm.fax.value.length < 10) {
		alert("Please enter a valid fax number.");
		document.theForm.fax.focus();
		return;	
	}	else if(document.theForm.zip.value.length > 1 && (document.theForm.zip.value.length < 7 && document.theForm.country.value=='CA')) {
		alert("Please put a space in a Canadian postal code.");
		document.theForm.zip.focus();
		return;				
	}	else if(document.theForm.b_zip.value.length > 1 && (document.theForm.b_zip.value.length < 7 && document.theForm.b_country.value=='CA')) {
		alert("Please put a space in a Canadian postal code.");
		document.theForm.b_zip.focus();
		return;								
	} else if(document.theForm.usesms.checked && document.theForm.cell.value.length < 10) {
		alert("Please put the text number in the cell number field.");
		document.theForm.cell.focus();
		return;	
	} else if(document.theForm.email && document.theForm.pref.value == 'email' && (document.theForm.email.value.length < 1 || ! emailRegEx.test(document.theForm.email.value))) {
		alert("Please enter a valid email address.");
		document.theForm.email.focus();
		return;			
	} else if(document.theForm.usesms.checked && (document.theForm.smsnet.value.length < 1 && document.theForm.smsaddr.value.length < 15)) {
		alert("Please choose your carrier, or enter a complete three-part address in the box:\n\nPhone\n@\nCarrier string");
		document.theForm.smsnet.focus();
		return;	
	} else if(document.theForm.usrname && document.theForm.usrname.value.length < 5 && document.theForm.edit.value != 1) {
		alert("Please use a username of at least 5 characters");
		document.theForm.usrname.focus();
		return;
	} else if(document.theForm.pdrpass && document.theForm.pdrpass.value.length < 5) {
		alert("Please use a password of at least 5 characters");
		document.theForm.pdrpass.focus();
		return;			
	}									
document.theForm.submit();	
}

function checkAddTechInfo() {
	if ((document.theForm.status.value == 'lead' || document.theForm.status.value == 'term') && document.theForm.active.value == 1) {
		alert("This status cannot be active.");
		document.theForm.status.focus();
		return; 
	} else if(document.theForm.first.value.trim().length < 1 && document.theForm.company.value.trim().length < 1) {
		alert("Please enter a company or first name.");
		document.theForm.first.focus();
		return;
	} else if(document.theForm.bizph.value.length < 10 || ! testPhone(document.theForm.bizph.value)) {
		alert("Please enter a valid phone number.");
		document.theForm.bizph.focus();
		return;	
	} else if(document.theForm.zip.value.length > 1 && (document.theForm.zip.value.length < 7 && document.theForm.country.value=='CA')) {
		alert("Please put a space in a Canadian postal code.");
		document.theForm.zip.focus();
		return;				
	} else if(document.theForm.b_zip.value.length > 1 && (document.theForm.b_zip.value.length < 7 && document.theForm.b_country.value=='CA')) {
		alert("Please put a space in a Canadian postal code.");
		document.theForm.b_zip.focus();
		return;						
	}												
document.theForm.submit();			
}


function checkAddUserInfo() {
    emailRegEx = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
	if(document.theForm.company.value.length < 1) {
		alert("Please enter a company name.");
		document.theForm.company.focus();
		return;
	}	else if(document.theForm.first.value.length < 1) {
		alert("Please enter a first name.");
		document.theForm.first.focus();
		return;			
	}	else if(document.theForm.last.value.length < 1) {
		alert("Please enter a last name.");
		document.theForm.last.focus();
		return;	
	} else if(document.theForm.fax && document.theForm.pref.value == 'fax' && document.theForm.fax.value.length < 10) {
		alert("Please enter a valid fax number.");
		document.theForm.fax.focus();
		return;							
	}	else if(document.theForm.city.value.length < 1) {
		alert("Please enter a city.");
		document.theForm.city.focus();
		return;			
	}	else if(document.theForm.st.value.length < 1) {
		alert("Please select a state/province.");
		document.theForm.st.focus();
		return;			
	}	else if(document.theForm.zip.value.length < 1) {
		alert("Please enter a postal code.");
		document.theForm.zip.focus();
		return;			
	}	else if(document.theForm.zip.value.length > 1 && (document.theForm.zip.value.length < 7 && document.theForm.country.value=='CA')) {
		alert("Please put a space in a Canadian postal code.");
		document.theForm.zip.focus();
		return;				
	}	else if(document.theForm.b_zip.value.length > 1 && (document.theForm.b_zip.value.length < 7 && document.theForm.b_country.value=='CA')) {
		alert("Please put a space in a Canadian postal code.");
		document.theForm.b_zip.focus();
		return;	
	} else if(document.theForm.email && document.theForm.pref.value == 'email' && (document.theForm.email.value.length < 1 || ! emailRegEx.test(document.theForm.email.value))) {
		alert("Please enter a valid email address.");
		document.theForm.email.focus();
		return;		
	}		
document.theForm.submit();			
}

function checkAddNonTechInfo() {
	emailRegEx = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
	if(document.theForm.company.value.length < 1) {
		alert("Please enter a company name.");
		document.theForm.company.focus();
		return;
	}	else if(document.theForm.first.value.length < 1) {
		alert("Please enter a first name.");
		document.theForm.first.focus();
		return;			
	}	else if(document.theForm.last.value.length < 1) {
		alert("Please enter a last name.");
		document.theForm.last.focus();
		return;	
	} else if(document.theForm.email && (document.theForm.email.value.length < 1 || ! emailRegEx.test(document.theForm.email.value))) {
		alert("Please enter a valid email address.");
		document.theForm.email.focus();
		return;		
	}
	
document.theForm.submit();			
}

function checkNonTechUserInfo() {
	emailRegEx = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
	if(document.theForm.first.value.length < 1) {
		alert("Please enter a first name.");
		document.theForm.first.focus();
		return;
	} else if(document.theForm.last.value.length < 1) {
		alert("Please enter a last name.");
		document.theForm.last.focus();
		return;			
	} else if(document.theForm.email && (document.theForm.email.value.length < 1 || ! emailRegEx.test(document.theForm.email.value))) {
		alert("Please enter a valid email address.");
		document.theForm.email.focus();
		return;			
	} else if(document.theForm.usrname && document.theForm.usrname.value.length < 5 && document.theForm.edit.value != 1) {
		alert("Please use a username of at least 5 characters");
		document.theForm.usrname.focus();
		return;
	} else if(document.theForm.pdrpass && document.theForm.pdrpass.value.length < 5) {
		alert("Please use a password of at least 5 characters");
		document.theForm.pdrpass.focus();
		return;			
	}	
		
document.theForm.submit();	
}

function checkUserInfo() {
	emailRegEx = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
	if(document.theForm.first.value.length < 1) {
		alert("Please enter a first name.");
		document.theForm.first.focus();
		return;
	} else if(document.theForm.last.value.length < 1) {
		alert("Please enter a last name.");
		document.theForm.last.focus();
		return;			
	} else if(document.theForm.bizph.value.length < 10 || ! testPhone(document.theForm.bizph.value)) {
		alert("Please enter a valid phone number (only).");
		document.theForm.bizph.focus();
		return;	
	} else if(document.theForm.fax && document.theForm.pref.value == 'fax' && document.theForm.fax.value.length < 10) {
		alert("Please enter a valid fax number.");
		document.theForm.fax.focus();
		return;	
	}	else if(document.theForm.zip.value.length > 1 && (document.theForm.zip.value.length < 7 && document.theForm.country.value=='CA')) {
		alert("Please put a space in a Canadian postal code.");
		document.theForm.zip.focus();
		return;				
	}	else if(document.theForm.b_zip.value.length > 1 && (document.theForm.b_zip.value.length < 7 && document.theForm.b_country.value=='CA')) {
		alert("Please put a space in a Canadian postal code.");
		document.theForm.b_zip.focus();
		return;								
	} else if(document.theForm.email && document.theForm.pref.value == 'email' && (document.theForm.email.value.length < 1 || ! emailRegEx.test(document.theForm.email.value))) {
		alert("Please enter a valid email address.");
		document.theForm.email.focus();
		return;			
	} else if(document.theForm.usrname && document.theForm.usrname.value.length < 5 && document.theForm.edit.value != 1) {
		alert("Please use a username of at least 5 characters");
		document.theForm.usrname.focus();
		return;
	} else if(document.theForm.pdrpass && document.theForm.pdrpass.value.length < 5) {
		alert("Please use a password of at least 5 characters");
		document.theForm.pdrpass.focus();
		return;			
	}	
		
document.theForm.submit();	
}

function testPhone(num) {
	RegEx = /^[2-9]\d{2}-\d{3}-\d{4}$/;
	if(RegEx.test(num)) {
		return true;	
	} else {
		return false;
	}	
}


function checkTechType() {
	if(document.theForm.repair_type.value.length < 1 && (document.theForm.cft.checked || document.theForm.hcft.checked || document.theForm.gcft.checked)) {
		alert("Please choose a repair type.");
		document.theForm.repair_type.focus();
		return;
	} else if(document.theForm.is_servicedrive.checked && document.theForm.sd_sell_contracts.checked) 
		{
		if(document.theForm.crcsigner.value.length < 1) 
			{
			alert("Please select a signer.");
			document.theForm.crcsigner.focus();	
			return;
			} 
		else if(document.theForm.acct_code.value.length < 1) 
			{
			alert("Please enter the account prefix.");
			document.theForm.acct_code.focus();	
			return;
			}
		else if(document.theForm.dealer_code.value.length < 1) 
			{
			alert("Please enter the dealer code.");
			document.theForm.dealer_code.focus();
			return;		
			}	
		}	
document.theForm.submit();	
}

function setAcctCode() {
	if(document.theForm.crcsigner.value=='DG') 
		{
		document.theForm.acct_code.value='DG';
		document.theForm.ptr.value='dg';
		}
	else if(document.theForm.crcsigner.value=='EFG')		
		{
		document.theForm.ptr.value='efg';
		}
}

function clearAddTech(num) {
	if(num==1) {
		document.theForm.techname1.value='';
		document.theForm.techphone1.value='';
	} else if (num==2) {
		document.theForm.techname2.value='';
		document.theForm.techphone2.value='';		
	} else if (num==3) {
		document.theForm.techname3.value='';
		document.theForm.techphone3.value='';
	}
	return;
}

function checkTechActions() {
	var action = document.theForm.action.value;
	var agree=confirm("Are you sure?");
	if (agree && action != 'print') {
		document.theForm.submit();
		}	
	if (agree && action == 'print') {
		
		window.open("tech_actions.php?mode=doprint","newWin","width=800px, height=600px, resizable, scrollbars");
		}
}

function sendUserPass(id) {
	var str="id=" + id;	
	postDataReturnText('ajax_sendUserPass.php',str,ajax_display);
}

//************************************

function populateNotes() {
	txt = new noteKeys();
	var str = eval("txt." + document.theForm.note_type.value)
	document.theForm.note.value=str;	
	return;
}

function noteKeys() {
	this.NI = 'Not Interested: ';
	this.OU = 'Owner Unavailable: ';
	this.SP = 'Send Packet: ';
	this.PR = 'Packet Received: ';
	this.GN = 'General Note: ';
	this.TC = 'Tech Contacted: ';
	this.SU = 'Tech Signed Up: ';
	this.FD = 'Followup Done: ';
}

//************************************

function ajaxDelSubtech(tid,id){
	var str="tid=" + tid + "&id=" + id;
	postDataReturnText('ajax_DelSubtech.php',str,ajax_reload_info);
}

function ajaxDelTechfiles(id,cftid){
	var str="cftid=" + cftid + "&id=" + id;
	postDataReturnText('ajax_DelTechfiles.php',str,ajax_reload_files);
}

function ajax_reload_info(tid) {
	location.href='tech_info.php?id=' + tid;
}

function ajax_reload_files(cftid) {
	location.href='tech_files.php?id=' + cftid;
}

function forceCheckSD() {
	document.theForm.is_servicedrive.checked=true;
	return;
}

function displayButtons(obj) {
	if(obj.checked && document.theForm.crcsigner.value=='DG') {
		document.getElementById('ctype').style.display = 'block';	
		} else {
		document.getElementById('ctype').style.display = 'none';
		}		
}

function checkSDSW() {
	emailRegEx = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
	if(document.theForm.first.value.length < 1) {
		alert("Please enter a first name.");
		document.theForm.first.focus();
		return;
	} else if(document.theForm.last.value.length < 1) {
		alert("Please enter a last name.");
		document.theForm.last.focus();
		return;	
	} else if(! emailRegEx.test(document.theForm.email.value)) {
		alert("Please enter a valid email address.");
		document.theForm.email.focus();
		return;			
	}									
document.theForm.submit();	
}

// not in use
function checkTechCSI() {
	var len1 = document.theForm.r1_q1.length;
	var len2 = document.theForm.r2_q1.length;
	var len3 = document.theForm.r3_q1.length;
	var chosen1 = "";
	var chosen2 = "";
	var chosen3 = "";
	var chosen4 = "";
	for (i = 0; i < len1; i++) {
	if (document.theForm.r1_q1[i].checked) {
		chosen1 = document.theForm.r1_q1[i].value;
		}
	if (document.theForm.r1_q2[i].checked) {
		chosen2 = document.theForm.r1_q2[i].value;
		}	
	if (document.theForm.r1_q3[i].checked) {
		chosen3 = document.theForm.r1_q3[i].value;
		}
	if (document.theForm.r1_q4[i].checked) {
		chosen4 = document.theForm.r1_q4[i].value;
		}					
	}
	if(document.theForm.ref1company.value.length > 1 && document.theForm.ref1.value==0 && (! chosen1 || ! chosen2 || ! chosen3 || ! chosen4)) {
		alert("Please score this tech for reference 1.");
		return;
	}	
	chosen1 = "";
	chosen2 = "";
	chosen3 = "";
	chosen4 = "";
	for (i = 0; i < len2; i++) {
	if (document.theForm.r2_q1[i].checked) {
		chosen1 = document.theForm.r2_q1[i].value;
		}
	if (document.theForm.r2_q2[i].checked) {
		chosen2 = document.theForm.r2_q2[i].value;
		}	
	if (document.theForm.r2_q3[i].checked) {
		chosen3 = document.theForm.r2_q3[i].value;
		}
	if (document.theForm.r2_q4[i].checked) {
		chosen4 = document.theForm.r2_q4[i].value;
		}					
	}
	if(document.theForm.ref2company.value.length > 1 && document.theForm.ref2.value==0 && (! chosen1 || ! chosen2 || ! chosen3 || ! chosen4)) {
		alert("Please score this tech for reference 2.");
		return;
	}	
	chosen1 = "";
	chosen2 = "";
	chosen3 = "";
	chosen4 = "";
	for (i = 0; i < len3; i++) {
	if (document.theForm.r3_q1[i].checked) {
		chosen1 = document.theForm.r3_q1[i].value;
		}
	if (document.theForm.r3_q2[i].checked) {
		chosen2 = document.theForm.r3_q2[i].value;
		}	
	if (document.theForm.r3_q3[i].checked) {
		chosen3 = document.theForm.r3_q3[i].value;
		}
	if (document.theForm.r3_q4[i].checked) {
		chosen4 = document.theForm.r3_q4[i].value;
		}					
	}
	if(document.theForm.ref3company.value.length > 1 && document.theForm.ref3.value==0 && (! chosen1 || ! chosen2 || ! chosen3 || ! chosen4)) {
		alert("Please score this tech for reference 3.");
		return;
	}	
document.theForm.submit();		
}

function ajaxExportTotal(){
	var len = document.Form1.view.length;
	var chosen = "";
	for (i = 0; i < len; i++) {
	if (document.Form1.view[i].checked) {
		chosen = document.Form1.view[i].value;
		}
	}
	var str="view=" + chosen;
	postDataReturnText('ajax_exportTotal.php',str,ajax_display);
}

function ajaxRunRecon(){
	var len = document.Form2.run.length;
	var chosen = "";
	for (i = 0; i < len; i++) {
	if (document.Form2.run[i].checked) {
		chosen = document.Form2.run[i].value;
		}
	}
	var str="run=" + chosen;
	postDataReturnText('ajax_runRecon.php',str,ajax_display);
}

function enableExportRun(disable) {
	if(disable) {document.Form2.btnSubmit.disabled=true;}
	else {document.Form2.btnSubmit.disabled=false;}
	return;	
}

function checkZipLength() {
	if(document.theForm.zip.value.length > 1 && document.theForm.zip.value.length < 7 && document.theForm.country.value == 'CA') {
		alert("Please put a space in a Canadian postal code.");
		document.theForm.zip.focus();
		return;	
	}
	document.theForm.submit();				
}

function ajaxCheckUserDup() {
	var str="usrname=" + document.theForm.usrname.value + "&id=" + document.theForm.id.value;
	postDataReturnText('ajax_CheckUserDup.php',str,ajaxDupAlert);	
}

function ajaxDupAlert(response) {
	if(response==1) {
		alert("Please choose another user name.");
		document.theForm.usrname.focus();
		return;	
	}
}

function setWhoIsCallingBlock(crc) {
	if(document.theForm.source.value=='IC') {
	document.getElementById('icDiv').style.display = 'block';	
	document.getElementById('custDiv').style.display = 'none';	
	document.getElementById('bsDiv').style.display = 'none';	
	} 	else if(document.theForm.source.value=='CUST') {
	document.getElementById('custDiv').style.display = 'block';	
	document.getElementById('icDiv').style.display = 'none';
	document.getElementById('bsDiv').style.display = 'none';	
	}	else if(document.theForm.source.value=='BS') {
	getCRC(crc);	
	}
}

function getCRC(crc) {
	var str="zip=" + document.theForm.zip.value + "&state=" + document.theForm.st.value + "&crc=" + crc;
	postDataReturnText('ajax_getCRC.php',str,ajaxDisplay);		
}

function ajaxDisplay(response) {
	var data = response.split("|");
	//document.getElementById('crcDiv').innerHTML = data[1];	
	document.getElementById(''+data[0]+'').innerHTML = data[1];
	document.getElementById('bsDiv').style.display = 'block';	
	document.getElementById('icDiv').style.display = 'none';	
	document.getElementById('custDiv').style.display = 'none';		
}


function checkSearchTech() {
	document.theForm.submit();									
}

function checkCSI() {
	var button1_choice = false;
	var button2_choice = false;
	var button3_choice = false;
	var button4_choice = false;
	var button5_choice = false;
	
	if(theForm.declined.checked || theForm.noanswer.checked) {
	document.theForm.submit();
	return true;
	}
	
	for (counter = 1; counter <= 5; counter++) {
	// If a radio button has been selected it will return true
	// (If not it will return false)
	if (theForm.q1[counter].checked) {
	button1_choice = true; 
	}
}
	for (counter = 1; counter <= 5; counter++) {
	if (theForm.q2[counter].checked) {
	button2_choice = true; 
	}
}
	for (counter = 1; counter <= 5; counter++) {
	if (theForm.q3[counter].checked) {
	button3_choice = true; 
	}
}
	for (counter = 1; counter <= 5; counter++) {
	if (theForm.q4[counter].checked) {
	button4_choice = true; 
	}
}
	for (counter = 1; counter <= 5; counter++) {
	if (theForm.q5[counter].checked) {
	button5_choice = true; 
	}
}
	if(! button1_choice) {
		alert("Please answer question 1.");
		return;
	} else if(! button2_choice) {
		alert("Please answer question 2.");
		return;
	} else if(! button3_choice) {
		alert("Please answer question 3.");
		return;
	} else if(! button4_choice) {
		alert("Please answer question 4.");
		return;
	} else if(! button5_choice) {
		alert("Please answer question 5.");
		return;
	}
	document.theForm.submit();
}

function checkCSIND() {
	var button1_choice = false;
	var button2_choice = false;
	var button3_choice = false;
	var button4_choice = false;
	
	if(theForm.declined.checked || theForm.noanswer.checked) {
	document.theForm.submit();
	return true;
	}
	
	for (counter = 1; counter <= 5; counter++) {
	// If a radio button has been selected it will return true
	// (If not it will return false)
	if (theForm.q1[counter].checked) {
	button1_choice = true; 
	}
}
	for (counter = 1; counter <= 5; counter++) {
	if (theForm.q2[counter].checked) {
	button2_choice = true; 
	}
}
	for (counter = 1; counter <= 5; counter++) {
	if (theForm.q3[counter].checked) {
	button3_choice = true; 
	}
}
	for (counter = 1; counter <= 5; counter++) {
	if (theForm.q4[counter].checked) {
	button4_choice = true; 
	}
}

	if(! button1_choice) {
		alert("Please answer question 1.");
		return;
	} else if(! button2_choice) {
		alert("Please answer question 2.");
		return;
	} else if(! button3_choice) {
		alert("Please answer question 3.");
		return;
	} else if(! button4_choice) {
		alert("Please answer question 4.");
		return;
	}
	document.theForm.submit();
}

function fetchMake() {
	if(document.theForm.vehvin) {
		var str = "vehvin=" + theForm.vehvin.value;
		postDataReturnText('../servicedrive/ajax_fetchMake.php',str,ajaxReturnMake);
		}	
}

function ajaxReturnMake(response) {
	var data = response.split("|");
	if(data) {
	document.theForm.vehyear.value = data[0];
	document.theForm.vehmake.value = data[1];
	document.theForm.vehmodel.value = data[2];
	}
}

function checkHCCustInfo() {
	emailRegEx = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
	if(document.theForm.fname.value.length < 1) {
		alert("Please enter a first name.");
		document.theForm.fname.focus();
		return;
	} else if(document.theForm.lname.value.length < 1) {
		alert("Please enter a last name.");
		document.theForm.lname.focus();
		return;	
	} else if(document.theForm.email && document.theForm.email.value.length > 1 && ! emailRegEx.test(document.theForm.email.value)) {
		alert("Please enter a valid email address.");
		document.theForm.email.focus();
		return;			
	} else if(document.theForm.addr1.value.length < 1) {
		alert("Please enter an address.");
		document.theForm.addr1.focus();
		return;				
	} else if(document.theForm.city.value.length < 1) {
		alert("Please enter a city.");
		document.theForm.city.focus();
		return;						
	} else if(document.theForm.st.value.length < 1) {
		alert("Please select the state.");
		document.theForm.st.focus();
		return;						
	} else if(document.theForm.zip.value.length < 1) {
		alert("Please enter the zip code.");
		document.theForm.zip.focus();
		return;								
	} else if(document.theForm.phone1.value.length < 10 || ! testPhone(document.theForm.phone1.value)) {
		alert("Please enter a valid phone number (only).");
		document.theForm.phone1.focus();
		return;	
	} else if(document.theForm.caller.value.length < 1) {
		alert("Please select call source.");
		document.theForm.caller.focus();
		return;				
	} else if(document.theForm.insco.value.length < 1) {
		alert("Please select insurance company.");
		document.theForm.insco.focus();
		return;						
	} else if(document.theForm.vehvin.value.length < 17) {
		alert("Please enter the VIN.");
		document.theForm.vehvin.focus();
		return;		
	} else if(! testVin(document.theForm.vehvin.value)) {
		alert("Vin number is invalid.");
		document.theForm.vehvin.focus();
		return;												
	} else if(document.theForm.vehyear.value.length < 1) {
		alert("Please enter the year.");
		document.theForm.vehyear.focus();
		return;						
	} else if(document.theForm.vehmake.value.length < 1) {
		alert("Please enter the make.");
		document.theForm.vehmake.focus();
		return;								
	} else if(document.theForm.vehmodel.value.length < 1) {
		alert("Please enter the model.");
		document.theForm.vehmodel.focus();
		return;						
	}									
document.theForm.submit();	
}

function checkDemo() {
	if(document.theForm.company.value.length < 1) {
		alert("Please enter demo location.");
		document.theForm.company.focus();
		return;	
	} else if(document.theForm.addr1.value.length < 5) {
		alert("Please enter an address.");
		document.theForm.addr1.focus();
		return;	
	} else if(document.theForm.city.value.length < 1) {
		alert("Please enter a city.");
		document.theForm.city.focus();
		return;	
	} else if(document.theForm.st.value.length < 1) {
		alert("Please select a state.");
		document.theForm.st.focus();
		return;	
	} else if(document.theForm.zip.value.length < 5) {
		alert("Please enter the zipcode.");
		document.theForm.zip.focus();
		return;	
	} else if(document.theForm.contact.value.length < 4) {
		alert("Please enter the contact person.");
		document.theForm.contact.focus();
		return;	
	} else if(document.theForm.phone1.value.length < 10) {
		alert("Please enter the contact phone.");
		document.theForm.phone1.focus();
		return;	
	} else if(document.theForm.agent.value.length < 4) {
		alert("Please enter the agent name.");
		document.theForm.agent.focus();
		return;	
	} else if(document.theForm.phone2.value.length < 10) {
		alert("Please enter the agent phone.");
		document.theForm.phone2.focus();
		return;									
	} else if(document.theForm.reqdate.value.length < 1) {
		alert("Please enter the requested date.");
		document.theForm.reqdate.focus();
		return;	
	} else if(document.theForm.reqtime.value.length < 1) {
		alert("Please enter the requested time.");
		document.theForm.reqtime.focus();
		return;			
	} else if(document.theForm.demo_cc.value.length < 1) {
		alert("Please select a cost center.");
		document.theForm.demo_cc.focus();
		return;
	} else if(document.theForm.billto.value.length < 1) {
		alert("Please select a bill to.");
		document.theForm.billto.focus();
		return;	
	} else if(document.theForm.sch_ts && document.theForm.sch_ts.value == '0000-00-00 00:00:00') {
		alert("Please pick a time.");
		document.theForm.sch_ts.focus();
		return;			
	} else if(document.theForm.assigntech && document.theForm.assigntech.value < 1 && document.theForm.override.value < 1) {
		alert("Please assign a tech.");
		document.theForm.assigntech.focus();
		return;	
	} else if(document.theForm.payamt && document.theForm.payamt.value == '0.00' && document.theForm.cls.value == 1) {
		alert("Please enter the tech payment.");
		document.theForm.payamt.focus();
		return;								
	}
	var str = "zip=" + theForm.zip.value;
	postDataReturnText('ajax_testZip.php',str,ajaxTestZip);									
}

function ajaxTestZip(response) {
	if (response==0) {
		alert("Zip code is invalid");
		document.theForm.zip.focus();
		return;									
	} else {
	document.theForm.submit();		
	}
}

function checkSCClaimInfo() {
	if(document.theForm.fname.value.length < 1) {
		alert("Please enter the first name.");
		document.theForm.fname.focus();
		return;
	} else if(document.theForm.lname.value.length < 1) {
		alert("Please enter the last name.");
		document.theForm.lname.focus();
		return;		
	} else if(document.theForm.addr1.value.length < 1) {
		alert("Please enter the address.");
		document.theForm.addr1.focus();
		return;		
	} else if(document.theForm.city.value.length < 3) {
		alert("Please enter city.");
		document.theForm.city.focus();
		return;				 
	} else if(document.theForm.st.value == "") {
		alert("Please select state.");
		document.theForm.state.focus(); 
		return;				
	} else if(document.theForm.zip.value.length < 5) {
		alert("Please enter a valid zip.");
		document.theForm.zip.focus();
		return;				 
	} else if(document.theForm.phone1.value.length < 1) {
		alert("Please enter a phone number.");
		document.theForm.phone1.focus();
		return;
	} else if(document.theForm.vehyear.value.length < 1) {
		alert("Please select vehicle year.");
		document.theForm.vehyear.focus();
		return;	
	} else if(document.theForm.vehmake.value.length < 1) {
		alert("Please enter vehicle make.");
		document.theForm.vehmake.focus();
		return;	
	} else if(document.theForm.vehmodel.value.length < 1) {
		alert("Please enter vehicle model.");
		document.theForm.vehmodel.focus();
		return;	
	} else if(document.theForm.vehvin.value.length < 1) {
		alert("Please enter vehicle vin.");
		document.theForm.vehvin.focus();
		return;									
	} else if(document.theForm.damage_date && (document.theForm.damage_date.value.length < 10 || document.theForm.damage_date.value=='0000-00-00')) {
		alert("Please enter valid damage date.");
		document.theForm.damage_date.focus();
		return;	
	} else if(document.theForm.affgrp.value.length < 2) {
		alert("Please select a program.");
		document.theForm.affgrp.focus();
		return;							
	} else if((theForm.affgrp.value == "vt" && document.theForm.insclaimnum.value.length < 6)  || (theForm.affgrp.value == "dr" && document.theForm.insclaimnum.value.length < 5)) {
		alert("Please enter the claim number.");
		document.theForm.insclaimnum.focus();
		return;
	} else if((document.theForm.affgrp.value == "apco") && (document.theForm.policynum.value.length != 10)) {
		alert("Please enter 10 digit Policy/Agreement Number.");
		document.theForm.policynum.focus();
		return;	
	}			
	document.theForm.submit();		
}

function checkHClaimInfo() {
	if(document.theForm.fname.value.length < 1) {
		alert("Please enter the first name.");
		document.theForm.fname.focus();
		return;
	} else if(document.theForm.lname.value.length < 1) {
		alert("Please enter the last name.");
		document.theForm.lname.focus();
		return;		
	} else if(document.theForm.addr1.value.length < 1) {
		alert("Please enter the address.");
		document.theForm.addr1.focus();
		return;		
	} else if(document.theForm.city.value.length < 3) {
		alert("Please enter city.");
		document.theForm.city.focus();
		return;				 
	} else if(document.theForm.st.value == "") {
		alert("Please select state.");
		document.theForm.state.focus(); 
		return;				
	} else if(document.theForm.zip.value.length < 5) {
		alert("Please enter a valid zip.");
		document.theForm.zip.focus();
		return;				 
	} else if(document.theForm.phone1.value.length < 1) {
		alert("Please enter a phone number.");
		document.theForm.phone1.focus();
		return;
	} else if(document.theForm.vehyear.value.length < 1) {
		alert("Please select vehicle year.");
		document.theForm.vehyear.focus();
		return;	
	} else if(document.theForm.vehmake.value.length < 1) {
		alert("Please enter vehicle make.");
		document.theForm.vehmake.focus();
		return;	
	} else if(document.theForm.vehmodel.value.length < 1) {
		alert("Please enter vehicle model.");
		document.theForm.vehmodel.focus();
		return;	
	} else if(document.theForm.vehvin.value.length < 17) {
		alert("Please enter vehicle vin.");
		document.theForm.vehvin.focus();
		return;		
	} else if(! testVin(document.theForm.vehvin.value)) {
		alert("Vin number is invalid.");
		document.theForm.vehvin.focus();
		return;	
	} else if(document.theForm.source.value.length < 1 && document.theForm.id.value=='') {
		alert("Please select Who is Calling.");
		document.theForm.source.focus();
		return;														
	} else if(document.theForm.source.value=='IC' && document.theForm.ic_insco.value.length < 2 && document.theForm.id.value=='') {
		alert("Please select the ic insurance company.");
		document.theForm.ic_insco.focus();
		return;		
	} else if(document.theForm.source.value=='CUST' && document.theForm.cust_insco.value.length < 2 && document.theForm.id.value=='') {
		alert("Please select the insurance company.");
		document.theForm.cust_insco.focus();
		return;		
	} else if(document.theForm.source.value=='BS' && document.theForm.bs_insco.value.length < 2 && document.theForm.id.value=='') {
		alert("Please select the insurance company.");
		document.theForm.bs_insco.focus();
		return;						
	} else if(document.theForm.source.value=='IC' && document.theForm.ic_insclaimnum.value.length < 2 && document.theForm.id.value=='') {
		alert("Please enter the insurance claim number.");
		document.theForm.ic_insclaimnum.focus();
		return;	
	} else if(document.theForm.source.value=='CUST' && document.theForm.cust_insclaimnum.value.length < 2 && document.theForm.id.value=='') {
		alert("Please enter the insurance claim number.");
		document.theForm.cust_insclaimnum.focus();
		return;	
	} else if(document.theForm.crc && document.theForm.crc.value.length < 1 && document.theForm.id.value=='') {
		alert("Please select the body shop.");
		document.theForm.crc.focus();
		return;			
	} else if(document.theForm.source.value=='BS' && document.theForm.bs_insclaimnum.value.length < 2 && document.theForm.id.value=='') {
		alert("Please enter the insurance claim number.");
		document.theForm.bs_insclaimnum.focus();
		return;					
	} else if(document.theForm.source.value=='IC' && document.theForm.ic_affgrp.value.length < 1 && document.theForm.id.value=='') {
		alert("Please select a storm.");
		document.theForm.ic_affgrp.focus();
		return;	
	} else if(document.theForm.source.value=='CUST' && document.theForm.cust_affgrp.value.length < 1 && document.theForm.id.value=='') {
		alert("Please select a storm.");
		document.theForm.cust_affgrp.focus();
		return;	
	} else if(document.theForm.source.value=='BS' && document.theForm.bs_affgrp.value.length < 1 && document.theForm.id.value=='') {
		alert("Please select a storm.");
		document.theForm.bs_affgrp.focus();
		return;					
	} else if(document.theForm.cust_has_sc && document.theForm.cust_has_sc.value==1 && document.theForm.policynum.value.length < 2 && document.theForm.id.value=='') {
		alert("Please enter the contract number.");
		document.theForm.policynum.focus();
		return;					
	}			
	var str = "vin=" + theForm.vehvin.value;
	postDataReturnText('ajax_priorClaims.php',str,ajaxPriorClaims);
}

// SC claims always return false
function ajaxPriorClaims(prior) {
	if(prior) {
		var agree=confirm("There are prior claims on this vin.\n" + 
	      "Please review those for duplications.");
		if (agree) {
			if(document.theForm.source.value=='IC') {
				document.theForm.affgrp.value = document.theForm.ic_affgrp.value;
				document.theForm.insco.value = document.theForm.ic_insco.value;	
				document.theForm.insclaimnum.value = document.theForm.ic_insclaimnum.value;	
				document.theForm.deductible.value = document.theForm.ic_deductible.value;	
				}
			else if(document.theForm.source.value=='CUST') {
				document.theForm.affgrp.value = document.theForm.cust_affgrp.value;
				document.theForm.insco.value = document.theForm.cust_insco.value;	
				document.theForm.insclaimnum.value = document.theForm.cust_insclaimnum.value;
				document.theForm.deductible.value = document.theForm.cust_deductible.value;	
				} 
			else if(document.theForm.source.value=='BS') {
				document.theForm.affgrp.value = document.theForm.bs_affgrp.value;
				document.theForm.insco.value = document.theForm.bs_insco.value;	
				document.theForm.insclaimnum.value = document.theForm.bs_insclaimnum.value;	
				} 		
			document.theForm.submit();
		} else {return;}
	} else {
		if(document.theForm.source.value=='IC') {
				document.theForm.affgrp.value = document.theForm.ic_affgrp.value;
				document.theForm.insco.value = document.theForm.ic_insco.value;	
				document.theForm.insclaimnum.value = document.theForm.ic_insclaimnum.value;	
				document.theForm.deductible.value = document.theForm.ic_deductible.value;	
				}
			else if(document.theForm.source.value=='CUST') {
				document.theForm.affgrp.value = document.theForm.cust_affgrp.value;
				document.theForm.insco.value = document.theForm.cust_insco.value;	
				document.theForm.insclaimnum.value = document.theForm.cust_insclaimnum.value;
				document.theForm.deductible.value = document.theForm.cust_deductible.value;	
				} 
			else if(document.theForm.source.value=='BS') {
				document.theForm.affgrp.value = document.theForm.bs_affgrp.value;
				document.theForm.insco.value = document.theForm.bs_insco.value;	
				document.theForm.insclaimnum.value = document.theForm.bs_insclaimnum.value;	
				} 		
		document.theForm.submit();
		}
}

function checkOSClaimInfo() {
	if(document.theForm.fname.value.length < 1) {
		alert("Please enter the first name.");
		document.theForm.fname.focus();
		return;
	} else if(document.theForm.lname.value.length < 1) {
		alert("Please enter the last name.");
		document.theForm.lname.focus();
		return;		
	} else if(document.theForm.addr1.value.length < 1) {
		alert("Please enter the address.");
		document.theForm.addr1.focus();
		return;		
	} else if(document.theForm.city.value.length < 3) {
		alert("Please enter city.");
		document.theForm.city.focus();
		return;				 
	} else if(document.theForm.st.value == "") {
		alert("Please select state.");
		document.theForm.state.focus(); 
		return;				
	} else if(document.theForm.zip.value.length < 5) {
		alert("Please enter a valid zip.");
		document.theForm.zip.focus();
		return;				 
	} else if(document.theForm.phone1.value.length < 1) {
		alert("Please enter a phone number.");
		document.theForm.phone1.focus();
		return;
	} else if(document.theForm.vehmake.value.length < 1) {
		alert("Please enter the service address.");
		document.theForm.vehmake.focus();
		return;	
	} else if(document.theForm.vehmodel.value.length < 1) {
		alert("Please enter the service city.");
		document.theForm.vehmodel.focus();
		return;	
	} else if(document.theForm.affgrp.value.length < 2) {
		alert("Please select a storm.");
		document.theForm.affgrp.focus();
		return;	
	} else if(document.theForm.insco.value.length < 2) {
		alert("Please select the insurance company.");
		document.theForm.insco.focus();
		return;		
	} else if(document.theForm.insclaimnum.value.length < 2) {
		alert("Please enter the insurance claim number.");
		document.theForm.insclaimnum.focus();
		return;	
	}			
	document.theForm.submit();		
}

function checkDealerSearch() {
	if((document.theForm.affgrp && document.theForm.affgrp.value.length < 1) && document.theForm.name.value.length < 1 && document.theForm.city.value.length < 1 && document.theForm.state.value.length < 1 && document.theForm.zip.value.length < 1 && document.theForm.dcft.checked==false && document.theForm.gcft.checked==false && document.theForm.icft.checked==false && document.theForm.wcft.checked==false) {
		alert("Please enter something.");
		return;
	}	
	document.theForm.submit();
}


function confirmDelete(claimId) {
 var answer=confirm("Are you sure you want to delete this claim?");	

 if (answer) {
 	//deleteClaim(claimId);
 	var qStr='claimId='+claimId;	
    postDataReturnText('ajax_delete_claim.php',qStr,ajax_delete_claim);
 } else {
   return false;
 }
}

function deleteClaim(claimId)
{
 var qStr='claimId='+claimId;	
 postDataReturnText('ajax_delete_claim.php',qStr,ajax_delete_claim);	
}
   
function ajax_delete_claim(data)
{
 window.location.reload(false);  
}

function checkQS() {
	if(document.qs.search.value.length < 1) {
		alert("Please enter the search term.");
		document.qs.search.focus();
		return;
	} else if(document.qs.field.value.length < 1) {
		alert("Please select the field.");
		document.qs.field.focus();
		return;	
	}			
	document.qs.submit();					
}

      
function showOrHideDiv(div,txt)
{
 var obj = document.getElementById(div);
 var currentDisplay = obj.style.display;
  
 if (currentDisplay == 'none')   
 {  
  document.getElementById(div).style.display = 'block';
  document.getElementById(txt).value='-';	
 }
 else
 { 
  document.getElementById(div).style.display = 'none';
  document.getElementById(txt).value='+';	  
 }  
}  

function checkFileUpload() {
	numlRegEx = /^[0-9]{5}$/;
	if(document.theForm.ro.value.length < 1) {
		alert("Please choose a file.");
		document.theForm.ro.focus();
		return;	
	}
	var cn = document.theForm.ro.value.split("\\");
	var cx = cn[cn.length-1];
	var cz = cx.substring(0,5);
	if(! numlRegEx.test(cz)) {
		alert("Filename must start with 5 digit claim number.");
		document.theForm.ro.focus();
		return;		
	}
	var str = "ro=" + cx;
	postDataReturnText('ajax_testDupFile.php',str,ajaxTestDupFile);	
}

function ajaxTestDupFile(response) {
	if (response==1) {
		alert("File name is a duplicate");
		document.theForm.ro.focus();
		return;									
	} else {
	document.theForm.submit();		
	}
}

// not in use
function basename (path, suffix) {
     // *     example 1: basename('/www/site/home.htm', '.htm');
    // *     returns 1: 'home'
 
    var b = path.replace(/^.*[\/\\]/g, '');
    
    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
        b = b.substr(0, b.length-suffix.length);
    }
    
    return b;
}

function allowContract() {
	if(document.theForm.has_contract[0].checked) {
	document.theForm.policynum.disabled=false;	
	} else {
	document.theForm.policynum.disabled=true;	
	}
	
}

function numFormat(e, p) {
	n = parseFloat(e.value);
	if (!isNaN(n))
		e.value = n.toFixed(2);
	else
		e.value = '';
}

function checkLogin() {
	if(document.theForm.name.value.length < 1) {
		alert("Please enter your username.");
		document.theForm.name.focus();
		return;
	} else if(document.theForm.pdrpass.value.length < 1) {
		alert("Please enter your password.");
		document.theForm.pdrpass.focus();
		return;		
	}			
	document.theForm.submit();		
}

function stormDetails(code) {
	var str="code=" + code;
	postDataReturnText('ajax_stormDetails.php',str,ajaxDisplayStormDetails);		
}

function ajaxDisplayStormDetails(response) {
	document.getElementById('stormDiv').innerHTML = response;	
}


function toggle(x,origColor){
	var newColor = '#222222';
	if ( x.style ) {
		x.style.backgroundColor = (newColor == x.style.backgroundColor)? origColor : newColor;
		alert('original color: '+origColor+' new color: '+newColor+ ' current color: '+x.style.backgroundColor); 
	}
} 
 

function getStormRevenue()
{ 
 var storm = $('storm').value;	
 var qStr = 'action=getStormRevenue&storm='+storm;
 postDataReturnText('ajax_storm_revenue.php',qStr,ajaxDisplayStormRevenue);
}   


function ajaxDisplayStormRevenue(data)
{
 $('storm_revenue_details').innerHTML = data;	
}


function checkAffinionClaim() {
	emailRegEx = /^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i;
	var len1 = document.theForm.vehcat.length;
	var choseveh = false;
	for (i = 0; i < len1; i++) {
	if (document.theForm.vehcat[i].checked) {
		choseveh = document.theForm.vehcat[i].value;
		}
	}
	if(document.theForm.fname.value.length < 1) {
		alert("Please enter the first name.");
		document.theForm.fname.focus();
		return;
	} else if(document.theForm.lname.value.length < 1) {
		alert("Please enter the last name.");
		document.theForm.lname.focus();
		return;	
	} else if(document.theForm.email && document.theForm.skip_email && ! document.theForm.skip_email.checked) {
		if(! emailRegEx.test(document.theForm.email.value)) {
			alert("Please enter a valid email address.");
			document.theForm.email.focus();
			return;
		}	
	} else if(document.theForm.addr1.value.length < 3) {
		alert("Please enter the address.");
		document.theForm.addr1.focus();
		return;				 						
	} else if(document.theForm.city.value.length < 3) {
		alert("Please enter the city.");
		document.theForm.city.focus();
		return;				 
	} else if(document.theForm.st.value.length < 1) {
		alert("Please select the state.");
		document.theForm.st.focus(); 
		return;				
	} else if(document.theForm.zip.value.length < 5) {
		alert("Please enter a valid zip.");
		document.theForm.zip.focus();
		return;				 
	} else if(document.theForm.phone1.value.length < 1) {
		alert("Please enter a phone number.");
		document.theForm.phone1.focus();
		return;
	} else if(document.theForm.vehyear.value.length < 1) {
		alert("Please select vehicle year.");
		document.theForm.vehyear.focus();
		return;	
	} else if(document.theForm.vehmake.value.length < 1) {
		alert("Please select vehicle make.");
		document.theForm.vehmake.focus();
		return;	
	} else if(document.theForm.vehmodel.value.length < 1) {
		alert("Please enter vehicle model.");
		document.theForm.vehmodel.focus();
		return;				
	} else if(document.theForm.affgrp.value.length < 1) {
		alert("Please select program.");
		document.theForm.affgrp.focus();
		return;							
	}
	if(! choseveh) {
		alert("Please select a vehicle category.");
		return;
	}	
	document.theForm.submit();
}
 



function dcx_participants_upload()
{
 document.dcxIncentiveUploadForm.submit(); 	
// var qStr = 'action=dcx_participants_upload';	
// postDataReturnText('ajax_dcx_incentive.php',qStr,ajaxDisplayDcxIncentive);	
}
 
    
function dcx_contracts_upload()
{   
 document.dcxIncentiveContractUploadForm.submit(); 	
// var qStr = 'action=dcx_participants_upload';	  
// postDataReturnText('ajax_dcx_incentive.php',qStr,ajaxDisplayDcxIncentive)  ;	
}


function ajaxDisplayDcxIncentive(data)
{
 alert (data);	
}