function checkdeletevehiclefromconfirmation(vehid){
//document.write(lead);
vehid=vehid;
var chkalert=confirm('Are You sure You want to delete this Vehicle'); 	
if (chkalert==true)
window.location="auto-confirmation.php?deleteVehicleUID="+vehid;

}

function validateEmail(form_id, email) {
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = document.forms[form_id].elements[email].value;

   if(address == null || address == "")
     return true;

   if(reg.test(address) == false) {
   	return false;
   }
   return true;
}

function checkdeletedriverfromconfirmation(drvid){
var chkalert=confirm('Are You sure You want to delete this Driver'); 	
if (chkalert==true)
window.location="auto-confirmation.php?deleteDriverUID="+drvid;

}	


function checkdeletevehicle(vehid,origfrom){
//document.write(lead);
vehid=vehid;
originatedfrom=origfrom;
var chkalert=confirm('Are You sure You want to delete this Vehicle'); 	
if (chkalert==true)
window.location="process_vehicle-form.php?deleteVehicleUID="+vehid+"&originatedfrom="+originatedfrom;

}
function checkdeletedriver(drvid,origfrom){
//document.write(lead);
originatedfrom=origfrom;
var chkalert=confirm('Are You sure You want to delete this Driver'); 	
if (chkalert==true)
window.location="process_auto-sample.php?deleteDriverUID="+drvid+"&originatedfrom="+originatedfrom;

}	

function checkdeletevehiclefromprocess(vehid){
//document.write(lead);
vehid=vehid;
var chkalert=confirm('Are You sure You want to delete this Vehicle'); 	
if (chkalert==true)
window.location="process_vehicle-form.php?deleteVehicleUID="+vehid;

}

function checkdeletedriverfromprocess(drvid){
var chkalert=confirm('Are You sure You want to delete this Driver'); 	
if (chkalert==true)
window.location="process_auto-sample.php?deleteDriverUID="+drvid;

}	

function formvalidation(reqfields,fname){
 emptyfields =""; 
 alertmsg = "\n\nPlease fill in all required feilds"; 

 for (var i=0; i<reqfields.length; i++) {
	var elementName = reqfields[i];
	var element = document.getElementById(elementName);
//alert (element.value);
//alert (document.getElementById(elementName));
//alert(element.value);
	if (element.value == "") 
	{
	emptyfields += "\n - "+elementName; 
	
	}//end if
 }//end for

	if(emptyfields != "")
	{
	alert (alertmsg+emptyfields);
	return false; 
	}
else 
fname.submit();
//return true; 

}// end formvalidation

function formvalidationhomeowners(reqfields,fname){
 emptyfields =""; 
 alertmsg = "\n\nPlease fill in all required feilds\n"; 

 for (var i=0; i<reqfields.length; i++) {
	var elementName = reqfields[i];
	var element = document.getElementById(elementName);

//alert (element.value);
//alert (document.getElementById(elementName));
//alert(element.value);

	if (element.value == "") 
	{	
	
		//element.style.borderColor = 'red';
	    //element.style.borderWidth = '2';
		element.style.background ='#cdd194';
	
	
		
		if(elementName=='Name0'){ en='First Name' }
		if(elementName=='Last'){  en='Last Name' }
		if(elementName=='DOBm'){  en='Date of Birth(Month)' }
		if(elementName=='DOBd'){  en='Date of Birth(Day)' }
		if(elementName=='DOBy'){  en='Date of Birth(Year)' }
		if(elementName=='Address'){  en='Property Address' }
		if(elementName=='City'){  en='City' }
		if(elementName=='State'){  en='State' }
		if(elementName=='email0'){  en='Email' }
		if(elementName=='Daytime_Phone'){  en='Day Time Phone' }
		if(elementName=='ContactMethod'){  en='Sed Quotes Via' }
		if(elementName=='type'){  en='Type of Property' }
		if(elementName=='construction'){  en='Construction of Home' }
		if(elementName=='style'){  en='Style of Home' }
		if(elementName=='stories'){  en='Number of Stories' }
		if(elementName=='yrbuilt'){  en='Year Home Built' }
		if(elementName=='heat'){  en='Type of Heating' }
		if(elementName=='elecamps'){  en='Electrical System' }
		if(elementName=='garage'){  en='Garage Type' }
		if(elementName=='cars'){  en='Number of cars Garage Hold' }
		if(elementName=='replcost'){  en='Purchase Price of Home' }
		if(elementName=='mortgage'){  en='Mortgage Amount' }
		if(elementName=='dwelling'){  en='Dwelling Amount' }
		if(elementName=='contents'){  en='Personal Property Cov.' }
		if(elementName=='schedjewel'){  en='Jewelry' }
		if(elementName=='schedfurs'){  en='Furs' }
		if(elementName=='schedsilver'){  en='Silver' }
		if(elementName=='schedjewel1'){  en='Other' }
		if(elementName=='comments'){  en='Comments' }
		

emptyfields += "\n - "+en; 
	
	}//end if
 }//end for

	if(emptyfields != "")
	{
	alert (alertmsg+emptyfields);
	
	return false; 
	}
else 
fname.submit();
//return true; 

}// end formvalidation




