function count_len(count_from, post_to, limit) {
	post_to.value=count_from.value.length;
	if (count_from.value.length>limit) {
		alert("Your Description cannot exceeds " +limit+ " characters");
		count_from.focus();
		return false;
	}
	
}
   
/*following function calls to show any type of validation in any form*/
function form_validation(form_object) {
	/*fetching the total number of elements from form*/
	total_elements=(form_object.elements.length);
    
	var email_check = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
	/*running loop to check the elements of form one by one*/
	for(element_count=0; element_count<total_elements; element_count++) {
		
		/*storing element object*/
		var element_object=form_object.elements[element_count];
		
		/*storing element name*/
		var element_id=element_object.id;
		
		/*storing element value*/
		var element_value=chktrim(element_object.value);
		
		/*storing element type*/
		var element_type=element_object.type;
		
		/*spliting the element namer*/
		var array_split=element_id.split("_");		
		//alert(element_object+', '+element_id+', '+element_value+', '+element_type+', '+array_split[0]);
		if(array_split[0].indexOf('req')!=-1){
			if(element_type=='select-one'){
				if (element_object.options[element_object.selectedIndex].value=="")  {
					alert('Please Select ' +array_split[2]);
					element_object.focus();
					return false;
				}
			}
			else if(element_type=='checkbox'){
				if (element_object.checked == false)  {
					alert('Please check the  ' +array_split[2]);
					element_object.focus();
					return false;
				}
			}
			else{
				if(element_value.length<1){
					alert('Please enter ' +array_split[2]);
					element_object.focus();
					return false;
				}
				else if(element_id.indexOf('_Email-id')!=-1){
					if(!email_check.test(element_value)){
						alert('Please enter valid ' +array_split[2]);
						element_object.focus();
						return false;
					}
					
					
				}
				else if(element_id.indexOf('_int_')!=-1){
					if(!parseInt(element_value)){
						alert('Please enter valid ' +array_split[2]);
						element_object.focus();
						return false;
					}
				}
				else if(array_split[0].indexOf('prohb')!=-1){
					
					if(array_split[0].indexOf('prohb')!=-1 || array_split[0].indexOf('prohb1')!=-1){
					   	//To check indiamart, Alibaba etc words in email field
					   	if(isProhibited(element_object))
					   		return false;
					}
					
					if(array_split[0].indexOf('prohb')!=-1 || array_split[0].indexOf('prohb2')!=-1){
					   	//To check .net .com etc words in company name field
					    if(!isValid(element_object))
					   		return false;
					}
					
				}
			}
		}
		else if(array_split[0].indexOf('prohb')!=-1 && element_value.length>0){
			if(element_id.indexOf('_int_')!=-1){
				if(!parseInt(element_value)){
					alert('Please enter valid ' +array_split[2]);
					element_object.focus();
					return false;
				}
			}
			else{
				if(array_split[0].indexOf('prohb')!=-1 || array_split[0].indexOf('prohb1')!=-1){
				   	//To check indiamart, Alibaba etc words in email field
				   	if(isProhibited(element_object))
				   		return false;
				}
				
				if(array_split[0].indexOf('prohb')!=-1 || array_split[0].indexOf('prohb2')!=-1){
				   	//To check .net .com etc words in company name field
				    if(!isValid(element_object))
				   		return false;
				}
			}
		}
	}
}

// JavaScript Document
function addBookmark(title,url) {
if (window.sidebar) { 
window.sidebar.addPanel(title, url,""); 
} else if( document.all ) {
window.external.AddFavorite( url, title);
} else if( window.opera && window.print ) {
return true;
}
}

function sel_cat(form_object) {
	var pp=1;
	len=form_object.elements.length;
	var i=0;
	for(i=0; i<len; i++) {
		if ((form_object.elements[i].type == "radio") && (form_object.elements[i].checked==true)) {
			var selected_val=form_object.elements[i].value;
			var selected_no=form_object.elements[i].id;
			pp=2;
		}
	}
	if (pp==1) {
		alert("You have not selected any Record.");
		return false;
	}
	else{
		window.opener.document.forms.posting_form.dynamic_val.value=selected_val;
		window.opener.document.forms.posting_form.listing_category.value=selected_no;
		window.close();
	}
}
//////////////code by kripa ////////////////
function addOption(selectbox,text,value ){
	var optn = window.opener.document.createElement("option");
	var arr=new Array;
	arr=value.split("_");
	optn.text = arr[1];
	optn.value = arr[0];
	window.opener.document.getElementById('Service Areas').options.add(optn);	
}

