function resets()
{
for (var i=0;i<document.formreg.elements.length;i++)
 document.formreg.elements[i].value="";
}
function trim(strinput)
{
    var i;
					 while(strinput.charAt(0)==' '||strinput.charAt(0)=='\t'||strinput.charAt(0)=='\n'||strinput.charAt(0)=='\r')
					{
					strinput= strinput.substring(1);
					}
					i = strinput.length-1;
					while(strinput.charAt(i)==' '||strinput.charAt(i)=='\t'||strinput.charAt(i)=='\n'||strinput.charAt(i)=='\r')
					{
					strinput = strinput.substring(0,i);
					i = i-1;
					}
return strinput;
}
					function reg()
					{
var username  = document.formreg.username.value;
var emailStr=document.formreg.emailid.value;
var fullname= document.formreg.fullname.value;
var billingaddress= document.formreg.billingaddress.value;
var billpostalcode= document.formreg.billpostalcode.value;
var deliveryaddress= document.formreg.deliveryaddress.value;
var delpostalcode= document.formreg.delpostalcode.value;
var confirmemailid= document.formreg.confirmemailid.value;

									if(trim(username)=="")
									{
												alert("Enter UserName");
												document.formreg.username.focus();
												return false;
									}
									/*if(username.length<3)
									{
												alert("Your Name must be atleast minimum 5 character");
												document.formreg.username.focus();
												return false;
									}*/

										if(trim(fullname)=="")
										{
													alert("Enter Your Full Name");
													document.formreg.fullname.focus();
													return false;
										}
										
										if(trim(billingaddress)=="")
										{
													alert("Enter Your Billing Address");
													document.formreg.billingaddress.focus();
													return false;
										}
										if(billingaddress.length>250)
										{
													alert("Billing Address should not exceed 250 characters");
													document.formreg.billingaddress.focus();
													return false;
										}
										
										if(trim(billpostalcode)=="")
										{
													alert("Enter the Billing postel code");
													document.formreg.billpostalcode.focus();
													return false;
										}
										if(deliveryaddress.length>250)
										{
													alert("Delivery Address should not exceed 250 characters");
													document.formreg.deliveryaddress.focus();
													return false;
										}




	var emailPat=/^(.+)@(.+)$/

	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"

	var validChars="\[^\\s" + specialChars + "\]"

	var quotedUser="(\"[^\"]*\")"

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/

	var atom=validChars + '+'

	var word="(" + atom + "|" + quotedUser + ")"

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) 
	{
	  
		alert("Email address seems incorrect (check @ and .'s)");
		document.formreg.emailid.focus();
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]

	if (user.match(userPat)==null) 
	{
		alert("The username in Email doesn't seem to be valid.");
		document.formreg.emailid.focus();
		return false
	}

	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) 
	{   
		  for (var i=1;i<=4;i++) 
		  {
			if (IPArray[i]>255) 
			{
				alert("Destination IP address is invalid!");
				document.formreg.emailid.focus();

			return false
			}
		}
    return true
	}

	var domainArray=domain.match(domainPat)
	if (domainArray==null) 
	{
		alert("The email doesn't seem to be valid.");
		document.formreg.emailid.focus();
		return false
	}

	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
	   
	   alert("The address must end in a three-letter domain, or two letter country.");
	   document.formreg.emailid.focus();
	   return false
	}

	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   alert(errStr);
		  document.formreg.emailid.focus();
	   return false
	}
if(trim(confirmemailid)=="")
	{
				alert("Enter  Confirm Email ID");
				document.formreg.confirmemailid.focus();
				return false;
	}
	if(trim(confirmemailid)!=trim(emailStr))
	{
				alert("Wrong Confirmation Email id");
				document.formreg.confirmemailid.focus();
				return false;
	}								


					}


