//function to go to home page when cancell button is clicked
function goHome()
{
	window.location = "http://www.desais.in";
}

function countChars(whichTxt,txt)
{
	var cnt = txt.length;
	var txtVal="(min. 50 characters)"
	//disaplay no of chars
	if(whichTxt=="reason")
	{	
		var elm = document.getElementById("reasonTxt");
		txtVal="You have typed " + cnt + " characters"
	}
	elm.innerHTML=txtVal;

}


function isEmailAddr(email)
{

	if (email=="no email")
	{
		return true;
		exit;
	}
	var result = false;
	var theStr = new String(email);
	var index = theStr.indexOf("@");
	if (index > 0)
	{
	var pindex = theStr.indexOf(".",index);
	if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
	}
	return result;
}


function isWebAddr(webadd)
{

	var result = false;
	var theStr = new String(webadd);
	var index = theStr.indexOf("www");
	if (index >= 0)
	{
		//check if there are 2 .
		var addArr=theStr.split(".")
		if (addArr.length <3)
		{
			result=false;
		}else{result=true;}
	}
	return result;
}

function validRequired(formField, fieldLabel, required)
{
  var result = true;

  if ((formField.value == "") && (required))
  {
    if (formField.name == "sib1")
	{
		alert('If no siblings then please put "NIL in the first box else\n\n Please enter a value for the "' + fieldLabel +'" field.');
	}else
	{  
		alert('Please enter a value for the "' + fieldLabel +'" field.');
	}

    if (formField.name == "Country")
	{
		document.brochure.CountryLst.focus();
	}else
	{
		formField.focus();
	}	
    result = false;
  }
  
  return result;
}

function validEmail(formField,fieldLabel,required)
{
  var result = true;
  
  if (required && !validRequired(formField,fieldLabel,required))
    result = false;

  if (result && ((formField.value.length < 3 || !isEmailAddr(formField.value))))
  {
    alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    formField.focus();
    result = false;
  }
   
  return result;

}

function validWebsite(formField,fieldLabel,required)
{
  var result = true;
  
  if (required && !validRequired(formField,fieldLabel,required))
    result = false;

  if (result && ((formField.value.length < 3) || !isWebAddr(formField.value)) )
  {
    alert("Please enter a complete website address in the form: www.mywebsite.com");
    formField.focus();
    result = false;
  }
   
  return result;

}




// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()-";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++);
    {   
            // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone, minDigits){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
//return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
// allow blanks in certain fields
if (s.length>0)
{
	return (isInteger(s) && s.length >= minDigits);
}
return true;

}


function validNum(formField, fieldLabel, minDigits)
{
	var result = true;
	var Phone = formField.value

	if (Phone.length==0)
	{
		return true;
	}
	if (Phone.length > 0)
	{
		result = false;
	}
	//alert(Phone.length);
	if(Phone.length < minDigits)
	{
		alert("Please Enter a Valid " + fieldLabel + " Number");
		formField.focus();
		return  false;
	}
	//alert(result + fieldLabel);
	if(!result)
	{
		//check for characters
		if(isNaN(Phone))
			{
				alert("Please Enter a Valid " + fieldLabel + " Number");
				formField.focus();
				return  false;
			}
			return true;
	}

	return result;
}


function validNum1(formField, fieldLabel, minDigits)
{
	var Phone=formField;
	var result = true;
	if (checkInternationalPhone(Phone.value,minDigits)==false)
	{
		alert("Please Enter a Valid " + fieldLabel + " Number");
		//Phone.value="";
		Phone.focus();
		result = false;
	}
	return result;
 }


function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function validDate(formField,fieldLabel,required)
{
  var result = true;

  if (required && !validRequired(formField,fieldLabel))
    result = false;
  
   if (result)
   {
     var elems = formField.value.split("/");
     
     result = (elems.length == 3); // should be three components
     
     if (result)
     {
       var day = parseInt(elems[0],10);
       var month = parseInt(elems[1],10);
       var year = parseInt(elems[2],10);
      result = !isNaN(month) && (month > 0) && (month < 13) &&
            !isNaN(day) && (day > 0) && (day < 32) &&
            !isNaN(year) && (elems[2].length == 4);
     }
     
      if (!result)
     {
       alert('Please enter a date in the format DD/MM/YYYY for the "' + fieldLabel +'" field.');
      formField.focus();    
    }
  } 
  
  return result;
}

