/*
********** BEGIN BLOCK: ***********
------------------------------------------------------
DESC  : BROWSER SNIFFER CODE
ADDED : JOSH MILLER
DATE  : 01-28-2004
------------------------------------------------------
*/
// THIS WAS ADDED BY JOSH MILLER, 01/28/2004:
var strUserAgent = String(navigator.userAgent);
strUserAgent = strUserAgent.toLowerCase();
var intMajorVersion = parseInt(navigator.appVersion);
var fltMinorVersion = parseFloat(navigator.appVersion);
var errorMessage;
var pricingAndAvailCheck = false;

// Internet Explorer:
var is_IE4minus = ((intMajorVersion<4) && (strUserAgent.indexOf("msie")!=-1));
var is_IE4 = ((strUserAgent.indexOf("msie")!=-1) && (intMajorVersion==4) && (strUserAgent.indexOf("msie 5")==-1) && (strUserAgent.indexOf("msie 6")==-1));
var is_IE5plus = ((intMajorVersion==4) && ((strUserAgent.indexOf("msie 5.0")!=-1) || (strUserAgent.indexOf("msie 6.0")!=-1)));
var is_IE4_Mac = ((intMajorVersion==4) && (navigator.appVersion.indexOf("Mac")>-1));
var is_IE5_Mac = ((intMajorVersion>4) && (navigator.appVersion.indexOf("Mac")>-1));

// Netscape:
var isNetscape = ((strUserAgent.indexOf("mozilla")!=-1) && (strUserAgent.indexOf("spoofer")==-1) && (strUserAgent.indexOf("compatible")==-1));
var is_NS4 = ((isNetscape) && (intMajorVersion==4));
var is_NS6plus = ((isNetscape) && (intMajorVersion>=5));
var is_Gecko = strUserAgent.indexOf("gecko")!=-1;

// Other Browsers:
var is_AOL = strUserAgent.indexOf("aol") !=-1;
var is_HotJava = strUserAgent.indexOf("hotjava") !=-1;
var is_Opera = window.opera?true:false;
var is_WebTV = strUserAgent.indexOf("webtv") !=-1;

var browserName = getBrowserName(strUserAgent);
var browserVer = intMajorVersion;

function getBrowserName(strUserAgent) {
	if ( is_IE4minus || is_IE4 || is_IE5plus || is_IE4_Mac || is_IE5_Mac ) {
		return "Internet Explorer";
	} else if (isNetscape) {
		return "Netscape";
	} else if (is_Opera) {
		return "Opera";	
	}
}

function getBrowserStr() {
	var browserStr = "";
	browserStr = navigator.userAgent;
	return browserStr;
}
/*
********** END BLOCK: ***********
*/


/* 
Desc:  Flash Detection 
By:    Eric Meysenburg
Date:  3-18-2004

------- start Flash Detection ------
*/

var requiredFlashVersion = 5;		// Version the user needs to view site (max 6, min 2)
var useRedirect = false;   			// Flag indicating whether or not to load a separate page for Flash. 
									// True = separate page;  false = embed alternate html directly into this page.
// System globals
var flash2Installed = false;    // boolean. true if flash 2 is installed
var flash3Installed = false;    // boolean. true if flash 3 is installed
var flash4Installed = false;    // boolean. true if flash 4 is installed
var flash5Installed = false;    // boolean. true if flash 5 is installed
var flash6Installed = false;    // boolean. true if flash 6 is installed
var maxVersion = 6;             // highest version we can actually detect
var actualFlashVersion = 0;          // version the user really has
var hasRightFlashVersion = false;    // boolean. true if it's safe to embed the flash movie in the page
var jsVersion = 1.0;            // the version of javascript supported


// Check the browser...we're looking for ie/win
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;    // true if we're on ie
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; // true if we're on windows

// This is a js1.1 code block, so make note that js1.1 is supported.
jsVersion = 1.1;

