/**
 * Contains the cookie set for each page.
 */
var COOKIE_SET = extract(document.cookie,'=',';');
var arrOnloadEvents = new Array(100); // 100 maximum functions can be executed on the page load event.
/**
 * Parses the cookie string.
 */
function extract (str, midchar, endchar) {

  var result = new Object();
  var name, value;
  var beginning, middle, end;

  beginning = (str.indexOf("?") == 0) ? 1 : 0;

  while (beginning < str.length) {

    middle = str.indexOf(midchar, beginning);
    end = str.indexOf(endchar, beginning);

    if (end == -1) {
      end = str.length;
    }

    if (middle > end || middle == -1) {
      name = trim(str.substring(beginning, end));
      value = "";
    }
    else {
      name = trim(str.substring(beginning, middle));
      value = trim(str.substring(middle + midchar.length, end));
    }

    result[name] = unescape(value);
    beginning = end + endchar.length;
  }

  return result;
}

/**
 * Returns the specified variable from the query string.
 */
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];
    }
  }
  return '';
}

/**
 * Trims leading and trailing whitespace.
 */
function trim (str) {
  return str.replace(/^\s*|\s*$/g,"");
}

/**
 * Sets the content of the named meta tag to the specified value.
 * If a meta tag with the given name does not exist, it will be added to
 * the document.
 */
function set_meta_tag (name, content) {

	var exists = false;

	// Loop through all existing meta tags
	var meta_tag = document.getElementsByTagName('meta');
	for (var i = 0; i < meta_tag.length; i++) {

		// If the specified tag is found, set its content
		if (meta_tag[i].name == name) {
			meta_tag[i].content = content;
			exists = true;
		}
	}

	// If the tag was not found, create it and add it to the document
	if (!exists) {

		// Create the tag
		var meta = document.createElement('meta');
		meta.name = name;
		meta.content = content;

		// Add it to the head section
		var head = document.getElementsByTagName('head');
		head[0].appendChild(meta);
	}
}

/**
 * Intercepts a menu item click.
 */
function handle_menu_item_click (link) {

  // Move the highlight to the clicked item
  var item = link.parentNode;
  document.cookie = "menu_item_highlighted=" + item.id + ";";

  if (link.href.indexOf("unlinked") > -1) {
    event.returnValue = false;
    window.location.reload();
  }
}

/**
 * Expands the specified menu item, as well as any parent menu items.
 */
function expand_menus (lobjMenuElement) {

  // Expand the item if it has sub-items
  var sub_items = lobjMenuElement.getElementsByTagName('UL');
  if (sub_items.length > 0) {
    css_replace_class(lobjMenuElement, "collapsed", "expanded");
	css_replace_class(lobjMenuElement.getElementsByTagName('A').item(0),"collapsed", "expanded");
  }

  // Expand any parent items
  //while (lobjMenuElement.parentNode.className != "main-menu") {
  while(lobjMenuElement.parentNode.className != "main-menu"){
    lobjMenuElement = lobjMenuElement.parentNode.parentNode;
	css_replace_class(lobjMenuElement,"collapsed", "expanded");
	css_replace_class(lobjMenuElement.getElementsByTagName('A').item(0), "collapsed", "expanded");
  }
}

/**
 * Initializes the main menu.
 */
function init_menu (menu, highlighted) {
  // Activate the specified menu
  var nav = document.getElementById(menu);
  if (nav != null) {
    css_append_class(nav, "active-menu")
  }

  // Apply highlight and expand menus structure
  if (highlighted != null) {
    var highlighted_item = document.getElementById(highlighted);
    if (highlighted_item != null) {
      css_append_class(highlighted_item, "highlighted")

      highlighted_item.getElementsByTagName('A').item(0).className += ' highlighted';
      expand_menus(highlighted_item);
/*
*/







    }
  }
}


/**
 * Handles tab clicks for glossary pages.
 */
