// JavaScript Document


//
//This script detects the following:
//Flash  Windows Media Player
//Java   Shockwave
//RealPlayer  QuickTime
//Acrobat Reader SVG Viewer


var agt=navigator.userAgent.toLowerCase();
var ie  = (agt.indexOf("msie") != -1);
var ns  = (navigator.appName.indexOf("Netscape") != -1);
var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
var mac = (agt.indexOf("mac")!=-1);

if (ie && win) {	pluginlist =  detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") + detectIE("PDF.PdfCtrl.5","Acrobat Reader");}
if (ns || !win) {
		nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
		pluginlist = detectNS("application/x-shockwave-flash","Shockwave Flash") +  detectNS("application/pdf","Acrobat Reader");}

function detectIE(ClassID,name1) { result = false; document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); if (result) return name1+','; else return ''; }
function detectNS(ClassID,name1) { n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name1+","; return n; }

pluginlist += navigator.javaEnabled() ? "Java," : "";
if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);

//SAMPLE USAGE- detect "Flash"
//if (pluginlist.indexOf("Flash")!=-1)
//document.write("You have flash installed")


/*
    Written by Jonathan Snook, http://www.snook.ca/jonathan
    Add-ons by Robert Nyman, http://www.robertnyman.com
*/

/**
 * This function allows the programmer to retrieve objects biased on the class name you 
 * want to retrieve. Similar to the GetElementByID and GetElementByTagName.
 * @member UtilNS
 * @param {object} oElm The object you want to search, could be a whole document or something more specific.
 * @param {string} strTagName The string containing the name of the tag name i.e. "a", "div", "span" what ever the class name is attached to.
 * If no tag is given it will search all elements.
 * @param {string} strClassName The string containing the class name you're searching for
 * @returns An array filled with the class names found in the search
 * @type Array
 * {@link  http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/#more-256 getElementsByClassName} Utility Function
 */


function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return arrReturnElements;
}

/**
 * This function allows the programmer to retrieve objects biased on an array of class names you 
 * want to retrieve. Similar to the GetElementByID and GetElementByTagName.
 * @member UtilNS
 * @param {object} oElm The object you want to search, could be a whole document or something more specific.
 * @param {string} strTagName The string containing the name of the tag name ie "a", "div", "span" what ever the class name is attached to.
 * If no tag is given it will search all elements.
 * @param {array} strClassName The string containing the class name you're searching for
 * @returns An array filled with the class names found in the search
 * @type Array
 * {@link  http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/#more-256 getElementsByClassName} Utility Function
 */

/*
	Revised to support looking for multiple class names,
	no matter in which order they're applied to the element
*/
function getElementsByClassName(oElm, strTagName, oClassNames){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var arrRegExpClassNames = new Array();
	if(typeof oClassNames == "object"){
		for(var i=0; i<oClassNames.length; i++){
			arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
		}
	}
	else{
		arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
	}
	var oElement;
	var bMatchesAll;
	for(var j=0; j<arrElements.length; j++){
		oElement = arrElements[j];
		bMatchesAll = true;
		for(var k=0; k<arrRegExpClassNames.length; k++){
			if(!arrRegExpClassNames[k].test(oElement.className)){
				bMatchesAll = false;
				break;
			}
		}
		if(bMatchesAll){
			arrReturnElements.push(oElement);
		}
	}
	return arrReturnElements;
}
/**
 * This function adds the push functionality for IE 5
 * @member UtilNS
 * {@link  http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/#more-256 getElementsByClassName} Utility Function
 */
 
// Array support for the push method in IE 5
//Array.prototype.push = ArrayPush;
//function ArrayPush(value){
//	this[this.length] = value;
//}
// 
/*
	Examples of how to call the function:
	
	To get all a elements in the document with an "info-links" class:
    getElementsByClassName(document, "a", "info-links");
    
	To get all div elements within the element named "container", with a "col" and a "left" class:
    getElementsByClassName(document.getElementById("container"), "div", ["col", "left"]);
*/
//

