	
// CURRENT DAY AND DATE
// Appears in the main-bottom.php

var mydate=new Date()
var theYear=mydate.getFullYear()
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()

if (daym<10)
	daym="0"+daym
	var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
	var montharray=new Array("01","02","03","04","05","06","07","08","09","10","11","12")
	// CURRENT DAY AND DATE
	
// MAIL URL TO A FRIEND
	// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
	<!-- Begin
		function mailsome1()
			{
				who=prompt("Enter recipient's email address: ","email@cubicinteractive.com");
				what=prompt("Enter the subject: ","Try out this Car Find Wesbite");
				if (confirm("Are you sure you want to mail "+who+" with the subject of "+what+"?")==true)
					{
					parent.location.href='mailto:'+who+'?subject='+what+'';
					}
			}
	// End -->
// MAIL URL TO A FRIEND	


//PAGE LOAD SPEED
	// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
	loadtime="0"
	loading=true
	s="s"
	{refresh()}
	function refresh()
	{setTimeout("count()",250)}
	function count()
	{if (loading)
	{loadtime=loadtime+++0.25;refresh()}}
	function done()
	{if (loadtime==1)
	{s=""}
	alert("It took "+loadtime+" second"+s+" to load the page");loading=false}
//PAGE LOAD SPEED


var contactCount = -1;
var isContactSelected = false;

var driversCount = -1;
var isDriversSelected = false;

var tradeInCount = -1;
var isTradeInSelected = false;

var depositeCount = -1;
var isDepositeSelected = false;

var financeCount = -1;
var isFinanceSelected = false;


