// JavaScript Document



function isValid(input,type) {
  
  var ValidChars; 
  
  if (type == "alpha"){
    ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.,\'\ ";
  } else if (type == "num"){ 
    ValidChars = "0123456789";
  } else { 
    ValidChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*";
  }
  
  var IsTrue=true;
  var Char;
  
  for (i = 0; i < input.length && IsTrue == true; i++) { 
    Char = input.charAt(i); 
    if (ValidChars.indexOf(Char) == -1){
      IsTrue = false;
    }
  }
  
  if (input == ""){IsTrue = false;} 
  return IsTrue;
}


function openpopup(pop_page){

	var popurl="usatelpop.php?pg=" + pop_page ;
	if (pop_page == "int_rates"){
		p_width = 440;
	} else {
		p_width = 350;
	}
	
	winpops=window.open(popurl,"","width=" + p_width + ",scrollbars=YES,height=350")
	
}


function changeFocus(fField, nField){

    if (isValid(fField.value,"num") && fField.value.length == 3){
        nField.focus();
      nField.select();
    }
}


function checkPhone(){
	npa = document.foldertool.index_npa.value;
	nxx = document.foldertool.index_nxx.value;
	
	if (nxx.length == 3){
		if (!isValid(npa,"num")){
			alert("Please enter a valid Area Code");
			document.foldertool.index_npa.focus();
			document.foldertool.index_npa.select();
		} else if (!isValid(nxx,"num")){
			alert("Please enter a valid Exchange Number");
			document.foldertool.index_nxx.focus();
			document.foldertool.index_nxx.select();
		} else {
			if (npa == 207 && isValid(nxx,"num")) {
				var popurl="usatelpop.php?pg=MAINE_POP" ;
				winpops = window.open(popurl,"","width=350,scrollbars=YES,height=190")
			}		
			window.location.href = "index.php?index_npa=" + npa + "&index_nxx=" + nxx;			
		}
	} 
}
