// JavaScript Document

function makeObject(){
	var x;
	if (window.ActiveXObject){
		x = new ActiveXObject("Microsoft.XMLHTTP");
	}else if (window.XMLHttpRequest){
		x = new XMLHttpRequest();
	}
	return x;
}

function  checkEnterLogin(e){ //e is event object passed from function invocation
	var characterCode ;//literal character code will be stored in this variable	
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e;
	characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
	//e = event
	characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		userLoginValidate();			
	}
}

function AddProductImages(){
	var browserName 	= navigator.appName;
	var temp=new Array();
	var browserVersion = navigator.appVersion;
	temp = browserVersion.split(';');
	
	if(temp[1]){
		var version = temp[1].split(' ');
	}
	
	var tbl 		= document.getElementById('tblproductimage');
	var lastRow 	= tbl.rows.length;
	var iteration 	= lastRow;	
	if(iteration<4) {
		var row 	    = tbl.insertRow(lastRow);
		var newitem 	= iteration+1;	
		//alert(newitem);
		row.setAttribute('id', "tr_productimag_"+newitem);	
		//Text box for perdiem peoples input
		
		var Perdiemce009 = row.insertCell(0);
		var e0 = document.createElement('label');		
		e0.innerHTML = 'Image '+ newitem;
		if (browserName=="Microsoft Internet Explorer") {
			e0.setAttribute('className', 'text2new');
		} else {
			e0.setAttribute('class', 'text2new');	
		}

		Perdiemce009.setAttribute('align', 'left');	
		Perdiemce009.appendChild(e0);

		//Check box to remove the row
		var Perdiemcell2 = row.insertCell(1);
		var e4  = document.createElement('input');
		e4.type = "hidden";
		e4.name = 'image_id_' + newitem;
		e4.id   = 'image_id_' + newitem;
		Perdiemcell2.appendChild(e4);	
		var e5 = document.createElement('label');
		e5.innerHTML = ' : ';
		
		if (browserName=="Microsoft Internet Explorer")	{
			if(version[2]>="8"){
				e5.setAttribute('class', 'text2new');
			}else{
				e5.setAttribute('className', 'text2new');
			}
		} else {
			e5.setAttribute('class', 'text2new');	
		}	
		
		Perdiemcell2.setAttribute('align','left')
		Perdiemcell2.appendChild(e5);
		
		
		var Perdiemcell0 = row.insertCell(2);
		var e3 = document.createElement('input');
		e3.type = 'file';
		e3.name = 'image_path_' + newitem;
		e3.id 	= 'image_path_' + newitem;
		
		if (browserName=="Microsoft Internet Explorer") {
			if(version[2]>="8"){
				e3.setAttribute('class', 'input-file');
			}else{
				e3.setAttribute('className', 'input-file');
			}
		} else {
			e3.setAttribute('class', 'input-file');	
		}
		
		Perdiemcell0.appendChild(e3);			
		document.form1.rowcount.value = newitem;	
	}	
}	

function AddPictures(){
	var browserName 	= navigator.appName;
	var temp=new Array();
	var browserVersion = navigator.appVersion;
	temp = browserVersion.split(';');
	if(temp[1]){
		var version = temp[1].split(' ');
	}
	
	var div 		= document.getElementById('addproductdiv');
	var iteration 	= parseInt(document.getElementById('rowcount').value,10);
	
	if(document.getElementById("addproduct").style.display=="none") {
		document.getElementById("addproduct").style.display = '';
		return false;
	}
	if(iteration<10) {
		var newitem 	= iteration+1;			
		var e0 = document.createElement('div');		
		e0.id   = 'image_' + newitem;			
		
		var e4  = document.createElement('input');
		e4.type = "hidden";
		e4.name = 'image_id_' + newitem;
		e4.id   = 'image_id_' + newitem;
		e0.appendChild(e4);	
		
		var e3 = document.createElement('input');
		e3.type = 'file';
		e3.name = 'image_path_' + newitem;
		e3.id 	= 'image_path_' + newitem;
		if (browserName=="Microsoft Internet Explorer") {
			if(version[2]>="8"){
				e3.setAttribute("class", "formFile validate['image']");
			}else{
				e3.setAttribute("className", "formFile validate['image'");
			}
		} else {
			e3.setAttribute("class", "formFile validate['image'");	
		}		
		e0.appendChild(e3);		
		div.appendChild(e0);			
		document.getElementById('rowcount').value = newitem;	
	}	
}	

function RemovePictures(page_from){
	var existing_ids = document.getElementById("exist_count").value;
	//alert(existing_ids);
	var iteration 	 = parseInt(document.getElementById('rowcount').value,10);
		if(iteration>existing_ids) {
			if(iteration==1){
				if(page_from=="fromEdit" && existing_ids==0){
					document.getElementById("addproduct").style.display="none";
				}
			}else{
					var newitem 	= iteration;
					var image_id = 'image_'+newitem;
					var el 		= document.getElementById(image_id);
					el.parentNode.removeChild(el);
					var newitem 	= iteration-1;
					document.getElementById('rowcount').value = newitem;
				}
		}
		else {
			if(page_from=="fromEdit"){
				if(existing_ids!=0){
					alert("Please use the 'Delete' option below the File Upload \nto remove the existing pictures.");
				}
			}
		}
		
		if(iteration==2){
			if(page_from=="fromAdd"){
				document.getElementById("addproduct").style.display="none";
				document.getElementById("image_path_1").value="";
				}
		}
}

/*-------------------------------------------------------------------------------------------------------*/
/*For Text box*/

function AddTextBoxes()
{
	var browserName = navigator.appName;
	var div 		= document.getElementById('addTextBoxdiv');
	var iteration 	= parseInt(document.getElementById('rowcount').value,2);	
	if(document.getElementById("addtext").style.display=="none") {
		document.getElementById("addtext").style.display = '';
		return false;
	}
	if(iteration<2) {	
		var newitem 	= iteration+1;			
		var e0 = document.createElement('div');		
		e0.id   = 'text_' + newitem;			
		
		/*var e4  = document.createElement('input');
		e4.type = "hidden";
		e4.name = 'text_id_' + newitem;
		e4.id   = 'text_id_' + newitem;
		e0.appendChild(e4);	*/
		
		var e3 = document.createElement('input');
		e3.type = 'text';
		e3.name = 'user_buyer_phone_' + newitem;
		e3.id 	= 'user_buyer_phone_' + newitem;
		
		if (browserName=="Microsoft Internet Explorer") {
			e3.setAttribute('className', 'input-text1');
		} else {
			e3.setAttribute('class', 'input-text1');	
		}		
		e0.appendChild(e3);		
		div.appendChild(e0);			
		document.getElementById('rowcount').value = newitem;	
	}	
}	

/*-------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------------*/
/*For Text box*/
var p_div_name,c_div_name,ele_name,hid_rcount,num;

function AddEmailTextBoxes(p_div_name,c_div_name,ele_name,hid_rcount,num)
{
	//alert('parent div '+p_div_name+', child div '+c_div_name+',element name'+ele_name+', row count '+hid_rcount+', Number '+num)
	
	
	var browserName = navigator.appName;
	var div 		= document.getElementById(c_div_name);
	var iteration 	= parseInt(document.getElementById(hid_rcount).value,4);
	if(document.getElementById(p_div_name).style.display=="none") {
		document.getElementById(p_div_name).style.display = '';
		return false;
	}
	if(iteration<num) {	
		var newitem 	= iteration+1;			
		var e0 = document.createElement('div');		
		e0.id   = 'text_' + newitem;			
		
		/*var e4  = document.createElement('input');
		e4.type = "hidden";
		e4.name = 'text_id_' + newitem;
		e4.id   = 'text_id_' + newitem;
		e0.appendChild(e4);	*/
		
		var e3 = document.createElement('input');
		e3.type = 'text';
		e3.name = ele_name+'_' + newitem;
		e3.id 	= ele_name+'_' + newitem;
		
		if (browserName=="Microsoft Internet Explorer") {
			e3.setAttribute('className', 'input-text1');
		} else {
			e3.setAttribute('class', 'input-text1');	
		}		
		e0.appendChild(e3);		
		div.appendChild(e0);			
		document.getElementById(hid_rcount).value = newitem;	
	}	
}	

/*-------------------------------------------------------------------------------------------------------*/


function cleartext(cntrl, defvalue){
	var cntrlvalue = document.getElementById(cntrl).value;	
	if(document.getElementById(cntrl).value == defvalue){
	  document.getElementById(cntrl).value = "";
	  return false;
	}else if(document.getElementById(cntrl).value ==""){
		  document.getElementById(cntrl).value = defvalue;
		  return false;
	}
}

function cleartextBlur(cntrl, defvalue){
	var cntrlvalue = document.getElementById(cntrl).value;	
	if(document.getElementById(cntrl).value ==""){
		  document.getElementById(cntrl).value = defvalue;
		  return false;
	}
}

function cleartextFocus(cntrl, defvalue){
	var cntrlvalue = document.getElementById(cntrl).value;	
	if(document.getElementById(cntrl).value == defvalue){
	  document.getElementById(cntrl).value = "";
	  return false;
	}
}


