var validChars="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";



function checkValidChars(obj,fldName)
{
var str=trim_string(obj)
for(i=0;i<str.length;i++)
	{
	/*if(checkChar(str.charAt(i))=="yes")
		{
		i=i+1
		continue
		}*/

	if(validChars.indexOf(str.charAt(i))==-1)
		{
		alert("Invalid character found in " + fldName + ". Please do not provide spaces in firstname, middlename, lastname,caste,email fields")
		obj.focus()
		obj.select()
		return false
		}
	}
return true
}

function trim_string(obj) {
     var ichar, icount;
     var strValue = obj.value
     ichar = strValue.length - 1;
     icount = -1;
     while (strValue.charAt(ichar)==' ' && ichar > icount)
         --ichar;
     if (ichar!=(strValue.length-1))
         strValue = strValue.slice(0,ichar+1);
     ichar = 0;
     icount = strValue.length - 1;
     while (strValue.charAt(ichar)==' ' && ichar < icount)
         ++ichar;
     if (ichar!=0)
         strValue = strValue.slice(ichar,strValue.length);
     return strValue;
 }

function trim_string_str(str1) {
     var ichar, icount;
     var strValue = str1
     ichar = strValue.length - 1;
     icount = -1;
     while (strValue.charAt(ichar)==' ' && ichar > icount)
         --ichar;
     if (ichar!=(strValue.length-1))
         strValue = strValue.slice(0,ichar+1);
     ichar = 0;
     icount = strValue.length - 1;
     while (strValue.charAt(ichar)==' ' && ichar < icount)
         ++ichar;
     if (ichar!=0)
         strValue = strValue.slice(ichar,strValue.length);
     return strValue;
 }

function checkBlank(obj,fldName)
{
obj.value=trim_string(obj)
if(obj.value=="")
	{
	alert("Please fill " + fldName + " field.")
	obj.select()
	obj.focus()
	return false
	}
return true
}

function fillCombo(st,ed)
{
for(i=st;i<=ed;i++)
	document.write("<option value=" + i + ">" + i + "</option>")
}

function allowOnlyCharKeys(e)
{
var key = parseInt(e.keyCode);
if((key < 65 || key > 90) && (key < 97 || key > 122 ))
	{
	e.keyCode=0;
	}
}

function allowOnlyNumKeys(e)
{
var key = parseInt(e.keyCode);
if((key < 48 || key > 57))
	{
	e.keyCode=0;
	}
}


function allowNumAndCharKeys(e)
{
var key = parseInt(e.keyCode);
if((key < 65 || key > 90) && (key < 97 || key > 122 ) && (key < 48 || key > 57) )
	{
	e.keyCode=0;
	}
}


function checkValidBirthDate(dd,mm,yy)
{
var monthDays="31,28,31,30,31,30,31,31,30,31,30,31".split(",")

if(parseInt(dd.options[dd.selectedIndex].value)>monthDays[mm.selectedIndex])
	{
	if(mm.selectedIndex==2 && parseInt(dd.options[dd.selectedIndex].value)==29 && (parseInt(yy.options[yy.selectedIndex].value)%4==0) )
		{
		}
	else
		{
		if(mm.selectedIndex==2 && (parseInt(yy.options[yy.selectedIndex].value)%4==0))
			{
			alert("This month only have 29 days.")
			dd.focus()
			return false
			}
		alert("This month only have " + monthDays[mm.selectedIndex] + " days.")
		dd.focus()
		return false
		}
	}
return true
}

function checkAdData(obj)
{
if(obj.value.indexOf('«')>-1 || obj.value.indexOf('»')>-1 || obj.value.indexOf('`')>-1)
	{
	alert("Invalid Character found")
	obj.focus()
	obj.select()
	return false
	}
return true
}