// JavaScript Document
/*

	Javascript class to setup various utility methods
	
	Trace function plugs into firebug in firefox...for development only
	
	required code at the bottom of file instantiates the utility class
	
	This setup keeps js (unobtrusive!) OUT of markup.
	
*/

/*Event.observe(window, 'load', showPage);

function showPage () {
	document.body.removeClassName('hidebody');
}*/
/* Start Utility */
var Utility = Class.create({
	initialize: function(){
		this.trace("Javascript loaded.");
		this.safariFix();
		// if we are in debug mode set debug to false
		// otherwise set it to false if ie, true otherwise
		this.debug = (Prototype.Browser.IE) ? false : false;
		Event.observe(window, 'load', this.loaded.bind(this));
	
	},
	loaded: function(){
		this.trace('DOM loaded and available.');
		// add pseudo classes as classes for unsupported browsers
		$$('li:last-child').invoke('addClassName', 'last-child');
		$$('li:first-child').invoke('addClassName', 'first-child');
		
		this.setupDropDown();
		
		if($$('.tabs')){
			$$('.tabs').each(function(tab){
				util.trace(tab.id);
				new OTabs(tab);
			});
			
		}
		
		// anchor outline fix
		if(Prototype.Browser.IE){
			$$('a').invoke('observe', 'click', function(event){
				event.target.blur();
			});
		}
		
		// if there is a slideshow element, start it up
		if($('slideshow')){
			new OSlideshow($('slideshow').show(),5, true);
		}
		
		// instantiates collapsible list elements
		if($$('.collapsible')){
			$$('.collapsible').each(function(el){
				new Collapsible(el, true);
			});
		}
		//$$('.sections .collapsible').each(function(el){
			//new Collapsible(el);
		//});
	},
	
	setupDropDown: function(){
		// adds hasSubmenu class if there is a nested list
		$$('#navigation>li').invoke('hide');
		$$('#navigation>li').each(function(node, i){
		 		if(node.select('ul').first()) {
					node.addClassName('hasSubmenu');
				}
		 });
		
		
		$$('#navigation>li>ul>li').each(function(node, i){						
		 		if(node.select('ul').first()) {
					node.addClassName('hasSubmenu');
				}
		 });
		
		
		
		// toggles .anchor hover
		$$("#navigation li>a").each(function(node, i){
			node.onmouseover = node.onmouseout = function(){
				node.toggleClassName('anchor_hover');
			}
		
		});
		
		
		
		// toggles .over on submenu
		$$("#navigation li.hasSubmenu").each(function(node, i){
			//node.cleanWhitespace();
			// if there’s a ul
		//	var ul = node.select('ul').first();//$A(node.getElementsByTagName("ul")).first();
			//if(ul != null){ 
					// toggle it’s visibility on these events
					
				node.onmouseover = function(){
					node.select('ul').first().show();
				}
				node.onmouseout = function(){
					node.select('ul').first().hide();
				}
		//	}
			
			
		});
		$$('#navigation>li').invoke('show');
		//reset any stray overs
		
	},
	
	// This function is used for development only
	trace: function($message){
		// Comment out this line for production
		if (this.debug && ((window['console']) || (console['firebug']))) console.log($message);
		
	},
	
	safariFix: function(){
		// if we are in safari, insert a stylesheet into <head>
		if(Prototype.Browser.WebKit){
			document.documentElement.firstChild.insert('<link rel="stylesheet" href="/partners/internal/v2/admin2/safari-fixes.css" type="text/css" media="screen" charset="utf-8" />');
		}
	}
});


function change()
{
	document.getElementById("light").style.display="block";
	document.getElementById("fade").style.display="block";
	document.getElementById("light").innerHTML = "<div id='load' style='margin-right:250px; margin-top:50px;'><img src='/admin/images/sitefinder/sitefinder_loader.gif' width='32' height='32' /></div><iframe src='/admin/sitefinder/sitefinder.html' frameborder='0' width='624' height='455' scrolling='no' allowtransparency='true' id='siteid' style='visibility:hidden'></iframe>";
}



util = new Utility();
/* End Utility */

/* Start Collapser */
// adds a toggle to collapse or expand a sidebar element
var Collapsible = Class.create({
	initialize: function(el){
		// insert controls
		if(!el.select('.collapser').length){
			var toggler = new Element('a', {'class' : 'collapser', href: '#'}).update('Close');

				// add button to top header
			el.select('h3').first().insert({after: toggler.cloneNode(true)});

				// add button to sidebar_content
			el.select('.sidebar_content').first().insert(toggler.cloneNode(true));
		}
		
			// observe controls
		el.select('.collapser', 'h3').each(function(button, i){
			button.setStyle({cursor: 'pointer'});
			button.observe('click', function(event){
				event.stop();
				el.toggleClassName('collapsed');
			})
		});
	}
});


/* End Collapser */


/* Start Tabs */

// adds functionality for tabbed sections of content
var OTabs = Class.create({
	initialize: function(tab){
		// find tabs and content they refer to
		var top = tab;
		var contents = top.select('.tab-content').first();
		var ui = top.select('.tab-nav').first();
		if(Prototype.Browser.IE) $(top).setStyle({height: 20+contents.getHeight()+'px'});
		// initialize tabs
		if(!contents.select('li:first-child').first().hasClassName('active') || !ui.select('li:first-child').first().hasClassName('active')){
			[ 	
				contents.select('li:first-child').first(),
				ui.select('li:first-child').first()
			// invokes toggleClassName and sets class to active
			// for the first tab and tab content
			].invoke('toggleClassName', 'active');
		
		}
		// watch tab links
		ui.select('a').each(function(button, i){
			button.observe('click', function(event){
				// stop browser from following tab link
				event.stop();
				
				[	// switch off active content
					
					ui.select('li.active').first(),
					contents.select('li.active').first(),
					
					//switch on selected content
					$(this.rel),
					this.up()
				].invoke('toggleClassName', 'active');
				if(Prototype.Browser.IE) $(top).setStyle({height: 20+contents.getHeight()+'px'});
			});
		}.bind(this));
	}
});
/* End Tabs */


