// JavaScript Document

function validate_Buyer_Registration()
{

if(document.buyerregistration.BuyersCompanyName.value=="")
{
alert("Please Enter CompanyName");
document.buyerregistration.BuyersCompanyName.focus;
document.buyerregistration.BuyersCompanyName.select();
return false;
}
if(document.buyerregistration.BuyersContactPerson.value=="")
{
alert("Please Enter Contact Person");
document.buyerregistration.BuyersContactPerson.focus;
document.buyerregistration.BuyersContactPerson.select();
return false;
}
if(document.buyerregistration.BuyersCountryID.value=="")
{
alert("Please Select Country");
document.buyerregistration.BuyersCountryID.focus;
//document.buyerregistration.ersCountryID.select();
return false;
}
if(document.buyerregistration.email.value=="")
	{
		alert("Please Enter Email - ID..");
		document.buyerregistration.email.focus;
		document.buyerregistration.email.select();
		return false;
	}
	else
	{
			var	Email=buyerregistration.email.value;
			var bond=buyerregistration.email;
		
			 if (!isEmail(Email,bond) )
			  {
			      return false;			    
			  }
	}
		
if(document.buyerregistration.BuyersPassword.value=="")
{
alert("Please Enter Password");
document.buyerregistration.BuyersPassword.focus;
document.buyerregistration.BuyersPassword.select();
return false;
}
if(document.buyerregistration.BuyersPasswordC.value=="")
	{
		alert("Please Enter Buyers Password Again..");
		document.buyerregistration.BuyersPasswordC.focus;
		document.buyerregistration.BuyersPasswordC.select();
		return false;
	}
	if(document.buyerregistration.BuyersPassword.value!=document.buyerregistration.BuyersPasswordC.value)
	{
		alert("Buyers Password Again AND Confirm Password is not Same..");
		document.buyerregistration.BuyersPasswordC.focus;
		document.buyerregistration.BuyersPasswordC.select();
		return false;
	}
if(document.buyerregistration.CategoryID.value=="")
			{
				alert("Please Select Category ..");
				
				return false;
			}
if(document.buyerregistration.SubCategoryID.value=="")
			{
				alert("Please Select Sub Category ..");
				
				return false;
			}
		if(document.buyerregistration.Title.value=="")
			{
				alert("Please Enter Title..");
				document.buyerregistration.Title.focus;
				document.buyerregistration.Title.select();
				return false;
			}
		if(document.buyerregistration.wordimgt.value!="")
			{
				lvalue=document.buyerregistration.wordimgt.value.length
				val=document.buyerregistration.wordimgt.value
				lindex=val.indexOf(".")
				docstr=val.substring(lindex+1,lvalue)
				if(docstr!="jpg" && docstr!="jpeg" && docstr!="bmp" && docstr!="gif" && docstr!="JPG" && docstr!="BMP" && docstr!="GIF" && docstr!="JPEG")
				{
					alert("Image Should be ,jpeg,bmp,gif..");		
					document.buyerregistration.wordimgt.focus();
					return false;
				}
			}	
		if(document.buyerregistration.Quantity.value=="")
			{
				alert("Please Enter Quantity..");
				document.buyerregistration.Quantity.focus;
				document.buyerregistration.Quantity.select();
				return false;
			}
		if(document.buyerregistration.UnitID.value=="0")
			{
				alert("Please Select Unit ..");
				
				return false;
			}
			
		var from = document.buyerregistration.AproxValueFrom.value;
		var to = document.buyerregistration.AproxValueTo.value;
		if(from!="" && to!="")
		{
			if (to-from<0)
			{
				alert("From Value Cannot Be Greater Than To Value");
				document.buyerregistration.AproxValueTo.focus;
				document.buyerregistration.AproxValueTo.select();
				return false;
			}
			
		}
		
		if(document.buyerregistration.DeliveryCountryID.value=="0")
			{
				alert("Please Select Delivery Country ..");
				
				return false;
			}

}
function isEmail(s,sbond)
		
				{
				   // there must be >= 1 character before @, so we
				   // start looking at character position 1
				   // (i.e. second character)
				   var i = 1;
				   var sLength = s.length;
 
				   // look for @
				   while ((i < sLength) && (s.charAt(i) != "@"))
				   { i++
				   }
				   if ((i >= sLength) || (s.charAt(i) != "@")) 
				   {
					  alert( "Invalid Email." );
					  sbond.focus();
				      return false;
				   }
				   else i += 2;
 
				   // look for .
				   while ((i < sLength) && (s.charAt(i) != "."))
				   { i++
				   }
 
				   // there must be at least one character after the .
				   if ((i >= sLength - 1) || (s.charAt(i) != ".")) 
				   {
					  alert( "Invalid Email." );
					  sbond.focus();
 					  //isEmail = false
 					  return false;
				   }
				   
					//alert("wow");
				   //else return true;
					
					return true;
					
				}
