
var phonecode = new Array();
phonecode[0] = "";
phonecode[1] = "93";
phonecode[2] = "355";
phonecode[3] = "213";
phonecode[4] = "1-684";
phonecode[5] = "376";
phonecode[6] = "244";
phonecode[7] = "1-264";
phonecode[8] = "672";
phonecode[9] = "1-268";
phonecode[10] = "54";
phonecode[11] = "7";
phonecode[12] = "297";
phonecode[13] = "61";
phonecode[14] = "43";
phonecode[15] = "994";
phonecode[16] = "1-242";
phonecode[17] = "973";
phonecode[18] = "880";
phonecode[19] = "1-246";
phonecode[20] = "375";
phonecode[21] = "32";
phonecode[22] = "501";
phonecode[23] = "229";
phonecode[24] = "1-441";
phonecode[25] = "975";
phonecode[26] = "591";
phonecode[27] = "387";
phonecode[28] = "267";
phonecode[29] = "";
phonecode[30] = "55";
phonecode[31] = "246";
phonecode[32] = "673";
phonecode[33] = "359";
phonecode[34] = "226";
phonecode[35] = "257";
phonecode[36] = "855";
phonecode[37] = "237";
phonecode[38] = "1";
phonecode[39] = "238";
phonecode[40] = "1-453";
phonecode[41] = "236";
phonecode[42] = "235";
phonecode[43] = "56";
phonecode[44] = "86";
phonecode[45] = "852";
phonecode[46] = "853";
phonecode[47] = "61";
phonecode[48] = "672";
phonecode[49] = "57";
phonecode[50] = "269";
phonecode[51] = "242";
phonecode[52] = "682";
phonecode[53] = "506";
phonecode[54] = "225";
phonecode[55] = "385";
phonecode[56] = "53";
phonecode[57] = "357";
phonecode[58] = "420";
phonecode[59] = "243";
phonecode[60] = "45";
phonecode[61] = "253";
phonecode[62] = "1-767";
phonecode[63] = "1-809";
phonecode[64] = "670";
phonecode[65] = "593";
phonecode[66] = "20";
phonecode[67] = "503";
phonecode[68] = "240";
phonecode[69] = "291";
phonecode[70] = "372";
phonecode[71] = "251";
phonecode[72] = "298";
phonecode[73] = "500";
phonecode[74] = "679";
phonecode[75] = "358";
phonecode[76] = "33";
phonecode[77] = "594";
phonecode[78] = "689";
phonecode[79] = "262";
phonecode[80] = "241";
phonecode[81] = "995";
phonecode[82] = "49";
phonecode[83] = "233";
phonecode[84] = "350";
phonecode[85] = "30";
phonecode[86] = "299";
phonecode[87] = "1-473";
phonecode[88] = "590";
phonecode[89] = "1-671";
phonecode[90] = "502";
phonecode[91] = "224";
phonecode[92] = "245";
phonecode[93] = "592";
phonecode[94] = "509";
phonecode[95] = "672";
phonecode[96] = "379";
phonecode[97] = "504";
phonecode[98] = "36";
phonecode[99] = "354";
phonecode[100] = "91";
phonecode[101] = "62";
phonecode[102] = "98";
phonecode[103] = "964";
phonecode[104] = "353";
phonecode[105] = "972";
phonecode[106] = "39";
phonecode[107] = "1-876";
phonecode[108] = "81";
phonecode[109] = "962";
phonecode[110] = "7";
phonecode[111] = "254";
phonecode[112] = "686";
phonecode[113] = "82";
phonecode[114] = "850";
phonecode[115] = "965";
phonecode[116] = "996";
phonecode[117] = "856";
phonecode[118] = "371";
phonecode[119] = "961";
phonecode[120] = "266";
phonecode[121] = "231";
phonecode[122] = "218";
phonecode[123] = "423";
phonecode[124] = "370";
phonecode[125] = "352";
phonecode[126] = "389";
phonecode[127] = "261";
phonecode[128] = "265";
phonecode[129] = "60";
phonecode[130] = "960";
phonecode[131] = "223";
phonecode[132] = "356";
phonecode[133] = "692";
phonecode[134] = "596";
phonecode[135] = "222";
phonecode[136] = "230";
phonecode[137] = "269";
phonecode[138] = "52";
phonecode[139] = "691";
phonecode[140] = "373";
phonecode[141] = "377";
phonecode[142] = "976";
phonecode[143] = "382";
phonecode[144] = "1-664";
phonecode[145] = "212";
phonecode[146] = "258";
phonecode[147] = "95";
phonecode[148] = "264";
phonecode[149] = "674";
phonecode[150] = "977";
phonecode[151] = "599";
phonecode[152] = "687";
phonecode[153] = "64";
phonecode[154] = "505";
phonecode[155] = "227";
phonecode[156] = "234";
phonecode[157] = "683";
phonecode[158] = "672";
phonecode[159] = "1-670";
phonecode[160] = "47";
phonecode[161] = "968";
phonecode[162] = "92";
phonecode[163] = "680";
phonecode[164] = "507";
phonecode[165] = "675";
phonecode[166] = "595";
phonecode[167] = "51";
phonecode[168] = "63";
phonecode[169] = "872";
phonecode[170] = "48";
phonecode[171] = "351";
phonecode[172] = "1";
phonecode[173] = "974";
phonecode[174] = "262";
phonecode[175] = "40";
phonecode[176] = "7";
phonecode[177] = "250";
phonecode[178] = "290";
phonecode[179] = "1-869";
phonecode[180] = "1-758";
phonecode[181] = "508";
phonecode[182] = "1-784";
phonecode[183] = "685";
phonecode[184] = "378";
phonecode[185] = "239";
phonecode[186] = "966";
phonecode[187] = "221";
phonecode[188] = "381";
phonecode[189] = "381";
phonecode[190] = "248";
phonecode[191] = "232";
phonecode[192] = "65";
phonecode[193] = "421";
phonecode[194] = "386";
phonecode[195] = "677";
phonecode[196] = "252";
phonecode[197] = "27";
phonecode[198] = "995";
phonecode[199] = "34";
phonecode[200] = "94";
phonecode[201] = "249";
phonecode[202] = "597";
phonecode[203] = "47";
phonecode[204] = "268";
phonecode[205] = "46";
phonecode[206] = "41";
phonecode[207] = "963";
phonecode[208] = "886";
phonecode[209] = "992";
phonecode[210] = "255";
phonecode[211] = "66";
phonecode[212] = "220";
phonecode[213] = "31";
phonecode[214] = "228";
phonecode[215] = "690";
phonecode[216] = "676";
phonecode[217] = "1-868";
phonecode[218] = "216";
phonecode[219] = "90";
phonecode[220] = "993";
phonecode[221] = "1-649";
phonecode[222] = "688";
phonecode[223] = "256";
phonecode[224] = "380";
phonecode[225] = "971";
phonecode[226] = "44";
phonecode[227] = "1";
phonecode[228] = "1";
phonecode[229] = "598";
phonecode[230] = "998";
phonecode[231] = "678";
phonecode[232] = "58";
phonecode[233] = "84";
phonecode[234] = "1-284";
phonecode[235] = "1-340";
phonecode[236] = "681";
phonecode[237] = "212";
phonecode[238] = "967";
phonecode[239] = "38";
phonecode[240] = "260";
phonecode[241] = "263";


