var isNN = (navigator.appName.indexOf("Netscape")!=-1);

function fnTab(input,len, e){
  var keyCode = (isNN)?e.which:e.keyCode; 
  var filter = (isNN)?[0,8,9]:[0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)){
    input.value = input.value.slice(0,len);
    input.form[(getIndex(input)+1)%input.form.length].focus();
  }
  function containsElement(arr, ele){
    var found = false, index = 0;
    while(!found && index < arr.length)
      if(arr[index]==ele)
        found = true;
      else
        index++;
    return found;
  }
  function getIndex(input){
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index==-1)
      if (input.form[i] == input)index = i;
      else i++;
    return index;
  }
  return true;
}

function fnValidNumericField(field, fieldSize, fieldDisplayName) {
	if (field.value == "" ) {alert("Please enter " + fieldDisplayName + ".");}
	else if (field.value.length < fieldSize) {alert(fieldDisplayName + " is incomplete.");}
	else if (!fnOnlyDigits(field.value)) {alert(fieldDisplayName + " is incorrect.\nPlease enter only numbers.");}
	else{return (true);}

	field.focus();
	return (false);
}

function fnY2k(number) { return (number < 1000) ? number + 1900 : number; }
function fnValidDate (thisDate,sep) {
	if (thisDate.length == 10) {
		if (thisDate.substring(2,3) == sep && thisDate.substring(5,6) == sep) {
			var month  = thisDate.substring(0,2);
			var date = thisDate.substring(3,5);
			var year  = thisDate.substring(6,10);

			var test = new Date(year,month-1,date);

			if (year == fnY2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
				why = '';
				return true;
			}else {
				why = 'the date is invalid';
				return false;
			}
		}else {
			why = 'you can only use slashes \( \/\) between the numbers';
			return false;
		}
	}else {
		why = 'the date is not long enough';
		return false;
	}
}



function fnOnlyDigits(numberStr) {
	var validChars = "0123456789";
	for (var i=0; i<numberStr.length; i++) {
		if (validChars.indexOf(numberStr.charAt(i)) == "-1")
			return (false);
	}
	return (true);
}

function fnValidEmail(tfName) {
	var GoodChars = "@_-.:/ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var UpperEmail = tfName.value.toUpperCase()
	var ValidChars = true;
	
	for (tfCharNum = 0; tfCharNum > tfName.value.length; tfCharNum++) {
		Char = UpperEmail.charAt(tfCharNum);
		for (gcCharNum = 0;  gcCharNum < GoodChars.length;  gcCharNum++) {
				if (Char == GoodChars.charAt(gcCharNum))
				break;
		}
					
		if (gcCharNum == GoodChars.length)   {
			ValidChars = false;
			break;
   		}
	}
	
	if (!ValidChars || tfName.value.length < 7 || tfName.value.indexOf("@") == "-1" ||
		tfName.value.indexOf(".") == "-1" || tfName.value.indexOf("@") != tfName.value.lastIndexOf("@")) {
			return (false);
	}
	return (true);
}




function fnCertDetails(){	
	var url = 'http://www.phonedog.com/content/redirect.aspx?id=73'	
	thewindow = window.open(url,"certWin", config="height=512,width=500,toolbar=no,menubar=no,scrollbars=no,resizable=yes,location=no,directories=no,status=no");
}

function fnFindPlan(){
	var fm = document.forms['frmStates'];
	var sel = fm.s.selectedIndex;
	
	if(sel == 0){
		alert('Please select your state...');
		fm.s.focus();
		return false;
	}
	else
		return true;
}

function fnFindPlan2(){
	var fm = document.forms['frmStates2'];
	var sel = fm.s.selectedIndex;
	
	if(sel == 0){
		alert('Please select your state...');
		fm.s.focus();
		return false;
	}
	else
		return true;
}

function fnFindCell(){
	var fm = document.forms['frmZip'];
	var sel = fm.zip.value;
	
	if(sel == ""){
		alert('Please enter your zip code and click the "Go" button.');
		fm.zip.focus();
		return false;
	}
	else
		return true;
}

