function localLinkFix() {
	// loops through the links on the page and will make clicks to set domains skip the NPS survey
   var myArray = document.links;
   for (i=0;i<myArray.length;i++) {
	  if (myArray[i].href.indexOf('qwest.com') ==-1 && myArray[i].href.indexOf('tservicesq.com') == -1 && myArray[i].href.indexOf('qwestwifilocator.com') == -1 && myArray[i].href.indexOf('qwest.xanboo.com') == -1 && myArray[i].href.indexOf('qweststore.cellmania.com') == -1 && myArray[i].href.indexOf('vzwshop.com') == -1 && myArray[i].href.indexOf('www.twitter.com/talktoqwest') == -1 && myArray[i].href.indexOf('storelocator.qwestapps.com') == -1 && myArray[i].href.indexOf('.live.com') == -1 && myArray[i].href.indexOf('.qwestreferafriend.com') == -1 && myArray[i].href.indexOf('.dexknows.com') == -1 && myArray[i].href.indexOf('incredibleinternet.com') == -1 && myArray[i].href.indexOf('trackBannerSelection')==-1 && myArray[i].href.indexOf('javascript')==-1 && myArray[i].href.indexOf('/residential/')==-1 && myArray[i].href.indexOf('/smallbusiness/')==-1 && myArray[i].href.indexOf('localhost')==-1) myArray[i].onclick=setAbandoningPage;
	  else if(myArray[i].href.indexOf('javascript')==-1){ //do this to ensure that the banner rotation links still work
		myArray[i].onclick=setNotAbandoningPage;
	}
   }
}
function setAbandoningPage() {
// skips NPS suvrey if this is false, part of onclick so need return
   window.abandoningPage=true;
   return true;
}
function setNotAbandoningPage(){
	window.abandoningPage=false;
	return true;
}

function targetBlank (url) {
  blankWin = window.open(url,'_blank','menubar=yes,toolbar=yes,location=yes,directories=yes,fullscreen=no,titlebar=yes,hotkeys=yes,status=yes,scrollbars=yes,resizable=yes width=1100,height=680');
}

function getOceQCookie(strPageCookie){
	cookieString = document.cookie;
	index = cookieString.indexOf(strPageCookie + "=");
	if (index == -1)
		return null;
	index = cookieString.indexOf("=", index) + 1;
	endstr = cookieString.indexOf(";", index);
	if (endstr == -1) endstr = cookieString.length;
	return unescape(cookieString.substring(index, endstr));
}

function validateTN(formName){
	npa = document.forms[formName].npa;
	nnx = document.forms[formName].nnx;
	line = document.forms[formName].line;
	qLinkName = document.forms[formName].evar6.value;
	invalid = false;

	if(npa.value.search(/\d\d\d/))
	invalid = npa;
	else if(nnx.value.search(/\d\d\d/))
	invalid = nnx;
	else if(line.value.search(/\d\d\d\d/))
	invalid = line;
	if(invalid)
	{
		invalid.focus();
		alert("You must enter a valid telephone number.");
	}
	else
	{
		track6(qLinkName);
		document.location = "/shop/residential/broadbandlanding?tn=" + npa.value + nnx.value + line.value;
	}
	return false;
}
function submitEnter(formname){
	if (window.event && window.event.keyCode == 13)
		validateTN(formname);
}
function submitLogin(){
	if (window.event && window.event.keyCode == 13)
		residential_login.submit();
}
function submitLoginHome(){
	if (window.event && window.event.keyCode == 13)
		residential_login.submit();
}
function track6(qLinkName){
	var s=s_gi(s_account);s.templtv=s.linkTrackVars;s.templte=s.linkTrackEvents;s.linkTrackVars='eVar6';s.eVar6=qLinkName;s.tl(this,'o',qLinkName);if(s.templtv)s.linkTrackVars=s.templtv;if(s.templte)s.linkTrackEvents=s.templte;
}

var timeout    = 100;
var closetimer = 0;
var dd_active = false;

function dd_close() {
	$("#nav_tabs li").removeClass("hover_tab");
	$("#nav_tabs li").removeClass("hover_off");

	$("#nav_account").removeClass("hover_tab");

	if(dd_active) dd_active.css('visibility', 'hidden');
}