/**
 * This function is another function to search by class Name
 * @member UtilNS
 * @param {string} searchClass The object you want to search, could be a whole document or something more specific.
 * @param {object} node The object which you want to search inside of.
 * @param {string} tag The string containing the name of the tag name i.e. "a", "div", "span" what ever the class name is attached to.
 * If no tag is given it will search all elements.
 * @returns An array filled with the class names found in the search
 * @type Array
 * @depreciated Not used will be removed
 */
 
function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}
/**
 * This function removes the white space of a string from the left. Used to check if entries are blank.
 * @member UtilNS
 * @param {string} sString The readioObject
 * @returns A string that has the white space removed from the left
 * @type String
 */

function leftTrim(sString) {
	while (sString.substring(0,1) == ' ')
	{ sString = sString.substring(1, sString.length); }
	return sString;
}
/**
 * This function removes the white space of a string from the right. Used to check if entries are blank.
 * @member UtilNS
 * @param {string} sString The readioObject
 * @returns A string that has the white space removed from the right.
 * @type String
 */
 
function rightTrim(sString) {
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{ sString = sString.substring(0,sString.length-1); }
	return sString;
}
/**
 * This function removes all the white space of a string. Used to check if entries are blank.
 * @member UtilNS
 * @param {string} sString The radioObject
 * @returns A string that has all the white space removed.
 * @type String
 */
 
function trimAll(sString) {
	while (sString.substring(0,1) == ' ')
	{ sString = sString.substring(1, sString.length); }
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{ sString = sString.substring(0,sString.length-1); }
	return sString;
}

/**
 * This function is a primitive error handler. It displays the error it is passed in the form
 * of an alert box.
 * @member UtilNS
 * @param {string} msg The string containing the error message.
 * @param {string} url The string containing the url.
 * @param {int} l The int containing the line number of the error.
 * @returns A boolean of false to cancel the bubble.
 * @type Boolean
 */
function handleErr(msg,url,l){txt="There was a JavaScript error on this page.\n\n";
    txt+="Error: " + msg + "\n";
    txt+="URL: " + url + "\n";
    txt+="Line: " + l + "\n\n";
    txt+="Click OK to continue.\n\n";
    alert(txt);return false;
}

/***  fontSize functions  ***/

/*Increase Font*/
// free to use as long as this copyright notice stays intact
var tags = new Array( 'div','td','tr','p','b','table','strong','emphasis','a','h1','h2','h3','pre','sub','sup','i','th','cp','ul','ol','li','dt','dd');
var pixelArray =  new Array('6','8','10','12','14','16','18');
var emArray =  new Array('0.7','0.9','1.0','1.5','2.0','2.5','3');
var initSize = 3;


/***  Menu Functions  ***/
	// get all branch classes parent IDs and compare them with the keywords
	// loop through arrays find similar
	// open branches
var fixIds = new Array();
var runFixIds = false;

/**
 * This function opens the menu according to the url. If the url is not
 * in the menu it is unable to open it to the proper level. It opens
 * the menu at the root menu if the root menu is chosen.
 * open branches to closed by changing the arrow image.
 * @member MenuNS
 * @see toggleDivs
 */

