function echeck(str, msgInvalid) {

		if(str=="")
			return true;
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length-1;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   alert(msgInvalid);
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert(msgInvalid);
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert(msgInvalid);
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert(msgInvalid);
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert(msgInvalid);
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert(msgInvalid);
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert(msgInvalid);
		    return false;
		 }

 		 return true;				
	}

function ValidateMail(id, msgNone, msgInvalid){
	
	var emailID=document.getElementById(id);
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert(msgNone);
		emailID.focus();
		return false;
	}
	if (emailID.value.indexOf("script>")>-1){
		alert(msgInvalid);
		emailID.focus();
		return false;
	}
	if (echeck(emailID.value, msgInvalid)==false){
		//emailID.value=""
		emailID.focus();
		return false;
	}
	return true;
 }
 
function ValidateMailNotFocus(id, msgNone, msgInvalid){
	
	var emailID=document.getElementById(id);
	
	if ((emailID.value==null)||(emailID.value=="")){
		alert(msgNone);
//		emailID.focus();
		return false;
	}
	if (emailID.value.indexOf("script>")>-1){
		alert(msgInvalid);
		//emailID.focus();
		return false;
	}
	if (echeck(emailID.value, msgInvalid)==false){
		//emailID.value=""
//		emailID.focus();
		return false;
	}
	return true;
 }
 
function ValidateMailAllowBlank(id, msgInvalid){
	
	var emailID=document.getElementById(id);
	
	if (echeck(emailID.value, msgInvalid)==false){
		emailID.focus();
		return false;
	}
	if (emailID.value.indexOf("script>")>-1){
		alert(msgInvalid);
		emailID.focus();
		return false;
	}
	return true;
 }

 function ValidateText(id, msg, len)
 {
	var obj = document.getElementById(id);

	if(obj.value==null || obj.value==""){
		alert(msg);
		obj.focus();
		return false;
	}
	if(obj.value.indexOf("script>")>-1){
		alert(msg);
		obj.focus();
		return false;
	}
	else if(len>0)
	{
		if(obj.value.length<len){
			alert(msg);
			obj.focus();
			return false;
		}
	}
	
	return true;
 }

 function ValidateText(id, msg, min, max)
 {
	var obj = document.getElementById(id);

	if(obj.value==null || obj.value==""){
		alert(msg);
		obj.focus();
		return false;
	}
	if(obj.value.indexOf("script>")>-1){
		alert(msg);
		obj.focus();
		return false;
	}
	else if(obj.value.length<min || obj.value.length>max){
			alert(msg);
			obj.focus();
			return false;
		}
	
	
	return true;
 }

 function ValidateTextNotFocus(id, msg)
 {
	var obj = document.getElementById(id);
	
	if(obj.value==null || obj.value==""){
		alert(msg);
		return false;
	}
	if(obj.value.indexOf("script>")>-1){
		alert(msg);
		return false;
	}
	return true;
 }

 function ValidateTextNotFocusMin(id, msg, len)
 {
	var obj = document.getElementById(id);

	if(obj.value==null || obj.value==""){
		alert(msg);
		return false;
	}
	if(obj.value.indexOf("script>")>-1){
		alert(msg);
		return false;
	}
	else if(parseInt(len)>0)
	{
		if(obj.value.length<parseInt(len)){
			alert(msg);
			return false;
		}
	}
	
	return true;
 }

function CompareText(id1, id2, msg)
 {
	if(document.getElementById(id1).value != document.getElementById(id2).value){
		alert(msg);
		document.getElementById(id2).focus();
		return false;
	}
	
	return true;
 }

