
//reload
function timedRefresh(timeoutPeriod)
{
	setTimeout("location.reload(true);",timeoutPeriod);
}
//Function to clear textbox
function ClearText(field,text)
{
    if(document.getElementById(field).value==text)
        document.getElementById(field).value="";
}

//Function to filltextbox
function FillText(field,text)
{
    if(document.getElementById(field).value=="")
        document.getElementById(field).value=text;
}


//Function to display

function display(Element)
{
    Element.style.display="block";
}

//Function to hide

function hide(Element)
{
    Element.style.display="none";
}

//Function to trim white spaces at start and end
String.prototype.trim = function ()
{
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}


function openPopUp(Path,PageName,Properties)
{
    var win=window.open(Path,PageName,Properties);
	win.opener=self;
	win.focus();
}

function setvalue(object,value)
{
    document.getElementById(object).value=value;
}

function setindex(object,index)
{
    document.getElementById(object).selectedIndex=index;
}

function setcheck(object,value)
{
    document.getElementById(object).checked=value;
}

function setfocus(object)
{
    document.getElementById(object).focus();
}

//Function to check empty value
function novalue(alias)
{
    if(document.getElementById(alias).value.replace(/ /gi,"")=="")
    {
        document.getElementById(alias).focus();
        return true;
    }
    else
    {
        return false;
    }
}

//Function to check value
function isvalue(alias,text)
{
    if(document.getElementById(alias).value==text)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function value(alias)
{
    return document.getElementById(alias).value;
}

function notselected(alias)
{
    if(document.getElementById(alias).selectedIndex<=0)
    {
        document.getElementById(alias).focus();
        return true;
    }
    else
    {
        return false;
    }
}
    
//Function to check "n" minimum characters
function minchars(alias,n)
{
	if(alias.value.length<n)
	{
		alert("Please enter atleast "+n+" characters.");
		alias.focus();
		return false;
	}
	return true;
}


//Function to check whether first letter is character or not
function firstchar(alias)
{
	str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	for(i=0;i<str.length;i++)
	{
		if(alias.value.charAt(0)==str.charAt(i))
			break;
	}
	if(i==str.length)
	{
		alert("Please do not enter numbers, spaces and special characters in starting.");
		alias.focus();
		return false;
	}
	return true;
}

//Function to check whether last letter is character or not
function lastchar(alias)
{
	str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	for(i=0;i<str.length;i++)
	{
		if(alias.value.charAt(alias.value.length-1)==str.charAt(i))
			break;
	}
	if(i==str.length)
	{
		alert("Please do not enter numbers, spaces and special characters in ending.");
		alias.focus();
		return false;
	}
	return true;
}

//Function to check for UserId(accepts only Capitals and '-')

function isuserid(alias)
{
	str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-";
	for(i=0;i<alias.value.length;i++)
	{
		if(alias.value.charAt(i)=='-')
		{
			if(alias.value.length>i)
			{
				if(alias.value.charAt(i+1)=='-')
				{
					alert("Please enter User ID correctly");
					alias.focus();
					return false;
				}
			}
		}
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
				break;
		}
		if(j>=str.length)
		{
			alert("Please enter your User ID correctly");
			alias.focus();
			return false;
		}
	}
	return true;
}

//Function to check for username
function isusername(alias)
{
	str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.";
	for(i=0;i<alias.value.length;i++)
	{
		if(alias.value.charAt(i)=='-')
		{
			if(alias.value.length>i)
			{
				if(alias.value.charAt(i+1)=='-')
				{
					alert("Please enter your Username correctly");
					alias.focus();
					return false;
				}
			}
		}
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
				break;
		}
		if(j>=str.length)
		{
			alert("Please do not enter spaces and special characters");
			alias.focus();
			return false;
		}
	}
	return true;
}

function isspecialchar(alias)
{
	str="&#*$/\<>?%^~";
	for(i=0;i<alias.value.length;i++)
	{
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
			{
				alert("Please do not enter special characters");
				alias.focus();
				return true;
			}
		}
	}
	return false;
}