/*function sel_country(form_object) {
	var pp=1;
	len=form_object.elements.length;
	var i=0;
	for(var i=0;i<len;i++) {
	  obj1	=	form_object.elements[i];
	  if(obj1.type!='button'){
		  for(k=0;k<obj1.length;k++){
		   if(obj1[k].selected){
			var selected_val=obj1[k].value;
				obj	=window.opener.document.getElementById('r_Service Areas');
				for(j=0;j<obj.length;j++){
					
						if(obj[j].value==selected_val){
							obj[j].selected=true;
						}
				}
			 pp=2;
		    }
	      }
	  break;
	  }
	}
	if(pp==1) {
		alert("You have not selected any Country.");
		return false;
	}else{
		window.close();
	}
}*/

function removecountry(form_object){
	obj	=document.getElementById('Service Areas');
	var len=obj.length;	
	for(var i=obj.length-1;i>=0;i--){
		if(obj[i].selected){
			obj.remove(i);
		}
	}
}
function confirmcountry(form_object){
	obj	=document.getElementById('Service Areas');
	var len=obj.length;
	for(var i=0;i<obj.length;i++){
		obj[i].selected=true;
	}
}
function sel_country(form_object) {
	var pp=1;
	len=form_object.elements.length;
	var i=0;
	for(var i=0;i<len;i++) {
	  obj1	=	form_object.elements[i];
	  if(obj1.type!='button'){
		  for(k=0;k<obj1.length;k++){
		   if(obj1[k].selected){
			var selected_val=obj1[k].value;
				obj	=window.opener.document.getElementById('Service Areas');
				var exist=0;
				var arr=new Array;
				arr=selected_val.split("_");
				for(var j=0;j<obj.length;j++){
					if(obj[j].value==arr[0]){
						exist=1;
						break;
					}						
				}
				if(exist==0){
					addOption(obj,"test",obj1[k].value);
				}
			 pp=2;
		    }
	      }
	  break;
	  }
	}
	if(pp==1) {
		alert("You have not selected any Country.");
		return false;
	}else{
		window.close();
	}
}
function sel_list_cat(name) {
	str	=	window.opener.document.getElementById('list_catname').innerHTML;
	obj1=	window.opener.document.getElementById('listing_category').value;
	var chObj	=	document.getElementsByName(name);
	var result	=	false;	
	for(var i=0;i<chObj.length;i++){
		if(chObj[i].checked){
		  result=true;
		  selected_no=chObj[i].id;
		  selected_val=chObj[i].value;
          if(obj1==''){
		    obj1	=	selected_no;
		  }else{
			obj1	=	obj1 + ',' + selected_no;
		  }
		  str	=str+"\n"+selected_val+",";
		}
	}

	if(!result){
		 alert("Please select atleast one category.");
		 return false;
	}else{
		window.opener.document.getElementById('list_catname').innerHTML=str;
		window.opener.document.getElementById('listing_category').value=obj1;
		window.close();
	}
	
	
	/*
	
	
	
	

	
	obj1	=	window.opener.document.getElementsByName('listing_category[]');
	var pp=1;
	len=form_object.elements.length;
	var i=0;
	for(i=0; i<len; i++) {		
	 if (form_object.elements[i].type=="checkbox") {
			x=form_object.elements[i].name;
			obj=document.getElementsByName(x);
			k=0;
			for(j=0;j<obj.length;j++){				
			  if(obj[j].checked==true){
				var selected_no=obj[j].value;
				//var selected_val=form_object.elements[i].id;
				
				
				//forms.posting_form.listing_category;
//alert(obj1[k]);
alert(k);
					//obj1[k].value	=	selected_no;
					k++;
				//str	=str+"\n"+selected_val;				
				pp=2;
			  }
			}
		}
	}
	if (pp==1) {
		alert("You have not selected any Record.");
		return false;
	}
	else{
		alert(obj1);
		window.opener.document.getElementById('list_catname').innerHTML=str;
		window.close();
	}*/
}
//////////////end of code by kripa/////////////////////////
function form_radio_validation(form_object, msg) {
	var pp=1;
	len=form_object.elements.length;
	var i=0;
	for(i=0; i<len; i++) {
		if ((form_object.elements[i].type == "radio") && (form_object.elements[i].checked==true)) {
			var selected_val=form_object.elements[i].value;
			var selected_no=form_object.elements[i].id;
			pp=2;
		}
	}
	if (pp==1) {
		alert(msg);
		return false;
	}
}
	