function handle_gloss_tab_click (link) {

	// Hide all visible tags
	for (var i = 0; i < 26; i++) {

		var tab = document.getElementById('tab-' + i);
		if (tab != null) {
			tab.className = tab.className.replace(' GlossTabSelected', ' GlossTabDeselected');
			if (tab.id == link.id) {
				tab.className = tab.className.replace(' GlossTabDeselected', ' GlossTabSelected');
			}
		}

		var data_tab = document.getElementById('data-tab-' + i);
		if (data_tab != null) {
			data_tab.className = data_tab.className.replace(' tab-open', ' tab-closed');
			if (data_tab.id == 'data-' + link.id) {
				data_tab.className = data_tab.className.replace(' tab-closed', ' tab-open');
			}
		}
	}
}

/**
 * Intercepts a bio click.
 */
function handle_bio_click (link) {

  if (link.id.match("go-") != null) {

    var current = document.getElementById("tab-init");
    current.className = current.className.replace(' tab-open', ' tab-closed');

    var target = document.getElementById(link.id.replace('go-', 'tab-'));
    target.className = target.className.replace(' tab-closed', ' tab-open');
  }
  else if (link.id.match("return-") != null) {

    var current = document.getElementById(link.id.replace('return-', 'tab-'));
    current.className = current.className.replace(' tab-open', ' tab-closed');

    var target = document.getElementById("tab-init");
    target.className = target.className.replace(' tab-closed', ' tab-open');
  }

  event.returnValue = false;
}

/**
 * Intercepts a community-relations project click.
 */
function handle_comm_rel_click (link) {

  if (link.id.match("go-") != null) {

    var current = document.getElementById("tab-init");
    current.className = current.className.replace(' tab-open', ' tab-closed');

    var head = document.getElementById("tab-head");
    head.className = head.className.replace(' tab-open', ' tab-closed');

    var target = document.getElementById(link.id.replace('go-', 'tab-'));
    target.className = target.className.replace(' tab-closed', ' tab-open');
  }
  else if (link.id.match("return-") != null) {

    var current = document.getElementById(link.id.replace('return-', 'tab-'));
    current.className = current.className.replace(' tab-open', ' tab-closed');

    var target = document.getElementById("tab-init");
    target.className = target.className.replace(' tab-closed', ' tab-open');

    var head = document.getElementById("tab-head");
    head.className = head.className.replace(' tab-closed', ' tab-open');
  }

  event.returnValue = false;
}


/**
 * Toggles between project index views.
 */
function handle_project_index_toggle (link) {

	var elem = document.getElementsByTagName('*');

	for (var i = 0; i < elem.length; i++) {

	  if (elem[i].className.match("Visible") != null) {
	    elem[i].className = elem[i].className.replace(' Visible', ' Hidden');
	  }
	  else if (elem[i].className.match("Hidden") != null) {
      elem[i].className = elem[i].className.replace(' Hidden', ' Visible');
	  }
  }

  event.returnValue = false;
}

/**
 * Handles tab clicks for ESC topic pages.
 */
function handle_esc_tab_click (link) {

  // Hide all visible tags
  for (var i = 0; i < 10; i++) {

    var tab = document.getElementById('tab-' + i);
    if (tab != null) {
      tab.className = tab.className.replace(' ESC_TabSelected', ' ESC_TabDeselected');
      if (tab.id == link.id) {
        tab.className = tab.className.replace(' ESC_TabDeselected', ' ESC_TabSelected');
      }
    }

    var data_tab = document.getElementById('data-tab-' + i);
    if (data_tab != null) {
      data_tab.className = data_tab.className.replace(' Visible', ' Hidden');
      if (data_tab.id == 'data-' + link.id) {
        data_tab.className = data_tab.className.replace(' Hidden', ' Visible');
      }
    }
  }
}

/**
 * Intercepts a bio click.
 */