// Write vbscript detection on ie win. IE on Windows doesn't support regular
// JavaScript plugins array detection.
if(isIE && isWin){
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
	document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
	document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
	document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
}

function detectFlash()
{  
  // If navigator.plugins exists...
  if (navigator.plugins) {
    // ...then check for flash 2 or flash 3+.
    if (navigator.plugins["Shockwave Flash 2.0"]
        || navigator.plugins["Shockwave Flash"]) {

      // Some version of Flash was found. Time to figure out which.
      
      // Set convenient references to flash 2 and the plugin description.
      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;

      // DEBUGGING: uncomment next line to see the actual description.
      // alert("Flash plugin description: " + flashDescription);
      
      // A flash plugin-description looks like this: Shockwave Flash 4.0 r5
      // We can get the major version by grabbing the character before the period
      // note that we don't bother with minor version detection. 
      // Do that in your movie with $version or getVersion().
      var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
     
      // We found the version, now set appropriate version flags. Make sure
      // to use >= on the highest version so we don't prevent future version
      // users from entering the site.
      flash2Installed = flashVersion == 2;    
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion >= 6;
    }
  }
  	
	// loop through all versions we're checking, and set actualFlashVersion to highest detected version
	for (var i = 2; i <= maxVersion; i++) {	
		if (eval("flash" + i + "Installed") == true) actualFlashVersion = i;
	}
	// if we're on webtv, the version supported is 2 (pre-summer2000, or 3, post-summer2000)
	// note that we don't bother sniffing varieties of webtv. you could if you were sadistic...
	if(navigator.userAgent.indexOf("WebTV") != -1) actualFlashVersion = 2;	
	
	// uncomment next line to display flash version during testing
	// alert("version detected: " + actualFlashVersion);


	// we're finished getting the version. time to take the appropriate action

	if (actualFlashVersion >= requiredFlashVersion) { 		// user has a new enough version
		hasRightFlashVersion = true;						// flag: it's okay to write out the object/embed tags later

		if (useRedirect) {							// if the redirection option is on, load the flash page
			if(jsVersion > 1.0) {					// need javascript1.1 to do location.replace
				window.location.replace(flashPage);	// use replace() so we don't break the back button
			} else {
				window.location = flashPage;		// otherwise, use .location
			}
		}
	} else {	// user doesn't have a new enough version.
	
		if (useRedirect) {		// if the redirection option is on, load the appropriate alternate page
			if(jsVersion > 1.0) {	// need javascript1.1 to do location.replace
				window.location.replace((actualFlashVersion >= 2) ? upgradePage : noFlashPage);
			} else {
				window.location = (actualFlashVersion >= 2) ? upgradePage : noFlashPage;
			}
		}
	}
}
	
/*
------- start Flash Detection ------
*/


var doc = null;

if (isNetscape)
{
	doc = "document.";
}
else
{
	doc = "document.all.";
}


/*  ---General Images swapping---  */
var oldImg = new Image();
var imgNamePlaceholder;

function swapper(currentLink, img, replacement)
{
	imgNamePlaceholder = img;
	oldImg.src = eval(doc + img + ".src");
	var newImg = new Image();
	newImg.src = replacement;
	eval(doc + img + ".src = \"" + newImg.src + "\"");
}

function unswap()
{
	eval(doc + imgNamePlaceholder + ".src = \"" + oldImg.src + "\"");
} 

/*  ---Popup---  */

function popup(fileName)
{
	if(fileName.indexOf("http://") == -1)
	{
		popupPath = "http://local.sprint.com" + fileName;
		popOptions = 'height=530,width=420,screenX=50,screenY=50,left=50,top=50,scrollbars=yes,resizable=no';
	}
	else 
	{
		popupPath = fileName;
		popOptions = 'height=530,width=420,screenX=50,screenY=50,left=50,top=50,scrollbars=yes,resizable=no';
	}
	popupWin = window.open(popupPath,'',config=popOptions);
}

