function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
}
function echeck(eid) {
document.getElementById(eid).value=Trim(document.getElementById(eid).value);
var str=document.getElementById(eid).value;

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   document.getElementById(eid).focus();
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   document.getElementById(eid).focus();
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    document.getElementById(eid).focus();
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    document.getElementById(eid).focus();
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    document.getElementById(eid).focus();
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    document.getElementById(eid).focus();
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    document.getElementById(eid).focus();
		    return false
		 }

 		 return true					
	}

function checkvalid()
{
document.frmfrm.txtlastname.value=Trim(document.frmfrm.txtlastname.value);
document.frmfrm.txtorderno.value=Trim(document.frmfrm.txtorderno.value);
document.frmfrm.txtcomment.value=Trim(document.frmfrm.txtcomment.value);
document.frmfrm.txtemail.value=Trim(document.frmfrm.txtemail.value);

	if ((document.frmfrm.txtlastname.value.length)<3)
	{
		alert ("Please Enter valid last name");
		document.frmfrm.txtlastname.focus();
		return false;
	}
	
	if (Trim(document.frmfrm.txtorderno.value) == "")
	{
		alert ("Please Enter valid order number");
		document.frmfrm.txtorderno.focus();
		return false;
	}
	
	if (isNaN(document.frmfrm.txtorderno.value))
	{
		alert ("Please Enter valid order number");
		document.frmfrm.txtorderno.value='';
		document.frmfrm.txtorderno.focus();
		return false;
	}

	if (Trim(document.frmfrm.txtcomment.value) == "")
	{
		alert ("Please Enter comment");
		document.frmfrm.txtcomment.focus();
		return false;
	}
	
	if (Trim(document.frmfrm.txtemail.value) != Trim(document.frmfrm.txtagainemail.value))
	{
		alert ("Both email adderss should be same");
		document.frmfrm.txtagainemail.focus();
		return false;
	}
	
	return echeck("txtemail");

	return false;
}