function handle_article_click (link) {

  if (link.id.match("go-") != null) {

    var current = document.getElementById("tab-init");
    current.className = current.className.replace(' tab-open', ' tab-closed');

    var target = document.getElementById(link.id.replace('go-', 'tab-'));
    target.className = target.className.replace(' tab-closed', ' tab-open');
  }
  else if (link.id.match("return-") != null) {

    var current = document.getElementById(link.id.replace('return-', 'tab-'));
    current.className = current.className.replace(' tab-open', ' tab-closed');

    var target = document.getElementById("tab-init");
    target.className = target.className.replace(' tab-closed', ' tab-open');
  }

  event.returnValue = false;
}

/**
 * Sets the cookie indicating which welcome option is selected.
 */
function handle_welcome_option_click (selected) {

  // Write a cookie with the currently selected option
	document.cookie = "welcome_option_selected=" + selected.id + ";";

  // Highlight the current option and unhighlight everything else
  for (var i = 0; i < 3; i++) {

    var option = document.getElementById('option' + i);
    var cell = document.getElementById('option' + i + '_cell');
    var tab_A = document.getElementById('option' + i + '_A');
    var tab_B = document.getElementById('option' + i + '_B');

	  if (option != null) {
	    if (option.id == selected.id && option.className.match('_Deselected') != null) {
	     	option.className = option.className.replace('_Deselected', '_Selected');
	     	cell.className = cell.className.replace('Deselected', 'Selected');
	     	tab_A.className = tab_A.className.replace(' tab-open', ' tab-closed');
	     	tab_B.className = tab_B.className.replace(' tab-closed', ' tab-open');
	    }
	    else {
	     	option.className = option.className.replace('_Selected', '_Deselected');
	     	cell.className = cell.className.replace('Selected', 'Deselected');
	     	tab_A.className = tab_A.className.replace(' tab-closed', ' tab-open');
	     	tab_B.className = tab_B.className.replace(' tab-open', ' tab-closed');
	    }
	  }
  }

  event.returnValue = false;
}

/**
 * Checks a cookie and highlights the selected option.
 */
function init_welcome_page () {

	var option_selected = COOKIE_SET["welcome_option_selected"];

	if (option_selected != null && option_selected != "") {

		var option = document.getElementById(option_selected);
    var cell = document.getElementById(option_selected + '_cell');
    var tab_A = document.getElementById(option_selected + '_A');
    var tab_B = document.getElementById(option_selected + '_B');
		if (option != null) {
			option.className = option.className.replace('_Deselected', '_Selected');
	    cell.className = cell.className.replace('Deselected', 'Selected');
	    tab_A.className = tab_A.className.replace(' tab-open', ' tab-closed');
	    tab_B.className = tab_B.className.replace(' tab-closed', ' tab-open');
		}

		var msg = document.getElementById('message');
		if (msg != null) {
			msg.className += ' ' + option_selected;
		}
	}
}

/**
 * Sets the cookie indicating which welcome option is selected.
 */
function handle_top_nav_option_click (selected) {

  // Set the current account type
  if (selected.id == "My Home Account") {
    document.cookie = "CurrentCustomerSegment=R;";
  }
  else if (selected.id == "My Business Account") {
    document.cookie = "CurrentCustomerSegment=B;";
  }

  // Go to the selected navigation item
	document.location.href = selected.href;
}

/**
 * Sets the cookie indicating which welcome option is selected.
 */
function handle_top_nav_option_goto (selected, goto_url) {

  // Set the current account type
  if (selected.id == "My Home Account") {
    document.cookie = "CurrentCustomerSegment=R;";
  }
  else if (selected.id == "My Business Account") {
    document.cookie = "CurrentCustomerSegment=B;";
  }

  // Go to the selected navigation item
	document.location.href = goto_url;
}

/**
 * Handles mouseovers on the top nav.
 */
function handle_top_nav_mouseover (selected) {

  if (selected.className.match("Selected") == null) {
    var e = selected.getElementsByTagName('DIV');
    e[0].style.backgroundPosition = '-250px bottom';
  }
}

/**
 * Handles mouseouts on the top nav.
 */