function  checkEnterCountrySubmit(e){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable	
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e;
	characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
	//e = event
	characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		return false;
	}
}
function  checkEnterTownSubmit(e){ //e is event object passed from function invocation
	var characterCode; //literal character code will be stored in this variable	
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e;
	characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
	//e = event
	characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		return false;
	}
}

//Alert message for deleting admin user

function deleteAdmin(id) {
	if(confirm("Are you sure to delete the Admin?")) {
	    document.form1.action="admin.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function deleteProduct(id) {
	if(confirm("Are you sure to delete the Product?")) {
	    document.form1.action="product.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function deleteUserSeller(id) {
	if(confirm("Are you sure to delete the Seller?")) {
	    document.form1.action="user_seller.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function deleteEnquiry(id) {
	if(confirm("Are you sure to delete the Enquiry?")) {
	    document.form1.action="enquiry.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function deleteOwner(id) {
	if(confirm("Are you sure to delete the Owner?")) {
	    document.form1.action="product_owner.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function deleteDistributor(id) {
	if(confirm("Are you sure to delete the Distributor?")) {
	    document.form1.action="distributor.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function deleteTechnologist(id) {
	if(confirm("Are you sure to delete the Technologist?")) {
	    document.form1.action="technologist.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function deleteCustomer(id) {
	if(confirm("Are you sure to delete the Customer?")) {
	    document.form1.action="customer.php?action=delete&id="+id;
		document.form1.submit();
 	}  
}

function deleteIndustryType(id){
	if(confirm("Are you sure to delete the Industry type?")) {
	    document.form1.action="industry_types.php?action=delete&id="+id;
		document.form1.submit();
 	} 
}

function deleteCategory(id){
	if(confirm("Are you sure to delete the Category?")) {
	    document.form1.action="category.php?action=delete&id="+id;
		document.form1.submit();
 	} 
}

function deleteProductType(id){
	if(confirm("Are you sure to delete the Product type?")) {
	    document.form1.action="product_type.php?action=delete&id="+id;
		document.form1.submit();
 	} 
}

function deleteProductSubType(id){
	if(confirm("Are you sure to delete the Product sub type?")) {
	    document.form1.action="product_subtype.php?action=delete&id="+id;
		document.form1.submit();
 	} 
}

function deleteAgentLogo(id) {
	if(confirm("Are you sure to delete the Agent Logo?")) {
		if(document.form1.frompublic && document.form1.frompublic.value=="1") { //from public site
			window.location.href ="editMyAccount.php?action=imagedelete&id="+id;		
		}else { //from cms
			window.location.href ="user_seller.php?action=imagedelete&id="+id;
		}
 	}  
}

function deleteProductDocument(product_id,fieldname,name) {
	if(confirm("This action to delete the "+name+" will delete the source file.\n Are you sure to delete this?")) {
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		}//If the user is using IE
		else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}	
		var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="1") ? 'controlpanel/' : '';
		var url = path+"ajaxdeleteproductdocument.php?product_id="+product_id+"&fieldname="+fieldname;
		alert(url);
		xmlhttp.open('GET', url, true);
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				var answer = xmlhttp.responseText;
				if(document.getElementById("frompublic") && document.getElementById("frompublic").value=="1") {
					window.location.href = "editProduct.php?id="+product_id;		
				}else {
					window.location.href = "product.php?action=edit&id="+product_id;	
				}
				
			}
		}
		xmlhttp.send(null);	
	}
}

function deleteProductImages(image_id,rowid,product_id) {	
	if(confirm("Are you sure to delete the Image "+rowid+"?")) {
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		}//If the user is using IE
		else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}	
		var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="1") ? 'controlpanel/' : '';
		var url = path+"ajaxdeleteproductimage.php?image_id="+image_id;	
		xmlhttp.open('GET', url, true);
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				var answer = xmlhttp.responseText;
				if(document.getElementById("frompublic") && document.getElementById("frompublic").value=="1") {
					window.location.href = "editProduct.php?id="+product_id;		
				}else {
					window.location.href = "product.php?action=edit&id="+product_id;
				}
			}
		}
		xmlhttp.send(null);	
	}
}



function deleteCountry(country_id) {	
	if(confirm("Are you sure to delete the Country?")) {
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		}//If the user is using IE
		else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}	
		var url = "ajaxcountrydelete.php?country_id="+country_id;						
		xmlhttp.open('GET', url, true);
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				var answer = xmlhttp.responseText;
				if(trim(answer)=="") {
					window.location.href = "country_view.php";
				}else {
					alert(answer);				
					return false;
				}
			}
		}
		xmlhttp.send(null);	
	}
}

function deleteTown(town_id) {	
	if(confirm("Are you sure to delete the Town?")) {
		if (window.XMLHttpRequest) {
			xmlhttp = new XMLHttpRequest();
		}//If the user is using IE
		else if (window.ActiveXObject) {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}	
		var url = "ajaxtowndelete.php?town_id="+town_id;						
		xmlhttp.open('GET', url, true);
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				var answer = xmlhttp.responseText;
				if(trim(answer)=="") {
					window.location.href = "town_view.php";
				}else {
					alert(answer);				
					return false;
				}
			}
		}
		xmlhttp.send(null);	
	}
}


function checkCR(evt) {

    var evt  = (evt) ? evt : ((event) ? event : null);

    var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);

    if (evt.keyCode == 13) {
		alert("Please do not use your return key when entering the body texts.");
		document.frmcategory.txtabodydescription.focus();
		return false;
	}
}

function chooseSellerType(value) {
	if(value=="0") {
		document.getElementById("agentlogo").style.display = '';	
	}else {
		document.getElementById("agentlogo").style.display = 'none';	
	}	
}


function onClickSaleorRent(value) {
	if(value=="0") {
		document.getElementById("rent").style.display = '';
		document.getElementById("askprice").style.display = 'none';
		document.getElementById("rentprice").style.display = '';		
		document.getElementById("petsallowed").style.display = '';
	}else {
		document.getElementById("rent").style.display = 'none';
		document.getElementById("askprice").style.display = '';
		document.getElementById("rentprice").style.display = 'none';
		document.getElementById("petsallowed").style.display = 'none';
	}
	document.getElementById("rentorsale").value = value;
}


function changeUserType(value) {
	if(value=="1") {
		document.getElementById("buyerpart").style.display = '';
		document.getElementById("sellerpart").style.display = 'none';
		//var f = document.form1;
	}else {
		document.getElementById("buyerpart").style.display = 'none';
		document.getElementById("sellerpart").style.display = '';	
		var f = document.form2;
		//document.getElementById("user_seller_agent").checked = true;
		//document.getElementById("agentlogo").style.display = '';
	}	
	for(var s=0; s<f.elements.length; s++){ 
		elem = f.elements[s];
		if(elem.type=="text" || elem.type=="password" || elem.type=="textarea") {
			elem.value = "";
		}else if(elem.type=="checkbox") {
			elem.checked = false;			
		}
	}
}
/* --------------------------------------------------------------------------------------------- */
/* New registrtion */
function changeUserTypeNew(value) {
	if(value=="1") {
		
		document.getElementById("buyerpart").style.display = '';
		
		document.getElementById("sellerpart").style.display = 'none';
		
		//var f = document.form1;
	}else {
		
		document.getElementById("buyerpart").style.display = 'none';
		
		document.getElementById("sellerpart").style.display = '';	
		
		//var f = document.form2;
		//document.getElementById("user_seller_agent").checked = true;
		//document.getElementById("agentlogo").style.display = '';
	}	
	/*for(var s=0; s<f.elements.length; s++){ 
		elem = f.elements[s];
		if(elem.type=="text" || elem.type=="password" || elem.type=="textarea") {
			elem.value = "";
		}else if(elem.type=="checkbox") {
			elem.checked = false;			
		}
	}*/
}
/* --------------------------------------------------------------------------------------------- */
function choosePropertyType(value) {	
	if(value=="0") {
		document.getElementById("petsallowed").style.display = '';
		document.getElementById("rentprice").style.display = '';
		
		document.getElementById("rent").style.display = '';
		document.getElementById("askprice").style.display = 'none';
	}else {		
		document.getElementById("property_is_pets_allowed").checked = false;
		document.getElementById("petsallowed").style.display = 'none';
		document.getElementById("rentprice").style.display = 'none';
		
		document.getElementById("rent").style.display = 'none';
		document.getElementById("askprice").style.display = '';
	}	
	document.getElementById("rentorsale").value = value;
}



function  countryValidate() {
	var form = document.form1;
	if(TextValidate(form.country_name,"Country Name")==false) { return false;	}	
	var country_id = form.country_id.value;	
	var type =  (trim(country_id)=="") ? "add" : "modify";	
	var cname = form.country_name.value;	
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}
	//If the user is using IE
	else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	$trans = {'&' : '^$^', '#' : '^@^', '+' : '$^@'};
	var passname = strtr(cname, $trans);
	var url = "ajaxcountrynamecheck.php?type="+type+"&name="+passname+"&country_id="+country_id;	
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(trim(answer)=="") {
				document.form1.action = "country.php";
				document.form1.submit();
			}else {
				alert(answer);
				document.form1.country_name.focus();
				return false;
			}
		}
	}
	xmlhttp.send(null);	
}

