var ie = document.all?true:false;
var ns = document.layers?true:false;




//Only numbers are allowed
function addresschk(x){	
	var num=/[a-zA-Z0-9.,/\;\-\"'"\s]+/;
	numflag=x.value.match(num);	
	if(numflag != x.value){
		alert("Please Enter Valid Address")
		x.focus();
 		x.select();
		return false;
	}
	return true;
}



//when blank field is not allowed
function blankchk(x,y){	
	if (x.value=="" || x.value== null){
		alert("Please enter "+y);
		x.focus();
		return false;
	}
	return true;
}


function phonechk(x){
var ph=/[0-9\#\+\(\)\-\s]+/;
var phflag=x.value.match(ph);	
		if(phflag != x.value){
			alert("Please enter valid phone numbers only");
			x.focus();
	 		x.select();
			return false;
		}
	return true;
}

function blankfield(x)
{
	
	//alert(x.value);
	var sValue = (x.value) ;
	if (sValue=="" )
	{
		
		x.focus();
		return false;
	}
	return true;
}

function dropdownselect(x)
{
	if(x.selectedIndex==0){
		x.focus();
		//x.options[0].focus();
		return false;
	}
	return true;
}
function alphanumchk(x){	
	var num=/[a-zA-Z 0-9]+/;
	numflag=x.value.match(num);	
		if(numflag != x.value){
			alert("Please enter numbers and alphabets only");
			x.focus();
	 		x.select();
			return false;
		}
	return true;
}
//Only numbers are allowed
function numchk(x){	
	var num=/[0-9]+/;
	numflag=x.value.match(num);	
		if(numflag != x.value){
			alert("Please enter numbers only");
			x.focus();
	 		x.select();
			return false;
		}
	return true;
}

//Email validation
function emailchk(x){
	var email =/[-a-zA-Z0-9_\.]+@[-a-zA-Z0-9]+\.[-a-zA-Z0-9\.]+/;
	var eflag = x.value.match(email);
	if(eflag!=x.value){
		alert("Please enter a valid Email.");
		x.focus();
		x.select();
		return false;
	}
	return true;
}




//Only alphabets are allowed
function alphachk(x){
	
	var alpha=/[a-zA-Z]+/;
	 var alphaflag=x.value.match(alpha);	
	if(alphaflag != x.value){
		alert("Please enter alphabets only.");
		x.focus();
 		x.select();
		return false;
	}
	return true;
}	


//First element of dropdown cannot be selected
function dropdownchk(x){
	if(x.options[0].selected==true){
		alert("Please select one option from  "+x.name);
		x.options[0].focus();
		return false;
	}
	return true;
}


//Validation where only Alphabets and space is allowed.
function alphaspchk(x){
	var sp=/[a-zA-Z\s]+/;
	alpflag=x.value.match(sp);	
	if(alpflag != x.value){
		alert("Enter Your Complete Name ")
		x.focus();
 		x.select();
		return false;
	}
	return true;
}

function validate(d_dd,d_mm,d_yy)
{
	
	if(d_dd!=null)
	{
		if((d_dd.selectedIndex==0)||(d_mm.selectedIndex==0)||(d_yy.selectedIndex==0))
		{
			alert("Select Appropriate Date date");return false;
		}
		
		if(!validdate(d_dd.value,d_mm.value,d_yy.value))
		{
			d_dd.focus();
			return false;
		}
	}
	return true;
}	
function validdate(dd,mm,yy)
{
	 if  (((yy % 4 == 0) && (yy % 100 != 0)) || (yy % 400 == 0))
	  {
		  if(mm == 2)
	  	{
				if(dd > 29)
				{
					alert("This is a Leap Year, Select a date upto 29th.");
					return false;
				}
			}
		}
	 else
	  {
			if(mm == 2)
			{
				if(dd > 28)
				{
					alert("Select a date upto 28th for the month of February");
					return false;
				}
			}
	  }
		if(mm == 4 || mm == 6 || mm == 9 || mm == 11)
		{
			if(dd > 30)
			{
				alert("Select date upto 30th for this Month")
				return false;
			}
		}
	return true;	
}
