// JavaScript Document


/**
 * This function dynamically changes the variables on the Order Online page.
 * Because the forms submit to different pages, the variables needed to have
 * a name change so they can be correctly processed. Also since the form initially
 * contains all the information for both divisions it is necessary to delete from CFL
 * and change Tampa Bay
 * @member OrderOnlineNS
 */
 /**  Need rewrite for multiple divisions **/
/*
function readyOOPage()
{
	//alert("order online page: "+urlArray);
	var inputNamesTampa = new Array("streetnumber", "streetname", "unit", "zip");
	var inputNamesCfl = new Array("streetNumber","streetName", "postCode");
	
	var asterisk3 = document.getElementById("asterisk3");
	asterisk3.style.visibility = "hidden";
	
	if(division[0] == "cfl")
	{
		//alert("case cfl");
			if(firstLoad)
			{
			var ooTampa1 = document.getElementById("ooTampa1");
			var ooTampa2 = document.getElementById("ooTampa2");
			var ooTampa1_td = document.getElementById("ooTampa1_td");
			var ooTampa2_td = document.getElementById("ooTampa2_td");
			var asterisk1 = document.getElementById("asterisk1");
			var exItems = getElementsByClassName(document, "span", "ooEx");
			var inputBoxes = document.getElementsByTagName("input");
			
			for(i=0; i < exItems.length; i++)
			{
				exItems[i].style.visibility = "hidden";
			}
			
			for(var i=0; i < inputBoxes.length; i++)
			{
				if(inputBoxes[i].type == "text")
				{				
					for(var j=0; j < inputNamesCfl.length; j++)
					{
						
						if(inputBoxes[i].name.toLowerCase() == inputNamesCfl[j].toLowerCase())
						{
						inputBoxes[i].name = inputNamesCfl[j];
						inputBoxes[i].id = inputNamesCfl[j];
						}
						
					}
				
				}
			
			}
			asterisk1.style.visibility = "hidden";
			
				ooTampa1.removeChild(ooTampa1_td);
				ooTampa2.removeChild(ooTampa2_td);
				firstLoad = false;
			}
			
			document.orderonline_rnav["event"].value = "step.display.address.select";
	}
	else if(division[0] == "tampabay")
	{
		if(firstLoad)
		{
		var inputBoxes = document.getElementsByTagName("input");
		var ooChange = document.getElementById("ooChange");
		var ooChangeText = "<strong>U</strong>nit/Apartment Number (ex 14B)";
		var ooTampa2 = document.getElementById("ooTampa2");
		
		for(var i=0; i < inputBoxes.length; i++)
		{
			if(inputBoxes[i].type == "text")
			{				
				for(var j=0; j < inputNamesTampa.length; j++)
				{
					if(inputBoxes[i].name.toLowerCase() == inputNamesTampa[j].toLowerCase())
					{
						inputBoxes[i].name = inputNamesTampa[j];
						inputBoxes[i].id = inputNamesTampa[j];
					}
					else if(inputBoxes[i].name == "city" && inputNamesTampa[j] == "unit")
					{
						inputBoxes[i].name = inputNamesTampa[j];
						inputBoxes[i].id = inputNamesTampa[j];
						inputBoxes[i].accessKey = "U";
						inputBoxes[i].size = "12";
						inputBoxes[i].maxlength ="12";
					}
					else if(inputBoxes[i].name == "postcode" && inputNamesTampa[j] == "zip")
					{
						inputBoxes[i].name = inputNamesTampa[j];
						inputBoxes[i].id = inputNamesTampa[j];
						
					}
				}

				
			}

		}

        document.orderonline_rnav["event"].value = "entry.display.address.select";

        ooChange.innerHTML = ooChangeText;

		firstLoad = false;
		}
	}
		//document.form[0].onsubmit = "return orderOnlineForm(this.form)";
}
*/
/**
 * This function fixes the contact us Block in Mozilla.
 * Because each of the browsers interprets the sizes and placement of
 * various objects differently it was necessary to include this function so that
 * across browsers they look similar.
 * @member ContactUsNS
 */
