//var bgBad = "BLUE";
var bgBad = "#cccc99";
  var bgGood = "white";

function setColor(el, bg) 
{ 
 if (el.style) el.style.backgroundColor = bg;
}
function vweb(abc,com,opt)

{
if (opt == 0 && abc.value=="")
{
setColor(abc, bgGood);
 return true;
}
if  (abc.value.indexOf(".") < 1)
		{
		alert("Please enter Valid  Value For " +com+"");
	abc.focus();
		//abc.select();
		//setColor(abc, bgBad);
		return false;
		}
		else
{
		return true;
}
}


function vcheck(Item, Value, Name)
{
var a=0;
		for(var j=0;j<Item.length;j++)
		{
			if(Item[j].checked == true ){
				a = parseInt(a) + 1;
	  	}	
		}
		if (a<Value)
		alert("Minimum of "+ Value+" values should selected from "+ Name);
		else
		return true;
}

function vtel(abc,com,opt)
{
if (opt == 0 && abc.value=="")
{
setColor(abc, bgGood);
 return true;
}
if (opt == 1 && abc.value=="")
{
alert("Please Enter Value For " +com+ "Field");
abc.select();
setColor(abc, bgBad);
return (false);
} 
 	  if (abc.value != "")
		  {

			  if (abc.value.length < 4)
			  {
			    alert("Please enter at Least 5 digits  in \""+ com+ "\" field.");
			abc.focus();
			abc.select();
			setColor(abc, bgBad);
		                return (false);
			  }
		  var checkprice= "1234567890\-() .";
		  var price1 = abc.value;
		  var pricevalid = true;
		
		  for (i = 0;  i < price1.length;  i++)
			  {
			    ch = price1.charAt(i);
			    for (j = 0;  j < checkprice.length;  j++)
				      if (ch == checkprice.charAt(j))
				        	break;
					    if (j == checkprice.length)
					    {
					      pricevalid = false;
					      break;
					   }
			 }
		
				
			  if (!pricevalid)
				 {
				    alert("Please enter valid  \""+ com +"\" field.");
					//abc.value = "" ;
					    abc.focus();
					setColor(abc, bgBad);
				    return (false);

				  }
			else
				{

			setColor(abc, bgGood);
			return (true);
				}
			  
		}

}
//


function vname(abc,len,com,opt,strcrt)
{

var checkOK;
var mess;
if (opt == 0 && abc.value=="")
{

setColor(abc, bgGood);
 return true;
}
if (strcrt=="na")
{
 checkOK = " AB'CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz. \r\n\f";
mess  = "Please enter only letter and whitespace characters in the \""+com+"\" field."
}

if (strcrt=="ad")
{
 checkOK = " AB'CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz. ~!@#$%^&\*()\_+\|\?\>\/<\:{}][\'\;\/..-,#@$,. & 1234567890()[]\r\n\f-" + '"' ;
mess  = "Please enter only letter , whitespace  , and Address characters  in the \""+com+"\" field."
}




if (strcrt=="str")
{
 checkOK = "AB'CDEFG1234567890HIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \r\n\f@$&";
mess = "Please enter only letter and Numeric Characters in the \""+com+"\" field."
}
if (strcrt=="com")
{
 checkOK = "AB'CD1234567890~!@#$%^&\*()\_+\|\?\>\/<\:{}][\'\;\/..-,EFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \/ \\\/\r\n\f"+'"';
mess = "Please Enter Characters Which Are Allowed in Key Board \""+com+"\" field."
}
//else
//{
//checkOK = "AB'CD1234567890~!@#$%^&*()_+|?><:{}][';/.,EFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \r\n\f"+'"';
//mess = "Please Enter Characters Which Are Allowed in Key Board \""+com+"\" field."
//}


//alert(checkOK);


checkOK = " AB'CDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz. ~!@#$%^&\*()\_+\|\?\>\/<\:{}][\'\;\/..-,#@$,. & 1234567890()[]\r\n\f-" + '"' ;
mess = "Please enter only letter and Numeric Characters in the \""+com+"\" field."

if (abc.value == "")
	  {
		    alert("Please enter a value for the \""+com+" \" field.");
abc.select();
setColor(abc, bgBad);
		    abc.focus();
		    return (false);
	  }

  if (abc.value.length < 1)
	  {
		    alert("Please enter at least 1 characters in the \""+com+"\" field.");
		    abc.focus();
setColor(abc, bgBad);
abc.select();
		    return (false);
	  }

  if (abc.value.length > len)
	  {
		    alert("Please enter at most "+len+" characters in the \""+com+"\" field.");
		    abc.focus();
abc.select();
setColor(abc, bgBad);
		    return (false);
	  }
	  
		
		  var checkStr = abc.value;
		  var allValid = true;
		  for (i = 0;  i < checkStr.length;  i++)
			  {
			    ch = checkStr.charAt(i);
			    for (j = 0;  j < checkOK.length;  j++)
				      if (ch == checkOK.charAt(j))
				        break;
					    if (j == checkOK.length)
						    {
						      allValid = false;
     						      break;
						    }
			  }
		  if (!allValid)
			  {
			    alert(mess);
			    abc.focus();
abc.select();
setColor(abc, bgBad);

			    return (false);
			  }
else 
{
setColor(abc, bgGood);
return true;
}

}