function CompareTextNotFocus(id1, id2, msg)
 {
	if(document.getElementById(id1).value != document.getElementById(id2).value){
		alert(msg);
		return false;
	}
	
	return true;
 }

 function ValidateCheck(id, msg)
 {
	var obj = document.getElementById(id);

	if(!obj.checked){
		alert(msg);
		obj.focus();
		return false;
	}
	
	return true;
 }
 
 function CheckExt(val, msgInv)
 {
	//var extensions = ",.jpg,.jpeg,.gif,.bmp,.png,.psd,.pdf,.doc,.xls,.odt,";
     var extensions = ",.jpg,.jpeg,.gif,.pdf,.doc,.docx,.odt,.tiff";
	var start = val.lastIndexOf('.');
	if(start<2)
		return false;
	
	var ext = val.substring(start);
	if(extensions.indexOf(","+ext,",")<0)
		 return false;
		
	return true;
 }
 
 function ValidateImageNotEmpty(id, msgBos, msgInvalid)
 {
	var obj = document.getElementById(id);

	if(obj.value.length==0){
		alert(msgBos);
		obj.focus();
		return false;
	}
	else if(!CheckExt(obj.value)){
		alert(msgInvalid);
		obj.focus();
		return false;
	}
	
	return true;
 }
 
 function ValidateImageNotFocus(id, msgBos, msgInvalid)
 {
	var obj = document.getElementById(id);

	if(obj.value.length==0){
		alert(msgBos);
		return false;
	}
	else if(!CheckExt(obj.value)){
		alert(msgInvalid);
		return false;
	}
	
	return true;
 }
 
 function ValidateImage(id, msgInvalid)
 {
	var obj = document.getElementById(id);

	if(obj!=null){
		if(obj.value.length==0){
			return true;
		}
		else if(!CheckExt(obj.value)){
			alert(msgInvalid);
			obj.focus();
			return false;
		}
	}
	
	return true;
 }
 
function NumericOnly(){
	key = window.event.keyCode;
	ch = String.fromCharCode(key);
	if (!(ch >= '0' && ch <= '9')) 
	{
		event.returnValue = 0;
	}
	else return true;
}
 
function NumericOnlyMax(id, max){
	var obj = document.getElementById(id);
	
	if(obj.value.length>=max)
		return false;
	
	key = window.event.keyCode;
	ch = String.fromCharCode(key);
	if (!(ch >= '0' && ch <= '9')) 
	{
		event.returnValue = 0;
	}
	else return true;
}
 
function CurrencyOnly(id){
	var obj = document.getElementById(id);
	var at = obj.value.indexOf(',');
	
	key = window.event.keyCode;
	ch = String.fromCharCode(key);
	if (!((ch >= '0' && ch <= '9') || ch==',')) 
	{
		event.returnValue = 0;
	}
	else if(at!=-1 && at<obj.value.length-2)
	{
		event.returnValue = 0;
 	}
	else if(ch==',' && at!=-1)
	{
		event.returnValue = 0;
 	}
	else return true;
}

function DisableButton(id)
{
	//document.getElementById(id).disabled = true;
}																			


function trapEnter(btn)
{
	 if (document.all){
	    if (event.keyCode == 13)
	    {
			event.returnValue=false;
			event.cancel = true;
			if(document.getElementById(btn)!=null)
			document.getElementById(btn).click();
	    }
	 }
}

function postForm(btn)
{
	__doPostBack(btn, '');
//	if(document.getElementById(btn)!=null)
//		document.getElementById(btn).disabled = true;
    //
    document.getElementById("waitDiv").style.width = document.body.scrollWidth.toString() + "px";
    document.getElementById("waitDiv").style.height = document.body.scrollHeight.toString() + "px";
    document.getElementById("waitDiv").style.visibility = "visible";

	return true;
}

function postFormNoDisable(btn)
{
//	__doPostBack(btn, '');

    document.getElementById("waitDiv").style.width = document.body.scrollWidth.toString() + "px";
    document.getElementById("waitDiv").style.height = document.body.scrollHeight.toString() + "px";
    document.getElementById("waitDiv").style.visibility = "visible";
}

function disableNoPost() {
    document.getElementById("waitDiv").style.width = document.body.scrollWidth.toString() + "px";
	document.getElementById("waitDiv").style.height = document.body.scrollHeight.toString()+"px";
	document.getElementById("waitDiv").style.visibility = "visible";
	
}
