// -----------------------------------------------------------------------------
// Browser Sniffer
// -----------------------------------------------------------------------------
// sniffer_version = "1.1"
var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();

// *** BROWSER VERSION *********************************************************
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);

var iePos  = appVer.indexOf('msie');
if (iePos !=-1) {
   is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)));
   is_major = parseInt(is_minor);
}              

var is_getElementById   = (document.getElementById) ? "true" : "false";
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
var is_documentElement = (document.documentElement) ? "true" : "false";

var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));

if ((navigator.vendor) && ((navigator.vendor=="Netscape6") || (navigator.vendor=="Netscape")) && (is_nav)) {
   is_major = parseInt(navigator.vendorSub);
   is_minor = parseFloat(navigator.vendorSub);
}

var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up 	= (is_nav && is_minor >= 4); 
var is_navonly	= (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
var is_nav6up 	= (is_nav && is_minor >= 6);
var is_nav5up 	= (is_nav && is_minor >= 5);
var is_nav7up 	= (is_nav && is_minor >= 7);
var is_ie   	= ((iePos!=-1));
var is_ie4   	= (is_ie && is_major == 4);
var is_ie4up 	= (is_ie && is_minor >= 4);
var is_ie5up 	= (is_ie && is_minor >= 5);
var is_ie5_5  	= (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie6up 	= (is_ie && is_minor >= 6);

// *** PLATFORM *******************************************************************	
var is_win   		= ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_win95 		= ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));
var is_winme 		= ((agt.indexOf("win 9x 4.90")!=-1));  
var is_win2k 		= ((agt.indexOf("windows nt 5.0")!=-1) || (agt.indexOf("windows 2000")!=-1));
var is_winxp 		= ((agt.indexOf("windows nt 5.1")!=-1) || (agt.indexOf("windows xp")!=-1));
var is_winxp_sp2 	= ((is_winxp) && (agt.indexOf("sv1")!=-1));	//Currently only works in IE
var is_win98 		= ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
var is_winnt 		= ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
var is_win32 		= (is_win95 || is_winnt || is_win98 || ((is_major >= 4) && (navigator.platform == "Win32")) || (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));
var is_mac   		= (agt.indexOf("mac")!=-1);


// -----------------------------------------------------------------------------
// Image Rollover Functions
// -----------------------------------------------------------------------------
// old school
function rollOver(img_name, img_src)
{
	if (document.images)
	{
		document [img_name].src = img_src;
	}
}

// new DOM hotness
function imgSwap( imgID, imgURL )
{
	return document.getElementById( imgID ).src = imgURL;
}

// -----------------------------------------------------------------------------
// window popup functions
// -----------------------------------------------------------------------------
// General Purpose popUp Script
// usage: (#, #, 'name', 'url', 1/0, 1/0) where the last 2 parameters must be a 1 or 0.
function popUpWindow (window_width, window_height, window_name, window_url, _resizeable, _scrollbars )
{
	var options="resizable="+_resizeable+",scrollbars="+_scrollbars+",width="+window_width+",height="+window_height+"";
	popupWin=window.open(window_url, window_name, options);
	return false;
}

// popup function places window into lower left corner.
// usage: (#, #, 'name', 'url', 1/0, 1/0) where the last 2 parameters must be a 1 or 0.
function popUpWindowMarketing (window_width, window_height, window_name, window_url, _resizeable, _scrollbars )
{
	var top;
	var left;
	
	top = screen.height - window_height - 40;
	left = 0;
	
	if (top < 0) { top = 0; }
	
	var options="top=" + top +
							",left=" + left +
							",resizable=" + _resizeable +
							",scrollbars="+ _scrollbars +
							",width=" + window_width + 
							",height=" + window_height + "";
							
	popUpWinMarketing = window.open(window_url, window_name, options);
	return false;
}

