/* Version 1.2 last updated by Andrew Burgess on 01-06-2009 */
try{document.execCommand('BackgroundImageCache', false, true);} catch(e){}

/* SWFObject v2.1 <http://code.google.com/p/swfobject/>
	Copyright (c) 2007-2008 Geoff Stearns, Michael Williams, and Bobby van der Sluis
	This software is released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/

/* ROTATE MARQUEES */
	var timeoutVariable; // Global variable for Timeouts. 
	var heroTime = 7000; // used by initiateRotateHero() and  autoRotate(heroToShow)	

/* WINDOWS ONLOAD */
Event.observe(window, 'load', function(){
	var bUnit = $("pageID").readAttribute("rel");

	attLocalization(bUnit);
	
	if ($('rotateNext1')) {
		autoRotate('hero1');
	}
	
	assignPopupHandler();		
	//insert search drop down so javascript enabled browsers can select where to search. Non-js browser will not see a drop down.
	if($("searchDropdown")){
		$("searchDropdown").replace('<label for="selectSearch">Search in: </label><select id="selectSearch"><option id="selectOne" selected="true">Select One</option><option id="cin" value="cin">Wireless</option><option id="res" value="res">Residential</option><option id="uSearch" value="uve">U-verse</option></select>');	
	}

	if(getCookie("uvp_env")){
		//setCookie("uvp_env_homeGreen","yes","365","/","")		
	}

	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))){
		document.title = "AT&T";
	}		
});
function loginOnload() {
	document.forms['Uverse'].elements['style'].value = 'uverse';
	var theC = getCookie("rem");
	if(theC != null) {
		var cArr = theC.split('|');	
		var myApp = cArr[1];
		var myC = cArr[0];
		if(myApp == 'mobility' && myC != null && myApp != 'nonce') {
			var myCArr = myC.split("!");
			$('ctnAreaCode').value = myCArr[0];
			$('ctnPrefix').value = myCArr[1];
			$('ctnNumber').value = myCArr[2];
			$('remWireless').checked = true;
		} else if(myApp == 'accountmanager' && myC != null && myApp != 'nonce') {
			$('accUverse').value = '';
			$('userAccountmanager').value = myC;
			$('remAccountmanager').checked = true;
		} else if(myApp == 'uverse' && myC != null && myApp != 'nonce') {
			$('userAccountmanager').value = '';
			$('accUverse').value = myC;
			$('remUverse').checked = true;
		} 
	}
	else {
		myApp = 'nonce';
	}
	loginSwitch(myApp);
}
function loginSwitch(appToSelect) {
	var getSelectValue = $('login-select').options[$('login-select').selectedIndex].value;
	if(typeof appToSelect != 'undefined') {
		switch(appToSelect) {
			case 'mobility':
				getSelectValue = 'wireless';
			break;
			case 'accountmanager':
				getSelectValue = 'account';
			break;
			case 'uverse':
				getSelectValue = 'uverse';
			break;
			case 'none':
				getSelectValue = 'wireless';
			break;
		}
	}

	$('AMPwd').href = 'https://cprodmasx.att.com/commonLogin/igate_wam/redirect.do?destination=forgotPassword&source=login';
	$('UVPwd').href = 'https://cprodmasx.att.com/commonLogin/igate_wam/redirect.do?destination=forgotPassword&source=login';
	var myC = getCookie("rem");
	if(getSelectValue == "wireless") {
		document.forms['login-select-form'].elements['login-select'].selectedIndex = 0;
		$('divWireless').setStyle({display: 'block'});
		$('divAccountmanager').setStyle({display: 'none'});
		$('divUverse').setStyle({display: 'none'});	
		
		$('ctnAreaCode').title = 'Please enter your phone number, there are 3 auto tabbing text fields, enter your area code';
		$('ctnPrefix').title = 'Enter the next 3 digits of phone number';
		$('ctnNumber').title = 'Enter last 4 digits of phone number';
		
		$('ctnAreaCode').onkeyup = new Function("autotab('Wireless', this, 3)");
		$('ctnPrefix').onkeyup = new Function("autotab('Wireless', this, 3)");
		$('ctnNumber').onkeyup = new Function("autotab('Wireless', this, 4)");
	}
	else if(getSelectValue == "account") {
			
		document.forms['login-select-form'].elements['login-select'].selectedIndex = 1;
		$('divWireless').setStyle({display: 'none'});
		$('divAccountmanager').setStyle({display: 'block'});
		$('divUverse').setStyle({display: 'none'});	
		
	}
	else if(getSelectValue == "uverse") {
		document.forms['login-select-form'].elements['login-select'].selectedIndex = 2;
		$('divWireless').setStyle({display: 'none'});
		$('divAccountmanager').setStyle({display: 'none'});
		$('divUverse').setStyle({display: 'block'});	
	}
}