//Function to check name (allows letters,space and .)
function isname(alias)
{
	str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .!@#$&*()-_,<>:;/";
	for(i=0;i<alias.value.length;i++)
	{
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
				break;
		}
		if(j==str.length)
		{
			alert("Please do not enter  '   ");
			alias.focus();
			return false;
		}
	}
	if(!notdoublespace(alias))
	{
		return false;
	}
	return true;
}

//Function to check name (allows letters,space and .)
function isname1(alias)
{
	str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .";
	for(i=0;i<alias.value.length;i++)
	{
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
				break;
		}
		if(j==str.length)
		{
			alias.focus();
			return false;
		}
	}
	/*if(!notdoublespace(alias))
	{
		return false;
	}*/
	return true;
}

//Function to check password(allows only letters and numbers
function ispassword(alias)
{
	str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.-@~$";
	for(i=0;i<alias.value.length;i++)
	{
		if(alias.value.charAt(i)=='-')
		{
			if(alias.value.length>i)
			{
				if(alias.value.charAt(i+1)=='-')
				{
					alert("Please enter your password correctly");
					alias.focus();
					return false;
				}
			}
		}
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
				break;
		}
		if(j>=str.length)
		{
			alert("Please do not enter special characters except .,-,@,~ and $ in password");
			alias.value="";
			alias.focus();
			return false;
		}
	}
	return true;
}

// Function to avoid numbers in first three places
function onlycharn(alias,n)
{
	str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	for(i=0;i<n;i++)
	{
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
				break;
		}
		if(j>=str.length)
		{
			alert("Please do not enter numbers, special characters upto "+n+" places");
			alias.focus();
			return false;
		}
	}
	return true;
}

// Function to allow only characters
function isonlychar(alias)
{
	str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
	for(i=0;i<alias.value.length;i++)
	{
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
				break;
		}
		if(j>=str.length)
		{
			alert("Please enter characters only.");
			alias.focus();
			return false;
		}
	}
	return true;
}

// Function to allow only numbers
function isonlynum(alias)
{
	str="0123456789";
	for(i=0;i<alias.value.length;i++)
	{
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
				break;
		}
		if(j>=str.length)
		{
			alert("Please enter numbers only.");
			alias.focus();
			return false;
		}
	}
	return true;
}

// Function to allow only numbers
function isonlynum1(alias)
{
	str="0123456789";
	for(i=0;i<alias.value.length;i++)
	{
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
				break;
		}
		if(j>=str.length)
		{
			return false;
		}
	}
	return true;
}

function isonlynumber(alias)
{
	str="0123456789";
	for(j=0;j<alias.length;j++)
	{
		for(k=0;k<str.length;k++)
		{
			if(alias.charAt(j)==str.charAt(k))
				break;
		}
		if(k>=str.length)
		{
			return false;
		}
	}
	return true;
}

// Function to check for all special characters
function isalphanumeric(alias)
{
	str="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 ";
	for(i=0;i<alias.value.length;i++)
	{
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
				break;
		}
		if(j>=str.length)
		{
			alert("Please enter characters and numbers only.");
			alias.focus();
			return false;
		}
	}
	return true;
}

// Function to check for spaces
function notspace(alias)
{
	for(i=0;i<alias.value.length;i++)
	{
		if(alias.value.charAt(i)==" ")
		{
			alert("Please do not enter space.");
			alias.focus();
			return false;
		}
	}
	return true;
}

//Function to check for double spaces
function notdoublespace(alias)
{
	for(i=0;i<alias.value.length;i++)
	{
		if(alias.value.charAt(i)==" ")
		{
			if(alias.value.charAt(i+1)==" ")
			{
				alert("Please do not enter double spaces.");
				alias.focus();
				return false;
			}
		}
	}
	return true;
}

//Function to check Phone Number

