/*
 * @(#)ValidationUtility.js        04/nov/2000
 *
 * Copyright (c) 2000 Vistaar e-business solutions.
 *
 * This java script file is used for validating fields
 * @version 1.0 03-nov-2000
 * @author Joseph Vinoth 
 */

/**
  * method isEmail is used to check whether the given field has a valid 
  * Email Address or not.
  *
  * @param fieldName --> the field which you want to check Email or not
  */
  
function isEmail(fieldName){
	/*
	 * this method will return false if the given field is not empty
	 * or field does't have any "@" or "." symbol or length is less than 6. 
	 */
	
	/** fieldValue is used to hold the value of the field*/
	fieldValue = fieldName.value;
	
	if (isEmpty(fieldName)) {                 //to check the given
		return false;							    //value is empty or not
	}
	
	else if (fieldValue.indexOf("@") == -1) {	    //to check the given
		return false;								//value has "@" symbol or not 	
	}
				
	else if (fieldValue.indexOf(".") == -1) {		//to check the given
		return false;								//value has "." or not
	}
	
	else if (fieldValue.length < 6) {			    //to check the given	
		return false;								//value has more than 6 chracter
	}
	
	else if (fieldValue.indexOf(" ") != -1) {		//to check the given	
		return false;								//value has any blank spaces
	}
	
	else {
		return true;
	}	
}


function isNmmEmail(fieldName){
	/*
	 * this method will return false if the given field is not empty
	 * or field does't have any "@" or "." symbol or length is less than 6.Allow multiple entry of email. 
	 */
	
	/** fieldValue is used to hold the value of the field*/
	fieldValue = fieldName.value;
	
	if (isEmpty(fieldName)) {                 //to check the given
		return false;							    //value is empty or not
	}
	
	else if (fieldValue.indexOf("@") == -1) {	    //to check the given
		return false;								//value has "@" symbol or not 	
	}
				
	else if (fieldValue.indexOf(".") == -1) {		//to check the given
		return false;								//value has "." or not
	}
	
	else if (fieldValue.length < 6) {			    //to check the given	
		return false;								//value has more than 6 chracter
	}
	else {
		return true;
	}	
}

/**
  * method doEmpty is used to check whether the given field is 
  * Empty or not and display some error message if it is empty.
  *
  * @param fieldName --> the field which you want to Empty or not
  * @param errrMsg   --> the error message to display if the field is empty
  */

function doEmpty(fieldName,errorMsg){

	if (isEmpty(fieldName)) {					//to check the given
		window.alert(errorMsg);						//value is empty or not
		return true;
	}
}

/**
  * method isEmpty is used to check whether the given field is 
  * Empty or not.
  *
  * @param fieldName --> the field which you want to Empty or not
  */

function isEmpty(fieldName){
    /*
     * This method will return true if the field is empty and return
     * false if it is not empty.
     */
    emptyFlag = true;
	if (fieldName.value == ''){						//to check the given
		return true;								//value is empty or not
	}
	else{
	    for(i=0;i<(fieldName.value).length;i++){
	    	if((fieldName.value).charAt(i)!=' '){
	    		emptyFlag = false;
	    		break;
	    	}	
	    }	    	
	   return emptyFlag;
	}   
}

/**
  * method isEmptyValue is used to check whether the given value is 
  * Empty or not.
  *
  * @param fieldName --> the field which you want to Empty or not
  */

function isEmptyValue(val){
    /*
     * This method will return true if the field is empty and return
     * false if it is not empty.
     */
    emptyFlag = true;
	if (val == ''){						//to check the given
		return true;								//value is empty or not
	}
	else{
	    for(i=0;i<(val).length;i++){
	    	if((val).charAt(i)!=' '){
	    		emptyFlag = false;
	    		break;
	    	}	
	    }	    	
	   return emptyFlag;
	}   
}

function isNumber(theNumber,EmbededCharacter)
{	    	
	var count = 0
	for(i=0;i<=theNumber.length;i++)
	{	//alert("count = " +1)
		var theCharacter = theNumber.substring(i,i+1)		
		if(isNaN(theCharacter))
		{
			if(EmbededCharacter.indexOf(theCharacter) != -1) 
			{	
				count = count + 1
			}
			else
			{
				return(false)
			}	
		}		
	}			
	if(theNumber.length == count)
	{
		return(false)
	}	
	return(true)
}

function checkDate(fieldName){

	if (! isEmpty(fieldName)) 
	{
		if(! validateDateOfDDMONYYYYForm( fieldName.value ) )
    	{
    		window.alert("Please enter the correct Date strictly in the 01-Jan-2000 form" );
        	return true;  	
    	}
	}
}