function  onChangeCountry(country_id) {
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}//If the user is using IE
	else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var x = document.form1.property_town;
	var len = x.options.length;
	for (j = len - 1; j>=1; j--) {
		x.remove(j);
	}	
	var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="1") ? 'controlpanel/' : '';
	var url = path+"ajaxtownnamelist.php?country_id="+country_id;	
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(trim(answer)!="") {
				var text = answer.split("^^");
				var reccount = text[0];
				var record = text[1].split("$@$");
				for(i=0;i<reccount;i++) {
					var subcat = record[i].split("!$!");
					var j = i+1;
					document.form1.property_town.options[j] =  new Option(subcat[1],subcat[0]);
				}
				document.form1.property_town.options[0].selected =true;					
			}
		}
	}
	xmlhttp.send(null);	
}



function  townValidate() {
	var form = document.form1;
	if(SelectValidate(form.country_id,"Country")==false) { return false;	}
	if(TextValidate(form.town_name,"Town Name")==false) { return false;	}
	var country_id = form.country_id.value;	
	var town_id = form.town_id.value;	
	var type =  (trim(town_id)=="") ? "add" : "modify";	
	var cname = form.town_name.value;	
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}
	//If the user is using IE
	else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	$trans = {'&' : '^$^', '#' : '^@^', '+' : '$^@'};
	var passname = strtr(cname, $trans);
	var url = "ajaxtownnamecheck.php?type="+type+"&name="+passname+"&town_id="+town_id+"&country_id="+country_id;	
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(trim(answer)=="") {
				document.form1.action = "town.php";
				document.form1.submit();
			}else {
				alert(answer);
				document.form1.town_name.focus();
				return false;
			}
		}
	}
	xmlhttp.send(null);	
}


// To validate admin form fields
function adminValidate() {
	if(SelectValidate(document.frmadmin.seladminsalutation,"Salutation")==false) { return false;	}
	if(TextValidate(document.frmadmin.txtadminname,"Admin Name")==false) { return false;	}
 	if(TextValidate(document.frmadmin.txtadminemail,"Email")==false) { return false;	}
	if(EmailValidate(document.frmadmin.txtadminemail,"Email")==false) { return false;	}
	if(TextValidate(document.frmadmin.txtadminusername,"Username")==false) { return false;	}
	if(TextValidate(document.frmadmin.pwdadminpassword,"Password")==false) { return false;	}
	if(TextValidate(document.frmadmin.pwdadminconfirmpassword,"Confrim Password")==false) { return false;}
   	if(document.frmadmin.pwdadminconfirmpassword.value != document.frmadmin.pwdadminpassword.value){
		alert("Your Password and Confirm Password does not match.");
		document.frmadmin.pwdadminconfirmpassword.focus();
		return false;
	}
	document.frmadmin.action = "admin.php";
	document.frmadmin.submit();
}

function enquiryValidate() {
	var form = document.form1;
	if(SelectValidate(form.enquiry_propertyid,"Property")==false) { return false;	}
	if(TextValidate(form.enquiry_name,"Name")==false) { return false;	}
	if(TextValidate(form.enquiry_email,"Email")==false) { return false;	}
	if(EmailValidate(form.enquiry_email,"Email")==false) { return false;	}
	if(TextValidate(form.enquiry_phone,"Phone")==false) { return false;	}
	if(TextAreaValidate(form.enquiry_message,"Message")==false) { return false;	}
	form.action = "enquiry.php";
	form.submit();
}



// To validate admin form fields
function propertyValidate() {
	var form = document.form1;
	if(SelectValidate(form.property_type,"Type")==false) { return false;	}	
	if(optvalidatenew("form1","property_is_rent_or_price","Type")==false) { return false;	}
	var text = (document.getElementById("rentorsale").value=="1") ? "Asking Price" : "Rent";
 	if(NumberValidate(form.property_price,text)==false) { return false;	}
	if(document.getElementById("rentorsale").value!="1") {		
		if(optvalidatenew("form1","property_price_type","Rent Type")==false) { return false;	}
	}

	if(TextValidate(form.property_postcode,"Postcode")==false) { return false;	}
	if(TextAreaValidate(form.property_address1,"Address 1")==false) { return false;	}
	if(TextAreaValidate(form.property_address2,"Address 2")==false) { return false;	}
	if(TextAreaValidate(form.property_address3,"Address 3")==false) { return false;	}
	if(TextValidate(form.property_country,"Country")==false) { return false;	}
	if(TextValidate(form.property_town,"Town")==false) { return false;}		
	if(trim(form.property_floor_plan.value)!=""){
		var filename = form.property_floor_plan.value.split(".");
		var len = filename.length-1;
		var file_ext = filename[len];
		file_ext = file_ext.toLowerCase(); 
		if(file_ext!="pdf") {
		  alert("Please select a valid pdf document");
		  form.property_floor_plan.focus();
		  return false;
		}  
	}
	
	if(trim(form.property_epc_pdf.value)!=""){
		var filename = form.property_epc_pdf.value.split(".");
		var len = filename.length-1;
		var file_ext = filename[len];
		file_ext = file_ext.toLowerCase(); 
		if(file_ext!="pdf") {
		  alert("Please select a valid pdf document");
		  form.property_epc_pdf.focus();
		  return false;
		}  
	}

	if(NumberValidate(form.property_bedrooms,"Number of Bedrooms")==false) { return false;	}
	if(NumberValidate(form.property_bathrooms,"Number of Bathrooms")==false) { return false;}
	if(TextAreaValidate(form.property_facilities,"Facilities")==false) { return false;	}
	if(TextAreaValidate(form.property_description,"Detailed Description")==false) { return false;	}
	form.action = "property.php";
	form.submit();
}

// Reports validate

function reportValidate(){
		var form = document.form1;
		if(SelectValidate(form.report_product_id,"Product")==false) { return false;	}
		if(SelectValidate(form.report_type,"Report type")==false) { return false;	}
		
		/*if(trim(form.report_path_name.value)==""){
			alert("Please select a valid pdf document");
			form.report_path_name.focus();
			return false;
		}*/

		if(trim(form.report_path_name.value)!=""){
			var filename = form.report_path_name.value.split(".");
			var len = filename.length-1;
			var file_ext = filename[len];
			file_ext = file_ext.toLowerCase(); 
			if(file_ext!="pdf") {
			  alert("Please select a valid pdf document");
			  form.report_path_name.focus();
			  return false;
			}
		}
		/*if(TextAreaValidate(form.report_comments,"Facilities")==false) { return false;	}*/
		form.action = "report.php";
		form.submit();
}


