// CSI INCLUDE FOR HEADER AND FOOTER FILES
// JS file developed in support to convert all SSI Includes to a CSI Include using javascript
// javascript to read in two paramaters within the <div id="prim_sec">, based on the parameters, 
// the appropriate header file is loaded and then the appropriate secondary navigation link is 
// highlighted. If nothing is passed (no div exists), the header_main.htm is loaded by default.
  
$(document).ready(function(){


		$("ul.lang-menu li:first").hover(
			function () {
				$(this).children("ul").addClass('xlanghover');
			},function(){
				$(this).children("ul").removeClass('xlanghover');	
			});//hover
		$('ul#languageSelect a img').hover(function() {
		   var newSrc = $(this).attr('src').replace('_s.gif','_h.gif');
		   $(this).attr('src',newSrc);
		}, function() {
			var oldSrc = $(this).attr('src').replace('_h.gif','_s.gif');
			$(this).attr('src',oldSrc);
		});
	    $('li.menu ul').bgiframe();
		$("li.menu").hover(
			function () {
				$(this).children("ul").addClass('xmenuhover');
			},function(){
				$(this).children("ul").removeClass('xmenuhover');	
			});//hover
		
		$('li.menu:last').css('margin','0 0 0 0');
		$('#ikeyword').focus(function () {
		   $(this).attr('value','');
		});
		var langHeader= $(".xheader").attr("id");
		if ( document.cookie.indexOf("iPlanetDirectoryPro=") == -1) {
		   switch(langHeader)
				{								
					case "JPheader":
						$('#signIn').html("<a href='" + dst_url + "'>\u30b5\u30a4\u30f3\u30a4\u30f3<\/a>");
						break;
					case "CNheader":
						$('#signIn').html("<a href='" + dst_url + "'>\u767b\u5f55\u5e76\u8bbf\u95ee\u5e10\u6237<\/a>");
						break;	
					default:  
						$('#signIn').html("<a href='" + dst_url + "'>Sign in<\/a>");
				}
		} else {
		   switch(langHeader)
				{								
					case "JPheader":
						$('#signIn').html("<a href='" + dst_url + "'>\u30de\u30a4 \u30a2\u30ab\u30a6\u30f3\u30c8<\/a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='https:\/\/" + dst_hostname + "\/webreg\/logout.do'>\u30b5\u30a4\u30f3\u30a2\u30a6\u30c8<\/a>");									break;
					case "CNheader":
						$('#signIn').html("<a href='" + dst_url + "'>\u6211\u7684\u5e10\u6237<\/a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='https:\/\/" + dst_hostname + "\/webreg\/logout.do'>\u9000\u51fa<\/a>");									break;	
					default:  
						$('#signIn').html("<a href='" + dst_url + "'>My Account<\/a>&nbsp;&nbsp;|&nbsp;&nbsp;<a href='https:\/\/" + dst_hostname + "\/webreg\/logout.do'>Sign Out<\/a>");
				}
		}
				







});

// Author: Ramola Gokhale
// For Sign In / My Account
devInt = new Array ("xdtestlinx", "xdstagelinx", "www.stage.xd.xilinx.com", "www.preview.xd.xilinx.com", 
                    "xitestlinx", "xistagelinx", "www.stage.xi.xilinx.com", "www.preview.xi.xilinx.com",
                    "xdtargetj", "xdstagelinxj", "japan.stage.xd.xilinx.com", "japan.preview.xd.xilinx.com",
                    "xitargetj", "xistagelinxj", "japan.stage.xi.xilinx.com", "japan.preview.xi.xilinx.com",
                    "xdcns-target", "xdcns-stagelinx", "china.stage.xd.xilinx.com", "china.preview.xd.xilinx.com",
                    "xicns-target", "xicns-stagelinx", "china.stage.xi.xilinx.com", "china.preview.xi.xilinx.com",
                    "xisecure", "secure.xi");

