	function checkEmail(emailaddress)
	{
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(emailaddress.value))
		{
			return (true);
		}
		alert("Please enter your valid email address");
		return (false);
	}

	function trim(inputString) 
	{
		if (typeof inputString != "string") { return inputString; }
		var retValue = inputString;
		var ch = retValue.substring(0, 1);

		while (ch == " ") 
		{ 
			retValue = retValue.substring(1, retValue.length);
			ch = retValue.substring(0, 1);
		}
		ch = retValue.substring(retValue.length-1, retValue.length);
		
		while (ch == " ") 
		{
			retValue = retValue.substring(0, retValue.length-1);
			ch = retValue.substring(retValue.length-1, retValue.length);
		}
		
		while (retValue.indexOf("  ") != -1) 
		{ 
			retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
		}
		return retValue; 
	} 


/*	Validation for add/edit good business	*/

	function checkBusiness(mf)
	{
		var tomatch= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
		if(mf.lname.value=="")
		{
			alert("Please enter the last name/surname.");
			mf.lname.focus();
			return false;
		}		
		if(mf.fname.value=="")
		{
			alert("Please enter the first name.");
			mf.fname.focus();
			return false;
		}
		if(trim(mf.email.value)=="")
		{ 
			alert("Please enter email address");
			mf.email.focus();
			return false;
		}
		if(checkEmail(mf.email)==false)
		{
			mf.email.focus();
			return false; 
		}
		if(mf.phone.value=="")
		{
			alert("Please enter the contact phone number.");
			mf.phone.focus();
			return false;
		}
		var valid= "+-()1234567890 ";
		if (mf.phone.value !="")
		{
			var string = mf.phone.value;
			var length = string.length;
			for(var i=0;i<=length;i++)
			{
				var substring = string.substr(i,1);
				if(valid.indexOf(substring)== -1)
				{
					alert("Please enter your valid telephone number");
					mf.phone.select()
					return(false)
				}
			}
		}		
		if(mf.company.value=="")
		{
			alert("Please enter the company name.");
			mf.company.focus();
			return false;
		}
		if(mf.address.value=="")
		{
			alert("Please enter the address.");
			mf.address.focus();
			return false;
		}
		if(mf.city.value=="")
		{
			alert("Please enter the city.");
			mf.city.focus();
			return false;
		}
		if(mf.zipcode.value=="")
		{
			alert("Please enter the zipcode.");
			mf.zipcode.focus();
			return false;
		}
		if(mf.country.value=="")
		{
			alert("Please select country.");
			mf.country.focus();
			return false;
		}
		if(mf.url_for_sale.value=="")
		{
			alert("Please enter url for sale.");
			mf.url_for_sale.focus();
			return false;
		}
		if(mf.url_for_sale.value!="")
		{
			var theurl=mf.url_for_sale.value;
			if(!tomatch.test(theurl))
			{
				alert("Please enter valid URL like http://www.yoururl.com");
				mf.url_for_sale.focus();
				return false;
			}
		}
		if(mf.visitors.value=="")
		{
			alert("Please enter visitors.");
			mf.visitors.focus();
			return false;
		}
/*
		if(mf.turnover.value=="")
		{
			alert("Please enter yearly turnover.");
			mf.turnover.focus();
			return false;
		}
*/
		if(mf.maintainance_working_hour.value=="")
		{
			alert("Please enter maintainance working hour per month.");
			mf.maintainance_working_hour.focus();
			return false;
		}	
		if(mf.selling_price.value=="")
		{
			alert("Please enter selling price.");
			mf.selling_price.focus();
			return false;
		}
		if(mf.seo_optimized[0].checked==false && mf.seo_optimized[1].checked==false)
		{
			alert("Please select at least one option for seo optimization");
			mf.seo_optimized[0].focus();
			return false;
		}		
		if(!mf.terms_agreed.checked)
		{
			alert("Please accept the terms of agreement to proceed registration");
			mf.terms_agreed.focus();
			return false;
		}
		return true;		
	}
	
/*	Validation for contact business	*/

	function checkContactBiz(mf)
	{
		if(mf.ref_number.value=="")
		{
			alert("Please enter the reference number.");
			mf.ref_number.focus();
			return false;
		}		
		if(mf.lname.value=="")
		{
			alert("Please enter the last name/surname.");
			mf.lname.focus();
			return false;
		}		
		if(mf.fname.value=="")
		{
			alert("Please enter the first name.");
			mf.fname.focus();
			return false;
		}
		if(trim(mf.email.value)=="")
		{ 
			alert("Please enter email address");
			mf.email.focus();
			return false;
		}
		if(checkEmail(mf.email)==false)
		{
			mf.email.focus();
			return false; 
		}
		if(mf.phone.value=="")
		{
			alert("Please enter the contact phone number.");
			mf.phone.focus();
			return false;
		}
		var valid= "+-()1234567890 ";
		if (mf.phone.value !="")
		{
			var string = mf.phone.value;
			var length = string.length;
			for(var i=0;i<=length;i++)
			{
				var substring = string.substr(i,1);
				if(valid.indexOf(substring)== -1)
				{
					alert("Please enter your valid telephone number");
					mf.phone.select()
					return(false)
				}
			}
		}		
		if(mf.address.value=="")
		{
			alert("Please enter the address.");
			mf.address.focus();
			return false;
		}
		if(mf.city.value=="")
		{
			alert("Please enter the city.");
			mf.city.focus();
			return false;
		}
		if(mf.zipcode.value=="")
		{
			alert("Please enter the zipcode.");
			mf.zipcode.focus();
			return false;
		}
		if(mf.country.value=="")
		{
			alert("Please select country.");
			mf.country.focus();
			return false;
		}
		if(mf.message.value=="")
		{
			alert("Please enter message.");
			mf.message.focus();
			return false;
		}
		return true;		
	}
	