function check_count_change()
{
	var val = document.dataform.country.options[document.dataform.country.selectedIndex].value;

	if(val != document.dataform.country_iso.value)
	{
		if(phonecode[document.dataform.country.selectedIndex] != '')
		{
			var reg=new RegExp("-");
			if(reg.test(phonecode[document.dataform.country.selectedIndex]))
			{
				var ph_arr=phonecode[document.dataform.country.selectedIndex].split('-');
				document.dataform.S_ccode.value ='+'+ph_arr[0];
				document.dataform.S_acode.value =ph_arr[1];
				document.dataform.S_cmobile.value ='+'+ph_arr[0];
				document.dataform.S_acode.style.color= "#000000";
			}
			else
			{
				document.dataform.S_ccode.value = '+'+phonecode[document.dataform.country.selectedIndex];
				document.dataform.S_cmobile.value = '+'+phonecode[document.dataform.country.selectedIndex];
				document.dataform.S_acode.value ='Area Code';
				document.dataform.S_acode.style.color= "#cccccc";
			}
		}
		else
		{
			document.dataform.S_ccode.value = '';
			document.dataform.S_cmobile.value = '';
			document.dataform.S_acode.value ='Area Code';
			document.dataform.S_acode.style.color= "#cccccc";
		}
	}
	document.dataform.country_iso.value = val;
	document.dataform.S_country.value = document.dataform.country.options[document.dataform.country.selectedIndex].text;
}