// popup function places window into upper right corner.
// usage: (#, #, 'name', 'url', 1/0, 1/0) where the last 2 parameters must be a 1 or 0.
function popUpWindowOrdering (window_width, window_height, window_name, window_url, _resizeable, _scrollbars )
{
	var top;
	var left;
	
	top = 0;
	left = screen.width - window_width - 10;

	if (left < 0) { left = 0; }

	var options="top=" + top +
							",left=" + left +
							",resizable=" + _resizeable +
							",scrollbars="+ _scrollbars +
							",width=" + window_width + 
							",height=" + window_height + "";
							
	popUpWinOrdering = window.open(window_url, window_name, options);
	return false;
}

// loads URL into window that oppened popup
// usage: openerLink('URL');
function openerLink(link_location)
{
	opener.location.href=link_location;
	return false;
}

// -----------------------------------------------------------------------------
// loopqual autotab functions
// -----------------------------------------------------------------------------
// checks if keycode is a number
function isNumericLQ()
{
	if (is_nav)
	{
		return;
	}
	else
	{
		get=event.keyCode;
		if((get>47&&get<58)||(get==8)||(get==9)) 
		{
			return true;
		}
		else
		{
			event.returnValue=false;
		}
	}
}

// automatically changes focus to linkItem once maxLength of hItem is reached
// DON'T USE ON NUMBER/LINE, AS THE RE-FOCUS TO THE GO BUTTON DOESN'T WORK!
function AutoTabLQ(hItem, maxLength, linkItem )
{	
	isNumericLQ();
	if (is_mac)
	{
		return;
	}
	else
	{
		if (is_ie)
		{
			var vKeyCode,oItem;
			oItem = eval(linkItem);	
			vKeyCode = window.event.keyCode
			if(vKeyCode==9 && window.event.shiftKey){ return; }
			switch(window.event.keyCode)
			{
				case 37 : return;
				case 39 : return;
				case 16 : return;
				case 46 : return;
			}
			if (window.event.keyCode != 9 )
			{
				if( typeof(oItem) == "object" )
				{					
					if(bAutotab && (String(oItem.value).length ==0) && (String(hItem.value).length == maxLength) && (window.event.keyCode != 8))
					{
						oItem.focus();
					}
				}
			}
		}
		bAutotab = true;
	}
}

// turns autotab on
bAutotab = true;

// turns autotab off
function stopAutoTabLQ()
{
	bAutotab = false;
}

// -----------------------------------------------------------------------------
// Flash Player version sniffer
// -----------------------------------------------------------------------------
var flashTargetMajor
if (flashTargetMajor == "")
{
	flashTargetMajor = 5;
}
var flashTargetMinor = 0;	// The release number (example where 79 is the minor version: 6,0,79,0) - leave as 0 if uncertain

var hasFlash = false,
    hasActiveX = false,
    navPlugins = (navigator.plugins.length > 0),
    ieVer = parseFloat(navigator.appVersion.split("MSIE")[1]);

var fullVersion, majorVersion, minorVersion;

if(navPlugins || (is_ie && is_mac && ieVer >= 5)) {
	var plugin = navigator.plugins["Shockwave Flash"];
	var pluginDescription = plugin.description.split(" ");
	for(var i=0; i<pluginDescription.length; i++) {
		if(!isNaN(parseInt(pluginDescription[i]))) {
			majorVersion = parseInt(pluginDescription[i]);
			minorVersion = parseInt(plugin.description.split("r")[1]);
			break;
		}
	}
	if(majorVersion >= flashTargetMajor && minorVersion >= flashTargetMinor) hasFlash = true;
}
else if(is_win && is_ie) {
	document.write('<script language="VBScript"\>\n');
	document.write('function isHere(chk)\n');
	document.write('  isHere = false\n');
	document.write('  on error resume next\n');
	document.write('  if ScriptEngineMajorVersion > 1 then\n');
	document.write('    isHere = IsObject(CreateObject(chk))\n');
	document.write('  end if\n');
	document.write('end function\n');
	document.write('</script\>');

	//try {
		hasActiveX = isHere("msxml");
		if (!hasActiveX) {
			hasActiveX = isHere("Microsoft.ActiveXPlugin.1");
		}
	//} catch(e) {
	//	hasActiveX = false;
	//}
	if(hasActiveX) {
		for(var i=2; i<=flashTargetMajor; i++) {
			if(isHere("ShockwaveFlash.ShockwaveFlash."+i)) majorVersion = i;
		}
	}
	minorVersion = 0;
	if(majorVersion >= flashTargetMajor) hasFlash = true;
}
fullVersion = majorVersion+",0,"+minorVersion+",0";

