function trimString(str)
{
	if (!(str == "")) {
	while('' + str.charAt(0) == ' '){
		str=str.substring(1,str.length);
	}
	}
	//take out trailing spaces
	if (!(str == "")) {
	while (str.charAt(str.length - 1) == ' '){
    	str = str.substring(0, str.length - 1);
	}
	}
	return str;
}
function validateSize(obj, limit) {
    
	var val = trimString(obj.value);
	if (val.length > limit){
		alert("You have exceeded the field limit of " + limit + " characters.");
		obj.value = val.substring(0, limit);
	}
}
function validateMulti(obj, limit){
    var sel = 0;
    var isValid = true;
    for (var i = 0; i < obj.length; i++){
        if (obj[i].selected){
            sel++;
            if(sel > limit){
                if (isValid){
                    //only show message once
                    alert("You can only select up to " + limit + " items to search on");
                    isValid = false;
                }
                obj[i].selected = false;
            }
        }
    }
}
function replaceDiacriticals(obj) {

    text = obj.value;
   
    if(text !="") {
    text = replace(text,unescape('%u2018'),unescape('%27'));
	text = replace(text,unescape('%u2019'),unescape('%27'));
    text = replace(text,unescape('%u201c'),unescape('%22'));
	text = replace(text,unescape('%u201d'),unescape('%22'));
	text = replace(text,unescape('%u2014'),'-');//replace em dash
	text = replace(text,unescape('%u2013'),'-');//replace en dash
	text = replace(text,unescape('%u2003'),' ');//replace em space
	text = replace(text,unescape('%u2003'),' ');//replace en space
	obj.value = text;
    }
}
function replace(string,text,by) {
    // Replaces text with by in string
    var strLength = string.length;
    var txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}
function checkWildCard(strng){
	if (strng.length > 0){
		var wildCard = "*";
		//var str = strng.replace(/%/g, "*");
		var arr = strng.split(wildCard);	
		if(arr.length > 1){			
			for (var y = 0; y < arr.length; y++){
			    if ((arr[y].length < 3) && (arr[y] != "")) {
			        ShowInvalidCharError();
					
					return false;
				}
			}
		}
		if (strng == "*") {
		    ShowInvalidCharError();
		   // alert("You must enter at least 3 concurrent characters when using the wildcard \"*\".");	
		    return false;    
		}    
	}
	return true;
}
function valid_email(str){
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
	if (!reg1.test(str) && reg2.test(str)) 
	{
		return true;
	}
	return false;
}
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
function validUserId(str){
	var myRegxp = /^[a-zA-Z0-9\(]+$/;	
	if ((str.length <= 6 || str.length >= 21)||(!(myRegxp.test(str))))
	{
		alert("The User ID you entered cannot be processed. Please enter a new User ID that is 7-20 characters long and has no punctuation, symbols, or spaces.");
		return false;
	}
	return true;
}
function validPwd(str){
	//var myRegxpw = /^[a-zA-Z0-9\!\*\@\#\_\$\&\(\)\+\,\.\/\:\;\=\?\~\[\"\^\¼]+$/;
	var myRegxpw = /^[a-zA-Z0-9\(]+$/;	
	if ((str.length <= 5 || str.length >= 11))
	{
		alert("The password you entered cannot be processed. Please enter a new password that is 6-10 characters long and has no punctuation, symbols, or spaces.");
		return false;
	}else if (!(myRegxpw.test(str))){
		alert("The password you entered cannot be processed. Please enter a new password.");
		return false;
	}
	return true;
/*
	var myRegxpw = /^[a-zA-Z0-9\!\*\@\#\_\$\&\(\)\+\,\.\/\:\;\=\?\~\[\"\^\¼]+$/;//1"
	if ((str.length <= 5 || str.length >= 11))					{
		alert("The password you entered cannot be processed.\r\nPlease enter a new password that is 6-10 characters long.");
		return false;
	}else if (!(myRegxpw.test(str))){
		alert("The password you entered cannot be processed.\r\nPlease enter a new password.");
		return false;
	}
	var hasNum = true;
	var hasAlph = true;
	var lastAlpha = true;
	var regNum = /[0-9]+/;
	var regAlph = /[a-zA-Z]+/ ;
	if (!(regNum.test(str))){
		alert("The password you entered cannot be processed.\r\nPlease enter a new password containing at least 1 number.");
		return false;
	}
	if (!(regAlph.test(str))){
		alert("The password you entered cannot be processed.\r\nPlease enter a new password containing at least 1 letter.");
		return false;
	}
	if (!(regAlph.test(str.charAt(str.length - 1)))){
		alert("The password you entered cannot be processed.\r\nPlease enter a new password with a letter as your last character.");
		return false;
	}
	return true;
	*/
}

function validateContactUs(){
	var doc = document.frmContactUS;
	// trim all fields
	//user modified for update registration form
	doc.txtSenderName.value		= trimString(doc.txtSenderName.value);
	doc.txtSenderEmail.value	= trimString(doc.txtSenderEmail.value);
	doc.txtComments.value	    = trimString(doc.txtComments.value);
	
	var sname		= doc.txtSenderName.value;
	var email  	= doc.txtSenderEmail.value;
	var comments	= doc.txtComments.value;
	var msg = "";
	if (sname == "")
		msg += "Sender Name\r\n";
	if (email == "")
		msg += "Email\r\n";
	if (comments == "")
		msg += "Comments\r\n";
	
	if (msg != ""){
		msg = "The following are required fields.\r\n\r\n" + msg;
		alert(msg);
		return false;
	}
	if(!(valid_email(email))){
		alert("Please enter a valid email address.");
		doc.txtSenderEmail.focus();
		return false;
	}
	return true;
}
// window.onload = regInit;