function isphonenumber(alias)
{
	str="+-0123456789";
	//to allow only numbers and +,-
	for(i=0;i<alias.value.length;i++)
	{
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
				break;
		}
		if(j>=str.length)
		{
			alert("Please enter phone number correctly(only numbers,+,-).");
			alias.focus();
			return false;
		}		
	}
	//to allow + only in starting
	for(i=1;i<alias.value.length;i++)
	{
		if(alias.value.charAt(i)=="+")
		{
			alert("Please enter + only in starting.");
			alias.focus();
			return false;
		}
	}
	//Not to allow +,- in ending.
	if(alias.value.charAt((alias.value.length)-1)=="-")
	{
		alert("Please donot enter +,- in ending.");
		alias.focus()
		return false;
	}
	//Not to allow - more than once
	count=0;
	for(i=0;i<alias.value.length;i++)
	{
		if(alias.value.charAt(i)=="-")
			count++;
		if(count>1)
		{
			alert("Please donot enter - twice.");
			alias.focus();
			return false;
		}
	}
	
	//Not to allow more than 14 characters
	if((alias.value.length<10)||(alias.value.length>14))
	{
		alert("Please enter 10-14 digit phone number.");
		alias.focus();
		return false;
	}
	return true;
}

//Function to check Phone Numbers

function isphonenumbers(alias)
{
	str="+-0123456789";
	var phnumbers=alias.value.split(",");
	for(r=0;r<phnumbers.length;r++)
	{
		var phnumber=phnumbers[r].replace(" ","");
		if(phnumber=="")
		{
			alert("Please enter contact numbers correctly");
			alias.focus();
			return false;
		}
		//to allow only numbers and +,-
		for(i=0;i<phnumber.length;i++)
		{
			for(j=0;j<str.length;j++)
			{
				if(phnumber.charAt(i)==str.charAt(j))
					break;
			}
			if(j>=str.length)
			{
				alert("Please enter phone number correctly(only numbers,+,-).");
				alias.focus();
				return false;
			}		
		}
		//to allow + only in starting
		for(i=1;i<phnumber.length;i++)
		{
			if(phnumber.charAt(i)=="+")
			{
				alert("Please enter + only in starting.");
				alias.focus();
				return false;
			}
		}
		//Not to allow +,- in ending.
		if(phnumber.charAt((phnumber.length)-1)=="-")
		{
			alert("Please donot enter +,- in ending.");
			alias.focus()
			return false;
		}
		//Not to allow - more than once
		count=0;
		for(i=0;i<phnumber.length;i++)
		{
			if(phnumber.charAt(i)=="-")
				count++;
			if(count>1)
			{
				alert("Please donot enter - twice.");
				alias.focus();
				return false;
			}
		}
	
		//Not to allow more than 14 characters
		if((phnumber.length<10)||(phnumber.length>14))
		{
			alert("Please enter 10-14 digit phone number.");
			alias.focus();
			return false;
		}		
	}
	return true;
}

//Function to check radiobutton list

function isrbselected(alias)
{
	for(i=0;i<alias.length;i++)
	{
		if(alias[i].checked)
			break;
	}
	if(i==alias.length)
	{
		return false;
	}
	return true;
}

//Function to check percentage
function percentage(alias)
{
	str="0123456789.";
	count=0;
	for(i=0;i<alias.value.length;i++)
	{
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
			{
				if(alias.value.charAt(i)==".")
					count++;
				break;
			}
		}
		if(j==str.length)
		{
			alert("Please enter numbers and . only");   
			alias.focus();
			return false;
		}
	}
	if(count>1)
	{
		alert("Please enter the value correctly.");
		alias.focus();
		return false;
	}
	if(count==0)
	{
		if(alias.value.length>2)
		{
			alert("Please enter the value correctly.");
			alias.focus();
			return false;
		}
	}
	if(count==1)
	{
		if(alias.value.length>5)
		{
			alert("Please enter the value correctly.");
			alias.focus();
			return false;
		}
		if(alias.value.length==5)
		{
			if(alias.value.charAt(2)!=".")
			{
				alert("Please enter the value correctly.");
				alias.focus();
				return false;
			}
		}
		if(alias.value.length==4)
		{
			if((alias.value.charAt(1)!=".")&&(alias.value.charAt(2)!="."))
			{
				alert("Please enter the value correctly.");
				alias.focus();
				return false;
			}
		}
		if(alias.value.length<=3)
		{
			alert("Please enter the value correctly.");
			alias.focus();
			return false;
		}
	}
	
	return true;
}

