//<!-- New Styleguide Navigation Trail and related Libraries ->
// Author: Tonie Santos, CMS  02-14-2005

var rootDir     = "Home";
var gdList      = new List();	
var gdcounter   = 0;	
var glbDebug    = 0;
var glbBaseName = "";

var glbCurrentDateYYYY_MM_DD	= "";
var glbCurrentDateMM_DD_YYYY	= "";
var glbCurrentDateDD_MM_YYYY	= ""
var glbCurrentYear      	= ""; //YYYY
var glbCurrentDay      		= ""; //DD
var glbCurrentMonth    		= ""; //MM
var glbCurrentDayoftheWeek	= ""; //Sunday<->Saturday
var glbDASH                     = "-";
var glbNavigationPreview        = 1;

getCurrentDate(glbDASH);

function cssfix(str)
{
	var str = str.replace(/{/gi, "");
	str = str.replace(/</gi, "");
	str = str.replace(/\\/gi, "");
	str = str.replace(/\(/gi, "");
	str = str.replace(/\)/gi, "");
	str = str.replace(/\>/gi, "");
	str = str.replace(/\'/gi, "");
	str = str.replace(/\"/gi, "");
	str = str.replace(/\;/gi, "");
	str = str.replace(/\+/gi, "");
	str = str.replace(/\%/gi, "");
	str = str.replace(/\^/gi, "");
	str = str.replace(/\}/gi, "");
	str = str.replace(/\[/gi, "");
	str = str.replace(/\]/gi, "");
	str = str.replace(/\&/gi, "");
	return str;
	
}	

/*** Primary Navigation Top Level Tab Function ****/
/*** gdSpaceGif is declared in navigation_tab.js  **/
function buildPrimaryNav(sdPNL) {
      if(typeof(gdSpacerGif)=="undefined"){ 
         gdSpacerGif = "/common/images/spacer.gif";
      }
      var sdSpacer = relative(gdSpacerGif,glbBaseURL);
      var sdTabImage = "";
      var sdPath = "";
      var sdAltText = "";
      var sdOnFlag  = "N";
      
      var sdNav = '<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="black">' +
                  '<tr>';
      
      for (var i = 0; i < sdPNL.items.length; i++) {		  
	  if ( (sdOnFlag == "N") &&                                        //Make sure On happens only once
	       ( (sdPNL.items[i].xPath == glbBaseURL) || 		   //If Current page same as tab 
	         (sdPNL.items[i].xPath == glbHomeURLinFullList) ) ) {      //If Full List Main URL same as tab
	     sdTabImage = relative(sdPNL.items[i].xImageOn, glbBaseURL);   //On Image
	     sdOnFlag = "Y";
	  }
	  else { 				      //Off Image
	     sdTabImage = relative(sdPNL.items[i].xImageOff, glbBaseURL);
	  }
	  sdAltText = sdPNL.items[i].xName;
	  sdPath = relative(sdPNL.items[i].xPath, glbBaseURL);  
	  sdNav += '<td valign="top"><a href="' + sdPath + '"><img src="' + sdTabImage + '" alt="' + sdAltText + '" height="16" border="0" /></a></td>';
      }	
       
      sdNav    += '<td valign="bottom" width="100%"><table width="100%" border="0" cellspacing="0" cellpadding="0">' +
                                 '<tr>' +
                                 '<td bgcolor="#ff9900"><img src="' + sdSpacer + '" alt="" height="1" width="1" border="0" /></td>' +
                                 '</tr>' +
                                 '<tr>'  +
                                 '<td bgcolor="#990000"><img src="' + sdSpacer + '" alt="" height="1" width="1" border="0" /></td>' +
                                  '</tr>' +
                                 '</table></td>' +
                                 '</tr>' +
                                 '</table>';
      return sdNav;                                 
}

/*** End Primary Navigation Tab Function ****/

/*** Related Library Functions ****/
				
function saveCookie(name,value,days) {
        if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000))
                var expires = "; expires="+date.toGMTString()
        }
        else expires = ""
        document.cookie = name+"="+value+expires+"; path=/"
}

function readCookie(name) {
        var nameEQ = name + "="
        var ca = document.cookie.split(';')
        for(var i=0;i<ca.length;i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length)
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length)
        }
        return null
}
function deleteCookie(name) {
        saveCookie(name,"",-1)
}

function pop(url,w,h,l,t) {

    var winwidth = 780; // width of the new window
        if (w > 0) winwidth = w;
    var winheight = 500; // height of the new window
    	if (h > 0) winheight = h;
    var winleft = 75;
    	if (l > 0) winleft = l;
    var wintop = 125;
    	if (t > 0) wintop = t;

    if(parseInt(navigator.appVersion)>=4) {

        winleft = (screen.width / 2) - (winwidth / 2); // center the window right to left
        wintop = (screen.height / 2) - (winheight / 2); // center the window top to bottom

    }

    var attrib =  'top=' + wintop + ',left=' + winleft + ',height=' + winheight + ',width=' + winwidth + ', directories=yes,location=yes,menubar=yes,scrollbars=yes,status=yes,toolbar=yes,resizable=yes';

    window.open(url, "PopUp", attrib);
    return void(null);

}

