


	function ChkEmpty(fld,Name)
	{
		if  ( !isNotEmpty( fld.value, Name ))
		{	return false
		}
		
	}
		
	function ChkFld( fld,Name,Type,Blank)
	{   	
		if (Blank == "B")
		{
			if  ( !isNotEmpty( fld.value, Name ))
			{	
				return false
			}
		}
		if (Type == "A") //Alphabets
		{
		  return !isNotAlphabets(fld.value,Name)
		}	
		else 
		{	if	(Type == "N") //Numeric
			{	return !isNotNumeric(fld.value,Name)
			}
			else
			{	if	(Type == "X") // AlphaNumeric
				{
					return !isNotAlphNumeric(fld.value,Name)
				}
				else
				{	if	(Type == "L") // Login Name Field
					{
						
						return !isNotLogin(fld.value)
					}
					else
					{
						if	(Type == "D")
						{
							return !isDate(fld.value)
						}
						else
						if	(Type == "E")
						{
							return !isNotEmailId(fld.value)
						}

							
					}
			 }
		  }	 	
		}
		return true			 
	}

function isNotEmpty(field, name)
	{
		if (field =="")
		{
			alert("Please enter the " + name + ".");
			return false;
		}
		
		for (var i=0;i < field.length;i++)
		{
			if (field.substring(i,i+1) != " ")
			{
			  return true
			}
		}
		alert("The " + name + " field is empty. Please enter the " + name + "." );
		return false
	}


function isNotAlphabets(str, Name)
{
	for (var i = 0; i < str.length; i++)
	{
		var ch = str.substring(i, i + 1);
		if((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch) && (ch !=' '))
		{
			alert("This " + Name + " accepts only Alphabets.\n\nPlease re-enter " + Name + ".");
			return true;
		}
	}
	return false;
}


function isNotNumeric(str, Name)
{
	for (var i = 0; i < str.length; i++)
	{
		var ch = str.substring(i, i + 1);
		if((ch < "0" || ch > "9") && (ch !="-") && (ch !=' ')&& (ch !='.')) 
		{
			alert("The " + Name + " accepts only numeric value.Please re-enter the " + Name + ".");
			return true;
		}
	}
	return false;
}

function isNotAlphNumeric(str, Name)
{
	
	for (var i = 0; i < str.length; i++)
	{
		var ch = str.substring(i, i + 1);
		if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != ' ') && (ch != '-') &&  (ch != '@') && (ch != '.') && (ch != ' ') && (ch != "'"))
		{
			alert("The " + Name + " only accepts letters,numbers & underscore.Please re-enter the " + Name + ".");
			return true;
		}
	}

	
	
	
	return false;
}
		
function isNotLogin(str)
{
	var ch = str.substring(0,1 );
	if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))  && (ch != '_')) 
	{
		alert("First character of the  field  must be letters or underscore.\n\nPlease re-enter ");
		return true;
	}
	
	return isNotAlphNumeric(str)
}
function isNotEmailId(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var ch = str.substring(0,1 );
		
		/*if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))  && (ch != '_')) 
		{
			alert("First character of the  field  must be letters or underscore.\n\nPlease re-enter ");
			return true;
		}*/
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return true;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		  return true;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr-1){
		    alert("Invalid E-mail ID")
		    return true;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return true;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return true;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return true;
		 }

		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return true
		 }

		 return false;
	}
	/*
function isNotEmailId(str)
{
	var ch = str.substring(0,1 );
	if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch))  && (ch != '_')) 
	{
		alert("First character of the  field  must be letters or underscore.\n\nPlease re-enter ");
		return true;
	}
	
	if ( !isNotAlphNumeric(str) )
	{	
		var flag
		flag = true
		for (var i=0;i < str.length;i++)
		{	if (str.substring(i,i+1) == "@")
			{ 	flag = false
				break
			}
		}
		if ( flag )
		{	alert("Invalid Email. Please re-enter in 'abcd@xyz.com' format ");
			return true
		}	
		
		return false
	}	
	return true
}

*/

function isDate( dd , mm  , yy)
{
		var yy,mm,dd;
		var im,id,iy;
		var present_date = new Date();
		Curyy = 1900 + present_date.getYear();
		Curmm = present_date.getMonth();
		Curdd = present_date.getDate();
		
		if (is_greater_date(yy,mm,dd,Curyy,Curmm,Curdd) && is_valid_day(mm,dd,yy))
		{
	        return true; 
		}
		return false;
	}


//Checking for Valid Date

function is_valid_day(dd,mm,yy)
{
	if ((yy % 4) == 0) 
	{ 
		var days_in_month = "312931303130313130313031";
	 } 
	else 
	{ 
		var days_in_month = "312831303130313130313031";
	 } 
	var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	if (mm != -1)
	{
		if (dd > days_in_month.substring(2*mm,2*mm+2))
		{
			alert ("The date field is entered wrongly (the day field value 	exceeds the number of days for the month entered).");
			return false;
		}
	}
	return true;
}

function is_greater_date(yy,mm,dd,yy1,mm1,dd1)
{
	if (yy > yy1)
	{
		alert("The month field is entered incorrectly. The year entered exceeds the current year.");
		return false;
	}
	if (yy == yy1)
	{
		if (mm > mm1)
		{
			alert("The month field is entered incorrectly.");
			return false;
		}
		if (mm == mm1)
		{
			if (dd > dd1)
			{
			  alert("The day field is entered incorrectly.");
			   return false;
			}
		}
	}
	return true;
}


	function Validate(frm)
	{   	
		if ( !ChkFld( frm.cname,"Name","A","B" ) )	
		{	frm.cname.focus() 
			return false		
		}
		if ( !ChkFld( frm.comname,"Company Name","","B" ) )	
		{	frm.comname.focus() 
			return false		
		}
		if ( !ChkFld( frm.email,"Email Id","E","B" ) )	
		{	frm.email.focus() 
			return false		
		}
		if ( !ChkFld( frm.addr,"Address","","B" ) )	
		{	frm.addr.focus() 
			return false		
		}
		if ( !ChkFld( frm.country,"Country","A","B" ) )	
		{	frm.country.focus() 
			return false		
		}	
		if( !ChkFld(frm.phno,"Phone Number","N","B"))	
		{	frm.phno.focus() 
			return false		
		}
		if ( !ChkFld( frm.qry,"Nature of Enquiry","A","B" ) )	
		{	frm.qry.focus() 
			return false		
		}
		if ( !ChkFld( frm.msg,"Message","","B" ) )	
		{	frm.msg.focus() 
			return false		
		}
		if ( !ChkFld( frm.vercode,"Code","","B" ) )	
		{	frm.vercode.focus() 
			return false		
		}
		
   		
		return true
	}