function openMenu()
{
	//	var menuID = "Menu1";
	var menuID = "ctl00_ContentPlaceHolder1_Menu1";
	var menuItem = document.getElementById(menuID);
	
	if(runFixIds)
		return;
		
	try
	{
		if(!menuItem || menuItem.id != menuID)
			return;
	}
	catch(e) {return;}
		
	var aTagsMenu = menuItem.getElementsByTagName("a");
	var itemId = null;
	var i=0;
	
	if(!aTagsMenu)
		return;
	
	for( ; i < aTagsMenu.length; i++)
	{
		if(urlPath == aTagsMenu[i].href)
			break;
	}
	
	// highlight first element

	try
	{
		itemId = aTagsMenu[i].firstChild;
		itemId.className = "SlideMenuItemSelected";
		fixIds.push(itemId.id);
		itemId = new String(itemId.id);
		itemId = itemId.substring(1);
		swapFolder("I"+itemId);
	
		
		var topDivTest = aTagsMenu[i];
		var topLevel = false;
		var cnt = 0;
		
		// Check to see if menu is top level
		do
		{
			if(topDivTest.tagName == "DIV" && topDivTest.className == "branch2")
			{
					topLevel = true;
			}
			topDivTest = topDivTest.parentNode;
			cnt++;
		}
		while (topDivTest.tagName != "span" && topDivTest.id != menuID && cnt < 6);
	
		if(topLevel)
		{
			itemId = aTagsMenu[i].firstChild;
			itemId = new String(itemId.id);
			itemId = itemId.substring(1);
			showBranch(menuID, itemId);
			// open folder correction
			swapFolder("I"+itemId);
		}
		else
		{
			
			if(!PrePath)
				PrePath = new Array();
			
			var leaf = aTagsMenu[i];
			leaf = leaf.parentNode;
			// climb tree looking for parents
			do
			{
				
				if(leaf.tagName == "DIV")
				{
					PrePath.push(leaf.id);
					showBranch(menuID, leaf.id);
					var temp = document.getElementById("M"+leaf.id);
					try
					{
						if(temp){
							temp.className = "MenuSelected"; 
							fixIds.push(temp.id);
						}
					}
					catch(f) {}
					
				}
				leaf = leaf.parentNode;
			}
			while (leaf.tagName != "span" && leaf.id != menuID );
		}
	}
	catch(e) {} 
	// stop when reach MenuID
	runFixIds = true;
}

var firstLoad = true;

/*Scripts for the Tree Menu*/
/*Here Ends part is for focus the forms catch the enter key*/

var PrePath = null;
/**
 * This function opens the left hand menu nested menus and keeps track of the
 * part of the menu that is already open.
 * It closes the open branches if they aren’t part of the menu being opened.
 * Updates the PrePath array with the location of the branches visited.
 * @member MenuNS
 * @param {string} menuName The id of the menu
 * @param {string} branch The id of the branch of the menu to be opened.
 */
function showBranch(menuName,branch){
	var objBranchID = document.getElementById(branch);
	var objBranch = objBranchID.style;	
	var found = false;
	var menuItem = document.getElementById(menuName);
	
	//alert("Showbranch: "+branch);
	
	if(objBranch.display=="block")
	{
		objBranch.display="none";
	}
	else
	{
			if(PrePath != null) {
				try{
					for(var i=0; i < PrePath.length; i++){						
					//alert("search for loop: "+i+"  prepath:"+PrePath[i] +"  objBranch:"+objBranchID.id+" "+objBranchID.parentNode.id);
						if(PrePath[i] == objBranchID.id || 
						   PrePath[i] == objBranchID.parentNode.id)
						{
							found = true;
							break;
						}
						
					}
				}
				catch(e){}
				if(!found || runFixIds){
					//alert("closing branch");
					closeAllBranches(menuName,branch);
					PrePath = new Array();
				}
			}
			else {
					PrePath = new Array();
			}
				
				objBranch.display="block";
				objBranch.visibility="visible";
				
	    } // else branch block
		swapFolder('I' + branch);
		//alert(objBranchID.className);
		
	//} // part of the else?
	var id = new String(objBranchID.id);
	PrePath.push(id);
	
}

/**
 * This function swaps the arrow on the side of the menu from blue to orange. Or
 * back from orange to blue. Also sets the parentNode className to
 * or from SlideMenuItemSelected this is the orange color for the menu.
 * @member MenuNS
 * @param {string} img The id of the img that needs to be opened or closed
 */
