// JavaScript Document
function resettoggle() {
	var e = document.getElementById('foo');
	e.style.display = 'none';
}

function toggle_visibility(id,total,ImgId) {
	for(i=1;i<=total;i++){
		var SubId= "Sub_"+i;
		var SubImgId = "SubImg_"+i;
		if(document.getElementById(SubId)){
			if(id != SubId){
				c = document.getElementById(SubId);
				c.style.display = 'none';
				document.getElementById(SubImgId).src = "images/business/plus.gif";;
			}
		}
	}
	var SubImgID = document.getElementById(ImgId);
	var e = document.getElementById(id);
	if(e.style.display == 'none'){
		SubImgID.src = "images/business/minus.gif";
		e.style.display = 'block';
	}else{
		SubImgID.src = "images/business/plus.gif";
		e.style.display = 'none';
	}
}
	function doRegistrationStep(intStep) {
		document.frmBusiness.hdRegisterStep.value = intStep;
		if(ValidateRegister(document.frmBusiness))
			document.frmBusiness.submit();
	}
	function ValidateRegister(objForm) {
		RegisterStep = objForm.hdRegisterStep.value;
		switch(RegisterStep)
		{
			case "1":
				objForm.action.value = "chooseplan";
				break;
			case "2":
				if(!validateStep2Process())
					return false;
				else{
					objForm.action.value = "detail";
				}
				break;
			case "3":
				if(!validateStep3Process())
					return false;
				else	{
					objForm.action.value = "logininfo";
				}
					
				break;
			case "4":
				if(!validateUserLoginProcess())
					return false;
				else	{
					objForm.action.value = "userlogin";
				}
				break;
		}
		return true;
	}
	function CheckSelection()
	{
		var checked1 = 0;
		if($('B_ListingPlan').value == 'premium' || $('B_ListingPlan').value == 'sponsored')
			for(i=0;i<document.frmBusiness.elements.length;i++)
				 if(document.frmBusiness.elements[i].name.indexOf("Business_PaymentMethods")>-1)
						if(document.frmBusiness.elements[i].checked == true)
								 var checked1 = 1;
			if( checked1 == 0 )
				return false;
		else
			return true;
	}

function UsernameValidation(e)
	{			
		var key = window.event ? e.keyCode : e.which;
		var keychar = String.fromCharCode(key);
		for(var i=32;i<62;i++){
			if(i == key){
				alert('Invalid User Name');
				return false;
			}
		}
				
	}
