function validateEmail(fld)
{
	var my=fld.value;
	var attherate=my.indexOf("@");
	var lastattherate = my.lastIndexOf("@")
	var dotpos=my.lastIndexOf(".");
	var posspace = my.indexOf(" ");
	var totallen = my.length;
	
	if (attherate<=0 || dotpos<=0 || attherate > dotpos || (dotpos-attherate)<=1 || (dotpos == totallen-1) || posspace > -1 || attherate!=lastattherate)
		return false;
	else
		return true;
}	

function Trim(myval)
{
	var chklen=myval.length; 
	var pos=0;
	mychar = myval.charAt(0);

	while(pos>=0 || lstpos >=0)
	{
		pos=myval.indexOf(" ");
		if (pos==0)
		{
			myval=myval.substring(1,chklen);
			chklen = myval.length;
			mychar = myval.charAt(0);
		}
		lstpos=myval.lastIndexOf(" ");

		if (lstpos==chklen-1)
		{	
			myval=myval.substring(0,chklen-1);
			chklen=myval.length;
			mychar = myval.charAt(chklen-1);
		}
		
		if(mychar!=" ")
			break;

	}
	return myval;			
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) 
		return false;
    }
    // All characters are numbers.
    return true;
}

function validateForm(frm,arr_compulsoryfields,arr_friendlynames)
{
	for(i=0;i<arr_compulsoryfields.length;i++)
	{
		myfld = eval("frm."+arr_compulsoryfields[i])
		
		if(Trim(myfld.value) == "")
		{
			alert(arr_friendlynames[i]+" is not entered. Please enter "  + arr_friendlynames[i] + ".");			
			myfld.focus();
			return false;
		}		
	}
	return true;
}
/// add by ranjana 19 march
///only numeric value entered
function num_onKeypress()
{
	var string="1234567890";
	if (string.indexOf(unescape('%' + window.event.keyCode.toString(16))) != -1) 
		window.event.returnValue = true;
	else
		window.event.returnValue = false;
}

/// Added by rakes shrivastav to accomodate decimal validation
///only numeric value entered
function numeric_onKeypress()
{
	var string=".1234567890";
	if (string.indexOf(unescape('%' + window.event.keyCode.toString(16))) != -1) 
		window.event.returnValue = true;
	else
		window.event.returnValue = false;
}

// Minimum Qunatity eneter atleast one
function HandleError(esrc)
{
	var val = parseInt(esrc.value);
	if (val < 1 )
	{
		alert ("Quantity cannot be less than one");
		esrc.value =1;
	}
}
