function openWin(URL){
	var aWindow=window.open(URL, "Claims","width=770,height=480,toolbar=no,scrollbars=yes,resizable=yes,menubar=no,statusbar=yes,locationbar=no");
	aWindow.focus();
}

//Open up a 'what is this' popup window in the center of user screen
function openWhatIsThis(URL){
	//set default screen size
	var w = 480, h = 340;
	
	w = screen.availWidth;
	h = screen.availHeight;
	
	var popW = 500, popH = 350;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	
	var aWindow=window.open(URL,'whatisthis','width=' + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos + ',scrollbars=yes');
	
	aWindow.focus();
}

//Checks that the string contains the valid integer.
function isInteger(str) {
	var objRegExpInteger  = /^\d+$/;
	return objRegExpInteger.test(str);
}

//To Check Numeric
function isNumeric(str){
		return isInteger(str);
}

//To Check Numeric with specified length
function isNumericInRange(str, minlen, maxlen){
	if(checkString(str)) {
		if (( str.length < minlen ) || ( str.length > maxlen )) {
			return false;
		}else {	
			return isInteger(str);
		}		
	}else {
		return false;
	}	
}

//Checks for the float string. 
function isFloat(str){		   
	var objRegExpFloat=/^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
	return objRegExpFloat.test(str);
}


//To Check Email Address
function checkEmail(value){
	var pattern=/[^@_\.\w\d]|@@|\.\.|__|^@|^\.|^_|@$|\.$|_$|@\.|\.@|@_|_@|\._|_\.|(@)[^@]*\1/g
	if((((value.match(/@/)) && (value.match(/\./))) == null)||(value.match(pattern) != null)){
		return false;
	}
	return true;
}

//To Check Alphabets
function isAlphabet(str){
	var objRegExpString  =/^[a-zA-Z_0-9\.\!\@\$\&\(\)\-\,\?\:\;\s]+$/;
	return objRegExpString.test(str);
}

