String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}

var digits = "0123456789";
var phoneNumberDelimiters = ".()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function validPhone(objField)
{
	Phone = objField;
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number");
		Phone.value="";
		Phone.select();
		Phone.focus();
		return false;
	}
}

function vPhone(objField){
	var re
	var y = objField.id
	var x = document.all[objField.name]
	switch (y){
	case "Area Code":
	re = /^[0,1,2,3,4,5,6,7,8,9]{3}$/
	if (re.test(x.value) == false){
		alert("Invalid " + y + ". Must be three numbers like 123")
		document.abcapp[objField.name].value=""
		document.abcapp[objField.name].select()
		document.abcapp[objField.name].focus()
		return false	
	}
		break	
	case "Phone Number":
	re = /^[0,1,2,3,4,5,6,7,8,9]{3}[-][0,1,2,3,4,5,6,7,8,9]{4}$/
	if (re.test(x.value) == false){
		alert("Invalid " + y + " format should be like 123-1234")
		document.abcapp[objField.name].value=""
		document.abcapp[objField.name].select()
		document.abcapp[objField.name].focus()
		return false
	}
		break
	default:
		
}
}


function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function vZIP(objField) {
var valid = "0123456789-";
var hyphencount = 0;
x=objField.value

if (x.length!=5 && x.length!=10) {
alert("Please enter your 5 digit or 5 digit+4 zip code. format: 97045 or 97045-6789");
document.all[objField.name].select()
document.all[objField.name].focus()
return false;
}
for (var i=0; i < x.length; i++) {
temp = "" + x.substring(i, i+1);
if (temp == "-") hyphencount++;
if (valid.indexOf(temp) == "-1") {
alert("Invalid characters in your zip code.  Please try again.");
document.all[objField.name].select()
document.all[objField.name].focus()
return false;
}
if ((hyphencount > 1) || ((x.length==10) && ""+x.charAt(5)!="-")) {
alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
document.all[objField.name].select()
document.all[objField.name].focus()
return false;
   }
}
return true;
}

function vName(objField){
	var re
	var y = objField.name
	var x = document.all[y]
	re = /^([A-Za-z' -.]{1,25}|[.]{0,1})$/
	if(objField.value.length != 0){
		if (re.test(x.value) == false){
			alert("Invalid " + y)
			x.value = ""
			x.select()
			x.focus()
			return false
		}
		else{
			changeCase(objField)
		}
	}
	else{
		alert(y+" is required")
		x.select()
		x.focus()
		return false
	}
}

function getSelText()
{
var y = document.getElementById("Commission")
document.abcapp["BoardName"].value = y.options[y.selectedIndex].text
}

function changeCase(objField) {
var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = objField.value;
strLen = tmpStr.length;
if (strLen > 0)  {
for (index = 0; index < strLen; index++)  {
if (index == 0)  {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(index, index+1);
if (tmpChar == " " && index < (strLen-1))  {
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
preString = tmpStr.substring(0, index+1);
postString = tmpStr.substring(index+2,strLen);
tmpStr = preString + tmpChar + postString;
         }
      }
   }
}
objField.value = tmpStr;
}

function vMail(objField) {
	var x = document.all[objField.name]

if(-1 == x.value.indexOf("@")) { 
       x.value=""; 
       x.select(); 
       x.focus(); 
       alert("Invalid email address"); 
       return false; 
       }
    if(-1 != x.value.indexOf(",")) { 
       x.value=""; 
       x.select(); 
       x.focus(); 
       alert("Your email must not have a ',' in it"); 
       return false; 
       }
    if(-1 != x.value.indexOf("#")) { 
       x.value=""; 
       x.select(); 
       x.focus(); 
       alert("Your email must not have an '#' in it." ); 
       return false; 
       }
    if(-1 != x.value.indexOf("!")) { 
       x.value=""; 
	   x.select(); 
       x.focus(); 
       alert("Your email must not have a '!' in it." ); 
       return false; 
       }
    if(-1 != x.value.indexOf(" ")) { 
       x.value=""; 
       x.select(); 
       x.focus(); 
       alert("Your email must not have a space in it." ); 
       return false; 
       }
    if(x.value.length == (x.value.indexOf("@")+1) ) {
       alert("Invalid email address.");
       x.value=""; 
       x.select(); 
       x.focus();
       return false;
       }

    if(x.value.length == 0) { 
      x.value=""; 
	  x.select(); 
      x.focus(); 
      alert("Please enter your email."); 
      return false; 
      }

    return true;
  }

function refresh(){
location.reload()
}

function reqInput(objField){
x=objField.name
y=objField.id
if(document.abcapp[x].value==""){
	alert(x+" is required")
	this.select()
	this.focus()
	return false
}
}

function chkPage(sPage){
var x = document.all[sPage.name]
		if(x.f_firstname.value == ""){
			alert("First Name is required")
			x.f_firstname.select()
			x.f_firstname.focus()
			return false
		}
		else if(x.f_lastname.value == ""){
			alert("Last Name is required")
			x.f_lastname.select()
			x.f_lastname.focus()
			return false
		}
		else if(x.f_email.value == ""){
			alert("Email is required")
			x.f_email.select()
			x.f_email.focus()
			return false
		}

}

function spChars(objField){
	sText = ""
	if(objField.value != ""){
		sText = objField.value
		if(objField.id == "CondList"){
			while(sText.indexOf("\n") != -1){
				sText = sText.replace("\n","<li>")
			}
			sText = "<li>" + sText 
		}else{
			while(sText.indexOf("\n") != -1){
				sText = sText.replace("\n","<br>")
			}
		}
	}
	return sText
}