function validYear(formField,fieldLabel,required)
{
  var result = true;

  if (required && !validRequired(formField,fieldLabel))
    result = false;
  
   if (result)
   {
       var year = parseInt(formField.value);
      result = !isNaN(year) && (year.toString().length == 4);
     }
     
      if (!result)
     {
       alert('Please enter a Year in the format YYYY for the "' + fieldLabel +'" field.');
      formField.focus();    
    }
  return result;
}


function validLength(formField, fieldLabel, minLen)
{
	var result = true;
	var aboutUr = trim(formField.value);
//	alert(aboutUr.length);
	if(aboutUr.length < minLen)
	{
		alert("min. " +  minLen + " characters required for " + fieldLabel);
		formField.value="";
		formField.focus();
		var elm = document.getElementById("reasonTxt");
		elm.innerHTML="(min. " + minLen + " charactes)";
		return  false;
	}
	return result;
}
function trim(str)
{
    if(!str || typeof str != 'string')
        return null;

    return str.replace(/^[\s]+/,'').replace(/[\s]+$/,'').replace(/[\s]{2,}/,' ');
}


function validateForm(theForm)
{
	//Name check
	if (!validRequired(theForm.Person,"Contact Person", true))
	return false;
	//this is company check
	if (!validRequired(theForm.Company,"Company", true))
	return false;
	//this is address check
	if (!validRequired(theForm.add1,"Address", true))
	return false;
	//counrty
	if (!validRequired(theForm.Country,"Counrty", true))
	return false;
	//tel check
	if (!validRequired(theForm.telCtyCode,"Telephone Counrty Code", true))
	return false;
	if (!validNum(theForm.telCtyCode,"Telephone Country Code", 1))
	return false;
	if (!validRequired(theForm.telCtCode,"Telephone City Code", true))
	return false;
	if (!validNum(theForm.telCtCode,"Telephone City Code", 1))
	return false;
	if (!validRequired(theForm.Tel,"Telephone Number", true))
	return false;
	if (!validNum(theForm.Tel,"Telephone Number", 6))
	return false;
	
	//mobile check
	if (!validRequired(theForm.cellCtyCode,"Mobile Counrty Code", true))
	return false;
	if (!validNum(theForm.cellCtyCode,"Mobile Country Code", 1))
	return false;
	if (!validRequired(theForm.cellCtCode,"Mobile City Code", true))
	return false;
	if (!validNum(theForm.cellCtCode,"Mobile City Code", 1))
	return false;
	if (!validRequired(theForm.cell,"Mobile Number", true))
	return false;
	if (!validNum(theForm.cell,"Mobile Number", 10))
	return false;
	
	//email check
	if (!validEmail(theForm.EmailId,"Email",true))
	return false;
	//website check
	if (!validWebsite(theForm.website,"Website", true))
	return false;
	//feedback
	if (!validRequired(theForm.reason,"Reason to download",true))
	return false;
	if (!validLength(theForm.reason,"Reason to download", 50))
		return false;
}

// country code array

var acode = new Array();
var ncode = new Array();	 
acode[0]="", ncode[0]="";
//acode[1]="IND",  ncode[1]="91";
acode[1]="IND",  ncode[1]="91";
acode[2]="AFG",  ncode[2]="93";
acode[3]="ALB",  ncode[3]="355";
acode[4]="DZA",  ncode[4]="213";
acode[5]="ASM",  ncode[5]="684";
acode[6]="AND",  ncode[6]="376";
acode[7]="AGO",  ncode[7]="244";
acode[8]="AIA",  ncode[8]="264";
acode[9]="ATA",  ncode[9]="672";
acode[10]="ATG",  ncode[10]="268";
acode[11]="ARG",  ncode[11]="54";
acode[12]="ARM",  ncode[12]="374";
acode[13]="ABW",  ncode[13]="297";
acode[14]="AUS",  ncode[14]="61";
acode[15]="AUT",  ncode[15]="43";
acode[16]="AZE",  ncode[16]="994";