function swapFolder(img){
	var MyArray;
	var MyArrays;
	var Path;
	objImg = document.getElementById(img);

	try
	{
		//alert(objImg.parentNode.className);
		if(objImg.src.indexOf('-closed.gif')>-1) {
			MyArray = objImg.src; 
			MyArrays = objImg.src.lastIndexOf("-");
			Path = MyArray.substring(0,MyArrays) + "-open.gif";
			objImg.src = Path;
			//alert("swapFolder className:"+objImg.parentNode.className);
			if(objImg.parentNode.className)
			{
				objImg.parentNode.className = "SlideMenuItemSelected";
			}
			
		} else {
			MyArray = objImg.src; 
			MyArrays = objImg.src.lastIndexOf("-");
			Path = MyArray.substring(0,MyArrays) + "-closed.gif";
			objImg.src = Path;
			if(objImg.parentNode.className == "SlideMenuItemSelected")
			{
				objImg.parentNode.className = "branch";
			}
		}
		//alert(objImg.parentNode.className);
	}
	catch(e){}
}
/**
 * This function closes all the branches of the menu and converts all
 * open branches to closed by changing the arrow image.
 * @member MenuNS
 * @param {string} menuName The id of the menu.
 * @param {string} w The id of the branch that is currently opened.
 * @see toggleDivs
 */
 
function closeAllBranches(menuName,w) {
	var menuItem = document.getElementById(menuName);
	var slideMenuArray = getElementsByClassName(menuItem, "div", "SlideMenuItemSelected");
	var menuSelectedArray = getElementsByClassName(menuItem, "div", "MenuSelected");
	var branch1Array = getElementsByClassName(menuItem, "div", "branch1");
	
	if(fixIds.length > 0 && runFixIds)
	{
		for(i=0; i < fixIds.length; i++)
		{
			var temp = document.getElementById(fixIds[i]);
			temp.className = "branch";
			
		}
		fixIds = new Array();
		runFixIds = false;
	}
	
	for(i=0; i < branch1Array.length; i++)
	{
			if( branch1Array[i].id != w)
			{
				if( branch1Array[i].id != "")
				{
					toggleDivs(branch1Array[i].id, "toggle");
					var img = "I" + branch1Array[i].id;
					var objImg = document.getElementById(img);
					var MyArray = objImg.src;
					var MyArrays = objImg.src.lastIndexOf("-");
					var Path = MyArray.substring(0,MyArrays) + "-closed.gif";
					objImg.src = Path;
				}

			}
			
		}

    toggleDivs(w, "toggle");
}

/**
 * This function checks if the class is MenuOver or branch. It does not change the class if it
 * is MenuSelected or SlideMenuItemSelected which would indicate that the 'branch is' open already.
 * @member MenuNS
 * @param {object} the branch object
 * @see treemenu.xsl
 */
function checkMenuClass(entry)
{
	if(entry.className == 'MenuOver')
	{
		entry.className = 'branch';
	}
	else if(entry.className == 'branch')
	{
		entry.className = 'MenuOver';
	}
	
}


/*End Scripts for the Tree Menu*/

/* BGT Toggle divs scripts */
//Detect browser settings for showing and hiding DIVs
//Works with IE, Netscape, Firefox
     isNS4 = (document.layers) ? true : false;
     isIE4 = (document.all && !document.getElementById)	? true : false;
     isIE5 = (document.all && document.getElementById)	? true : false;
     isNS6 = (!document.all && document.getElementById)	? true : false;

/**
 * This function changes the css values for visibility and display
 * which is an effective way to hide and show divs without reloading a page.
 * open branches to closed by changing the arrow image.
 * @member UtilNS
 * @param {string} strDivName The id of the div which will be toggled
 * @param {string/boolean} bolVisible The boolean/string variable which effects how it will display
 */	 

function toggleDivs(strDivName,bolVisible){
	//Identify the element based on browser type
	if (isNS4) 					{	objElement = document.layers[strDivName];				}
	else if (isIE4) 			{	objElement = document.all[strDivName].style;			}
	else if (isIE5 || isNS6)	{	objElement = document.getElementById(strDivName).style;	}
	
	if(isNS4 || isIE4)	{
		if(bolVisible=="toggle")	{
			if			(objElement.visibility=="hidden")	{	objElement.visibility="visible";	}
			else if 	(objElement.visibility=="visible")	{	objElement.visibility="hidden";		}
		}
		else if(!bolVisible)		{	objElement.visibility ="hidden";	}
		else						{	objElement.visibility ="visible";	}
	}
	else if (isIE5 || isNS6) {
		if(bolVisible=="toggle")	{
			if			(objElement.display=="none" || objElement.visibility=="hidden")
														{	objElement.display="";		
															objElement.visibility="visible"; }
			else if 	(objElement.display=="" || objElement.visibility=="visible")		
														{	objElement.display="none";
															objElement.visibility="hidden"; }
		}
		else if(!bolVisible)	{	objElement.display = "none"; objElement.visibility="hidden"; }
		else 					{	objElement.display = ""; objElement.visibility="visible";}
	}
}


