function emailcheck(Email)
{
	if (Email=="" || Email.indexOf ('@', 0) == -1 || Email.indexOf ('.', 0) == -1)
	{
		return false;
	}
	else
	return true;	
}
function limit_length(n,ma,t)
{  
	if(n.value.length>ma)
	{	alert("Text matter for "+ t +" cannot exceed "+ ma +" characters");
		n.focus();
		n.select();		
		return false;
	}
	else
	{return true;}
}


 function valid()
 {
	this.LTrim = VLTrim;
	this.RTrim = VRTrim;
	this.Trim =  VTrim;
	this.tarea = Vtarea	;		// a-z0-9._-
	this.alphanum = Valphanum	;		// a-z0-9._-
	this.num = Vnum	;		// a-z0-9._-
	this.numbers = Vnumbers	;
	this.name = Vname	;
	this.tempname = Vtempname	;
	this.email = Vemail;			//email
	this.phone = Vphone;			//phone
	this.tarea1 = Vtarea1	;		// a-z0-9._-
	this.tarea2 = Vtarea2	;		// a-z0-9._-  compulsory
	this.alphanum1 = Valphanum1	;	// a-z0-9._-
	
}
function Trim(S)
{
	reg=/\s/ig;
	var c=new String();
	var D = new String();
	D = S;
	var newstring=new String("");
	for (i=1; i<=D.length; i++)
	{
		c=D.charAt(i-1);
		if (c.search(reg) == "-1")
		{
			newstring=newstring.concat(c);
		}
	}
	return newstring;
}


function endTrim(S)
{
	var c=new String();
	var newstring=new String("");
	//for (i=1; i<=S.length; i++)
	//{
		c=S.charAt(1);
		if (c.search(" ") == "-1")
		{
			newstring= newstring.substr(2,newstring.length);
		}
		/*c= S.charAt(newstring.length - 1)
		if (c.search(" ") == "-1")
		{
			newstring= newstring.substr(1,newstring.length - 1);
		}*/
	//}
		return newstring;
}

function checkempty(ctrl,msg)
{
	if(eval(ctrl+".value")==0)
	{
		alert(msg);	
		eval(ctrl+".focus()");	
		return false;
	}
	else
	{
		return true;
	}
}

function checknumber(ctrl,msg)
{
	x=eval(ctrl+".value");
	if(isNaN(x))
	{
		alert(msg);	
		eval(ctrl+".select()");
		eval(ctrl+".focus()");	
		return false;
	}
	else
	{
		return true;
	}
}

//set up year
function sYear(yrf, yrt, objyear)
{
	ctr=0;
	for (var i = 0; i < objyear.length; i++)
	{
		objyear.options[0] = null;
	}
	timeC = new Date();
	currYear = timeC.getFullYear();
	for (var i=yrf,j=0; i <= yrt; i++,j++)
	{
		objyear.options[j] = new Option(i);
	}
	objyear.options[objyear.options.length-1].selected=true;
}



// function sets up the year and month controls.
function setyears(yrf,yrt,objyear,objmonth,objday)
{
 	ctr=0;
	for (var i = 0; i < objyear.length; i++)
	{
		objyear.options[0] = null;
	}
	timeC = new Date();
	currYear = timeC.getFullYear();
	for (var i=yrf,j=0; i <= yrt; i++,j++)
	{
		objyear.options[j] = new Option(i);
	}
	objyear.options[objyear.options.length-1].selected=true;
	if(objmonth.options.length>0)
	{
		objmonth.options[0] = null;	
	}
	objmonth.options[0] = new Option('January',1);
	objmonth.options[1] = new Option('February',2);
	objmonth.options[2] = new Option('March',3);
	objmonth.options[3] = new Option('April',4);
	objmonth.options[4] = new Option('May',5);
	objmonth.options[5] = new Option('June',6);
	objmonth.options[6] = new Option('July',7);
	objmonth.options[7] = new Option('August',8);
	objmonth.options[8] = new Option('September',9);
	objmonth.options[9] = new Option('October',10);
	objmonth.options[10] = new Option('November',11);
	objmonth.options[11] = new Option('December',12);
	objmonth.options[0].selected=true;
	populate(objyear,objmonth,objday);
}