function handle_top_nav_mouseout (selected) {

  if (selected.className.match("Selected") == null) {
    var e = selected.getElementsByTagName('DIV');
    e[0].style.backgroundPosition = 'left bottom';
  }
}

/**
 * Highlights the selected option in the top navigation.
 */
function init_standard_header (option) {

  var opt = document.getElementById(option);
  if (opt != null) {

		opt.className = opt.className.replace(' Deselected', ' Selected');

		var images = opt.getElementsByTagName('IMG');
		images[0].src = images[0].src.replace('_idle','_highlight');
  }
}

/**
 * Sets the default tab on the FAQ index page, or hides tabs if not required by
 * user profile.
 */
function init_faq_index_tabs () {

  var current = COOKIE_SET["CurrentCustomerSegment"];

  var tab_0 = document.getElementById('tab-0');
  var tab_1 = document.getElementById('tab-1');

  // Select the appropriate tab
  handle_esc_tab_click(current == 'B' ? tab_1 : tab_0);
}

/**
 * Swaps out element classes
 */
function ChangeClass (vstrElementId, vstrClassName) {

  var element = document.getElementById(vstrElementId);
  if (element != null) {
    element.className = vstrClassName;
  }
}

/**
 * Renders the Signout Button in the Loggedin or Loggedout state
 */
function RenderSignoutImage (vstrLoggedInClass, vstrLoggedOutClass) {

	if (SmIsLoggedIn()) {
    ChangeClass('idLogoutButton',vstrLoggedInClass);
	}
	else {
    ChangeClass('idLogoutButton',vstrLoggedOutClass);
	}
}

/**
 * Function Check to test if the user is logged in or not.
 */
function SmIsLoggedIn () {

	var smsession = COOKIE_SET["SMSESSIONID"];

	if (smsession != null && smsession.length > 0) {
		return true ;
	}
	else {
		return false;
	}
}

/**
 * Preloads rollover images.
 */
function preload_images () {

  if (document.images) {

    var pic1= new Image(297,34);
    pic1.src="/en_US/Images/Site_Component_Images/Header/title_for_your_home_hi.png";

    var pic2= new Image(297,34);
    pic2.src="/en_US/Images/Site_Component_Images/Header/title_for_your_business_hi.png";

    var pic3= new Image(297,34);
    pic3.src="/en_US/Images/Site_Component_Images/Header/title_access_your_account_hi.png";

    var pic4= new Image(200,8);
    pic4.src="/en_US/Images/Site_Component_Images/Header/main_nav_rollover.jpg";
  }
}

/**
 * Handles 'Learn More' link on prospect overview page.
 */
    function newenroll (frm) {

      frm.txtZipcode.value = (frm.txtZipcode.value == '') ? COOKIE_SET['txtZipcode'] : frm.txtZipcode.value;
      frm.dwelling.value = (frm.dwelling.value == '') ? COOKIE_SET['dwelling'] : frm.dwelling.value;
      frm.zipvalidate.value = (frm.zipvalidate.value == '') ? COOKIE_SET['zipvalidate'] : frm.zipvalidate.value;
      frm.txtgeoZone.value = (frm.txtgeoZone.value == '') ? COOKIE_SET['txtgeoZone'] : frm.txtgeoZone.value;
      frm.txtEmailAdd.value = (frm.txtEmailAdd.value == '') ? COOKIE_SET['txtEmailAdd'] : frm.txtEmailAdd.value;
      frm.txtAreYouCustomer.value = (frm.txtAreYouCustomer.value == '') ? COOKIE_SET['txtAreYouCustomer'] : frm.txtAreYouCustomer.value;
      frm.txtAAdvantage.value = (frm.txtAAdvantage.value == '') ? COOKIE_SET['txtAAdvantage'] : frm.txtAAdvantage.value;
      frm.txtPromocode.value = (frm.txtPromocode.value == '') ? COOKIE_SET['txtPromocode'] : frm.txtPromocode.value;
      frm.txtTDSP.value = (frm.txtTDSP.value == '') ? COOKIE_SET['txtTDSP'] : frm.txtTDSP.value;
      frm.tagtype.value = (frm.tagtype.value == '') ? COOKIE_SET['tagtype'] : frm.tagtype.value;
      frm.errorfield.value = (frm.errorfield.value == '') ? COOKIE_SET['errorfield'] : frm.errorfield.value;
      frm.errorfieldPath.value = (frm.errorfieldPath.value == '') ? COOKIE_SET['errorfieldPath'] : frm.errorfieldPath.value;

	  // CEP Changes
	  frm.cid.value = (frm.cid.value == '') ? COOKIE_SET['cid'] : frm.cid.value;
	  frm.program.value = (frm.program.value == '') ? COOKIE_SET['program'] : frm.program.value;
	  // CEP Changes

	//Mover Concierge
	  frm.txtRealtorId.value = (frm.txtRealtorId.value == '') ? COOKIE_SET['txtRealtorId'] : frm.txtRealtorId.value;
	//Mover Concierge

      frm.submit();

      event.returnValue = false;
    }

