//Post Form Javascripts

// $Id: $
// $HeadURL: $

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 tdescription()
{
	if(document.postForm.desc.value=='Please enter your buying requirements in detail. Provide key information like product specifications, estimated quantity etc.')
	{
		document.postForm.desc.value='';
	}
}

function settext()
{
	if(document.postForm.desc.value=='')
	{
		document.postForm.desc.value='Please enter your buying requirements in detail. Provide key information like product specifications, estimated quantity etc.';
	}
}
// // Start of on focus js
function tes(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("testimonial").getElementsByTagName("div"); 
		
			for (var i=0; i<ar.length; i++){
				if(ar[i].className == "hepl_test") {
					ar[i].className = "hepl_test_off";
				}
			}
		document.getElementById(obj).className = "hepl_test";
	}
}


function hide_t(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("testimonial").getElementsByTagName("div"); 
		
			for (var i=0; i<ar.length; i++){
				if(ar[i].className == "hepl_test_off") {
					ar[i].className = "hepl_test_off";
				}
			}
		document.getElementById(obj).className = "hepl_test_off";
	}
}



function form_tst()
{
if(document.getElementById('form_tst1').style.display == "none")
{
document.getElementById('form_tst1').style.display=""; 
} 
else
{
document.getElementById('form_tst1').style.display="none"; 
}
}


function value_edit(input_border)
{
document.getElementById(input_border).className="select_sp_new1";
}

function value_edit1(input_border)
{
document.getElementById(input_border).className="select_sp_new";
}


function edit(form)
{
document.getElementById(form).onkeypress="return true";
}






function t_description1()
{
	if
	(
		document.form2.first.value=='First Name')	{
		document.form2.first.value='';
	}		
}

function settext1()
{
	if 
	(document.form2.first.value=='')
		{
		document.form2.first.value='First Name';
		}
}	

function t_description2()
{
	if
	(
		document.form2.last.value=='Last Name')	{
		document.form2.last.value='';
	}		
}

function settext2()
{
	if 
	(document.form2.last.value=='')
		{
		document.form2.last.value='Last Name';
		}
}	


function product()
{
document.getElementById('product').style.display="block";
document.getElementById('ad_m').style.display="none";
}

// // End of on focus js




//Captcha code Starts
var d = new Date();
var epoch_time =(d.getTime()-d.getMilliseconds())/1000;
var randomnumber=Math.floor(Math.random()*9999);
var randomnumber1=Math.floor(Math.random()*9999);
var ran_num=randomnumber+"."+epoch_time+"."+randomnumber1;

// Remove by Gunjan
// var url="http://www.media4trade.com/captchaserver?cRef="+ran_num+"&style=2";
var url="/cgi/get_captcha.cgi?cref="+ran_num+"&style=2";
function setCaptchaRef()
{
	document.postForm.captcha_ref.value = ran_num;
}
//Captcha code Ends

function ajaxFunction()
{
	var xmlHttp;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	
	return xmlHttp;
}

function rem_default()
{
	if(document.getElementById("txtTitle").value=="Looking for..." || document.getElementById("txtTitle").value=="Please write your prdouct name here...")
	{
		document.getElementById("txtTitle").value='';
	}
}

function get_keywords()
{
	var xmlHttp=ajaxFunction();
	var ofrTitle=document.getElementById("txtTitle").value;
	if(xmlHttp)
	{
		if(ofrTitle && ofrTitle.length > 2 && ofrTitle != "Looking for...")
		{
			xmlHttp.onreadystatechange=function()
			{
				if(xmlHttp.readyState==4)
				{
				document.getElementById("txtKeywords").value=xmlHttp.responseText;
				}
			}
			xmlHttp.open("GET","/cgi/eto-dirsearch-mcat.mp?ss="+escape(ofrTitle),true);
			xmlHttp.send(null);
		}
	}
}