function dd_open() {
	dd_cancel();
	dd_close();
	dd_shift($(this));

	$(this).addClass("hover_tab");
	dd_active = $(this).find('ul.nav_dd').css('visibility', 'visible');
}

function dd_shift(element_id) {
	if($("#nav_residentials").html() == element_id.html()) {
		$("#nav_small_business ").addClass("hover_off");
		$("#nav_enterprise").addClass("hover_off");
	} else if($("#nav_small_business").html() == element_id.html()) {
		$("#nav_residentials ").addClass("hover_off");
		$("#nav_enterprise").addClass("hover_off");
	}
}

function dd_timer () {
	closetimer = window.setTimeout(dd_close, timeout);
}

function dd_cancel(){
	if(closetimer) {
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

function parseURL( name )	{
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( window.location.href );
	  if( results == null )
		return "";
	  else
		return results[1];
	}

function load_content(contentLocation, contentName, isLoaded){
	if(!isLoaded){
		$(contentLocation).load(contentName);
		switch(contentLocation){
			case "#hsi_content":
				tabLoaded['hsi']=true;
			break; 
			case "#tv_content":
				tabLoaded['tv']=true;
			break;
			case "#phones_content":
				tabLoaded['phones']=true;
			break;
			case "#service_content":
				tabLoaded['service']=true;
			break;
			case "#qwestatease_content":
				tabLoaded['qwestatease']=true;
			break;
		}
	}
	show_content(contentLocation);
}
function show_content(contentLocation){
	var divName=contentLocation.split("_");
	//remove leading #
	var myContent=divName[0].replace("#","");
	window.location.hash=myContent;
	hide_content();
	$(contentLocation).fadeIn(500);
}
function show_layer(new_layer){
		if(current_layer != new_layer){
			hide_layers();
			$(new_layer).fadeIn(250);
			current_layer = new_layer;
		}
	}


function hide_content(){
	$('#offers_content').hide();
	$('#connected_content').hide();
	$('#hsi_content').hide();
	$('#tv_content').hide();
	$('#phones_content').hide();
	$('#service_content').hide();
	$('#qwestatease_content').hide();

	$('#offersNav a').removeClass('offersNavSelected');
	$('#connectedNav a').removeClass('connectedNavSelected');
	$('#hsiNav a').removeClass('hsiNavSelected');
	$('#tvNav a').removeClass('tvNavSelected');
	$('#phonesNav a').removeClass('phonesNavSelected');
	$('#serviceNav a').removeClass('serviceNavSelected');
}

function clearJsession() {
 if(hasJSessionCookie()) {
  setCookie('JSESSIONID', '0', '', '/', getDomain(), '');
 }
}

function setCookie( name, value, expires, path, domain, secure ){
 // set time, it's in milliseconds
 var today = new Date();
 today.setTime( today.getTime() );

 document.cookie = name + "=" +escape( value ) +
 ( ( expires ) ? ";expires=" + expires : "" ) +
 ( ( path ) ? ";path=" + path : "" ) +
 ( ( domain ) ? ";domain=" + domain : "" ) +
 ( ( secure ) ? ";secure" : "" );
}

function getCookie( check_name ) {
 var a_all_cookies = document.cookie.split( ';' );
 var a_temp_cookie = '';
 var cookie_name = '';
 var cookie_value = '';
 var b_cookie_found = false;

 for ( i = 0; i < a_all_cookies.length; i++ )
 {
  a_temp_cookie = a_all_cookies[i].split( '=' );
  cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
  if ( cookie_name == check_name )
  {
   b_cookie_found = true;
   if ( a_temp_cookie.length > 1 )
   {
    cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
   }
   return cookie_value;
   break;
  }
  a_temp_cookie = null;
  cookie_name = '';
 }
 if ( !b_cookie_found )
 {
  return null;
 }
}

// Checks to see if cookie exists
function hasJSessionCookie() {
 var hasCookie = false;
 var cookieValue = getCookie('JSESSIONID');

 if (cookieValue == null) {
  hasCookie = false;
 } else {
  hasCookie = true;
 }

 return hasCookie;
}

function getDomain() {
 var cookieDomain = document.domain;
 if (cookieDomain.indexOf('qwest.com') > -1) {
  cookieDomain = ".qwest.com";
 } else if (cookieDomain.indexOf("tservicesq.com") > -1) {
  cookieDomain = ".tservicesq.com";
 }
 return cookieDomain;
}