// Function for the worldwide popup

function OPNworldwideCountries(page){

if(page=="hp")
{
	document.writeln("<div id=\'panelDiv\' style=\"position:absolute;right:110px; top:20px;visibility:hidden; z-index:500000; WIDTH: 350px; BORDER-RIGHT: #9b9b9b 2px solid; PADDING-RIGHT: 12px;BORDER-TOP: #9b9b9b 2px solid; PADDING-LEFT: 12px; PADDING-BOTTOM: 12px; BORDER-LEFT: #9b9b9b 2px solid; PADDING-TOP: 12px;BORDER-BOTTOM: #9b9b9b 2px solid; BACKGROUND-COLOR: #f8f7f7\" onmouseover=\"panelMOv();\" onmouseout=\"panelMOu();\">");
}
else if(Prototype.Browser.IE)
{
	document.writeln("<div id=\'panelDiv\' style=\"position:absolute;right:50%; margin-right:-368px; top:42px;visibility:hidden; z-index:500000; WIDTH: 380px; BORDER-RIGHT: #9b9b9b 2px solid; PADDING-RIGHT: 12px;BORDER-TOP: #9b9b9b 2px solid; PADDING-LEFT: 12px; PADDING-BOTTOM: 12px; BORDER-LEFT: #9b9b9b 2px solid; PADDING-TOP: 12px;BORDER-BOTTOM: #9b9b9b 2px solid; BACKGROUND-COLOR: #f8f7f7\" onmouseover=\"panelMOv();\" onmouseout=\"panelMOu();\">");
}
else
{
	document.writeln("<div id=\'panelDiv\' style=\"position:absolute;right:50%; margin-right:-368px; top:40px;visibility:hidden; z-index:500000; WIDTH: 350px; BORDER-RIGHT: #9b9b9b 2px solid; PADDING-RIGHT: 12px;BORDER-TOP: #9b9b9b 2px solid; PADDING-LEFT: 12px; PADDING-BOTTOM: 12px; BORDER-LEFT: #9b9b9b 2px solid; PADDING-TOP: 12px;BORDER-BOTTOM: #9b9b9b 2px solid; BACKGROUND-COLOR: #f8f7f7\" onmouseover=\"panelMOv();\" onmouseout=\"panelMOu();\">");
}

document.writeln("<table width=100%>");
document.writeln("<tr align=left><td colspan=5 class=\'sngPst\' style=\"border-bottom:#cccccc 1px solid\"><b>SELECT A LANGUAGE<\/b><\/td><\/tr>");
document.writeln("<tr valign=top><td width=35% class=\'sngPst\'>");
document.writeln("<div nowrap><b>APAC</b><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/apac/chinese_sm/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:SIMPLIFIED CHINESE\';\">Simplified Chinese<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/apac/chinese_tr/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:TRADITIONAL CHINESE\';\">Traditional Chinese<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/apac/korean/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:KOREAN\';\">Korean<\/a><\/div> ");
document.writeln("<\/td>");


document.writeln("<td width=30% class='sngPst'>");
document.writeln("<div nowrap><b>EMEA</b><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/emea/english/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:ENGLISH\';\">EMEA English<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/emea/french/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:FRENCH\';\">French<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/emea/german/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:GERMAN\';\">German<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/emea/italian/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:ITALIAN\';\">Italian<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/emea/polish/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:POLISH\';\">Polish<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/emea/spanish/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:EMEA SPANISH\';\">Spanish<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/emea/russian/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:EMEA RUSSIAN\';\">Russian<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/emea/czech/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:EMEA CZECH\';\">Czech<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/emea/turkish/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:EMEA TURKISH\';\">Turkish<\/a><\/div> ");
document.writeln("<\/td>");


document.writeln("<td width=35% class='sngPst'>");
document.writeln("<div nowrap><b>LAD</b><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/lad/portuguese/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:BRAZILIAN PORTUGUESE\';\">Brazilian Portuguese<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/home/prospective/lad/spanish/welcome.html\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:SPANISH\';\">LAD Spanish<\/a><\/div> ");
document.writeln("<\/td><\/tr>");
document.writeln("<tr><td><\/td><\/tr>");
document.writeln("<\/table>");
document.writeln("<\/div>");

}


// Worldwide popup menu

function panelMOv() {
	if (navigator.appName != "Netscape") {
		var dropdown = document.getElementById("group");
		dropdown.style.visibility = "hidden";
	}

	var p = document.getElementById("panelDiv");
	p.style.visibility = "visible";
}

function panelMOu() {
	var p = document.getElementById("panelDiv");
	p.style.visibility = "hidden";	

	if (navigator.appName != "Netscape") {
		var dropdown = document.getElementById("group");
		dropdown.style.visibility = "visible";
	}
}

function mvqMOv() {
	if (navigator.appName != "Netscape") {
		var dropdown = document.getElementById("group");
		dropdown.style.visibility = "hidden";
	}

	var mvqPDiv = document.getElementById("panelDiv"); 
	mvqPDiv.style.visibility = "visible";
}

function mvqMOu() {
	var mvqPDiv = document.getElementById("panelDiv"); 
	mvqPDiv.style.visibility = "hidden";

	if (navigator.appName != "Netscape") {
		var dropdown = document.getElementById("group");
		dropdown.style.visibility = "visible";
	}
}
 

