// BEGIN Country Selector
function countrySelector() {
	document.getElementById('cs_sitelist').style.display='block';

}
function closeSelector() {
	document.getElementById('cs_sitelist').style.display='none';
}
// END Country Selector

// BEGIN Main Navigation - DO NOT REMOVE
var numSubNavs=6;
var sectionName='SecNav_';
var subMenuOffset=0;
var subNavTop='160px';
function ShowNav(id) {
	try{
		hideThis(id);
		//hideElements();
		navHoverStyle(id);
		var thisElement = document.getElementById('SecNav_' + id)
		var mainNavItemLeft = document.getElementById('MainNav_' + id).offsetLeft;
		var leftMargin = mainNavItemLeft + subMenuOffset;
		//document.getElementById('SecNavigation').style.left = leftMargin + 'px';
		thisElement.style.left = leftMargin + 'px';
		thisElement.style.display = 'block';
	}
	catch(ex){
		window.status=ex;
	}
}
function hideThis(id) {
	for(i=1;i<numSubNavs+1;i++){
		section = document.getElementById(sectionName + i);
		section.style.display='none';
	}
}
function hideElements(){
	for(i=1;i<numSubNavs+1;i++){
		section = document.getElementById(sectionName + i);
		section.style.display='none';
		document.getElementById('MainNav_' + i).style.background='transparent';
		if ((document.getElementById('MainNav_'+i).firstChild.firstChild.style.background).indexOf('url')>-1) {
			//alert(document.getElementById('MainNav_'+i).firstChild.firstChild.style.background);
			document.getElementById('MainNav_'+i).firstChild.firstChild.style.background='none';
			document.getElementById('MainNav_'+i).firstChild.style.background='none';
		}

	}
}
function navHoverStyle(navID) {
  if (!navID) { return; }
	for(i=1;i<numSubNavs+1;i++){
		if (i != navID) {
			document.getElementById('MainNav_'+i).firstChild.firstChild.style.background='none';
			document.getElementById('MainNav_'+i).firstChild.style.background='none';
		}
	}
	document.getElementById('MainNav_'+navID).firstChild.firstChild.style.background='url(images/common/navigation/navSelect_right-over.gif) bottom right no-repeat';
	document.getElementById('MainNav_'+navID).firstChild.style.background='url(images/common/navigation/navSelect_left-over.gif) bottom left no-repeat';
}
// END Main Navigation

