
var errMsg_emp="Please provide "
var errMsg_inv="Please provide valid "

var VALIDATE_EMAIL= "^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
var VALIDATE_NAME= "abcdefghijklmnopqrstuvwxyz' "
var VALIDATE_ALPHA= "abcdefghijklmnopqrstuvwxyz"
var VALIDATE_CNAME= "abcdefghijklmnopqrstuvwxyz1234567890#&()./,'- " 
var VALIDATE_SALUTN= "abcdefghijklmnopqrstuvwxyz. "
var VALIDATE_CNAME1= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.() "
var VALIDATE_ADDR= "abcdefghijklmnopqrstuvwxyz1234567890&[],./-'()\n\r "
var VALIDATE_INTPIN="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234568790 "
var VALIDATE_ANUM="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234568790"
var VALIDATE_NUM="1234568790"
var VALIDATE_STATE= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890. "

/*
function chkBlank(ele,elenm,frm,defval)
{
	if(frm.ele.type.toLowerCase()=='text' || frm.ele.type.toLowerCase()=='textarea')
	{
		if(trim(frm.ele.value)=='' || trim(frm.ele.value)==defval)
			{
				alert(errMsg_emp+elenm);
				frm.ele.focus();
				return false;
			}		
	}
	if(frm.ele.type.toLowerCase()=='select-one')
	{
		if(frm.ele.selectedIndex==0)
			{
				alert(errMsg_emp+elenm);
				frm.ele.focus();
				return false;
			}		
	}
}*/

function isValidDate(day,month,year){	
/*
Purpose: return true if the date is valid, false otherwise

Arguments: day integer representing day of month
month integer representing month of year
year integer representing year

Variables: dteDate - date object

*/
var dteDate;

//set up a Date object based on the day, month and year arguments
//javascript months start at 0 (0-11 instead of 1-12)
dteDate=new Date(year,month,day);

/*
Javascript Dates are a little too forgiving and will change the date to a reasonable guess if it's invalid. We'll use this to our advantage by creating the date object and then comparing it to the details we put it. If the Date object is different, then it must have been an invalid date to start with...
*/

return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
}

///////compare dates
function CompareDates(dt1,dt2)
{
   var str1  = dt1.split("/");
   var str2  = dt2.split("/");
   
   
  /* var dt1   = parseInt(str1.substring(0,2),10);
   var mon1  = parseInt(str1.substring(3,5),10);
   var yr1   = parseInt(str1.substring(6,10),10);
   var dt2   = parseInt(str2.substring(0,2),10);
   var mon2  = parseInt(str2.substring(3,5),10);
   var yr2   = parseInt(str2.substring(6,10),10);*/
   var date1 = new Date(str1[2], parseInt(str1[0],10)-1, str1[1]);
   var date2 = new Date(str2[2], parseInt(str2[0],10)-1, str2[1]);

   if(date2 > date1)
   {     
      return true;
   }
   else
   {
     return false;
   }
} 
///////////////
function numberValidate(incomingString, defaultValue)
	{
		if(trimSpace(incomingString).length == 0 || incomingString.search(/[^0-9\.]/g) != -1 || incomingString==defaultValue || parseInt(incomingString, 10) <= 0 )
		{
			return false;
		}
		else
			return true;	
	}
/////////////////////	
function chkinput(val,chklst)
{
	 //var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	var checkOK =chklst ;
	var checkStr = val;
	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)
	  {	
		return false;
		//obj.value=obj.value.substring(0,(checkStr.length));
	  }
}

function V(arg)
{
	return(document.getElementById(arg).value)	
}

function getCheckedButton(group,form) {
if (typeof group == 'string') group = form.elements[group];
for (var i = 0, n = group.length; i < n; ++i)
if (group[i].checked) return group[i];
return null;
}

function chkchar(obj,chklst)
{
	 var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	var checkOK =chklst ;
	var checkStr = obj.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)
	  {	
		obj.value=obj.value.substring(0,(checkStr.length)-1);
	  }
}