function checkmail(mailid,msg)
{
	if (msg=='')
		msg="Invalid Email Address";
	if (eval(mailid+".value")=='')
	{
		alert(msg);
		eval(mailid+".focus()");
		return false;
	}
	else
	{
		flag1=0;
		flag2=0;
		stri = new String(eval(mailid+".value"));
		for(i=0;i<stri.length;i++)
		{
			if (stri.substr(i,1) =="@")
				flag1++;

			if (stri.substr(i,1) ==".")
				flag2++;

		//	if (flag1 > 0 && flag2 > 0) break;
		}
		if (flag1!=1 || flag2 != 1)
		{
			alert(msg); 
			eval(mailid+".focus()");
			return false;
		}
		else
		{
			return true;
		}
	}
	return true;
}

function checkphone(phone)
{

		stri = new String(phone);
		for(i=0;i<stri.length;i++)
		{
			flag1=0;
			num = stri.substr(i,1);
			if (num =="(" || num ==")" || num =="-" || num ==" " || (num <= "9" && num >= "0"))
				flag1 = 1;
			else
			{
				alert("Phone Number Entered is not proper!! Please add Proper Phone Number!!"); 
				eval(phone+".focus()");
				return false;			
			}

		}

		return true;
}




function isAlphabets(y,lana){	
	var x=y.value;
	var z=x.length;
  	for(i=0;i<z;i++){	
		if((x.substring(i,i+1)<'a' || x.substring(i,i+1)>'z') && ( x.substring(i,i+1)<'A' || x.substring(i,i+1)>'Z')&&( x.substring(i,i+1)!=' '))
		{
		alert("The value of "+lana+"                                                                                                                                                                                                                                                                 should be Alphabets");
		y.focus();
		y.select();
		return false;
		}
	}
	return true;
	}
function isLength(y,l,na)
	{
	x=y.value;
	if(x.length>l)
	 {
		alert("The length of "+na+" should not be greater than "+l);
		y.focus();
		y.select();
		return false;
	}
	return true;
}

function isDay(y)
{
	
	x=y.value;
	
	if(x==""||isNaN(x)==true||x>31)
	{
	 	alert("Please Fill In Day Properly");
		y.focus();
		y.select();
		return false;
	}
		return true;
}
function isYear(y)
{
		
	x=y.value;
	
	if(x==""||isNaN(x)==true || x.length>4)
	{
	 	alert("Please Fill In Year Properly");
		y.focus();
		y.select();
		return false;
	}
	return true;
}
	
function isMonth(m)
 {
	y=m.value;
	if(y.length==0 || (isNaN(y)==true) || y<1 || y>12)
	{
		alert("Please Enter Month in Proper format")
		m.focus();
		m.select();
		return false;
	}
	return true;
}
function isDate(d)
 {
	y=d.value;
	if(y.length==0 || (isNaN(y)==true) || y<1 || y>31)
	{
		alert("Please Enter Date in Proper Format")
		d.focus();
		d.select();
		return false;
	}
	return true;
}
function isMonth(m)
 {
	y=m.value;
	if(y.length==0 || (isNaN(y)==true) || y<1 || y>12)
	{
		alert("Please Enter Month in Proper format")
		m.focus();
		m.select();
		return false;
	}
	return true;
}
function isProperDate(d,m)
{
	x=d.value;
	y=m.value;
	
	var month=["","January","February","March","April","May","June","July","August","September","Octomber","November","December"];
	if(y==4 || y==6 || y== 9 || y==11)
 	 {
		if(x==31)
		 {
			alert("Please Enter Proper Date. \n "+month[y]+"  have 30 days");
			d.focus();
			d.select();
			return false;
		}
		 
	}
	 return true;
	
}