// generates index by stripping everything from the id up to the last _
function popupCalendarGenIndex(fieldPrefix, calImage, allEnabled) {
  var index = calImage.id.substring(calImage.id.lastIndexOf('_')+1);
  var fieldId = fieldPrefix + index;
  var calImageId =calImage.id.substring(0, calImage.id.lastIndexOf('_')+1) + index;
  popupCalendarGeneric(fieldId, calImageId, allEnabled);
}

// popup calendar with all dates until today disabled
function popupCalendar(fieldId, calImageId) {
  popupCalendarGeneric(fieldId, calImageId, false);
}

// popup calendar with all dates enabled
function popupCalendarAllEnabled(fieldId, calImageId) {
  popupCalendarGeneric(fieldId, calImageId, true);
}

// popup calendar using a flaoting div tag and navigation dropdowns for months and years enabled
function popupCalendarGeneric(fieldId, calImageId, allEnabled) {
  var calPop = new CalendarPopup('calDiv');
  calPop.showNavigationDropdowns();
  if (!allEnabled) calPop.addDisabledDates(null,formatDate(new Date(),'yyyy-MM-dd'));
  calPop.select(document.getElementById(fieldId),calImageId,'MM/dd/yyyy');
  return false;
}

// hide current step and go to the next step
function goToNextStep (thisStep, nextStep) {
  thisStep = document.getElementById(thisStep);
  nextStep = document.getElementById(nextStep);
  thisStep.style.display = "none";
  nextStep.style.display = "inline";
  window.scrollTo(800,800);
}

// check for empty or null fields in reqdFields array in myForm
function validate(reqdFields, myForm) {
  var isOk = true;
  for (var i=0; i<reqdFields.length; i++) {
    var elementName = reqdFields[i];
    var element = document.getElementById(elementName);

if(element != null) {
    if (element.type.indexOf('radio')!=-1) {
      var element0 = element;
      var element1 = document.getElementById(elementName.substring(0, elementName.length-1)+'1');
      elementName = elementName.substring(0, elementName.length-2);

      if (!element0.checked && !element1.checked) {
        highlightEnclosed(elementName, true);
        isOk = false;
      } else {
        highlightEnclosed(elementName, false);
      }
    } else { // non-radios
      if (element.value.replace(/^\s*|\s*$/g,'')==null || element.value.replace(/^\s*|\s*$/g,'')=="") {
        if (element.type.indexOf('select')!=-1) {
          highlightEnclosed(elementName, true);
        } else {
          highlightSimple(element, true);
        }
        isOk = false;
      } else {
        if (element.type.indexOf('select')!=-1) {
          highlightEnclosed(elementName, false);
        } else {
          highlightSimple(element, false);
        }
      }
    }
  }
}
  if (!isOk) {
    alert("Please provide the required information");
  } else {
    myForm.submit();
  }
}

// highlight/unhighlight simple form fields
function highlightSimple(element, highlight) {
  if (highlight) {
    element.style.borderColor = 'red';
    element.style.borderWidth = '2';
  } else {
    element.style.borderTopWidth = '2';
    element.style.borderColor = 'silver';
    element.style.borderBottomWidth = '1';
    element.style.borderRightWidth = '1';
  }
}

// highlight/unhighlight complex form fields enclosed in td tags
function highlightEnclosed(enclosedElementName, highlight) {
  var tdElement = document.getElementById(enclosedElementName + '_td');
  if (highlight) {
     tdElement.style.borderColor = 'red';
     tdElement.style.borderWidth = '2';
  } else {
     tdElement.style.borderColor = 'white';
     tdElement.style.borderWidth = '0';
  }
}