function intermediate_check()
{

	var OfferCode = COOKIE_SET["txtOfferCode"];
	var zipCode = COOKIE_SET["zipCode"];
	alert("The Offer Code is "+ OfferCode );
	alert("The Zip Code is "+ zipCode );

         if(null != OfferCode && "" != OfferCode)
	 {
		alert("Inside if");
		location.href='/ResProspectOverview.do';
	 }
	 else
	 {
		alert("Inside else");

		if(null != OfferCode && "" != OfferCode)
	        {
			alert("Inside inner if");
			location.href='/en_US/OWE/residential/newenroll.jsp?tag_value=OWE_V1&tagtype=OWE_V1';
		}
		else
		{

			alert("Inside inner else");
			location.href='/en_US/OWE/residential/newenroll.jsp';
		}

	 }


}

/**
 * Replaces a series of tags in the specified message with personalized
 * values.
 */
function add_personalization (message, replacements) {

  for (var i in replacements) {
    message = message.replace(i, replacements[i]);
  }

  return message;
}

/**
 * Appends an onload function to the holder array.
 */
function add_onload_event(vstrFunctionName) {

	arrOnloadEvents[arrOnloadEvents.length] = vstrFunctionName;

}

/**
 * iterates through the onload events and runs them in order
 */
function launch_onload_events(){

	var lintCount = 0;

	for(lintCount = 0; lintCount <= arrOnloadEvents.length; lintCount++){
		if(arrOnloadEvents[lintCount]){
		eval(arrOnloadEvents[lintCount]);
		}
	}

}

/**
 * changes the css display property of an element
 */
function setDisplayById(vstrElementId, vstrStyleVal){
	document.getElementById(vstrElementId).style.display = vstrStyleVal;
}
/**
 * changes the css visibility property of an element
 */
function setVisibilityById(vstrElementId, vstrStyleVal){
	document.getElementById(vstrElementId).style.visibility = vstrStyleVal;
}

/**
 * Fix for crossbrowser (IE vs Firefox) compatibility for png24 and alpha layer transparancy
 */
function LoadPng24(vstrImageId, vstrImageUrl, vstrWidth, vstrHeight){
	if(GetBrowserName() == "Internet Explorer 6"){
		document.getElementById(vstrImageId).innerHTML = "<img id=\"" + vstrImageId + "_img\" style=\"width:" + vstrWidth + ";height:" + vstrHeight + ";filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + vstrImageUrl + "', sizingMethod='scale')\" src=\"/en_US/Images/Site_Component_Images/Content_Area_1/clear.png\"  />";
	}else{
		document.getElementById(vstrImageId).innerHTML = "<img id=\"" + vstrImageId + "_img\" style=\"width:" + vstrWidth + ";height:" + vstrHeight + ";\" src=\"" + vstrImageUrl + "\" />";
	}
}

/**
 * Returns the clients browser name
 */
