// JavaScript Document

function fieldCheck()
{
	
 	 size_residence=document.estimation_form.size_residence.value;
	 name=document.estimation_form.name.value;
 	 email=document.estimation_form.email.value;
	 email1=checkemail(email,"Email Id seems to be incorrect");
	 phone=document.estimation_form.phone.value;
	 phone_len=phone.length;
	 msg="";
	if(size_residence=="")
	{
	msg+="Select Size of residence \n";
	}

	if(name=="")
	{
	msg+="Enter  name\n";
	}
	
	if(email=="")
	{
		msg+="Enter Email Id \n";
	}
	else{
		if(email1!="")
		{
	   msg+=email1;
		}
	}
	
	if(phone=="")
	{
	msg+="Enter Phone \n";
	}
	else
	{
	  if(!(phone_len >=10 && phone_len <=11))
	  {
	   msg+="Enter Valid Phone Number \n";
	  }
	}
	
	if(msg!="")
	{
			alert(msg);
			return false;
	}
	return true;
}

function estimationCheck()
{
	 
	 name=document.avl_estimation_form.name.value;
 	 email=document.avl_estimation_form.email.value;
	 email1=checkemail(email,"Email Id seems to be incorrect");
	 phone=document.avl_estimation_form.phone.value;
	 moving_date=document.avl_estimation_form.moving_date2.value;
	 from_state=document.avl_estimation_form.from_state.value;
 	  from_city=document.avl_estimation_form.from_city.value;
	 from_zipcode=document.avl_estimation_form.from_zipcode.value;
	 to_state=document.avl_estimation_form.to_state.value;
	 to_city=document.avl_estimation_form.to_city.value;
	 zipcode_len=from_zipcode.length;
 	 size_residence=document.avl_estimation_form.size_residence.value;
	 phone_len=phone.length;
	 
	 msg="";
	
	
	if(name=="")
	{
	msg+="Enter  name\n";
	}
	
	if(email=="")
	{
		msg+="Enter Email Id \n";
	}
	else{
		if(email1!="")
		{
	   msg+=email1;
		}
	}
	
	if(phone=="")
	{
	msg+="Enter Phone \n";
	}
	else
	{
	  if(!(phone_len >=10 && phone_len <=11))
	  {
	   msg+="Enter Valid Phone Number \n";
	  }
	}
	
	 if(moving_date=="")
	{
	msg+="Select date \n";
	}

	if(from_state=="select")
	{
	msg+="Select From State \n";
	}

	if(from_city=="")
	{
	msg+="Enter From City \n";
	}

	if(from_zipcode=="")
	{
	msg+="Enter From Zipcode \n";
	}
	else
	{
	  if(zipcode_len != 5)
	  {
	   msg+="Zipcode should be 5 digit \n";
	  }
	}

	if(to_state=="select")
	{
	msg+="Select To State\n";
	}

	if(to_city=="")
	{
	msg+="Enter To City \n";
	}
	
	if(size_residence=="")
	{
	msg+="Select Size of residence \n";
	}

	
	
	if(msg!="")
	{
			alert(msg);
			return false;
	}
	return true;
}


function fieldCheck1()
{
	
 	 name=document.estimation_form.name.value;
 	 email=document.estimation_form.email.value;
	 email1=checkemail(email,"Email Id seems to be incorrect");
	 phone=document.estimation_form.phone.value;
	  phone_len=phone.length;
	 msg="";
	

	if(name=="")
	{
	msg+="Enter  name\n";
	}
	
	if(email=="")
	{
		msg+="Enter Email Id \n";
	}
	else
	{
	  if(!(phone_len >=10 && phone_len <=11))
	  {
	   msg+="Enter Valid Phone Number \n";
	  }
	}
	
	if(phone=="")
	{
	msg+="Enter Phone \n";
	}
	else
	{
	  if(!(phone_len >=10 && phone_len <=11))
	  {
	   msg+="Phone Number should be minimum 10 digit \n";
	  }
	}
	
	if(msg!="")
	{
			alert(msg);
			return false;
	}
	return true;
}


