function IsZip(strString,extraChar)
{
	
   var strValidChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ- ";
   strValidChars=strValidChars+extraChar;
   var strChar;
   var blnResult = true;
   if ((strString.length == 0) || (strString.length > 7) || (strString.length < 5)) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1) blnResult = false;
      }
   return blnResult;
}
/*##########################################################################
				Function for Email Validation
				Arguments : 1. email string
				Returns   : True / False
###########################################################################*/


/*
function emailCheck(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if ( (str.indexOf(dot))==(lstr-1) ) return false;
	if (str.indexOf(at)==-1) return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
	return true;
}
*/
 function emailCheck(objForm) 
 {
	
   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
   var address = objForm.value;
   if(reg.test(address) == false)
   {
      //alert('Invalid Email Address');
      return false;
   }
  }




/*##########################################################################
					Function for Text Box Empty validation
					Arguments : 1. Text Box Object
								2. Message to display
					Returns   : True / False
###########################################################################*/

function emptyvalidation(entered, alertbox)
{
	with (entered)
	{
		while (value.charAt(0) == ' ')
			value = value.substring(1);
		while (value.charAt(value.length - 1) == ' ')
			value = value.substring(0, value.length - 1);
		if (value==null || value=="")
		{
			if (alertbox!="") alert(alertbox);
			return false;
		}
		else return true;
	}
}


/*##########################################################################
					Function Numeric Validation
					Arguments : 1. Numeric value
								2. Extra alpha-Characters to pass
					Returns   : True / False
###########################################################################*/

function IsNumeric(strString,extraChar)
{
   var strValidChars = "0123456789";
   strValidChars=strValidChars+extraChar;
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1) blnResult = false;
      }
   return blnResult;
}


/*##########################################################################
			Function for Collect value from multiple select Field
				Arguments : 1. Multiple Select Field Object
				Returns   : Coma Seperated Values
###########################################################################*/

function SelectAllList(listObject)
{
	var allvalues="";
	for(var i = 0;i < listObject.length;i++)
		if (listObject.options[i].selected==true)
			allvalues+=listObject.options[i].value + ','; 
	if(allvalues!="")
		allvalues=allvalues.substring(0, allvalues.length - 1);
	return allvalues;
}


/*##########################################################################
	Function to count the number of selections from multiple select Field
				Arguments : 1. Multiple Select Field Object
				Returns   : Selected Count
###########################################################################*/

function SelectAllCount(listObject)
{
	var count=0;
	for(var i = 0;i < listObject.length;i++)
		if (listObject.options[i].selected==true)
			count++;
	return count;
}


/*##########################################################################
				Function for check values in select list
   			 		Arguments : 1. Select Field
					Returns   : True / False
###########################################################################*/

function checkSelect(strObj,nameObj)
{
	if(strObj.selectedIndex=="0"){
		alert("Select one '"+ nameObj+"'");
		strObj.focus();	
		return false;
	}
}


/*##############################################################################################################
	Function for selecting all the check-boxes on click one check box
   			 		Arguments : 1. check box array object
								2. select-all check box object
					Returns   : Checks / Unchecks all check boxes
function call : <input type="checkbox" name="selectall" value="0" onclick="allchecked(document.frm.del,this);" />
#################################################################################################################*/

function allchecked(list,checkall)
{
	if(!list.length)
	{
		if(list.value!='')
		{
			if(checkall.checked==true)
				list.checked=true;
			else
				list.checked=false;
		}
	}
	for(i=0;i < list.length;i++)
	{
		if(checkall.checked==true)
			list[i].checked=true;
		else
			list[i].checked=false;
	}
}


/*###########################################################################
	Function for getting the values of all the checked check-boxes
	 		Arguments : 1. check box array object
			Returns   : Coma Seperated Values
############################################################################*/

function checkedValues(list)
{
	var allvalues="";
	for(var i=0;i < list.length;i++)
		if(list[i].checked==true)
			allvalues+=list[i].value + ','; 
	if(allvalues!="")
		allvalues=allvalues.substring(0, allvalues.length - 1);
	return allvalues;		
}


/*##############################################################################################################
	Function for getting the count of the checked check-boxes
   			 		Arguments : 1. check box array object
					Returns   : Count of checked check boxes
#################################################################################################################*/

function checkedCount(list)
{
	var checkedCount=0;
	for(var i=0;i < list.length;i++)
		if(list[i].checked==true)
			checkedCount++;
	return checkedCount;		
}


/*##############################################################################################################
			Function for checking special Characters in string
   			 		Arguments : 1. Text box object
								2. Text box Name
								3. Extra Charectors to check
					Returns   : True / False
#################################################################################################################*/

function checkString(strObj,nameObj,extChar)
{
	strValue=strObj.value;
	var invChar = "`~!#$%^/\?*()=+{[}];:',";
	invChar=invChar+extChar;
	len=strValue.length;
	for(i=0;i<len;i++)
		if(invChar.indexOf(strValue.charAt(i))!=-1){
			alert("The character "+strValue.charAt(i)+" is not allowed in "+nameObj);
			strObj.select();
			strObj.focus();
			return false;
		}
	return true;		
}
function checkNum(strString)
{
	var strValidChars = "0123456789- ";
   var strChar;
   var blnResult = true;
   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         	{
        	 blnResult = false;
         	}
      }
   return blnResult;	
}

/*##############################################################################################################
			Function for validating password and confirm password
   			 		Arguments : 1. Password Object
								2. Confirm Password Object
					Returns   : True / False
#################################################################################################################*/

function confirmPwd(pwd,confPwd)
{
	var passLen = pwd.value.length;
	if((passLen>=3)&&(passLen<12))
	{
		if(pwd.value==confPwd.value)
			return true;
		else		
		{
			alert("Password re-typed does not match");				
			confPwd.value="";
			pwd.focus();
			return false;
		}
	}
	else
	{
		alert("password must be atleast of 6 charecters and not more than 12")
		confPwd.value="";
		pwd.value="";
		pwd.focus();
		return false;
	}
	return true;
}



/*###########################################################################
							Validate 
#############################################################################*/

/*##########################################################################
                            FUNCTION CALLS
############################################################################
function formvalidation(thisform)
{
	with (thisform)
	{
		if (emptyvalidation(name,"Please Enter the Name")==false) 
		{
			name.select();
			name.focus();
			return false;
		}
		
		if(checkString(name,"First Name","")==false) return false;
		
		if(confirmPwd(pwd,confPwd)==false) return false;
		
		if(emailCheck(email.value)==false)
		{
			alert("Invalid E-mail ID");
			email.select();
			email.focus();
			return false;
		}
		
		if(IsNumeric(phone1.value," -")==false)
		{
			alert("Please enter a valid phone number");
			phone1.select();
			phone1.focus();
			return false;
		}
		if (checkSelect(patState,"State")==false)
			return false;
		
		allregion.value=SelectAllList(sregion);
		countregion.value=SelectAllCount(sregion);
		allcheckVal.value=checkedValues(list);
		countCheck.value=checkedCount(list);
	}
	
	return true;
}*/