// To validate admin form fields
function userSellerValidate() {
	var form = document.form1;	
	if(OptValidate(form.user_seller_type_sale,"Seller Type")==false) { return false;	}
	if(trim(form.user_seller_agent_logo.value)!=""){
		var filename = form.user_seller_agent_logo.value.split(".");
		var len = filename.length-1;
		var file_ext = filename[len];
		file_ext = file_ext.toLowerCase(); 
		if(file_ext!="gif" && file_ext!="jpg"  && file_ext!="jpeg") {
		  alert("Please select a valid image of jpg, jpeg or gif formats");
		  form.user_seller_agent_logo.focus();
		  return false;
		}  
	} 	
	if(TextValidate(form.user_seller_firstname,"First Name")==false) { return false;	}
	if(TextValidate(form.user_seller_lastname,"Last Name")==false) { return false;	}
	if(TextValidate(form.user_seller_companyname,"Company Name")==false) { return false;	}
	if(TextValidate(form.user_seller_email1,"Email 1")==false) { return false;	}
	if(EmailValidate(form.user_seller_email1,"Email 1")==false) { return false;	}
	if(trim(form.user_seller_email2.value)!="") {
		if(EmailValidate(form.user_seller_email2,"Email 2")==false) { return false;	}		
	}
	if(trim(form.user_seller_email3.value)!="") {
		if(EmailValidate(form.user_seller_email3,"Email 3")==false) { return false;	}		
	}
	if(trim(form.user_seller_email4.value)!="") {
		if(EmailValidate(form.user_seller_email4,"Email 4")==false) { return false;	}		
	}
	if(trim(form.user_seller_email5.value)!="") {
		if(EmailValidate(form.user_seller_email5,"Email 5")==false) { return false;	}		
	}
	if(TextValidate(form.user_seller_phone,"Phone")==false) { return false;	}
	if(TextValidate(form.user_seller_mobile,"Mobile")==false) { return false;}	
	if(TextAreaValidate(form.user_seller_address1,"Address1")==false) { return false;	}	
	if(TextValidate(form.user_seller_town,"Town")==false) { return false;	}	
	if(TextValidate(form.user_seller_country,"Country")==false) { return false;}	
	if(TextValidate(form.user_seller_postcode,"Postcode")==false) { return false;	}
	if(TextValidate(form.user_seller_password,"Password")==false) { return false;	}
	if(form.user_seller_confirm_password) {
		if(TextValidate(form.user_seller_confirm_password,"Confirm Password")==false) { return false;	}		
		if(Comparetextboxes(form.user_seller_password,form.user_seller_confirm_password)== false) { return false;}
	}
	
	var type = "add";
	var id = form.user_seller_id.value;
	var passname = trim(form.user_seller_email1.value);
	if(form.user_seller_id.value!="") {
		var type = "edit";		
	}
	//ajax validation for email address
	var xmlhttp = makeObject();
	var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="2") ? '../' : '';
	var url = path+"ajaxselleremailcheck.php?type="+type+"&name="+passname+"&id="+id;
	//alert(url);
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(trim(answer)=="") {
				form.submit();
			}else {
				alert(answer);
				form.user_seller_email1.focus();
				return false;
			}
		}
	}
	xmlhttp.send(null);
}
// To validate admin form fields
function userBuyerValidate() {
	var form = document.form2;	
	if(TextValidate(form.user_buyer_firstname,"First Name")==false) { return false;	}
	if(TextValidate(form.user_buyer_lastname,"Last Name")==false) { return false;	}
	if(TextValidate(form.user_buyer_email,"Email")==false) { return false;	}
	if(EmailValidate(form.user_buyer_email,"Email")==false) { return false;	}
	if(TextValidate(form.user_buyer_phone1,"Phone 1")==false) { return false;	}
	if(TextValidate(form.user_buyer_mobile,"Mobile")==false) { return false;}	
	if(TextAreaValidate(form.user_buyer_address1,"Address1")==false) { return false;	}	
	if(TextValidate(form.user_buyer_town,"Town")==false) { return false;	}	
	if(TextValidate(form.user_buyer_country,"Country")==false) { return false;}	
	if(TextValidate(form.user_buyer_postcode,"Postcode")==false) { return false;	}
	if(TextValidate(form.user_buyer_password,"Password")==false) { return false;	}
	if(form.user_buyer_confirm_password) {
		if(TextValidate(form.user_buyer_confirm_password,"Confirm Password")==false) { return false;	}		
		if(Comparetextboxes(form.user_buyer_password,form.user_buyer_confirm_password)== false) { return false;}
	}
	
	var type = "add";
	var id = form.user_buyer_id.value;
	var passname = trim(form.user_buyer_email.value);
	if(form.user_buyer_id.value!="") {
		var type = "edit";		
	}
	//ajax validation for email address
	var xmlhttp = makeObject();
	var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="2") ? '../' : '';
	var url = path+"ajaxbuyeremailcheck.php?type="+type+"&name="+passname+"&id="+id;						
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(trim(answer)=="") {
				form.submit();
			}else {
				alert(answer);
				form.user_buyer_email.focus();
				return false;
			}
		}
	}
	xmlhttp.send(null);
	
}


// To validate admin form fields

//Owners validation 

function userOwnerValidate() {
	
	var form = document.form2;
	
	if(TextValidate(form.owner_first_name,"First Name")==false) { return false;	}
	if(TextValidate(form.owner_last_name,"Last Name")==false) { return false;	}
	if(SelectValidate(form.owner_gender,"Gender")==false){ return false;	}
	if(TextValidate(form.owner_designation,"Designation")==false) { return false;	}
	if(TextValidate(form.owner_email,"email")==false) { return false;	}
	if(EmailValidate(form.owner_email,"email")==false){ return false;}
	if(TextValidate(form.owner_mobile,"Mobile")==false) { return false;	}
	if(MobileValidate(form.owner_mobile,"Mobile")==false) { return false;	}
	if(SelectValidate(form.owner_industry,"Industry")==false){ return false;	}
	if(TextValidate(form.owner_org_name,"Organization name")==false) { return false;	}
	if(TextValidate(form.owner_org_address,"Organization address")==false) { return false;	}
	//if(TextValidate(form.owner_org_postalcode,"Organization Postalcode")==false) { return false;	}
	if(form.owner_org_postalcode.value!=""){
		if(NumberValidate(form.owner_org_postalcode,"Organization Postalcode")==false) { return false;	}
	}
	if(form.owner_org_logo && trim(form.owner_org_logo.value)!=""){
		var filename = form.owner_org_logo.value.split(".");
		var len = filename.length-1;
		var file_ext = filename[len];
		file_ext = file_ext.toLowerCase(); 
		//alert(file_ext);
		if((file_ext!="jpg") && (file_ext!="jpeg") && (file_ext!="gif")) {
		  alert("Please select a valid image file (jpg/jpeg/gif) for Organisation Logo");
		  form.owner_org_logo.focus();
		  return false;
		}  
	}

	if(TextValidate(form.owner_org_profile,"Company profile")==false) { return false;	}
	/*if(TextValidate(form.owner_org_url,"URL")==false) { return false;	}*/
	
	if(UrlValidate(form.owner_org_url,"URL")==false) { return false;	}
	
	if(TextValidate(form.owner_org_phone,"Phone")==false) { return false;	}
	if(PhoneValidateNormal(form.owner_org_phone,"Phone")==false) { return false;	}
	if(SelectValidate(form.owner_org_presence,"Presence in")==false){ return false;	}
	if(SelectValidate(form.owner_org_year,"Year of Establishment")==false){ return false;	}
	if(SelectValidate(form.owner_org_customers,"No of Customers")==false){ return false;	}
	
	if(form.owner_corporate_profile && trim(form.owner_corporate_profile.value)!=""){
		var filename = form.owner_corporate_profile.value.split(".");
		var len = filename.length-1;
		var file_ext = filename[len];
		file_ext = file_ext.toLowerCase(); 
		if(file_ext!="pdf") {
		  alert("Please select a valid PDF document for corporate profile");
		  form.owner_corporate_profile.focus();
		  return false;
		}  
	}

	if(form.owner_mgmt_team_profile && trim(form.owner_mgmt_team_profile.value)!=""){
		var filename = form.owner_mgmt_team_profile.value.split(".");
		var len = filename.length-1;
		var file_ext = filename[len];
		file_ext = file_ext.toLowerCase(); 
		if(file_ext!="pdf") {
		  alert("Please select a valid PDF document for Management Team");
		  form.owner_mgmt_team_profile.focus();
		  return false;
		}  
	}
	
	//if(TextValidate(form.owner_username,"Username")==false) { return false;	}
	//if(TextValidate(form.owner_password,"Password")==false) { return false;	}
	
	/*if(form.owner_confirm_password) {
		if(TextValidate(form.owner_confirm_password,"Confirm Password")==false) { return false;	}		
		if(Comparetextboxes(form.owner_password,form.owner_confirm_password)== false) { return false;}
	}*/
	
	/*var type = "add";
	var id = form.owner_id.value;
	var passname = trim(form.owner_username.value);
	var email = trim(form.owner_email.value);
	if(form.owner_id.value!="") {
		var type = "edit";		
	}
	
	//ajax validation for username or email 
	
	var xmlhttp = makeObject();
	var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="2") ? '../' : '';
	var url = path+"ajaxowneremailcheck.php?type="+type+"&name="+passname+"&id="+id;						
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(trim(answer)=="") {
				form.submit();
			}else {
				alert(answer);
				form.owner_email.focus();
				return false;
			}
		}
	}
	xmlhttp.send(null);*/

	form.submit();
	
}

/*Distributor validation */

function userDistributorValidate() {
	
	var form = document.form2;
	
	if(TextValidate(form.distributor_first_name,"First Name")==false) { return false;	}
	if(TextValidate(form.distributor_last_name,"Last Name")==false) { return false;	}
	if(SelectValidate(form.distributor_gender,"Gender")==false){ return false;	}
	if(TextValidate(form.distributor_designation,"Designation")==false) { return false;	}
	if(TextValidate(form.distributor_email,"Email")==false) { return false;	}
	if(EmailValidate(form.distributor_email,"Email")==false){ return false;}
	if(TextValidate(form.distributor_mobile,"Mobile")==false) { return false;	}
	if(MobileValidate(form.distributor_mobile,"Mobile")==false) { return false;	}
	if(SelectValidate(form.distributor_industry,"Industry")==false){ return false;	}
	if(TextValidate(form.distributor_org_name,"Organization name")==false) { return false;	}
	if(TextValidate(form.distributor_org_address,"Organization address")==false) { return false;	}
	if(TextValidate(form.distributor_org_postalcode,"Organization Postalcode")==false) { return false;	}
	if(NumberValidate(form.distributor_org_postalcode,"Organization Postalcode")==false) { return false;	}
	if(UrlValidate(form.distributor_org_url,"URL")==false) { return false;	}
	if(TextValidate(form.distributor_org_phone,"Phone")==false) { return false;	}
	if(PhoneValidateNormal(form.distributor_org_phone,"Phone")==false) { return false;	}
	
	if(SelectValidate(form.distributor_area_interest,"Area of Interest")==false){ return false;	}
	if(SelectValidate(form.distributor_states,"States Coverage")==false){ return false;	}
	if(SelectValidate(form.distributor_coverage,"Distributor Coverage")==false){ return false;	}
	
	if(TextValidate(form.distributor_username,"Username")==false) { return false;	}
	if(TextValidate(form.distributor_password,"Password")==false) { return false;	}
	
	if(form.distributor_confirm_password) {
		if(TextValidate(form.distributor_confirm_password,"Confirm Password")==false) { return false;	}		
		if(Comparetextboxes(form.distributor_password,form.distributor_confirm_password)== false) { return false;}
	}
	
	/*var type = "add";
	var id = form.distributor_id.value;
	var passname = trim(form.distributor_username.value);
	var email = trim(form.distributor_email.value);
	if(form.distributor_id.value!="") {
		var type = "edit";		
	}
	
	//ajax validation for username or email 
	
	var xmlhttp = makeObject();
	var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="2") ? '../' : '';
	var url = path+"ajaxowneremailcheck.php?type="+type+"&name="+passname+"&id="+id;						
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(trim(answer)=="") {
				form.submit();
			}else {
				alert(answer);
				form.distributor_email.focus();
				return false;
			}
		}
	}
	xmlhttp.send(null);*/
	
	form.submit();
}

