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 (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;
	}
	return true;
 }

 function ValidateText(id, msg, len)
 {
	var obj = document.getElementById(id);

	if(obj.value==null || obj.value==""){
		alert(msg);
		obj.focus();
		return false;
	}
	else if(len>0)
	{
		if(obj.value.length<len){
			alert(msg);
			obj.focus();
			return false;
		}
	}
	
	return true;
 }

 function ValidateNum(id, msg)
 {
	var obj = document.getElementById(id);

	if(obj.value==null || obj.value=="" || parseInt(obj.value)==0){
		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;
	}
	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 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,.ipx,";
	var start = val.lastIndexOf('.');
	if(start<2)
		return false;
	
	var ext = val.substring(start);
	if(extensions.indexOf(","+ext.toLowerCase(),",")<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 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 CurrencyOnly(id){
	var obj = document.getElementById(id);
	var at = obj.value.indexOf(',');
	var txt = '';
	if (window.getSelection)
	{
		txt = window.getSelection();
    }
	else if (document.getSelection)
	{
		txt = document.getSelection();
    }
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
    }
	
	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 && ch!=',')
	{
		if(txt=='')
		{
			var index = 0;
			if (obj.createTextRange) 
			{
				var r = document.selection.createRange().duplicate()
				r.moveEnd('character', obj.value.length)
				if (r.text == '') 
					index = obj.value.length;
				else
					index = obj.value.lastIndexOf(r.text)
			} 
			else 
				index = obj.selectionStart

			if(at<index)
				event.returnValue = 0;
		}
 	}
	else if(ch==',' && at!=-1)
	{
		if(txt.indexOf(',')<0)
			event.returnValue = 0;
 	}
	return true;
}
function CurrencyCont(id){
	var obj = document.getElementById(id);
	if(obj.value.length==0)
		obj.value = "0";
	else
	{
		if(obj.value.indexOf(',')==0)
			obj.value = "0"+obj.value;
		if(obj.value.indexOf(',')==obj.value.length-1)
			obj.value = obj.value+"00";
	}
}
 
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;
}

function postFormNoDisable(btn)
{
	__doPostBack(btn, '');
}