function PasswordValidation(e){
	
		var key = window.event ? e.keyCode : e.which;
		var keychar = String.fromCharCode(key);
		for(var i=32;i<46;i++){
			if(i == key){
				alert('password don\'t have special character ');
				return false;
			}
		}
	
}
	function validateStep3Process()		{
			var B_UserName  				= $('Business_UserName');
			var B_UserPassword 				= $('Business_UserPassword');
			var B_UserConfirmPassword		= $('Business_UserConfirmPassword');
			var Business_UserEmailAddress 	= $('Business_UserEmailAddress');
			if(trim(B_UserName.value) == '')	{
				alert('Enter Your Login User Name!');
				B_UserName.focus();
				return false;
			}else if(trim(B_UserName.value).length < 5)	{
				alert('UserName Should be atleast 5 digits!');
				B_UserName.focus();
				return false;
			}else if(trim(B_UserPassword.value) == '')	{
				alert('Enter Your Login Password!');
				B_UserPassword.focus();
				return false;
			}
			else if(trim(B_UserPassword.value).length < 5)	{
				alert('Password Should be atleast 5 digits!');
				B_UserPassword.focus();
				return false;
			}else if(trim(B_UserConfirmPassword.value) == '')	{
				alert('Enter Your Confirm Password!');
				B_UserConfirmPassword.focus();
				return false;
			}
			else if(trim(B_UserConfirmPassword.value) != B_UserPassword.value)	{
				alert('Both Passwords should be same!');
				B_UserConfirmPassword.select();
				return false;
			}else if(Business_UserEmailAddress.value == "")	{
				alert("Email Address Should not be empty")
				Business_UserEmailAddress.value='';
				Business_UserEmailAddress.focus();
				return false;
			}else if(!CheckExacltyAnEmail(Business_UserEmailAddress.value,1)){
				Business_UserEmailAddress.focus();
				return false;
			}
			return true;
	}
	
	function CheckEmail() {
		var str = escape($('Business_UserEmailAddress').value);
		var success = function(t){CheckEmailComplete(t);}
		var failure = function(t){loadfailed(t)}
		var url = 'myaccount.php';
		var pars = 'op=checkemail&email='+str;
		var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
	}
	
	function validateStep2Process()		{
			var B_CompanyName  	= $('Business_CompanyName');
			var B_CompanyPhone 	= $('Business_PhoneNumber');
			var B_SecondaryPhoneNumber = $('Business_SecondaryPhoneNumber')
			var B_FaxNumber		= $('Business_FaxNumber')
			var B_TollFreeNumber = $('Business_TollFreeNumber')
			var Business_CustomURL 	= $('Business_CustomWebSiteURL');
			var B_Address		= $('Business_Address');
			var B_City			= $('Business_City');
			var B_State			= $('Business_State');
			var B_ZipCode		= $('Business_ZipCode');
			var B_PaymentMethods = $('Business_PaymentMethods'); 
			var B_Faxnumber      = $('Business_FaxNumber');
			if(trim(B_CompanyName.value) == '')	
			{
				alert("Company Name Shouldn\'t be left Empty!");
				B_CompanyName.focus();
				return false;
			}
			else if(trim(B_CompanyPhone.value) == '')
			{
				alert('Phone Number Shouldn\'t be left Empty!');
				B_CompanyPhone.focus();
				return false;
			}
			if(trim(B_CompanyPhone.value)!=''){
				var e=trim(B_CompanyPhone.value);
				var ph1=e.replace(/\(/g,"");
				var ph2=ph1.replace(/\)/g,"");
				var ph=ph2.replace(/\-/g,"");
				if(isAlpha(ph)){		
				alert('Invalid Phone Number');
				B_CompanyPhone.focus();
				return false;
				}
			}
			if(trim(B_SecondaryPhoneNumber.value)!=''){
				var e1=trim(B_SecondaryPhoneNumber.value);
				var phs1=e1.replace(/\(/g,"");
				var phs2=phs1.replace(/\)/g,"");
				var phs=phs2.replace(/\-/g,"");
				if(isAlpha(phs)){
					alert('Invalid Phone Number');
					B_SecondaryPhoneNumber.focus();
					return false;
				}
			}
			if(trim(B_FaxNumber.value)!=''){
				var F=trim(B_FaxNumber.value);
				var f1=F.replace(/\(/g,"");
				var f2=f1.replace(/\)/g,"");
				var Fax=f2.replace(/\-/g,"");
				if(isAlpha(Fax)){
					alert('Invalid Fax Number');
					B_FaxNumber.focus();
					return false;
				}
			}
			if(trim(B_TollFreeNumber.value)!=''){
				var TF=trim(B_TollFreeNumber.value);
				var t1=TF.replace(/\(/g,"");
				var t2=t1.replace(/\)/g,"");
				var TollFree=t2.replace(/\-/g,"");
				if(isAlpha(TollFree)){
					alert('Invalid Number');
					B_TollFreeNumber.focus();
					return false;
				}
			}
			if(trim($('Business_Website').value) != "http://")
			{
				if(IsValidWebsiteURL($('Business_Website').value) == false)	{
					alert("Invalid Business Website.\n Give Like http://www.example.com");
					$('Business_Website').value = 'http://';
					$('Business_Website').focus();
					return false;
				}
			}
			if(trim(Business_CustomURL.value) == "")	{
				alert('Custom URL should not be empty!');
				Business_CustomURL.focus();
				return false;
			}
			if(isValidCutomUrl(trim(Business_CustomURL.value)) == false)	{
				alert('InValid Custom URL!');
				Business_CustomURL.focus();
				return false;
			}
			if(trim(B_Address.value)== '')
			{
				alert('Street Address Shouldn\'t be left Empty!');
				B_Address.focus();
				return false;
			}
			if(trim(B_City.value)=='')
			{
				
				alert('Business City Shouldn\'t be left Empty!');
				B_City.focus();
				return false;
			}
			if(!isAlpha(B_City.value))
			{
				alert('City Should be a Valid City Name!');
				B_City.focus();
				return false;
			}
			if(B_State.value == '')
			{
				alert('State  Shouldn\'t be left Empty!');
				B_State.focus();
				return false;
			} 
			if(trim(B_ZipCode.value) == '')
			{
				alert('Zipcode Shouldn\'t be left Empty!');
				B_ZipCode.focus();
				return false;
			} 
			if(trim(B_ZipCode.value)!='' ){
				var zpc=trim(B_ZipCode.value);
				if(isAlpha(zpc)){		
				alert('Invalid Zipcode Number');
				B_ZipCode.focus();
				return false;
				}
			}
			if(parseInt(trim(B_ZipCode.value)) == 0)	{
				alert('Please Give a Valid Zipcode!');
				B_ZipCode.focus();
				return false;
			}
			 if(!IsValidZipCode(B_ZipCode.value, 'ZipCode'))
			{
				B_ZipCode.focus();
				return false;
			}
			if(document.getElementById("ValidateMemberVerification").value == "Yes" && $('Business_Categories').value =='')	{
				alert('Please Select Some Categories Here!');
				return false;
			}
			return true;
	}
	

	function validateUserLoginProcess()		{
			var B_UserLoginName  	= $('Business_MemberName');
			var B_UserLoginPassword 	= $('Business_MemberPassword');
			if(trim(B_UserLoginName.value) == '')	{
				alert('Enter Your Login Name!');
				B_UserLoginName.focus();
				return false;
			}
			else if(trim(B_UserLoginPassword.value) == '')	{
				alert('Enter Your Login Password!');
				B_UserLoginPassword.focus();
				return false;
			}
			return true;
	}

	var PreviewValues = Array();
	PreviewValues["CompanyName"] = "Company Name";
	PreviewValues["PhoneNumber"] = "(XXX) XXX-XXXX";
	PreviewValues["WebsiteURL"] = "";
	PreviewValues["Location"] = "City, state - Zipcode";

	function setPreviewValue(strType,strValue) {
		strValue = trim(strValue);
		objForm	 = document.frmBusiness;
		if(document.getElementById("Preview_"+strType))
		{
			if(strValue != "" || strType == "Location")
			{
				switch(strType)
				{
					case "Location":
						strAddress 	= objForm.Business_Address.value;
						strCity		= objForm.Business_City.value;
						strState	= objForm.Business_State.value;
						strZipCode	= objForm.Business_ZipCode.value;
						strLocation = "";
						if(strAddress !="")
							strLocation = strAddress + "<br>";
						if(strCity != "")
						{
							strLocation = strLocation + strCity;
							if(strState != "")
								strLocation = strLocation + ", ";
						}
						if(strState != "")
						{
							strLocation = strLocation + strState;
							if(strZipCode != "")
								strLocation = strLocation + " - ";
						}
						if(strZipCode != "")
							strLocation = strLocation + strZipCode;
						if(strLocation != "")
							document.getElementById("Preview_"+strType).innerHTML = strLocation;	
						else
							document.getElementById("Preview_"+strType).innerHTML = PreviewValues[strType];
					break;
					case "WebsiteURL":
						if(strValue != 'http://')
							document.getElementById("Preview_"+strType).innerHTML = "<a href='' target='_blank'>" + strValue + "</a>";
						else
							document.getElementById("Preview_"+strType).innerHTML ="";
					break;
					default:
						document.getElementById("Preview_"+strType).innerHTML = strValue;
					break;
				}
			}
			else
			{
				if(strType != "Location")
					document.getElementById("Preview_"+strType).innerHTML = PreviewValues[strType];
			}
		}
		
	}

	function showLayer(LayerType) {
		if(document.getElementById(LayerType))
		{
			if(document.getElementById(LayerType).style.display == "none" )	{
				document.getElementById(LayerType).style.display = "block";
				
			}
			else
			{
				document.getElementById(LayerType).style.display = "none";
			}
				
		}
		
	}

	function changeClass(Id) {
		if(document.getElementById(Id))
		{
			if(document.getElementById(Id).className == "showAdd")	{
				document.getElementById(Id).className = "showDel";
			}
			else
			{
				document.getElementById(Id).className='showAdd';
			}
				
		}
	}
	/***********************functions to select categories in the registration page - start ********************************************/
	function getCategories() {
		var str = escape($('txtCategory').value);
		var success = function(t){getCategoriesComplete(t);}
		var failure = function(t){loadfailed(t)}
		var url = 'ajax/category.php';
		var pars = 'op=search&search=' + str;
		var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
	}
	function loadfailed(t)	{
	}
	function getCategoriesComplete(t){
		$("categorySuggestItems").style.display = "block";
		$("categorySuggestItems").innerHTML =t.responseText; 
	}
	
	//Mouse over function
	function suggestOver(div_value) {
		div_value.className = 'suggest_link_over';
	}
	//Mouse out function
	function suggestOut(div_value) {
		div_value.className = 'suggest_link';
	}
	

