// 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 */
// Removed Utility code as utility.js have the same code
// Date/Time Modified: 25sth Sep 2009, 10.50AM PDT
/* 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();
		/* Home page - tab fix */
		if(typeof(ui)=='undefined')
		{
		var ui = top.select('.tab-nav-hp').first();
		}
		/*  End  */
		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:31px;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:30px;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/ja/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:JAPANESE\';\">Japanese<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/ko/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:KOREAN\';\">Korean<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/zhs/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:SIMPLIFIED CHINESE\';\">Simplified Chinese<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/zht/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:TRADITIONAL CHINESE\';\">Traditional Chinese<\/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/cs/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:EMEA CZECH\';\">Czech<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/emea-en/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:ENGLISH\';\">EMEA English<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/fr/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:FRENCH\';\">French<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/de/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:GERMAN\';\">German<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/ita/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:ITALIAN\';\">Italian<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/pl/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:POLISH\';\">Polish<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/ru/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:EMEA RUSSIAN\';\">Russian<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/es/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:EMEA SPANISH\';\">Spanish<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/tr/index.htm\" 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/ptb/index.htm\" class=\'sngPst\' onClick=\"s_objectID=\'R8:WW:BRAZILIAN PORTUGUESE\';\">Brazilian Portuguese<\/a><\/div> ");
document.writeln("<div nowrap><a href=\"/partners/esa/index.htm\" 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";
	}
}
 

/* Start slidshow.js */