function IsEmailValid(formObj) 
{
  var emailStr=formObj
  var emailPat=/^(.+)@(.+)$/
  var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
  var validChars="\[^\\s" + specialChars + "\]"
  var quotedUser="(\"[^\"]*\")"
  var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
  var atom=validChars + '+'
  var word="(" + atom + "|" + quotedUser + ")"
  var userPat=new RegExp("^" + word + "(\\." + word+ ")*$")
  var domainPat=new RegExp("^" + atom + "(\\." +atom +")*$")
  var matchArray=emailStr.match(emailPat)
  if (matchArray==null) 
  {
      return "Email address seems incorrect (check@ and .'s).\n"
  }
  var user=matchArray[1]
  var domain=matchArray[2]

  // See if "user" is valid
  if (user.match(userPat)==null) 
  {
     // user is not valid
     return "The username doesn't seem to be valid.\n"
     
  }
  var IPArray=domain.match(ipDomainPat)
  if (IPArray!=null) 
  {
     // this is an IP address
     for (var i=1;i<=4;i++) 
     {
          if (IPArray[i]>255) 
          {
               return "Destination IP address appears to be invalid!\n"
               
          }
     }
      
  }
  var domainArray=domain.match(domainPat)
  if (domainArray==null) 
  {
     return "The domain name doesn't appear to be valid.\n"
     
  }
  var atomPat=new RegExp(atom,"g")
  var domArr=domain.match(atomPat)
  var len=domArr.length
  if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) 
  {
     // the address must end in a two letter or three letter word.
     return "The address must end in a three-letter domain, or two letter country.\n"
     
  }
  // Make sure there's a host name preceding the domain.
  if (len<2) 
  {
     var errStr="This address is missing a hostname!\n"
     return errStr
  }
  // If we've gotten this far, everything looks  great!
 return "";
}

function ValidateNum(input,event)
{
	var keyCode = event.which ? event.which : event.keyCode;
	//alert(parseInt(keyCode));
	
	//numeric integer
	if(parseInt(keyCode)>=48 && parseInt(keyCode)<=57)
		{
		return true;
		}
		
		//up down arrow
	if(parseInt(keyCode)>=37 && parseInt(keyCode)<=40)
		{
		return true;
		}
	if(parseInt(keyCode)==13 || parseInt(keyCode)==46 || parseInt(keyCode)==9 || parseInt(keyCode)==8)
		{
		return true;
		}
	return false;
	
}

function ValidateName(input,event)
{
	var keyCode = event.which ? event.which : event.keyCode;
	//Small Alphabets
	if(parseInt(keyCode)>=97 && parseInt(keyCode)<=122)
		{
		return true;
		}
	//Caps Alphabets
	if(parseInt(keyCode)>=65 && parseInt(keyCode)<=90)
		{
		return true;
		}
	//Space-Return-Dot
	if(parseInt(keyCode)==32 || parseInt(keyCode)==13 || parseInt(keyCode)==46 || parseInt(keyCode)==9)
		{
		return true;
		}
	//input.focus();
	return false;
	//alert(keyCode);
}

function checkDot(txt,y)
{
   var str=String();
   str=txt;
   dot=0;
   val=str.length;
   if(val<=0)
   	return y;
   for(var i=0;i<val;i++)
   {
      var xx =str.substring (i, i+1)
	  if( xx=="." || xx=="," || xx=="/" || xx=="\\" || xx==";" || xx=="'" || xx=="\"" || xx=="!" || xx=="@" || xx=="#" || xx=="$" || xx=="%" || xx=="^" || xx=="&" || xx=="*" || xx=="(" || xx=="\)" || xx=="-" || xx=="_" || xx=="+" || xx=="=" || xx=="|" || xx=="<" || xx==">" || xx=="?" )
	  {
	     dot=dot+1;
	  }
   }
   if(dot>0)
	  return y;
   else
	  return '';
}
function isNumber(formObj,y)
{
     var objVal;
     var co;
     co=0;
     objVal = formObj;
     var valLength = objVal.length;
	 if(valLength<=0)
	 	return y;
     var testChar  = " ";
     for (var i=0; i<valLength; i++) 
     {
       testChar = objVal.charAt(i);
          if (testChar < '0' || testChar > '9')
          {
              co=co+1;
          }
     }
     if(co>0)
        return y;
     else
       return '';   
}

function agefocus()
	{
		if(!(document.search_caller.DOBYEAR.value=="0") && !(document.search_caller.DOBMONTH.value=="0") && !(document.search_caller.DOBDAY.value=="0"))
		{	
			document.search_caller.DOBMONTH.value="0";
			document.search_caller.DOBDAY.value="0";		
			document.search_caller.DOBYEAR.value="0";
		}
	}	

function agesel()
	{
		document.search_caller.AGE.value="";
	}