function vindex(abc,com,opt)
{
if (opt==0 && abc.selectedIndex < 1)
{ 
 return true;
}
	 if (abc.selectedIndex < 1)
			  {
			    alert("Please select one of the \""+ com +"\" options.");
			    abc.focus();
			    return (false);
			  }
	else{


	return true;
		}
}


var maxi;
//dec  0 means decimal not allowed 
//dec other than 0 means decimal allowed 

function val(abc,max,com,opt)
{

if (abc.value=="" && opt==0) 
{
setColor(abc, bgGood);
return true;	
}

if (isNaN(abc.value))
	{
	alert("Please Enter Valid value in " +com+" field.");
abc.select();
setColor(abc, bgBad);
	abc.focus();
	return false;
	}

if (abc.value <= 0)
	{
	alert("Please Enter Valid Value in " +com+" field.");
abc.select();
setColor(abc, bgBad);
	abc.focus();
	return false;
	}



if (abc.value > max)
{
alert( "Please enter Maximum of "+max+" in "+com+" field.");
abc.focus();
abc.select();
setColor(abc, bgBad);
return (false);
}
else
setColor(abc, bgGood);
return true
}

 
function vno(abc,maxi,com,opt)
{
if (abc.value=="" && opt==0) 
{
setColor(abc, bgGood);
return true;	
}
var checkprice= "1234567890.";
if (abc.value == "")
			  {
			    alert("Please enter a Valid value In \""+com+"\" field.");
			    abc.focus();
abc.select();
setColor(abc, bgBad);

			    return (false);
			  }
			  if (parseInt(abc.value) > maxi )
			  {
			    alert("Please enter valid value In \""+com+"\" field.");

abc.select();
setColor(abc, bgBad);
			    abc.focus();
			    return (false);
			  }
		
		  var price1 = abc.value;
		  var pricevalid = true;
		
			  for (i = 0;  i < price1.length;  i++)
			  {
			    ch = price1.charAt(i);
			    for (j = 0;  j < checkprice.length;  j++)
				      if (ch == checkprice.charAt(j))
				        	break;
					    if (j == checkprice.length)
					    {
					      pricevalid = false;
					      break;
					   }
			 }
		
				
			  if (!pricevalid)
				 {
				    alert("Please enter valid  \""+com+"\" field.");
				    abc.value = "" ;

abc.select();
setColor(abc, bgBad);
				    abc.focus();
				    return (false);
				  }


else
{
setColor(abc, bgGood);
return (true);
}
}
//