//Function to check float
function isfloat(alias)
{
	str="0123456789.";
	count=0;
	for(i=0;i<alias.value.length;i++)
	{
		for(j=0;j<str.length;j++)
		{
			if(alias.value.charAt(i)==str.charAt(j))
			{
				if(alias.value.charAt(i)==".")
					count++;
				break;
			}
		}
		if(j==str.length)
		{
			alert("Please enter numbers and . only");   
			alias.focus();
			return false;
		}
	}
	if(count>1)
	{
		alert("Please enter the value correctly.");
		alias.focus();
		return false;
	}
	
	return true;
}

//Function to check valid email id (Passing Control)

function ismailid(alias)
{
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|in|COM|NET|ORG|EDU|INT|MIL|GOV|ARPA|BIZ|AERO|NAME|COOP|INFO|PRO|MUSEUM|IN)$/;
	/* 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="\\(\\)><@,*;:\\#\\$\\*\\^\\\\\"\\.\\[\\]";

	/* 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=alias.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("The Email address seems incorrect.Please check @ and .'s");
		alias.focus();
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++)
	{
		if (user.charCodeAt(i)>127)
		{
			alert("The username contains invalid characters.Please check.");
			alias.focus();
			return false;
		}
	}
	for (i=0; i<domain.length; i++) 
	{
		if (domain.charCodeAt(i)>127) 
		{
			alert("Ths domain name contains invalid characters.Please check.");
			alias.focus();
			return false;
		}
	}

	// See if "user" is valid 

	if (user.match(userPat)==null) 

	{

		// user is not valid

		alert("The username doesn't seem to be valid.Please check.");
		alias.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!Please check.");
				alias.focus();
				return false;
			}
		}
		return true;
	}
	// Domain is symbolic name.  Check if it's valid.
 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat)==-1) 
		{
			alert("The domain name does not seem to be valid.Please check.");
			alias.focus();
			return false;
		}
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding 
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 && 
		domArr[domArr.length-1].search(knownDomsPat)==-1) 
	{
		alert("Please enter the email address with a well-known domain or two letter " + "country.");
		alias.focus();
		return false;
	}

	// Make sure there's a host name preceding the domain.

	if (len<2) 
	{
		alert("This email address is missing a hostname!Please check.");
		alias.focus();
		return false;
	}
	return true;
}



//Function to check valid email id(passing value)

function ismailids(alias)
{
	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */

	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|in|COM|NET|ORG|EDU|INT|MIL|GOV|ARPA|BIZ|AERO|NAME|COOP|INFO|PRO|MUSEUM|IN)$/;
	/* 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="\\(\\)><@,*;:\\#\\$\\*\\^\\\\\"\\.\\[\\]";

	/* 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. */
	
	//Get emailids separated by commas
	var mailids=alias.value.split(",");
	
	//check every emailid
	for(r=0;r<mailids.length;r++)
	{
		var emailid=mailids[r].replace(" ","");
		
		if(emailid=="")
		{
			alert("Please enter emailids correctly");
			alias.focus();
			return false;
		}
	
		var matchArray=emailid.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("The Email address seems incorrect.Please check @ and .'s");
			alias.focus();
			return false;
		}
		var user=matchArray[1];
		var domain=matchArray[2];

		// Start by checking that only basic ASCII characters are in the strings (0-127).

		for (i=0; i<user.length; i++)
		{
			if (user.charCodeAt(i)>127)
			{
				alert("The username contains invalid characters.Please check.");
				alias.focus();
				return false;
			}
		}
		for (i=0; i<domain.length; i++) 
		{
			if (domain.charCodeAt(i)>127) 
			{
				alert("Ths domain name contains invalid characters.Please check.");
				alias.focus();
				return false;
			}
		}

		// See if "user" is valid 

		if (user.match(userPat)==null) 

		{

			// user is not valid

			alert("The username doesn't seem to be valid.Please check.");
			alias.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!Please check.");
					alias.focus();
					return false;
				}
			}
			return true;
		}
		// Domain is symbolic name.  Check if it's valid.
 
		var atomPat=new RegExp("^" + atom + "$");
		var domArr=domain.split(".");
		var len=domArr.length;
		for (i=0;i<len;i++)
		{
			if (domArr[i].search(atomPat)==-1) 
			{
				alert("The domain name does not seem to be valid.Please check.");
				alias.focus();
				return false;
			}
		}

		/* domain name seems valid, but now make sure that it ends in a
		known top-level domain (like com, edu, gov) or a two-letter word,
		representing country (uk, nl), and that there's a hostname preceding 
		the domain or country. */

		if (checkTLD && domArr[domArr.length-1].length!=2 && 
			domArr[domArr.length-1].search(knownDomsPat)==-1) 
		{
			alert("Please enter the email address with a well-known domain or two letter " + "country.");
			alias.focus();
			return false;
		}

		// Make sure there's a host name preceding the domain.

		if (len<2) 
		{
			alert("Email address is missing a hostname!Please check.");
			alias.focus();
			return false;
		}
	}
	return true;
}