acode[17]="BHS",  ncode[17]="242";
acode[18]="BHR",  ncode[18]="973";
acode[19]="BGD",  ncode[19]="880";
acode[20]="BRB",  ncode[20]="246";
acode[21]="BLR",  ncode[21]="375";
acode[22]="BEL",  ncode[22]="032";
acode[23]="BLZ",  ncode[23]="501";
acode[24]="BEN",  ncode[24]="220";
acode[25]="BMU",  ncode[25]="441";
acode[26]="BTN",  ncode[26]="975";
acode[27]="BOL",  ncode[27]="591";
acode[28]="BIH",  ncode[28]="387";
acode[29]="BWA",  ncode[29]="267";
acode[30]="BVT",  ncode[30]="";
acode[31]="BRA",  ncode[31]="55";
acode[32]="IOT",  ncode[32]="";
acode[33]="BRN",  ncode[33]="673";
acode[34]="BGR",  ncode[34]="359";
acode[35]="BFA",  ncode[35]="226";
acode[36]="BDI",  ncode[36]="257";
acode[37]="KHM",  ncode[37]="855";

acode[38]="CMR",  ncode[38]="373";
acode[39]="CAN",  ncode[39]="1";
acode[40]="CPV",  ncode[40]="238";
acode[41]="CYM",  ncode[41]="345";
acode[42]="CAF",  ncode[42]="236";
acode[43]="TCD",  ncode[43]="235";
acode[44]="CHL",  ncode[44]="56";
acode[45]="CHN",  ncode[45]="86";
acode[46]="CXR",  ncode[46]="61";
acode[47]="CCK",  ncode[47]="61";
acode[48]="COL",  ncode[48]="57";
acode[49]="COM",  ncode[49]="269";
acode[50]="COG",  ncode[50]="242";
acode[51]="COD",  ncode[51]="243";
acode[52]="COK",  ncode[52]="682";
acode[53]="CRI",  ncode[53]="506";
acode[54]="CIV",  ncode[54]="";
acode[55]="HRV",  ncode[55]="385";
acode[56]="CUB",  ncode[56]="53";
acode[57]="CYP",  ncode[57]="357";
acode[58]="CZE",  ncode[58]="420";

acode[59]="DNK",  ncode[59]="45";
acode[60]="DJI",  ncode[60]="253";
acode[61]="DMA",  ncode[61]="767";
acode[62]="DOM",  ncode[62]="809";

acode[63]="TMP",  ncode[63]="";
acode[64]="ECU",  ncode[64]="593";
acode[65]="EGY",  ncode[65]="20";
acode[66]="SLV",  ncode[66]="503";
acode[67]="GNQ",  ncode[67]="240";
acode[68]="ERI",  ncode[68]="291";
acode[69]="EST",  ncode[69]="372";
acode[70]="ETH",  ncode[70]="251";

acode[71]="FLK",  ncode[71]="500";
acode[72]="FRO",  ncode[72]="298";
acode[73]="FJI",  ncode[73]="679";
acode[74]="FIN",  ncode[74]="358";
acode[75]="FRA",  ncode[75]="33";
acode[76]="FXX",  ncode[76]="";
acode[77]="GUF",  ncode[77]="594";
acode[78]="PYF",  ncode[78]="689";
acode[79]="ATF",  ncode[79]="";

acode[80]="GAB",  ncode[80]="241";
acode[81]="GMB",  ncode[81]="220";
acode[82]="GEO",  ncode[82]="995";
acode[83]="DEU",  ncode[83]="49";
acode[84]="GHA",  ncode[84]="233";
acode[85]="GIB",  ncode[85]="350";
acode[86]="GRC",  ncode[86]="30";
acode[87]="GRL",  ncode[87]="299";
acode[88]="GRD",  ncode[88]="473";
acode[89]="GLP",  ncode[89]="590";
acode[90]="GUM",  ncode[90]="670";
acode[91]="GTM",  ncode[91]="502";
acode[92]="GIN",  ncode[92]="";
acode[93]="GNB",  ncode[93]="245";
acode[94]="GUY",  ncode[94]="592";

acode[95]="HTI",  ncode[95]="509";
acode[96]="HMD",  ncode[96]="";
acode[97]="VAT",  ncode[97]="";
acode[98]="HND",  ncode[98]="504";
acode[99]="HKG",  ncode[99]="852";
acode[100]="HUN",  ncode[100]="36";