function updateDay(change,formName,yearName,monthName,dayName)
{	
	
	var form = document.forms[formName];
	var yearSelect = form[yearName];
	var monthSelect = form[monthName];
	var daySelect = form[dayName];
	var year = yearSelect[yearSelect.selectedIndex].value;
	var month = monthSelect[monthSelect.selectedIndex].value;
	var day = daySelect[daySelect.selectedIndex].value;

	if (change == 'month' || (change == 'year' && month == 2))
	{
		var i = 31;
		var flag = true;
		if(month!=0)
		{
		while(flag)
		{
			var date = new Date(year,month-1,i);
			if (date.getMonth() == month - 1)
			{
				flag = false;
			}
			else
			{
				i = i - 1;
			}
		}
		}
		daySelect.length = 0;
		daySelect.length = i;
		daySelect[0] = new Option("-Date-",0);		
		var j = 1;
		while(j <= i)
		{
			daySelect[j] = new Option(j,j);
			j = j + 1;
		}
	}
	daySelect.selectedIndex = 0;
}

function checkempty1(x,y)
{
	
	if(x.value==0)
	{
		alert(y);
		x.focus();
		return false;
	}
	
}

function checkempty(x,y)
{
	if(x==0)
		return y;
	else
		return "";
}

function checkemail(x,y)
{
	if(x==0)
		return y;
	else
		return IsEmailValid(x);
}

/*function check_mobile(x,y)
{
	
	if(x=="")
		return y;
	else
	{
		chk=x.charAt(0);
		if(chk!=9)
			return y;
		if(x.length!=10)
			return y;
		
		
		return "";
	}
}*/

function check_mobile(x,y)
{
	
	if(x=="")
		return y;
	else
	{
		chk=x.charAt(0);
		start2=x.substr(0,2);
		len=x.length;
		
		if(chk!=9 && chk!=8)
			return y;
		if(len==12)
		{
			if(start2==91)
				return "";
		}
		else if(len==10)
		{
			return "";
		}
		else
		{
			return y;
		}
		
		
		
	}
}

function check_radio(x)
{
	var val="";
	
	for(i=0;i<x.length;i++)
	{
		if(x[i].checked==true)
		{
			val=x[i].value;
		}
	}
	return val;
}

function string_replace(str,findstr,replacestr)
{
	size=str.length;
	for(i=0;i<size;i++)
	{
		str=str.replace(findstr,replacestr);
	}	
	return str;
}

function check_checkboxvalidate(x)
{
	count = 0;
	isValid = false;
	nBox = document.getElementsByName(x);
	for (i=0; i<nBox.length; i++)
	{
		if (nBox[i].checked == true)
		{
		count++
		}
	}
	if (count == 0)
	{
		return false;
	}
	else
	{
		return true;
	}

}

function winOpen(strUrl,strWindow, strParameters) 
{
	var newWin=window.open(strUrl,strWindow,strParameters);
	newWin.focus();
}

var UFE_RE = /%u([0-9A-Za-z]{4})/g;
function unicodeFreeEscape(s) 
{
  return escape(s).replace(UFE_RE, "%ff");
}

//disable the mouse right click

function clickIE4()
{
	if (event.button==2)
	{
		return false;
	}
}

function clickNS4(e)
{
	if (document.layers||document.getElementById&&!document.all)
	{
		if (e.which==2||e.which==3)
		{
			return false;
		}
	}
}

if (document.layers)
{
	document.captureEvents(Event.MOUSEDOWN);
	document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById)
{
	document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false")
//End Disable right click




function trim(str){
return str.replace(/^\s+|\s+$/g,''); 
}
function isEmail(objField){
	if(trim(objField.value)==""){
		return false;
	}
	if(objField.value.length > 0){
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(objField.value)){
			return true;
		}
	}
	return false;
}

function checkAlphaNumeric(objValue){ 
	var re = /^[a-zA-Z_0-9]$/;
	if (!re.test(objValue))
	{ 
		return false;
	} else {
		return true;
	}
}
function resetFrm(frm){
	
}

function changeSelect(fieldID, newOptions, newValues) 
{
	selectField = document.getElementById(fieldID); 
	selectField.options.length = 0;
	//alert(newOptions.length);
	var opt=new Option();
	if(fieldID=='quickbrand')
	{
		opt.text="Select Brand";
	}
	else if(fieldID=='quickmodule')
	{
		opt.text="Select Model";
	}
	else
	{
		opt.text="Select";
	}
	opt.value="";
	document.getElementById(fieldID).options[0]=opt;
	for (i=0; i<newOptions.length; i++) 
	{
		selectField.options[selectField.length] = new Option(newOptions[i], newValues[i]);  
	}
}

//Decode

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}