function popupWindow(fileName)
{
	popupWin = window.open("/home/local/popupinfo/" + fileName,'',config='height=530,width=420,screenX=50,screenY=50,left=50,top=50,scrollbars=yes');
}

function popupOutsideCSB(address)
{
	popupWin = window.open(address,'',config='height=800,width=650,screenX=25,screenY=25,left=25,top=25,scrollbars=yes,resizable=yes');
	return false;
}

function OpenWin(file, winName, properties)
{
	popupWin = window.open(file, winName, properties);
	return false;
}

function redirectParent(parentURL)
//use this function to redirect the parent and close the popup window.  
//if you want to retain the popup add a "false" parameter [redirectParent(parentURL, false);]
//if the current window is not a popup, then it will redirect the current window.  
//if the current window is not a popup, and a false has been passed to retain the popup, then a new window will be opened!
{
	var closePopup = true;
	var parentWindow = (window.opener)? window.opener: window;
	
	if(redirectParent.arguments.length > 1)	{closePopup = redirectParent.arguments[1];}
	
	if(parentWindow == window && !closePopup) {window.open(parentURL);}
	else
	{
		parentWindow.location = parentURL;
		if(closePopup) {self.close();}
	}	
}

/*  ---Anchor function---  */

function anchorLink(spot)
//This function will work around the base href problem with # anchors.
{
	loc = document.URL;	
	newLoc = loc + "#" + spot;
	window.location = newLoc;
}

/*  ---Cookie Information---  */

function getCookieInfo(field){ return getUSERCookieInfo(field);}
// backwards compatibility issue.  -- function deprecated

function getUSERCookieInfo(field)
{
	//Ufield: All Caps "field"      Cfield: Cookie field
	var Ufield = field.toUpperCase();
	var Cfield = ["HEADER"];
	Cfield[1] = "NPA";
	Cfield[2] = "COC";
	Cfield[3] = "LINE";
	Cfield[4] = "ORDERSTATUS";
	Cfield[5] = "DSLNPA";
	Cfield[6] = "DSLCOC";
	Cfield[7] = "DSLLINE";
	Cfield[8] = "DSLORDERSTATUS";
	Cfield[9] = "COMPANY";
	Cfield[10] = "STATE";
	Cfield[11] = "ZIP";
	Cfield[12] = "PROMOTION";
	Cfield[13] = "PROMOTIONFLAG";
	Cfield[14] = "SESSIONID";
	Cfield[15] = "STARTPAGE";
	Cfield[16] = "MODE";
	Cfield[17] = "CUSCODE";
	Cfield[18] = "LOYALTYCODE";
	Cfield[19] = "DEVMKTS";
	Cfield[20] = "COLLEGE";
	Cfield[21] = "DSLHELPINFO";
	Cfield[22] = "WIRECENTER";
	Cfield[23] = "EMPLOYERNAME";
		
	place = -1;
	returnVal = -1;
	
	
	for (i = 0; i<Cfield.length; i++)
	{
		if(Cfield[i] == Ufield) place = i;
	}
	
	var Ucookie = getCookieContents("user");	
	
	if(Ucookie != -1)
	// be sure that there was a user cookie sent back.
	{
		var cookieParts = Ucookie.split("%09");
	
		if (place != -1)
		{
			returnVal = cookieParts[place];
		}
	}
	returnVal = (returnVal.length == 0)? -1 : returnVal;
	return returnVal;
	
}

function getPERSISTUSERCookieInfo(field){ return getPERSISTENTUSERCookieInfo(field);}
// backwards compatibility issue.  -- function deprecated

