/**
 * JavaScript: Global Landing JavaScript include
 *
 * @file              /javascript/global_landing.js
 * @author            chris.geheran@barclaysglobal.com
 * @revision          $Id$
 */


		/*
		 * @DESC:
		 *
		 *  SHOW INVESTOR TYPE:
		 *  Displays the investor type box for european countries
		 *
		*/
		function showInvestorType(countryCd) {
			var investorDivId = "gl_investortype_"+countryCd;
			var divRef = document.getElementById(investorDivId);

			hideInvestorTypes();
			highlightItem(countryCd);
			divRef.style.display = "block";

			toggleDynamicBottomDisclaimer("show", countryCd);
    }

    /*
     * @DESC:
     *
     *  SHOW DYNAMIC DISCLAIMER:
     *  Required to change the bottom disclaimer if selecting a European country
     *
    */
    function toggleDynamicBottomDisclaimer(action, countryCd) {
        var staticBottom = document.getElementById("static_bottom_disclaimer");
        var dynamicBottom = document.getElementById("dynamic_bottom_disclaimer");
       	var ca_dynamicBottom = document.getElementById("dynamic_bottom_disclaimer_ca");

        dynamicBottom.style.display = (action=="show" && countryCd!="CA") ? "block" : "none";
        ca_dynamicBottom.style.display = (action=="show" && countryCd=="CA") ? "block" : "none";
        staticBottom.style.display = (action=="show") ? "none" : "block";
        
    }

    /*
    * @DESC:
    *
    *  HIGHLIGHTS LI ITEM:
    *  Highlights the selected country in the list
    *
    */
    function highlightItem(countryCd) {
        var aId = "leftlink_"+countryCd;
        var obj = document.getElementById(aId); //getting the a tag
        var li = obj.parentNode.parentNode;
        var h = document.getElementById("selected");
        if (h!=null) {
            h.id = "";
            h.className = "";
        }
        li.className = "select";
        li.id = "selected";
        obj.blur();
    }

    /* @Function: Hide All Investor Types / DeHighlight Row */
    function hideInvestorTypes() {
        var childDivs = document.getElementById("gl_investortypes").getElementsByTagName("DIV");
        var h = document.getElementById("selected");

        if (h!=null) {
            h.id = "";
            h.className = "";
        }

        for (var i=0; i<childDivs.length; i++) {
            if (childDivs[i].className=="gl_investortype") childDivs[i].style.display = "none";
        }

        toggleDynamicBottomDisclaimer("hide", "");
    }

	/*
	 * @Function: Submit the new locale (doesnt write a cookie, only used with GL page
	 *
	 * @Parameters:
	 *    c: Country Code
	 *		l: Language Code
	 */
	function submitNewLocale(c,l) {
		document.getElementById("cCd").value = c;
		document.getElementById("lCd").value = l;
		document.getElementById("new_locale_form").submit();
	}

	/*
	 * @Function: Submit Investor Type to respective site
	 *
	 * @Parameters:
	 *    c: Country Code
	 *		l: Language Code
	 *    i: Investor Type
	 *		d: Domain
	 */
	function submitInvestorType(c,l,i,d) {
		var investorForm = document.getElementById("termsAcceptForm");
        
        // Check for local and internal hosts.
        var match = d.split(/\./g);
		var siteUrl = d;
		if(match.length > 1) {
            siteUrl = c.toLowerCase()+d;
        }

        //Exception for UK (Akamai uses country code UK, but .net requires GB
        if (c=="UK") c="GB";

		investorForm.action = investorForm.action.replace("*",siteUrl);
		if (c=="CA") {
			investorForm.action = investorForm.action.replace("!","splash.do");
		}
		else{
			investorForm.action = investorForm.action.replace("!","legal/submit_terms_conditions.do");
		}
		
        document.getElementById("countryCd").value = c;
		document.getElementById("languageCd").value = l;
		document.getElementById("userTypeCd").value = i;

        /* The Germany site seems to want lang to be set as lang and languageCd */
		if (c.toUpperCase()=="DE") {
			var langNode = document.createElement("input");
			langNode.setAttribute("type","hidden");
			langNode.setAttribute("id","lang");
			langNode.setAttribute("name","lang");
			langNode.setAttribute("value",l);
			investorForm.appendChild(langNode);
		}

        investorForm.submit();
	}

    /*
     * @Description: This function has been copied in from .net to support content disclaimer links.
     */
    var a_opened_window;
    function openWindow(url, width, height, title, showMenu){
      var window_attributes;
      if(!a_opened_window || a_opened_window.closed){
        if (showMenu) {
          window_attributes = "height=" + height + ",width=" + width + ",statusbar=no,resizable=yes,scrollbars=yes,menubar=1"
        } else {
          window_attributes = "height=" + height + ",width=" + width + ",statusbar=no,resizable=yes,scrollbars=yes,menubar=no"
        }
        if(openWindow.arguments.length > 4){
        var i=4
          for(i; i < openWindow.arguments.length; i++){
            window_attributes += openWindow.arguments[i]
          }
        }
        if(!title || title.length == 0){
          title = "subwindow"
        }
        a_opened_window = window.open(url,title,window_attributes);
      }else{
        a_opened_window.location.href = url
      }
      a_opened_window.focus();
    }


    /*
	 * @DESC:
	 *
	 *  POP AND DISABLE:
	 *  The below block of javascript manages the special popups used on the global gateway page and
	 *  disables the main body while the popup is showing. Set Z-Index in CSS definitions.
	 *
	*/

	/* @CONSTRUCTOR: Defining the main language object and its member variables */
		function PopAndDisable(popId, dimmerId) {
			this.dimmerObj = new Object();
			this.popObj = new Object();

			this.init(popId, dimmerId);
		}

	/* @METHOD: Initializer, sets objects z-index's */
		PopAndDisable.prototype.init = function(pid,did) {
			this.popObj = document.getElementById(pid);
			this.dimmerObj = document.getElementById(did);
			if(document.documentElement.scrollHeight < document.documentElement.clientHeight){
				this.dimmerObj.style.height = (document.documentElement.clientHeight+document.documentElement.scrollTop)+"px";
			}
			else{
				this.dimmerObj.style.height = (document.documentElement.scrollHeight+document.documentElement.scrollTop)+"px";
			}
			
		}

	/*
	 * @METHOD: popDiv
	 *
	 * @DESC: This centers the div in the browser window and changes its visibility
	 *
	 */
		PopAndDisable.prototype.pop = function() {
			var w = this.popObj.style.width;
			var h = this.popObj.style.height;
			w = w.substr(0,w.indexOf('px'));
			h = h.substr(0,h.indexOf('px'));
			var xc,yc;

			// get the x and y coordinates to center the newsletter panel
			xc = Math.round((document.body.clientWidth/2)-(w/2))
			yc = Math.round((document.body.clientHeight/2)-(h/2))

			//disable the background
			this.dimmerObj.style.display = "block";

			// show the newsletter panel
			this.popObj.style.left = xc + "px";
			this.popObj.style.top = yc + "px";
			this.popObj.style.display = "block";
		}

	/*
	 * @METHOD: closeDiv
	 *
	 * @DESC: This closes the popped div
	 *
	 * @PARAMETERS:
	 * d = Div ID
	 */
		PopAndDisable.prototype.close = function() {
			this.popObj.style.display = "none";
			this.dimmerObj.style.display = "none";
		}

	/*
	 * @METHOD: resizeDiv
	 *
	 * @DESC: This resizes the popped div	 
	 */
		PopAndDisable.prototype.resize = function() {
			if(document.documentElement.scrollHeight < document.documentElement.clientHeight){
				this.dimmerObj.style.height = (document.documentElement.clientHeight+document.documentElement.scrollTop)+"px";
			}
			else{
				this.dimmerObj.style.height = (document.documentElement.scrollHeight+document.documentElement.scrollTop)+"px";
			}			
		}