function buildBreadcrumbs(section, page, sub){
  var bc = "<ul><li><a href='index.htm'>Home</a></li>";
  var section_buffer = '';
  var page_buffer;
  if (section){
    // split the section path in sections
    var section_array = section.split('/');
    var section_path = "";
    if (section_array.length == 0) {
      section_array = new Array();
      section_array[0] = section;
    }  

    for (var i = 0; i < section_array.length; i++) {
      page_buffer = section_array[i].replace('.htm', '')
      if (page_buffer != section_buffer) {
        section_path += section_array[i];
        bc += "<li>&nbsp;&nbsp;<img src='images/common/interface/bullet-bluechevrons.gif'>";
        bc += "<a href='index.htm?section=" + section_path + "'>";
        bc += UpCase(removeTags(section_path)) + "</li>";
        if ( i < section_array.length - 1)
          section_path += '/';     
      }
      section_buffer = page_buffer;
    }
  }

  if (page) { // Take the parts but only put a link on the last part (with the htm)
    var page_array = page.split('/');
    if (page_array.length == 0){
      page_array = new Array();
      page_array[0] = page;
    }
    
    for (var j = 0; j < page_array.length; j++) {
      if (page_array[j].indexOf('.htm') >= 0) {
        bc += "<li>&nbsp;&nbsp;<img src='images/common/interface/bullet-bluechevrons.gif'>";
        //bc += "<a href='index.htm?section=" + section_path + "/" + page_array[j] + "'>";
        bc += UpCase(removeTags(page_array[j])) + "</li>"; 
      } else {
       // bc += "<li>&nbsp;&nbsp;<img src='images/common/interface/bullet-bluechevrons.gif'>" + removeTags(page_array[j]) + "</li>"; 
      }
    }
  }
    
  if (sub) {
    bc += "<li>&nbsp;&nbsp;<img src='images/common/interface/bullet-bluechevrons.gif'>";
    //bc += "<a href='index.htm?section=" + section_path + "&sub=" + sub + "'>";
    bc += removeTags(sub).capitalize() + "</li>";
  }
  bc += "</ul>";
  document.getElementById("header_bc").innerHTML = bc;
}
function changeBannerImage(name, state) {
	if (state)
	{
		document.getElementById(name).src = "./images/web_banner_big_10th.png";
	}
	else
	{
		document.getElementById(name).src = "./images/web_banner_big.png";
	}
}
function checkBrowser(){

  if (!getCookie("browser_check")){
    var iVersion;
    var sMessage = "This site is optimized for IE v7.0, Firefox 2x/3x, Safari and Chrome.\n" 
                 + "Some pages may not display properly.\nPlease update your browser version.";
    var browserName = navigator.userAgent;
    var browser_name_array = navigator.userAgent.split(' ');
    if (browser_name_array.length > 0)
      browserName = browser_name_array[browser_name_array.length - 1];

    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
      iVersion=new Number(RegExp.$1) // capture x.x portion and store as a number
      if (iVersion>=6){
        sMessage = '';
      }
    }
    else if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);
      iVersion=new Number(RegExp.$1) // capture x.x portion and store as a number
      if (iVersion>=2){
        sMessage = '';
      }
    }
		else if (/Safari[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ sMessage = ''; } //test for Safari/x.x (ignoring remaining digits);
    else if (/Chrome[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ sMessage = ''; } //test for Chrome x.x (ignoring remaining digits);
    else { }
    if (sMessage != '') { 
      browserName = browserName.replace('/', ' ');
      //sMessage = 'You are using ' + browserName + '\n\n' + sMessage;
      alert(sMessage);
    }
    setCookie("browser_check", "true", 1);
  }
}
function loadContent() {
  // Get section and page variables
  var section = getQueryVariable('section');
  var menu = getQueryVariable('menu');
  var page = getQueryVariable('page');
  var sub = getQueryVariable('sub');
  var section_name= '';
  var bread_section = '';
  var first_section = section;
  var last_section = section;
  var new_section = section;
  var new_menu = 'home.htm';
  var new_page = '';
  var new_sub = '';
  var url;
  var i = 0;

  // If no page or section, load index.htm
  if (!section && !page){ 
    loadLeft('content/' + new_menu);
    buildBreadcrumbs();
    loadNewsFeed();
    setPage();
    return;
  }
  
  //First clear the content in the index page
  document.getElementById("pagecontent").innerHTML = 'Loading ...';

  // Scenarios :
  // 1 - When only a page is set, and no section, we should keep the current menu. 
  // 2 - If a section is set and a page is set,  then we will use the section main menu
  // 3 - If a page is set and a menu is set, then we will use the 2 selected elements
  if (section) {
    // If the section has several parts, split them and take the last one to build the menu and page
    // if the last par contains .htm -> it is the page to display
    // If it does not, build the page name with the section name
    i = section.lastIndexOf('.htm');
    if ( i > 0) {
      i = section.indexOf('/');
      section_name = section.substr(0, i);
      i = section.lastIndexOf('/');
      first_section = section.substr(0, i);
      new_section = section;
      new_menu = first_section + '/' + 'd_' + section_name;
    }
    else {         
      i = section.lastIndexOf('/');
      if ( i >= 0) {
        first_section = section.substr(0, i);
        last_section = section.substr(i + 1);
        new_section = section + '/' + last_section ;
        new_menu = section + '/' + 'd_' + last_section;
      }
      else {
        new_section = section + '/' + section;
        new_menu = section + '/' + 'd_' + section;
      }
    }
  }
  
  //Save breadcrumb part
  if (new_section)
    bread_section = new_section;
  else
    new_section = '';
  
  if (menu) {
    if (section)
      new_menu = section + '/' + menu;
    else
      new_menu = menu;
  } 
  if (page) { 
    if (section) { new_section = section + '/' + page; }
    else { 
      new_page = page;
      new_section = page; 
      if (menu) { 
        new_menu = menu; 
      }
    }
  }

  //Check .htm ending
  if (bread_section.lastIndexOf('.htm') < 0)
    bread_section += '.htm';
  if (new_section.lastIndexOf('.htm') < 0)
    new_section += '.htm';  
  if (new_page.lastIndexOf('.htm') < 0)
    new_page += '.htm';
  if (new_menu.lastIndexOf('.htm') < 0)
    new_menu += '.htm';  

  //url = 'index.htm?section=' + new_section;
  //alert(new_menu + ' / ' + new_page);
 
  loadPages('content/' + new_menu, 'content/' + new_section);
  
  // If sub section 
  if (sub)
  {
    new_sub = 'content/' + first_section;
    if (section.indexOf('.htm') >= 0) {
      new_sub += '/' + sub;
    }
    else {
      new_sub += '/' + last_section + '/' + sub;
    }
    loadDiv(new_sub, 'display');
  }
  //Build bread crumbs
  buildBreadcrumbs(bread_section, page, sub);
  //Correct sidebar/content height difference
  setPage();

}
function loadNewsFeed() {
   new rsspausescroller("dssupport", "newsfeed", "news", "rssclass", 2000, "", "date+description");
}
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
	if (vars)
	{
	  for (var i=0;i<vars.length;i++) {
	    var pair = vars[i].split("=");
	    if (pair[0] == variable) {
	      return pair[1];
	    }
	  } 
	}
}
function removeTags(str){
  var sRet = str.replace(".htm", "").replace(/_/g, " ");
  if (sRet.indexOf("/") > 0) {
    sRet = sRet.slice(sRet.lastIndexOf("/") + 1);
  }
  return sRet
}
function UpCase(str){

  if (str.indexOf(' ') < 0) { return str.capitalize(); }
  else { 
    var ret = str.split(' ');
    var out = ret[0].capitalize();
    for (var i =1; i < ret.length ; i++){
      out += ' ' + ret[i].capitalize();
    }
  }
  return out;
}
// ~~~~~~~~functions used for fix: client-side script expanded content flows over footer ~~~~~~~~ \\
function setPage(){
  P7_equalCols2(0,'sidebar','p','main_panel','p');
  P7_expMenu();
}
/*
var d = document;
var sidebar_original_height = 0; // var used for fix: client-side script expanded content flows over footer
function evenColumns() {
	if (d.getElementById) { // determine if browser uses DOM
		var main_panel = d.getElementById('main_panel');
		var sidebar = d.getElementById('sidebar');
		if (sidebar != null) {
      //alert('sidebar_original_height=' + sidebar_original_height);
			if (main_panel.offsetHeight >= sidebar.offsetHeight) {
				sidebar.style.height = (main_panel.offsetHeight) + 'px';
				main_panel.style.height = (main_panel.offsetHeight) + 'px';
			} else if (sidebar.offsetHeight >= main_panel.offsetHeight) {
				main_panel.style.height = (sidebar.offsetHeight) + 'px';
				sidebar.style.height = (sidebar.offsetHeight) + 'px';
			}
      sidebar_original_height = sidebar.style.height; // var added for fix: client-side script expanded content flows over footer
		}
	}
}
 function evenColumnsAgain() {
  // the columns' heights may have been changed after load by client-side script,
  // so adjust them again here.
  if (d.getElementById) { // determine if browser uses DOM
    var main_panel = d.getElementById('main_panel');
    var sidebar = d.getElementById('sidebar');
    //alert('sidebar_original_height=' + sidebar_original_height); 
    if (sidebar != null) { 
      if (main_panel.offsetHeight >= sidebar_original_height) {
        sidebar.style.height = (main_panel.offsetHeight) + 'px';
        main_panel.style.height = (main_panel.offsetHeight) + 'px';
      } else if (sidebar_original_height >= main_panel.offsetHeight) {
        main_panel.style.height = (sidebar_original_height) + 'px';
        sidebar.style.height = (sidebar_original_height) + 'px';
      }
   } 
  }
}
function resizePanelHeight(divId, expand) {
// adjust the height of the main content panel to reflect any client-side expanding or collapsing of divs, so that the content does not flow over the footer.
// params:
// divId: id of div that will be expanded or collapsed - so that we can get the height of it.
// expand: 'true/false' - true if div will be expanded.
if (d.getElementById) { // determine if browser uses DOM
  var main_panel = d.getElementById('main_panel');
  var div = d.getElementById(divId); 
  if (div != null) { 
    var height = 0; 
    // now increase/decrease height of content area
    if (expand == true){
      // get the height of the div AFTER expanding it.
      div.style.display='block'; 
      height = div.offsetHeight
      main_panel.style.height = (main_panel.offsetHeight + height) + 'px';
    }
    else{
      // get the height of the div BEFORE collapsing it.
      height = div.offsetHeight
      div.style.display='none';
      main_panel.style.height = (main_panel.offsetHeight - height) + 'px';
    } 
 } 
}
// now readjust all columns
evenColumnsAgain();
}
// ~~~~~~~~end - functions used for fix: client-side script expanded content flows over footer ~~~~~~~~ \\
*/