function getPERSISTENTUSERCookieInfo(field)
{
	//Ufield: All Caps "field"      Cfield: Cookie field	
	var Ufield = field.toUpperCase();
	var Cfield = ["HEADER"];
	Cfield[1] = "NPA";
	Cfield[2] = "COC";
	Cfield[3] = "LINE";
	Cfield[4] = "ZIP";
	Cfield[5] = "STATE";
	Cfield[6] = "COMPANY";
	Cfield[7] = "WIRECENTER";
	Cfield[8] = "MARKETGROUP";


	place = -1;
	returnStr = -1;
	
	for (i = 0; i<Cfield.length; i++)
	{
		if(Cfield[i] == Ufield) place = i;
	}
	
	var Ucookie = getCookieContents("PERSISTENTUSER");	
	
	if(Ucookie != -1)
	// be sure that there was a user cookie sent back.
	{
		var cookieParts = Ucookie.split("%09");
	
		if (place != -1)
		{
			returnVal = cookieParts[place];
		}
	}
	returnVal = (typeof(returnVal) == "undefined" || returnVal == null || returnVal.length == 0)? -1 : returnVal;
	return returnVal;
	
}

function getCookieContents(field)
{
	var Ufield = field.toUpperCase();
	var cookieContents = document.cookie;
	var returnVal = -1;
	var cookiePairs = cookieContents.split(";");
	var cookieParts;

	if(cookieContents.length > 0)
	// be sure that there is a cookie
	{
		for (i=0; i<cookiePairs.length; i++)
		{
			cookieParts = cookiePairs[i].split("=");
			if((cookieParts[0].toUpperCase() == Ufield) || (cookieParts[0].toUpperCase() == (" " + Ufield)))
			{
				returnVal = cookieParts[1];
			}
		}
	}
	
	return returnVal;
}

function isValidNumber(field, minNum, maxNum)
//  This function will test a String to be sure it is all digits and that the 
//	correct number of characters have been met as defined in minNum and maxNum.
{
	var acceptable = true;

	//alert("field: " + field + "\nvalue: '" + field.value + "'");

	if((field.length < minNum) || (field.length > maxNum)) return !acceptable;

	for(var i = 0; (i < field.length && acceptable); i++)
	{
		var c = field.charAt(i);
		if(!isDigit(c))
		{
			acceptable = false;
		}
	}

	return acceptable;

}

function isDigit(c)
//This function is seperated from isValidNumber so it can deal with c as an integer.
{
	return ((c <= 9) && (c >= 0));
}

// Eric Meysenburg - 1/13/2005
// get values from Querystring

function queryString(key)
{
	var page = new PageQuery(window.location.search); 
	return unescape(page.getValue(key)); 
}
function PageQuery(q) 
{
	if(q.length > 1) this.q = q.substring(1, q.length);
	else this.q = null;
	this.keyValuePairs = new Array();
	if(q) {
		for(var i=0; i < this.q.split("&").length; i++) {
			this.keyValuePairs[i] = this.q.split("&")[i];
		}
	}
	this.getKeyValuePairs = function() { return this.keyValuePairs; }
	this.getValue = function(s) {
		for(var j=0; j < this.keyValuePairs.length; j++) {
			if(this.keyValuePairs[j].split("=")[0] == s)
			return this.keyValuePairs[j].split("=")[1];
		}
		return false;
	}
	this.getParameters = function() {
		var a = new Array(this.getLength());
		for(var j=0; j < this.keyValuePairs.length; j++) {
			a[j] = this.keyValuePairs[j].split("=")[0];
		}
		return a;
	}
	this.getLength = function() { return this.keyValuePairs.length; } 
}
// end querystring function