//To Check Names
function isName(str){
	var objRegExpString  =/^[a-zA-Z_0-9\'\.\!\@\$\&\(\)\-\,\?\:\;\s]+$/;
	return objRegExpString.test(str);
}

//To Check Class and package provided contains only alphabets, numbers and dot.
function isAlphanumeriAndDot(str){
	var objRegExpString  =/^[a-zA-Z_0-9\.]+$/;
	return objRegExpString.test(str);
}


//To Check Alphabets with specified length
function isAlphabetInRange(str, minlen, maxlen){
	if(checkString(str)) {
		if (( str.length < minlen ) || ( str.length > maxlen )) {
			return false;
		}else {
			var objRegExpString  =/^[a-zA-Z_0-9\.\!\@\$\&\(\)\-\,\?\:\;\s]+$/;
			return objRegExpString.test(str);
		}
	}else {
		return false;
	}
}

//To Check Alphanumeric
function isAlphanumeric(str){
	var objRegExpAlphaNumeric  =/^[a-zA-Z0-9]+$/;
	return objRegExpAlphaNumeric.test(str);
}

//To Check Alphanumeric with specified length
function isAlphanumericInRange(str, minlen, maxlen){
	if(checkString(str)) {
		if (( str.length < minlen ) || ( str.length > maxlen )) {
			return false;
		}else {
			var objRegExpAlphaNumeric  =/^[a-zA-Z0-9]+$/;
			return objRegExpAlphaNumeric.test(str);
		}
	}else {
		return false;
	}
}

//check for leading & trailing spaces
//remove leading and trailing whitespace characters       
function trim(strval) {
	var objRegExptrimAll=/^(\s*)([\W\w]*)(\b\s*$)/;	
	if(objRegExptrimAll.test(strval)) {
		strval = strval.replace(objRegExptrimAll, '$2');
	}
   var obj = / +/g;
   strval = strval.replace(obj, " ");
   if (strval == " ") {strval = ""; }   return strval;

	return strval;
} 

//check for leading spaces
//remove leading a whitespace characters
function trimLead(strval){
	var objRegExptrimLead=/^(\s*)(\b[\w\W]*)$/;
	if(objRegExptrimLead.test(strval)) {
		strval = strval.replace(objRegExptrimLead, '$2');
	}
	return strval;
}

//check for trailing spaces
//remove trailing a whitespace characters
function trimTrail(strval){
	var objRegExptrimTrail=/^([\w\W]*)(\b\s*)$/;
	if(objRegExptrimTrail.test(strval)) {
		strval = strval.replace(objRegExptrimTrail, '$1');
	}
	return strval;
}

//To check the form element value should not be empty or length should not be zero or 
//the value should not start with a space.
function checkString(strval){
	if(strval=='' || strval.length==0 || strval.charAt(0)==' '){
		return false;
	}
	else {
		return true;
	}
}

//It returns false if the field is empty (or not selected or not checked).
//param-frmElement is object of form element i.e. document.<form_name>.<element_name>
function checkField(frmElement){
	if(frmElement.type=='select-one') {
		var listObjval = frmElement.options[frmElement.selectedIndex].value;
		if(listObjval == "" || listObjval == "-1"){
			return false;
		}
		else {
			return true;
		}
	}else if(frmElement.type=='text') {							
		return checkString(frmElement.value);				
	}else if(frmElement.type=='textarea') {							
		return checkString(frmElement.value);				
	}else if(frmElement.type=='checkbox') {	
		if(frmElement.checked){
			return true;
		}
		else {
			return false;
		}			
	}else if(frmElement.type=='radio') {
		if(frmElement.checked){
			return true;
		}
		else {
			return false;
		}			
	}			
}	

//To check all the checkboxes of a group in a form
//param-frmElement is object of form element i.e. document.<form_name>.<element_name>
function checkAll(frmelement) {
	if(typeof(frmelement.length)!='undefined') {
		for(var ii=0; ii < frmelement.length; ii++ ) {
			frmelement[ii].checked=1;
		}
	}else {
		frmelement.checked=1;
	}
		
	
}
//To uncheck all the checkboxes of a group in a form
//param-frmElement is object of form element i.e. document.<form_name>.<element_name>
function UncheckAll(frmelement) {
	if(typeof(frmelement.length)!='undefined') {
		for(var ii=0; ii < frmelement.length; ii++ ) {
			frmelement[ii].checked=0;
		}
	}else {
		frmelement.checked=0;
	}
}
//It returns true if a checkbox or a radio button is checked from a group of checkboxes or radio buttons respectively.
//param-frmElement is object of form element i.e. document.<form_name>.<element_name>
function isChecked(frmelement) {
	isCheckedVal=false;
	if(typeof(frmelement.length)!='undefined') {
		for(var ii=0; ii < frmelement.length; ii++ ) {
			if(frmelement[ii].checked==1) {
				isCheckedVal = true;
				break;
			}
		}
	}else if(frmelement.checked == 1) {
		isCheckedVal = true;
	}
	return isCheckedVal;
}
//To uncheck the "Select All" check box once any of the checkboxes is uncheck
//param-frmElement is object of form element i.e. document.<form_name>.<element_name>
function UncheckSelectAll(frmelement) {
		frmelement.checked=0;
}

//This method is used to prevent submition of form more than once. And this method should be 
//implemented at the place of successful submition condition. 
//btnobj---> It is the object of submit button in a form. 
function checkSubmit(btnobj) {
	var buttonValue = "Please wait...";
	if(btnobj.value != buttonValue) {
		btnobj.value = buttonValue;
		return true;
	}
	else {
		alert("You have submitted the request, please wait.");
		return false;
	}
}


//This method is used to prevent submition of form more than once. And this method should be 
//implemented at the place of successful submition condition. And this method should used for 
// the confirmation and the message of the confirmation should be passed as a parameter. 
//btnobj---> It is the object of submit button in a form. 
//msg---> confirmation message.
function checkConfirmSubmit(btnobj,msg) {
	var buttonValue = "Please wait...";
	if(btnobj.value != buttonValue) {		
		if(confirm(msg)) {
			btnobj.value = buttonValue;
			return true;
		}
	}
	else {
		alert("You have submitted the request, please wait.");
		return false;
	}
}

//To Check Alphabets only
function isAlphabetOnly(str){
	var objRegExpString  =/^[a-zA-Z]+$/;
	return objRegExpString.test(str);
}

//This function will prefix numbers that are less than 10 with "0"
function prefixZero(numberValue) {
	if (numberValue >= 10) {
		return ""+numberValue;
	} else {
		return "0"+numberValue;
	}
}

function validateFromAndToDate(fromDay, fromMonth, fromYear, toDay, toMonth, toYear) {

	var fromDate = fromYear+prefixZero(fromMonth)+prefixZero(fromDay);
	var toDate = toYear+prefixZero(toMonth)+prefixZero(toDay);

	if (fromDate > toDate) {
		return false;
	}

	return true;
}

function checkPOBOX(value){

	if(value.length > 0) {
		value = trim(value).toUpperCase();
		re = /\ |\.|\!|\~|\`|\@|\#|\$|\%|\^|\&|\*|\(|\)|\-|\_|\+|\=|\{|\}|\[|\]|\||\\|\;|\:|\"|\'|\<|\,|\>|\?|\//g;
		value = value.replace(re, "");

		if(value.indexOf('POBOX') >= 0) {
			return false;
		}
	}
	return true;
}

//checks if the PIN matches all of the following criteria:
//a) At least one alphabetical character;
//b) One numeric character;
//c) Not equal to user ID;
//d) Username backwards
//e.) Exactly 8 chars 
function validatePIN(value, userid, minlength, maxlength){
/*	alert("isAlphanumericInRange: " + isAlphanumericInRange(value, minlength, maxlength));
	alert("checkHasAlpha: " + checkHasAlpha(value));
	alert("checkHasDigit: " + checkHasDigit(value));
	alert("validateNotEqual: " + validateNotEqual(value, userid));
	alert("validateNotEqual: " + validateNotEqual(value, reverseString(userid)));*/


		return isAlphanumericInRange(value, minlength, maxlength)
				&& checkHasAlpha(value)
				&& checkHasDigit(value)
				&& validateNotEqual(value, userid)
				&& validateNotEqual(value, reverseString(userid));
}	


//checks if the string contains an alpha char.
function checkHasAlpha(value){
	for(var i=0; i<value.length; i++){
		var ch = value.substring(i, i+1);
		ch = ch.toUpperCase();

		if(ch >="A" && ch <="Z"){
			return true;
		}
	}
	return false;
}
//checks if the string contains a numeric char.
function checkHasDigit(value){
	for(var i=0; i<value.length; i++){
		var ch = value.substring(i, i+1);

		if(ch >="0" && ch <="9"){
			return true;
		}
	}
	return false;
}

/*
 * function: validate whether first field equals second field
 * return: true if input 1 equals input 2; false otherwise
 */
 function validateNotEqual(value1, value2) {
 	if (value1 != value2) {
 		return true;
 	} else {
 		return false;
 	}
 }
  
 /*returns a reversed string*/
 function reverseString(value){
 	var newStr = null;
 	var initi = value.length-1;
 	
	for(var i=initi; i>=0; i--){
		var ch = value.substring(i, i+1);
		if(i == initi){
	 		newStr = ch;
		}else{
			newStr = newStr.concat(ch);
		}
	}
	return newStr;
}

/*
 * function: allow alphabet and numeric key code
 */
function alphaNumericKey() {
  var event = window.event;
  key = event.keyCode;
  if (!isAlphaKey(key) && !isNumericKey(key) || key == 32) {
    return false;
  }
  return true;
}

/*
 * function: validate if key code is alphabets and space
 */
function isAlphaKey(arg) {
   return (arg > 64 && arg < 91) || (arg > 96 && arg < 123) || arg == 32;
}

/*
 * function: validate if a character is digit
 */
function isNumericKey(arg) {
  return (arg >= "0".charCodeAt(0)) && (arg <= "9".charCodeAt(0));
}

