//check summary textbox input for special MS Word characters
var codeNumbers   = new Array(8218, 402, 8222, 8230, 8224, 8225, 710, 8240, 352, 8249, 338, 8216, 8217, 8220, 8221, 8226, 8211, 8212, 732, 8482, 353, 8250, 339, 376);
var characters = new Array(",", "f", '"', "...", "+", "++", "^", "o/oo", "Sh", "<", "Oe", "'", "'", '"', '"', "*", "-", "--", "~", "(TM)", "sh", ">", "oe", "Y"); 

sfHover = function() {
	var sfEls = document.getElementById("menu_list").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

function TidyInput(e) {
	var output = trim(e.value);
	if (output!="") {
		for (i = 0; i < codeNumbers.length; i++) {
		var rep = new RegExp("\\u" + codeNumbers[i].toString(16), "g");
		output = output.replace(rep, characters[i]);
		}
		e.value = output;
	}  
}

function trim(str) {
  var temp = str;
  while(left(temp, 1)== " ") {temp = temp.substring(1)}
  while(right(temp, 1) == " ") {temp = temp.substring(0, temp.length - 1)}
  return temp;
}

function left(str, n) {
  return str.substring(0, n);
}

function right(str, n) {
  return str.substring(str.length - n);
}

function IsEmpty(str) {
  if (str == "" || str == null) {return true;}
  return false;	
}

function isValidPassword(fieldName1, str1, fieldName2, str2){
  var temp1 = trim(str1);
  if (temp1 == "" || temp1 == null){alert(fieldName1 + ' must be supplied'); return false;}

  if ((temp1.length >= 8)&& temp1.match(/[\w]/)&& temp1.match(/[a-zA-Z]+/)&& temp1.match(/[\d]+/))
  {
      var temp2 = trim(str2);
      if (temp2 == "" || temp2 == null){alert(fieldName2 + ' must be supplied'); return false;}

      if (temp1 != temp2){alert("Passwords must be identical."); return false;}  
      return true;
   }
  else {
    alert('Passwords must be eight or more characters in length and must contain at least one number and letter.');    
    return false;
  }
}

function IsAlphaNumericWithSpaceOptionalValue(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){return true;}
  if (!temp.match(/^[a-zA-Z0-9 ]+$/)){alert(fieldName + ' is not a valid alpha numeric value'); return false;}
  return true;
}

function IsAlphaNumericValue(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){alert(fieldName + ' must be supplied'); return false;}
  if (!temp.match(/^[a-zA-Z0-9]+$/)){alert(fieldName + ' is not a valid alpha numeric value'); return false;}
  return true;
}

function IsAlphaNumericWithSpaceValue(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){alert(fieldName + ' must be supplied'); return false;}
  if (!temp.match(/^[a-zA-Z0-9 ]+$/)){alert(fieldName + ' is not a valid alpha numeric value'); return false;}
  return true;
}

function IsValidKeyword(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){return true;}
  if (temp.match(/[^a-zA-Z0-9 &,_\-\.$:]/)){alert(fieldName + ' is not a valid alpha numeric value'); return false;}
  return true;
}

function IsValidStringValue(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){alert(fieldName + ' must be supplied'); return false;}
  if (temp.match(/<|>|[^\x20-\x7e]/)) {alert(fieldName + ' is not valid.' + ' Only alphanumeric characters and punctuation characters (excluding < and >) are allowed for this field.'); return false;}
  {return true;}
}

function IsNumericValue(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){alert(fieldName + ' must be supplied'); return false;}
  if (!temp.match(/^\d{1,}$/)) {alert(fieldName + ': wrong format'); return false;}
  return true;
}

function IsValidMultilineString(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){return true;}
  if (temp.match(/<|>|[^\x20-\x7e\t\r\n]/)){alert(fieldName + ' is not valid.' + ' Only alphanumeric characters, punctuation (excluding < and >), tab and newline characters are allowed for this field.'); return false;}
  return true;
}

function IsEmailAddress(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){alert(fieldName + ' must be supplied'); return false;}
  if (!temp.match(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/)) {alert(fieldName + ': wrong format'); return false;}
  return true;
}

function IsURL(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){alert(fieldName + ' must be supplied'); return false;}
  var v = new RegExp(); 
  v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
  if (!v.test(temp)) {alert(fieldName + ': not valid URL'); return false;}
  return true;
}

function IsFilePath(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){alert(fieldName + ' must be supplied'); return false;}
  if (!temp.match(/^(\\{2})[^\\][\w\s\\.]+$/)) {alert(fieldName + ': not valid path'); return false;}
  return true;
}

function IsFilePath_OptionalValue(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){return true;}
  if (!temp.match(/^(\\{2})[^\\][\w\s\\.]+$/)) {alert(fieldName + ': not valid file path'); return false;}
  return true;
}

function IsFileName(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){alert(fieldName + ' must be supplied'); return false;}
  if (temp.match(/[^a-zA-Z0-9 &_\-\.%]/)) {alert(fieldName + ' is not valid.' + ' Only alphanumeric and following characters ( _-.%) are allowed for this field.'); return false;}
  {return true;}
}

function IsFileName_OptionalValue(fieldName, str) {
  var temp = trim(str);
  if (temp == "" || temp == null){return true;}
  if (temp.match(/[^a-zA-Z0-9 &_\-\.%]/)) {alert(fieldName + ' is not valid.' + ' Only alphanumeric and following characters ( _-.%) are allowed for this field.'); return false;}
  {return true;}
}


function IsPhoneNumber(fieldName, str) {
  var s = str.replace(" ","");
  var temp = trim(s);
  if (temp == "" || temp == null){alert(fieldName + ' must be supplied'); return false;}
  if (!temp.match(/^\d{8,}$/)) {alert(fieldName + ': please enter valid Phone Number including an area code'); return false;}
  return true;
}

function CheckPageNo(){
	var msgErrPageNoRange = "Wrong page number.";
	var f = document.Form1;
	if (!IsNumericValue('Go to Page', f.txtGoToPage.value)){return false;}
	var pageno =  new Number(f.txtGoToPage.value);
	var total = new Number(f.hfldPageCount.value);
	if ((pageno > 0)&&(pageno <= total)){return true;}
	else {
		alert(msgErrPageNoRange);
		return false;
	}
}

function PageLinkClicked(pageno) {
	var page =  document.getElementById("txtGoToPage");
	page.value = pageno;
}