// -----------------------------------------------------------------------------
// misc EBIZ functions, schedule for deletion
// -----------------------------------------------------------------------------
function Trim(str)
{
	var temp = "";
	temp = str;
	temp = temp.replace (/^\s*/, "");
	temp = temp.replace (/\s*$/, "");
	return temp;
}

function Enter1(FormName)
{
	if (globalSearch(FormName) == true)
	{
		return true;
	}
	else
	{
		return false;
	}

}

function globalSearch(FormName) 
{
	var path = new String();
	var SearchString = new String();
	path = document.location.pathname;
	var qry;
	var SelectiveSearch ;

	for(s=0;s<document.formSearch.elements.length;s++)
	{
		if (document.formSearch.elements[s].name == "SearchText")
		{
			var indT = s;
		}

		if (document.formSearch.elements[s].name == "QueryText")                                                        
		{
			var indQ = s;
		}

		if (document.formSearch.elements[s].name == "Coll")                                                        
		{
			var C1 = s;
		}

		if (document.formSearch.elements[s].name == "Coll2")                                                        
		{
			var C2 = s;
		}

		if (document.formSearch.elements[s].name == "site")                                                        
		{
			var se = s;
		}

		if (document.formSearch.elements[s].name == "kb")                                                        
		{
			var kb = s;
		}

		if (document.formSearch.elements[s].name == "box")                                                        
		{
			var B = s;
		}

		if (document.formSearch.elements[s].name == "ps")                                                        
		{
			var ps = s;
		}

		if (document.formSearch.elements[s].name == "om")                                                        
		{
			var om = s;
		}

		if (document.formSearch.elements[s].name == "cs")                                                        
		{
			var cs = s;
		}
	} 
	document.formSearch.elements[C2].value = "home_products, home_support, business_products, business_support";
	document.formSearch.elements[C1].value = "Enterprise, Federal, Wholesale, Corporate Information, LearningCorner";
	SelectiveSearch = "0"
	document.formSearch.elements[B].value = "1";

	SearchString = Trim(document.formSearch.elements[indT].value);

	if(SearchString != "" && SearchString != "keyword")
	{
		document.formSearch.elements[indQ].value = document.formSearch.elements[indT].value;
		document.formSearch.action = FormName;
		return true;
	}
	else
	{
		alert("Please type in something to search for.");
		document.formSearch.elements[indT].focus();
	}
	
	return false;
}