function GetBrowserName() {

	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie 6.0") != -1) return 'Internet Explorer 6';
	if (agt.indexOf("msie 7.0") != -1) return 'Internet Explorer 7';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
	if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
	return navigator.userAgent.substr(0,agt.indexOf('\/'));}
	else return 'Netscape';} else if (agt.indexOf(' ') != -1)
	return navigator.userAgent.substr(0,agt.indexOf(' '));
	else return navigator.userAgent;

}

/**
 * Javascript Url redirect function
 */
function GoTo(vstrUrl){
	document.location.href=vstrUrl;
}


/**
 * Toggles the visibility of the "View All Plans" button on the the residential prospect overview page.
 */
function ToggleViewAllPlansButton(){

	var lblnShowAllPlansButton = false;

	//Code to determine if there is more than one plan available to this zip code.
	var lstrPlanList = COOKIE_SET["txtOfferCode"];
	var larrPlanList = lstrPlanList.split("|");
	if(larrPlanList.length > 1){
		lblnShowAllPlansButton = true;
	}

	//Code to remove/show the button based on the above codes results.
	if(lblnShowAllPlansButton){
		document.getElementById("idViewAllPlansButton").style.display="block";
	}else{
		document.getElementById("idViewAllPlansButton").style.display="none";
	}
}

/**
 * Toggles the visibility of the "Contact Us" button on the the business prospect overview page.
 */
function ToggleContactUsButton(){
	var lblContactButton = false;
	//Code to determine if usageAmount is more.
	var usage = COOKIE_SET["usageAmount"];
	if(null != usage && "" != usage)
	{
		lblContactButton = true;
	}

	//Code to remove/show the button based on the above codes results.
	if(lblContactButton){
		document.getElementById("idContactUs").style.display="block";
	}else{
		document.getElementById("idContactUs").style.display="none";
	}
}

function ToggleOfferView(){
	var lblOfferCode = false;
	//Code to determine if usageAmount is more.
	var offerCode = COOKIE_SET["txtOfferCode"];
	var zipCode = COOKIE_SET["txtZipcode"];
	if((undefined==offerCode) || (undefined==zipCode))
		location.href='/en_US/OWE/residential/newenroll.jsp';
	else
	{	
		if(null != offerCode && "" != offerCode)
		{
			lblOfferCode = true;
		}
		
		//Code to remove/show the button based on the above codes results.
		if(lblOfferCode){
			document.getElementById("id_offer_display").style.display="block";
		}else{
			document.getElementById("id_offer_display").style.display="none";
			//location.href='/en_US/OWE/residential/newenroll.jsp';
			//location.href='/en_US/OWE/residential/newenroll.jsp?errorfield=NOOFFER&errorfieldPath=true';
			location.href='/' + LANGUAGE_CODE +'/OWE/residential/newenroll.jsp?errorfield=NOOFFER&errorfieldPath=true';
		}
	}
}



/**
 * Firefox friendly way of replacing classnames within an html element.
 */
function css_replace_class(vobjElement, vstrOldClassName, vstrNewClassName){
	//Grab the value of the class attribute from the object
	var lstrClass = vobjElement.className;
	//debug_alert(vobjElement.id + " " + lstrClass);

	if(lstrClass){
		//Create an array with the class values
		var larrClasses = lstrClass.split(" ");

		var lintCount;

		//Loop through the array find the original class name and replace with the new class
		//	name
		for(lintCount = 0; lintCount < larrClasses.length; lintCount++){
			if(larrClasses[lintCount] == vstrOldClassName){
				larrClasses[lintCount] = vstrNewClassName;
				//debug_alert(vstrOldClassName + " => " + vstrNewClassName);
			}
		}

		var lstrClassBuffer = "";
		//Put the class back together
		for(lintCount = 0; lintCount < larrClasses.length; lintCount++){
			lstrClassBuffer+= larrClasses[lintCount] + " ";
		}
		//debug_alert(lstrClassBuffer);

		//re-assign the class to the html element.
		vobjElement.className = lstrClassBuffer;
	}
}

