//-------------------------------------------------------------------------------------
 
var logflag=0;
var passflag=0;
var cpassflag=0;

var fnameflag=0
var lnameflag=0
var profflag=0

var othspecflag=0;

var hospflag=0;
var addflag=0;

var cityflag=0;
var pinflag=0;
var telflag=0;

var mailflag=1;
var pat;
var hollow;
 
//-------------------------------------------------------------------------------------
function textchecker()
{
	fname=document.register.fname.value;
	lname=document.register.lname.value
	addr=document.register.addr.value
	city=document.register.city.value
	pin=document.register.pin.value	
	tel=document.register.tel.value
	fax=document.register.fax.value
	mobile=document.register.mobile.value
	hosp=document.register.hosp.value
	prof=document.register.prof.value
	othspec=document.register.othspec.value
	login=document.register.login.value
	pass=document.register.pass.value
 	cpass=document.register.cpass.value


	if(fname=="" || fname==null)
	{
		fnameflag=1;
	}
	else
	{
	pat = /[^abcdefghijklmnopqrstuvwxyz.\-\' ]/i
	hollow = fname.match(pat)
		if (hollow!=null || hollow=="")
		{
			fnameflag=1;
		}
		else
		{
			fnameflag=0;
		}
	}

	if(lname=="" || lname==null)
	{
		lnameflag=1;
	}
	else
	{
	pat = /[^abcdefghijklmnopqrstuvwxyz.\-\' ]/i
	hollow = lname.match(pat)
		if (hollow!=null || hollow=="")
		{
			lnameflag=1;
		}
		else
		{
			lnameflag=0;
		}
	}

	if(addr=="" || addr==null)
	{
		addflag=1;
	}
	else
	{
		addflag=0;
	}

	if(city=="" || city==null)
	{
		cityflag=1;
	}
	else
	{
		cityflag=0;
	}

	if(pin=="" || pin==null)
	{
		pinflag=1;
	}
	else
	{
		digit = /[^1234567890 ]/i
		hollow = pin.match(digit)
		if (hollow!=null || hollow=="")
		{
			pinflag=1;
		}
        else
		{
			pinflag=0;
		}
	}
	
	
	if(pin=="" || pin==null)
	{
		pinflag=1;
	}
	else
	{
		digit = /[^1234567890 ]/i
		hollow = pin.match(digit)
		if (hollow!=null || hollow=="")
		{
			pinflag=1;
		}
        else
		{
			pinflag=0;
		}
	}

	if(tel=="" || tel==null)
	{
		telflag=1;
	}
	else
	{
		digit = /[^1234567890\- ]/i
		hollow = tel.match(digit)
		if (hollow!=null || hollow=="")
		{
			telflag=1;
		}
                else
		{
			telflag=0;
		}
	}

	if(fax=="" || fax==null)
	{
		faxflag=0;
	}
	else
	{
		digit = /[^1234567890\- ]/i
		hollow = fax.match(digit)
		if (hollow!=null || hollow=="")
		{
			faxflag=1;
		}
                else
		{
			faxflag=0;
		}
	}

	if(mobile=="" || mobile==null)
	{
		mobileflag=0;
	}
	else
	{
		digit = /[^1234567890\- ]/i
		hollow = mobile.match(digit)
		if (hollow!=null || hollow=="")
		{
			mobileflag=1;
		}
                else
		{
			mobileflag=0;
		}
	}

	if(hosp=="" || hosp==null)
	{
		hospflag=1;
	}
	else
	{
	pat = /[^abcdefghijklmnopqrstuvwxyz.,\-\' ]/i
	hollow = hosp.match(pat)
		if (hollow!=null || hollow=="")
		{
			hospflag=1;
		}
		else
		{
			hospflag=0;
		}
	}

	if(prof=="" || prof==null)
	{
		profflag=1;
	}
	else
	{
	pat = /[^abcdefghijklmnopqrstuvwxyz.,\-\' ]/i
	hollow = prof.match(pat)
		if (hollow!=null || hollow=="")
		{
			profflag=1;
		}
		else
		{
			profflag=0;
		}
	}

	if(othspec=="" || othspec==null)
	{
		othspecflag=0;
	}
	else
	{
		pat = /[^abcdefghijklmnopqrstuvwxyz ]/i
		hollow = othspec.match(pat)
		if (hollow!=null || hollow=="")
		{
			othspecflag=1;
		}
		else
		{
			othspecflag=0;
		}
	}

	if(login=="" || login==null)
	{
		logflag=1;
	}
	else
	{
	pat = /[^abcdefghijklmnopqrstuvwxyz1234567890 ]/i
	hollow = login.match(pat)
		if (hollow!=null || hollow=="")
		{
			logflag=1;
		}
		else
		{
			logflag=0;
		}
	}


	if(pass=="" || pass==null)
	{
		passflag=1;
	}
	else
	{
	pat = /[^abcdefghijklmnopqrstuvwxyz1234567890 ]/i
	hollow = pass.match(pat)
		if (hollow!=null || hollow=="")
		{
			passflag=1;
		}
		else
		{
			passflag=0;
		}
	}

	if(pass == cpass)
	{
		cpassflag=0;
	}
	else
	{
		cpassflag=1;
	}

}

//-----------------------------------------------------------------------------------
function mailsender()
{
	mailer=document.register.email.value	

  if(mailer=="" || mailer==null)
  {
  mailflag=1;	
  }
  else
  {
    paters = /@/
    hollowss = mailer.match(paters)
    if (hollowss==null)
    {
      mailflag=1;
    }
    else
    {
      poters = /[.]/
      hollosss = mailer.match(poters)
      if (hollosss==null)
			{
				mailflag=1;
			}
			  else
			{
				mailflag=0;
			}
		}
	}	
}
	
//-----------------------------------------------------------------------------------



function last()
{
	textchecker();
	mailsender();
	if (fnameflag==1)
	{
		alert("Please Enter a Valid First Name");
		document.register.fname.focus();
		return false;
	}
	else
	{
		if (lnameflag==1)
		{
			alert("Please Enter a Valid Family Name/Last Name");
			document.register.lname.focus();
			return false;
		}
		else
		{	
			if (addflag==1)
			{
				alert("Please Enter a Valid Address");	
				document.register.addr.focus();
				return false;
			}
			else
			{
				if (cityflag==1)
				{
					alert("Please Enter Your City");
					document.register.city.focus();
					return false;
				}
				else
				{
					if (pinflag==1)
					{
						alert("Please Enter a valid PIN/ZIP code");
						document.register.pin.focus();
						return false;
					}
					else
					{
						if (mailflag==1)
						{
							alert("Please Enter a Email address");	
							document.register.email.focus();
							return false;
						}
						else
						{
							if (telflag==1)
							{
								alert("Please Enter a Valid Telephone Number\n\nNo spaces or special characters are not allowed");
								document.register.tel.focus();
								return false;
							}
							else
							{
								if (faxflag==1)
								{
									alert("Please Enter a Valid Fax Number\n\nNo spaces or special characters are not allowed");
									document.register.fax.focus();
									return false;
								}
								else
								{
									if (mobileflag==1)
									{
										alert("Please Enter a Valid Mobile Number\n\nNo spaces or special characters are not allowed");
										document.register.mobile.focus();
										return false;
									}
									else
									{
										if (hospflag==1)
										{
											alert("Please Enter Your Hospital/Clinic name");	
											document.register.hosp.focus();
											return false;
										}
										else
										{
											if (profflag==1)
											{
												alert("Please Enter Your Profession");	
												document.register.prof.focus();
												return false;
											}
											else
											{
												if (logflag==1)
												{
												   alert("Please Enter a Login Name\n\nNo special charectors allowed");
												   document.register.login.focus();
												   return false;
												}
												else
												{
													if (passflag==1)
													{
														alert("Please Enter a Password\n\nNo special characters allowed");
														document.register.pass.focus();
														return false;
													}
													else
													{
														if (cpassflag==1)
														{
															alert("Password does not Matches");
															document.register.cpass.focus();
															return false;
														}
														else
														{
															return true;
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}