//<meta author="nilesh" created="29-jan-01" modified="1-mar-01">



function trims(val)
{
var str  = new String(val);
var newStr = str;

if (val=="") return val; 


for (i=0;i<str.length;i++)
	if(str.charCodeAt(i)==32)
		newStr = str.substring(i+1,str.length)
	else
		break;

str = newStr;

for (i=str.length-1;i>=0;i--)
	if(str.charCodeAt(i)==32)
		newStr = str.substring(0,i)
	else
		break;


return newStr;
}

function email_Check(email)
{
var flag=true;

//numbers Keycode = 48-57
//alphabets Keycode = 97-122
//@ Keycode = 64
//. Keycode = 46

if (email.value=="") {alert("Cannot leave Email field blank");return false;}

var eMail=new String(trims(email.value));
eMail = eMail.toLowerCase()

//********** check for whether first character is alphabet or not*******************************
if((eMail.substring(0,1)<"a" || eMail.substring(0,1)>"z") && (eMail.substring(0,1)<"A" || eMail.substring(0,1)>"Z"))
{
alert("The Email id should begin with an alphabetic character.");
return false;
}





//*********CHECK FOR A VALID ABOVE MENTIONED CHARACTERS****************	

for (i=0;i<eMail.length;i++)
	{
     keycode = eMail.charCodeAt(i);
	 if (((keycode<44) || (keycode>57)) && ((keycode<94) || (keycode>122)))   
		if ((keycode!=64) && (keycode!=46)) 
			{
				flag=false;
				break;
			} 
	}

countt=0;
for (i=0;i<eMail.length;i++)
  {
	if (eMail.charCodeAt(i)==64)
	  {
		countt=countt+1;		
	  }
	if (countt > 1)	
	{alert("Invalid Email id");return false;}

  } 

//**********CHECK IF "@" & "." IS PRESENT & CHECK IF ITS ATLEAST IN THE "a@b.c" FORMAT**************

if (flag)
	if (eMail.indexOf(".")>1 && eMail.indexOf("@")>0) 
		if((eMail.indexOf(".")-eMail.indexOf("@"))>1 ||(eMail.indexOf(".")-eMail.indexOf("@"))<1)
			if(((eMail.length-1)-eMail.indexOf("."))>=1)
				return true;
			else 
				{alert("Invalid Email id");return false;}
		else
			{alert("Invalid Email id");return false;}
	else
		{alert("Invalid Email id");return false;}
else
	{alert("Invalid Email id");return false;}
 

}


function numericcheckspace(fld,msg){  // to check alphanumeric value with space
  nr1=fld.value;
  flg=0;
  str="";
  spc=""
  arw="";
  counter = "";
	
  for (var i=0;i<nr1.length;i++){
   cmp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
   tst=nr1.substring(i,i+1)
   
	if (cmp.indexOf(tst)<0){
    			flg++;
    			str+=" "+tst;
    			spc+=tst;
    			arw+="^";
   	}
	else {
   			if (tst.indexOf(" ") > -1 && (i<1))  {
					//alert("space" + i)
		 			flg++;
    				str+=" "+"space";
    				spc+=tst;
    				arw+="^";
			}
   			else{arw+="_";}
	}
  }
  /*if (flg!=0){
   if (spc.indexOf(" ")>-1) {
    str+=" and a space";
    } 
   alert(nr1+"\r"+arw+"\rI'm sorry. This entry must be a alphanumeric. I found "
   +flg+" unacceptable: "+str+"."); */

  if (flg!=0){ 	
			alert(msg);
			fld.focus();
			fld.select();
			return false;
  }
  else {
		return true;
  }
} 

function numericcheck(fld,msg){    /// to check alphanumeric value
	
  nr1=fld.value;
  flg=0;
  str="";
  spc=""
  arw="";
	
  for (var i=0;i<nr1.length;i++){
   cmp="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
   tst=nr1.substring(i,i+1)
	
   if (cmp.indexOf(tst)<0){
    flg++;
    str+=" "+tst;
    spc+=tst;
    arw+="^";
   }
   else{arw+="_";}
  }
  /*if (flg!=0){
   if (spc.indexOf(" ")>-1) {
    str+=" and a space";
   }
	return false;
   //alert(nr1+"\r"+arw+"\rI'm sorry. This entry must be a alphanumeric. I found "
   //+flg+" unacceptable: "+str+".");*/

  if (flg!=0){
		alert(msg);
		fld.focus();
		fld.select();
		return false;
  }
  else 
		return true;
 }


 function checkselect(inputField) {
		if (inputField.value == "S") 
			return false;
		else
			return true;
}