function pop(url) {
    var winwidth = 385; // width of the new window
    var winheight = 525; // height of the new window
    var winleft = 75;
    var wintop = 125;

    if(parseInt(navigator.appVersion)>=4) {

        winleft = (screen.width / 2) - (winwidth / 2); // center the window right to left
        wintop = (screen.height / 2) - (winheight / 2); // center the window top to bottom

    }

    var attrib =  'top=' + wintop + ',left=' + winleft + ',height=' + winheight + ',width=' + winwidth + ',scrollbars=no, resizable=yes';

    window.open(url, "PopUp", attrib);
    return void(null);

}

function relative(resourceURL, locationURL) {
	var relativePath = "";
	
	if ( (resourceURL.indexOf("http://") == 0) || (resourceURL.indexOf("https://") == 0) ) { //		
		return resourceURL;
	}
	else if (resourceURL.indexOf("#") == 0) {
			relativePath = "#";
			return relativePath;
	}
	
	aResource = resourceURL.substring(1, resourceURL.length).split("/");
	aLocation = locationURL.substring(1, locationURL.length).split("/");

	// first, remove anything in either path that is common
	var start = 0;
	
	for (m=0; m<aResource.length; m++) {
		if (m <= aLocation.length && aResource[m] != aLocation[m]) {
			start = m;			
			break;					
		}
	}
	
	aResource = aResource.slice(start, aResource.length);
	aLocation = aLocation.slice(start, aLocation.length);
	
	// then, get the relativePathative path from locationURL to the root
	var n = 0;
	while (n < aLocation.length-1) {
		relativePath += "../";
		n++;		
	}

	// lastly, add each remaining element of the resource path to the relativePath path.
	for (p=0; p<aResource.length; p++) {
		relativePath = (p==aResource.length-1)?relativePath + aResource[p]:relativePath + aResource[p] + "/";
	}

	return relativePath;
}

function navigateTo (urlNav) {
 if  ( (urlNav.indexOf("http://") == -1)  && (urlNav.indexOf("https://") == -1) ) {
        var  sdrelNav = relative(urlNav,glbBaseURL);
        urlNav = sdrelNav;
     
  }
  document.location.href= urlNav;
}

function gotoURL (sdrelpath,sdabspath,sdopt) {
       var sdprotocol=location.protocol;
       var sdhost=location.host;
       var sdhref=location.href;
       if ( (sdhref.indexOf("WORKAREA") < 0) && (sdopt == "https") ) {   //NOT in TeamSite
            var sdurlpath = "https://" + sdhost +  sdabspath;
            location.href(sdurlpath);
       }
       else {    //In TeamSite
            location.href(sdrelpath);
       }
}

function StripWhiteSpace (s) { 
    var i;
    var returnString = "";
    bag = " \t\n\r";;
    
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }

    return returnString;
}


function List() {
   this.items = new Array();
   this.add = ListAdd;
}

function ListAdd(value) {
   var i = this.items.length;
   this.items[i] = new Array();
      this.items[i].value = value;
      this.items[i].xName = arguments[0];
      this.items[i].xPath = arguments[1];
      this.items[i].xImageOn = arguments[2];
      this.items[i].xImageOff = arguments[3];      
}   

function makeArray() {
  var args = makeArray.arguments;
  for (var i = 0; i < args.length; i++) {
    this[i] = args[i];
  }
  this.length = args.length;
}

function getCurrentDate(sdsep) {
  if ( (sdsep == null) || (sdsep == "") ) { sdsep = "-"};
  var sdDays = new makeArray("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
  
  var sdCurrent = new Date();
  if (sdCurrent.getDate() < 10) {
     glbCurrentDay = "0" + sdCurrent.getDate();
  }
  else {
     glbCurrentDay = sdCurrent.getDate();
  }
  glbCurrentMonth = sdCurrent.getMonth() + 1;
  if (glbCurrentMonth < 10) {
     glbCurrentMonth = "0" + glbCurrentMonth;
  }
  
  glbCurrentYear = sdCurrent.getFullYear();
  glbCurrentDayoftheWeek = sdDays[sdCurrent.getDay()];
  glbCurrentDateYYYY_MM_DD = "" + glbCurrentYear  + sdsep + glbCurrentMonth + sdsep + glbCurrentDay;
  glbCurrentDateMM_DD_YYYY = "" + glbCurrentMonth + sdsep + glbCurrentDay   + sdsep + glbCurrentYear;
  glbCurrentDateDD_YY_YYYY = "" + glbCurrentDay + sdsep + glbCurrentMonth   + sdsep + glbCurrentYear; 
  if (glbDebug > 0) { alert ("Today is " + glbCurrentDayoftheWeek + ", " + glbCurrentDateMM_DD_YYYY) };
}

// method used in header and footer s
function getImgSrc(getImg, relSrc) {
var absSrc = '';
var temp = new Array();
temp = getImg.split(' ');
	for (i=0;i<temp.length; i++) {

	   if(temp[i].indexOf('src=') != -1) {
		   absSrc += 'src="' + relSrc + '"';
	   } else {
		   absSrc += temp[i] + ' ';
	   }
	}
  return absSrc;
}