// -----------------------------------------------------------------------------
// XSS guard functions
// -----------------------------------------------------------------------------
// implemented on the client side (in case the hacker uses the form fields???)
function cleanString(InStr){
    InStr = InStr.replace(/\</g,"");
    InStr = InStr.replace(/\>/g,"");
    InStr = InStr.replace(/\"/g,"");
    InStr = InStr.replace(/\'/g,"");
    InStr = InStr.replace(/\%/g,"");
    InStr = InStr.replace(/\;/g,"");
    InStr = InStr.replace(/\(/g,"");
    InStr = InStr.replace(/\)/g,"");
    InStr = InStr.replace(/\&/g,"");
    InStr = InStr.replace(/\+/g,"");
    InStr = InStr.replace(/\=/g,"");
    return InStr;
}

// -----------------------------------------------------------------------------
// validation functions
// -----------------------------------------------------------------------------
// Error Messages
var errorMessageDisplayed = '';
var errorMessage = 'Follow the directions below for DSL address qualification.\n\n';
var errorStreetNumber = 'Please enter a valid Street Number.\n';
var errorStreet = 'Please enter a valid Street.\n';
var errorState = 'Please choose a valid State.\n';
var errorCity = 'Please enter a valid City.\n';
var errorZIP = 'Please enter a valid ZIP Code.\n';


domain_error="Please enter a valid Domain Name";
email_error="Please enter a valid E-Mail address";
phone_error="Please enter a valid 10 digit phone number";
first6_error="Please enter a valid area code and the first 3 digits of your phone number";
zip_error="Please enter a valid 5 or 9 digit zip code";
rep_id_error="The Rep I.D. is not in the correct format, please check your I.D. and re-enter."

// Validates address form (dry loopqual)
function checkAddressForm()
{
	
	var error_count = 0;
	errorMessageDisplayed = errorMessage;
	
	if (document.forms.addressentry.txt_address_streetnumber.value == '')
	{
		error_count++;
		errorMessageDisplayed += errorStreetNumber;
	}
	
	if (document.forms.addressentry.txt_address_street.value == '')
	{
		error_count++;
		errorMessageDisplayed += errorStreet;
	}

	if (document.forms.addressentry.txt_address_city.value == '')
	{
		error_count++;
		errorMessageDisplayed += errorCity;
	}
							
	if (document.forms.addressentry.dd_address_state.value == '')
	{
		error_count++;
		errorMessageDisplayed += errorState;
	}
	
	if (document.forms.addressentry.txt_address_zip.value == '')
	{
		error_count++;
		errorMessageDisplayed += errorZIP;
	}

	if (error_count > 0)
	{
		alert (errorMessageDisplayed);
		return false;
	}
	else
	{
		return true;
	}
}

// Validates LoopQuals on Bridge Pages (standard and RepID versions)
function validateLoopQual(){
	var valid_form = 0;
	
	valid_form=validatePhoneNumber(document.form1.txtAreaCode.value, document.form1.txtPrefix.value, document.form1.txtPhoneNumber.value);
	
	if(valid_form){
		return true;
	}else{
		alert(phone_error);
		return false;
	}
}

//valid only if phone number AND Rep ID are properly formatted (or Rep ID is blank)
function validateRepLoopQual(){
	var valid_form = 0;
	var error_str = "";

	var rep_id=document.form1.repid;
	
	if (validatePhoneNumber(document.form1.txtAreaCode.value, document.form1.txtPrefix.value, document.form1.txtPhoneNumber.value)){
		valid_form = 1;
	}else{
		error_str = phone_error;
	}

	if (rep_id.value != ""){
		if (rep_id.value.length == 6){
			if(validateRepIDFormat(rep_id.value)){
				valid_form = 1;
			}else{
				valid_form = 0;
				error_str = rep_id_error;
			}
		}else{
			valid_form = 0;
			error_str = "The Rep I.D. should contain 6 characters, please try again.";
		}	
	}
		
	if(valid_form){
		return true;
	}else{
		alert(error_str);
		return false;					
	}
}

// checks domain names for character exceptions
// min length of field should be 2, maxlength should be 68
function isDomain(domain_name)
{
	var valid=1
	var symbol_exceptions = ["~", "`", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "=", "[", "]", "{", "}", "|", "\\", "<", ">", ",", "/", "?"];
	
	if(domain_name.length < 2 )
	{
		valid=0;
	}
	else
	{
		for (var n=0; n<symbol_exceptions.length; n++)
		{
			if (domain_name.indexOf(symbol_exceptions[n])!=-1)
			{
				valid=0;
			}
		}
	}
	return valid;
}

// validates phone numbers
function validatePhoneNumber(area_code, exchange, last4)
{
	var area_code_string=area_code+"";
	var exchange_string=exchange+"";
	var last4_string=last4+"";
	
	var valid=1;
	
	if(area_code=="" || exchange=="" || last4=="")
	{
		valid=0;
	}
	else if(isNaN(area_code) || isNaN(exchange) || isNaN(last4))
	{
		valid=0;
	}
	else if(area_code_string.length!=3 || exchange_string.length!=3 || last4_string.length!=4)
	{
		valid=0;
	}
	
	return valid;
}

// validates area-code and local exchange (first 6 digits of a phone #)
function validateFirstSix(area_code, exchange)
{
	var area_code_string=area_code+"";
	var exchange_string=exchange+"";
	
	var valid=1;
	
	if(area_code=="" || exchange=="")
	{
		valid=0;
	}
	else if(isNaN(area_code) || isNaN(exchange))
	{
		valid=0;
	}
	else if(area_code_string.length!=3 || exchange_string.length!=3)
	{
		valid=0;
	}
	
	return valid;
}

// validates email addresses
// smallest email that validates as true: xx@xx.xx
function validateEmail(email_address)
{
	var valid=1
	
	if(email_address.indexOf('@') == -1 || email_address.indexOf('.') == -1)
	{
		valid=0;
	}
	
	if(valid==1)
	{
		var splitAt = email_address.split("@")
		var splitDot = splitAt[1].split(".")
		
		if(splitAt[0].length < 2 || splitDot[0].length < 2 || splitDot[1].length < 2)
		{
			valid=0;
		}
	}
	return valid;
}

// validates zip code for either a 5 digit or 9 digit zip (numbers only)
function validateZip(zip)
{
	var valid=0;
		
	var zip_string = zip + "";
	var zip_numbers="";
	
	//this loop goes through the zip and removes any non-digit characters
	for(var n=0; n<zip_string.length; n++)
	{
		if(!isNaN(zip_string.charAt(n)) && zip_string.charAt(n) != " ")
		{
			zip_numbers=zip_numbers +zip_string.charAt(n);
		}
	}
	
	if(zip_numbers.length==5 || zip_numbers.length==9)
	{
		valid=1;
	}
	
	return valid;
}

// validates that a field isn't empty
function isNotEmpty ( textfield )
{
	var valid = 0;
	if ( textfield.length != 0 )
	{
		valid = 1;
	}
	return valid;
}

// validates the REP ID format
function validateRepIDFormat( rep_id ){
	var valid = 1;

	first_character=rep_id.charAt(0); 
	second_character=rep_id.charAt(1); 
	third_character=rep_id.charAt(2); 
	fourth_character=rep_id.charAt(3); 
	fifth_character=rep_id.charAt(4); 
	sixth_character=rep_id.charAt(5);
	
	numeric=third_character+fourth_character+fifth_character+sixth_character;

	if(!isNaN(first_character) || !isNaN(second_character) || isNaN(numeric)){
		valid = 0;
	}

	return valid;
}	

// -----------------------------------------------------------------------------
// print functions
// -----------------------------------------------------------------------------
var a_mac=(navigator.userAgent.indexOf("Mac") != -1);	//1 if Macintosh
var ie4x=0;
	
if (document.all && !window.print && !a_mac) //true on on IE4 (Windows) 
{
	ie4x=1;	
}

function printPage()
{
	// Takes care of printing on NS4, NS6, IE5, IE6
	if (window.print)	
	{
		window.print();
	}
	else if (ie4x)
	{
		// Takes care of IE4
		vbPrintPage();
	}
	else
	{
		alert("Sorry, your browser doesn't support this feature. To print, from the File menu, select Print.");
	}
	return false;
}

// Writtes a print object for IE4 (Windows) into the page
if (ie4x) with (document)	
{
	writeln('<OBJECT ID="WB" WIDTH="0" HEIGHT="0" CLASSID="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>');
	writeln('<' + 'SCRIPT LANGUAGE="VBScript">');
	writeln('Sub window_onunload');
	writeln('  On Error Resume Next');
	writeln('  Set WB = nothing');
	writeln('End Sub');
	writeln('Sub vbPrintPage');
	writeln('  OLECMDID_PRINT = 6');
	writeln('  OLECMDEXECOPT_DONTPROMPTUSER = 2');
	writeln('  OLECMDEXECOPT_PROMPTUSER = 1');
	writeln('  On Error Resume Next');
	writeln('  WB.ExecWB OLECMDID_PRINT, OLECMDEXECOPT_DONTPROMPTUSER');
	writeln('End Sub');
	writeln('<' + '/SCRIPT>');
}