function set()
{
	var product_detail='';
	for(var i=1; i <= quantity_count; i++)
	{
		var prd = document.getElementById('product'+i).value;
		var qty = document.getElementById('qty'+i).value;

		if(qty)
		{
			prd = prd+'    x    '+qty;
		}

		product_detail = product_detail+prd+'\n';
	}

	if(product_detail != '')
	{
		product_detail = '\n==========================================\n'+product_detail;
	}

	document.getElementById('product_details').value = product_detail;

	var temp2 =document.dataform.Description.value;
	var temp3 = temp2.replace(/\s/gi,"");
	if(temp3.length == 0)
	{
		alert ("Kindly describe your requirement.");
		document.dataform.Description.value='';
		document.dataform.Description.focus();
		return false;
	}

	var salute = document.dataform.S_salute.options[document.dataform.S_salute.selectedIndex].value;

	var f_name = document.dataform.S_name.value;
	if ((f_name.length == 0) || (f_name == "First Name"))
	{
		alert ("Kindly enter your name.");
		document.dataform.S_name.focus();
		document.dataform.S_name.style.color= "#000000";
		return false;
	}
	if(document.dataform.S_name.value)
	{
		var val = document.dataform.S_name.value;
		val = val.replace(/\s/g, "");
		if(val.length == 0)
		{
			alert ("Kindly enter your name.");
			document.dataform.S_name.focus();
			document.dataform.S_name.style.color= "#000000";
			return false;
		}
	}

	if (document.dataform.S_email.value.length == 0)
	{
		alert("Kindly enter your Email ID.");
		document.dataform.S_email.focus();
		return false;
	}
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.dataform.S_email.value)))
	{
			alert("Invalid Email ID. Kindly enter the correct ID.");
			document.dataform.S_email.focus();
			return (false);
	}

	if (document.dataform.country.selectedIndex == "")
	{
		alert ("Kindly select your country name.");
		document.dataform.country.focus();
		return false;
	}

	if (document.dataform.S_ccode.value.length == 0 || document.dataform.S_ccode.value == "Country Code")
	{
		alert ("Kindly enter your country code.");
		document.dataform.S_ccode.focus();
		return false;
	}

/*----------to check valid country code--------------*/
	if (isNaN(document.dataform.S_ccode.value))
	{
		alert ("Kindly enter valid country code number.");
		document.dataform.S_ccode.focus();
		return false;
	}

	if(document.dataform.S_acode.value > ""  && document.dataform.S_acode.value != "Area Code")
	{
		if (isNaN(document.dataform.S_acode.value))
		{
			alert ("Kindly enter valid area code number.");
			document.dataform.S_acode.focus();
			return false;
		}
	}

	if ((document.dataform.S_phone.value.length == 0 || document.dataform.S_phone.value == "Phone Number") && (document.dataform.S_mobile.value.length == 0 || document.dataform.S_mobile.value == "Mobile / Cell Phone Number"))
	{
		alert ("Kindly enter either Phone Number or Mobile Number.");
		document.dataform.S_phone.focus();
		document.dataform.S_phone.style.color= "#000000";
		return false;
	}


	if(document.dataform.S_phone.value)
	{
		var val = document.dataform.S_phone.value;
		val = val.replace(/\s/g, "");
		if(val.length == 0)
		{
			alert ("Kindly enter valid phone number.");
			document.dataform.S_phone.focus();
			document.dataform.S_phone.style.color= "#000000";
			return false;
		}
	}

	if ((document.dataform.S_phone.value.length > "") && (document.dataform.S_phone.value != "Phone Number"))
	{
		if(isNaN(document.dataform.S_phone.value))
		{
			alert ("Kindly enter valid phone number.");
			document.dataform.S_phone.focus();
			document.dataform.S_phone.style.color= "#000000";
			return false;
		}
	}