function readyContactUs()
{	
	var contentBlock = document.getElementById("contentDiv");
	var pTags = contentBlock.getElementsByTagName("p");
	var divTags = contentBlock.getElementsByTagName("div");
	var expandDiv = document.getElementById("expandDivLeft");
	var heightP=0;
	var heightD=0;

	for(var i=0; i < pTags.length; i++)
	{
		if(pTags[i].scrollHeight > heightP)
			heightP = pTags[i].scrollHeight;
	}
	for(var i=0; i < divTags.length; i++)
	{
		if(divTags[i].scrollHeight > heightD)
			heightD = divTags[i].scrollHeight;
	}
	expandDiv.style.height = ((heightD + heightP)/2) + 20 + "px";
	contentBlock.style.height =(((heightD + heightP)/1.2) + 20 )+"px";
	
}

/**
 * This function fixes the content block which contains the zip code in the Corporate section.
 * Because of the template the page is biased on  it was necessary to change and remove elements of the 
 * cell to insure proper placement.
 * @member ZipCodeNS
 */
 
function fixContactUs()
{
	var cBlock4 = document.getElementById("ContentBlock4");
	var cBlock4ParentTd = cBlock4.parentNode;
	cBlock4ParentTd.style.padding = 0;
	var cBlock4Table = cBlock4ParentTd.parentNode;
	cBlock4Table.style.background = "";
	var TableFirstChild = cBlock4Table.firstChild;
	cBlock4Table.removeChild(TableFirstChild);
}


/**
 * This function fixes the loginType for Tampa bay since its a different form for 
 * Tampa then CFL.
 * @member ZipCodeNS
 * @depreciated Prime target for moving to the block itself
 */
 /**  Need rewrite for multiple divisions **/
 /*
function fixMyAccount()
{
      
	if(division[0] == "tampabay")
	{
		var loginType = document.getElementById("loginType");
		loginType.value="onlinePaymentForm"		
		//loginType.options[0] = new Option('Online Payment','onlinePaymentForm');
		//loginType.options[1] = new Option('Digital Phone Statement','diPhFormT');	
		//loginType.options[0].selected = true;
	}
}
*/

/**
 * This function checks the login box for my account. To see if they 
 * are blank.
 * @member LoginNS
 * @param {object} f The form Object
 * @returns A value representating if the information has been filled in.
 * @type Boolean
 */
 /**  Need rewrite for multiple divisions espanol**/
function checkLogonData(f)
{
   if ((trimAll(f.userName.value.length) == 0) || (trimAll(f.password.value.length) == 0))
   { 
	   if(division[0] == "espanol") // division espanol
		{
			alert("Por favor coloque su nombre de usuario y la contrase"+ unescape('%F1') +"a.");
		}
		else
		{
			alert("Please enter a Username and Password.");
		}
      
      return false;
   }
   return true;
}

/**
 * This function validates the user input then depending on the form
 * creates the needed variables and submits to the proper url. 
 * @member LoginNS
 * @param {object} e The event object
 * 
 */
 /**  Need rewrite for multiple divisions **/
