// JavaScript Document
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) { //v3.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); 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 validateFormFrontPage()
{
	if($('#first_name').val()=='')
	{
		alert('Name field can not be empty.');
		$('#first_name').focus();
		return false;
	}	
	if($('#day_phone').val()=='')
	{
		alert('Day Phone field can not be empty.');
		$('#day_phone').focus();
		return false;
	}	
	if($('#date_requested').val()=='')
	{
		alert('Enter the date of appointment.');
		$('#date_requested').focus();
		return false;
	}	
	if($('#appt_preference').val()=='')
	{
		alert('Select your appointment preference.');
		$('#appt_preference').focus();
		return false;
	}	
	if($('#service_requested').val()=='')
	{
		alert('Select the service you would like to request.');
		$('#service_requested').focus();
		return false;
	}	
	return true;
	

}

function validateFormAppointment()
{
	if($('#first_name').val()=='')
	{
		alert('First Name field can not be empty.');
		$('#first_name').focus();
		return false;
	}	
	if($('#last_name').val()=='')
	{
		alert('Last Name field can not be empty.');
		$('#last_name').focus();
		return false;
	}	
	if($('#day_phone').val()=='')
	{
		alert('Day Phone field can not be empty.');
		$('#day_phone').focus();
		return false;
	}	
	if($('#address').val()=='')
	{
		alert('Address field can not be empty.');
		$('#address').focus();
		return false;
	}	

	if($('#city').val()=='')
	{
		alert('City field can not be empty.');
		$('#city').focus();
		return false;
	}	
	if($('#state').val()=='')
	{
		alert('State field can not be empty.');
		$('#state').focus();
		return false;
	}	
	if($('#zip').val()=='')
	{
		alert('Zip field can not be empty.');
		$('#zip').focus();
		return false;
	}	
	if(!echeck($('#email').val()))
	{
		$('#email').focus();
		return false;
	}
/*	if($('#car_year').val()=='')
	{
		alert('Enter your vehicle year information');
		$('#car_year').focus();
		return false;
	}	
	if($('#car_make').val()=='')
	{
		alert('Enter the make of your vehicle');
		$('#car_make').focus();
		return false;
	}	
	if($('#car_model').val()=='')
	{
		alert('Enter the model of your vehicle.');
		$('#car_model').focus();
		return false;
	}
	if($('#engine_size').val()=='')
	{
		alert('Enter the engine size of your vehicle.');
		$('#engine_size').focus();
		return false;
	}			
*/	if($('#date_requested').val()=='')
	{
		alert('Enter the date of appointment.');
		$('#date_requested').focus();
		return false;
	}	
	if($('#appt_preference').val()=='')
	{
		alert('Select your appointment preference.');
		$('#appt_preference').focus();
		return false;
	}	
	if($('#service_requested').val()=='')
	{
		alert('Select the service you would like to request.');
		$('#service_requested').focus();
		return false;
	}	
	if($('#captchastring').val()=='')
	{
		alert('Please enter the sucurity text.');
		$('#captchastring').focus();
		return false;
	}	
	
	return true;
}

function validateFormEmployment()
{
	if($('#first_name').val()=='')
	{
		alert('Name field can not be empty.');
		$('#first_name').focus();
		return false;
	}	
	if($('#day_phone').val()=='')
	{
		alert('Day Phone field can not be empty.');
		$('#day_phone').focus();
		return false;
	}	
	if($('#address').val()=='')
	{
		alert('Address field can not be empty.');
		$('#address').focus();
		return false;
	}	

	if($('#city').val()=='')
	{
		alert('City field can not be empty.');
		$('#city').focus();
		return false;
	}	
	if($('#state').val()=='')
	{
		alert('State field can not be empty.');
		$('#state').focus();
		return false;
	}	
	if($('#zip').val()=='')
	{
		alert('Zip field can not be empty.');
		$('#zip').focus();
		return false;
	}	
	if(isNaN($('#zip').val()))
	{
		alert('Zip field should have a numeric value.');
		$('#zip').focus();
		return false;
	}	

	if(!echeck($('#email').val()))
	{
		$('#email').focus();
		return false;
	}
	if($('#desired_position').val()=='')
	{
		alert('Please let us know what is your desired position');
		$('#desired_position').focus();
		return false;
	}
	
	if($('#certification').val()=='')
	{
		alert('Plese let us know about your certifications');
		$('#certification').focus();
		return false;
	}	
	if($('#desired_income').val()=='')
	{
		alert('Please let us know what is your desired income');
		$('#desired_income').focus();
		return false;
	}	
	if(isNaN($('#desired_income').val()))
	{
		alert('Desired income should have a numeric value.');
		$('#desired_income').focus();
		return false;
	}
	if($('#captchastring').val()=='')
	{
		alert('Please enter the sucurity text.');
		$('#captchastring').focus();
		return false;
	}	
	
	
	return true;
}

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

function validateSubscriptionForm()
{
	if(document.getElementById('f_name').value=='')
	{
		alert('First Name field can not be empty.');
		document.getElementById('f_name').focus();
		return false;
	}
	if(document.getElementById('l_name').value=='')
	{
		alert('Last Name field can not be empty.');
		document.getElementById('l_name').focus();
		return false;
	}	
	if(!echeck(document.getElementById('email_addr').value))
	{
		document.getElementById('email_addr').focus();
		return false;
	}
	return true;
}

function makeBlank(id,val,check)
	{
		
		var trimmed = val.replace(/^\s+|\s+$/g, '') ;
		if(trimmed==check)
		{
			eval("document.getElementById('"+id+"').value=''");
		}
	}
	function putValue(id,val,check)
	{
		
		var trimmed = val.replace(/^\s+|\s+$/g, '') ;
		
		if(trimmed=='')
		{
			eval("document.getElementById('"+id+"').value='"+check+"'");

		}	
		
	}


function changeFontSize(strDirection)
{
	var arrCookies = get_cookie_array();

	if ( !arrCookies['fontsize'] || arrCookies['fontsize'] == 'undefined' || arrCookies['fontsize'] == "NaN" ) {
		document.cookie = "fontsize=3; expires=Sun, 01-Dec-2020 08:00:00 GMT; path=/";
		var fontsize = 1;
		
	} else {
		var fontsize = parseInt(arrCookies['fontsize']);	
		if ( strDirection == "up" && fontsize < 5 ) {
			fontsize++;
				
		} else if ( strDirection == "down" && fontsize > 1 ) {
			fontsize--;
			
		}
		
		document.cookie = "fontsize=" + fontsize + "; expires=Sun, 01-Dec-2020 08:00:00 GMT; path=/";
		
	}
	
	var arrTds = document.getElementsByTagName('div');
	
	for ( var i=0; i<arrTds.length; i++ ) {
		if ( arrTds[i].className.indexOf("normal_text") != -1 ) {
			arrTds[i].className = "normal_text_" + fontsize; 
				
		}
		
	}//for
}

function get_cookie_array()
{
	var arrCookies = new Array();
	var arrParts = document.cookie.split(";");
	
	for ( var i=0; i<arrParts.length; i++ ) {
		arrParts2 = arrParts[i].split("=");
		arrCookies[trim(arrParts2[0])] = trim(arrParts2[1]);
		
	}//for
	
	return arrCookies;
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function Form_Invoice_Validator(theForm)

{

  var chkVal = theForm.InvoiceNumber.value;

  var prsVal = chkVal;

  if (chkVal== "")

  {

    alert("Please enter a value in the \"InvoiceNumber\" field.");

    theForm.InvoiceNumber.focus();

    return (false);

  }



  var chkVal = theForm.Amount.value;

  var prsVal = chkVal;

  if (chkVal== "" || isNaN(chkVal))

  {

    alert("Please enter proper value in the \"Amount\" field.");

    theForm.Amount.focus();

	theForm.Amount.value='';

    return (false);

  }

 

  var chkVal = theForm.Contact_FirstName.value;

  var prsVal = chkVal;

  if (chkVal == "")

  {

    alert("Please enter a value in the \"FirstName\" field.");

    theForm.Contact_FirstName.focus();

    return (false);

  }



  var chkVal = theForm.Contact_LastName.value;

  var prsVal = chkVal;

  if (chkVal == "")

  {

    alert("Please enter a value in the \"LastName\" field.");

    theForm.Contact_LastName.focus();

    return (false);

  }



  var chkVal = theForm.Contact_Email.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Please enter a value in the \"Email\" field.");

    theForm.Contact_Email.focus();

    return (false);

  }

  

  var chkVal = theForm.CardNumber.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Please enter a value in the \"Card Number\" field.");

    theForm.CardNumber.focus();

    return (false);

  }

  var chkVal = theForm.CardCVV.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Please enter a value in the \"Card Identification Number\" field.");

    theForm.CardCVV.focus();

    return (false);

  }

  var chkVal = theForm.CardAddress.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Please enter a value in the \"Card Address\" field.");

    theForm.CardAddress.focus();

    return (false);

  }

  var chkVal = theForm.CardCity.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Please enter a value in the \"Card City\" field.");

    theForm.CardCity.focus();

    return (false);

  }

  var chkVal = theForm.CardState.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Please enter a value in the \"Card State\" field.");

    theForm.CardState.focus();

    return (false);

  }

  var chkVal = theForm.CardZip.value;

  var prsVal = chkVal;

  if (chkVal == "" || isNaN(chkVal))

  {

    alert("Please enter proper value in the \"Card Zip\" field.");

    theForm.CardZip.focus();

    return (false);

  }

  

  

  return (true);

}