/*Technologist validate */

function userTechnologistValidate() {
	
	var form = document.form2;
	
	if(TextValidate(form.tech_first_name,"First Name")==false) { return false;	}
	if(TextValidate(form.tech_last_name,"Last Name")==false) { return false;	}
	if(SelectValidate(form.tech_gender,"Gender")==false){ return false;	}
	if(TextValidate(form.tech_designation,"Designation")==false) { return false;	}
	if(TextValidate(form.tech_email,"Email")==false) { return false;	}
	if(EmailValidate(form.tech_email,"Email")==false){ return false;}
	if(TextValidate(form.tech_mobile,"Mobile")==false) { return false;	}
	if(MobileValidate(form.tech_mobile,"Mobile")==false) { return false;	}
	if(TextValidate(form.tech_education,"Education Qualification")==false) { return false;	}
	if(TextValidate(form.tech_occupation,"Occupation")==false) { return false;	}
	if(TextValidate(form.tech_org_name,"Organization name")==false) { return false;	}
	if(form.tech_org_url.value!=""){
		if(UrlValidate(form.tech_org_url,"URL")==false) { return false;	}
	}
	if(SelectValidate(form.tech_experience,"Total Years of Experience")==false){ return false;	}
	if(TextValidate(form.tech_username,"Username")==false) { return false;	}
	if(TextValidate(form.tech_password,"Password")==false) { return false;	}
	
	if(form.tech_confirm_password) {
		if(TextValidate(form.tech_confirm_password,"Confirm Password")==false) { return false;	}		
		if(Comparetextboxes(form.tech_password,form.tech_confirm_password)== false) { return false;}
	}
	
	/*var type = "add";
	var id = form.tech_id.value;
	var passname = trim(form.tech_username.value);
	var email = trim(form.tech_email.value);
	if(form.tech_id.value!="") {
		var type = "edit";		
	}
	
	//ajax validation for username or email 
	
	var xmlhttp = makeObject();
	var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="2") ? '../' : '';
	var url = path+"ajaxowneremailcheck.php?type="+type+"&name="+passname+"&id="+id;						
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(trim(answer)=="") {
				form.submit();
			}else {
				alert(answer);
				form.tech_email.focus();
				return false;
			}
		}
	}
	xmlhttp.send(null);*/
	
	form.submit();
}


/*Customer validate */

function userCustomerValidate() {
	
	var form = document.form2;
	
	if(TextValidate(form.customer_first_name,"First Name")==false) { return false;	}
	if(TextValidate(form.customer_last_name,"Last Name")==false) { return false;	}
	if(SelectValidate(form.customer_gender,"Gender")==false){ return false;	}
	if(TextValidate(form.customer_mobile,"Mobile")==false) { return false;	}
	if(MobileValidate(form.customer_mobile,"Mobile")==false) { return false;	}
	if(TextValidate(form.customer_address,"Address")==false) { return false;	}
	if(TextValidate(form.customer_occupation,"Occupation")==false) { return false;	}
	if(TextValidate(form.customer_email,"Email")==false) { return false;	}
	if(EmailValidate(form.customer_email,"Email")==false){ return false;}
	
	if(TextValidate(form.customer_product,"Product Purchased")==false) { return false;	}
	if(TextValidate(form.customer_modelname,"Model name")==false) { return false;	}
	if(TextValidate(form.customer_date_purchase,"Date of purchase")==false) { return false;	}
	if(TextValidate(form.customer_dealer_name,"	Dealer name")==false) { return false;	}
	
	if(TextValidate(form.customer_username,"Username")==false) { return false;	}
	if(TextValidate(form.customer_password,"Password")==false) { return false;	}
	
	if(form.customer_confirm_password) {
		if(TextValidate(form.customer_confirm_password,"Confirm Password")==false) { return false;	}		
		if(Comparetextboxes(form.customer_password,form.customer_confirm_password)== false) { return false;}
	}
	
	/*var type = "add";
	var id = form.customer_id.value;
	var passname = trim(form.customer_username.value);
	var email = trim(form.customer_email.value);
	if(form.customer_id.value!="") {
		var type = "edit";		
	}
	
	//ajax validation for username or email 
	
	var xmlhttp = makeObject();
	var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="2") ? '../' : '';
	var url = path+"ajaxowneremailcheck.php?type="+type+"&name="+passname+"&id="+id;						
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(trim(answer)=="") {
				form.submit();
			}else {
				alert(answer);
				form.customer_email.focus();
				return false;
			}
		}
	}
	xmlhttp.send(null);*/
	
	form.submit();
}

/*Product validate*/
function productValidate(){
		var form = document.form1;
		if(SelectValidate(form.product_owner_id,"Owner")==false){ return false;}
		if(TextValidate(form.product_name,"Product Name")==false) { return false;}
		if(SelectValidate(form.product_category,"Category")==false){ return false;}
		if(SelectValidate(form.product_type,"Type")==false){ return false;}
		if(SelectValidate(form.product_fueltype,"Fuel Type")==false){ return false;}
		/*if(SelectValidate(form.product_customers,"No. of Customers")==false){ return false;}
		if(TextValidate(form.product_model,"Model Number")==false) { return false;}
		if(TextValidate(form.product_accessories,"Accessories")==false) { return false;}*/
		if(TextValidate(form.product_short_desc,"Short description")==false) { return false;}
		if(TextValidate(form.product_detailed_desc,"Detailed description")==false) { return false;}
		if(TextValidate(form.product_pricing,"Base price")==false) { return false;}
		/*if(TextValidate(form.product_additonal_pricing,"Additional price details")==false) { return false;}
		if(TextValidate(form.product_transport,"Transport")==false) { return false;}
		if(TextValidate(form.product_warranty,"Warranty")==false) { return false;}*/
		if(TextValidate(form.product_manufacture,"Manufactured in")==false) { return false;}
		
		if(form.product_specification && trim(form.product_specification.value)!=""){
			var filename = form.product_specification.value.split(".");
			var len = filename.length-1;
			var file_ext = filename[len];
			file_ext = file_ext.toLowerCase(); 
			if(file_ext!="pdf") {
			  alert("Please select a valid PDF document for product Specification");
			  form.product_specification.focus();
			  return false;
			}  
		}
		
		if(form.product_brochure && trim(form.product_brochure.value)!=""){
			var filename = form.product_brochure.value.split(".");
			var len = filename.length-1;
			var file_ext = filename[len];
			file_ext = file_ext.toLowerCase(); 
			if(file_ext!="pdf") {
			  alert("Please select a valid PDF document for Product Brochure");
			  form.product_brochure.focus();
			  return false;
			}  
		}
		
		if(form.product_bulk_customer && trim(form.product_bulk_customer.value)!=""){
			var filename = form.product_bulk_customer.value.split(".");
			var len = filename.length-1;
			var file_ext = filename[len];
			file_ext = file_ext.toLowerCase(); 
			if(file_ext!="xls" || file_ext!="xlsx"  ) {
			  alert("Please select a valid PDF document for Customer Details");
			  form.product_bulk_customer.focus();
			  return false;
			}  
		}
		
		if(form.product_tech_review && trim(form.product_tech_review.value)!=""){
			var filename = form.product_tech_review.value.split(".");
			var len = filename.length-1;
			var file_ext = filename[len];
			file_ext = file_ext.toLowerCase(); 
			if(file_ext!="pdf") {
			  alert("Please select a valid PDF document for Technical Review Report");
			  form.product_tech_review.focus();
			  return false;
			}  
		}
		
		if(form.product_research_report && trim(form.product_research_report.value)!=""){
			var filename = form.product_research_report.value.split(".");
			var len = filename.length-1;
			var file_ext = filename[len];
			file_ext = file_ext.toLowerCase(); 
			if(file_ext!="pdf") {
			  alert("Please select a valid PDF document for Customer Research Report");
			  form.product_research_report.focus();
			  return false;
			}  
		}
		
		if(form.product_customer_review && trim(form.product_customer_review.value)!=""){
			var filename = form.product_customer_review.value.split(".");
			var len = filename.length-1;
			var file_ext = filename[len];
			file_ext = file_ext.toLowerCase(); 
			if(file_ext!="pdf") {
			  alert("Please select a valid PDF document for Customer Reviews");
			  form.product_customer_review.focus();
			  return false;
			}  
		}
		
		if(form.rowcount && trim(form.rowcount.value)!=""){
		var count = parseInt(form.rowcount.value,10);
		for(var i=1;i<=count;i++) {
			var fieldname = "image_path_"+i;
			var fname = document.getElementById(fieldname).value;
			if(fname!="") {
				var filename = fname.split(".");
				var len = filename.length-1;
				var file_ext = filename[len];
				file_ext = file_ext.toLowerCase(); 
				if(file_ext!="gif" && file_ext!="jpg"  && file_ext!="jpeg") {
				  alert("Please select a valid image of jpg, jpeg or gif formats");
				  document.getElementById(fieldname).focus();
				  return false;
				}
			}
		}
	}
	form.submit();
}

