// JavaScript Document
function isEmailValid(st) {
	var error = false;
	var at = st.indexOf("@");
	var dot = st.indexOf(".", at);
	var invStringPresent = false;
	var invalidString = ['!', '#', '$', '%', '^', '&', '*', '+', '/', "\\", '(', ')', '[', ']', '{', '}', ';', ':', "'", '\"', '<', '>', ',', '?', '~', '`', ' ', '=', '|'];
	//check for invalid strings
	for (i=0; i<invalidString.length; i++) {
		if (st.indexOf(invalidString[i])>=0) {
			invStringPresent = true;
			//trace("Invalid String "+invalidString[i]+" present");
		}
	}
	//trace("AT = "+at+" , DOT = "+dot);
	switch (true) {
	case invStringPresent :
		// for Invalid Strings
	case (at<0) :
		// 'at' presence
	case (at == 0) :
		// 'at' NOT at the beginning
	case (st.indexOf("@", at+1)>=0) :
		// only one 'at'		
	case (dot<0) :
		// 'dot' presence
	case (dot<at) :
		// 'dot' after at
	case (st.lastIndexOf(".") == st.length-1) :
		// 'dot' not in the last
	case ((dot-at) == 1) :
		// NO 'dot' immediately after 'at'
		error = true;
	}
	//trace("ERROR = "+error);
	return (!error);
}
var formName;
function getForm(frm1)
{
	formName = frm1
}


function IsSelect(con, msg)
{
	val = (eval("document."+formName+"."+con+".value"));
	foc = (eval("document."+formName+"."+con+".focus()"));
	if(val==0)
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		foc;
		return false;
	}
	else
	{
		return true;
	}
}


function IsNumber(con, msg)
{
	val = (eval("document."+formName+"."+con+".value"));
	foc = (eval("document."+formName+"."+con+".focus()"));
	if(!(IsEmpty(con, "")))
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		foc;
		setval =(eval("document."+formName+"."+con+".value=''"));
		return false;
	}
	if(isNaN(val))
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		setval =(eval("document."+formName+"."+con+".value=''"));
		foc;
		return false;
	}
	else
	{
		return true;
	}
}

function ChkLength(con, conLen, msg)
{
	val = (eval("document."+formName+"."+con+".value"));
	foc = (eval("document."+formName+"."+con+".focus()"));
	if(val.length<conLen)
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		foc;
		return false;
	}
	return true;
}

function IsEmpty(con, msg)
{
	val = (eval("document."+formName+"."+con+".value"));
	foc = (eval("document."+formName+"."+con+".focus()"));
	if(val==0)
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		setval =(eval("document."+formName+"."+con+".value=''"));
		foc;
		return false;
	}
	return true;
}

function IsSame(con1,con2, msg)
{
	val1 = (eval("document."+formName+"."+con1+".value"));
	foc1 = (eval("document."+formName+"."+con1+".focus()"));
	val2 = (eval("document."+formName+"."+con2+".value"));
	foc2 = (eval("document."+formName+"."+con2+".focus()"));
	if(!(IsEmpty(con1, "")))
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		foc;
		return false;
	}
	if(!IsEmpty(con2, ""))
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		foc;
		return false;
	}

	if(val1!=val2)
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		setval =(eval("document."+formName+"."+con1+".value=''"));
		setval =(eval("document."+formName+"."+con2+".value=''"));
		(eval("document."+formName+"."+con1+".focus()"));
		return false;
	}
	return true;
}

function IsEmail(con, msg)
{
	val = (eval("document."+formName+"."+con+".value"));
	foc = (eval("document."+formName+"."+con+".focus()"));
	if(!(IsEmpty(con, "")))
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		foc;
		setval =(eval("document."+formName+"."+con+".value=''"));
		return false;
	}
	var filter=/^.+@.+\..{2,3}$/
	if (filter.test(val))
		return true;
	else
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		return false;
	}
	return true;
}