function autotab (formname, curr_field, char_count) {
	var Val;	
    var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var theEvent = window.event || arguments.callee.caller.arguments[0];	
	Val = (isNN) ? theEvent.which : theEvent.keyCode;

	//CHECKING FOR THE SHIFT KEY OR THE TAB KEY BEING PRESSED
	if (Val == 16 || Val == 9 || Val == 36 || Val == 37 || Val == 39 || Val == 46) {
	} else {
	   var ele_len = document.forms[formname].elements.length;  				//form length
	   var field_legnth = document.forms[formname].elements[curr_field.name].value.length;  //field element
							     					//field length or kepress input count

	   for (var z=0; z<ele_len; z++)
	       document.forms[formname].elements[z].name;

	   if (char_count == field_legnth) {
	      for(var k=0; k<ele_len; k++)
		 if(curr_field.name == document.forms[formname].elements[k].name) {
		    if(document.forms[formname].elements[k+1].type == 'text') {
		    	document.forms[formname].elements[k+1].focus();
		    } else {
		    	document.forms[formname].elements[k+2].focus();
		    }
		    return;
		 }
	   }
	}
}



function remMe(appName) {
	if($(appName).checked == false) {
		setCookie("rem",'',"-1","/","");
		var loginFormName = 'none';
	} else {
		var loginFormName = appName.substr(3,appName.length);
	}
	var cred = '';
	var app = '';
	switch(loginFormName) {
		case 'Wireless':
			cred = $F('ctnAreaCode') + '!' + $F('ctnPrefix') + '!' + $F('ctnNumber');
			app = 'mobility';
		break;
		case 'Accountmanager':
			cred = $F('userAccountmanager');
			app = 'accountmanager';	
		break;
		case 'Uverse':
			cred = $F('accUverse');	
			app = 'uverse';
		break;
	}
	if(loginFormName != 'none') {
		setCookie("rem",cred + '|' + app,"30","/","");	
	}
}



function SearchHome(){
	var localStr = getCookie("attPersistantLocalization");
	var companyStr = "";
	var companyNameStr = "";
	var uLoc = "";
	if ((localStr != null) && (localStr != "")){
		var localArr = localStr.split("|");
		for (i=0; i<localArr.length; i++){
			if (localArr[i].indexOf("company") > -1){
				var companyArr = localArr[i].split("=");
				var companyBar = $("li[id='toolbar']");
				var companyStr = companyArr[1];
				companyNameStr = companyArr[1];				
			}
		}
	}
	
	// get user type
	myULoc = targetingFW.getUserType();
		
	
	if(document.getElementById("query").value == "" || document.getElementById("query").value == null){
		alert("Please enter at least one search keyword in the search field.");
		if($("query")){
			document.getElementById("query").focus();
		}
		else {
			document.getElementById("q").focus();
		}
		return false;		
	}
	

	if(document.getElementById("query").value != "" || document.getElementById("query").value != null){
		var dirtyText = document.getElementById("query").value;
		var searchText = unescape(dirtyText);
		var sendText = searchText.replace(/\s+/g, '+');
		if(myULoc != '') {
			document.getElementById('uLoc').value = myULoc;
		}
		if(companyNameStr != '') {
			document.getElementById('companyStr').value = companyNameStr;
		}
		var bUnit = $("pageID").readAttribute("rel");
		document.homeSearch.submit();
	}
}