/*----------to check valid mobile no--------------*/
	if((document.dataform.S_cmobile.value > "")  && (document.dataform.S_cmobile.value != "Country Code"))
	{
		if (isNaN(document.dataform.S_cmobile.value))
		{
			alert ("Kindly enter valid country code number.");
			document.dataform.S_cmobile.focus();
			return false;
		}
	}


	if(document.dataform.S_mobile.value)
	{
		var val = document.dataform.S_mobile.value;
		val = val.replace(/\s/g, "");
		if(val.length == 0)
		{
			alert ("Kindly enter valid mobile / cell phone number.");
			document.dataform.S_mobile.focus();
			document.dataform.S_mobile.style.color= "#000000";
			return false;
		}
	}

	if((document.dataform.S_mobile.value > "")  && (document.dataform.S_mobile.value != "Mobile / Cell Phone Number"))
	{
		if (isNaN(document.dataform.S_mobile.value))
		{
			alert ("Kindly enter valid mobile / cell phone number.");
			document.dataform.S_mobile.focus();
			return false;
		}
	}

	var captcha_txt = document.getElementsByName("captcha_text");
	var captcha_txt_len = captcha_txt.length;
	if(captcha_txt_len == 1)
	{
		if (document.dataform.captcha_text.value.length == 0)
		{
			alert ("Kindly enter the code as appearing in the Image.");
			document.dataform.captcha_text.focus();
			return false;
		}
	}

	if (document.dataform.S_acode.value == "Area Code")
	{
		document.dataform.S_acode.value="";
	}

	if (document.dataform.S_cmobile.value == "Country Code")
	{
		document.dataform.S_cmobile.value="";
	}

	if (document.dataform.S_phone.value == "Phone Number")
	{
		document.dataform.S_phone.value="";
	}

	if (document.dataform.S_mobile.value == "Mobile / Cell Phone Number")
	{
		document.dataform.S_mobile.value="";
	}

	if (document.dataform.S_lname.value == "Last Name")
	{
		document.dataform.S_lname.value="";
	}

	if (document.dataform.S_city.value == "City")
	{
		document.dataform.S_city.value="";
	}

	if (document.dataform.S_pin.value == "Postal Code")
	{
		document.dataform.S_pin.value="";
	}

	if (document.dataform.S_state.value == "State")
	{
		document.dataform.S_state.value="";
	}

	newCookie = document.dataform.S_name.value;
	newCookie +="|"+document.dataform.S_email.value;
	newCookie +="|"+document.dataform.S_phone.value;
	newCookie +="|"+document.dataform.S_streetaddress.value;
	newCookie +="|"+document.dataform.S_city.value;
	newCookie +="|"+document.dataform.S_pin.value;
	newCookie +="|"+document.dataform.country.selectedIndex;
	newCookie +="|"+document.dataform.S_organization.value;
	newCookie +="|"+document.dataform.S_ccode.value;
	newCookie +="|"+document.dataform.S_acode.value;
	newCookie +="|"+document.dataform.S_salute.value;
	newCookie +="|"+document.dataform.S_lname.value;
	newCookie +="|"+document.dataform.S_mobile.value;
	setCookie("newImeshID",newCookie);
	return true;
}

function setCookie(name, value)
{
	expires = new Date();
	expires.setTime (expires.getTime() + 24 * 60 * 60 * 150 * 1000);
	
	if (value.length > 0)
 	document.cookie = name + "=" + escape(value)+ ";"+"expires=" + expires.toGMTString()+";"
}


function getCookie(Name)
{
	var search = Name + "="
	if (document.cookie.length > 0)
	{
		offset = document.cookie.indexOf(search)
		if (offset != -1) 
		{ // if cookie exists
			offset += search.length // set index of beginning of value
			end = document.cookie.indexOf(";", offset) // set index of end of cookie value
			if (end == -1) end = document.cookie.length
				return unescape(document.cookie.substring(offset, end))
		}
	}
	return "";
}

if( (cookie = getCookie("newImeshID")) > "")
{
	Values = cookie.split("|");

	if (Values.length >= 7)
	{
		if (Values[0]) document.dataform.S_name.value = Values[0];
		if (Values[1]) document.dataform.S_email.value = Values[1];
		if (Values[2]) document.dataform.S_phone.value = Values[2];
		if (Values[3]) document.dataform.S_streetaddress.value=Values[3];
		if (Values[4]) document.dataform.S_city.value=Values[4];
		if (Values[5]) document.dataform.S_pin.value=Values[5];
		if (Values[6])
		{
			document.dataform.country.options[Values[6]].selected=true;
			document.dataform.S_country.value = document.dataform.country.options[document.dataform.country.selectedIndex].text;
		}
		if (Values[7]) document.dataform.S_organization.value = Values[7];
		if (Values[8])
		{
			document.dataform.S_ccode.value = Values[8];
			document.dataform.S_cmobile.value = Values[8];
		}
		if (Values[9]) document.dataform.S_acode.value = Values[9];
		if (Values[10]) document.dataform.S_salute.value = Values[10];
		if (Values[11]) document.dataform.S_lname.value = Values[11];
		if (Values[12]) document.dataform.S_mobile.value = Values[12];
	}
}