acode[101]="ISL",  ncode[101]="354";
acode[102]="IDN",  ncode[102]="62";
acode[103]="IRN",  ncode[103]="98";
acode[104]="IRQ",  ncode[104]="964";
acode[105]="IRL",  ncode[105]="353";
acode[106]="ISR",  ncode[106]="972";
acode[107]="ITA",  ncode[107]="39";

acode[108]="JAM",  ncode[108]="876";
acode[109]="JPN",  ncode[109]="81";
acode[110]="JOR",  ncode[110]="962";

acode[111]="KAZ",  ncode[111]="7";
acode[112]="KEN",  ncode[112]="254";
acode[113]="KIR",  ncode[113]="686";
acode[114]="PRK",  ncode[114]="850 ";
acode[115]="KOR",  ncode[115]="82";
acode[116]="KWT",  ncode[116]="965";
acode[117]="KGZ",  ncode[117]="996";

acode[118]="LAO",  ncode[118]="856";
acode[119]="LVA",  ncode[119]="371";
acode[120]="LBN",  ncode[120]="961";
acode[121]="LSO",  ncode[121]="266";
acode[122]="LBR",  ncode[122]="231";
acode[123]="LBY",  ncode[123]="218";
acode[124]="LIE",  ncode[124]="";
acode[125]="LTU",  ncode[125]="370";
acode[126]="LUX",  ncode[126]="352";

acode[127]="MAC",  ncode[127]="853";
acode[128]="MKD",  ncode[128]="389";
acode[129]="MDG",  ncode[129]="261";
acode[130]="MWI",  ncode[130]="265";
acode[131]="MYS",  ncode[131]="60";
acode[132]="MDV",  ncode[132]="960";
acode[133]="MLI",  ncode[133]="223";
acode[134]="MLT",  ncode[134]="356";
acode[135]=" MHL",  ncode[135]="692";
acode[136]="MTQ",  ncode[136]="596";
acode[137]="MRT",  ncode[137]="222";
acode[138]=" MUS",  ncode[138]="230";
acode[139]=" MYT",  ncode[139]="269";
acode[140]="MEX",  ncode[140]="52";
acode[141]="FSM",  ncode[141]="691";
acode[142]="MDA",  ncode[142]="373";
acode[143]="MCO",  ncode[143]="377";
acode[144]="MNG",  ncode[144]="976";
acode[145]="MSR",  ncode[145]="664";
acode[146]="MAR",  ncode[146]="212";
acode[147]="MOZ",  ncode[147]="258";
acode[148]="MMR",  ncode[148]="95";

acode[149]="NAM",  ncode[149]="264";
acode[150]="NRU",  ncode[150]="674";
acode[151]="NPL",  ncode[151]="977";
acode[152]="NLD",  ncode[152]="31";
acode[153]="ANT",  ncode[153]="599";
acode[154]="NCL",  ncode[154]="687";
acode[155]="NZL",  ncode[155]="64";
acode[156]="NIC",  ncode[156]="505";
acode[157]="NER",  ncode[157]="227";
acode[158]="NGA",  ncode[158]="234";
acode[159]="NIU",  ncode[159]="683";
acode[160]="NFK",  ncode[160]="672";
acode[161]="MNP",  ncode[161]="850";
acode[162]="NOR",  ncode[162]="47";

acode[163]="OMN",  ncode[163]="968";

acode[164]="PAK",  ncode[164]="92";
acode[165]="PLW",  ncode[165]="680";
acode[166]="PAN",  ncode[166]="507";
acode[167]="PNG",  ncode[167]="675";
acode[168]="PRY",  ncode[168]="595";
acode[169]="PER",  ncode[169]="51";
acode[170]="PHL",  ncode[170]="63";
acode[171]="PCN",  ncode[171]="";
acode[172]="POL",  ncode[172]="48";
acode[173]="PRT",  ncode[173]="351";
acode[174]="PRI",  ncode[174]="787";

acode[175]="QAT",  ncode[175]="974";

acode[176]="REU",  ncode[176]="262";
acode[177]="ROM",  ncode[177]="40";
acode[178]="RUS",  ncode[178]="7";
acode[179]="RWA",  ncode[179]="250";