/* Industry Types validate*/

function industryTypeValidate(){
		var form = document.form1;	
		if(TextValidate(form.industry_name,"Industry Name")==false) { return false;	}
		form.submit();
}

/* Category validate*/

function categoryValidate(){
		var form = document.form1;	
		if(TextValidate(form.category_name,"Category Name")==false) { return false;	}
		form.submit();
}

/* Product type validate*/

function typeValidate(){
		var form = document.form1;	
		if(TextValidate(form.type_name,"Product Type Name")==false) { return false;	}
		if(SelectValidate(form.type_category_id,"Category")==false){ return false;	}
		form.submit();
}


/* Product type validate*/

function subtypeValidate(){
		var form = document.form1;	
		if(TextValidate(form.subtype_name,"Product Type Name")==false) { return false;	}
		if(SelectValidate(form.subtype_cat_id,"Category")==false){ return false;	}
		form.submit();
}

//----------------------------------------New Buyer validate ---------------------------------------------------------------//

function newUserBuyerValidate() {
	var form = document.regForm;	
	if(TextValidate(form.txtFirstName,"First Name")==false) { return false;	}
	if(TextValidate(form.txtLastName,"Last Name")==false) { return false;	}
	if(TextValidate(form.txtPostcode,"Postcode")==false) { return false;	}
	
	if(TextAreaValidate(form.txtStreet,"Street")==false) { return false;	}		
	//if(SelectValidate(form.selCountry,"Country")==false) { return false;}	
	//if(SelectValidate(form.selState,"State")==false) { return false;	}
	//if(SelectValidate(form.selTown,"Town")==false) { return false;	}
	if(TextValidate(form.user_email,"Email")==false) { return false;	}
	if(EmailValidate(form.user_email,"Email")==false) { return false;	}
		
	if(TextValidate(form.txtPwd,"Password")==false) { return false;	}
	if(form.txtConfirmPwd) {
		if(TextValidate(form.txtConfirmPwd,"Confirm Password")==false) { return false;	}		
		if(Comparetextboxes(form.txtPwd,form.txtConfirmPwd)== false) { return false;}
	}
	
	if(TextValidate(form.user_phone,"Phone")==false) { return false;	}
	if(TextValidate(form.txtAddContact,"Additional Contact Number")==false) { return false;}
	/*if(form.user_buyer_allow_thirdparty.checked==true){
		form.user_buyer_allow_thirdparty.value=1;
	}*/
	var type = "add";
	var id = form.user_buyer_id.value;
	var passname = trim(form.user_email.value);
	if(form.user_buyer_id.value!="") {
		var type = "edit";		
	}
	
	//ajax validation for email address
	
	var xmlhttp = makeObject();
	var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="2") ? '../' : '';
	var url = path+"ajaxbuyeremailcheck.php?type="+type+"&name="+passname+"&id="+id;						
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(trim(answer)=="") {
				form.submit();
			}else {
				alert(answer);
				form.user_buyer_email.focus();
				return false;
			}
		}
	}
	xmlhttp.send(null);
	
}



// To validate admin form fields
function userPropertyValidate(submit_type) {
	var form = document.form1;	
	if(optvalidatenew("form1","property_is_rent_or_price","Type")==false) { return false;	}	
	//if(OptValidate(form.property_is_rent_or_price,"Type")==false) { return false;	}
	if(TextValidate(form.property_postcode,"Postcode")==false) { return false;	}
	if(TextAreaValidate(form.property_address1,"Street")==false) { return false;	}
	if(TextAreaValidate(form.property_address2,"Local Area")==false) { return false;	}
	if(SelectValidate(form.property_town,"Town")==false) { return false;}	
	if(SelectValidate(form.property_country,"Country")==false) { return false;	}	
	if(SelectValidate(form.property_type,"Property Type")==false) { return false;	}	
 	if(SelectValidate(form.property_bedrooms,"Number of Bedrooms")==false) { return false;	}	
	
	//price validation
	var ptype = form.property_is_rent_or_price.value;
	var text = (document.getElementById("rentorsale").value=="1") ? "Asking Price" : "Rent";
	var priceval = trim(form.property_price.value);
	if(isNaN(priceval) && priceval.length<=1) {
		alert("Please enter "+text);
		form.property_price.focus();
		return false;
	}
	var pricevalue = "";
	for(var j=1;j<priceval.length;j++) {
		if(isNaN(priceval[j])) {
			alert("Please enter a valid "+text);
			form.property_price.focus();
			return false;
		}
		pricevalue = pricevalue+priceval[j];
	}	
	form.property_price_value.value = pricevalue; 
	
	if(document.getElementById("rentorsale").value!="1") {		
		if(optvalidatenew("form1","property_price_type","Rent Type")==false) { return false;	}
	}
	
	//if(NumberValidate(form.property_price,"Price")==false) { return false;	}		
	
	if(form.rowcount && trim(form.rowcount.value)!=""){
		var count = parseInt(form.rowcount.value,10);
		for(var i=1;i<=count;i++) {
			var fieldname = "image_path_"+i;
			var fname = document.getElementById(fieldname).value;
			if(fname!="") {
				var filename = fname.split(".");
				var len = filename.length-1;
				var file_ext = filename[len];
				file_ext = file_ext.toLowerCase(); 
				if(file_ext!="gif" && file_ext!="jpg"  && file_ext!="jpeg") {
				  alert("Please select a valid image of jpg, jpeg or gif formats");
				  document.getElementById(fieldname).focus();
				  return false;
				}  
			}
		}
	} 	

	
	if(form.property_floor_plan && trim(form.property_floor_plan.value)!=""){
		var filename = form.property_floor_plan.value.split(".");
		var len = filename.length-1;
		var file_ext = filename[len];
		file_ext = file_ext.toLowerCase(); 
		if(file_ext!="pdf") {
		  alert("Please select a valid pdf document");
		  form.property_floor_plan.focus();
		  return false;
		}  
	} 	
	if(form.property_epc_pdf && trim(form.property_epc_pdf.value)!=""){
		var filename = form.property_epc_pdf.value.split(".");
		var len = filename.length-1;
		var file_ext = filename[len];
		file_ext = file_ext.toLowerCase(); 
		if(file_ext!="pdf") {
		  alert("Please select a valid pdf document");
		  form.property_epc_pdf.focus();
		  return false;
		}  
	} 	
	if(TextAreaValidate(form.property_description,"Detailed Description")==false) { return false;	}	
	form.submit_type.value = submit_type;
	form.submit();
}


function AddShorstlist(property_id) {	
	var xmlhttp = makeObject();
	var url = "ajaxAddShorstlist.php?property_id="+property_id;						
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			var answerarray = answer.split("@@");
			var flag = trim(answerarray[0]);
			var msg = trim(answerarray[1]);
			if(flag=="1") {
				alert(msg);
				return false;
			}else if(flag=="2"){
				window.location.href = msg;				
			}
		}
	}
	xmlhttp.send(null);		
}


function userLoginValidate() {
	var form = document.form1;
	if(TextValidate(form.user_email,"Email Address")==false) { return false;	
	
	}
	if(EmailValidate(form.user_email,"Email Address")==false) { return false;	}
	if(TextValidate(form.user_password,"Password")==false) { return false;	}
	if(OptValidate(form.user_seller_type_sale,"User Type")==false) { return false;	}
	form.submit();
}

function userChangePassword() {
	var form = document.form1;
	if(TextValidate(form.current_pwd,"Current Password")==false) { return false;	}
	if(TextValidate(form.new_pwd,"New Password")==false) { return false;	}
	if(TextValidate(form.confirm_pwd,"Confirm Password")==false) { return false;	}
	if(form.new_pwd.value!=form.confirm_pwd.value){
		alert("The new and confirm password doesn't match");
		form.new_pwd.value=form.confirm_pwd.value='';
		form.new_pwd.focus();
		return false;
		}
	form.submit();
}

