/* 
 ****************************************************
 * isNumeric
 * verifies it's a number
 ****************************************************
*/
  function isNumeric(numIn) {
    for (i=0;i<numIn.length;i++) {
      tempStr = numIn.substr(i,1)
      if (tempStr == "0" || tempStr == "1" || tempStr == "2" || tempStr == "3"
	    || tempStr == "4" || tempStr == "5" || tempStr == "6" || tempStr == "7"
	    || tempStr == "8" || tempStr == "9") {
	    tempStr = tempStr;
	  }else{
	    return false;
	  }
	}
	return true;
  }
  
/* 
 ****************************************************
 * isAlpha
 * verifies it's a character
 ****************************************************
*/
  function isAlpha(wordIn) {
    for (i=0;i<wordIn.length;i++) {
      tempStr = wordIn.substr(i,1).toUpperCase();
      if (tempStr == "A" || tempStr == "1" || tempStr == "2" || tempStr == "3"
	    || tempStr == "4" || tempStr == "5" || tempStr == "6" || tempStr == "7"
	    || tempStr == "8" || tempStr == "9") {
	    tempStr = tempStr;
	  }else{
	    return false;
	  }
	}
	return true;
  }
  
/* 
 ****************************************************
 * valid800
 * Verify phone number for 800 nums w/out 1 and any
 * other chars
 ****************************************************
*/ 
  function is800(phone){
    var tempStr;
    
    if (phone.length != 10 || phone.substr(0,1) != 8){
      return false
    }
    for (i=0;i<10;i++) {
      tempStr = phone.substr(i,1)
      if (tempStr == "0" || tempStr == "1" || tempStr == "2" || tempStr == "3"
	    || tempStr == "4" || tempStr == "5" || tempStr == "6" || tempStr == "7"
	    || tempStr == "8" || tempStr == "9") {
	    tempStr = tempStr
	  }else{
	    return false
	  }
	}
	return true
  }
  
/* 
 ****************************************************
 * validPhone
 * Verify phone number in xxxxxxxxxx,(xxx)xxx-xxxx,
 * xxx-xxx-xxxx, (xxx) xxx-xxxx
 * other chars
 ****************************************************

  function isPhoneFmt(phone){
    var tempStr;
    
    if (phone.length != 10 && (phone.length <= 12 && phone.length >= 14)){
      return false;
    }else if (phone.length == 10) {
      //xxxxxxxxxx
      if (! isNumeric(phone)) {
        return false;
      }
    }else if (phone.length == 12) {
      //xxx-xxx-xxxx
      if (! isNumeric(phone.substr(0,3)) || phone.substr(3,1) != "-" ||
        ! isNumeric(phone.substr(4,3)) || phone.substr(7,1) != "-" ||
        ! isNumeric(phone.substr(8,4))) {
          return false;
      }
    }else if (phone.length == 13) {
      //(xxx)xxx-xxxx
      if (phone.substr(0,1) != "(" || ! isNumeric(phone.substr(1,3)) ||
        phone.substr(4,1) != ")" || ! isNumeric(phone.substr(5,3)) ||
        phone.substr(8,1) != "-" || ! isNumeric(phone.substr(9,4))) {
        return false;
      }
    }else if (phone.length == 14) {
      //(xxx) xxx-xxxx
      if (phone.substr(0,1) != "(" || ! isNumeric(phone.substr(1,3)) ||
        phone.substr(4,1) != ")" || phone.substr(5,1) != " " || ! isNumeric(phone.substr(6,3)) ||
        phone.substr(9,1) != "-" || ! isNumeric(phone.substr(10,4))) {
        return false;
      }
	}
	return true;
  }*/ 

function isPhone (phoneIn) {
  if (phoneIn.length < 6 || phoneIn.length > 16 || ! isNumeric(phoneIn) ||
    (phoneIn.substr(0,3) != "011" && phoneIn.substr(0,1) != "1") ||
    (phoneIn.substr(0,1) == "1" && phoneIn.length != 11)) {
    return false;
  }else{
    return true;
  }
}
    
/* 
 ****************************************************
 * validEmail
 * Verify to some extent email address 
 ****************************************************
*/
  function isEmail(email) {
    invalidChars = " /:,;"
	if (email == "") {
	  return false
	}
	for (i=0; i<invalidChars.length; i++) {
	  badChar = invalidChars.charAt(i)
	  if (email.indexOf(badChar,0) != -1) {
		return false
	  }
	}
	atPos = email.indexOf("@",1)
	if (atPos == -1) {
      return false
	}
	if (email.indexOf("@",atPos+1) != -1) {
	  return false
	}
    periodPos = email.indexOf(".",atPos)
    if (periodPos == -1) {
      return false
	}
	if (periodPos+2 > email.length)	{
	  return false
	}
      return true
  }
  
/* 
 ****************************************************
 * validPswd
 * Verify security code, 4 digits
 ****************************************************
*/ 
  function validPswd(password) {
    var tempStr;
	for (i=0; i<4; i++) {
	  tempStr = password.substr(i,1)
	  if (i==0) {
		if (tempStr =="*" || tempStr == "#" || tempStr == "0") {
		  return false
		}
	  }
	  if (tempStr == "0" || tempStr == "1" || tempStr == "2" || tempStr == "3"
	    || tempStr == "4" || tempStr == "5" || tempStr == "6" || tempStr == "7"
	    || tempStr == "8" || tempStr == "9" || tempStr == "*") {
	    tempStr = tempStr
	  }else{
	    return false
	  }
	}
	return true 
  } 

/* 
 ****************************************************
 * validZip
 * Verify zip code
 ****************************************************
*/ 
  function isZip(zip) {
    var tempStr;
    if (zip.length != 5 && zip.length != 10) {
      //if it isn't xxxxx or xxxxx-xxxx format
      return false;
    }else if (zip.length == 5) {
      if (!isNumeric(zip.substr(0,5))) {
        return false; 
      }
    }else if (zip.length == 10) {
      if (zip.substr(5,1) != "-" || ! isNumeric(zip.substr(6,4))) {
        return false;
      }
    } 
	return true; 
  } 
  
/* 
 ****************************************************
 * isDate
 * verifies it's a valid date
 ****************************************************
*/
  function isDate (myDate,sep) {
  // checks if date passed is in valid mm/dd/yyyy format
    
    if (myDate.length == 10) {
      if (myDate.substr(2,1) == sep && myDate.substr(5,1) == sep) {
        var month  = myDate.substr(0,2);
        var day = myDate.substr(3,2);
        var year  = myDate.substr(6,4);
        var test = new Date(year,month-1,day);
        if ((year == test.getFullYear()) && (month-1 == test.getMonth()) && (day == test.getDate())) {
          return true;
        }else{
          return false;
        }
      }else{
        return false;
      }
    }else{
      return false;
    }
 }
  
/* 
 ****************************************************
 * openNew
 * Open new window with specified URL and size
 ****************************************************
*/
  function openNew(urlIn,widthIn,heightIn){
    window.open(urlIn,"_blank","resizable=1,scrollbars=yes,width=" + widthIn + 
      ",height=" + heightIn);
  }