/*  ---Navigation Controllers---  */
		
	function setNav(propString)
	{
		var parts = propString.split(",");
		for (i = 0; i < parts.length; i++)
		{
			pair = parts[i].split("=");
			cleanVal = cleanString(pair[1]);
			//if(pair[0].toUpperCase().indexOf("TOP") != -1){ changeTop("topNav" + cleanVal);}
			if(pair[0].toUpperCase().indexOf("RED") != -1){ changeTop("redNav" + cleanVal);}
			if(pair[0].toUpperCase().indexOf("EBPP") != -1){ changeTop("ebpp_nav" + cleanVal);}
			if(pair[0].toUpperCase().indexOf("LEFT") != -1){ changeLeft(cleanVal);}
			if(pair[0].toUpperCase().indexOf("INSET") != -1){ changeInset(cleanVal);}
		}
	}
	
	function changeTop(changeling)
	{
		var defImg = new Image();
		var onImg = new Image();
		var fileName;
		defImg.src = eval(doc + changeling + ".src");
		fileName = defImg.src.slice(0, (defImg.src.length - 4));
		onImg.src = fileName + "_on.gif";
		eval(doc + changeling + ".src = \"" + onImg.src + "\"");		
	}
	
	function changeLeft(changeling)	
	{	
		if(!isNetscape)
		{
			//var tdObj = eval(doc + "leftNav" + changeling);
			//tdObj.style.background = "#F3F3DF";
			var aObj = eval(doc + "link" + changeling);
			aObj.style.color = "black";
			var td2Obj = eval(doc + "leftNav" + changeling + "2");
			if(td2Obj)
			{
				td2Obj.style.background = "#F3F3DF";
			}
		}
	}
	
	function changeInset(changeling)
	{
		var imgObj = eval("document.inset" + changeling);
		var arrow = new Image();
		arrow.src = "/home/local/images/MISC_small_arrow.gif";
		imgObj.src = arrow.src;
	}
	
	function cleanString(inc)
	{

		var clean = "";
		for (c = 0; c < inc.length; c++)
		{
			if(inc.charAt(c) != " ") clean += inc.charAt(c);
		}
		return clean;
	}
	
//*********************************************
//These methods will sort arrays
//sortByVal will sort a drop down list by it's value

function bubbleSort(inputArray)
{
	var start = 0;
	var rest = inputArray.length - 1;
	for (var i = rest - 1; i >= start;  i--) 
	{
		for (var j = start; j <= i; j++) 
		{
			if (inputArray[j+1] < inputArray[j]) 
			{
				var tempValue = inputArray[j];
				inputArray[j] = inputArray[j+1];
				inputArray[j+1] = tempValue;
      		}
   		}
	}
	return inputArray;
}

function dualBubbleSort(inputArray, secondInputArray)
{
	var start = 0;
	var rest = inputArray.length - 1;
	for (var i = rest - 1; i >= start;  i--) 
	{
		for (var j = start; j <= i; j++) 
		{
			if (inputArray[j+1] < inputArray[j]) 
			{
				var tempValue = inputArray[j];
				var secondTempValue = secondInputArray[j];
				inputArray[j] = inputArray[j+1];
				secondInputArray[j] = secondInputArray[j+1];
				inputArray[j+1] = tempValue;
				secondInputArray[j+1] = secondTempValue;
      		}
   		}
	}
	var outputArray = new Array();
	for(i=0; i<inputArray.length; i++)
	{
		outputArray[outputArray.length] = inputArray[i];
		outputArray[outputArray.length] = secondInputArray[i];
	}
	
	return outputArray;
}


function sortByVal(field)
{
	var currentOptionsValues = new Array();
	var currentOptionsText = new Array();
	for(i=0; i<field.options.length; i++)
	{
		currentOptionsValues[i] = field.options[i].value;
		currentOptionsText[i] = field.options[i].text;
	}
	var orderedOptions = dualBubbleSort(currentOptionsValues, currentOptionsText);
	field.options.length = 0;
	for(i=0; i<orderedOptions.length; i+=2)
	{
		field.options[field.options.length] = new Option(orderedOptions[i+1], orderedOptions[i]);	
	}
	
	field.options[0].selected = true;
}

// Determine location by entering zip code
// used for reverted Zip to Phone functionality

function validateZip()
{
	var error = false;
	var zip = isValidNumber(document.form1.zip.value, 5, 5);
	if (!zip) {
		errorMessage = "ZIP code was not entered correctly.\nPlease try again.";
		var error = true;
	}
	if (error) {
		alert(errorMessage);
	}
	return (!error);

}