var replaceImgEn = new Array("/uploadedImages/BHNCorporate/EasyStreetCorpHome_Default.jpg",
						   "/uploadedImages/Divisions/Shared_Content/EasyStreetDivHome_Default.jpg");

var replaceImgEs = new Array("/uploadedImages/BHNCorporate/EasyStreetCorpHome_Default.jpg",
						   "/uploadedImages/Divisions/Shared_Content/EasyStreetDivHome_Default.jpg");


// need to change for espanol think

/**
 * This function checks to see if the flash player is installed. If it isn’t it
 * inserts the replaceImg from the array depending on if it’s corporate or a division.
 * It removes the flash object from the html and inserts an image in its place.
 * @member UtilNS
 */
/**  Need rewrite for multiple divisions espanol **/
function readyFlash()
{
	
// Check to see if the version meets the requirements for playback
	if (pluginlist.indexOf("Flash")==-1)
	{  // if we've detected an acceptable version
      // flash is too old or we can't detect the plugin
    	
		
	var myNewImgNode = document.createElement("img");
	var flashNode =  document.getElementById("flashMovie");
	var replaceImg = null;
	
	if(division[0] === "espanol") // division espanol
	{
		replaceImg = replaceImgEs;
	}
	else
	{
		replaceImg = replaceImgEn;
	}
	
	if(urlArray[1] == "corporate.aspx")
	{
		myNewImgNode.src = replaceImg[0];
		myNewImgNode.width = "780";
	}
	else if(urlArray[1] == "default.aspx") 
	{
		myNewImgNode.src = replaceImg[1];
		myNewImgNode.width = "600";
	}
	 
	 
	 
	 
	 
	 myNewImgNode.height = "190";
	 myNewImgNode.alt ="Bright House Networks";
	 
	 flashNode.removeChild(flashNode.firstChild);
	
	 flashNode.appendChild(myNewImgNode);
  }
  
}

 /**
 * This function finds the radio button that has been checked.
 * @member UtilNS
 * @param {object} w The readioObject
 * @depreciated Not called anywhere.
 */
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

/**
*Streamlines the window.open function for creating pop-ups.
*/
function pop_window(win_url,win_width,win_height,scrollbars)
{
    //-- Set defaults.
    scrollbars = scrollbars == null ? 'yes' : scrollbars;

    //-- window.open requires a unique window name be given.  I am creating a random number to append to
    //-- the standard window name of popup.

    try
    {
        var rand_num = Math.random*1000;
        var round_rand_num; 

        round_rand_num = Math.round(rand_num);            
        pop_handle = window.open(win_url,"popup"+round_rand_num,"toolbar=no,location=no,directories=no,status=no,scrollbars="+scrollbars+",resizable=no,copyhistory=no,width="+win_width+",height="+win_height);
        return;
    }
    catch(ex)
    {
        alert(ex.description);
    }
}

/**
* Gets the query string parameters as 0 based indexed array.
*/
function getQueryStringParams()
{
    //-- Get the index of the query string start.
	var queryStringStart = window.location.href.indexOf('?');
	
	var request = new Array();
	if(queryStringStart > 0)
	{
		var parmString = window.location.href.substr(queryStringStart + 1);
		var keyValuePairs = parmString.split('&');
		
		for(i = 0;i < keyValuePairs.length;i++)
		{
			var kvp = keyValuePairs[i].split('=');
			request[i] = kvp[1];
		}
	}
	
	return request;
}

/**
* Gets the value of the query string variable with the given name.
*/
function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
}