
// For all scripts running on AJAX online if and only if AJAX to runned more than once in a same form.somesh
// Start
function showHint1(str,sitename,geturl) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request");
		return;
	}
	var url=sitename+geturl;
	url=url+"&q="+str;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged1;	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null)
}
// End


function stateChanged1() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		document.getElementById("txtHint1").innerHTML=xmlHttp.responseText;
	} 
}

function GetXmlHttpObject() { 
	var objXMLHttp=null;
	if (window.XMLHttpRequest) {
		objXMLHttp=new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	return (objXMLHttp);
} 


////////////////////////////////ajax chk//////////////
var xmlHttp 
function Check_Availability1(url, displayitem) {
	xmlHttp=GetXmlHttpObject();
	//document.getElementById(displayitem).innerHTML="Loading............";
	if (xmlHttp==null) {	
		alert ("Your browser does not support AJAX!");
		return;
	} 
	url =url+"&sid="+Math.random();		
	xmlHttp.onreadystatechange=function stateChanged() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {			
			if(xmlHttp.responseText.length>0) {			
				document.getElementById("txtHint").innerHTML=xmlHttp.responseText;							
				if (xmlHttp.responseText=="<font color=red>incorrect Email ID</font>" || xmlHttp.responseText=="<font color=red>Email ID already exist.</font>") {			
					document.joinForm.username.focus();
					document.getElementById('txtHint').style.display = 'block'; 
					return false;
				}
			}
			else {
				document.getElementById("txtHint").innerHTML="";
				document.getElementById('txtHint').style.display = 'none'; 
			}
		}
	};
	
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function chk3() {
	if (chktrim(document.joinForm.detailReq.value).length<=20) {
		alert("Your Message should be minimum 20 characters");
		document.joinForm.detailReq.focus();
		return false;
	}
}
var pop = '';
function openSave(detl2) {
	if (pop && !pop.closed) {
		pop.close();
	}
	pop=eval("window.open('trade-search.php?id=msgsave&id1=msgRep&msgDetail="+detl2+"','NewWIN','chrome[4],toolbar=no,left=10,top=5,width=480,height=400,directories=no,menubar=no,SCROLLBARS=yes')");
	if (!pop.opener) popUpWin.opener = self;
}

function openwin1(file,Iwidth,Iheight) {
      var newWin1=window.open(file,'iypWin2','x=0,y=0,toolbar=no,location=no,directories=no,status=no,scrollbars=yes, copyhistory=no,width='+Iwidth+',height='+Iheight+',screenX=0,screenY=0,left=20,top=20');
}

function openwin4(file,Iwidth,Iheight) {
      var newWin1=window.open(file,'nWin4','x=0,y=0,toolbar=no,location=no,directories=no,status=yes,scrollbars=yes, copyhistory=no,width='+Iwidth+',height='+Iheight+',screenX=0,screenY=0,left=20,top=20');
}


function b2b_search(chk1) {		

	if (chk1.term.value=="" || chk1.term.value=="Enter Keywords Here . . ." ) {		
  		alert("Enter Tradelead Keyword");
  		chk1.term.focus();
  		return false;
	}
}


function chk_joinnow() {
	if (chktrim(document.joinForm.detailReq.value).length<=20) {
		alert("Your Message should be minimum 20 characters");
		document.joinForm.detailReq.focus();
		return false;
	}			
	
	if (chktrim(document.joinForm.your_name.value).length==0) {
		alert("Enter your name");
		document.joinForm.your_name.focus();
		return false;
	}	
	if (chktrim(document.joinForm.comp_name.value).length==0) {
		alert("Enter your company name");
		document.joinForm.comp_name.focus();
		return false;
	}					
	if (chktrim(document.joinForm.username.value).length == 0) {
		alert("E-mail ID can't be left blank");
		document.joinForm.username.focus();
		return false;
	}
	if (document.joinForm.username.value.indexOf('@') == -1) {
		alert("Error in Email ID");
		document.joinForm.username.focus();
		return false;
	}
	if (document.joinForm.username.value.indexOf('.') == -1) {
		alert("Error in Email ID");
		document.exist_user.user_name.focus();
		return false;
	}
	if (document.joinForm.username.value.indexOf('@') !=  document.joinForm.username.value.lastIndexOf('@')) {
		alert("Please Specify One Email ID only");
		document.joinForm.username.focus();
		return false;
	}
	if (chktrim(document.joinForm.password.value).length==0) {
		alert("Enter Your Password");
		document.joinForm.password.focus();
		return false;
	}					
	
	
	if (document.joinForm.country.options[document.joinForm.country.selectedIndex].value=="")  {
      	alert("Select your Country");
      	document.joinForm.country.focus();
      	return false;
   	}
	
	if (chktrim(document.joinForm.street_address.value).length ==0) {
		alert("Enter your Street Address");
		document.joinForm.street_address.focus();
		return false;
	}
	if (!parseInt(document.joinForm.ph_ccode.value)) {
		alert("Incorrect Phone  - Country Code");
		document.joinForm.ph_ccode.focus();
		return false;
	}
	if (chktrim(document.joinForm.ph_acode.value).length ==0) {
		alert("Enter Phone Number - Area Code");
		document.joinForm.ph_acode.focus();
		return false;
	}
	if (!parseInt(document.joinForm.ph_acode.value)) {
		alert("Incorrect Phone - Area Code");
		document.joinForm.ph_acode.focus();
		return false;
	}
	if (chktrim(document.joinForm.ph_ccode.value).length ==0) {
		alert("Enter Phone Number - Country Code");
		document.joinForm.ph_ccode.focus();
		return false;
	}
	if (chktrim(document.joinForm.ph_number.value).length ==0) {
		alert("Enter Phone Number");
		document.joinForm.ph_number.focus();
		return false;
	}
	if (!parseInt(document.joinForm.ph_number.value)) {
		alert("Incorrect Phone Number");
		document.joinForm.ph_number.focus();
		return false;
	}	
	if (document.joinForm.bus_ty.options[document.joinForm.bus_ty.selectedIndex].value=="")  {
      	alert("Select your Business Type");
      	document.joinForm.bus_ty.focus();
      	return false;
   	}
}

function chk2() {
   	document.joinForm.charlen.value=document.joinForm.detailReq.value.length;
	if (document.joinForm.detailReq.value.length>2000) {
		alert("Your Message has been exceed the 2000 characters");
		document.joinForm.detailReq.focus();
		return false;
	}
}
	
function chktrim(inputString) {
	if (typeof inputString != "string") {
		return inputString;
	}

	var retValue = inputString;
	var ch = retValue.substring(0, 1);
	while (ch == " ") {
		retValue = retValue.substring(1, retValue.length);
		ch = retValue.substring(0, 1);
	}
	ch = retValue.substring(retValue.length-1, retValue.length);
	while (ch == " ") {
		retValue = retValue.substring(0, retValue.length-1);
		ch = retValue.substring(retValue.length-1, retValue.length);
	}
	while (retValue.indexOf("  ") != -1) {
		retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
	}
	return retValue;
}

function chk_login1(objfrm) {
	   
	if (objfrm.user_name.value.length == 0) {
		
      alert("E-mail ID can't be left blank");
      objfrm.user_name.focus();
      return false;
   }
      
   if (objfrm.user_name.value.indexOf('@') == -1) {
	   
      alert("Error in Email ID");
      objfrm.user_name.focus();
      return false;
   }
   if (objfrm.user_name.value.indexOf('.') == -1) {
	   
      alert("Error in Email ID");
      objfrm.user_name.focus();
      return false;
   }
   if (objfrm.user_name.value.indexOf('@') !=  objfrm.user_name.value.lastIndexOf('@')) {
      alert("Please Specify One Email ID only");
      objfrm.user_name.focus();
      return false;
   }
        		
   if (objfrm.pass_word.value.length==0) {
      alert("Enter Your Password ");
      objfrm.pass_word.focus();
      return false; 
   }
   //To check Indiamart, alibaba etc words in email field
   if(isProhibited(objfrm.user_name)){
   		objfrm.action="../contact-us.htm?msg=err";
   		objfrm.submit;
   		return true;
   }
   return true;
}




function chk_login(objfrm) {
	
	if (chktrim(document.joinForm.detailReq.value).length<=20) {
		
		alert("Your Message should be minimum 20 characters");
		document.joinForm.detailReq.focus();
		return false;
	}			
	  
	if (objfrm.user_name.value.length == 0) {
		
      alert("E-mail ID can't be left blank");
      objfrm.user_name.focus();
      return false;
   }
      
   if (objfrm.user_name.value.indexOf('@') == -1) {
      alert("Error in Email ID");
      objfrm.user_name.focus();
      return false;
   }
   if (objfrm.user_name.value.indexOf('.') == -1) {
      alert("Error in Email ID");
      objfrm.user_name.focus();
      return false;
   }
   if (objfrm.user_name.value.indexOf('@') !=  objfrm.user_name.value.lastIndexOf('@')) {
      alert("Please Specify One Email ID only");
      objfrm.user_name.focus();
      return false;
   }
        		
   if (objfrm.pass_word.value.length==0) {
      alert("Enter Your Password ");
      objfrm.pass_word.focus();
      return false; 
   }   
   return true;
}

function catg_search1(chk1) {

	if ( chktrim(chk1.term.value).length <=1 || ( chktrim(chk1.term.value).length >=1 && chk1.term.value=="Enter Keywords here...")) {
		alert("Enter Product / Services Keyword(s)");
		chk1.term.focus();
		return false;
	}
	if (chk1.busty.options[chk1.busty.selectedIndex].value == "") {
		alert("Select a Searching Category");
		chk1.busty.focus();
		return false;
	}
	return true;
}
function chktrim(inputString) {
     if (typeof inputString != "string") { return inputString; }
     var retValue = inputString;
     var ch = retValue.substring(0, 1);
     while (ch == " ") { 
       retValue = retValue.substring(1, retValue.length);
       ch = retValue.substring(0, 1);
     } 
     ch = retValue.substring(retValue.length-1, retValue.length);
     while (ch == " ") { 
        retValue = retValue.substring(0, retValue.length-1);
        ch = retValue.substring(retValue.length-1, retValue.length);
     }
     while (retValue.indexOf("  ") != -1) { 
        retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
     }
     return retValue; 
} 

/* to view the existing user form or non-existing user form in category section like (agriculture)*/
function showme(val) {
	 if(val=="e") {
		document.getElementById('exis_div').style.display = 'block'; 
		document.getElementById('newmem_div').style.display = 'none'; 				
	 }
	 else if(val=="n") {
		
		document.getElementById('exis_div').style.display = 'none'; 
		document.getElementById('newmem_div').style.display = 'block'; 
	 }
}

function openSave(detl2) {
	if (pop && !pop.closed) {
		pop.close();
	}
	pop=eval("window.open('trade-search.php?id=msgsave&id1=msgRep&msgDetail="+detl2+"','NewWIN','chrome[4],toolbar=no,left=10,top=5,width=480,height=400,directories=no,menubar=no,SCROLLBARS=yes')");
	if (!pop.opener) popUpWin.opener = self;
}

//Function to check validation on member requirement(post-requirement.php) page and for post trade lead(post-trade-lead.php) page.somesh
function post_requirement_det(chk1,val,from) { 
	if (from=="tl") {
		if (chk1.tradelead_type.value=="x") {
        	alert("Enter Your Trade Lead Type");
         	chk1.tradelead_type.focus();
         	return false;
      	}
      	if (chk1.quantity.value=="") {
        	alert("Enter Quantity");
         	chk1.quantity.focus();
         	return false;
      	}
      	if (chk1.subject.value=="") {
        	alert("Enter subject");
         	chk1.subject.focus();
         	return false;
      	}
      	if (chk1.subject.value.length>40) {
         	alert("Please Enter Subject Maximum Of 40 Characters");
         	chk1.subject.focus();
         	return false;
      	}	  	
      	
      	if (chk1.keywords.value=="") {
        	alert("Enter Keywords");
         	chk1.keywords.focus();
         	return false;
      	}	  	
      	
      	if (chk1.details.value=="") {
         	alert("Enter details");
         	chk1.details.focus();
         	return false;
      	}
  	}
	if (from=="post_requirement") {
		if (chk1.req_detail.value.length==0) {
         	alert("Enter Your Requirement Details (Maximum 1000 characters)");
         	chk1.req_detail.focus();
         	return false;
      	}
  	}
	if (val=="y") {
		
   		if (chk1.your_name.value.length==0) {
         	alert("Enter Your Name ");
         	chk1.your_name.focus();
         	return false;
      	}
      	//To check .net .com etc words in Your name field
		if (!isValid(chk1.your_name)) {
    		return false;
 		}
 		
 		if (chk1.comp_name.value.length==0) {
         	alert("Enter Your Company Name ");
         	chk1.comp_name.focus();
         	return false;
      	}
 		
 		if (chk1.username.value.length == 0) {
	 		alert("E-mail address can't be left blank");
			chk1.username.focus();
			return false;
      	}
    	if (chk1.username.value.indexOf('@') == -1) {
         	alert("Error in e-mail address");
         	chk1.username.focus();
         	return false;
    	}
    	if (chk1.username.value.indexOf('.') == -1) {
			alert("Error in e-mail address");
         	chk1.username.focus();
         	return false;
    	}
     	if (chk1.username.value.indexOf('@') != chk1.username.value.lastIndexOf('@')) {
			alert("Please Specify One E-mail address only");
         	chk1.username.focus();
         	return false;
     	}
      	//To restict indiamart,tradeindia,alibaba etc. email id .somesh
    	if(isProhibited(chk1.username)) {
	    	return false;
    	}
    	
    	if (chk1.password.value.length==0) {
         	alert("Enter Your Password");
         	chk1.password.focus();
         	return false;
      	}    	
 		
    	//To check .net .com etc words in Company name field
		/*if(!isValid(chk1.comp_name)) {
    		return false;
 		}*/
 		if (chk1.country.options[chk1.country.selectedIndex].value == "x") {
      		alert("Select Country Name ");
      		chk1.country.focus();
      		return false;
     	}
      	if (chk1.street_address.value.length==0) {
        	alert("Enter Your Address ");
         	chk1.street_address.focus();
         	return false;
      	}
      	//To check .net .com etc words in name field
    	if (!isValid(chk1.street_address)) {
    		return false;
 		}
		if (chk1.ph_ccode.value.length==0) {
			alert("Enter Your Country Code ");
         	chk1.ph_ccode.focus();
			return false;
      	}
      	if (chk1.ph_acode.value.length==0) {
			alert("Enter Your Area Code ");
         	chk1.ph_acode.focus();
         	return false;
      	}
      	if (chk1.ph_number.value.length==0) {
	      	alert("Enter Your Phone Number ");
	      	chk1.ph_number.focus();
	      	return false;
      	}
      	document.joinForm.id.value="submit_member";		    
	}
	if (val=="n") {
		if (chk1.user_name.value.length == 0) {
		  alert("E-mail ID can't be left blank");
		  chk1.user_name.focus();
		  return false;
		}
		if (chk1.user_name.value.indexOf('@') == -1) {
		  alert("Error in Email ID");
		  chk1.user_name.focus();
		  return false;
		}
		if (chk1.user_name.value.indexOf('.') == -1) {
		  alert("Error in Email ID");
		  chk1.user_name.focus();
		  return false;
		}
		if (chk1.user_name.value.indexOf('@') !=  chk1.user_name.value.lastIndexOf('@')) {
		  alert("Please Specify One Email ID only");
		  chk1.user_name.focus();
		  return false;
		}  
		//To check 'india mart,alibaba etc. words
		if(isProhibited(chk1.user_name)) {
				return false;
		}
		if (chk1.pass_word.value.length==0) {
		  alert("Enter Your Password ");
		  chk1.pass_word.focus();
		  return false; 
		}
		document.joinForm.id.value="login";		
	}
}

/*Function  : isProhibited(param) 
  Objective : To check object value is allow or not
  @param    : Object
  Output    :
  	True    : If value is not allowed to enter
  	False   : If value is allowed to enter */
  	
function isProhibited(obj){
	var objval=obj.value;
	invalidstr=new Array("indiamart","india mart", "alibaba","ali baba","tradeindia", "trade-india");
	for(i=0;i<invalidstr.length;i++){
		if (chktrim(objval).toLowerCase().indexOf(chktrim(invalidstr[i]).toLowerCase())>=0){	
			alert("Usage of "+invalidstr[i]+" is Prohibited on this site.") 
			obj.focus();
			return true;		
		}
	}
	return false;
}//end of isProhibited()

function isValid(obj){ //function to validate hotmail,gmail etc in your name,company name etc field in search and join now pages.somesh
	var objval=obj.value;
    invalidstr = new Array("hotmail", "gmail", "indiatimes", "rediffmail", "yahoo", ".com", ".net",".org", ".co.in", ".co.cn", ".co.ca", ".gov", ".co.uk");
		 		
	for(i=0;i<invalidstr.length;i++){
		if (chktrim(objval).toLowerCase().indexOf(chktrim(invalidstr[i]).toLowerCase())>=0){	
			alert("Please don't use "+invalidstr[i]+".") 
			obj.focus();
			return false;		
		}
	}
	return true;
}//end isValid

	
/* to view the existing user form or non-existing user form in category section like (agriculture)*/
function showme(val) {
	 if(val=="e") {
		document.getElementById('exis_div').style.display = 'block'; 
		document.getElementById('newmem_div').style.display = 'none'; 				
	 }
	 else if(val=="n") {
		
		document.getElementById('exis_div').style.display = 'none'; 
		document.getElementById('newmem_div').style.display = 'block'; 
	 }
}	

function trade_detl(var1, sty) {
	window.location='/trade-search.php?id=detail&pty_ids='+var1+'&sty='+sty+'';
}

function emailThisPage(rUrl) {
	
    var target = document.location;

  	var win = window.open(''+rUrl+'/email_with_us.htm?sendurl=' + target, 'notice', 'width=600,height=500,location=no,toolbar=no,status=no,resizable=no,scrollbars=yes');
  	win.focus();
}

function addToFavorite(){
	
	var titleVar = document.title;
	
	var urlVar = document.location;
	
	// firefox
	if (window.sidebar) {
		window.sidebar.addPanel(titleVar, urlVar, "");
	}
	// opera
	else if(window.opera && window.print) { 
		var elem = document.createElement('a');
		elem.setAttribute('href',urlVar);
		elem.setAttribute('title',titleVar);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	// ie
	else  {
		window.external.AddFavorite(urlVar,titleVar)
	}	

}

function firefoxAlert(pageurl) {
	
	if(navigator.appName=="Microsoft Internet Explorer") {
		
		pageurl.style.behavior='url(#default#homepage)';pageurl.setHomePage('http://www.indianyellowpages.com');
	}
	else {
		alert('To set Indianyellowpages.com as your home page in Firefox, click and drag the button to the "Home" icon in your browser.');
	}
	return false;
}	

/*
function id(id) { return (document.getElementById(id)); }
function db(id) { id.style.display=''; }
function dn(id) { id.style.display='none'; }
*/

var iypFunctions={
	id:function(id) { return (document.getElementById(id)); },
	db:function(id) { id.style.display=''; },
	dn:function(id) { id.style.display='none'; }
}
var tradeFunctions={
	idsDetailPage:function() {
		h1=iypFunctions.id('t1h1');
		h2=iypFunctions.id('t1h2');
		d1=iypFunctions.id('t1d1');
		d2=iypFunctions.id('t1d2');
	},
	detailTab1:function() {
		tradeFunctions.idsDetailPage();
		h1.className='tradeDetailsT1hOn';
		h2.className='tradeDetailsT1hOff';
		iypFunctions.db(d1);
		iypFunctions.dn(d2);
	},
	detailTab2:function() {
		tradeFunctions.idsDetailPage();
		h1.className='tradeDetailsT1hOff';
		h2.className='tradeDetailsT1hOn';
		iypFunctions.dn(d1);
		iypFunctions.db(d2);
	}

}

function countCharacter(PId,ShowId,maxchar) {
	
	var char=document.getElementById(PId).value;
	
	var showdata=document.getElementById(PId).value;
	var charleng=char.length;
	
	if (charleng > maxchar) {

		document.getElementById(PId).value = document.getElementById(PId).value.substring(0, maxchar);
	
	}
	
	if(maxchar-charleng>=0) {
	
	document.getElementById(ShowId).innerHTML=maxchar-charleng;

	}
	else{

	document.getElementById(ShowId).innerHTML=0;

	}
}