///////////get rid of all spaces////////////
function trimSpace(x)
{
	if(x!='')
	{
		var emptySpace = / /g;
		var trimAfter = x.replace(emptySpace,"");
	}
	return(trimAfter);
}	
//////get rid of leading & lagging spaces//////
function trim(strText) { 
    // get rid of leading spaces 
	if(strText!='')
	{
			while (strText.substring(0,1) == ' ') 
				strText = strText.substring(1, strText.length);
		
			// get rid of trailing spaces 
			while (strText.substring(strText.length-1,strText.length) == ' ')
				strText = strText.substring(0, strText.length-1);
	}
   return strText;
   
}

////allow only characters///////
function charonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
	//alert(unicode)
	if (unicode!=8)
		{
			if ((unicode!=32 && (unicode<65 || (unicode>90 && (unicode<97 || unicode>122)))) && unicode!=39 && unicode!=45 && unicode!=13 && unicode!=15 &&   unicode!=39 && unicode!=14 && unicode!=9  )
			return false
		}
}
function ismaxlength(obj){
var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
if (obj.getAttribute && obj.value.length>mlength)
obj.value=obj.value.substring(0,mlength)
}
/////
function txtlim(obj,limit){
	var mlength=parseInt(limit);
	if (obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}
/////////////address field validation//////////
function chkaddr(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8)
		{
		if ((unicode!=32 && (unicode<65 || (unicode>90 && (unicode<97 || unicode>122)))) && unicode!=39 && unicode!=44 && unicode!=9 && unicode!=45 && unicode!=46 && unicode!=13 && unicode!=15 && unicode!=14 && unicode!=47 && unicode!=38 && unicode!=40 && unicode!=41 && ((unicode<48||unicode>57)&& unicode!=9))
				return false
		}
}
//////////////
function numbersonly(e)
{
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8)
		{
			if ((unicode<48||unicode>57)&& unicode!=9 && unicode!=13 && unicode!=15 && unicode!=14 )
			return false
		}
}
////////////allow only these characters-> abcdefghijklmnopqrstuvwxyz1234567890#&()./,'-
function alphanumeric(e)
	{
		var unicode=e.charCode? e.charCode : e.keyCode
		if (unicode!=8 && unicode!=13)
		{		
			if ((unicode>64 && unicode<91) || (unicode>96 && unicode<123) || (unicode>47 && unicode<58) || (unicode==9) || (unicode==32) || (unicode>43 && unicode<48)|| (unicode>38 && unicode<42) || (unicode==35) || (unicode==38) && unicode!=13 && unicode!=15 && unicode!=14 ) 
			return true;
			else
			return false;
		}
	}
	
////////////allow only these characters-> abcdefghijklmnopqrstuvwxyz1234567890
function alphanumerics(e)
	{
		var unicode=e.charCode? e.charCode : e.keyCode;
		//alert(unicode)
		if (unicode!=8 && unicode!=13 && unicode!=13 && unicode!=15 && unicode!=14)
		{		
			if ((unicode>64 && unicode<91) || (unicode>96 && unicode<123) || (unicode>47 && unicode<58) || (unicode==9) || (unicode==32) )
			return true;
			else
			return false;
		}
	}
///////////check for valid email format//////////////
function emailValidate(incomingString, defaultValue)
{
	if(trimSpace(incomingString).length == 0 || incomingString.search(/^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/g) == -1 || incomingString==defaultValue)
	{
		return false;
	}
	else
		return true;	
}	
////////////////////
function resetfrm(frm)
 {
 var oForm=frm;
	var iCounter=0	
	var sFldname,sFldType
	var iLength
	iLength=oForm.elements.length	
	while(iCounter<iLength)
	{		
		sFldType=oForm.elements[iCounter].type;
		sFldname=oForm.elements[iCounter].name;
		if (sFldType.toLowerCase() == "text")
			{
				oForm.elements[iCounter].value='';
			}
		if (sFldType.toLowerCase() == "select-one")
			{			
				oForm.elements[iCounter].options[0].selected=true
			}
		if (sFldType.toLowerCase() == "textarea")
			{			
				oForm.elements[iCounter].value='';
			}
		if (sFldType.toLowerCase() == "textarea")
			{			
				oForm.elements[iCounter].value='';
			}	
		if (sFldType.toLowerCase() == "checkbox" || sFldType.toLowerCase() == "radio")
			{			
				oForm.elements[iCounter].checked=false;
			}	
			
			
		iCounter = iCounter + 1		
	}
 }
	
	
	
	
 ///////////////////////