function showshiptable(id)
	{
		if (document.getElementById(id).style.display=="none" || document.getElementById(id).style.height=="0px")
			{
			document.getElementById(id).style.display="block";
			}
		else
			{
			document.getElementById(id).style.display="none";
			}	
	}
	
function addvalue(id){
			document.getElementById("indexing").value = id;
			document.getElementById("list1").style.display="none";
}

menu_status = new Array();

function showHide(theid){
    if (document.getElementById) {
    var switch_id = document.getElementById(theid);

        if(menu_status[theid] != 'hide') {
           switch_id.className = 'hide';
           menu_status[theid] = 'hide';
        }else{
           switch_id.className = 'show';
           menu_status[theid] = 'show';
        }
    }
}

function prod_search(){
	var objradio = document.indexingform.toindex;
	var prod_index = document.indexingform.prod_index.value;
	if(prod_index == "Select"){
		alert("Please Select Parameter");	
		return false;
	}
	if(validateRadio1(objradio)!=true){
		alert("Please Make a Selection in Product or Company.");	
		return false;
	}
	else{
		var prod_array	= new Array();
		prod_array  = prod_index.split("-");
		start_value = trim(prod_array[0],'');
		end_value 	= trim(prod_array[1],''); 
		document.indexingform.start_value.value = start_value;
		document.indexingform.end_value.value = end_value;
	}
}

function setlength(field,maxlength)
{
	if(field){
		var len=field.value.length;
		var field_name=field.name;
		if(len <= maxlength){
			if(document.getElementById(field_name+"_count")){
				document.getElementById(field_name+"_count").innerHTML=len;
			}
		}else{
			document.getElementById(field_name+"_count").innerHTML = '<span class="errnote">'+len+'</span>';
			return false;
		}
	}
}
		
function validateRadio1(obj){
		 for(var i=0; i<obj.length; i++){ 
		  if(obj[i].checked==true){
		  	//return obj[i].value;
			return true;
		  }
		 } 
	 }
	 
function validateRadio(obj){
		 for(var i=0; i<obj.length; i++){ 
		  if(obj[i].checked==true){
		  	return obj[i].value;
			return true;
		  }
		 } 
	 }	 
	 
function searchit(){
	var query = document.queryform.query.value;
	var county = document.queryform.county.value;
//	var objradio = document.queryform.tosearch;
//	var to_search = 'company';
//	for(var r=0;r < objradio.length;r++)
//	{
//	  if(objradio[r].checked)
//	  {
//	  	to_search =	objradio[r].value;
//		break;
//	  }
//	}
//	if(query == ""){
//		alert("Please enter any keyword");	
//		return false;
//	}
//	else{
//		if(to_search == 'product'){
//			document.queryform.action = "prod_search.php?query="+query+"&county="+county;
//		}else{
//			document.queryform.action = "search.php?query="+query+"&county="+county;
//		}	
	if(query == ""){
			alert("Please Enter the Keyword");
			return false;
	}else{
		if(county != ""){
			document.queryform.action = "search.php?query="+query+"&county="+county;	
		}else{
			document.queryform.action = "search.php?query="+query;	
		}
		document.queryform.method = "post";
		document.queryform.submit();
	}
//	}
}

function showComolist(){
								
							var list = new Array()
							list[0]="Aa - Az";	
							list[1]="Ba - Bz";
							list[2]="Ca - Cz";
							list[3]="Da - Dz";
							list[4]="Ea - Ez";
							list[5]="Fa - Fz";
							list[6]="Ga - Gz";
							list[7]="Ha - Hz";
							list[8]="Ia - Iz";
							list[9]="Ja - Jz";
							list[10]="Ka - Kz";
							list[11]="La - Lz";
							list[12]="Ma - Mz";
							list[13]="Na - Nz";
							list[14]="Oa - Oz";
							list[15]="Pa - Pz";
							list[16]="Qa - Qz";
							list[17]="Ra - Rz";
							list[18]="Sa - Sz";
							list[19]="Ta - Tz";
							list[20]="Ua - Uz";
							list[21]="Va - Vz";
							list[22]="Wa - Wz";
							list[23]="Xa - Xz";
							list[24]="Ya - Yz";
							list[25]="Za - Zz";
							
							var combolist = "";
							for(i=0;i<=list.length-1;i++){
								combolist = combolist + "<li><a href='#' id='"+list[i]+"' onclick='addvalue(this.id)' >" + list[i] + "</a></li>\n";
							}
	return combolist;
}

/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
**/
 
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
	