function userForgotPasswordValidate() {
	var form = document.form1;
	if(TextValidate(form.user_email,"Email Address")==false) { return false;	}
	if(EmailValidate(form.user_email,"Email Address")==false) { return false;	}
	if(OptValidate(form.user_seller_type_sale,"User Type")==false) { return false;	}
	form.submit();
}

function SearchProduct(page) {
	document.getElementById("page").value = page;
	document.getElementById("pageDisp").value = document.getElementById("selPage").value;
	//alert('page = '+document.getElementById("page").value);
	//alert('pageDisp ='+document.getElementById("pageDisp").value);
	document.frmsearch.submit();
}

function SortProduct(sort_val) {
	document.getElementById("sortby").value = sort_val;
	/*document.getElementById("page").value=document.getElementById("selPage").value;*/
	document.getElementById("pageDisp").value = document.getElementById("selPage").value;
	
	document.frmsearch.submit();
}

function DispProduct(disp_val) {
	document.getElementById("pageDisp").value = disp_val;
	document.frmsearch.submit();
}

//Free 

function SearchProductFree(page) {
	document.getElementById("page").value = page;
	document.getElementById("pageDisp").value = document.getElementById("selPagef").value;
	document.frmsearch.submit();
}

function SortProductFree(sort_val) {
	document.getElementById("sortby").value = sort_val;
	document.frmsearch.submit();
}

function DispProductFree(disp_val) {
	document.getElementById("pageDisp").value = disp_val;
	document.frmsearch.submit();
}

// To validate page form fields
function pageValidate() {
	//var incontent="";
	//incontent=tinyMCE.getContent('txtabodydescription');
	if(TextValidate(document.frmpage.txtpagename,"Page Name")==false) { return false;}
	if(document.getElementById("txtabodydescription").value=="")
	{
	alert("Please enter the content.");
	document.getElementById("txtabodydescription").focus();
	return false;
	}
	
	
	document.frmpage.action="page.php";
	document.frmpage.submit();
}

// Alert message for deleting a page

function deletePage(id) {
	if(confirm("Are you sure to delete the Page?")) {
	    document.form1.action="page.php?action=delete&id="+id;
		document.form1.submit();
 	}  	
}



// Removes leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)&nbsp;/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim(value) {
	
	var re = /((\s*\S+)*)\s*&nbsp;/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	 return value.replace(/^\s+|\s+$/g,'');
}

function contact_validation(){
		if(TextValidateDummy(document.contactForm.contactName,'Name')==false) return false;	
		if(EmailValidateDummy(document.contactForm.contactEmail,"Email Address")==false){return false;}	
		if(TextValidateDummy(document.contactForm.contactSubject,'Subject')==false) return false;	
		if(TextValidateDummy(document.contactForm.contactMessage,'Message')==false) return false;
		
		document.contactForm.action = "contact_mail.php";
		document.contactForm.submit();	
	}
	
	
/*Go scale Functions*/

//Login Validating Function

function user_login_check(){
	 var form = document.loginForm;
	 if(TextValidate(form.txtUname,'username')==false) return false;	
	 if(TextValidate(form.txtPwd,'password')==false) return false;
	 var type = document.getElementById("hidd_usertype").value;
	 var username = document.getElementById("txtUname").value;
	 var pass = document.getElementById("txtPwd").value;

	var xmlhttp = makeObject();
	var url = "ajaxsignin.php?type="+type+"&uname="+username+"&pword="+pass;
	//alert(url);
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(answer!="" && answer!="denied"){
			//alert(answer);
			var login_val = answer.split("~");
				if(trim(login_val[1])=="accessed" && trim(login_val[0])=="1") {
					window.location.href = "ownerProfile.php";
				}else if(trim(login_val[1])=="accessed" && trim(login_val[0])=="2"){
					window.location.href = "distributorProfile.php";
				}else if(trim(login_val[1])=="accessed" && trim(login_val[0])=="3"){
					window.location.href = "technologistProfile.php";
				}else if(trim(login_val[1])=="accessed" && trim(login_val[0])=="4"){
					window.location.href = "customerProfile.php";
				}else {
					alert("Username or Password Incorrect. \n Please try again");
					return false;
				}
			}else {
					alert("Username or Password Incorrect. \n Please try again");
					return false;
				}
		}
	}
	xmlhttp.send(null);
}

function  checkEnterLoginOwn(e){ //e is event object passed from function invocation
	var characterCode ;//literal character code will be stored in this variable	
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e;
	characterCode = e.which; //character code is contained in NN4's which property
	}
	else{
	//e = event
	characterCode = e.keyCode; //character code is contained in IE's keyCode property
	}	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		user_login_check();			
	}
}


function switch_tabs(tab){
	var browserName 	= navigator.appName;
	var temp=new Array();
	
	var browserVersion = navigator.appVersion;
	temp = browserVersion.split(';');

	if(temp[1]){
		var version = temp[1].split(' ');
	}

	if(tab=="basic"){
		/*document.getElementById("freeList").style.display="none";
		document.getElementById("basicList").style.display="";*/
		var category_id  = document.getElementById("cat").value;
		document.getElementById("active").value="basic";
		var ele_1 = document.getElementById("tab1");
		var ele_2 = document.getElementById("tab2")
		if (browserName=="Microsoft Internet Explorer") {
			if(version[2]>="8"){
				ele_1.setAttribute('class', 'tabing-active');
				ele_2.setAttribute('class','tabing-inactive');
			}else{
				ele_1.setAttribute('className', 'tabing-active');
				ele_2.setAttribute('className','tabing-inactive');
			}
		} else {
			ele_1.setAttribute('class', 'tabing-active');	
			ele_2.setAttribute('class','tabing-inactive');
		}
		//alert("base");
		window.location.href = "productSearch.php?active=basic&cat="+category_id;
	}

	if(tab=="free"){
		/*document.getElementById("freeList").style.display="";
		document.getElementById("basicList").style.display="none";*/
		var category_id  = document.getElementById("cat").value;
		document.getElementById("active").value="free";
		var ele_1 = document.getElementById("tab2");
		var ele_2 = document.getElementById("tab1")
		if (browserName=="Microsoft Internet Explorer") {
			if(version[2]>="8"){
				ele_1.setAttribute('class', 'tabing-active');
				ele_2.setAttribute('class','tabing-inactive');
			}else{
				ele_1.setAttribute('className', 'tabing-active');
				ele_2.setAttribute('className','tabing-inactive');
			}
		} else {
			ele_1.setAttribute('class', 'tabing-active');	
			ele_2.setAttribute('class','tabing-inactive');
		}
		window.location.href = "productSearch.php?active=free&cat="+category_id;
	}
}

function switch_tabs_demo(tab){
	var browserName 	= navigator.appName;
	var temp=new Array();
	var browserVersion = navigator.appVersion;
	temp = browserVersion.split(';');
	if(temp[1]){
		var version = temp[1].split(' ');
	}
	
	if(tab=="basic"){
		/*document.getElementById("freeList").style.display="none";
		document.getElementById("basicList").style.display="";*/
		var category_id  = document.getElementById("cat").value;
		document.getElementById("active").value="basic";
		var ele_1 = document.getElementById("tab1");
		var ele_2 = document.getElementById("tab2")
		if (browserName=="Microsoft Internet Explorer") {
			if(version[2]>="8"){
				ele_1.setAttribute('class', 'tabing-active');
				ele_2.setAttribute('class','tabing-inactive');
			}else{
				ele_1.setAttribute('className', 'tabing-active');
				ele_2.setAttribute('className','tabing-inactive');
			}
		} else {
			ele_1.setAttribute('class', 'tabing-active');	
			ele_2.setAttribute('class','tabing-inactive');
		}
		//alert("base");
		window.location.href = "productShowcase.php?active=basic&cat="+category_id;
	}

	if(tab=="free"){
		/*document.getElementById("freeList").style.display="";
		document.getElementById("basicList").style.display="none";*/
		var category_id  = document.getElementById("cat").value;
		document.getElementById("active").value="free";
		var ele_1 = document.getElementById("tab2");
		var ele_2 = document.getElementById("tab1")
		if (browserName=="Microsoft Internet Explorer") {
			if(version[2]>="8"){
				ele_1.setAttribute('class', 'tabing-active');
				ele_2.setAttribute('class','tabing-inactive');
			}else{
				ele_1.setAttribute('className', 'tabing-active');
				ele_2.setAttribute('className','tabing-inactive');
			}
		} else {
			ele_1.setAttribute('class', 'tabing-active');	
			ele_2.setAttribute('class','tabing-inactive');
		}
		window.location.href = "productShowcase.php?active=free&cat="+category_id;
	}
}

/*Product Tab Switching*/