function numwithdec(fld,dig,dec,msg,msg1,msg2,msg3) {
		var a = fld.value;
		//var b = a.substring(a.indexOf('.')+1)
		//alert("hello"   + b.length);
		//(a.indexOf('.') == "0") ||
		var n = new Number(fld.value)
		
		if (n > 10) {
			alert(msg);
			fld.focus();
			fld.select();
			return false;
		}
 		
		if (a.substring(a.indexOf('.')+1).indexOf('.') >=0) {
			alert(msg1);
			fld.focus();
			fld.select();
			return false;
		}
		else if(a.indexOf('.') > dig){
			alert(msg2);
			fld.focus();
			fld.select();
			return false;
		}
		else if((a.substring(a.indexOf('.')+1).length > dec) && (a.indexOf('.') >=0)){
			alert(msg3)
			fld.focus();
			fld.select();
			return false;
		}
		
		else if((a.indexOf('.') <0) && (a.length > dig)) {
			alert(msg2);
			fld.focus();
			fld.select();
			return false;
		}
		else
			return true;	
	}	

function intmonth(mon1) {
	switch(mon1) {
	
		case "Jan": {
				return "1"
				break;
		}
		case "Feb": {
				return "2"
				break;
		}
		case "Mar": {
				return "3"
				break;
		}		  
		case "Apr": {
				return "4"
				break;
		}
		case "May": {
				return "5"
				break;
		}
		case "Jun": {
				return "6"
				break;
		}
		case "Jul": {
				return "7"
				break;
		}
		case "Aug": {
				return "8"
				break;
		}
		case "Sep": {
				return "9"
				break;
		}
		case "Oct": {
				return "10"
				break;
		}
		case "Nov": {
				return "11"
				break;
		}
		case "Dec": {
				return "12"
				break;
		}
     }
 }


function y2k(number)
     { 
           return (number < 1000) ? number + 1900 : number;
     }

function check_date(day,month,year)
 {
    var today = new Date();

    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);

    if (!day) return false
    var test = new Date(year,month,day);
    if ((y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false
}


function checkfieldval(inputField) {
	if (inputField.value.length == 0 ) {
		return false;}
	else 
		return true;
	

	/*else if( (inputField.value.indexOf(' ') >= 0 ) || (inputField.value.length < 4)) {
		if (ie && flag) alert(msg2);
		return false;
	}*/
}


function isnegetive(inputField,msg) {
		
	var numval = new Number(inputField.value)
	if(numval < 0) {
		alert(msg);
		inputField.focus();
		inputField.select();
		return false;
	}
	else
		return true;
}

function isdecimal(fld,msg) {
	if(fld.value.indexOf('.')>=0) { 
		alert(msg);
		fld.focus();
		fld.select();
		return false;
	}
	else
		return true;
}

function checkspace(fld,msg) {
	var fldval = new String(fld.value)
	if(fldval.indexOf(' ')>=0) { 
		alert(msg);
		fld.focus();
		fld.select();
		return false;
	}
	else
		return true;
}

function check_numval(inputField,msg){
	var numval = new Number(inputField.value)
	if (isNaN(numval)){
		alert(msg);
		inputField.focus();
		inputField.select();
		return false;
	}
	else
		return true;
}


function perfldblur(fld,flag) {
	if (flag.value != "" ) {
		fld.blur();
	}
}

function leavefield(fld) {
	fld.blur();	
}

function chkspchar(obj,msg,words)
{
var obj = eval("document.frmasset." + obj)
var objval =  obj.value
	for(i=0;i<objval.length;i++)
	{					

	  if(words=="false")
	  {		
		keycode=objval.charCodeAt(i);
			alert(keycode)
		if (((keycode<65) || (keycode>90)) && ((keycode<97) || (keycode>122)) && ((keycode<48) || (keycode>57)) )   
		{
			alert(msg);
			obj.focus();
			obj.select();
			return false;
		}
	  }
	  else 
	  {//words ="true"
		keycode=objval.charCodeAt(i);
                
		if (((keycode<65) || (keycode>90)) && ((keycode<97) || (keycode>122)) && ((keycode>48) || (keycode<57)) && (keycode!=32))   
		{        
 			
			alert(msg);
			obj.focus();
			obj.select();
			return false;
		}
		
	  }				 
	}
			return true;	
}

