function checkre()
{ 
	flag=true;
    errmsg="";	
	var docf=document.regfrm;
	var cnt=0;
		
	//email id check 
	/*if(docf.emailaddress.value=="")
	{
		alert("Please Enter Email");
		docf.emailaddress.focus();
		return false;
	}
	if(docf.emailaddress.value!="")
    {
			if (isWhitespace(docf.emailaddress.value))
			{
				alert("Please Enter Email");
				 docf.emailaddress.focus();
				 return false;
			}
			else
			{
				if(isValidEmail(docf.emailaddress.value)==false)
				{
					 alert("Please Enter Correct Email");
					 docf.emailaddress.focus();
					 return false;
				}
			}
   }
	
		//end of code. 
		//alert(docf.username.value);
		if(docf.username.value=="")
		{
				alert("Please Enter User Name");
				docf.username.focus();
				return false;
		}




if(docf.username.value!="")
{
				if(isAlphaNumeric(docf.fname.value)==true)
				{
				 alert("Please Enter proper First name ");
				 docf.fname.focus();
				 return false;
				}
}
else



   
		if (isWhitespace(docf.username.value))
		{
			alert("Please Enter User Name");
			 docf.username.focus();
			 return false;
		}
		if(docf.firstname.value=="")
			{
				alert("Please Enter First Name");
				docf.firstname.focus();
				return false;
			}   
		if(!isAllCharacters(docf.firstname.value))
				{
				 alert("Please Enter proper First name ");
				 docf.firstname.focus();
				 return false;
				}
		if(docf.lastname.value=="")
			{
				alert("Please Enter Last Name");
				docf.lastname.focus();
				return false;
			}   
		   
				   
		if(docf.lastname.value!="")
			{
				if(!isAllCharacters(docf.lastname.value))
				{
				 alert("Please Enter proper Last name ");
				 docf.lastname.focus();
				 return false;
				}
			}
		   
		 // password matching.
		   if(docf.password.value=="")
			{
					alert("Please Enter Password");
					docf.password.focus();
					return false;
			}
		   if(docf.password.value!="")
			{
				 if (isWhitespace(docf.password.value))
				{
					alert("Please Enter Password.");
					docf.password.focus();
					return false;
				}
				else
				{
					if(isValidPassword(docf.password.value)==false)
					{
					 alert("Please Enter  Confirm password  Above 6 Chars & below 15 chars");
					 docf.password.focus();
					 return false;
					}
				}
			}
			if(docf.cpassword.value=="")
			{
							alert("Please Enter Password to confirm it.");
							docf.cpassword.focus();
							return false;
			}
	
			if(docf.cpassword.value!="")
			{
					if (isWhitespace(docf.cpassword.value)==true)
					{
						alert("Please Enter  Confirm password.");
						docf.cpassword.focus();
						return false;
					}
					else
					{
						if(isValidPassword(docf.cpassword.value)==false)
						{
						 alert("Please Enter  Confirm password  Above 6 Chars & below 15 chars");
						 docf.cpassword.focus();
						 return false;
						}
						
				}
					
			}
	
	if(docf.password.value!= "" && docf.cpassword.value != "")
	{
		if(docf.password.value != docf.cpassword.value)
		{
			alert("Both password didn't match !");
			docf.cpassword.focus();
			return false;
		}
	}

	// end of password matching
if(docf.country.value=="")
{
				alert("Please Select Country");
				docf.country.focus();
				return false;
}

		  if(docf.city.value=="")
{
				alert("Please Enter City Name");
				docf.city.focus();
				return false;
}

if(docf.city.value!="")
{
				if(!isAllCharacters(docf.city.value))
				{
				 alert("Please Enter proper City name ");
				 docf.city.focus();
				 return false;
				}
}

if(docf.postcode.value=="")
{
				alert("Please Enter Post Code");
				docf.postcode.focus();
				return false;
}

if(docf.postcode.value!="")
{
				if(!isAllNumerics(docf.postcode.value))
				{
					alert("Please Enter Post Code");
				docf.postcode.focus();
				return false;
				}
}*/

/*if(docf.photo.value=="")
{
				alert("Please upload your picture.");
				docf.photo.focus();
				return false;
}
if(docf.photo.value)
	{
		path=docf.photo.value;
		ext=path.split(".");
		//alert(ext[1]!="jpg" || ext[1] !="gif" || ext[1] !="png" || ext[1] !="jpeg" || ext[1] !="JPEG" || ext[1] !="JPG" || ext[1] !="GIF");
		if((ext[1]!="jpg") && (ext[1] !="gif" )&&(ext[1] !="png") &&(ext[1] !="jpeg") && (ext[1] !="JPEG") && (ext[1] !="JPG" )&& (ext[1] !="GIF"))
		{
			alert("Please enter correct format of your picture.");
			docf.photo.focus();
			return false;
		}
		
	}
	if(docf.message1.value.length < 50)
{
	alert("Your personal introduction is too short. Please write at least 50 characters. Your current introduction is only"+ docf.message1.value.length +"characters.");
	docf.message1.focus();
	return false;
	
	}*/
/*for (i=0;i<docf.gender.length;i++) 
{
	if (docf.gender[i].checked) 
	{
		cnt=cnt+1;
	}
}
if(cnt==0)
{
	alert("Please Select Gender");
	return false;
}
if(docf.dd.value=="")
{
				alert("Please Select Date");
				docf.dd.focus();
				return false;
}


if(docf.mm.value=="")
{
				alert("Please Select Month");
				docf.mm.focus();
				return false;
}

if(docf.yyyy.value=="")
{				alert("Please Select Year");
				docf.yyyy.focus();
				return false;
}
if(docf.agree.value=="")
{
				alert("Please Select the term and condition");
				docf.agree.focus();
				return false;
}

/*
if(docf.verify.value!="")
{
				if(isAlphaNumeric(docf.fname.value)==true)
				{
				 alert("Please Enter proper First name ");
				 docf.fname.focus();
				 return false;
				}
}
else
{
				alert("Please Enter Verification Code");
				docf.verify.focus();
				return false;
}
*/
}	



 var whitespace =" \t\n\r ";
