﻿// JScript File
<!--

var word = /(\bBITCH\b|\bFUCK|\bCUNT\b|\bASSHOLE\b|\bPOES\b|\bSHIT\b|\bDICK HEAD\b|\bDICKHEAD\b|\bPUSSY\b|\bWHORE\b|\bFAGGAT\b)/;

function CheckNumVehicles(max)
{
    var msg = "";
    var num = 0;
    
    num = document.getElementById("txtVehCount").value;
    if (num >= max)
      msg += "- Maximum number of " + max + " vehicles are allowed.\n";
      
    return msg;
}


function CheckStep1(objName,objSName,objTitle,objGender,objAreaCode,objContactNo,objCellNo,objEmail,objDD,objMM,objYY,objSuburb,trHide,trHide2,trShow)
{
	var msg = "";
	  
    msg += CheckNameString(objName, "first name", true);
    msg += CheckNameString(objSName, "surname", true);
    msg += CheckTitleGender(objTitle,objGender);
	msg += CheckFullContactNo(objContactNo, false);
    msg += CheckCellNo(objCellNo, false);
    msg += IsOneContactNumber(objAreaCode, objContactNo, objCellNo);
    msg += CheckEmail(objEmail, word, true);
    msg += CheckDOB(objDD, objMM, objYY, true);
    msg += CheckSuburb(objSuburb, true);
	  
    if (msg == "") {
		applyDisplay(trHide, "none");
		applyDisplay(trHide2, "none");
		applyDisplay(trShow, "");
    } else {
	    alert("The following errors were encountered.\n\n" + msg);
    }
    
    return false;

}

function QuoteSubmit(objName,objSName,objTitle,objGender,objAreaCode,objContactNo,objCellNo,objEmail,objDD,objMM,objYY,objSuburb,objCarDes,objHome
                    ,objBuild,objUnspecified,objSpecified,objSpectacles,objCells,objBicycles,objEquipment
                    ,cbCar,cbBike,cbCaravan,cbTrailer,cbHome,cbBuild,cbPortable,btnID,btnUID) 
{
    var btn = document.getElementById(btnID);
	var msg = "";
	  
	msg += CheckNameString(objName, "first name", true);
	msg += CheckNameString(objSName, "surname", true);
	msg += CheckTitleGender(objTitle,objGender);
	msg += CheckFullContactNo(objContactNo, false);
	msg += CheckCellNo(objCellNo, false);
	msg += IsOneContactNumberFull(objContactNo, objCellNo);
	msg += CheckEmail(objEmail, word, true);
	msg += CheckDOB(objDD, objMM, objYY, true);
	msg += CheckSuburb(objSuburb, true);
	
	if (cbHome.checked)
		msg += CheckHomeContents(objHome, false);
	
	if (cbBuild.checked)
		msg += CheckBuilding(objBuild, false);
		
	if (cbPortable.checked)		
		msg += CheckPortable(objUnspecified, objSpecified, objSpectacles, objCells, objBicycles, objEquipment, false);
	  
	var numVeh = 0;
	var numCar = 0;
	var numBike = 0;
	var numCaravan = 0;
	var numTrailer = 0;

	if (cbCar.checked)	
		numCar = document.getElementById("txtCarCount").value;
	
	if (numBike.checked)	
		numBike = document.getElementById("txtBikeCount").value;
	
	if (numCaravan.checked)	
		numCaravan = document.getElementById("txtCaravanCount").value;
	
	if (numTrailer.checked)	
		numTrailer = document.getElementById("txtTrailerCount").value;
		
	numVeh = numCar + numBike + numCaravan + numTrailer;

    if ((numVeh == 0) && ((objHome.value == "") || (objHome.value == "0")) && ((objBuild.value == "") || (objBuild.value == "0")))
    {
		if (objCarDes.selectedIndex > 0)
			msg += '- Please press the "submit" button to add your car to the quote.\n';
		else
			msg += "- Car, motorbike, caravan, trailer, building or home contents cover need to be selected.\n";
	}
    else
    {
        if ((numCar == 0) && ((objHome.value == "") || (objHome.value == "0")))
        {
          var unspecified = objUnspecified.value;
          var specified = objSpecified.value;
          var spectacles = objSpectacles.value;
          var cells = objCells.value;
          var bicycles = objBicycles.value;
          var equipment = objEquipment.value;
          
          if ( 
               !(((unspecified == "") || (unspecified == "0")) && ((specified == "") || (specified == "0")) && ((spectacles == "") || (spectacles == "0"))
               && ((cells == "") || (cells == "0")) && ((bicycles == "") || (bicycles == "0")) && ((equipment == "") || (equipment == "0")))
             )
          {
				if (objCarDes.selectedIndex > 0)
					msg += '- Please press the "submit" button to add your car to the quote.\n';
				else
					msg += "- Portable possessions cover is only available with car or home contents cover.\n";
	      }  
        }
    }
    
	if (msg == "") {
	    if ((objCarDes.selectedIndex <= 0) ||
	        (objCarDes.selectedIndex > 0 && confirm("Would you like to continue without adding the car you have selected?")))
	    {
			return true;
		}
	    else
	    {
			return false;
	    }
	} else {	
		alert("The following errors were encountered.\n\n" + msg);
		return false;
	}
}

