function ValidateAsNotEmpty(ErrorMessage, value)
{
	if (value==""||value==null)
	{ 
		alert(ErrorMessage);
		return false;
	}
	return true;
}

function ValidateAsNotEmptyArray(ErrorMessage,form,elem)
{	
     flag = false;
     var theElements = document.forms[form].elements[elem];
     for (var count = 0; count < theElements.length; count++) {
          if (theElements[count].checked) flag = true;
     }
     if (!flag)
     {
 	    alert(ErrorMessage); 
     } 
	 return flag;	
}

function ValidateAsEmail(ErrorMessage, value)
{		
		if (value=="") return true;
		var r_email = new RegExp("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,4}$","ig");
		var arr = r_email.exec(value);
		if (arr == null)
		{   
		 	alert(ErrorMessage);
			return false;
		}
		return true;
}

function ValidateAsURL(ErrorMessage, value)
{
		if (value=="") return true;
		var r_url = new RegExp("^(http|https|ftp)://(www\.)?.+([-!#\$%&'*+/0-9=?A-Z^_`a-z{|}~]+\\.)+[a-zA-Z]{2,4}\$","ig");
		var arr = r_url.exec(value);
		if (arr == null)
		{   
		 	alert(ErrorMessage);
			return false;
		}
		return true;
}

function ValidateAsWM(ErrorMessage, value)
{
		if (value=="") return true;
		var r_wm= new RegExp("^Z[0-9]{12}","ig");
		var arr = r_wm.exec(value);
		if (arr == null)
		{   
		 	alert(ErrorMessage);
			return false;
		}
		return true;
}

function ValidateRegularExpression(ErrorMessage, value, reg)
{
		if (value=="") return true;
		var r_re = new RegExp(reg,"ig");
		var arr = r_re.exec(value);
		if (arr == null)
		{   
		 	alert(ErrorMessage);
			return false;
		}
		return true;
}
function ValidateMinimumLength(ErrorMessage, value, len)
{
		if ( value.length<len )
		{   
		 	alert(ErrorMessage);
			return false;
		}
		return true;
}

function ValidateMaximumLength(ErrorMessage, value, len)
{
		if ( value.length>len )
		{   
		 	alert(ErrorMessage);
			return false;
		}
		return true;
}

function ValidateAsEqualTo(ErrorMessage, val1, val2)
{
		if ( val1 != val2 )
		{   
		 	alert(ErrorMessage);
			return false;
		}
		return true;
}

function ValidateAsDifferentFrom(ErrorMessage, val1, val2)
{
		if ( val1 == val2 )
		{   
		 	alert(ErrorMessage);
			return false;
		}
		return true;
}

function ValidateAsInteger(ErrorMessage, val1, val2, val3)
{
		if (val1 == "") return true;
		if (isNaN(parseInt(val1, 10)) || (val2 != '') && (parseInt(val1, 10) < val2) || (val3 != '') && (parseInt(val1, 10) > val3))
//		if (isNaN(val1)) || (val2 != '') && (val1 < val2) || (val3 != '') && (val1 > val3))
		{   
		 	alert(ErrorMessage);
			return false;
		}
		return true;
}

function ValidateAsFloat(ErrorMessage, val1, val2, val3)
{
		if (val1=="") return true;
		if (isNaN(parseFloat(val1, 10)) || (val2 != '') && (parseFloat(val1, 10) < val2) || (val3 != '') && (parseFloat(val1, 10) > val3))
//		if (isNaN(val1) || (val2 != '') && (val1 < val2) || (val3 != '') && (val1 > val3))
		{   
		 	alert(ErrorMessage);
			return false;
		}
		return true;
}

function ValidateMAX_FILE_SIZE(ErrorMessage, val1,val2)
{
		if (val1>val2)
		{   
		 	alert(ErrorMessage);
			return false;
		}
		return true;
}