/**************functions to select categories in the registration page - end**************************/

	function DoContactValidation()	{
			var B_ContactName	= $('BusinessContactName');
			var B_ContactEmail	= $('BusinessContactEmail');
			var B_ContactMsg	= $('BusinessContactMsg');
	
			if(trim(B_ContactName.value) == '')	
			{
				alert("Name Field Shouldn't be left Empty!");
				B_ContactName.focus();
				return false;
			}
			else if(trim(B_ContactEmail.value) == '')
			{
				alert('Email Address Shouldn\'t be left Empty!');
				B_ContactEmail.focus();
				return false;
			}
			else if(isEmail(B_ContactEmail.value) == false)
			{
				//alert('Please Enter A Valid Email Address!');
				B_ContactEmail.select();
				return false;
			}
			else if(trim(B_ContactMsg.value)=='')
			{
				alert('Message Field Shouldn\'t be left Empty!');
				B_ContactMsg.focus();
				return false;
			}
			$('fAction').value	= 'contact';
			//document.BusinessContact.submit();
			return true;
	}
	function ShareBusinessValidate() {
			if(trim(document.ShareBusiness.YourName.value) == ""){
				alert("Your Name Should Not Be Empty");
				document.ShareBusiness.YourName.value='';
				document.ShareBusiness.YourName.focus();
				return false;
			}
			if(!isValidCutomUrl(trim(document.ShareBusiness.YourName.value)))	{
				alert("Please Enter A Valid Name");
				document.ShareBusiness.YourName.focus();
				return false;
			}
			if(trim(document.ShareBusiness.FriendsAddress.value) == ""){
				alert("Email Address Should Not Be Empty. \nPlease Give atleast one Email.");
				document.ShareBusiness.FriendsAddress.value='';
				document.ShareBusiness.FriendsAddress.focus();
				return false;
			}
			if(!multiEmail(trim(document.ShareBusiness.FriendsAddress.value)))	{
				document.ShareBusiness.FriendsAddress.focus();
				return false;
			}
			if(trim(document.ShareBusiness.Message.value) == ""){
				alert("Message Should Not Be Empty");
				document.ShareBusiness.Message.value='';
				document.ShareBusiness.Message.focus();
				return false;
			}
			$('fAction').value	= 'share';
			document.ShareBusiness.submit();
	}
	function multiEmail(email_field) {
		var email = email_field.split(',');
		for (var i = 0; i < email.length; i++) {
			if (!validateEmail(email[i], 1, 0)) { // use last argument as 1 if need exactly what user has mistaken with email
				alert('One or More Email Addresses Entered is Invalid');
				return false;
			}
		}
		return true;
	}

	function validateEmail(addr,man,db) {
		if (addr == '' && man) {
		   if (db) alert('email address is mandatory');
		   return false;
		}
		if (addr == '') return true;
		var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
		for (i=0; i<invalidChars.length; i++) {
		   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
			  if (db) alert('email address contains invalid characters');
			  return false;
		   }
		}
		for (i=0; i<addr.length; i++) {
		   if (addr.charCodeAt(i)>127) {
			  if (db) alert("email address contains non ascii characters.");
			  return false;
		   }
		}
		var atPos = addr.indexOf('@',0);
		if (atPos == -1) {
		   if (db) alert('email address must contain an @');
		   return false;
		}
		if (atPos == 0) {
		   if (db) alert('email address must not start with @');
		   return false;
		}
		if (addr.indexOf('@', atPos + 1) > - 1) {
		   if (db) alert('email address must contain only one @');
		   return false;
		}
		if (addr.indexOf('.', atPos) == -1) {
		   if (db) alert('email address must contain a period in the domain name');
		   return false;
		}
		if (addr.indexOf('@.',0) != -1) {
		   if (db) alert('period must not immediately follow @ in email address');
		   return false;
		}
		if (addr.indexOf('.@',0) != -1){
		   if (db) alert('period must not immediately precede @ in email address');
		   return false;
		}
		if (addr.indexOf('..',0) != -1) {
		   if (db) alert('two periods must not be adjacent in email address');
		   return false;
		}
		var suffix = addr.substring(addr.lastIndexOf('.')+1);
		if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
		   if (db) alert('invalid primary domain in email address');
		   return false;
		}
		return true;
	}	
	
	function DoSearchValidation(){			
			if(trim($('SearchText').value)=="" || $('SearchText').value == 'Keywords'){
			
					alert("Enter A Keyword!");
					$('SearchText').focus();
					return false;
			}						
			document.SearchKeyForm.submit();
	}

	function ForwardListing(){
		  var sel=0;
		  var a=1;
		  for (i=0; i<document.frmListing.elements.length; i++)
			{
			  if(document.frmListing.elements[i].type=="checkbox"){
					if(document.frmListing.elements[i].checked){
						sel =1;
					}
			  }
			}
		if(sel=="0"){
			alert("Please Select atleast one problem");
			return false;
		}
		else if(trim($('Listing_AdditionalComments').value) == '')
		{
			alert('Additional Comments Shouldn\'t be left Empty!');
			$('Listing_AdditionalComments').focus();
			return false;
		}
		else if(trim($('Listing_MemberEmail').value) == '')
		{
			alert('Email Address Shouldn\'t be left Empty!');
			$('Listing_MemberEmail').focus();
			return false;
		}
		else if(isEmail($('Listing_MemberEmail').value) == false)
		{
			$('Listing_MemberEmail').select();
			return false;
		}
		$('fAction').value = 'reportabuse';
		document.frmListing.submit();
	}
	function getStarValidation(strTitle) { 
		for(i=1;i<=5;i++)
			if(document.getElementById("Rating_"+strTitle+"_"+i).checked)
				return true;
		return false;	
	}
	function DoRatingValidation(DefaultListing)	{
		if(DefaultListing != "0"){
			/* $("Rating['Price']").value				= strRating["Price"];
			$("Rating['Professionalism']").value	= strRating["Professionalism"];
			$("Rating['Courtesy']").value			= strRating["Courtesy"];
			$("Rating['Quality']").value			= strRating["Quality"];
			$("Rating['Service']").value			= strRating["Service"];
			$("TotalRate").value					= strRating["Overall"];
			if($("Rating['Price']").value == '0')	
			{
				alert("Please vote for the Price");
				return false;
			}
			if($("Rating['Professionalism']").value == '0')	
			{
				alert("Please vote for the Professionalism");
				return false;
			}
			if($("Rating['Courtesy']").value == '0')	
			{
				alert("Please vote for the Courtesy");
				return false;
			}if($("Rating['Quality']").value == '0')	
			{
				alert("Please vote for the Quality");
				return false;
			}if($("Rating['Service']").value =='0')	
			{
				alert("Please vote for the Service");
				return false;
			} */
			if(getStarValidation('Price') == false)
			{
				alert("Please vote for the Price");
				return false;
			}
			if(getStarValidation('Professionalism') == false)	
			{
				alert("Please vote for the Professionalism");
				return false;
			}
			if(getStarValidation('Courtesy') == false)	
			{
				alert("Please vote for the Courtesy");
				return false;
			}if(getStarValidation('Quality') == false)	
			{
				alert("Please vote for the Quality");
				return false;
			}if(getStarValidation('Service') == false)	
			{
				alert("Please vote for the Service");
				return false;
			}
		}
		if($('ReviewTitle').value == '')	
		{
			alert("Review Title Shouldn't be left Empty!");
			$('ReviewTitle').focus();
			return false;
		}
		else if($('ReviewContent').value == '')
		{
			alert('Review Content Shouldn\'t be left Empty!');
			$('ReviewContent').focus();
			return false;
		}
		$('fAction').value	= 'rating';
		document.BusinessReview.submit();
	}

	strRating = new Array();
	strRating["Price"] 			 	= 0;
	strRating["Professionalism"] 	= 0;
	strRating["Courtesy"] 			= 0;
	strRating["Quality"] 			= 0;
	strRating["Service"] 			= 0;
	strRating["Overall"] 			= 0;
	function setMouseOverRating(intStar,strTitle) {
		for(i=1;i<=5;i++)
			document.getElementById("RatingStar_"+strTitle+"_"+i).src = strImagePath+"greystar.gif";
		for(i=1;i<=intStar;i++)
			document.getElementById("RatingStar_"+strTitle+"_"+i).src = strImagePath+"yellowstar.gif";
	}
	function ResetRating(strTitle) {
		intRatingStars = strRating[strTitle];
		setMouseOverRating(intRatingStars,strTitle);
	}
	function SetRating(intStar,strTitle) {
		strRating[strTitle] = intStar;
		document.getElementById("Rating_"+strTitle+"_"+intStar).checked = true;
		document.getElementById(strTitle+"Count").innerHTML = intStar;
		UpdateRating();
	}
	function UpdateRating() {
		intTotalRating 	= strRating["Price"]  + strRating["Professionalism"] + strRating["Courtesy"] + strRating["Quality"] + strRating["Service"];
		intOverallRating = intTotalRating/5;
		document.getElementById("TotalRating").innerHTML = "OverAll Rating: <span style='color:#00CC33;font-weight:bold;font-size:24px;line-height:38px;'>"+intOverallRating+"</span>";
		setOverallRating(intOverallRating);
	}
	function setOverallRating(intRate) {
		strRating["Overall"] = intRate;
		for(i=1;i<=5;i++)
		//	document.getElementById("Overall"+i).src = strImagePath+"greystar.gif";
	//	for(i=1;i<=Math.floor(intRate);i++)
		//	document.getElementById("Overall"+i).src = strImagePath+"full.gif";
		intBalance = intRate - Math.floor(intRate);
		if(intBalance > 0)
		{
			//document.getElementById("Overall"+i).src = strImagePath+"half.gif";
		}
	}
	function doClearRatingValues()	{
		$("Rating['Service']").value = 0;
		$("Rating['Professionalism']").value = 0;
		$("Rating['Price']").value = 0;
		$("Rating['Courtesy']").value = 0;
		$("Rating['Quality']").value = 0;
		$("TotalRate").value = 0;
		for(var i=1;i <= 5; i++)	{
			for(var k=1;k<=5;k++)	{
			var imgname	= "Start"+i+k;
			document.getElementById(imgname).src	= strImagePath+"greystar.gif";
			}
		}
		$('TotalRates').innerHTML	= "";
	}
	
	function doSuggestCompany()	{
		var B_CompanyName  	= $('Business_CompanyName');
		var B_CompanyPhone 	= $('Business_PhoneNumber');
		var B_Address		= $('Business_Address');
		var B_City			= $('Business_City');
		var B_State			= $('Business_State');
		var B_ZipCode		= $('Business_ZipCode');
		var B_PaymentMethods = $('Business_PaymentMethods'); 
		if(trim(B_CompanyName.value) == '')	
		{
			alert("Company Name Shouldn't be left Empty!");
			B_CompanyName.focus();
		}
		else if(trim(B_CompanyPhone.value) == '')
		{
			alert('Phone Number Shouldn\'t be left Empty!');
			B_CompanyPhone.focus();
		}
		else if(trim($('Business_Website').value) != "http://" && !IsValidWebsiteURL($('Business_Website').value))
		{
			alert("Invalid Business Website.\n Give Like http://www.example.com");
			$('Business_Website').value = 'http://';
			document.getElementById("Preview_WebsiteURL").innerHTML  = ''
			$('Business_Website').focus();
		}
		else if(trim(B_Address.value) == '')
		{
			alert('Street Address Shouldn\'t be left Empty!');
			B_Address.focus();
		}
		else if(trim(B_City.value)=='')
		{
			alert('Business City Shouldn\'t be left Empty!');
			B_City.focus();
		}
		else if(!isAlpha(B_City.value))
		{
			alert('City Should be a Valid City Name!');
			B_City.focus();
		}
		else if(B_State.value == '')
		{
			alert('State  Shouldn\'t be left Empty!');
			B_State.focus();
		} 
		else if(trim(B_ZipCode.value) == '')
		{
			alert('Zipcode Shouldn\'t be left Empty!');
			B_ZipCode.focus();
		} 
		else if(!CheckValidZipcode(B_ZipCode.value))
		{
			alert('Please Give a Valid Zipcode!');
			B_ZipCode.focus();
		}
		else	{
			document.frmBusiness.action.value	= 'submit';
			document.frmBusiness.submit();
		}
	}
	
	function doCompanyRegister() {
		var B_UserName  				= $('Business_UserName');
		var B_UserPassword 				= $('Business_UserPassword');
		var B_UserConfirmPassword		= $('Business_UserConfirmPassword');
		var Business_UserEmailAddress 	= $('Business_UserEmailAddress');
		var Business_UserZip 			= $('Business_UserZip');
		if(trim(B_UserName.value) == '')	{
			alert('Enter Your Login User Name!');
			B_UserName.focus();
		}
		else if(trim(B_UserPassword.value) == '')	{
			alert('Enter Your Login Password!');
			B_UserPassword.focus();
		}
		else if(trim(B_UserConfirmPassword.value) == '')	{
			alert('Enter Your Confirm Password!');
			B_UserConfirmPassword.focus();
		}
		else if(B_UserConfirmPassword.value != B_UserPassword.value)	{
			alert('Both Passwords should be same!');
			B_UserConfirmPassword.select();
		}else if(!isEmail(Business_UserEmailAddress.value))	{
			Business_UserEmailAddress.select();
		}else if(Business_UserZip.value == "")	{
			alert('Zip code should not be empty!');
			Business_UserZip.select();
		}	else	{
			document.frmBusiness.action.value	= 'register';
			document.frmBusiness.submit();
		}
	}
	
	function doCompanyLogin()		{
		if(validateUserLoginProcess())	{
			document.frmBusiness.action.value	= 'login';
			document.frmBusiness.submit();
		}
	}

	//****************************** Add Categories ***************************************/
	function ShowSubCategoryAdd(CategoryId,Subspanid,MasterSpanid,SpanCount){
		if(SpanCount!="")	{
				for(i=0;i<SpanCount;i++)
				{
				Val = MasterSpanid+i;
					if(Subspanid == Val) {
					var success = function(t){loadSubCategoryAddAsXMLComplete(t,Subspanid,MasterSpanid);}
					var failure = function(t){loadFailed(t);}
					var url 	= "ajax/business.php";
					var B_Subcategories	= $('UserSelected_Categories').value;
					var categorystored = B_Subcategories;
					var pars 	= "op=SubCategoryAdd&CategoryId="+CategoryId+"&Subspanid="+Subspanid+"&b_cats="+categorystored;
					var myAjax 	= new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
					} else {
					document.getElementById(Val).innerHTML = "";
					}
				}
			}
			else {
				var success = function(t){loadSubCategoryAddAsXMLComplete(t,Subspanid,MasterSpanid);}
				var failure = function(t){loadFailed(t);}
				var url 	= "ajax/business.php";
				var B_Subcategories	= $('UserSelected_Categories').value;
				var categorystored = B_Subcategories;
				var pars 	= "op=SubCategoryAdd&CategoryId="+CategoryId+"&Subspanid="+Subspanid+"&b_cats="+categorystored;
				var myAjax 	= new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
			}
	}
	
	function loadSubCategoryAddAsXMLComplete(t,Subspanid,MasterSpanid){
		objXML 					= t.responseXML;
		var strContent			= "<table><tr><td class='DirectoryMainCategorySmall' style=padding-left:15px>";
		var objElements 		= objXML.getElementsByTagName("SubName");
		if(objElements.length!="") {
			for (var iNode=0;iNode<objElements.length;iNode++)
			{
				thisNode 		 = objElements.item(iNode);
				var InterestList = thisNode.getAttribute("CatName").toString();
				var CategoryName   = thisNode.getAttribute("CatName").toString();
				CategoryName       = CategoryName.replace(/ /g,"_");
				CategoryName       = CategoryName.replace(/&/g,"AMP");
				strContent 		 = strContent + "<div>";
				if(thisNode.getAttribute("CheckedStatus").toString()=="Checked")
					strContent = strContent + "<div style='padding:1px;'><img src='"+SiteGlobalPath+"images/members/checked.gif' onclick=AddToList(this,'"+CategoryName+"','"+thisNode.getAttribute("CatIdent").toString()+"',this.form); name='"+thisNode.getAttribute("CatIdent").toString()+"'  id='"+thisNode.getAttribute("CatIdent").toString()+"' align='absmiddle' value='"+thisNode.getAttribute("CatIdent").toString()+"' style='cursor:pointer' />";
				else
					strContent = strContent + "<div style='padding:1px;'><img src='"+SiteGlobalPath+"images/members/notchecked.gif' onclick=AddToList(this,'"+CategoryName+"','"+thisNode.getAttribute("CatIdent").toString()+"',this.form); name='"+thisNode.getAttribute("CatIdent").toString()+"' id='"+thisNode.getAttribute("CatIdent").toString()+"' align='absmiddle' value='"+thisNode.getAttribute("CatIdent").toString()+"' style='cursor:pointer' />";
				strContent 		 = strContent+"<a onClick=ShowSubCategoryAdd("+thisNode.getAttribute("CatIdent").toString()+",'"+Subspanid+iNode+"','"+Subspanid+"',"+objElements.length+") class='DirectoryMainCategorySmall' style=cursor:pointer> ";
				strContent 		 = strContent+InterestList+"</a></div> <span id='"+Subspanid+iNode+"'></span>";
			} 
			strContent =strContent+"</td></tr></table>"; 
			if(document.getElementById(Subspanid).innerHTML)
				document.getElementById(Subspanid).innerHTML = "";
			else
				document.getElementById(Subspanid).innerHTML = strContent;
		}
	}
	var flag = new Array();
	function ShowCategoryAdd(CategoryId,spanid,SubSpainid){
		var success = function(t){loadCategoryAddAsXMLComplete(t,CategoryId,SubSpainid,spanid);}
		var failure = function(t){loadFailed(t);}
		var url 	= "ajax/business.php";
		var B_categories	= $('UserSelected_Categories').value;
		var categorystored = B_categories;
		var pars 	= "op=ShowCategoryAdd&b_cats="+categorystored;
		var myAjax 	= new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
	}
	function loadCategoryAddAsXMLComplete(t,CategoryId,SubSpainid,spanid){
		objXML 					= t.responseXML;
		var strContent			= "<table width='350' border='0' align='center' cellpadding='0' cellspacing='0'>";
		var objCatElements 		=  objXML.getElementsByTagName("MainCat");
		if(objCatElements.length!="") {
			for (var jNode=0;jNode<objCatElements.length;jNode++)
			{	
				thisCatNode 	 = objCatElements.item(jNode); 
				var CategoryList = thisCatNode.getAttribute("CatName").toString();
				var MainName     = thisCatNode.getAttribute("CatName").toString();
				MainName         = MainName.replace(/ /g,"_");
				MainName         = MainName.replace(/&/g,"AMP");
				strContent		 = strContent+"<tr><td>";
				//alert(thisCatNode.getAttribute("CatLevel").toString());
				if(thisCatNode.getAttribute("CatLevel").toString() == 1)
					strContent	 = strContent+"<div style='padding-left:5px;'><img src='"+SiteGlobalPath+"images/members/folder.gif'  id='"+thisCatNode.getAttribute("CatIdent").toString()+"' onClick=ShowCategoryAdd("+thisCatNode.getAttribute("CatIdent").toString()+",'CategoryspanId','SubCategory"+jNode+"') align='absmiddle' value='"+thisCatNode.getAttribute("CatIdent").toString()+"'  name='"+thisCatNode.getAttribute("CatIdent").toString()+"' style='cursor:pointer'  /> ";
				else if(thisCatNode.getAttribute("CheckedStatus").toString()=="Checked")
					strContent	 = strContent+"<div style='padding-left:5px;'><img src='"+SiteGlobalPath+"images/members/checked.gif' onclick=AddToList(this,'"+MainName+"','"+thisCatNode.getAttribute("CatIdent").toString()+"',this.form); id='"+thisCatNode.getAttribute("CatIdent").toString()+"' align='absmiddle' value='"+thisCatNode.getAttribute("CatIdent").toString()+"'  name='"+thisCatNode.getAttribute("CatIdent").toString()+"' style='cursor:pointer'  /> ";
				else
					strContent	 = strContent+"<div style='padding-left:5px;'><img src='"+SiteGlobalPath+"images/members/notchecked.gif' onclick=AddToList(this,'"+MainName+"','"+thisCatNode.getAttribute("CatIdent").toString()+"',this.form); id='"+thisCatNode.getAttribute("CatIdent").toString()+"' align='absmiddle' value='"+thisCatNode.getAttribute("CatIdent").toString()+"'  name='"+thisCatNode.getAttribute("CatIdent").toString()+"' style='cursor:pointer'/> ";
				strContent		 = strContent+"<a onClick=ShowCategoryAdd("+thisCatNode.getAttribute("CatIdent").toString()+",'CategoryspanId','SubCategory"+jNode+"') class='DirectoryMainCategory'  style=cursor:pointer;'>";
				strContent 		 = strContent+CategoryList+"</a></div><span id='SubCategory"+jNode+"'>";
				strContent       = strContent+"</span></td></tr>";
			} 
			strContent =strContent+"</table>";
			document.getElementById(spanid).innerHTML = strContent;
		}
		if(CategoryId!= "" && document.getElementById(SubSpainid).innerHTML =="") {
			if(flag[CategoryId] == 1){
				flag[CategoryId] =0;
			}else {
				ShowSubCategoryAdd(CategoryId,SubSpainid,'','');
				flag[CategoryId] =1;
			} 
		} 
	} 

	function CheckOnClickedOrNot(ChkId,SelectedId)	{
		var ChkID=ChkId.id;
		if (ChkId.title == "Label")	
			chkSrc="";
		else	
			chkSrc=ChkId.src;
		if (chkSrc.length > 0)
			chkSrc=chkSrc.substring(parseInt(chkSrc.lastIndexOf("/"))+parseInt(1),chkSrc.length);
		var cats = new Array();
		if($('UserSelected_Categories').value != '')
			cats = $('UserSelected_Categories').value.split(',');
		if (chkSrc=="checked.gif")	{
			document.getElementById(ChkID).src = SiteGlobalPath+"images/members/notchecked.gif";
			removeItems(cats, SelectedId);
		}	
		else {
			document.getElementById(ChkID).src = SiteGlobalPath+"images/members/checked.gif";
			cats.push(SelectedId);
		}
		cats = array_unique(cats);
		$('UserSelected_Categories').value = cats.join(',');
	}
	
	function array_unique(ar){
		var sorter = {};
		for(var i=0,j=ar.length;i<j;i++){
			sorter[ar[i]] = ar[i];
		}
		ar = [];
		for(var i in sorter){
			ar.push(i);
		}
		return ar;
	}
	
	function setDelete(Div_Val,categoryId) {
		var delPop = new Array();
		var nclass = document.getElementById(Div_Val).className;
		var hastopushorpop =Div_Val.replace('cb_', '');
		var newCatList = $('Business_Categories').value.split(',');
		if(nclass == 'link')	{
				removeItems(newCatList, hastopushorpop);
				document.getElementById(Div_Val).className = 'unlink';
				if(document.getElementById(categoryId))
					document.getElementById(categoryId).src=SiteGlobalPath+"images/members/notchecked.gif";
		}
		else if(nclass == 'unlink')	{
			newCatList.push(hastopushorpop);
			document.getElementById(Div_Val).className = 'link';
			if(document.getElementById(categoryId))	{
				document.getElementById(categoryId).src=SiteGlobalPath+"images/members/checked.gif";
			}
		}
		$('Business_Categories').value = newCatList.join(',');
		$('UserSelected_Categories').value =  newCatList.join(',');
	}
	
	var CatArray = new Array();
	function saveDataSelected(SelectedId, value){
		var CatValue='';
		var mclass;
		CatArray[SelectedId] = value;
		var cats = new Array();
		if($('Business_Categories').value != '')
			cats = $('Business_Categories').value.split(',');
		for (var key in CatArray){
			if(!isNaN(key) && key != '')	{
				if($("cb_"+key))
				{
					var catid = $("cb_"+key).id;
					var hastopushOrpop =catid.replace('cb_', '');
					mclass = $("cb_"+key).className;
					if(mclass == 'unlink')	{
						removeItems(cats, hastopushOrpop);
						mclass = 'unlink';
					}
				}
				else
				{
					cats.push(key); 
					mclass = 'link';
				}
				var MainName = CatArray[key];
				MainName         = MainName.replace(/_/g," ");
				MainName         = MainName.replace(/AMP/g,"&");
				CatValue =  CatValue+'<div style="float:left;cursor:pointer;font-size:10px;" id=cb_'+key+' onclick="javascript:setDelete(this.id,'+key+');" class='+mclass+'>'+MainName+'</div>&nbsp;&nbsp;<a href="index.php?op=directory.list&c='+key+'" target="blank"><img src="images/business/detailpage/link.gif" border="0" /></a><br>';
			}
		}
		$('Business_Categories').value = cats.join(',');
		$('UserSelected_Categories').value = cats.join(',');
		if(CatValue != '')	{
			$("catList").style.display = 'block';
			$("catList").innerHTML = CatValue;
		}
	}
	
	// funtion to pop the specific element in the array
	function removeItems(array, item) {
		var i = 0;
		while (i < array.length) {
			if (array[i] == item) {
				array.splice(i, 1);
			} else {
				i++;
			}
		}
		return array;
	}
	var AddToList = function(ChkId,CategoryName,CategoryId,objForm)
	{
		CheckOnClickedOrNot(ChkId, CategoryId);
		Chkbox = document.getElementById(CategoryId);
		 var str = Chkbox.src;
		 myString = str.split("/");
		 var strVal = myString.length-1;
		 var cats = new Array();
		if($('Business_Categories').value != '')
			cats = $('Business_Categories').value.split(',');
		 if(myString[strVal] == "checked.gif") {
			 var Div_Id = "cb_"+CategoryId;
			saveDataSelected(CategoryId, CategoryName);
			cats.push(CategoryId); 
			nclass = document.getElementById(Div_Id).className;
			 if(nclass == 'unlink')
				document.getElementById(Div_Id).className = 'link';
		}
		if(myString[strVal] == "notchecked.gif")
		{
			removeItems(cats, CategoryId);
			var Div_Id = "cb_"+CategoryId;
			setDelete(Div_Id, CategoryId);
		}
		$('Business_Categories').value = cats.join(',');
		$('UserSelected_Categories').value = cats.join(',');
	}
	//************************************add categories end ***********************//
	function isValidCutomUrl(url)	{
		// regular expression for cannot start with a number and cannot have only numbers. Its maximum length is 50
		// apart from, it can only include the symbols Underscore, Hyphen and spaces between words
		// var inValidChars = "/^[A-Za-z][-A-Za-z0-9_ ]{0,49}$/"; for case insensitive
		var reg = new RegExp(/^[A-Za-z][-A-Za-z0-9_]{0,49}$/i);
		if(reg.test(url))
			return true;
		else
			return false;
	}
	function IsValidWebsiteURL(Val){
		var reg = new RegExp(/^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.){1}[0-9A-Za-z\.\-]*\.[0-9A-Za-z\.\-]{0,3}$/);
		if(reg.test(Val))
			return true;
		else
			return false;
	}
	var mainCats = new Array();
	function getSavedCategories()	{
		if(document.frmBusiness.Showvarification.value == "Yes")	{
			mainCats = $('VerifiedCats').value.split(',');
		}
		else	{
			mainCats = $('UserSelected_Categories').value.split(',');
		}
		if(mainCats.length > 0)	{
			for(var i=0; i<mainCats.length; i++)	{
				var CategoryId = mainCats[i];
				var success = function(t){getCategoryNameComplete(t,CategoryId);}
				var failure = function(t){loadgetCategoryNamefailed(t)}
				var url = 'ajax/business.php';
				var pars = 'op=getcat&catid='+CategoryId;
				var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
			}
		}
		else{}
	}
	function loadgetCategoryNamefailed(t)	{
		alert('Failed on Categories Already Selected.\n Check Your Browser Supports for Ajax?');
	}
	var MainCatNames = new Array();
	function getCategoryNameComplete(t,CategoryId){
		var CategoryName = t.responseText;
		CategoryName = CategoryName.replace(/ /g,"_");
		CategoryName = CategoryName.replace(/&/g,"AMP");
		MainCatNames.push(CategoryName);
		for(var i=0; i<MainCatNames.length; i++)	{
			saveDataSelected(mainCats[i],MainCatNames[i]);
		}
	}
	var ExistinsUserCats = new Array();
	function getExistingUserCategories()	{
		if(document.frmBusiness.Showvarification.value == "Yes")
			ExistinsUserCats = $('VerifiedCats').value.split(',');
		
		if(ExistinsUserCats.length > 0)	{
			for(var i=0; i<ExistinsUserCats.length; i++)	{
				var CategoryId = ExistinsUserCats[i];
				var success = function(t){getExistingUserCategoriesComplete(t,CategoryId);}
				var failure = function(t){loadgetCategoryNamefailed(t)}
				var url = 'ajax/business.php';
				var pars = 'op=getcat&catid='+CategoryId;
				var myAjax = new Ajax.Request(url, {method:'post',postBody:pars, onSuccess:success, onFailure:failure});
			}
		}
		else{}
	}
	
	var ExistingCatNames = new Array();
	function getExistingUserCategoriesComplete(t,CategoryId){
		var CategoryName = t.responseText;
		CategoryName = CategoryName.replace(/ /g,"_");
		CategoryName = CategoryName.replace(/&/g,"AMP");
		ExistingCatNames.push(CategoryName);
		for(var i=0; i<ExistingCatNames.length; i++)	{
			showExistingCatsSelected(ExistinsUserCats[i],ExistingCatNames[i]);
		}
	}
	var ExistingCatsArray = new Array();
	function showExistingCatsSelected(SelectedId, value){
		
		var CatValue='';
		ExistingCatsArray[SelectedId] = value;
		for (var key in ExistingCatsArray){
			if(!isNaN(key) && key != '')	{
				var MainName = ExistingCatsArray[key];
				MainName         = MainName.replace(/_/g," ");
				MainName         = MainName.replace(/AMP/g,"&");
				CatValue =  CatValue+'<div style="float:left;font-size:10px; color:#4263FD;">'+MainName+'</div>&nbsp;&nbsp;<a href="index.php?op=directory.list&c='+key+'" target="blank"><img src="images/business/detailpage/link.gif" border="0" /></a><br>';
			}
		}
		if(CatValue != '')	{
			$("catList").style.display = 'block';
			$("catList").innerHTML = CatValue;
		}
		else if(CatValue == '')	{
			$("catList").style.display = 'block';
			$("catList").innerHTML = '<div style="float:left;font-size:10px; color:#4263FD;">No Categories Found</div><br>';	
		}
	}	

	function ReportReviewsValidation(){
		  var sel=0;
		  var a=1;
		  for (i=0; i<document.frmListing.elements.length; i++)
			{
			  if(document.frmListing.elements[i].type=="checkbox"){
					if(document.frmListing.elements[i].checked){
						sel =1;
					}
			  }
			}
		if(trim($('ConsumerName').value) == '')
		{
			alert('Please enter your name!');
			$('ConsumerName').focus();
			return false;
		}
		else if(trim($('UserEmail').value) == '')
		{
			alert('Email Address Shouldn\'t be left Empty!');
			$('UserEmail').focus();
			return false;
		}
		else if(isEmail($('UserEmail').value) == false)
		{
			$('UserEmail').select();
			return false;
		}
		else if(sel=="0"){
			alert("Please Select atleast one problem");
			return false;
		}
		else if(trim($('AdditionalComments').value) == '')
		{
			alert('Additional Comments Shouldn\'t be left Empty!');
			$('Listing_AdditionalComments').focus();
			return false;
		}
		$('fAction').value = 'reviewscomplaint';
		document.frmListing.submit();
	}