//given the value, str_trim trims down the string from all padded whitespaces...
function str_trim(str)
{	
	if(str.length > 0)
		while(str.charAt(0)==' ')
			str = str.substr(1);
		
	if(str.length > 0)
		while(str.charAt((str.length - 1))==' ')
			str = str.substring(0, str.length-1);
	
	return str;
}

// enter only numeric values without decimal
function checkNum()
{
	var carCode = event.keyCode;
	
	if ((carCode < 48) || (carCode > 57))
	{
		//alert(carCode);
		alert('Please enter only numeric values.');
		event.cancelBubble = true;
		event.returnValue = false;
	}
} 

function checkTime(box)
{
	if (parseFloat(box.value) > 12)
	 {
		  alert("Please Select an Value between 1 & 12");
		  box.focus();
		  box.value ="00";	
	 }
}

function checkTime1(box)
{
	if (parseFloat(box.value) > 60)
	 {
		  alert("Please Select an Value between 0 & 60");
		  box.focus();
		  box.value ="00";	
	 }
}


function CheckInteger(obj)
{
	regExpr = new RegExp(/^\d*$/);

	if(str_trim(obj.value)!="")
	{
		if(!regExpr.test(obj.value))
		{
			alert("Please Enter Valid Numbers");
			obj.value="0";		
		}
	}
	else
		obj.value="0";		
}

function checkNumDec()
{
	var carCode = event.keyCode;
		
	if ( ((carCode >= 48) && (carCode <= 57)) || (carCode == 46) )
	{
	}
	else
	{
		alert('Please enter only numeric values.');
		event.cancelBubble = true;
		event.returnValue = false;
		return;
	}
}

// check email address syntax
function checkEmail(x)
{
	a=new Array();
	s=x.value;
	
	for(i=0; i<s.length; i++)
		a[i]=s.charAt(i);

	dot = s.indexOf(".");
	at   = s.indexOf("@");

	if (dot == -1 || at == -1)
	{
		x.focus()
		alert ("Please Check Email Address");
		return 1;
	}

	str1=s.substring(dot+1,s.length);
	str2=s.substring(at+1, dot);
	str3=s.substring(0,at);

	if((str1.length==0)||(str2.length==0)||(str3.length==0))
	{
		x.focus()     
		alert ("Please Check Email Address");
		return 1;
	}

	return 0;
}


// replace a old string with a new one
function replaceString(oldS,newS,fullS)
{// Replaces oldS with newS in the string fullS  
	for (var i=0; i<fullS.length; i++)
		if (fullS.substring(i,i+oldS.length) == oldS)
			fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length);

	return fullS;
}


// enter fractional values
function checkdecimal(box) 
{ 
 var val = eval(box.value/1)
 // limit to 2 dec places (rounding up, if needed) 
 box.value = Math.round(val*100)/100 
 // check <7 before dec point 
 
 if((box.value=="NaN")) 
 {
  alert("Invalid Value");
  box.focus();
  box.value ="";
 }
 
} 

function chckdecval(box) 
{ 
 var val = eval(box.value/1)
 // limit to 2 dec places (rounding up, if needed) 
 box.value = Math.round(val*100)/100 
 // check <7 before dec point 
 
 if((box.value=="NaN")) 
 {
  alert("Invalid Value");
  box.focus();
  box.value ="";
 }
 else if (parseFloat(box.value) > 24)
 {
  alert("Please Select an appropriate value.");
  box.focus();
  box.value ="0";	
 }

} 

function validate_email(email_txt) 
{
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@([\\w].+)\.[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(email_txt);
}