var financeTypeCount = -1;
var isFinanceTypeSelected = false;
// FORM VALIDATION
function validate(obj)
{

	//define objects to validate
	var allElements = obj.elements;
	var coCount = 0;
	var errors = "";

	for( i=0 ; i<allElements.length; i++)
	{

		//CHECK FIRSTNAME NOT EMPTY
		if (allElements[i].type=="text" && allElements[i].name == "fullname")
		{
			var oFullName = allElements[i].value;
			if ( oFullName.length <= 0 )
			{
				errors += "-> Name is a Mandatory field\n";
			}			
			
		
		}
		
		//CHECK SURNAME NOT EMPTY
		if (allElements[i].type=="text" && allElements[i].name == "surname")
		{
			var oFullName = allElements[i].value;
			if ( oFullName.length <= 0 )
			{
				errors += "-> Surname is a Mandatory field\n";
			}			
		}		

		//CHECK FIRSTNAME NOT EMPTY AND CHECK VALIDATION RULES
		if (allElements[i].type=="text" && allElements[i].name == "firstname")
		{
			var oFullName = allElements[i].value;
			if ( oFullName.length <= 0 )
			{
				errors += "-> Name is a Mandatory  field\n";
			}
			else
			{			
			
			 var specialChars = "!@#$%^&*()+=[]\\\;,./{}|\":<>?";     
       var specialCharFlag = false;
			 var hasNumeric = true;
		
	   var noalpha = /^[a-zA-Z!@#$%^&*()\s-+=\[\]\;,./{}|":<>?]*$/;
       if (noalpha.test(oFullName)) {
        hasNumeric = false;
        }
         


			 for (var j = 0; j < oFullName.length; j++) 
			 {
			   
   			 	 if (specialChars.indexOf(oFullName.charAt(j)) != -1) 
              specialCharFlag = true;
         
				
       }
       
			if(hasNumeric)
                errors += "-> The Name should not contain numeric values \n";

			
           if(specialCharFlag)
            errors += "-> The Name field contains special characters \"!@#$%^&*()+=[]\\\;,./{}|\":<>?\" which are not allowed  \n";
         
			 	 if (oFullName.indexOf('\'') == 0  || oFullName.indexOf('-') == 0 ) 
           errors += "-> The 1st letter of the Name field contain a \"'\"  or a \"-\"  which is not allowed \n";
	     }
		}
		
		//CHECK SURNAME NOT EMPTY AND CHECK VALIDATION RULES
		if (allElements[i].type=="text" && allElements[i].name == "lastname")
		{
			var oSurName = allElements[i].value;
			if ( oSurName.length <= 0 )
			{
				errors += "-> Surname is a Mandatory field\n";
			}			
			else
            {
			var oSurName = allElements[i].value;
			var specialChars = "!@#$%^&*()+=[]\\\;,./{}|\":<>?";     
      var specialCharFlag = false;
			var vowelChars = "AEIOU";
			var vowelFlag = true;
	   var consonantChars = "BCDFGHJKLMNPQRSTVWXYZ";
	   var hasNumeric = true;
        
	   var noalpha = /^[a-zA-Z!@#$%^&*()\s-+=\[\]\;,./{}|":<>?]*$/;
       if (noalpha.test(oSurName)) {
        hasNumeric = false;
        }



		  var j = 0;
			 
			 for ( j = 0; j <oSurName.length; j++) 
			 {
   			 	 if (specialChars.indexOf(oSurName.charAt(j)) != -1) 
              specialCharFlag = true;
							
					 if(vowelChars.indexOf(oSurName.charAt(j)) == -1)
					   vowelFlag = false;
					  		

       }
		 if(hasNumeric)
            errors += "-> The Surname should not contain numeric values \n";
		

		 if(specialCharFlag)
            errors += "-> The Surname field contains special characters \"!@#$%^&*()+=[]\\\;,./{}|\":<>?\" which are not allowed  \n";

         if(vowelFlag)
            errors += "-> The Surname field should contain atleast one vowel \n";
			  
						
       if(oSurName.length >= 3)
			 {   
			 
		     if(vowelChars.indexOf(oSurName.toUpperCase().charAt(0)) != -1 &&
				    vowelChars.indexOf(oSurName.toUpperCase().charAt(1)) != -1   &&
						 vowelChars.indexOf(oSurName.toUpperCase().charAt(2)) != -1) 
               errors += "-> The first 3 letters of Surname field may not contain 3 consecutive vowels \n";
		   }
			
			
			if(oSurName.length >= 5)
			{
		    if(consonantChars.indexOf(oSurName.toUpperCase().charAt(0)) != -1  
				 && consonantChars.indexOf(oSurName.toUpperCase().charAt(1)) != -1 && consonantChars.indexOf(oSurName.toUpperCase().charAt(2)) != -1
				&& consonantChars.indexOf(oSurName.toUpperCase().charAt(3)) != -1 && consonantChars.indexOf(oSurName.toUpperCase().charAt(4)) != -1)		 
            errors += "-> The first 5 letters of Surname field may not contain 5 consecutive consonants \n";
	     }
					
			 	 if (oSurName.indexOf("'") == 0  || oSurName.indexOf("-") == 0 ) 
           errors += "-> The 1st letter of the Surname field contain a  or a which is not allowed \n";

     	  } 
		}	
		
		
		//CHECK QUERY DROPDOWN TITLE LIST
		if (allElements[i].name == "CLIENTREGION")
		{   
	
			var otitle = allElements[i].value;
			if  (allElements[i].selectedIndex == 0) {errors += "-> Your Region is a Mandatory field\n";}
		}
		
		//CHECK PHONE NUMBER VALID		
		if (allElements[i].type=="text" && allElements[i].name == "telnumber") 
		{
			var oContCou = allElements[i].value;	
			if (oContCou.length <= 0)
			{
				errors += "-> Contact Number is a Mandatory field\n";
			}		
		}			
		
				
		//CHECK POSTAL NOT EMPTY
		if (allElements[i].type=="textarea" && allElements[i].name == "postal")
		{
			var oFullName = allElements[i].value;
			if ( oFullName.length <= 0 ) {errors += "-> Postal Address is a Mandatory field\n";}			
		}

		//CHECK CARDHOLDERSNAME NOT EMPTY
		if (allElements[i].type=="text" && allElements[i].name == "cardholdersname")
		{
			var oFullName = allElements[i].value;
			if ( oFullName.length <= 0 ) {errors += "-> Card Holders Name is a Mandatory field\n";}			
		}
		
		//CHECK DIALING CODE IS NOT NULL OR IS NUMERIC
		if (allElements[i].type=="text" && allElements[i].name == "contact-area1") 
		{
			var oSwitchCou = allElements[i].value;	
			if (oSwitchCou.length <= 0) {errors += "-> Dialing Code is a mandatory field\n";}
			else if (isNaN(oSwitchCou)) {errors += "-> Dialing Code should be numeric\n";}
		}

		//CHECK DIALING CODE IS NOT NULL OR IS NUMERIC
		if (allElements[i].type=="text" && allElements[i].name == "contact-number") 
		{
			var oSwitchCou = allElements[i].value;	
			//if (oSwitchCou.length <= 0) {errors += "-> Tel. Number is a mandatory field\n";}
			if (isNaN(oSwitchCou)) {errors += "-> Tel. Number should be numeric\n";}
		}
		
		//CHECK QUERY DROPDOWN TITLE LIST
		if (allElements[i].name == "dialcodedrop")
		{
			var otitle = allElements[i].value;
			if  (otitle == '') {errors += "-> Tel. Dial Code is a Mandatory field\n";}
		}

		//CHECK DIALING CODE IS NOT NULL OR IS NUMERIC
		if (allElements[i].type=="text" && allElements[i].name == "dialcode") 
		{
			var oSwitchCou = allElements[i].value;	
			if (oSwitchCou.length <= 0) {errors += "-> Tel. Dialing Code is a mandatory field\n";}
			else if (isNaN(oSwitchCou)) {errors += "-> Tel. Dialing Code should be numeric\n";}
		}


		//CHECKBOX CHECK
		if (obj.name=='searchresults')
		{
		
				//CHECKBOX CHECK
				var checkcount = 0;
				for (var i=0;i<document.searchresults.elements.length;i++)
				{
				
					if ((allElements[i].type=="checkbox") && (allElements[i].name == "P_KEY[]") && (allElements[i].checked == true))
					{
						checkcount = 1;
						return;
					}
					else if ((allElements[i].type=="checkbox") && (allElements[i].name == "MEAD_CODE[]") && (allElements[i].checked == true))
					{
						checkcount = 1;
						return;
					}
					else if ((allElements[i].type=="checkbox") && (allElements[i].name == "carNotFound") && (allElements[i].checked == true))
                    {
                    	checkcount = 1;
						return;
                    }
				}
		
				if (checkcount == 0)
				{
					alert('Check at least one vehicle, select a checkbox\n');
					return false;
				}
		}
		

    var idyear="";
    var idmonth ="";
    var idday =""
    var idIsValid = true;
;
		//CHECK IDNUMBER		
	if (allElements[i].name == "idnumber")
	{
		var oIDNUMBER = allElements[i].value;
		if (oIDNUMBER!="")
		{

			if (!IsNumeric(oIDNUMBER))
				{
         	errors += "-> Your ID Number can only have numeric values\n";
					//alert ("Your ID Number can only have alpha numeric");
					//return false;
				}
			else
				{
	
					if (oIDNUMBER.length<13)
						{ 
             	errors += "-> Your ID Number is too short\n";
							//alert("Your ID Number is too short");
							//return false;
						}
					else
						{
                     
					//FULL CHECK
		    		var IDText = oIDNUMBER;
		            var IDOddCounter  = 0;
                    var IDEvenCounter = 0;
                    var IDTotalCounter = 0;
                    var IDTemp=0;			
					var sTotalCounter = '';
					var sTemp=' ';

            //1   2   3   4   5   6   7   8   9   10  11  12  13
            //5   7   1   0   3   0   0   0   2   0   0   8   7
						//5710300020087

						//alert (oIDNUMBER);
            for (k = 0; k < IDText.length; k++)
            {
            sTemp = IDText.substring(k, k+1);
			    if ((k % 2) == 0)
                {
                    if (k < 12)
                    {
											IDOddCounter += parseInt(sTemp);
											//alert('k '+k+', Odd Counter '+IDOddCounter+' length '+sTemp.length);
                    }
                }
               else
                {
									//alert('Ha '+IDText.substring(0,13));
									IDTemp = parseInt(sTemp) * 2;
									sTemp = IDTemp.toString();
									// alert(sTemp+' '+sTemp.length);
									// sTemp=IDTemp;
									// alert('sTemp '+sTemp);
									//alert('k : '+k+' sTemp : '+sTemp+' length : '+sTemp.length);
									
	                for (j = 0; j < sTemp.length; j++)
                    {
                        IDEvenCounter += parseInt(sTemp.substring(j, j+1));
                    }
                }
            }

						//alert('IDEvenCounter' + IDEvenCounter);
						//alert('IDOddCounter' + IDOddCounter);

            IDTotalCounter = IDEvenCounter + IDOddCounter;
						//alert('IDTotalCounter' + IDTotalCounter);
						sTotalCounter = IDTotalCounter.toString();
            //alert((10 - parseInt(sTotalCounter.substring(1, 2))));
            //alert((IDText.substring(IDText.length - 1, IDText.length)));
            
            if ((10 - parseInt(sTotalCounter.substring(1, 2))) == (parseInt(IDText.substring(IDText.length - 1, IDText.length)))
						|| ((10 - parseInt(sTotalCounter.substring(1, 2))) == (parseInt("10"))&&(IDText.substring(IDText.length - 1, IDText.length)=="0")))
            {           
                      
                       
                        idyear= IDText.substring(0,2);
                        idmonth = IDText.substring(2,4);
                        idday = IDText.substring(4,6);
                        var cboyear = "";
                        var cbomonth = "";
                        var cboday = "";

                        cboyear = document.getElementById("BIRTHYEAR").value.substring(2,4);
                        if(document.getElementById("BIRTHMONTH").selectedIndex < 10)
                        {
                         cbomonth = "0"+document.getElementById("BIRTHMONTH").selectedIndex.toString();
                        }
                       else
                       {
                         cbomonth = document.getElementById("BIRTHMONTH").selectedIndex.toString();
                       }
                      
                        cboday = document.getElementById("BIRTHDAY").value;
                        
                        if(cboyear != "" && cbomonth!="" && cboday!="")
                        {
                           if(cboyear != idyear)
                            errors += "-> Your Date Of Birth Year does not correspond to your ID Number\n";

                         if(cbomonth != idmonth)
                            errors += "-> Your Date Of Birth Month does not correspond to your ID Number\n";
  
                        if(cboday != idday)
                            errors += "-> Your Date Of Birth Day does not correspond to your ID Number\n";

                        	
                       }
                 
					
             } 
            else
			{
                   errors += "-> Your ID Number is not valid\n";
 			}
		 }

          
	  }

                   //errors += "-> Your ID Number is not valid\n";
		     		//FULL CHECK
       
	}

  }
		
        var cboyear = "";
        var cbomonth = ""; 
        var cboday = "";
  

		//CHECK QUERY DROPDOWN TITLE LIST
		if (allElements[i].name == "BIRTHYEAR")
		{
			var otitle = allElements[i].value;
			if  (allElements[i].selectedIndex == 0) {errors += "-> Birth date year is a Mandatory field\n";}
            else
            { 
            cboyear = otitle.substring(2,4);

            if(idyear != "") 
            {
              if(cboyear != idyear)
                errors += "-> Your Date Of Birth Year does not correspond to your ID Number\n";
            }
          }
		}
		
		//CHECK QUERY DROPDOWN TITLE LIST
		if (allElements[i].name == "BIRTHMONTH")
		{
			var otitle = allElements[i].value;
			if  (allElements[i].selectedIndex == 0) {errors += "-> Birth date month is a Mandatory field\n";}
            else
            {
              if(allElements[i].selectedIndex < 10)
              {
               cbomonth = "0"+allElements[i].selectedIndex.toString();
              }
              else
              {
               cbomonth = allElements[i].selectedIndex.toString();

               if(idmonth != "") 
               {
                if(cbomonth != idmonth)
                  errors += "-> Your Date Of Birth Month does not correspond to your ID Number\n";
               }

              }

            }
		}
		
		//CHECK QUERY DROPDOWN TITLE LIST
		if (allElements[i].name == "BIRTHDAY")
		{
			var otitle = allElements[i].value;
			if  (allElements[i].selectedIndex == 0) {errors += "-> Birth date day is a Mandatory field\n";}
           else
            {
             cboday = otitle;

            if(idday != "") 
            {
              if(cboday != idday)
                errors += "-> Your Date Of Birth Day does not correspond to your ID Number\n";
            }

            }
		}
		
        /*
		//CHECK QUERY DROPDOWN TITLE LIST
		if (allElements[i].name == "query")
		{
			var otitle = allElements[i].value;
			if  (allElements[i].selectedIndex == 0) {errors += "-> Query is a Mandatory field\n";}
		}
        */
		
   		//CHECK CONTACT METHOD DROPDOWN TITLE LIST
		if (allElements[i].name == "CONTACTMETHOD")
		{   
            contactCount=contactCount+1;
            var oContactMethod = allElements[i];

            if(oContactMethod.checked)
              {
                 isContactSelected = true;

              }

             if(!isContactSelected && contactCount == 1) 
             {           
              errors += "-> Contact method is a Mandatory field\n";     
              contactCount=-1;
              isContactSelected = false;
             }
           
		}
			var contactCheck = false;
				
      if(allElements[i].name == "CONTACTMETHOD")
      {
        if(allElements[i].value == 'Telephonically' && allElements[i].checked)
		{
        contactCheck =true;
		//CHECK TELEPHONE NUMBER IS VALID
     	    var oSwitchCou = document.getElementById("contactnumber").value;
			//if (oSwitchCou.length <= 0) {errors += "-> Tel. Number is a mandatory field\n"; }

       //CHECK DIALING CODE IS NOT NULL OR IS NUMERIC
            var oSwitchCou = document.getElementById("MOBILENUMBER").value;
     		//if (oSwitchCou.length <= 0) {errors += "-> Mobile number is a mandatory field\n";}

      }
      else if(allElements[i].value == 'Email' && allElements[i].checked)
      {
		//CHECK EMAIL ADDRESS NOT EMPTY AND VALID
			var oEmail = document.getElementById("email").value;
			var chkDot = true;
			var result = false;
			var ndxAt = ndxDot =  0;
			var ndxAt = ndxDot =  0;
 
     			if (oEmail.length <= 0 )
     			{
				errors += "-> E-mail Address is a Mandatory field\n";
    			}

      }

		}

		if (allElements[i].name == "MOBILENUMBER" && allElements[i].value != "")
				{
					var oSwitchCou = allElements[i].value;
						if (isNaN(oSwitchCou)) {errors += "-> The Mobile number should be numeric\n";}
						else if(oSwitchCou.length != 10 )
							{
								errors += "-> The Mobile number should be 10 digits long \n";
							}
						else
							{ 
								if((oSwitchCou.indexOf('8') != 1 && oSwitchCou.indexOf('7') != 1) || oSwitchCou.indexOf('0') !=0 )
									{
										errors += "-> The Mobile number should start with \"07\" or \"08\"  \n";
									}
							}
				}

	     	if (allElements[i].type=="text" && allElements[i].name == "contactnumber" && allElements[i].value !="") 
	    	{
			var oSwitchCou = allElements[i].value;	
            if (isNaN(oSwitchCou)) {errors += "-> Tel. Number should be numeric\n";}
			else if(oSwitchCou.length != 7)
			{errors += "-> Tel. Number field should be 7 digits long\n";}
            else
            {
						    var codeVal = document.getElementById('dialcodedrop').value;
							 if(codeVal == '012')
							 {
							          regExString =  "[2-9][0-9][0-9]";

		                     var re = new RegExp(regExString);
  		     
			                   checkDigits = oSwitchCou.substring(0,3);
 	                      	if(checkDigits.match(re))
	                    		 {}
                          else{ errors += "-> Tel. Number is not valid\n";}
							 }
							 else
							 {
               	  var ArrIndex = document.getElementById('dialcodedrop').selectedIndex;
                  var tempCLArray = CLArray[ArrIndex].toString();
  		           	var checkDigits = oSwitchCou.substring(0,3);
		    	       if(tempCLArray.indexOf(checkDigits)>=0)
		    	        {}
                 else{ errors += "-> Tel. Number is not valid\n";}
	 	           }
             }   
             
	    	}

	    	if (allElements[i].type == "text" && allElements[i].name == "email" && allElements[i].value!="")
	    	{
			var oEmail = allElements[i].value;
			var chkDot = true;
			var result = false;
			var ndxAt = ndxDot =  0;
			var ndxAt = ndxDot =  0;

				ndxAt  = oEmail.indexOf("@");
				ndxDot = oEmail.indexOf(".");
				ndxDot2 = oEmail.lastIndexOf(".");
									
					var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
					if (oEmail.match(illegalChars)) {errors += "The E-mail Address contains illegal characters\n";}
					//check for a '.' sign
					else if ((ndxDot < 0)) {errors += "->The E-mail Address lacks '.'\n\tThe format is 'you@domain.com'\n";}
					//check for an '@' sign
					else if ( (ndxAt < 0)) {errors += "->The E-mail Address lacks an '@'\n\tThe format is 'you@domain.com'\n";}
					else if (ndxDot2 - 3 <= ndxAt) {errors += "->You may be missing your domain name\n\tThe format is 'you@domain.com'";}
	    	}



						if (allElements[i].name == "MOBILENUMBER" && allElements[i].value == "")
				{
            var contact = document.getElementById("contactnumber");
						
						if(contact.value=="" && !contactCheck)
						 {
					     errors += "->Either Primary Contact or Cell Number should be filled in\n";	  
				      contactCheck = false;
						}
				}

	     	if (allElements[i].type=="text" && allElements[i].name == "contactnumber" && allElements[i].value==="") 
	    	{
            var contact = document.getElementById("MOBILENUMBER");
						
						if(contact.value=="" && contactCheck)
						 {
					     errors += "->Either Primary Contact or Cell Number should be filled in\n";	  
             contactCheck = false;
						 }
	    	}

   	//CHECK WHETHER DRIVERSLICENCE
		if (allElements[i].name == "DRIVERSLICENSE")
			{   

                driversCount=driversCount+1;
				var oContactMethod = allElements[i];
				
				if(oContactMethod.checked)
					{
						isDriversSelected = true;
					}
				
					if(!isDriversSelected && driversCount == 1) 
						{           	
							errors += "-> Drivers Licence indication is mandatory\n";     
							driversCount=-1;
							isDriversSelected = false;
						}
			}

   	//CHECK WHETHER TRADEINVEHICLE
		if (allElements[i].name == "TRADEINVEHICLE")
			{   
				tradeInCount=tradeInCount+1;
				var oContactMethod = allElements[i];
				
				if(oContactMethod.checked)
					{
						isTradeInSelected = true;
					}
				
				if(!isTradeInSelected && tradeInCount == 1) 
					{           	
						errors += "-> Trade-In indication is mandatory\n";     
						tradeInCount=-1;
						isTradeInSelected = false;
					}			
			}


   	//CHECK WHETHER MAKE IS INPUTED
		if (allElements[i].name == "MAKE01")
			{   
			var oMake01 = allElements[i].value;
			if ( oMake01.length <= 0 )
			{
				errors += "-> Make is a Mandatory field\n";
			}			
				
			}

			 	//CHECK WHETHER MODEL IS INPUTED
			if (allElements[i].name == "MODEL1")
			{   
			var oModel1 = allElements[i].value;
			if ( oModel1.length <= 0 )
			{
				errors += "-> Model is a Mandatory field\n";
			}			
				
			}
			



      if(allElements[i].name == "TRADEINVEHICLE")
				{
        if(allElements[i].value == 'YES' && allElements[i].checked)
					{
			
						var ocomments = document.getElementById("MAKE01");
						//alert(ocomments.options[2].value);
						
						if ( ocomments.selectedIndex == 0 || ocomments.value=="" ) {errors += "-> Make Selection is Mandatory field, please select a make\n";}
						
						var ocomments =  document.getElementById("TRADEINMODEL");
						if (  ocomments.selectedIndex == 0 || ocomments.value=="" ) {errors += "-> Model is Mandatory field, please select a model\n";}
						
						var ocomments = document.getElementById("TRADEINYEAR").value;
						if ( ocomments=='Year' ) {errors += "-> Model Year is a Mandatory field, please select a year\n";}
				
						var ocomments = document.getElementById("TRADEODEMETER").value;
						if ( ocomments!= '' ) {if(isNaN(ocomments))errors += "-> Odometer Reading should be a numeric\n";}

			        }  
                    
			        else if(allElements[i].value == 'NO' && allElements[i].checked)
					{
								
                                var oContactMethod = document.getElementsByName("TRADEDEPOSIT");
		
                                for(j=0;j<oContactMethod.length;j++)
                                { 
                                if(oContactMethod[j].checked)
									{
	                                   isDepositeSelected = true;									
    								}
                                }
                                
                                if(!isDepositeSelected)
                                {
                                 errors += "-> Deposite indication is mandatory\n";
					             isDepositeSelected = false; 
                                }
					}
                    	
				}


    
     /*
   	//CHECK WHETHER TRADEINDEPOSIT
		if (allElements[i].name == "TRADEDEPOSIT")
			{   
	
                var tradeVehicle = document.getElementById("TRADEINVEHICLE");
                alert(tradeVehicle.value);
                alert(tradeVehicle.checked);

                if(tradeVehicle.value == "NO" && tradeVehicle.checked)
                { 
  
  	    		depositeCount=depositeCount+1;
	 			var oContactMethod = allElements[i];
				
				if(oContactMethod.checked)
					{
						isDepositeSelected = true;
					}
				
				if(!isDepositeSelected && depositeCount == 1) 
					{           	
						errors += "-> Deposite indication is mandatory\n";     
						depositeCount=-1;
						isDepositeSelected = false;
					}
                 }			
			}
      */

		if (allElements[i].name == "FINANCEREQ")
			{   
         financeCount=financeCount+1;
         var oContactMethod = allElements[i];

         if(oContactMethod.checked)
           {
							isFinanceSelected = true;
           }

          if(!isFinanceSelected && financeCount == 1) 
						{           	
							errors += "-> Finance indication is mandatory\n";     
							financeCount=-1;
							isFinanceSelected = false;
						}

			        else if(allElements[i].value == 'NO' && allElements[i].checked)
					{
								var oContactMethod = document.getElementsByName("FINANCETYPE");
                                for(j=0;j<oContactMethod.length;j++)
                                { 
                                if(oContactMethod[j].checked)
									{
	                                   isFinanceTypeSelected = true;									
    								}
                                }
                                
                                if(!isFinanceTypeSelected)
                                {
                                 errors += "-> Finance Type indication is mandatory\n";
					             isFinanceTypeSelected = false; 
                                }
					}
			}  


 
		//CHECK QUERY DROPDOWN TITLE LIST
		if (allElements[i].name == "TITLE")
		{
			var otitle = allElements[i].value;
			if  (allElements[i].selectedIndex == 0) {errors += "-> Title is a Mandatory field\n";}
		}

		//CHECK COMMENTS DROPDOWN TITLE LIST
		if (allElements[i].name == "comments")
		{
			var ocomments = allElements[i].value;
			if ( ocomments.length <= 0 ) {errors += "-> Comments is a Mandatory field, please enter your Comments\n";}	
		}		


		/* 
		if(document.getElementById('TRADEINVEHICLE').checked)
			{
				if (allElements[i].name == "MAKE01")
				{
					var ocomments = allElements[i].value;
					if ( ocomments == '-- Make Selection --' ) {errors += "-> One Make Selection is Mandatory field, please select a make\n";}
				}
				
				if (allElements[i].name == "TRADEINMODEL")
				{
					var ocomments = allElements[i].value;
					if ( ocomments.length <=0 ) {errors += "-> Model is Mandatory field, please fill in the model\n";}
				}
				
				if (allElements[i].name == "TRADEINYEAR")
				{
					var ocomments = allElements[i].value;
					if ( ocomments=='Year' ) {errors += "-> Model Year is a Mandatory field, please select a year\n";}
				}
			}
   */
 }	
	
	if(errors)
		{
			alert("The following errors were found\n" + errors);
			errors = "";
			
			contactCount=-1;
			isContactSelected = false;      
			
			driversCount = -1;
			isDriversSelected = false;
			
			tradeInCount = -1;
			isTradeInSelected = false;
			
			depositeCount = -1;
			isDepositeSelected = false;
			
			financeCount = -1;
			isFinanceSelected = false;
			
			returnVal = false;
		}
	else
		{
			contactCount=-1;
			isContactSelected = false;
			
			driversCount = -1;
			isDriversSelected = false;
			
			tradeInCount = -1;
			isTradeInSelected = false;
			
			depositeCount = -1;
			isDepositeSelected = false;
			
			financeCount = -1;
			isFinanceSelected = false;

			financeTypeCount = -1;
			isFinanceTypeSelected = false;
			
			returnVal = true;
		}
	return returnVal; 

}
// FORM VALIDATION

// THREE CHECK BOX LIMITATION
var freeItemCount=0 
var maxFreeItems=3

function setItems(item)
	{ 
		if(item.checked)
			{
				freeItemCount=freeItemCount+1
			}
		else
			{
				freeItemCount=freeItemCount-1
			}
	
		if (freeItemCount>maxFreeItems)
			{
				item.checked=false 
				freeItemCount=freeItemCount-1 
				alert('You may only choose '+maxFreeItems+' vehicles. Uncheck an option if you want to pick another.')
			}
	} 
	
					function validateSearch()
				{
           
					var makeSelect = document.getElementById("MAKE01").value;
					if ( makeSelect == '-- Make Selection --' ) 
					 {
						alert( "-> One Make Selection is Mandatory field, please select a make"); 
						return false;
						}
					else return true;

				}
	
// THREE CHECK BOX LIMITATION

function IsNumeric(sText)
	{
		var ValidChars = "0123456789.";
		var IsNumber=true;
		var Char;
	 
		for (i = 0; i < sText.length && IsNumber == true; i++) 
			{ 
				Char = sText.charAt(i); 
					if (ValidChars.indexOf(Char) == -1)
						{
							IsNumber = false;
						}
			}
		return IsNumber;
	}