function zipDisplay()
{
	var zipcodeStr = "";
	if (getPERSISTENTUSERCookieInfo("zip") != -1 )
	{
		zipcodeStr = getPERSISTENTUSERCookieInfo("zip");
	}
	if ( zipcodeStr == "" ) {
		displayZip = "<span class='t11k-b'><a href=# onClick='openZipWindow(); return false;'>Click here</a> to check pricing</span>";
	} else if ( zipcodeStr == "-1") {
		displayZip = "<span class='t11k-b'><a href=# onClick='openZipWindow(); return false;'>Click here</a> to check pricing</span>";
	} else {
		displayZip = "<span class='t11k-b'>Pricing&nbsp;for&nbsp;ZIP&nbsp;code&nbsp;<a href='#' onClick='openZipWindow(); return false;'>" + zipcodeStr + "</a></span>";
	}
	return displayZip;

}

function submitZip()
{
	if ( validateZip() ) {
		document.form1.submit();
	}
}
function showZipEntry()
{
	document.getElementById('display').style.visibility="hidden";
	document.getElementById('entry').style.visibility="visible";
	if (getPERSISTENTUSERCookieInfo("zip") != -1 )
	{
		document.form1.zip.value = getPERSISTENTUSERCookieInfo("zip");
	}
}
function showZipDisplay()
{
	document.getElementById('display').style.visibility="visible";
	document.getElementById('entry').style.visibility="hidden";
}

// *** end ZIP to PHONE functions
// ******************************

function wireCenterDisplay()
{
	var displayWireCenter = getPERSISTENTUSERCookieInfo("WIRECENTER");
}

function openZipWindow()
{
	//showZipEntry();
	window.open('/servlet/ZipCode/zipcode','zip','height=450,width=375,screenX=50,screenY=50,left=50,top=50,scrollbars'); 
	return false;
}

function autotab(fn, fl) {
        var i;
        var idx;
        var next;        
        var docele;
        
        idx = -1;        
        for (i = 0; i < document.form1.length; i ++) {
                if (document.form1.elements[i].name == fn.name)
                        idx = i;
        }   
		            
        if (idx != -1) {
                // Find the next 'field'
                next = idx + 1;
                if (next >= document.form1.length)
                        next = 0 

                // Figure out the length of the given element.                        
                docele = document.form1.elements[idx].value;
				if (document.selection.type == "Text")
				{
				}
				else
				{ 
                	if (docele.length == fl) {
                        document.form1.elements[next].focus();
				}
                }
        }        
}

var doSurvey = 'yes';
function popSurvey(survey){
	var nDate = new Date();
	var nMonth = (nDate.getMonth())+1;
	if(survey == "ebillchurn" && doSurvey != 'no' && ((nMonth==2)||(nMonth==5)||(nMonth==8)||(nMonth==11)))
	{	
		var surveyWin = window.open("http://www.sprintlocalsurveys.com/ebill%20churn/ebillchurn.htm","Quarterly_Survey","width=770,height=500,scrollbars=yes,resizeable=true");
		surveyWin.focus();
	}
	else if(survey == "packages" && doSurvey != 'no' && ((nMonth==3)||(nMonth==6)||(nMonth==10)||(nMonth==9)||(nMonth==12)))
	{	
		var surveyWin = window.open("http://www.sprintlocalsurveys.com/bundleorder/bundleorder.htm","drop_survey","width=750,height=600,left=50,top=50,scrollbars,resizable");
		surveyWin.focus();
	}
	else if(survey == "hsi" && doSurvey != 'no' && ((nMonth==1)||(nMonth==4)||(nMonth==7)||(nMonth==10)))
	{	
		var surveyWin = window.open("http://www.sprintlocalsurveys.com/HSIorder/hsiorder.htm","drop_survey","width=750,height=600,left=50,top=50,scrollbars,resizable");
		surveyWin.focus();
	}
	else
	{	}
};
