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;
}

// Utility functions for form validation
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 entered 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 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=500,width=600,top=0,left=0,toolbar=0,location=1,directories=0,resizable=1,status=0,menubar=0,scrollbars=yes';	
theWin=window.open('http://www.satellitetvdeal.com/refer_friend.htm','BBBWin',features);
}

function fnBBB(path){
var features='height=500,width=600,top=0,left=0,toolbar=0,location=1,directories=0,resizable=1,status=0,menubar=0,scrollbars=yes';
theWin=window.open('http://www.satellitetvdeal.com/refer_friend.htm','BBBWin',features);
}

function fnLoadWin(){
if(window.closed){
fnOpenPopupScrolling("refer_friend.htm",600,500);
}
}

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);
}
}