function css_append_class(vobjElement, vstrClassName){
	//Grab the value of the class attribute from the object
	vobjElement.className+= " " + vstrClassName;
}

/**
 * Site friendly alert.. does not pause the application.
 */
var mobjDebugWindow = null;
function debug_alert(vstrString){
	var showDebugMessages = false;
	switch (get_site_from_url()) {
		case "dev.www.reliant.com:8085":
			showDebugMessages = true;
			break;
	}
	var isDebug = true;//true;
	if(isDebug && showDebugMessages){
		if(mobjDebugWindow == null){
			mobjDebugWindow = window.open('/en_US/layouts/base_debug_popup_window.jsp','rel_debug_window','width=400,height=400,toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
		}
		mobjDebugWindow.document.write("<div style='margin:0px; padding:5px;font-family:arial;font-size:11px;border-bottom:1px #CCCCCF solid;background-color:#F3F3FF;'>" + vstrString + "</div>");
	}
}

/**
 * Site friendly alert.. will also pause the application.
 */
function debug_alert_pause(vstrString){
	if (get_site_from_url()== "dev.www.reliant.com:8085") {
			alert(vstrString);
			debug_alert("<b>PAUSE:</b> " + vstrString);
	}
}

function get_site_from_url(){
	var lstrUrl = document.URL;
	lstrUrl = lstrUrl.replace("http://", "");
	var larrUrlItems = lstrUrl.split("/");
	return larrUrlItems[0];
}

function update_faq_area() {

  var faq_list = document.getElementById("id_faq_list");
  if (trim(faq_list.innerHTML).length > 0) {
    document.getElementById("id_faq_area").style.display = "block";
  }

  if (LANGUAGE_CODE == 'es_US') {
    document.getElementById("id_faq_label").innerHTML = "Preguntas frecuentes";
    document.getElementById("id_more_faqs").innerHTML = "Ver m&aacute;s preguntas frecuentes";
  }
  else {
    document.getElementById("id_faq_label").innerHTML = "FAQs";
    document.getElementById("id_more_faqs").innerHTML = "View more FAQs";
  }
}
/**
 * Redirects to itself with a message code if we are not in an approved browser
 */
function check_browser(){

  	var agt=navigator.userAgent.toLowerCase();
	var larrDeniedBrowsers = new Array("Safari");	
	var i;
	var lblnDeniedBrowser = false;
	var lstrBrowserName = GetBrowserName();
	
	for(i = 0; i<larrDeniedBrowsers.length; i++){
		if(larrDeniedBrowsers[i] == lstrBrowserName){
			lblnDeniedBrowser = true;
		}
	}
	
	var msg_code=getQueryVariable("msg_code");
	var lstr_incompatible_browser_msg_code = "browser_support";
	var lblnInErrorPage = false;
	
	
	if(msg_code.indexOf(lstr_incompatible_browser_msg_code) > -1){
		lblnInErrorPage = true;
	}
	
	
  	if((lblnDeniedBrowser) && !(lblnInErrorPage)){
		var lstrDelimeter;
		if(document.location.href.indexOf("?") > -1){
			lstrDelimeter = "&";
		}else{
			lstrDelimeter = "?";
		}
		var lstrThisPage = document.location.href.replace("msg_code=" + msg_code,"");
		GoTo(lstrThisPage + lstrDelimeter + "msg_code=" + msg_code + "|" + lstr_incompatible_browser_msg_code);
	}

}

/**
 * Pops up a window - every visit to that page - not recommended except on exit or confirmation pages
 */
function pop_up_window(vstrUrl,vstrWidth,vstrHeight){

	mobjNewWindow = window.open(vstrUrl,'rel_new_window','width=" + vstrWidth + ",height=" + vstrHeight + ",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');

}


/**  *********** use empty function when survey is not up,
	so that page load call doesn't have to be removed from layouts 

function loadornot() {
}
	*********** **/

/** ***********
 * Survey popup script - checks, sets cookie value, does popup 
 * added random number to limit pops to X percent of traffic
 * can be adjusted by change what random_num is less than
 * currently set to less than 3 of 9 for 33 percent
 *********** */
var popurl="http://www.surveyforyou.net/~rsrch/cgi-bin/ciwweb.pl?studyname=REWS&Password=password";
function openpopup(popurl) {
	var winpops=window.open(popurl,"","width=607,height=361,scrollbars=yes,resizable=yes");
}
function get_cookie(Name) {
	var search = Name + "=";
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search);
		if (offset != -1) { 
			offset += search.length;
			end = document.cookie.indexOf(";", offset);
			if (end == -1)
				end = document.cookie.length;
				returnvalue=unescape(document.cookie.substring(offset, end));
			}
		}
	return returnvalue;
}
var popfrequency='20 days';
function resetcookie() {
	var expireDate = new Date();
	expireDate.setDate(expireDate.getDate()-20);
	document.cookie = "survpop=;expires=" + expireDate.toGMTString();
}
function loadornot() {
		if (get_cookie('survpop')=='') {
			random_num = (Math.floor(Math.random()*99))
			if (random_num < 30) {  // limit popup to 30 percent of traffic - normally 10
				openpopup(popurl);
			}
					var expireDate = new Date();
					expireDate.setDate(expireDate.getDate()+parseInt(popfrequency));
					document.cookie = "survpop="+parseInt(popfrequency)+";expires=" + expireDate.toGMTString();
		}
}
if (get_cookie('survpop')!=parseInt(popfrequency)) {
	resetcookie();
	}