/*following function calls to show any type of validation in any form*/
function dynamic_form_validation(form_object) {
	/*fetching the total number of elements from form*/
	total_elements=(form_object.elements.length);
    
	/*running loop to check the elements of form one by one*/
	for(element_count=0; element_count<total_elements; element_count++) {
		
		/*storing element object*/
		var element_object=form_object.elements[element_count];
		
		/*storing element name*/
		var element_id=element_object.id;
		
		/*storing element value*/
		var element_value=chktrim(element_object.value);
		
		/*storing element type*/
		var element_type=element_object.type;
		
		/*spliting the element namer*/
		var array_split=element_id.split("_");		
		
		var validation_ans=array_split[0].split("-");		
		
		var validation_msg=''+array_split[1]+'';
		
		/*if element is required or prohibited and element is null*/
		if(validation_ans[0]=='r' || validation_ans[0]=='rp'){
			if(element_type=='select-one'){
				if (element_object.options[element_object.selectedIndex].value=="")  {
					alert('Please select '+validation_msg);
					element_object.focus();
					return false;
				}
			}
			else if(element_type=='checkbox'){
				if (element_object.checked == false)  {
					alert('Please check '+validation_msg);
					element_object.focus();
					return false;
				}
			}
			else{
				if(element_id=='Service Areas'){
					var len=document.getElementById('Service Areas').length;
					if(len<1){
						alert('Please select '+validation_msg);
						element_object.focus();
						return false;
					}
					
					if(!document.getElementById('Service Areas').options[0].selected){
						alert('Please confirm '+validation_msg);
						element_object.focus();
						return false;
					}
				}else if(element_value.length<1 && element_id!='Service Areas'){
					alert('Please enter '+validation_msg);
					element_object.focus();
					return false;
				}
			}
		}
		/*if element is required or required and prohibited and element is not null*/
		if((validation_ans[0]=='p' || validation_ans[0]=='rp') && element_value.length>0){
			var check="";
			/*validation for integer*/
			if(validation_ans[1]=='1'){
				check = /^([0-9])+$/;
				$allow_char="allowed characters are 0 to 9";
			}			
			/*validation for alphabets*/
			if(validation_ans[1]=='2'){
				check = /^([a-zA-Z\s])+$/;
				$allow_char="allowed characters are a to z";
			}			
			/*validation for alpha numeric field*/
			else if(validation_ans[1]=='3'){
				check= /^([a-zA-Z0-9\s])+$/;
				$allow_char="allowed alphanumeric characters are 0-9, a to z";
			}			
			/*validation for email field*/
			else if(validation_ans[1]=='4'){
				check= /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				$allow_char="allowed format email@website.com";
			}			
			/*validation for phone number, fax number field*/
			else if(validation_ans[1]=='5'){
				check=/^(\+)*([0-9])+([-\/\.])+([0-9])+([-\/\.])+([0-9])+$/;
				$allow_char="allowed format +91-011-21566456";
			}			
			/*validation for webaddress field*/
			else if(validation_ans[1]=='6'){
				check= /^(http|ftp):\/\/(www\.)?.+\.(com|net|org)$/;
				$allow_char="allowed format http://www.domainname.com";
			}			
			/*validation for date of birth field*/
			else if(validation_ans[1]=='7'){
				check= /^([0-9]){2}(\/|-)([0-9]){2}(\/|-)([0-9]){4}$/;
				$allow_char="allowed format  dd/mm/yyyy or dd-mm-yyyy";
			}			
			/*validation for integer field*/
			else if(validation_ans[1]=='8'){
				check= /^([0-9])+$/;
				$allow_char="allowed characters are 0 to 9";
			}			
			/*validation for float field*/
			else if(validation_ans[1]=='9'){
				check= /^([0-9\.])+$/;
				$allow_char="allowed format  7.5";
			}			
			/*validation for company name field*/
			else if(validation_ans[1]=='10'){
				check = /^([a-zA-Z0-9\s])+([&\-\.@\/])*([a-zA-Z0-9\s])*$/;
				$allow_char="allowed characters are 0 to 9, a to z, dot, &, hiphen";
			}			
			/*validation for address*/
			else if(validation_ans[1]=='11'){
				check = /^([a-zA-Z0-9\s])+([@&\-\.,\(\)\/])*([a-zA-Z0-9\s@&\-\.,\(\)\/])*$/;
				$allow_char="allowed characters are 0 to 9, a to z, &, comma, hiphen, dot, brackets";
			}			
			/*validation for ,phone number without country and area code*/
			else if(validation_ans[1]=='12'){
				check=/^(\+)*([0-9])+([-\/\.])*([0-9])+([-\/\.])*([0-9])+$/;
				$allow_char="allowed characters are 0 to 9, +, /, -";
			}			
			/*validation for mobile number*/
			else if(validation_ans[1]=='13'){
				check=/^(\+)*([0-9])+([-\/])*([0-9])+([-\/])*([0-9])+$/;
				$allow_char="allowed characters are 0 to 9, -, / and format could be +9891854673 or 91-011-9891854673";
			}			
			/*validation for grater than 0*/
			else if(validation_ans[1]=='14'){
				check= /^([1-9])+([0-9])*$/;
				$allow_char="must be greater than 0";
			}			
			/*validation for time format*/
			else if(validation_ans[1]=='15'){
				check= /^([0-9]){2}(:){1}([0-5]){1}([0-9]){1}(:){1}([0-5]){1}([0-9]){1}$/;
				$allow_char="must be in format of 01:20:20      01(Hours), 20(Minutes and limit is up to 59), 01(Seconds and limit is up to 59)";
			}			
			/*validation for price field*/
			else if(validation_ans[1]=='16'){
				check= /^([0-9\.])*([0-9])+([0-9\.])*$/;
				$allow_char="allowed characters are 0 to 9";
			}			
			/*validation for date field*/
			else if(validation_ans[1]=='17'){
				check= /^([0-9]{1})([0-9]{1})(\/|-{1})([0-9]{1})([0-9]{1})(\/|-{1})([1-9]{1})([0-9]{3})$/;
				$allow_char="allowed format dd-mm-yyyy";
			}			
			
			if(!check.test(element_value)){
				alert('Invalid '+validation_msg+', '+$allow_char );
				element_object.focus();
				return false;
			}
		}
	}
}