function vemail(emailad,com,opt)
 {
var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
var check=/@[\w\-]+\./;
var checkend=/\.[a-zA-Z]{2,3}$/;

if (emailad.value=="" && opt==0) 
{
setColor(emailad, bgGood);
return true;
}
 if(((emailad.value.search(exclude) != -1)||(emailad.value.search(check)) == -1)||(emailad.value.search(checkend) == -1)){
		alert("Please check Value for .."+ com +" Field");
	setColor(emailad, bgBad);
emailad.select();
	return false;
	}
	else {

setColor(emailad, bgGood);
return true;
	}
}

//



function vemail2(abc,com,opt)
{
if (abc.value=="" && opt==0) 
{
setColor(abc, bgGood);
return true;
}
		  if (abc.value == "")
			  {
			    alert("Please enter a value for the \""+com+"\" field'.");
			  abc.focus();
abc.select();
setColor(abc, bgBad);

			    return (false);
			  }

		  var checkMail= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_1234567890@.";
		  var checkId = abc.value;
		  var allValid1 = true;
		  for (i = 0;  i < checkId.length;  i++)
			  {
			    ch = checkId.charAt(i);
			    for (j = 0;  j < checkMail.length;  j++)
				      if (ch == checkMail.charAt(j))
				        	break;
					    if (j == checkMail.length)
					    {
					      allValid1 = false;
					      break;
					   }
			 }
		// Check for @ exists or not 
		  for (i = 0;  i < checkId.length;  i++)
			  {
				
			    ch = checkId.charAt(i);
				      if (ch == "@" )
				        	{ 
					allValid1 = true;
					break;
					}
				     else 
					{
					   allValid1 = false;
					} 

			 }


		// Check for  . exists or not 
		  for (i = 0;  i < checkId.length;  i++)
			  {
				
			    ch = checkId.charAt(i);
				      if ( ch == "." )
				        	{ 
					allValid1 = true;
					break;
					}
				     else 
					{
					   allValid1 = false;
					} 

			 }


		
			  if (!allValid1)
				 {
				    alert("Please enter valid  \""+com+"\" field.");
abc.select();
setColor(abc, bgBad);
				    abc.focus();
				    return (false);
				  }
			  
else
{
setColor(abc, bgGood);
return (true);
}

}

function vzip(abc,opt,com)
{

if (abc.value=="" && opt==0)
{

setColor(abc, bgGood);
 return true;	
}

  if (abc.value == "")
			  {
			    alert("Please enter a valid 5 digit  in \"zip\" field.");
abc.select();
setColor(abc, bgBad);

			    abc.focus();
			    return (false);
			  }
			  if (abc.value.length != 5)
			  {
			    alert("Please enter valid 5 digits  in \"zip\" field.");
abc.select();
setColor(abc, bgBad);

			    abc.focus();
			    return (false);
			  }
		  var checkprice= "1234567890";
		  var price1 = abc.value;
		  var pricevalid = true;
		
		  for (i = 0;  i < price1.length;  i++)
			  {
			    ch = price1.charAt(i);
			    for (j = 0;  j < checkprice.length;  j++)
				      if (ch == checkprice.charAt(j))
				        	break;
					    if (j == checkprice.length)
					    {
					      pricevalid = false;
					      break;
					   }
			 }
		
				
			  if (!pricevalid)
				 {
				    alert("Please enter valid Value For   "+com+"  field.");
				    abc.value = "" ;

abc.select();
setColor(abc, bgBad);
				    abc.focus();
				    return (false);
				  }


else{
return (true);

setColor(abc, bgGood);
}
}
function vandex(abc,ab,com,opt,tex)

{

if (opt==0 && abc.selectedIndex < 1)
{

  return true;
}
	 if ((abc.value == tex)&&(ab.value ==""))
			  {
			    alert(com);
			    abc.focus();
			    return (false);
			  }
	else{


	return true;
		}
}


function selectOption(Group, Value){
	for (var i=0;i<Group.length;i++){
		if (Group.options[i].value == Value) {
			Group.selectedIndex == Group[i].index;
			Group[i].selected = true;			
			break;
		}
	}
}