function killWindow(){
	var dirtyText = document.getElementById("query").value;
	var searchText = unescape(dirtyText);
	var sendText = searchText.replace(/\s+/g, '+');
	window.location.href=("https://uverse1.att.com/un/ESHAuditing.do?search="+sendText);
}

function attLocalization(bUnit){
	if($('pageID')){
		var localStr = getCookie("attPersistantLocalization");
		if ((localStr != null) && (localStr != "")){
			var localArr = localStr.split("|");
			var stateStr = "";
			for (i=0; i<localArr.length; i++){
				if (localArr[i].indexOf("state") > -1){
					var stateArr = localArr[i].split("=");
					var stateBar = $("li[id='toolbar']");
					stateStr = stateArr[1];
					
					$("localization").replace('<span style="margin-left:5px; font-size:1em"><strong>' + stateStr + '</strong> : <a href="http://www.att.com/gen/general?pid=1080&cdvn=landinglocalization&localization-reset=true&ltype='+bUnit+'&return-path='+window.location.href+'" title="Change">Change</a></span>');
				}
			}
		}
	}
	if(getCookie("uvp_env")){
		//setCookie("uvp_env_homeGreen","yes","365","/",""); 
	}
	/*
	if(getCookie("wirelesscookie")){		
	}
	if(getCookie("homephonecookie")){
	}
	if(getCookie("uvp_env") || getCookie("uvp_env_homeGreen")){
	}
	*/	
}