uatPub = new Array ("xttestlinx", "xtstagelinx", "www.stage.xt.xilinx.com", "www.preview.xt.xilinx.com",
                    "xttargetj", "xtstagelinxj", "japan.stage.xt.xilinx.com", "japan.preview.xt.xilinx.com",
                    "xtcns-target", "xtcns-stagelinx", "china.stage.xt.xilinx.com", "china.preview.xt.xilinx.com",
                    "xtsecure", "secure.xt",
                    "xptestlinx", "xpstagelinx", "testlinx", "stagelinx", "www.stage.xilinx.com", "www.preview.xilinx.com",
                    "xptargetj", "xpstagelinxj", "targetj", "stagelinxj", "japan.stage.xilinx.com", "japan.preview.xilinx.com",
                    "xpcns-target", "xpcns-stagelinx", "cns-target", "cns-stagelinx", "china.stage.xilinx.com", "china.preview.xilinx.com");

prod   = new Array ("www.zylinks.com", "www.origin.zylinks.com",
                    "japan.zylinks.com", "japan.origin.zylinks.com",
                    "china.zylinks.com", "china.origin.zylinks.com",
                    "secure.zylinks.com",
                    "www.xilinx.com", "www.origin.xilinx.com",
                    "japan.xilinx.com", "japan.origin.xilinx.com",
                    "china.xilinx.com", "china.origin.xilinx.com",
                    "secure.xilinx.com");

// Get the hostname.
var hostname = window.location.hostname;


// Determine the language id.
var language = ""; 
if (hostname.indexOf("japan")!= -1 || hostname.indexOf("targetj")!=-1 ||  hostname.indexOf("stagelinxj")!=-1) {
    language = "&languageID=2"; 
} else if (hostname.indexOf("china")!= -1 || hostname.indexOf("cns-target")!=-1 ||  hostname.indexOf("cns-stagelinx")!=-1) {
    language = "&languageID=3"; 
} 


// Start build the dst_url.
var dst_hostname = "secure.xilinx.com";


// Loop thru INT & DEV envs.
for (i=0; i<devInt.length; i++) {
    if(hostname == devInt[i] || hostname == devInt[i]+".xilinx.com" || hostname.indexOf(".xi.xilinx.com")!= -1) {
        dst_hostname = "secure.xi.xilinx.com";
        break;
    }
}


// Loop thru UAT & PUB envs.
for (i=0; i<uatPub.length; i++) {
    if(hostname == uatPub[i] || hostname == uatPub[i]+".xilinx.com" || hostname.indexOf(".xt.xilinx.com")!= -1) {
        dst_hostname = "secure.xt.xilinx.com";
        break;
    }
}


// Loop thru envs at ISP(ATT) : PROD-TEST & PROD. 
for (i=0; i<prod.length; i++) {
    if(hostname == prod[i] || hostname == prod[i]+".xilinx.com") {
        dst_hostname = "secure.xilinx.com";
        break;
    }
}


var dst_url = "https://" + dst_hostname + "/webreg/register.do?group=myprofile" + language;


// This function returns the "username" if the user is logged in. 
// Else returns an empty string. 
function getUsername()
{
    var cookies = document.cookie;
    var name = "XilinxUser";
    if (cookies.indexOf("iPlanetDirectoryPro") != -1 &&
        cookies.indexOf("XilinxUser")          != -1) {
        var startpos = cookies.indexOf(name)+name.length+1;
        var endpos = cookies.indexOf(";",startpos);
        if (endpos == -2) endpos = cookies.length;
        return unescape(cookies.substring(startpos,endpos));
    } else {
        return ""; // The user is not logged in.

    }
}


// placed the bgiframe.js code directly inside csi_HF.js so we don't need to add the <link> reference to each page
// bgiframe solves the IE6 Z-index issue with SELECT and hover 

(function($){
$.fn.bgIframe = $.fn.bgiframe = function(s) {
	// This is only for IE6
	if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
		s = $.extend({
			top     : 'auto', // auto == .currentStyle.borderTopWidth
			left    : 'auto', // auto == .currentStyle.borderLeftWidth
			width   : 'auto', // auto == offsetWidth
			height  : 'auto', // auto == offsetHeight
			opacity : true,
			src     : 'javascript:false;'
		}, s || {});
		var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
		    html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
		               'style="display:block;position:absolute;z-index:-1;'+
			               (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
					       'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
					       'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
					       'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
					       'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
					'"/>';
		return this.each(function() {
			if ( $('> iframe.bgiframe', this).length == 0 )
				this.insertBefore( document.createElement(html), this.firstChild );
		});
	}
	return this;
};

})(jQuery);