function isEmail(email1)
{
	txt=email1.value;
   if(txt!="")
    {
	if (txt.indexOf("@")<3)
	{
		alert("This Email Address Is Wrong. Please"
		+" Check the Prefix and '@' Sign.");
		email1.focus()
		email1.select()
		return false;
	}

	if ((txt.indexOf(".com")<5)&&(txt.indexOf(".org")<5)
	&&(txt.indexOf(".gov")<5)&&(txt.indexOf(".net")<5)
	&&(txt.indexOf(".mil")<5)&&(txt.indexOf(".edu")<5)
	&&(txt.indexOf(".co.in")<5)&&(txt.indexOf(".net.in")<5)
	&&(txt.indexOf(".co.uk")<5)&&(txt.indexOf(".net.uk")<5))	

	{
//		alert("This Email Address is wrong. Please"
//	/	+" Check the Suffix for Accuracy. (It should include a "
//		+".com, .edu, .net, .org,.gov,.co.in,.net.in or .mil)");
alert("Please Enter Valid Email ID")
		email1.value=""
		email1.focus()
		return false;
	}
   }
	return true;
}
function isNumber(num)
{
	result=true;
  
	for(i=0;i<num.length;i++)
	{	
		FOUND=false;
		for(digit=0;digit<10;digit++)
		{
			if(num.charAt(i)==(digit+""))
			{
				FOUND=true;
			}
		}
		if(!FOUND)
		{
			result=false;
			break;
		}
	}

	return result;
}
function isBlanks(y,name){
	var x=y.value
	if(x=="" || x.indexOf(" ")==0){
		alert("Please do not give any blank spaces in "+name)
		eval("y.focus()");
		eval("y.select()");
		return false;
	  }
	return true;
}

function isNumBlanks(y,msg){
	var x=y.value
	if(x=="" || x.indexOf(" ")==0){
		alert(msg)
		eval("y.focus()");
		eval("y.select()");
		return false;
	  }
	return true;
}	
	  
function isDecimal(y,name)
{	
	num=y.value
		result=true;
  
	for(i=0;i<num.length;i++)
	{	
		FOUND=false;
		for(digit=0;digit<10;digit++)
		{
			if(num.charAt(i)==(digit+"")||(num.charAt(i)=="."))
			{
				FOUND=true;
			}
		}
		if(!FOUND)
		{
			result=false;
			alert("Please provide Valid Numeric value for " +name)
			y.focus();
			y.select();
			break;
		}
	}

	return result;
}



function isPhone(num) //will return true if ph is in correct frmt
{
	result=true;
	filteredValues = "1234567890-";     // Characters stripped out
	for (i = 0; i < num.length; i++) 
	{
		var c = num.charAt(i);	
		if(filteredValues.indexOf(c)==-1)
		return false
	}
	return result;
}
function isYear1(y)
{
		
	x=y.value;
	
	if(isNaN(x)==true || x.length>4)
	{
	 	alert("Please Fill In Year Properly");
		y.focus();
		y.select();
		return false;
	}
	return true;
}	


function checkprice(price)
{

/**	
	if (phone=='')
	{
//		alert("Phone Number is not added!! Please Add Phone Number!!");
		return false;
	}
	else
	{
*/		
		stri = new String(price);
		for(i=0;i<stri.length;i++)
		{
			flag1=0;
			num = stri.substr(i,1);
			if (num =="." || (num <= "9" && num >= "0"))
				flag1 = 1;
			else
			{
//				alert("Price Entered is not proper!! Please add Proper Price!!"); 
				return false;			
			}

		//	if (flag1 > 0 && flag2 > 0) break;
		}

/**		if (flag1==0 || flag2 == 0)
		{
			alert("Email Address Entered is not proper!! Please add Proper Email Address!!"); 
			return false;
		}
		else
		{
			if(flag1>1)
			{
				alert("Email Address Entered is not proper!! Please add Proper Email Address!!");
				return false;
			}
		}
*/		return true;
}