//Layer.js - This file sets up the layers for the country navigation
//Written by: M.Amplo, S.Bender, K.Burkhardt
//Please note: This is NOT compatible with Netscape 6.0

var layerList = new Array();

//********************************************************************************
//Added For Image Placeholder Logic
var isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 &&
                parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
	var isMinIE4 = (document.all) ? 1 : 0;
	var isMinIE5 = (isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;
//*********************************************************************************


function createLayer(doc, name, left, top, width, height, visible, content) {
  var z = layerList.length;
  var layer;

  layerList[z] = name;

  if (document.layers) {
    document.writeln('<layer name="' + name + '" left=' + left + ' top=' + top + ' width=' + width + ' height=' + height +  ' visibility=' + (visible ? '"show"' : '"hide"') + ' z-index=' + z + '>');
    document.writeln(content);
    document.writeln('</layer>');
    layer = getLayer(doc, name);
    layer.width = width;
    layer.height = height;
  }
  
  if (document.all) {
    document.writeln('<div id="' + name + '" style="position:absolute; overflow:none; left:' + left + 'px; top:' + top + 'px; width:' + width + 'px; height:' + height + 'px;' + ' visibility:' + (visible ? 'visible;' : 'hidden;') + ' z-index=' + z + '">');
    document.writeln(content);
    document.writeln('</div>');
  }
}

function hideLayer(doc, name) {

  var layer = getLayer(doc, name);

  if (doc.layers)
    layer.visibility = "hide";
	
  if (doc.all)
    layer.visibility = "hidden";
}

function showLayer(doc, name) {

  var layer = getLayer(doc, name);

  if (doc.layers)
    layer.visibility = "show";

  if (doc.all)
    layer.visibility = "visible";
}

function getLayer(doc, name) {

  // Returns a handle to the named layer.

  if (doc.layers)
    return(doc.layers[name]);

  else if (doc.all) {
    layer = eval('doc.all.' + name + '.style');
    return(layer);
  }
  else
    return(null);
}

function getLayerVis(name) {
	var isVisible = null;
	
	if (document.layers){
		if (getLayer(name).visibility == "show") {
			isVisible = 1;
		} else {
			isVisible = 0;
		}
	}  

	else if (document.all) {
		if (getLayer(name).visibility == "visible") {
			isVisible = 1;
		} else {
			isVisible = 0;
		}
	} 
	else {
		isVisible = null;
	}
	
	return(isVisible);
	
}

function moveLayer(name, amt, dir) {

	var lh = getLayer(name);
	
	if (document.layers) {
		// move the layer lh by amt in the dir direction.
		if (dir == 0) {
			lh.top -= amt;
		} else {
			lh.top += amt;
		}
	} 

	else if (document.all) {
		if (dir == 0) {
			lh.top = eval(lh.top.substring(0, lh.top.indexOf('px'))) - amt;
		} else {
			lh.top = eval(lh.top.substring(0, lh.top.indexOf('px'))) + amt;
		}
	} else {
	// do nothing
	}
}

var param_string=unescape(location.search.substring(1,location.search.length));
//===============================================================================================================================================================================================================================================================================================
function getParam(name_string) {
var startIndex=(param_string.indexOf(name_string));     
    if (startIndex==-1)                               
        { return ""; }

    startIndex+=name_string.length;                     
    if ((startIndex>=param_string.length)||(param_string.charAt(startIndex)=='&'))
        { return ""; }

    else {
            var endIndex=param_string.indexOf('&',startIndex);
            if (endIndex==-1)
                { endIndex=param_string.length; }
            if (startIndex==endIndex)
                { return ""; }
            else
                { return param_string.substring(startIndex,endIndex); }
         }
}
//===============================================================================================================================================================================================================================================================================================
function SubCountriesLayer(paramcountry) {
	var content = '';
	var country = paramcountry;
    //===========================================================================================================================================================================================================================================================================================
    // Create reuters.com country menus [United States]		
	if (country==".com") {
       content += '<table cellpadding=0 cellspacing=0 border=0 bgcolor=#EBF5FF width=168>';

	   content += '<tr><td><img src="images/border.gif" width="1" height="21"></td><td valign="middle">&nbsp;<a class=navcountrytext href="javascript:goto_page(\'http://www.asia.reuters.com\');" onMouseOver="showSubMenu(0, 0);" onMouseOut="setTimer();"><img src="images/flagasia.gif" width="30" height="15" valign="bottom" border="0">&nbsp;&nbsp;&nbsp;Asia</a></td><td><img src="images/border.gif" width="1" height="21"></td></tr>';
       content += '<tr><td><img src="images/border.gif" width="1" height="3"></td><td><img src="images/border.gif" width="168" height="1"></td><td><img src="images/border.gif" width="1" height="3"></td></tr>';

	   content += '<tr><td><img src="images/border.gif" width="1" height="21"></td><td valign="middle">&nbsp;<a class=navcountrytext href="javascript:goto_page(\'http://www.reuters.de\');" onMouseOver="showSubMenu(0, 0);" onMouseOut="setTimer();"><img src="images/flagde.gif" width="30" height="15" valign="bottom" border="0">&nbsp;&nbsp;&nbsp;Germany</a></td><td><img src="images/border.gif" width="1" height="21"></td></tr>';
       content += '<tr><td><img src="images/border.gif" width="1" height="3"></td><td><img src="images/border.gif" width="168" height="1"></td><td><img src="images/border.gif" width="1" height="3"></td></tr>';

	   content += '<tr><td><img src="images/border.gif" width="1" height="21"></td><td valign="middle">&nbsp;<a class=navcountrytext href="javascript:goto_page(\'http://www.reuters.co.jp\');" onMouseOver="showSubMenu(0, 0);" onMouseOut="setTimer();"><img src="images/flagjp.gif" width="30" height="15" valign="bottom" border="0">&nbsp;&nbsp;&nbsp;Japan</a></td><td><img src="images/border.gif" width="1" height="21"></td></tr>';
       content += '<tr><td><img src="images/border.gif" width="1" height="3"></td><td><img src="images/border.gif" width="168" height="1"></td><td><img src="images/border.gif" width="1" height="3"></td></tr>';

	   content += '<tr><td><img src="images/border.gif" width="1" height="21"></td><td valign="middle">&nbsp;<a class=navcountrytext href="javascript:goto_page(\'http://www.reuters.co.za\');" onMouseOver="showSubMenu(0, 0);" onMouseOut="setTimer();"><img src="images/flagza.gif" width="30" height="15" valign="bottom" border="0">&nbsp;&nbsp;&nbsp;South Africa</a></td><td><img src="images/border.gif" width="1" height="21"></td></tr>';
       content += '<tr><td><img src="images/border.gif" width="1" height="3"></td><td><img src="images/border.gif" width="168" height="1"></td><td><img src="images/border.gif" width="1" height="3"></td></tr>';

	   content += '<tr><td><img src="images/border.gif" width="1" height="21"></td><td valign="middle">&nbsp;<a class=navcountrytext href="javascript:goto_page(\'http://www.reuters.co.uk\');" onMouseOver="showSubMenu(0, 0);" onMouseOut="setTimer();"><img src="images/flaguk.gif" width="30" height="15" valign="bottom" border="0">&nbsp;&nbsp;&nbsp;United Kingdom</a></td><td><img src="images/border.gif" width="1" height="21"></td></tr>';
       content += '<tr><td><img src="images/border.gif" width="1" height="3"></td><td><img src="images/border.gif" width="168" height="1"></td><td><img src="images/border.gif" width="1" height="3"></td></tr>';
	   content += '</table>'; }
    
    //===========================================================================================================================================================================================================================================================================================
    // Check browser and OS version and place layer in the proper position
	var img;
	var left;
	var top;
	//Retrieve The PlaceHolder Invisible Image Image
	img = getImage("countriesplaceholder");
	left = getImagePageLeft(img);
	top = getImagePageTop(img);	
	
	//Based On Browser Type Build The Layer
	//Netscape
	//Only Using Layers In IE Due To Netscape Problems
	/*
	if (document.layers) { 
    	createLayer(document, 'layer1', left - 35, top + 17, 170, 500, 0, content);
	}
	*/	
	//IE
    if (document.all) {
	//Check For IE Version
		var msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
		var result = parseFloat(navigator.appVersion.substr(msieIndex,3));
			
		if (result >= 5.5) {		
			createLayer(document, 'layer1', left - 29, top + 11, 170, 500, 0, content);
		}
		else {
			//Browser Is Less Than Version 5.5 So Implement The Coordinates Differently
			createLayer(document, 'layer1', left - 29, top + 11, 170, 500, 0, content);
		}
	}	
}
//===============================================================================================================================================================================================================================================================================================
//The Following Functions Are Used To Get The PlaceHolder Image
function getImage(name) {
  if (isMinNS4) {
    return findImage(name, document);
  }
  if (isMinIE4)
    return eval('document.all.' + name);
  return null;
}
function findImage(name, doc) {
  var i, img;
  for (i = 0; i < doc.images.length; i++)
    if (doc.images[i].name == name)
      return doc.images[i];
  for (i = 0; i < doc.layers.length; i++)
    if ((img = findImage(name, doc.layers[i].document)) != null) {
      img.container = doc.layers[i];
      return img;
    }
  return null;
}
function getImagePageLeft(img) {
  var x, obj;
  if (isMinNS4) {
    if (img.container != null)
      return img.container.pageX + img.x;
    else
      return img.x;
  }
  if (isMinIE4) {
    x = 0;
    obj = img;
    while (obj.offsetParent != null) {
      x += obj.offsetLeft;
      obj = obj.offsetParent;
    }
    x += obj.offsetLeft;
    return x;
  }
  return -1;
}
function getImagePageTop(img) {
  var y, obj;
  if (isMinNS4) {
    if (img.container != null)
      return img.container.pageY + img.y;
    else
      return img.y;
  }
  if (isMinIE4) {
    y = 0;
    obj = img;
    while (obj.offsetParent != null) {
      y += obj.offsetTop;
      obj = obj.offsetParent;
    }
    y += obj.offsetTop;
    return y;
  }
  return -1;
}
function SubAboutNavLayer() {
	var content = '';	
    //===========================================================================================================================================================================================================================================================================================
    // Create About Menu 				
       content += '<table cellpadding=0 cellspacing=0 border=0 bgcolor=#EBF5FF width=167>';
	   content += '<tr><td><img src="images/border.gif" width="1" height="21"></td><td>&nbsp;<a class=navcountrytext href="javascript:goto_page(\'http://about.reuters.com/products/\');" onMouseOver="showSubMenu(0, 0);" onMouseOut="setTimer();">Products</a></td><td><img src="images/border.gif" width="1" height="21"></td></tr>';
       content += '<tr><td><img src="images/border.gif" width="1" height="3"></td><td><img src="images/border.gif" width="167" height="1"></td><td><img src="images/border.gif" width="1" height="3"></td></tr>';
       content += '<tr><td><img src="images/border.gif" width="1" height="21"></td><td>&nbsp;<a class=navcountrytext href="javascript:goto_page(\'http://about.reuters.com/careers/\');" onMouseOver="showSubMenu(0, 0);" onMouseOut="setTimer();">Careers</a></td><td><img src="images/border.gif" width="1" height="21"></td></tr>';
       content += '<tr><td><img src="images/border.gif" width="1" height="3"></td><td><img src="images/border.gif" width="167" height="1"></td><td><img src="images/border.gif" width="1" height="3"></td></tr>';
       content += '<tr><td><img src="images/border.gif" width="1" height="21"></td><td>&nbsp;<a class=navcountrytext href="javascript:goto_page(\'http://about.reuters.com/investormedia/\');" onMouseOver="showSubMenu(0, 0);" onMouseOut="setTimer();">Investors & Media</a></td><td><img src="images/border.gif" width="1" height="21"></td></tr>';
       content += '<tr><td><img src="images/border.gif" width="1" height="3"></td><td><img src="images/border.gif" width="167" height="1"></td><td><img src="images/border.gif" width="1" height="3"></td></tr>';
	   content += '<tr><td><img src="images/border.gif" width="1" height="21"></td><td>&nbsp;<a class=navcountrytext href="javascript:goto_page(\'http://about.reuters.com/150/\');" onMouseOver="showSubMenu(0, 0);" onMouseOut="setTimer();">150th Anniversary</a></td><td><img src="images/border.gif" width="1" height="21"></td></tr>';
       content += '<tr><td><img src="images/border.gif" width="1" height="3"></td><td><img src="images/border.gif" width="167" height="1"></td><td><img src="images/border.gif" width="1" height="3"></td></tr>';
	   content += '</table>'; 
    //===========================================================================================================================================================================================================================================================================================
    
	//===========================================================================================================================================================================================================================================================================================
    // Check browser and OS version and place layer in the proper position
		
	var img;
	var left;
	var top;
	img = getImage("aboutplaceholder");
	left = getImagePageLeft(img);
	top = getImagePageTop(img);	
	
	
	//Netscape
	if (document.layers) { 
    	createLayer(document, 'layer2', left - 8, top + 17, 170, 500, 0, content);
	}		
	//IE
    if (document.all) {
	//Check For IE Version
		var msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
		var result = parseFloat(navigator.appVersion.substr(msieIndex,3));
			
		if (result >= 5.5) {		
			createLayer(document, 'layer2', left - 20, top + 11, 170, 500, 0, content);
		}
		else {
			//Browser Is Less Than Version 5.5 So Implement The Coordinates Differently
			createLayer(document, 'layer2', left - 20, top + 11, 170, 500, 0, content);
		}
	}
	
}
//===========================================================================================================================================================================================================================================================================================
// Global Variables
var timerID;
var dhtml = 0;
var	num_sub_layers = 1;
var ready = false;
var imageDB = new Array();
var imgbase = "images";

if ((document.layers)||(document.all)) {
	dhtml = 1; }
//===========================================================================================================================================================================================================================================================================================
function goto_page(new_page) {
	if (new_page != 'nothing') {
		clearNav();
    	document.location.href = new_page; }
	//this.parent.SLABody. 
}
//===========================================================================================================================================================================================================================================================================================
function clearNav(area) {
	var i;
	for (i=1; i <=num_sub_layers+1;i++) {
		hideLayer(document, "layer" + i);
		}
	showFormElements(area);
}
//===========================================================================================================================================================================================================================================================================================

function hideFormElements(area) {
	
	var vHome = "home";
	var vNews = "news";
	var vMarkets = "markets";
	var vQuotes = "quotes";
	
	if (area == vHome) {
		if (isMinIE4) {
			//Code To Hide GSL on Home Page If Necessary Uncomment
			/*
			document.topQuoteForm.lookupMethod[0].style.visibility = 'hidden';
			document.topQuoteForm.lookupMethod[1].style.visibility = 'hidden';
			document.topQuoteForm.ticker.style.visibility = 'hidden';
			*/
		}			
	}	
	if (area == vNews) {			
		if (isMinIE4) {
			//Code To Hide GSL on News Page If Necessary Uncomment
			/*
			document.topQuoteForm.lookupMethod[0].style.visibility = 'hidden';
			document.topQuoteForm.lookupMethod[1].style.visibility = 'hidden';
			document.topQuoteForm.ticker.style.visibility = 'hidden';
			*/
		}
	}
	if (area == vMarkets) {			
		//alert('you chose markets');				
	}
	if (area == vQuotes) {
		//Code To Hide Form Elements on Quote Lookup Page
		if (document.quoteBodyForm) {
			document.quoteBodyForm.quotesformselect.style.visibility = 'hidden';
		}
		else {
			//Code To Hide GSL on Quotes Results Page If Necessary Uncomment
			/*
			document.topQuoteForm.lookupMethod[0].style.visibility = 'hidden';
			document.topQuoteForm.lookupMethod[1].style.visibility = 'hidden';
			document.topQuoteForm.ticker.style.visibility = 'hidden';
			*/
		}		
	}	
}
//=================================================================================================
function showFormElements(area) {
	var vHome = "home";
	var vNews = "news";
	var vMarkets = "markets";
	var vQuotes = "quotes";

	if (area == 'home') {
		if (isMinIE4) {
			//Code To Show GSL on Home Page If Necessary Uncomment
			/*
			document.topQuoteForm.lookupMethod[0].style.visibility = 'visible';
			document.topQuoteForm.lookupMethod[1].style.visibility = 'visible';
			document.topQuoteForm.ticker.style.visibility = 'visible';
			*/
		}			
	}
	if (area == 'news') {			
		if (isMinIE4) {
			//Code To Show GSL on News Page If Necessary Uncomment
			/*
			document.topQuoteForm.lookupMethod[0].style.visibility = 'visible';
			document.topQuoteForm.lookupMethod[1].style.visibility = 'visible';
			document.topQuoteForm.ticker.style.visibility = 'visible';
			*/
		}
	}
	if (area == 'markets') {			
		//alert('you chose markets');
	}
	if (area == 'quotes') {			
		if (document.quoteBodyForm) {
			//Code To Show Form Elements on Quote Form Page
			document.quoteBodyForm.quotesformselect.style.visibility = 'visible';
		}
		else {
			//Code To Show GSL on Quote Results Page If Necessary Uncomment
			/*
			document.topQuoteForm.lookupMethod[0].style.visibility = 'visible';
			document.topQuoteForm.lookupMethod[1].style.visibility = 'visible';
			document.topQuoteForm.ticker.style.visibility = 'visible';
			*/
		}	
	}
}
function showSubMenu(mainMenu, subMenu, area)  {
  	clearTimeout(timerID);
	if (mainMenu) {
		clearNav();}
	if (subMenu > 0) {
		showLayer(document, "layer" + subMenu);
		hideFormElements(area);
	}
}
//===========================================================================================================================================================================================================================================================================================	
function setTimer(area) {
  timerID = setTimeout("clearNav(area)", 500);  
   }
//===========================================================================================================================================================================================================================================================================================	
function DisplayStat(cur_sel) {
	var new_page = cur_sel.options[cur_sel.selectedIndex].value;
	document.location.replace(new_page); }

//===========================================================================================================================================================================================================================================================================================	
function showCountries() { }
//===========================================================================================================================================================================================================================================================================================	
function getBrowserType() {

	//IE Found
	if (document.all) {
			var msieIndex = navigator.appVersion.indexOf("MSIE") + 5;
			var result = parseFloat(navigator.appVersion.substr(msieIndex,3));			
			if (result >= 5.5) {
				return "IE55";
			}
			else { 
				return "IE50";
			}
	}
	//Netscape 4
	else if (document.layers) {
			return "Netscape4";
	}
	//Netscape 6
	else if (document.getElementById) {
			return "Netscape6";
	}
}