function CheckCar(objVehYY, objVehDes, objDr, objDrName, objDrSName, objTitle, objGender, objDrDD, objDrMM, objDrYY, maxVeh, trLic, objLic, objLicYY, objLicMM, objMainYY) 
{
    var msg = "";

    msg += CheckNumVehicles(maxVeh);
    msg += CheckCarDropDown(objVehYY, objVehDes);
    msg += CheckCarDriver(objDr, objDrName, objDrSName, objTitle, objGender, objDrDD, objDrMM, objDrYY, trLic, objLic, objLicYY, objLicMM, objMainYY);
    
		if (msg == "") {
			return true;
		} else {
			alert("The following errors were encountered.\n\n" + msg);
			return false;
		}
}

function CheckCarDriver(objDr, objDrName, objDrSName, objTitle, objGender, objDrDD, objDrMM, objDrYY, trLic, objLic, objLicYY, objLicMM, objMainYY)
{
  var drSeq = objDr.selectedIndex;
  var msg = "";
  
  if (drSeq == objDr.length - 1)
  {
    msg += CheckNameString(objDrName, "driver's first name", true);
    msg += CheckNameString(objDrSName, "driver's surname", true);
    msg += CheckTitleGender(objTitle,objGender);
    msg += CheckDOB(objDrDD, objDrMM, objDrYY, true);
    msg += CheckDriverLicence(objLic, objLicYY, objLicMM, objDrYY.value);
  }
  else if (drSeq == 0 && trLic.style.display != 'none')
  {
    msg += CheckDriverLicence(objLic, objLicYY, objLicMM, objMainYY.value);
  }
  
  return msg;
}

function CheckMotorbike(objVehYY, objVehMake, objVehDes, objVal, objMin, objMax, maxVeh, minReg) 
{
    var msg = "";

    msg += CheckNumVehicles(maxVeh);
    msg += CheckMotorbikeDropDown(objVehYY, objVehMake, objVehDes, minReg);
    msg += CheckMotorbikeDetails(objVal, objMin, objMax);
    
		if (msg == "") {
			return true;
		} else {
			alert("The following errors were encountered.\n\n" + msg);
			return false;
		}
}

function CheckCaravan(objVehYY, objVehDes, objVal, objContVal, objMin, objMax, objContMin, objContMax, maxVeh, minReg) 
{
    var msg = "";

    msg += CheckNumVehicles(maxVeh);
    msg += CheckCaravanDropDown(objVehYY, objVehDes, minReg);
    msg += CheckCaravanDetails(objVal, objContVal, objMin, objMax, objContMin, objContMax);
    
		if (msg == "") {
			return true;
		} else {
			alert("The following errors were encountered.\n\n" + msg);
			return false;
		}
}

function CheckTrailer(objVehYY, objVehDes, objVal, objMin, objMax, maxVeh, minReg) 
{
    var msg = "";

    msg += CheckNumVehicles(maxVeh);
    msg += CheckTrailerDropDown(objVehYY, objVehDes, minReg);
    msg += CheckTrailerDetails(objVal, objMin, objMax);
    
		if (msg == "") {
			return true;
		} else {
			alert("The following errors were encountered.\n\n" + msg);
			return false;
		}
}

function SuburbSubmit(objSub) 
{
    var msg = "";
    var sub = objSub.value;

    //Trim all data
    sub = sub.replace(/^\s+|\s+$/,''); 
					
    if (sub==""){
      msg += "- Please enter suburb.\n";
    }
    if (sub.length < 3){
      msg += "- Please enter three or more characters for the suburb.\n";
    }						

		if (msg == "") {
			return true;
		} else {
			alert("The following errors were encountered.\n\n" + msg);
			return false;
		}
}

function SuburbCodeSubmit(objSub) 
{
    var msg = "";
    var sub = objSub.value;

    //Trim all data
    sub = sub.replace(/^\s+|\s+$/,''); 
					
    if (sub==""){
      msg += "- Please enter the postal code.\n";
    }
    if (!sub.match(/^\d{4}$/)){
      msg += "- Please enter a valid 4 digit postal code.\n";
    }						

		if (msg == "") {
			return true;
		} else {
			alert("The following errors were encountered.\n\n" + msg);
			return false;
		}
}

//-->