function Form_Invoice_Check_Validator(theForm)
{
  var chkVal = theForm.Contact_FirstName.value;

  var prsVal = chkVal;

  if (chkVal == "")

  {

    alert("Please enter a value in the \"FirstName\" field.");

    theForm.Contact_FirstName.focus();

    return (false);

  }



  var chkVal = theForm.Contact_LastName.value;

  var prsVal = chkVal;

  if (chkVal == "")

  {

    alert("Please enter a value in the \"LastName\" field.");

    theForm.Contact_LastName.focus();

    return (false);

  }



  var chkVal = theForm.Contact_Email.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Please enter a value in the \"Email\" field.");

    theForm.Contact_Email.focus();

    return (false);

  }

  

  var chkVal = theForm.bank_name.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Bank Name can't be empty.");

    theForm.bank_name.focus();

    return (false);

  }

  var chkVal = theForm.routing_number.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Routing number of the bank can not be empty.");

    theForm.routing_number.focus();

    return (false);

  }

  var chkVal = theForm.account_number.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Account number can't be empty");

    theForm.account_number.focus();

    return (false);

  }
  var chkVal = theForm.cust_account_name.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Please enter your name as it appears on your bank account.");

    theForm.cust_account_name.focus();

    return (false);

  }
  var chkVal = theForm.Address.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Please enter a value in the \"Address\" field.");

    theForm.Address.focus();

    return (false);

  }
  
  var chkVal = theForm.City.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Please enter a value in the \"City\" field.");

    theForm.City.focus();

    return (false);

  }

  var chkVal = theForm.State.value;

  var prsVal = chkVal;

  if (chkVal == "" )

  {

    alert("Please enter a value in the \"State\" field.");

    theForm.State.focus();

    return (false);

  }

  var chkVal = theForm.Zip.value;

  var prsVal = chkVal;

  if (chkVal == "" || isNaN(chkVal))

  {

    alert("Please enter proper value in the \"Zip\" field.");

    theForm.Zip.focus();

    return (false);

  }

  return (true);

}