var is_input = document.URL.indexOf('?');
var pcode = '';
var pname = '';

if (is_input != -1)
{
	addr_str = document.URL.substring(is_input+1, document.URL.length);
	strarr = addr_str.split("&");
	pname = unescape((strarr[0].split("="))[1]);
	pname = pname.replace(/\+/g," ");
	if(strarr[1])
	{
		pcode_name = unescape((strarr[1].split("="))[0]);
		pcode_value = unescape((strarr[1].split("="))[1]);
	}
	else
	{
		pcode_name = '';
		pcode_value = '';
	}
}
	
/*----For Description Text Status----*/

var fieldlimiter={

defaultoutput: "<b>[int]</b> characters remaining in your input limit.", //default message that gets output to statusid element

uncheckedkeycodes: /(8)|(13)|(16)|(17)|(18)/, //keycodes that are not checked, even when limit has been reached. See http://www.javascriptkit.com/jsref/eventkeyboardmouse.shtml for avail keycodes

limitinput:function(e, config){
	var e=window.event || e
	var thefield=config.thefield
	var keyunicode=e.charCode || e.keyCode
	if (!this.uncheckedkeycodes.test(keyunicode)){
		if (thefield.value.length>=config.maxlength){
			if (e.preventDefault)
				e.preventDefault()
			return false
		}
	}
},

showlimit:function(config){
	var thefield=config.thefield
	var statusids=config.statusids
	var charsleft=config.maxlength-thefield.value.length
	if (charsleft<0) //if user has exceeded input limit (possible if cut and paste text into field)
		thefield.value=thefield.value.substring(0, config.maxlength) //trim input
	for (var i=0; i<statusids.length; i++){
		var statusdiv=document.getElementById(statusids[i])
		if (statusdiv) //if status DIV defined
			statusdiv.innerHTML=this.defaultoutput.replace("[int]", Math.max(0, charsleft))
	}
	config.onkeypress.call(thefield, config.maxlength, thefield.value.length)
},

cleanup:function(config){
	for (var prop in config){
		config[prop]=null
	}
},


addEvent:function(targetarr, functionref, tasktype){
	if (targetarr.length>0){
		var target=targetarr.shift()
		if (target.addEventListener)
			target.addEventListener(tasktype, functionref, false)
		else if (target.attachEvent)
			target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)})
		this.addEvent(targetarr, functionref, tasktype)
	}
},

setup:function(config){
	if (config.thefield){ //if form field exists
		config.onkeypress=config.onkeypress || function(){}
		config.thefield.value=config.thefield.value
		this.showlimit(config)
		this.addEvent([window], function(e){fieldlimiter.showlimit(config)}, "load")
		this.addEvent([window], function(e){fieldlimiter.cleanup(config)}, "unload")		
		this.addEvent([config.thefield], function(e){return fieldlimiter.limitinput(e, config)}, "keypress")
		this.addEvent([config.thefield], function(){fieldlimiter.showlimit(config)}, "keyup")
	}
}

}



if(document.dataform.S_name.value != "First Name")
{
	document.dataform.S_name.style.color = "#000000";
}

if(document.dataform.S_lname.value != "Last Name")
{
	document.dataform.S_lname.style.color = "#000000";
}


if(document.dataform.S_city.value != "City")
{
	document.dataform.S_city.style.color = "#000000";
}


if(document.dataform.S_state.value != "State")
{
	document.dataform.S_state.style.color = "#000000";
}


if(document.dataform.S_pin.value != "Postal Code")
{
	document.dataform.S_pin.style.color = "#000000";
}


if(document.dataform.S_acode.value != "Area Code")
{
	document.dataform.S_acode.style.color = "#000000";
}


if(document.dataform.S_phone.value != "Phone Number")
{
	document.dataform.S_phone.style.color = "#000000";
}

if (document.dataform.S_mobile.value != "Mobile / Cell Phone Number")
{
	document.dataform.S_mobile.style.color = "#000000";
}
