// JavaScript Document

function email_validate(f) {
	if (document.frmgenusrname.email.value == ""){
		alert("Please Provide Email id")
		document.frmgenusrname.email.focus();
		return false
	}
	
	
	/* 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=",/<>?!'`;:#$%^&*()=|[]{}"+'"'+"\\\n\t";
	
	/* 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. "jiminy 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. joe@[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 john.doe@somewhere.com, john and doe 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=document.frmgenusrname.email.value.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)");
		document.frmgenusrname.email.focus();
		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 part of your email address before the '@' doesn't seem to be valid.");
		document.frmgenusrname.email.focus();
		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!");
				document.frmgenusrname.email.focus();
			return false
			}
		}
		return true
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		alert("Part of your email address after the '@' doesn't seem to be valid");
		document.frmgenusrname.email.focus();
		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), 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>6) {
	   // the address must end in a two letter or other TLD including museum
	   alert("The address must end in a top level domain (e.g. .com), or two letter country.");
	   document.frmgenusrname.email.focus();
	   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);
	   document.frmgenusrname.email.focus();
	   return false
	}
}

function usrname_validate() {
	if (document.frmchkusr.usrname.value == ""){
		alert("Please Provide Username")
		document.frmchkusr.usrname.focus();
		return false
	}
	if (document.frmchkusr.usrname.value.length > 9){
		alert("User name must be maximum 8 characters.")
		document.frmchkusr.usrname.focus();
		return false
	}
	return true
}
function getusrname_validate() {
	if (document.frmusercreate.old_username.value == ""){
		alert("Please Provide Your Old Username")
		document.frmusercreate.old_username.focus();
		return false;
	}
	if (document.frmusercreate.password.value == ""){
		alert("Please Provide Your Password")
		document.frmusercreate.password.focus();
		return false;
	}
	if (document.frmchkusr.usrname.value == ""){
		alert("Please Provide Username")
		document.frmchkusr.usrname.focus();
		return false
	}
	return true
}





function validate(f) {
	if (document.frmlogin.username.value == "")
	{
		alert("Please fill User Name")
		document.frmlogin.username.focus();
		return false
	}
	
	if (document.frmlogin.password.value == ""){
		alert("Please fill the password")
		document.frmlogin.password.focus();
		return false
	}
	return true
}

function gencode_validate(f) {
	if (document.frmgencode.username.value == ""){
		alert("Please fill User Name")
		document.frmgencode.username.focus();
		return false
	}
	
	if (document.frmgencode.password.value == ""){
		alert("Please fill the password")
		document.frmgencode.password.focus();
		return false
	}
	return true
}

function petstuck_validate(f) {
	
	if (document.frmpetstuck.username.value == ""){
		alert("Please Provide Your Username")
		document.frmpetstuck.username.focus();
		return false
	}
	if (document.frmpetstuck.password.value == ""){
		alert("Please Provide Your Password")
		document.frmpetstuck.password.focus();
		return false
	}
	if (document.frmpetstuck.sec_code.value == ""){
		alert("Please Provide Your Secret Code")
		document.frmpetstuck.sec_code.focus();
		return false
	}
	if (document.frmpetstuck.petname.value == ""){
		alert("Please Provide Your Pet Name")
		document.frmpetstuck.petname.focus();
		return false
	}
	if (document.frmpetstuck.pettype.value == ""){
		alert("Please Provide Type of Your Pet")
		document.frmpetstuck.pettype.focus();
		return false
	}
	if (document.frmpetstuck.roomname.value == ""){
		alert("Please Provide Type of Your Pet")
		document.frmpetstuck.roomname.focus();
		return false
	}
	if (document.frmpetstuck.roomname.value == ""){
		alert("Please Provide the Room Name Where Your Pet is Stucked")
		document.frmpetstuck.roomname.focus();
		return false
	}
	return true
}


function bug_report(f) {
	
	if (document.frmbugrep.username.value == ""){
		alert("Please Provide Your Username")
		document.frmbugrep.username.focus();
		return false
	}
	if (document.frmbugrep.password.value == ""){
		alert("Please Provide Your Password")
		document.frmbugrep.password.focus();
		return false
	}
	if (document.frmbugrep.bug_rep.value == ""){
		alert("Please Provide the Bug Details")
		document.frmbugrep.bug_rep.focus();
		return false
	}
	return true
}

function toggle(target, iNo)
{
	obj=document.getElementById(target+String(iNo));
	obj.style.display=( (obj.style.display=='none') ? '' : 'none');
}