function chkUser()
		{	
		
			var email=document.getElementById("login_email").value;
			if(email != ""){
			advAJAX.get({
				url: "includes/frndbconfig.php?QT=2&email="+email,
				onInitialization : function() {
					document.getElementById("msg").innerHTML="Checking Availability";	  
				}, 
				onSuccess : function(obj) {
					var xmlDoc   = obj.responseXML;
					var statuscode = xmlDoc.getElementsByTagName("statuscode")[0].childNodes[0].nodeValue;
					if(statuscode == 1){
						var password = xmlDoc.getElementsByTagName("password")[0].childNodes[0].nodeValue;	
						document.getElementById("msg-container").style.visibility = "visible";
						document.getElementById("msg-container").style.left = "664px";
						document.getElementById("msg-container").style.top = "390px";
						document.getElementById("msg").innerHTML = "<p>This Email is Already Exist.<br>You can continue with your existing password OR choose a different email.</p>";
						document.formfields.login_pass.disabled = "disabled";
						document.formfields.login_pass.style.background = "";
						document.formfields.login_cnfm_pass.disabled = "disabled";
						document.formfields.login_cnfm_pass.style.background = "";
						document.formfields.login_pass.value = password;
						document.formfields.login_cnfm_pass.value = password
						
					}else{
						document.getElementById("msg-container").style.left = "665px";
						document.getElementById("msg-container").style.top = "403px";
						document.getElementById("msg-container").style.visibility = "visible";	
						document.getElementById("msg").innerHTML = "<p>Email is Avaiilable. You can continue.</p>";
						document.formfields.login_pass.disabled = "";
						document.formfields.login_cnfm_pass.disabled = "";
						document.formfields.login_pass.value = "";
						document.formfields.login_cnfm_pass.value = "";
						setTimeout( function (){
						document.getElementById("msg-container").style.visibility = "hidden";
									  },4000);
					}
				},
				onError : function(obj) {
					/* In case of error we show an alert */
					alert("Error: " + obj.status);
				},
				onFinalization : function(){ 
					/* After all operations we show hidden layer */
				  //  someDiv.style.visibility = "visible";
				}
			});
			}
		}
		

function chkLogin()
		{	
			var email=document.getElementById("login_email").value;
			var pass=document.getElementById("login_pass").value;
			
		 if((email && pass) != ""){
			advAJAX.get({
				url: "includes/frndbconfig.php?QT=5&email="+email+"&pass="+pass,
				onInitialization : function() {
					document.getElementById("msg").innerHTML="Please wait......";	  
				}, 
				onSuccess : function(obj) {
					var xmlDoc   = obj.responseXML;
					var statuscode = xmlDoc.getElementsByTagName("statuscode")[0].childNodes[0].nodeValue;
					if(statuscode == 0){
						document.formfields.action = "user_cp.php";
						document.formfields.submit();
					}else if(statuscode == 1){
						document.getElementById("msg").innerHTML="Your account is not activated yet!";	  
						
					}else{
						document.getElementById("msg").innerHTML="Login Failed ! Please check your loginid and password.";	 			
					}
				
				},
				onError : function(obj) {
					/* In case of error we show an alert */
					alert("Error: " + obj.status);
				},
				onFinalization : function(){ 
					/* After all operations we show hidden layer */
				  //  someDiv.style.visibility = "visible";
				}
			});
			}
		}		

function showotherbox(){
		if(document.getElementById('busns_category').value!=-1){
			document.getElementById('other').style.display= "none";
			document.getElementById('busns_category_others').value = "";
		}
		
		if(document.getElementById('busns_category').value==-1){
				document.getElementById('other').style.display= "block";
		}
}	

function checkColour(val,x)
{
if(x==0){
val.style.background='#fffacd';
}
else{
val.style.background='#ffffff';
}
}

function setCookie(c_name,value)
{
	document.cookie=c_name+ "=" +escape(value);
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1; 
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
}

function searchtown(page,query,county,town){
	var townform = document.region3form;
	townform.action = page+"?query="+query+"&county="+county+"&town="+town;
	townform.method="post";
	townform.submit();
}

function submitmyform(){
	var myform = document.formfields;
	var x = document.formfields.ads_protection;
	var val = validateRadio(x);
	if(val == 1){
		document.getElementById("payment_stage1").style.display = "none";
		document.getElementById("payment_stage2").style.display = "block";
		myform.action="https://www.paypal.com/cgi-bin/webscr";
	}else{
		myform.action="includes/frndbconfig.php?QT=1&step=7";
	}	
	myform.method="post";
	myform.submit();
	return false;		
}

function fileUpload(form, action_url, div_id)  
 {  
 // Create the iframe...  
 var iframe = document.createElement("iframe");  
 iframe.setAttribute("id","upload_iframe");  
 iframe.setAttribute("name","upload_iframe");  
 iframe.setAttribute("width","0");  
 iframe.setAttribute("height","0");  
 iframe.setAttribute("border","0");  
 iframe.setAttribute("style","width: 0; height: 0; border: none;");  
   
 // Add to document...  
 form.parentNode.appendChild(iframe);  
 window.frames['upload_iframe'].name="upload_iframe";  
   
 iframeId = document.getElementById("upload_iframe");  
   
 // Add event...  
 var eventHandler = function()  {  
   
 if (iframeId.detachEvent)  
 iframeId.detachEvent("onload", eventHandler);  
 else  
 iframeId.removeEventListener("load", eventHandler, false);  
   
 // Message from server...  
 if (iframeId.contentDocument) {  
 content = iframeId.contentDocument.body.innerHTML;  
 } else if (iframeId.contentWindow) {  
 content = iframeId.contentWindow.document.body.innerHTML;  
 } else if (iframeId.document) {  
 content = iframeId.document.body.innerHTML;  
 }  
   
 //document.getElementById(div_id).innerHTML = content;  
   
 // Del the iframe...  
 setTimeout('iframeId.parentNode.removeChild(iframeId)', 250);  
 }  
   
 if (iframeId.addEventListener)  
 iframeId.addEventListener("load", eventHandler, true);  
 if (iframeId.attachEvent)  
 iframeId.attachEvent("onload", eventHandler);  
   
 // Set properties of form...  
 form.setAttribute("target","upload_iframe");  
 form.setAttribute("action", action_url);  
 form.setAttribute("method","post");  
 form.setAttribute("enctype","multipart/form-data");  
 form.setAttribute("encoding","multipart/form-data");  
   
 // Submit the form...  
 form.submit();  
 return true;  
 //document.getElementById(div_id).innerHTML = "Uploading..."; 
 }  