// enables slideshow functionality to an unordered list
// visual design controlled via styles in stylesheet
var OSlideshow = Class.create({
	name: 'Slideshow',
	initialize: function(el, delay, controls){
		this.el = el;

		//gather slides
		this.slides = this.el.childElements();
		// set delay if given, otherwise default to 5 seconds
		this.delay = delay || 5;
		// sets whether or not we want an interface
		this.controls = (controls == false || this.slides.length < 2) ? false : true;
		// defaults to not running
		this.running = false;
		// defaults to going forward instead of backward
		this.forward = true;
		// new cycler with a range = to number of slides
		this.cycle = new Cycle(this.slides.length);
		
		//loop through and hide slides, make first active
		this.nameSlides();
		//add controls
		if(this.controls) this.addControls();
		//start counter
		this.periodic = this.startPeriodic();
		
		// listen for slideshow:next event
		document.observe('slideshow:next', function(event){
			//if we got next invoke active class toggler
			$$('#slideshow li.active').first().hide().toggleClassName('active');
			$('slide['+event.memo.slide+']').show().toggleClassName('active');
			if(this.controls){
				// if we have controls, update them
				$$('#slideshow_controls li.button a.active').first().toggleClassName('active');
				$$('#slideshow_controls li.button a.jump[rel="slide['+event.memo.slide+']"]').first().toggleClassName('active');
			}
		}.bind(this));
	},
	
	startPeriodic: function(){
		// setup periodical executer to cycle through cycler
		if(this.slides.length > 1){
			// if we have more than one slide start cycling
			return new PeriodicalExecuter(function(pe){
				// if not paused
				if(this.running){
					// fire next event, with slide target being the cycler value
					document.body.fire('slideshow:next', {
						slide: this.forward ? this.cycle.next() : this.cycle.previous()
					});
				}
			}.bind(this), this.delay);	
		}
	},
	
	nameSlides: function(){
		// add extra markup to enable slideshow and hide slides
		this.slides.each(function(slide, i){
			if(slide.id != 'slideshow_ui'){
				slide.addClassName('slide');
				slide.id = 'slide['+i+']';
				slide.hide();
			}
			// show the first slide
			if(i == 0) slide.toggleClassName('active').show();
		});
	},
	
	addControls: function(){
		// add ui controls if we want them
		this.el.appendChild(new Element('li', {id: 'slideshow_ui'}).update(this.buildControls()));
		that = this;
		$$('#slideshow_controls li.button a').first().toggleClassName('active');
		
		// listen to pause clicks
		$$('#slideshow_controls #pause_slides').first().observe('click', function(event){
			event.stop();
			event.target.fire('slideshow:play_pause');
		});
		
		// listen for previous slide and fire next event with proper slide id
		$$('#slideshow_controls #previous_slide').first().observe('click', function(event){
			event.stop();
			if(that.running){
				that.periodic.stop();
				$('pause_slides').fire('slideshow:play_pause');
			}
			document.fire('slideshow:next', {
				slide: that.cycle.previous()
			});
		});
		
		// listen for next slide and fire next event with proper slide id
		$$('#slideshow_controls #next_slide').first().observe('click', function(event){
			event.stop();
			if(that.running){
				that.periodic.stop();
				$('pause_slides').fire('slideshow:play_pause');
			}
			document.fire('slideshow:next', {
				slide: that.cycle.next()
			});
		});
		
		// listen for jump click (direct jump), and fire id
		$$('#slideshow_controls .jump').each(function(jumper){
			jumper.observe('click', function(event){
				event.stop();
				//util.trace('hop ' + this.rel.gsub(/(\w+)\[|\]/, ''));
				
				document.fire('slideshow:next', {
					slide: that.cycle.reset(event.target.rel.gsub(/(\w+)\[|\]/, ''))
				});
			});
		});
		
		// listen for play/pause click, update if clicked and change this.running to pause or play
		document.observe('slideshow:play_pause', function(event){
			if(event.target.rel == 'pause'){
				this.running = false;
				event.target.rel = 'play';
				event.target.innerHTML = 'Play';
			} else {
				this.running = true;
				this.periodic = this.startPeriodic();
				event.target.rel = 'pause';
				
				event.target.innerHTML = 'Pause';
			}
			util.trace(event.target);
		}.bind(this));
	},
	
	// build interface markup
	buildControls: function(){
		var n = this.cycle.copy();
		var controls = new Element('ul', { id: "slideshow_controls"});
		var pause = new Element('a', {href: '#', id: 'pause_slides', rel: 'pause'}).update('Pause');
		var next = new Element('a', {href: '#', id: 'previous_slide', rel: this.slides.last().id}).update('&lsaquo;'); //'<li><a id="previous_slide" rel="'+this.slides.last().id+'" href="#">&lsaquo;</a></li>';)
		var prev = new Element('a', {href: '#', id: 'next_slide', rel: this.slides[n.next()].id}).update('&rsaquo;');
		
		controls.insert(new Element('li').insert(pause));
		controls.insert(new Element('li').insert(next));
		
		
		this.slides.each( function (slide, i){
			controls.insert(new Element('li', {'class': 'button'}).update(new Element('a', {'href': '#', 'class': 'jump', 'rel': 'slide['+i+']'}).update(i+1)));
		});
		
		controls.insert(new Element('li').update(prev));
		return controls;
	}
});

// cycle class repetatively cycles through a range of positive numbers
Cycle = Class.create({
	
	currentId: 0,
	range: 0,
	
	initialize: function(range, val){
		this.range = range;
		this.currentId = val || 0;
	},
	// increase and return
	next: function(by){
		by = by || 1;
		var increment = this.currentId + by;
		return this.currentId = increment % this.range;
	},
	// decrease and return
	previous: function(by){
		by = by || 1;
		var increment = this.currentId - by;
		if(increment<0)
			return this.currentId = this.range - 1;
			else
		return this.currentId = Math.abs(increment % this.range);
	},
	
	// return value
	value: function(){
		return this.currentId;
	},
	
	// resets to zero by default, accepts value, returns new value
	reset: function(to){
		return this.currentId = to || 0;
	},
	
	// returns a copy of cycle object
	copy: function(){
		var neo = new Object();
		for(var i in this){
			neo[i] = this[i];
		}
 		return neo;
	}
});
/*End slideshow.js*/