function isEmpty(str)
{  
	return ((str == null) || (str.length == 0))
}
/***************************************************************************************************************
*  
*      isWhitespace is using the if  Field Empty 
*
****************************************************************************************************************/
function isWhitespace(str)
{    var i;
	 var flag
 	 if (isEmpty(str)) return true;	
	    for (i = 0; i < str.length; i++)
 	   {   
 	       // Check that current character isn't whitespace.
 	       var c = str.charAt(i);

		   if (whitespace.indexOf(c) == -1)
		   		return false
 	   }	
 	   // All characters are whitespace.
		    return true;
			
			
}
function isAlphaNumeric(objValue)
{
		var characters="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}
/*************************************************************************************************************
* 
*  isValidPassword only it takes valid password
*
**************************************************************************************************************/
function isValidPassword(val)
{
strval = val
if (strval.length < 6 || strval.length > 15)
   {
   	return false
   }	
else
   {
	return true;
   }	
}
/*************************************************************************************************************
*
*  MatchPasswords is check the password and confirmpassword is match  or not
*
**************************************************************************************************************/
function MatchPasswords(val1,val2)
{
strval1 = val1
strval2 = val2
if (strval1!= strval2)
   {
   	return false
   }	
else
   {
	return true;
   }	
}
/*************************************************************************************************************
*
* isAllNumerics only it takes Numeric values
*
**************************************************************************************************************/
function isAllNumerics(objValue)
{
		var characters="0123456789."
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		//alert(objValue);
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
		  if(objValue<=0)
		   {
			return false
		   }else{ 	
			return true
		  }
}
/*************************************************************************************************************
*
* isValidEmail it checks the Email-Id is Valid or Not 
*
**************************************************************************************************************/
function isValidEmail(emailStr)
{
			/* The following pattern is used to check if the entered e-mail address
			   fits the user@domain format.  It also is used to separate the username
			   from the domain. */
			var emailPat=/^(.+)@(.+)$/
			/* The following string represents the pattern for matching all special
			   characters.  We don't want to allow special characters in the address. 
			   These characters include ( ) < > @ , ; : \ " . [ ]    */
			//var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
			var specialChars="\\(\\)<>@,`';:~!#$%^&*+=|{}?\\\\\\\"\\.\\[\\]"
			
			/* The following string represents the range of characters allowed in a 
			   username or domainname.  It really states which chars aren't allowed. */
			var validChars="\[^\\s" + specialChars + "\]"
			/* The following pattern applies if the "user" is a quoted string (in
			   which case, there are no rules about which characters are allowed
			   and which aren't; anything goes).  E.g. "sg cricket"@disney.com
			   is a legal e-mail address. */
			var quotedUser="(\"[^\"]*\")"
			/* The following pattern applies for domains that are IP addresses,
			   rather than symbolic names.  E.g. sg@[123.124.233.4] is a legal
			   e-mail address. NOTE: The square brackets are required. */
			var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
			/* The following string represents an atom (basically a series of
			   non-special characters.) */
			var atom=validChars + '+'
			/* The following string represents one word in the typical username.
			   For example, in sg.sg@somewhere.com, sg and sg are words.
			   Basically, a word is either an atom or quoted string. */
			var word="(" + atom + "|" + quotedUser + ")"
			// The following pattern describes the structure of the user
			var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
			/* The following pattern describes the structure of a normal symbolic
			   domain, as opposed to ipDomainPat, shown above. */
			var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


			/* Finally, let's start trying to figure out if the supplied address is
			   valid. */

			/* Begin with the coarse pattern to simply break up user@domain into
			   different pieces that are easy to analyze. */
			var matchArray=emailStr.match(emailPat)
			if (matchArray==null) {
			  /* Too many/few @'s or something; basically, this address doesn't
			     even fit the general mould of a valid e-mail address. */
				//alert("Email address seems incorrect (check @ and .'s)")
				return false
			}
			var user=matchArray[1]
			var domain=matchArray[2]

			// See if "user" is valid 
			if (user.match(userPat)==null) {
			    // user is not valid
			    //alert("The username doesn't seem to be valid.")
			    return false
			}

			/* if the e-mail address is at an IP address (as opposed to a symbolic
			   host name) make sure the IP address is valid. */
			var IPArray=domain.match(ipDomainPat)
			if (IPArray!=null) {
			    // this is an IP address
				  for (var i=1;i<=4;i++) {
				    if (IPArray[i]>255) {
				        //alert("Destination IP address is invalid!")
					return false
				    }
			    }
			    return true
			}

			// Domain is symbolic name
			var domainArray=domain.match(domainPat)
			if (domainArray==null) {
			//alert("The domain name doesn't seem to be valid.")
			    return false
			}

			/* domain name seems valid, but now make sure that it ends in a
			   three-letter word (like com, edu, gov) or a two-letter word,
			   representing country (uk, nl, no), and that there's a hostname preceding 
			   the domain or country. */

			/* Now we need to break up the domain to get a count of how many atoms
			   it consists of. */
			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) {
			   // the address must end in a two letter or three letter word.
			   //alert("The address must end in a three-letter domain, or two letter country.")
			   return false
			}

			// Make sure there's a host name preceding the domain.
			if (len<2) {
			   var errStr="This address is missing a hostname!"
			   //alert(errStr)
			   return false
			}

			// If we've gotten this far, everything's valid!
			return true;
}
function isAllCharacters(objValue)
{
		var characters="' -abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ."
		var tmp
		var lTag
		lTag = 0
		temp = (objValue.length)
		for (var i=0;i<temp;i++)
		{
			tmp=objValue.substring(i,i+1)
			if (characters.indexOf(tmp)==-1)
			{
				lTag = 1
			}
		}
		if(lTag == 1)
			return false
		else
			return true
}