function fnLLDFindPlan(){
	var fm = document.forms['frmLLDStates'];
	var rt = 0;
	
	if(fm.a.value == ""){alert("Please enter your Area Code");fm.a.focus();return false;}
	if(fm.p.value == ""){alert("Please enter your phone number's Prefix");fm.p.focus();return false;}
	if(!fnValidNumericField(fm.a,3,"Your Area Code")){fm.a.focus();return false;}
	if(!fnValidNumericField(fm.p,3,"Your Phone Number's Prefix")){fm.p.focus();return false;}
	if(fm.a.value.length < 3){alert("Your phone number's Area Code is incomplete.");fm.a.focus();return false;}
	if(fm.p.value.length < 3){alert("Your phone number's Prefix is incomplete.");fm.p.focus();return false;}
}

function fnLDPMFindPlan(){
	var fm = document.forms['frmLDPMStates'];
	var rt = 0;
	
	if(fm.a.value == ""){alert("Please enter your Area Code");fm.a.focus();return false;}
	if(fm.p.value == ""){alert("Please enter your phone number's Prefix");fm.p.focus();return false;}
	if(!fnValidNumericField(fm.a,3,"Your Area Code")){fm.a.focus();return false;}
	if(!fnValidNumericField(fm.p,3,"Your Phone Number's Prefix")){fm.p.focus();return false;}
	if(fm.a.value.length < 3){alert("Your phone number's Area Code is incomplete.");fm.a.focus();return false;}
	if(fm.p.value.length < 3){alert("Your phone number's Prefix is incomplete.");fm.p.focus();return false;}
}

function fnVoipFindPlan(){
	return true;
}



function fnOpenPopup(url,theWidth,theHeight){
	var theTop;
	var theLeft;
	
    if (document.all){
		theTop=(screen.height/2)-(theHeight/2);
		theLeft=(screen.width/2)-(theWidth/2)+175;
	}else{
		theTop=100;
		theLeft=5
		00;
	}
	
	var features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",toolbar=0,location=0,directories=0,resizable=1,status=0,menubar=0,scrollbars=no";
	theWin=window.open(url,'',features);
}

function fnOpenPopupScrolling(url,theWidth,theHeight){
	var theTop;
	var theLeft;
	
    if (document.all){
		theTop=(screen.height/2)-(theHeight/2);
		theLeft=(screen.width/2)-(theWidth/2)+175;
	}else{
		theTop=100;
		theLeft=5
		00;
	}

	var features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",toolbar=0,location=0,directories=0,resizable=1,status=0,menubar=0,scrollbars=yes";
	theWin=window.open(url,'',features);
}

function fnPop(url,theWidth,theHeight,theTop,theLeft,scrollbars){
	if(scrollbars == 1)
		scrollbars = 'yes';
	else
		scrollbars = 'no';
			
	var features='height='+theHeight+',width='+theWidth+',top='+theTop+',left='+theLeft+",toolbar=0,location=0,directories=0,resizable=1,status=0,menubar=0,scrollbars="+scrollbars;
	theWin=window.open(url,'popWin',features);
}

function fnBBB(){
alert('hr');
	var features='height=400,width=500,top=0,left=0,toolbar=0,location=1,directories=0,resizable=1,status=0,menubar=0,scrollbars=yes';	
	theWin=window.open('http://www.phonedog.com/content/redirect.aspx?id=72','BBBWin',features);
}

function fnBBB(path){
	var features='height=400,width=500,top=0,left=0,toolbar=0,location=1,directories=0,resizable=1,status=0,menubar=0,scrollbars=yes';
	theWin=window.open('http://www.phonedog.com/content/redirect.aspx?id=72','BBBWin',features);
}

function fnLoadWin(){
	if(window.closed){
		fnOpenPopupScrolling("ReferAFriendPopUp.aspx",500,450);
	}
}

function fnBookmark(url,title){
	if((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)){
		window.external.AddFavorite(url,title);
	}else{
		var msg = "Don't forget to bookmark us!";
		if(navigator.appName == "Netscape") msg += " (CTRL-D)";
			document.write(msg);
	}
}