/* Start Image refresh fix for IE */
	function fixIE6flicker(fix) {
	 try {
	  document.execCommand("BackgroundImageCache", false, fix);
	 } catch(err) { }
	}
	fixIE6flicker(true);
	
	function is_child_of(parent, child) {
		if( child != null ) {           
			while( child.parentNode ) {
				if( (child = child.parentNode) == parent ) {
					return true;
				}
			}
		}
		return false;
	}
	
	function fixOnMouseOut(element, event, JavaScript_code) {
		var current_mouse_target = null;
		if( event.toElement ) {             
			current_mouse_target             = event.toElement;
		} else if( event.relatedTarget ) {              
			current_mouse_target             = event.relatedTarget;
		}
		if( !is_child_of(element, current_mouse_target) && element != current_mouse_target ) {
			eval(JavaScript_code);
		}
	}
/* End Image refresh fix for IE */

/* OPN Hp JS code integrated */

  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
  
  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

	
//more industries
function indMOv() {
	var indarrow = document.getElementById("indarrow"); 
	var x = findPosX(indarrow);
	var y = findPosY(indarrow);

	var indDiv = document.getElementById("indDiv"); 
	//alert(navigator.appName);
	//if (navigator.appName == "Netscape")
		x = x-26;
	//else
		//x = x-26;
	if (navigator.appName == "Netscape")
		y = y+14;
	else
		y = y+12;
	//alert(x + " " + y);
	indDiv.style.left=x+'px';
	indDiv.style.top=y+'px';
	indDiv.style.position="absolute";
	
  	indDiv.style.visibility = "visible";
	indDiv.style.display = "";
}

function indMOu() {
	var indDiv = document.getElementById("indDiv"); 
	if (navigator.appName != "Netscape") {
		if (!indDiv.contains(window.event.toElement)) {
			indDiv.style.visibility = "hidden";
			indDiv.style.display = "";
		}
	} else {
		indDiv.style.visibility = "hidden";
		indDiv.style.display = "";
		}
}

function indPanelMOv() {
	var indDiv = document.getElementById("indDiv"); 
	indDiv.style.visibility = "visible";
	indDiv.style.display = "";
}

function indPanelMOu() {
	var indDiv = document.getElementById("indDiv"); 
	if (navigator.appName != "Netscape") {
		if (!indDiv.contains(window.event.toElement)){
			indDiv.style.visibility = "hidden";
			indDiv.style.display = "";
			}
	} else
	{
		indDiv.style.visibility = "hidden";
		indDiv.style.display = "";
		}
}

//Database
function indMOv2() {
	var indDiv = document.getElementById("indDiv2"); 
  indDiv.style.visibility = "visible";
}

function indMOv2() {
	var indarrow2 = document.getElementById("indarrow2"); 
	var x = findPosX(indarrow2);
	var y = findPosY(indarrow2);

	var indDiv = document.getElementById("indDiv2"); 
	//alert(navigator.appName);
//if (navigator.appName == "Netscape")
		x = x-26;
	//else
		//x = x-26;
	if (navigator.appName == "Netscape")
		y = y+14;
	else
		y = y+13;
	//alert(x + " " + y);
	indDiv.style.left=x+'px';
	indDiv.style.top=y+'px';
	indDiv.style.position="absolute";
	
  	indDiv.style.visibility = "visible";
	indDiv.style.display = "";
}

function indMOu2() {
	var indDiv = document.getElementById("indDiv2"); 
	if (navigator.appName != "Netscape") {
		if (!indDiv.contains(window.event.toElement))
		{
			indDiv.style.visibility = "hidden";
			indDiv.style.display = "";
		}
	} else
	{
		indDiv.style.visibility = "hidden";
		indDiv.style.display = "";
	}
}

function indPanelMOv2() {
	var indDiv = document.getElementById("indDiv2"); 
	indDiv.style.visibility = "visible";
}

