//<!------------------------------------------------------------------!>
/**
* @author BlazeDream Technologies.
* @version 1.0
* @time 06-09-04 2:00 PM Modified 16-09-04
*/
//<!------------------------------------------------------------------!>

/**
* This function evaluates the input string for a correct E-Mail format.
* It calls a function isEmpty to find whether the input string is Empty.
* @param strValue string value.
* @return true, if the Format is right || false otherwise.
*/
function isEmail(objField){
	if(objField.value.length > 0){
		if(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(objField.value)){
			return true;
		}
	}
	alert("Invalid E-mail Address! Please re-enter.");
	objField.select();
	return false;
}
//<!----------------------------------------------------------------

/**
* Checks the input string parameter for null and empty. 
* This function also validates the input string for whitespace.
* @param strData string input value.
* @return true if the text is null or empty string
* @return false if the text is not null or empty string
*/
function isEmpty(strData){
	if ((strData.length == 0)||(strData == null)){
		return true;
	}

	//Regular expression refers any 0 or more white space with any alphabets.
	//If that expression matches with the input string it returns true, false otherwise.
	if (/^\s*(?=\w)/.test(strData)){
		return false;
	}
    return true;
}
//<!------------------------------------------------------------------!>

/**
* Validate the input for a proper file name.
* @param strFile string File name.
* @return true || false
*/
function isFile(strFile){
	if(isEmpty(strFile)){
		return false;
	}

	var strFind = new String(strFile);
	var intPos = strFind.lastIndexOf("\\");

	if (/^[a-zA-Z]*[^\/:*?"<;>;|]+(?=\.\w{3,4})/.test(strFind.substring(intPos+1,strFile.length))){
		return true;	
	}
	return false;
}
//<!------------------------------------------------------------------!>

/**
* This function evaluates the input string for Whitespace.
* @param strValue string value.
* @return true, if it finds whitespaces || false otherwise.
*/
function isImage(strFile){
	if (!isFile(strFile)){
		return false;
	}

	var strFName = new String(strFile);
	var intIndx = strFName.lastIndexOf('.');
	var strExn = strFName.substring(intIndx+1,strFName.length).toLowerCase();

	if(/^\S*(gif|jpg|bmp)/.test(strExn)){
		return true;
	}
	return false;
}
//<!----------------------------------------------------------------

/**
* This function is used to validate the Phone number field.
* @param obField Form field object.
* @param strField Form field name.
* @return true, if it is in number || false otherwise.
*/
function isPhone(obField, strField){
	var strData = new String(obField.value);
	
	for (var i=0; i < strData.length; i++){
		if ((strData.charAt(i) != '-')&&(strData.charAt(i) < '0') || (strData.charAt(i) > '9')){
			alert("Numeric value is required for the field "+ strField);
			obField.select();
			return false;
		}
	}
	return true;
}
//<!----------------------------------------------------------------

/**
* This function is used to restrict the non-numeric value.
* @return false if non-numeric keycode
*/
function forceNumber(){
  if(event.keyCode < 48 || event.keyCode > 58) 
	  return false;
}
//<!----------------------------------------------------------------

/**
* This function is used to restrict the non-numeric value except space.
* @return false if non-numeric keycode
*/
function forceNumSpace(){
  if((event.keyCode < 48 || event.keyCode > 58)&&(event.keyCode != 32)) 
	  return false;
}
//<!----------------------------------------------------------------

/**
* This function is used to restrict the non-numeric value.
* @return false if non-numeric keycode
*/
function forceMoney(obField){
	if((event.keyCode<48 || event.keyCode>58) && event.keyCode!=46) 
		return false;

	if(event.keyCode==46){
		for(var intI = 0; intI < obField.length; intI++){
			if(obField.charAt(intI)=="."){
				return false;
			}
		}
	}
}
//<!----------------------------------------------------------------

/**
* Creates a window object and loads the image file.
* @param url refers the file to be loaded
*/
//<!----------------------------------------------------------------
function showImage(url){
	var obWin = window.open(url,"newWin","width=300,height=400,scrollbars=auto");
	obWin.focus();
}

/**
* strComp function compares two input strings and return result in boolean value.
* @param strFirst base text on which the other string is compared
* @param strSec compared string
* @return True || False.
*/
function strComp(strFirst,strSec){
	if (strFirst.length == strSec.length){
		var strResult = new String(strFirst);

		if (strResult.search(strSec) != -1){
			return true;
		}
	}
	return false;
}
//<!----------------------------------------------------------------