function switch_pro_tab(tab){
	var browserName 	= navigator.appName;
	var temp=new Array();
	var browserVersion = navigator.appVersion;
	temp = browserVersion.split(';');
	if(temp[1]){
		var version = temp[1].split(' ');
	}

	if(tab=="desc"){
		document.getElementById("description-div").style.display="";
		document.getElementById("reviews-div").style.display="none";
		/*document.getElementById("comment-div").style.display="none";*/
		
		var ele_1 = document.getElementById("tab1");
		var ele_2 = document.getElementById("tab2");
		/*var ele_3 = document.getElementById("tab3");*/

		
		if (browserName=="Microsoft Internet Explorer") {
			if(version[2]>="8"){
				ele_1.setAttribute('class', 'tabing-active');
				ele_2.setAttribute('class','tabing-inactive');
				/*ele_3.setAttribute('class','tabing-inactive');*/
			}else{
				ele_1.setAttribute('className', 'tabing-active');
				ele_2.setAttribute('className','tabing-inactive');
				/*ele_3.setAttribute('class','tabing-inactive');*/
			}
		} else {
			ele_1.setAttribute('class', 'tabing-active');
			ele_2.setAttribute('class','tabing-inactive');
			/*ele_3.setAttribute('class','tabing-inactive');*/
		}
	}

	if(tab=="review"){
		/*document.getElementById("freeList").style.display="none";
		document.getElementById("basicList").style.display="";*/
		document.getElementById("description-div").style.display="none";
		document.getElementById("reviews-div").style.display="";
		/*document.getElementById("comment-div").style.display="none";*/
		
		var ele_1 = document.getElementById("tab1");
		var ele_2 = document.getElementById("tab2");
		/*var ele_3 = document.getElementById("tab3");*/
		
		if (browserName=="Microsoft Internet Explorer") {
			if(version[2]>="8"){
				ele_1.setAttribute('class', 'tabing-inactive');
				ele_2.setAttribute('class','tabing-active');
				/*ele_3.setAttribute('class','tabing-inactive');*/
			}else{
				ele_1.setAttribute('className', 'tabing-inactive');
				ele_2.setAttribute('className','tabing-active');
				/*ele_3.setAttribute('class','tabing-inactive');*/
			}
		} else {
			ele_1.setAttribute('class', 'tabing-inactive');
			ele_2.setAttribute('class','tabing-active');
			/*ele_3.setAttribute('class','tabing-inactive');*/
		}
	}

	if(tab=="scmt"){
		/*document.getElementById("freeList").style.display="none";
		document.getElementById("basicList").style.display="";*/
		document.getElementById("description-div").style.display="none";
		document.getElementById("reviews-div").style.display="none";
		/*document.getElementById("comment-div").style.display="";*/

		var ele_1 = document.getElementById("tab1");
		var ele_2 = document.getElementById("tab2");
		/*var ele_3 = document.getElementById("tab3");*/

		if (browserName=="Microsoft Internet Explorer") {
			if(version[2]>="8"){
				ele_1.setAttribute('class', 'tabing-inactive');
				ele_2.setAttribute('class','tabing-inactive');
				/*ele_3.setAttribute('class','tabing-active');*/
			}else{
				ele_1.setAttribute('className', 'tabing-inactive');
				ele_2.setAttribute('className','tabing-inactive');
				/*ele_3.setAttribute('class','tabing-active');*/
			}
		} else {
			ele_1.setAttribute('class', 'tabing-inactive');
			ele_2.setAttribute('class','tabing-inactive');
			/*ele_3.setAttribute('class','tabing-active');*/
		}
	}
}

function  onChangeCategory(cat_id) {
	//alert("hi" + form + name);
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	}//If the user is using IE
	else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var x = document.form1.product_type;
	var len = x.options.length;
	for (j = len - 1; j>=1; j--) {
		x.remove(j);
	}
	var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="1") ? 'controlpanel/' : '';
	var url = path+"ajaxtypenamelist.php?category_id="+cat_id;	
	//alert(url);
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(trim(answer)!="") {
				var text = answer.split("^^");
				var reccount = text[0];
				var record = text[1].split("$@$");
				for(i=0;i<reccount;i++) {
					var subcat = record[i].split("!$!");
					var j = i+1;
					document.form1.product_type.options[j] =  new Option(subcat[1],subcat[0]);
				}
				document.form1.product_type.options[0].selected =true;
			}
		}
	}
	xmlhttp.send(null);
	
}

function  onChangeCategory2(cat_id) {
	//alert("hi" + form + name);
	if (window.XMLHttpRequest) {
		xmlhttp1 = new XMLHttpRequest();
	}//If the user is using IE
	else if (window.ActiveXObject) {
		xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var x = document.form1.product_fueltype;
	var len = x.options.length;
	for (j = len - 1; j>=1; j--) {
		x.remove(j);
	}
	var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="1") ? 'controlpanel/' : '';
	var url = path+"ajaxfueltypenamelist.php?category_id="+cat_id;	
	//alert(url);
	xmlhttp1.open('GET', url, true);
	xmlhttp1.onreadystatechange = function() {
		if(xmlhttp1.readyState == 4 && xmlhttp1.status == 200) {
			var answer1 = xmlhttp1.responseText;
			if(trim(answer1)!="") {
				var text1 = answer1.split("^^");
				var reccount1 = text1[0];
				var record1 = text1[1].split("$@$");
				for(i=0;i<reccount1;i++) {
					var subcat1 = record1[i].split("!$!");
					var j = i+1;
					document.form1.product_fueltype.options[j] =  new Option(subcat1[1],subcat1[0]);
				}
				document.form1.product_fueltype.options[0].selected =true;
			}
		}
	}
	xmlhttp1.send(null);
}

function  onChangeProductType(type_id) {
	//alert("hi" + type_id);
	document.getElementById("subTypeLoader").style.display = "";
	if (window.XMLHttpRequest) {
		xmlhttp1 = new XMLHttpRequest();
	}//If the user is using IE
	else if (window.ActiveXObject) {
		xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var x = document.frmsearch.productSubType;
	var len = x.options.length;
	for (j = len - 1; j>=1; j--) {
		x.remove(j);
	}
	var path = (document.getElementById("frompublic") && document.getElementById("frompublic").value=="1") ? 'controlpanel/' : '';
	var url = path+"ajaxfueltypenamelist.php?typeId="+type_id;	
	//alert(url);
	xmlhttp1.open('GET', url, true);
	xmlhttp1.onreadystatechange = function() {
		if(xmlhttp1.readyState == 4 && xmlhttp1.status == 200) {
			var answer1 = xmlhttp1.responseText;
			if(trim(answer1)!="") {
				var text1 = answer1.split("^^");
				var reccount1 = text1[0];
				var record1 = text1[1].split("$@$");
				for(i=0;i<reccount1;i++) {
					var subcat1 = record1[i].split("!$!");
					var j = i+1;
					document.frmsearch.productSubType.options[j] =  new Option(subcat1[1],subcat1[0]);
				}
				document.getElementById("subTypeLoader").style.display = "none";
				document.frmsearch.productSubType.options[0].selected =true;
			}
		}
	}
	xmlhttp1.send(null);
}

function moveAOI(){
	var txtSelectedValuesObj = document.getElementById('distributor_area_interest');
 	var selectedArray = new Array();
  	var selObj = document.getElementById('sel_AOI');
  	var i;
  	var count = 0;
  	for (i=0; i<selObj.options.length; i++) {
		if (selObj.options[i].selected) {
		  selectedArray[count] = selObj.options[i].value;
		  count++;
		}
  	}
 	txtSelectedValuesObj.value = selectedArray;
}


function moveStates(){
	
	var txtSelectedValuesObj = document.getElementById('distributor_states');
 	var selectedArray = new Array();
  	var selObj = document.getElementById('sel_SC');
  	var i;
  	var count = 0;
  	for (i=0; i<selObj.options.length; i++) {
		if (selObj.options[i].selected) {
		  selectedArray[count] = selObj.options[i].value;
		  count++;
		}
  	}
 	txtSelectedValuesObj.value = selectedArray;
		
}

function moveCoverages(){
	var txtSelectedValuesObj = document.getElementById('distributor_coverage');
 	var selectedArray = new Array();
  	var selObj = document.getElementById('sel_DistCv');
  	var i;
  	var count = 0;
  	for (i=0; i<selObj.options.length; i++) {
		if (selObj.options[i].selected) {
		  selectedArray[count] = selObj.options[i].value;
		  count++;
		}
  	}
 	txtSelectedValuesObj.value = selectedArray;
}

function moveOwnerState(){
	var txtSelectedValuesObj = document.getElementById('owner_org_presence');
 	var selectedArray = new Array();
  	var selObj = document.getElementById('sel_ow_st');
  	var i;
  	var count = 0;
  	for (i=0; i<selObj.options.length; i++) {
		if (selObj.options[i].selected) {
		  selectedArray[count] = selObj.options[i].value;
		  count++;
		}
  	}
 	 txtSelectedValuesObj.value = selectedArray;
}

function checkSuggestProdId(){
	var frm = document.autoSuggestForm;
	//alert(frm);
	if(frm.hidd_sug_id.value!=""){
		var sug_id = frm.hidd_sug_id.value;
		//window.location.href = "productDetails.php?id="+sug_id;
		frm.submit();
	}else {
		return false;
	}
}