function doLogin(e) {

	var ev = e.loginType.value;    
    
	if(division[0] == "espanol")
	{
		if(trimAll(e.username.value) == 0)
		{   alert("Por favor coloque su nombre de usuario");
			window.event.returnValue = false;
			return;
		}
		else if (trimAll(e.password.value) == 0)
		{   alert("Por favor coloque su contrase" + unescape('%F1') + "a");
			window.event.returnValue = false;
			return;
		}
	}
	else
	{
		if(trimAll(e.username.value) == 0)
    	{   alert("Please enter your User Name");
			window.event.returnValue = false;
			return;
		}
		else if (trimAll(e.password.value) == 0)
		{   alert("Please enter your password");
			window.event.returnValue = false;
			return;
		}
	}
	
	
    

	//var loginVars = division[0] + "_Login";
	var loginVars = eval(division[0] + "_login");
	
	var userVar =  document.getElementsByName(loginVars["user"])[0];
	var passVar = document.getElementsByName(loginVars["pass"])[0];
	
	userVar.value = e.username.value;
	passVar.value = e.password.value;
	//alert(userVar.value);
	
	/*
    else if (ev == "diCaForm") {
              document.forms[ev].userID.value = e.username.value
              document.forms[ev].password.value = e.password.value
		diCaForm cfl
		diCaForm clf
    }
    else if (ev == "diPhForm"){
           document.forms[ev].S16_.value = e.username.value
              document.forms[ev].S20_.value = e.password.value

    }
    else if (ev == "diPhFormT"){
           document.forms[ev].S16_.value = e.username.value
              document.forms[ev].S20_.value = e.password.value

    }
    else if (ev == "onlinePaymentForm") {
           document.forms[ev].userName.value = e.username.value
              document.forms[ev].password.value = e.password.value
    	tampabay
    }
	*/
             document.forms[ev].submit();     
}

/**
 * This function resets the login form after its been submitted.
 * @member LoginNS
 * @param {object} f The form object.
 */

function rVoidLogin(f) {
	f.username.value="";
	f.password.value="";
	return false;
}


/**   Form submitions  **/
/**
 * This function does error checking on the order online form and submits the
 * form is the values are correct and corresponding with the necessary fields.
 * Submits the order online forms depending on division urls are at the very top of this javascript file.
 * @member OrderOnlineNS
 * @param {object} theform The form Object
 * @param {object} evt The event Object
 * @param {int} go Really a Boolean value. Submit the form or not submit the form.
 * @returns A submitted form. If it validates correctly.
 * @type Form object
 */

/**  Need rewrite for multiple divisions **/
/*
var wscPage = "https://secure.cfl.mybrighthouse.com/wsc/Controller/Go?Event=WSC:LOGIN";
var wscPage2 = "https://secure.cfl.mybrighthouse.com/wsc/Controller/Go?Event=WSC:DOADDRESSSEARCH";
var wscPage3 = "https://brths.convergentcare.com/brths/validateSelfCareCustomer.do";
var wscPage4 = "http://wpm-a.voip.bhntampa.com/Ebill/SilverStream/Pages/pgLogin.html;jsessionid=%40454cb4%3a10a00476ca9?SiteNavRoleId=E"
var wscPage5 = "https://tampabay.mybrighthouse.com/order_online/install.aspx"; // tampa order online
var wscPage6 = "https://tampabay.mybrighthouse.com/order_online/upgrade.aspx"; // tampa order online upgrade
*/

/**
 * This function is the event handler for the Order Online forms.
 * Catches the return key press and forwards it to the orderOnlineForm function.
 * @member OrderOnlineNS
 * @param {object} theform The form Object
 * @param {object} evt The event Object
 * @returns The submitted form from orderOnlineForm
 * @type Form object
 * @see orderOnlineForm
 */
 
function setfocusOO(theform, evt)
{
	
    evt = (evt && evt.keyCode) ? evt : ((window.event) ? window.event : "");
	
	if(!theform)
	{
		var temp2 = document.getElementById("orderonline_rnav");
		theform = temp2;
	}
	
	//theform = (theform) ? theform : temp.form;
	
    if (evt && evt.keyCode == 13 )
    {
        return orderOnlineForm(theform, evt,true);
    } 
}


/**		Key Events		**/
/*This part is for focus the forms catch the enter key*/



/**
 * This function is the event handler for the My Account Login.
 * Catches the return key press and forwards it to the doLogin function.
 * @member MyAccountNS
 * @param {object} e The form Object
 * @param {object} evt The event Object
 * @see doLogin
 */
 
function setfocuslogin(e, evt)
{
evt = (evt) ? evt : ((window.event) ? window.event : "");
if (evt && evt.keyCode == 13)
{
doLogin(e);
if (trimAll(e.username.value)!=0 && trimAll(e.password.value)!=0 ){rVoidLogin(e);}
if(isIE5)
	{		
     window.event.returnValue=false;
	 return;
	}
	else
	{
	 evt.preventDefault();
	 return;
	}
return;
} 
}