function indPanelMOu2() {
	var indDiv = document.getElementById("indDiv2"); 
	if (navigator.appName != "Netscape") {
		if (!indDiv.contains(window.event.toElement))
		{
			indDiv.style.visibility = "hidden";
			indDiv.style.display = "";
		}
	} else
	{
		indDiv.style.visibility = "hidden";
		indDiv.style.display = "";
	}
}
//Middleware
function indMOv3() {
	var indDiv = document.getElementById("indDiv3"); 
  indDiv.style.visibility = "visible";
}

function indMOv3() {
	var indarrow3 = document.getElementById("indarrow3"); 
	var x = findPosX(indarrow3);
	var y = findPosY(indarrow3);

	var indDiv = document.getElementById("indDiv3"); 
	//alert(navigator.appName);
//if (navigator.appName == "Netscape")
		x = x-26;
	//else
		//x = x-26;
	if (navigator.appName == "Netscape")
		y = y+14;
	else
		y = y+12;
	//alert(x + " " + y);
	indDiv.style.left=x+'px';
	indDiv.style.top=y+'px';
	indDiv.style.position="absolute";
	
  	indDiv.style.visibility = "visible";
	indDiv.style.display = "";
}

function indMOu3() {
	var indDiv = document.getElementById("indDiv3"); 
	if (navigator.appName != "Netscape") {
		if (!indDiv.contains(window.event.toElement))
		{
			indDiv.style.visibility = "hidden";
			indDiv.style.display = "";
		}
	} else
	{
		indDiv.style.visibility = "hidden";
		indDiv.style.display = "";
	}
}

function indPanelMOv3() {
	var indDiv = document.getElementById("indDiv3"); 
	indDiv.style.visibility = "visible";
}

function indPanelMOu3() {
	var indDiv = document.getElementById("indDiv3"); 
	if (navigator.appName != "Netscape") {
		if (!indDiv.contains(window.event.toElement))
		{
			indDiv.style.visibility = "hidden";
			indDiv.style.display = "";
		}
	} else
	{
		indDiv.style.visibility = "hidden";
		indDiv.style.display = "";
	}
}
//Business Solutions
function indMOv1() {
	var indDiv = document.getElementById("indDiv1"); 
  indDiv.style.visibility = "visible";
}

function indMOv1() {
	var indarrow1 = document.getElementById("indarrow1"); 
	var x = findPosX(indarrow1);
	var y = findPosY(indarrow1);

	var indDiv = document.getElementById("indDiv1"); 
	//alert(navigator.appName);
//if (navigator.appName == "Netscape")
		x = x-26;
	//else
		//x = x-26;
	if (navigator.appName == "Netscape")
		y = y+14;
	else
		y = y+13;
	//alert(x + " " + y);
	indDiv.style.left=x+'px';
	indDiv.style.top=y+'px';
	indDiv.style.position="absolute";
	
  	indDiv.style.visibility = "visible";
	indDiv.style.display = "";
}

function indMOu1() {
	var indDiv = document.getElementById("indDiv1"); 
	if (navigator.appName != "Netscape") {
		if (!indDiv.contains(window.event.toElement))
		{
			indDiv.style.visibility = "hidden";
			indDiv.style.display = "";
		}
	} else
	{
		indDiv.style.visibility = "hidden";
		indDiv.style.display = "";
	}
}

function indPanelMOv1() {
	var indDiv = document.getElementById("indDiv1"); 
	indDiv.style.visibility = "visible";
}

function indPanelMOu1() {
	var indDiv = document.getElementById("indDiv1"); 
	if (navigator.appName != "Netscape") {
		if (!indDiv.contains(window.event.toElement))
		{
			indDiv.style.visibility = "hidden";
			indDiv.style.display = "";
		}
	} else
	{
		indDiv.style.visibility = "hidden";
		indDiv.style.display = "";
	}
}