function setCookie( name, value, expires, path, domain, secure ){
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires ){
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

function getCookie(name) {
	var dc = document.cookie;
	var cname = name + "=";
	var clen = dc.length;
	var cbegin = 0;
	while (cbegin < clen) {
	var vbegin = cbegin + cname.length;
	if (dc.substring(cbegin, vbegin) == cname) {
		var vend = dc.indexOf (";", vbegin);
		if (vend == -1) vend = clen;
			return unescape(dc.substring(vbegin, vend));
		}
		cbegin = dc.indexOf(" ", cbegin) + 1;
		if (cbegin== 0) break;
	}
	return null;
}	

function loadAccordions() {
	if(Prototype.Browser.Opera){
		if($("accTable")){$("accTable").setStyle({fontSize:"10px", textAlign:"left"});}
	}	
	var topAccordion = new accordion('accordion', {
		classNames : {
			toggle : 'accToggler',
			toggleActive : 'toggleActive',
			content : 'accContent'
		},
		defaultSize : {
			width : 230
		},
		direction : 'vertical'
	});
	
	// Open first one
	topAccordion.activate($$('#accordion .accToggler')[0]);		
}

/*-----------------------------------------------------------------------------------------------*/
// accordion.js v2.0
//
// Copyright (c) 2007 stickmanlabs
// Author: Kevin P Miller | http://www.stickmanlabs.com
// 
// Accordion is freely distributable under the terms of an MIT-style license.
//
// I don't care what you think about the file size...
//   Be a pro: 
//	    http://www.thinkvitamin.com/features/webapps/serving-javascript-fast
//     http://rakaz.nl/item/make_your_pages_load_faster_by_combining_and_compressing_javascript_and_css_files
//
if (typeof Effect == 'undefined') 
	throw("accordion.js requires including script.aculo.us' effects.js library!");

var accordion = Class.create();
accordion.prototype = {

	//
	//  Setup the Variables
	//
	showAccordion : null,
	currentAccordion : null,
	duration : null,
	effects : [],
	animating : false,
	
	//  
	//  Initialize the accordions
	//
	initialize: function(container, options) {
	  if (!$(container)) {
	    throw(container+" doesn't exist!");
	    return false;
	  }
	  
		this.options = Object.extend({
			resizeSpeed : 8,
			classNames : {
				toggle : 'accordion_toggle',
				toggleActive : 'accordion_toggle_active',
				content : 'accordion_content'
			},
			defaultSize : {
				height : null,
				width : null
			},
			direction : 'vertical',
			onEvent : 'click'
		}, options || {});
		
		this.duration = ((11-this.options.resizeSpeed)*0.15);

		var accordions = $$('#'+container+' .'+this.options.classNames.toggle);
		accordions.each(function(accordion) {
			//Event.observe(accordion, this.options.onEvent, this.activate.bind(this, accordion), false);
			Event.observe(accordion, 'mouseover', this.activate.bind(this, accordion), false);   				
			Event.observe(accordion, 'click', this.activate.bind(this, accordion), false);
			if (this.options.onEvent == 'mouseover') {
				accordion.onclick = function() {return false;};
			}
			if (this.options.onEvent == 'click') {
				accordion.onclick = function() {return false;};
			}			
			if (this.options.direction == 'horizontal') {
				var options = {width: '0px'};
			} else {
				var options = {height: '0px'};			
			}
			Object.extend(options,{display: 'none'});			
			
			this.currentAccordion = $(accordion.next(0)).setStyle(options);			
		}.bind(this));
	},
	
	//
	//  Activate an accordion
	//
	activate : function(accordion) {
		if (this.animating) {
			return false;
		}
		
		this.effects = [];
	
		this.currentAccordion = $(accordion.next(0));
		this.currentAccordion.setStyle({
			display: 'block'
		});		
		
		this.currentAccordion.previous(0).addClassName(this.options.classNames.toggleActive);

		if (this.options.direction == 'horizontal') {
			this.scaling = {
				scaleX: true,
				scaleY: false
			};
		} else {
			this.scaling = {
				scaleX: false,
				scaleY: true
			};			
		}
			
		if (this.currentAccordion == this.showAccordion) {
		  //this.deactivate();
		} else {
		  this._handleAccordion();
		}
	},
	// 
	// Deactivate an active accordion
	//
	deactivate : function() {
		var options = {
		  duration: this.duration,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			queue: {
				position: 'end', 
				scope: 'accordionAnimation'
			},
			scaleMode: { 
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			},
			afterFinish: function() {
				this.showAccordion.setStyle({
          height: 'auto',
					display: 'none'
				});				
				this.showAccordion = null;
				this.animating = false;
			}.bind(this)
		};    
    Object.extend(options,this.scaling);

    this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
    
		new Effect.Scale(this.showAccordion, 0, options);
	},

  //
  // Handle the open/close actions of the accordion
  //
	_handleAccordion : function() {
		var options = {
			sync: true,
			scaleFrom: 0,
			scaleContent: false,
			transition: Effect.Transitions.sinoidal,
			scaleMode: { 
				originalHeight: this.options.defaultSize.height ? this.options.defaultSize.height : this.currentAccordion.scrollHeight,
				originalWidth: this.options.defaultSize.width ? this.options.defaultSize.width : this.currentAccordion.scrollWidth
			}
		};
		Object.extend(options,this.scaling);
		
		this.effects.push(
			new Effect.Scale(this.currentAccordion, 100, options)
		);

		if (this.showAccordion) {
			this.showAccordion.previous(0).removeClassName(this.options.classNames.toggleActive);
			
			options = {
				sync: true,
				scaleContent: false,
				transition: Effect.Transitions.sinoidal
			};
			Object.extend(options,this.scaling);
			
			this.effects.push(
				new Effect.Scale(this.showAccordion, 0, options)
			);				
		}
		
    new Effect.Parallel(this.effects, {
			duration: this.duration, 
			queue: {
				position: 'end', 
				scope: 'accordionAnimation'
			},
			beforeStart: function() {
				this.animating = true;
			}.bind(this),
			afterFinish: function() {
				if (this.showAccordion) {
					this.showAccordion.setStyle({
						display: 'none'
					});				
				}
				$(this.currentAccordion).setStyle({
				  height: 'auto'
				});
				this.showAccordion = this.currentAccordion;
				this.animating = false;
			}.bind(this)
		});
	}
}
/*-----------------------------------------------------------------------------------------------*/


function assignPopupHandler() {
	$$('a.popup').each(function(element) {
		element.onclick = function() {
			return openPopup(this.href);
		}
	});
	
	$$('a.popupClose').each(function(element) {
		element.onclick = function() {
			return window.close();
		}
	});
}

function openPopup(url){
	window.open(url,'popup_window','height=600,width=800,resizable=yes,scrollbars=yes');
	return false;
}