//valdating the date
function validadate(dd,mm,yy)
{
    var today=new Date();
	var todaydate=new Date(today.getFullYear(),today.getMonth(),today.getDate());
	var date1=new Date(yy.value,mm.value-1,dd.value);
	if(date1>todaydate)
	{
	    alert("selected date is greater than today date! Please Select valid date");
		dd.focus();
		return false;
	}
				
	var myDayStr = dd.value;
    var myMonthStr = mm.value-1;
    var myYearStr = yy.value;
    var myMonth = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'); 
    var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr;
    var myDate = new Date();
    myDate.setFullYear( myYearStr, myMonthStr, myDayStr );
    if ( myDate.getMonth() != myMonthStr )
    {
        alert( "sorry! selected date '"+myDateStr+"' is NOT a valid date.");
        return false;
    } 
               
    return true;
}


//valdating the date
function validdate(ddmmyyyy)
{
    var today=new Date();
	var todaydate=new Date(today.getFullYear(),today.getMonth(),today.getDate());
	var date1=new Date(ddmmyyyy.value.split('/')[2],ddmmyyyy.value.split('/')[1]-1,ddmmyyyy.value.split('/')[0]);
	if(date1<todaydate)
	{
	    alert("selected date is greater than today date! Please Select valid date");
		ddmmyyyy.focus();
		return false;
	}
				
	var myDayStr = ddmmyyyy.value.split('/')[0];
    var myMonthStr = ddmmyyyy.value.split('/')[1]-1;
    var myYearStr = ddmmyyyy.value.split('/')[2];
    var myMonth = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'); 
    var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr;
    var myDate = new Date();
    myDate.setFullYear( myYearStr, myMonthStr, myDayStr );
    if ( myDate.getMonth() != myMonthStr )
    {
        alert( "sorry! selected date '"+myDateStr+"' is NOT a valid date.");
        ddmmyyyy.focus();
        return false;
    } 
               
    return true;
}
//date validation for greater date
function vdate(dd,mm,yy)
{
    var today=new Date();
	var todaydate=new Date(today.getFullYear(),today.getMonth(),today.getDate());
	var date1=new Date(yy.value,mm.value-1,dd.value);
	if(date1<=todaydate)
	{
	    alert("selected date is less than today date! Please Select valid date");
		dd.focus();
		return false;
	}
				
	var myDayStr = dd.value;
    var myMonthStr = mm.value-1;
    var myYearStr = yy.value;
    var myMonth = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sept','Oct','Nov','Dec'); 
    var myDateStr = myDayStr + ' ' + myMonth[myMonthStr] + ' ' + myYearStr;
    var myDate = new Date();
    myDate.setFullYear( myYearStr, myMonthStr, myDayStr );
    if ( myDate.getMonth() != myMonthStr )
    {
        alert( "sorry! selected date '"+myDateStr+"' is NOT a valid date.");
        return false;
    } 
               
    return true;
}

function CheckMaxPrefLoc(Obj)
{
	var length = Obj.length;
	var i = 0;
	var SelectedCount = 0;
	for(i=0; i<length; i++ )  {
		if( Obj.options[i].selected == true )  {
			if (Obj.options[i].value == -1 )
				Obj.options[i].selected = false;
			else
				SelectedCount++;
		}
		if ( SelectedCount > 3 )  {
			alert("You can choose a maximum of three locations.");
			var j = 0;
			for(j = length-1 ; j>= i; j-- )
				Obj.options[j].selected = false;
			break;
		}
	}
}