/**
 * Fills an empty div with images passed from the tiles of the page..
 */
function create_tracking_images(){
	
	var tracking_url_div = document.getElementById("id_tracking_urls");
	var tracking_urls = tracking_url_div.getElementsByTagName("span");
	var tracking_image;
	var tracking_images = document.getElementById("id_tracking_images");
	var i;
	var url_src;
	
	for(i=0;i<tracking_urls.length;i++){
		url_src = parse_info_url(tracking_urls[i].innerHTML.replace("&amp;","&"));

		if(url_src.length > 0){
			tracking_image = document.createElement("img");
			tracking_image.setAttribute("src",url_src);
//			tracking_image.setAttribute("style","border:10px #333333 solid;");
			tracking_images.appendChild(tracking_image);
		}
	}
}

/**
 * Parses dynamic datasets in a custom url.  Built specifically to allow dynamic data to populate 
 * static urls at runtime for tracking-urls (1,2).
 */
function parse_info_url(url){

	var set_search = "\\[(cookie|querystring|form),(.{1,15})\\]";
	var regx = new RegExp(set_search,"g");
	
	var mtch;
	var result_url = url;
	found_a_match = true;
	while(found_a_match){
		
		mtch = regx.exec(url);
		if (mtch != null) {
			var s = "Match at position " + mtch.index + ":\n";
			for (i = 0; i < mtch.length; i++) {
				s = s + mtch[i] + "\n";
			}
			result_url = result_url.replace(mtch[0],lookup_value(mtch[1],mtch[2]));
		}else{
			found_a_match = false;
		}
	}
	return result_url;
}

/**
 * looks up values in either the cookie or querystring of the page 
 */
function lookup_value(str_lookuptype,str_key){
	var str_returnvalue;
	switch(str_lookuptype){
		case "cookie":
			str_returnvalue = COOKIE_SET[str_key];
			break;
		case "form":
			str_returnvalue = get_form_value(str_key);
			break;
		case "querystring":
			str_returnvalue = getQueryVariable(str_key);
			break;
	}
	
	return str_returnvalue;
}

function get_form_value(str_key){
		var frms = document.forms;
		var default_value = "undefined";
		var new_value;
		for(i = 0; i < frms.length; i++ ){
			if(eval("frms[i]." + str_key)){
				return eval("frms[i]." + str_key + ".value");
			}
		}
}

function forward_to_secure(){
	if(window.location.href.lastIndexOf("http://") >= 0){
		window.document.location.href = window.document.location.href.replace("http://","https://");
	}
}