/**
 * This function is the event handler for the  Zip Code Search in the Corporate Site.
 * Catches the return key press and forwards it to the setcookieHP function.
 * @member CookieNS
 * @param {object} e The form Object
 * @param {object} evt The event Object
 * @see setCookieHP
 */

function setfocusZipHP(f, evt)
{
evt = (evt) ? evt : ((window.event) ? window.event : "");
if (evt && evt.keyCode == 13)
{
setcookieHP(f);
return;
} 
}
/**
 * This function is the event handler for the  Zip Code Search in the Corporate Site interior pages.
 * Catches the return key press and forwards it to the setcookieCB function.
 * @member CookieNS
 * @param {object} f The form Object
 * @param {object} evt The event Object
 * @see setcookieCB
 */
 
function setfocusZip(f, evt)
{

evt = (evt) ? evt : ((window.event) ? window.event : "");
if (evt && evt.keyCode == 13)
{
setcookieCB(f);
return;
} 
}


/**
 * This function is the event handler for the Need Help tool.
 * Catches the return key press and forwards it to the setcookieCB function.
 * @member NeedHelpNS
 * @param {object} f The form Object
 * @param {object} evt The event Object
 * @see goSection
 */
function setfocusNeedHelp(f, evt)
{
    var theInputs = document.getElementsByTagName("select");
	var theformBak = null;
	try
	{
		var test1 = f.topic.options;
	}
	catch(e) {
		theformBak = f;
		f = theInputs;
	}
	if(theformBak)
	{
		f = theformBak;
	}

   evt = (evt) ? evt : ((window.event) ? window.event : "");
    if (evt && evt.keyCode == 13)
    {
        goSection(f);
        return;
    } 
}

/**
 * This function is the event handler for the Search box.
 * Catches the return key press and forwards it to the doSearch1 function.
 * @member SearchNS
 * @param {object} theform The form Object
 * @param {string} va The value of the search form.qt.value
 * @see doSearch1
 */
function setfocusSearch(va, evt)
{
    evt = (evt && evt.keyCode) ? evt : ((window.event) ? window.event : "");
	
	if (evt && evt.keyCode == 13)
    {
        doSearch1(va, evt);
    } 
}

function readySearch()
{
	//var search1 = document.getElementsByName("qt");
    
    // Not every espanol page has a search box
//	if(search1.length > 0)
//	{
//	  search1 = search1[0];
//	  search1.value = "Buscar"	
//	}

    var qtbtn1 = document.getElementsByName("qtbutton");
    var str;

        if (qtbtn1 != null) {

           qtbtn1 = qtbtn1[0];

           qtbtn1.alt="Buscar"

	   str = qtbtn1.src
      
           // Avoid small yellow button because of limited space...
           if (str.indexOf("yellowbtn_f1") == -1) {
           
              qtbtn1.src="/uploadedimages/divisions/generic/searchBTN_sp1.gif" 

              qtbtn1.onmouseover = function anonymous()
              {
                 qtbtn1.src='/uploadedimages/divisions/generic/searchBTN_sp2.gif';
              } 

              qtbtn1.onmouseout = function anonymous()
              {
                 qtbtn1.src='/uploadedimages/divisions/generic/searchBTN_sp1.gif';
              }
            }
        }

//<meta name="lang" content="es" />
}

function checkSearchBox()
{
	var search2 = document.getElementsByName("qt");
	search2 = search2[0];

//	if(division[0] == "espanol")
//	{
//		if(search2.value == "Buscar")
//		{
//			search2.value = "";
//		}
//		else if(search2.value == "")
//		{
//			search2.value = "Buscar";
//		}
//		
//	}
//	else
//	{
//		if(search2.value == "Search")
//		{
//			search2.value = "";
//		}
//		else if(search2.value == "")
//		{
//			search2.value = "Search";
//		}
//	}
}
/*Here Ends part is for focus the forms catch the enter key*/