function CheckMaxPrefLoc(Obj,count)
{
	var length = Obj.length;
	var i = 0;
	var SelectedCount = 0;
	for(i=0; i<length; i++ )  {
		if( Obj.options[i].selected == true )  {
			if (Obj.options[i].value == -1 )
				Obj.options[i].selected = false;
			else
				SelectedCount++;
		}
		if ( SelectedCount > count )  {
			alert("You can choose a maximum of "+count+" locations.");
			var j = 0;
			for(j = length-1 ; j>= i; j-- )
				Obj.options[j].selected = false;
			break;
		}
	}
}

function selectedOptions(Obj)
{
	var length = Obj.length;
	var i = 0;
	var SelectedCount = 0;
	for(i=0; i<length; i++ )
	{
		if( Obj.options[i].selected == true )
		{
			if (Obj.options[i].value == -1 )
				Obj.options[i].selected = false;
			else
				SelectedCount++;
		}
	}
	return SelectedCount;
}

//Select all Checkboxes
function SelectAllCheckboxes(CheckBox)
{
    var xState=CheckBox.checked;
	var theBox=CheckBox;
	        
	elm=theBox.form.elements;
	for(i=0;i<elm.length;i++)
	{
	    if(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
		{
		    //elm[i].click();
			if(elm[i].checked!=xState)
			elm[i].click();
			//elm[i].checked=xState;
		}
	}
}

function CheckMaxSelection(Obj)
{
	var length = Obj.length;
	var i = 0;
	var SelectedCount = 0;
	for(i=0; i<length; i++ )  {
		if( Obj.options[i].selected == true )  {
			if (Obj.options[i].value == -1 )
				Obj.options[i].selected = false;
			else
				SelectedCount++;
		}
		if ( SelectedCount > 3 )  {
			alert("You can choose a maximum of three "+object+".");
			var j = 0;
			for(j = length-1 ; j>= i; j-- )
				Obj.options[j].selected = false;
			break;
		}
	}
}

function CheckMaxSelection(Obj,count,object)
{
	var length = Obj.length;
	var i = 0;
	var SelectedCount = 0;
	for(i=0; i<length; i++ )  {
		if( Obj.options[i].selected == true )  {
			if (Obj.options[i].value == -1 )
				Obj.options[i].selected = false;
			else
				SelectedCount++;
		}
		if ( SelectedCount > count )  {
			alert("You can choose a maximum of "+count+" "+object+".");
			var j = 0;
			for(j = length-1 ; j>= i; j-- )
				Obj.options[j].selected = false;
			break;
		}
	}
}

function CheckMinSelection(Obj,count,object)
{
	var length = Obj.length;
	var i = 0;
	var SelectedCount = 0;
	for(i=0; i<length; i++ )
	{
		if( Obj.options[i].selected == true )
		{
			if (Obj.options[i].value == -1 )
				Obj.options[i].selected = false;
			else
				SelectedCount++;
		}
	}
	if( SelectedCount < count )
	{
		alert("You should choose atleast "+count+" "+object+".");
		Obj.focus();
		return false;
	}
	else return true;
}

function displaySelectedOptions(ListObject,DisplayObject)
{
	var i = 0;
	var SelectedOptions="";
    for(i=0;i<ListObject.length;i++)
    {
		if(ListObject.options[i].selected == true )
		{
			if (ListObject.options[i].value == -1 )
				ListObject.options[i].selected = false;
			else
			{
			    if(SelectedOptions!="")
			    {
			        SelectedOptions+=", ";
			    }
			    SelectedOptions+=ListObject.options[i].value;
		    }
		}
    }
    if(SelectedOptions=="")
        SelectedOptions="none";
    DisplayObject.innerHTML="You selected "+SelectedOptions;
}

function textCounter(field, countfield, maxlimit)
{
    if (field.value.length > maxlimit)
	    field.value = field.value.substring(0, maxlimit);
	else 
		countfield.value = maxlimit - field.value.length;
}

function textCounter(field, maxlimit)
{
    if (field.value.length > maxlimit)
	    field.value = field.value.substring(0, maxlimit);
}