/*function to check/uncheck all the checkboxes in the form*/
function chk_unchk(val, form_name) {
   	dml=eval('document.'+form_name);
   	len=dml.elements.length;
   	var i=0;
   	for (i=0; i<len; i++) {
     	if (dml.elements[i].type == "checkbox") {
        	if (val == 1) { 
           		dml.elements[i].checked=true;
        	} 
			else {
           		dml.elements[i].checked=false;
        	}
     	}   
   	}
}






/*function to open popup*/
function openwin1(file,Iwidth,Iheight) {
   var newWin2=window.open(file,'newwin','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 to open popup*/
function openwin(file,Iwidth,Iheight) {
   var newWin1=window.open(file,'iypWin1','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 to remove the space from the field*/
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; 
}



/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var RequestObject = createRequestObject(); 

/* Function called to get the product categories list */
function ajaxCall(url, element_name, display_type){
		if(display_type == 'div'){
			document.getElementById(element_name).innerHTML = "<br><br><table align=center><b><font size=4>Loading..</font></b></table><br><br>";
		}
		else{
			document.getElementById(element_name).value = "&lt;br&gt;&lt;br&gt;&lt;table align=center&gt;&lt;b&gt;"+loading_msg+"&lt;/b&gt;&lt;/table&gt;&lt;br&gt;&lt;br&gt;";
		}
	
	/* Create the request. The first argument to the open function is the method (POST/GET),
		and the second argument is the url... 
		document contains references to all items on the page
		We can reference document.form_category_select.select_category_select and we will 		
		be referencing the dropdown list. The selectedIndex property will give us the 
		index of the selected item. 
	*/
	RequestObject.open('POST', url, true);
	/* Define a function to call once a response has been received. This will be our
		handleProductCategories function that we define below. */
	//RequestObject.onreadystatechange = post_value; 
	RequestObject.onreadystatechange = function (){
	
		if(RequestObject.readyState == 4){
			var response = RequestObject.responseText;
			if(display_type == 'div'){
				document.getElementById(element_name).innerHTML = response;
			}
			else{
				document.getElementById(element_name).value= response;
			}
		}	
	}
	/* Send the data. We use something other than null when we are sending using the POST
		method. */
	RequestObject.send(null);
}

/* Function called to handle the list that was returned from the internal_request.php file.. */
function post_value(){
	
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(RequestObject.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = RequestObject.responseText;
		
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById('ajax_div_disp_prod_frm').innerHTML = response;
	}
}

function addBookmark(title,url) {
	if (window.sidebar) { 
	window.sidebar.addPanel(title, url,""); 
	} else if( document.all ) {
	window.external.AddFavorite( url, title);
	} else if( window.opera && window.print ) {
	return true;
	}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function getRequest(action,value,siteUrl){
	try{
			ob1=new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try{
				ob1=new ActiveXObject("Microsoft.XMLHTTP");
		}catch(e2){
				ob1=false;
		}
	}
	if(!ob1 && typeof XMLHttpRequest!='undefined'){
			ob1=new XMLHttpRequest();
	}
	var url=siteUrl+"?val="+value+"&action="+action;
	ob1.open("GET",url,true);
	ob1.onreadystatechange=show_form;
	ob1.send(null);
}
function show_form(){
	if(ob1.readyState==4){
	 	var resp=ob1.responseText;
		document.getElementById('subcat').innerHTML = resp;

	}
}