function get_area()
{
	var xmlHttp=ajaxFunction();
	var city=document.getElementById("txtCity").value;
	if(xmlHttp)
	{
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
			document.getElementById("txtArea").value=xmlHttp.responseText;
			}
		}
		xmlHttp.open("GET","/cgi/GetAreaCode.mp?city="+escape(city),true);
		xmlHttp.send(null);
	}
}

function trim(sString)
{ 
	while (sString.substring(0,1) == ' ')
	{
	sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
	sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function check_count_change()
{
	var val = document.postForm.country.options[document.postForm.country.selectedIndex].value;
	//alert(val);
	if(val == 0)
	{
		document.postForm.ph_country.value='';
		return false;
	}
	//alert(document.postForm.country_iso.value);
	if(phonecode[document.postForm.country.selectedIndex] != '')
	{
		var a = phonecode[document.postForm.country.selectedIndex].split("-");
		document.postForm.ph_country.value = a[0];

		if(a[1] != undefined)
		{
		document.postForm.ph_area.value = a[1];
		}
	}
	document.postForm.country_iso.value = val;
	document.postForm.country_name.value = document.postForm.country.options[document.postForm.country.selectedIndex].text;
}

function assign_hidden_param(Form)
{
	if(!document.getElementById('pagenotfound'))
	{
		if (document.referrer && document.referrer!="")
		{
			Form.page_referrer.value=document.referrer;
		}
	}

	if(location.hostname)
	{
		Form.referer_url.value="http://"+location.hostname;
	}

	Form.usr_pass.value = Math.floor(Math.random()*9999)+100000;
	
	var is_input = document.URL.indexOf('?');
	
	if (is_input != -1)
	{
		var x;
		var addr_str='';
		var pname='';
		var strarr = new Array();
		
		addr_str = document.URL.substring(is_input+1, document.URL.length);
		strarr = addr_str.split("&");
		
		for (x in strarr)
		{
			if((strarr[x].split("="))[0] == "ref")
			{ 
				pname = unescape((strarr[x].split("="))[1]);
			}
		}
		
		Form.ref.value = pname;
	}
	if(trim(Form.title.value) != "")
	{
		var title = Form.title.value;
		//if(trim(Form.title2.value) != "")
		//	title +=","+Form.title2.value;
		//if(trim(Form.title3.value) != "")
		//	title +=","+Form.title3.value;
		//if(trim(Form.title4.value) != "")
		//	title +=","+Form.title4.value;

		//Form.title.value = title;
	}
}

function Check_ModReg(Form)
{
	assign_hidden_param(Form); // setting the hidden parameters of states & cites ...

	/* Trade offer feilds checking Starts... */

	if (Form.nature_of_business)
	{
		var check = 0;
		for(var i = 0; i < Form.nature_of_business.length; i++)
		{
			if(Form.nature_of_business[i].checked == true)
			{
				check = 1;
			}
		}
		if(check == 0)
		{
			alert("Please tell us your Nature of Business");
			Form.nature_of_business[0].focus();
			return false;
		}
	}

	if(trim(Form.title.value) == "") {
		alert("Kindly enter your Products.");
		Form.title.focus();
		return false;
	}

	if(Form.title.value.length > 100) {
		alert("Your product name should not be greater than 100 charecters.");
		Form.title.focus();
		return false;
	}

	if(trim(Form.desc.value) == "" || trim(Form.desc.value) == "Please enter your buying requirements in detail. Provide key information like product specifications, estimated quantity etc." ) {
		alert("Kindly describe your currect requirements.");
		Form.desc.focus();
		return false;
	}

	if(Form.desc.value.length > 1200) {
		alert("Your description should not be greater than 1200 charecters.");
		Form.desc.focus();
		return false;
	}

	if(Form.email.value == "" ) {
		alert("Kindly enter your E-mail ID.");
		Form.email.focus();
		return false;
	}
	else if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(Form.email.value))) {
			alert("Invalid Email ID. Kindly enter the correct ID.");
			Form.email.focus();
			return (false);
	}


	if(Form.first_name.value == "" ) 
	{
		alert("Kindly enter your Contact Name.");
		Form.first_name.focus();
		return false;
	}

	if (Form.qty && Form.qty.value == "")
	{
		alert("Please enter your Quantity.");
		Form.qty.focus();
		return false;
	}

	/* Trade offer feilds checking Ends... */
	
	/* Gluser feilds checking Starts... */
	if(Form.comp_name.value == "" ) {
		alert("Kindly enter your Company Name.");
		Form.comp_name.focus();
		return false;
	}
	
	if (Form.website.value.length != 0)
	{
		if(Form.website.value.indexOf(" ") != -1)	{
		alert("Kindly enter correct URL without any spaces in it.");
		Form.website.focus();
		return false;
		}
		if(Form.website.value.indexOf("@") != -1)	{
		alert("Invalid Website ! Kindly enter correct website.");
		Form.website.focus();
		return false;
		}
		if(Form.website.value.indexOf(".") == -1)	{
		alert("Invalid Website ! Kindly enter correct website.");
		Form.website.focus();
		return false;
		}
		validarr = Form.website.value.split(".");
	
		if(validarr[0].length<2)   	{
		alert("Invalid Website ! Kindly enter correct website.");
		Form.website.focus();
		return false;
		}
		if(validarr[1].length<2)   	{
		alert("Invalid Website ! Kindly enter correct website.");
		Form.website.focus();
		return false;
		}
	}

	if(Form.country_name.value == "" || Form.country.value == 0) 
	{
		alert("Kindly select the Country.");
		Form.country.focus();
		return false;
	}
	
	if(Form.ph_country.value == "") {
		alert("Kindly enter country code for Telephone Number.");
		Form.ph_country.focus();
		return false;
	}
	else if(Form.ph_no.value == "") {
		alert("Kindly enter your Telephone Number.");
		Form.ph_no.focus();
		return false;
	}

	//fax start
	if(Form.fax_country && Form.fax_country.value.length > 6) 
	{
		alert("Fax (Country Code) should not exceed 6 characters.");
		Form.fax_country.focus();
		return false;
	}
	if(Form.fax_area && Form.fax_area.value !='') 
	{
		if(isNaN(Form.fax_area.value))
		{
			alert("Fax (Area Code) should be an integer value.");
			Form.fax_area.focus();
			return false;
		}

		if(Form.fax_area.value.length > 6) 
		{
			alert("Fax (Area Code) should not exceed 6 characters.");
			Form.fax_area.focus();
			return false;
		}
	}
	
	if(Form.fax_no && Form.fax_no.value.length > 35) 
	{
		alert("Fax (Number) should not exceed 35 characters.");
		Form.fax_no.focus();
		return false;
	}
	//fax end

	if ((Form.captcha_text) && Form.captcha_text.value.length == 0)  {
			alert ("Kindly enter the code as appearing in the Image.");
			Form.captcha_text.focus();
			return false;
	}

	if (Form.first_name.value.length  > 20)
	{
		alert("First Name should not exceed 20 characters.");
		Form.first_name.focus();
		return false;
	}
// 	if (Form.last_name.value.length  > 20)
// 	{
// 		alert("Last Name should not exceed 20 characters.");
// 		Form.last_name.focus();
// 		return false;
// 	}
	if (Form.email.value.length > 100)
	{
		alert("Email should not exceed 100 characters.");
		Form.email.focus();
		return false;
	}
	
	if(Form.country_name.value.length > 40) {
		alert("Country Name should not exceed 40 characters.");
		Form.country_name.focus();
		return false;
	}
	if(Form.ph_country.value.length > 6) {
		alert("Telephone (Country Code) should not exceed 6 characters.");
		Form.ph_country.focus();
		return false;
	}
	if(Form.ph_area.value !='') {
		if(isNaN(Form.ph_area.value))
		{
			alert("Telephone (Area Code) should be an integer value.");
			Form.ph_area.focus();
			return false;
		}
	}
	if(Form.ph_area.value.length > 6) {
		alert("Telephone (Area Code) should not exceed 6 characters.");
		Form.ph_area.focus();
		return false;
	}
	if(Form.ph_no.value.length > 35) {
		alert("Telephone (Number) should not exceed 35 characters.");
		Form.ph_no.focus();
		return false;
	}
	
	if(Form.comp_name.value.length > 100) {
		alert("Company Name should not exceed 100 characters.");
		Form.comp_name.focus();
		return false;
	}

	newCookie =Form.email.value;
	newCookie +="|"+Form.salute.options[Form.salute.selectedIndex].value;
	newCookie +="|"+Form.first_name.value;
	newCookie +="|"+Form.comp_name.value;
	newCookie +="|"+Form.website.value;
	newCookie +="|"+Form.country.options[Form.country.selectedIndex].value;
	newCookie +="|"+Form.ph_country.value;
	newCookie +="|"+Form.ph_area.value;
	newCookie +="|"+Form.ph_no.value;

	setCookie("newImeshCTL",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 get()
{
	if(document.postForm.desc.value=='Please enter your buying requirements in detail. Provide key information like product specifications, estimated quantity etc.')
	{
		document.postForm.desc.className="txt-input2";
	}
	else
	{
		document.postForm.desc.className="txt-input3";
	}

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

		if (Values.length >= 9)
		{
			if (document.postForm.email.value.length == 0)
				document.postForm.email.value = Values[0];
			if(Values[1] == 'Mr.')
			{
				document.postForm.salute.selectedIndex=0;
			}
			else
			{
				document.postForm.salute.selectedIndex=1;
			}
			if (document.postForm.first_name.value.length == 0)
				document.postForm.first_name.value=Values[2];
/*			if (document.postForm.last_name.value.length == 0)
				document.postForm.last_name.value=Values[3];*/
			if (document.postForm.comp_name.value.length == 0)
				document.postForm.comp_name.value=Values[3];
			if (document.postForm.website.value.length == 0)
				document.postForm.website.value=Values[4];

			for (i=0;i<241;i++)
			{
				if (document.postForm.country.options[i].value.toUpperCase() == Values[5].toUpperCase()) {
				break;
				}
			}
			if (i == 241)
			{
				if (document.postForm.country.selectedIndex == 0)
					document.postForm.country.selectedIndex=0;
			}
			else
			{
				if (document.postForm.country.selectedIndex == 0)
					document.postForm.country.selectedIndex=i;
			}

			if (document.postForm.ph_country.value.length == 0)
				document.postForm.ph_country.value=Values[6];
			if (document.postForm.ph_area.value.length == 0)
				document.postForm.ph_area.value=Values[7];
			if (document.postForm.ph_no.value.length == 0)
				document.postForm.ph_no.value=Values[8];

			document.postForm.country_name.value=document.postForm.country.options[document.postForm.country.selectedIndex].text;
		}
	}
return true;
}

function getCookie(Name)
{
	var search = Name + "="
	if (document.cookie.length > 0)
	{ // if there are any cookies
		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 "";
}


function productcode()
{
	//Getting parameter name from url starts
	var is_input = document.URL.indexOf('?');

	var code = '';
	if (is_input != -1)
	{
		addr_str = document.URL.substring(is_input+1, document.URL.length);
		strarr = addr_str.split("&");
		var param_nam = unescape((strarr[0].split("="))[0]);
		if(param_nam == "code")
		{
			code = unescape((strarr[0].split("="))[1]);
			code = code.replace(/\+/g," ");
		}
	}
	//Getting parameter name from url ends
	//End
	if(code)
	{
		document.postForm.title.value = code;
	}
}


function tsearch()
{

	if
	(document.getElementById('sinput').value=="Product Search")	
		{
		document.getElementById('sinput').value="";
		}		
}

function srchpro()
{
	if 
	(document.getElementById('sinput').value=="")
		{
		document.getElementById('sinput').value="Product Search";
		}
}	