function IsAlpha(con, msg)
{
	s = (eval("document."+formName+"."+con+".value"));
	foc = (eval("document."+formName+"."+con+".focus()"));
	if(!(IsEmpty(con, "")))
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		foc;
		return false;
	}
		
	var len = s.length;
	for(var i=0;i<len;i++)
	{
		if(((s.charCodeAt(i)>=65)&(s.charCodeAt(i)<=90))|((s.charCodeAt(i)>=97)&(s.charCodeAt(i)<=122))|(s.charCodeAt(i)==32))
		{
			continue;	
		}
		else
		{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
			return false;
		}
	}
	return true;
}

function IsPhone(con, msg)
{
	s = (eval("document."+formName+"."+con+".value"));
	foc = (eval("document."+formName+"."+con+".focus()"));
	var counth = 0;
	var counts = 0;
	var len = s.length;
	for(var i=0;i<len;i++)
	{
		if((s.charCodeAt(i)==45)|(s.charCodeAt(i)==32)|((s.charCodeAt(i)>=48)&(s.charCodeAt(i)<=57)))
		{
			continue;	
		}
		else
		{
		if ((msg.length)!=0)
			{
				alert(msg);
			}
			foc;
			return false;
		}
	}
	for(var i=0;i<len;i++)
	{
		if(s.charCodeAt(i)==45)
			counth = counth + 1;
		if(s.charCodeAt(i)==32)
			counth = counts + 1;
	}			
	if((counth>1)|(counts>1))
		return true;
	else
		{
		if ((msg.length)!=0)
			{
				alert(msg);
			foc;
			return false;
			}
		}
}


function NoSpaces(con, msg)
{
	s = (eval("document."+formName+"."+con+".value"));
	foc = (eval("document."+formName+"."+con+".focus()"));
	if(!(IsEmpty(con, "")))
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		foc;
		return false;
	}
		
	var len = s.length;
	for(var i=0;i<len;i++)
	{
		if(((s.charCodeAt(i)>=65)&(s.charCodeAt(i)<=90))|((s.charCodeAt(i)>=97)&(s.charCodeAt(i)<=122))|((s.charCodeAt(i)>=48)&(s.charCodeAt(i)<=57)))
		{
			continue;	
		}
		else
		{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		foc;
		return false;
		}
	}
	return true;
}


function IsDate(con, msg)
{
	s = (eval("document."+formName+"."+con+".value"));
	foc = (eval("document."+formName+"."+con+".focus()"));
	if(!(IsEmpty(con, "")))
	{
		if ((msg.length)!=0)
		{
			alert(msg);
		}
		foc;
		return false;
	}
	var pos=s.indexOf('-');
	if (pos!=-1)
	{
		var jdate=s.substring(0, pos);
		s=s.substring(pos+1, s.length);
		pos=s.indexOf('-');
		if (pos!=-1)
		{
			var jmonth=s.substring(0,pos);
			if (jmonth>12)
			{
				if ((msg.length)!=0)
				{
					alert(msg);
				}
				foc;
				return false;
			}
			s=s.substring(pos+1, s.length);
			pos=s.indexOf('-');
			if (pos!=-1)
			{
				if ((msg.length)!=0)
				{
					alert(msg);
				}
				foc;
				return false;
			}
			jyear=s;
			if(jyear<1980)
			{
				if ((msg.length)!=0)
				{
					alert(msg);
				}
				foc;
				return false;
			}			
			switch(jmonth)
			{
				case '4':
				case '6':
				case '9':
				case '11':
					nodays=30;
					break;
				case '2':
					if(jyear%4==0)
						nodays=29;
				else
					nodays=28;
					break;
				default :
					nodays=31;
			}
			if(jdate>nodays)
			{
				if ((msg.length)!=0)
				{
					alert(msg);
				}
				foc;
				return false;
			}
		return true;
		}
	}
	if ((msg.length)!=0)
	{
		alert(msg);
	}
	foc;
	return false;
}