acode[180]="KNA",  ncode[180]="896";
acode[181]="LCA",  ncode[181]="758";
acode[182]="VCT",  ncode[182]="809";
acode[183]="WSM",  ncode[183]="";
acode[184]="SMR",  ncode[184]="378";
acode[185]="STP",  ncode[185]="239";
acode[186]="SAU",  ncode[186]="966";
acode[187]="SEN",  ncode[187]="221";
acode[188]="SYC",  ncode[188]="248";
acode[189]="SLE",  ncode[189]="232";
acode[190]="SGP",  ncode[190]="65";
acode[191]="SVK",  ncode[191]="421";
acode[192]="SVN",  ncode[192]="386";
acode[193]="SLB",  ncode[193]="677";
acode[194]="SOM",  ncode[194]="252";
acode[195]="ZAF",  ncode[195]="27";
acode[196]="SGS",  ncode[196]="";
acode[197]="ESP",  ncode[197]="34";
acode[198]="LKA",  ncode[198]="94";
acode[199]="SHN",  ncode[199]="";
acode[200]="SPM",  ncode[200]="";
acode[201]="SDN",  ncode[201]="249";
acode[202]="SUR",  ncode[202]="597";
acode[203]="SJM",  ncode[203]="";
acode[204]="SWZ",  ncode[204]="268";
acode[205]="SWE",  ncode[205]="46";
acode[206]="CHE",  ncode[206]="41";
acode[207]="SYR",  ncode[207]="963";

acode[208]="TWN",  ncode[208]="886";
acode[209]="TJK",  ncode[209]="7";
acode[210]="TZA",  ncode[210]="255";
acode[211]="THA",  ncode[211]="66";
acode[212]="TGO",  ncode[212]="228";
acode[213]="TKL",  ncode[213]="690";
acode[214]="TON",  ncode[214]="676";
acode[215]="TTO",  ncode[215]="868";
acode[216]="TUN",  ncode[216]="216";
acode[217]="TUR",  ncode[217]="90";
acode[218]="TKM",  ncode[218]="993";
acode[219]="TCA",  ncode[219]="649";
acode[220]="TUV",  ncode[220]="688";

acode[221]="UGA",  ncode[221]="256";
acode[222]="UKR",  ncode[222]="380";
acode[223]="ARE",  ncode[223]="971";
acode[224]="GBR",  ncode[224]="44";
acode[225]="USA",  ncode[225]="001";
acode[226]="UMI",  ncode[226]="";
acode[227]="URY",  ncode[227]="598";
acode[228]="UZB",  ncode[228]="998";

acode[229]="VUT",  ncode[229]="678";
acode[230]="VEN",  ncode[230]="58";
acode[231]="VNM",  ncode[231]="84";
acode[232]="VGB",  ncode[232]="";
acode[233]="VIR",  ncode[233]="";

acode[234]="WLF",  ncode[234]="681";
acode[235]="ESH",  ncode[235]="";

acode[236]="YEM",  ncode[236]="967";
acode[237]="YUG",  ncode[237]="381";
acode[238]="ZMB",  ncode[238]="260";
acode[239]="ZWE",  ncode[239]="263";

function changecode_bak(frm,textObj)
{
//	alert(frm[0].name)
	var fm = frm
	var fmNm=frm[0].name
	var x=textObj.selectedIndex;
//	alert(fm(fmNm).CountryLst.selectedIndex);
	 var x=textObj.selectedIndex;
	 fm(fmNm).Country.value = fm(fmNm).CountryLst.options[fm(fmNm).CountryLst.selectedIndex].text;
	 fm(fmNm).telCtyCode.value=ncode[x];
	 fm(fmNm).cellCtyCode.value=ncode[x];
	 fm(fmNm).faxCtyCode.value=ncode[x];
	 fm(fmNm).telCtCode.focus();
}

function changecode(frm,textObj)
{
//	alert(frm[0].name);
	var fm = frm
	var fmNm=frm[0].name
	var x=textObj.selectedIndex;
	 var x=textObj.selectedIndex;
	 fm[fmNm].Country.value = fm[fmNm].CountryLst.options[fm[fmNm].CountryLst.selectedIndex].text;
	 fm[fmNm].telCtyCode.value=ncode[x];
	 fm[fmNm].cellCtyCode.value=ncode[x];
	 fm[fmNm].telCtCode.focus();
}




