﻿//operaBool handles an issue related to Opera wanting to create two copies of each left side menu
var operaBool=1;
if (is_opera)
	operaBool=0;

//loadMenu function launches a specified left side menu
function loadMenu(menuNum){
	if (menuCookie[menuNum-1]==1) {	eval("window.frames.menuIframe" + menuNum + ".Go()"); }
}

//menuClear reinitializes all other menus except the menu calling the function. It's purpose is to allow all of the seperate menus to function together all one more cleanly
function menuClear(menuNum)
{
	if(menuNum!=1){window.frames.menuIframe1.Initiate();window.frames.menuIframe1.menuOverCounter=0;}
	if(menuNum!=2){window.frames.menuIframe2.Initiate();window.frames.menuIframe2.menuOverCounter=0;}
	if(menuNum!=3){window.frames.menuIframe3.Initiate();window.frames.menuIframe3.menuOverCounter=0;}
	if(menuNum!=4){window.frames.menuIframe4.Initiate();window.frames.menuIframe4.menuOverCounter=0;}
	if(menuNum!=5){window.frames.menuIframe5.Initiate();window.frames.menuIframe5.menuOverCounter=0;}
	if(menuNum!=6){window.frames.menuIframe6.Initiate();window.frames.menuIframe6.menuOverCounter=0;}
	if(menuNum!=7){window.frames.menuIframe7.Initiate();window.frames.menuIframe7.menuOverCounter=0;}
}

function rePosition(){
//	try{RePos();}catch(err){}
	
	for(var count=1; count<=7; count++) {
		if(menuCookie[count-1]==1)
			try{eval("window.frames.menuIframe"+ count +".RePos()");}catch(err){}
	}
}

function hideMenu(menuNum){
	document.getElementById("menuContainer"+menuNum).style.display="none";
}

function showMenu(menuNum)
{
	if(eval("window.frames.menuIframe" + menuNum + ".Crtd!=true"))
	{
		//eval("window.frames.menuIframe" + menuNum + ".Go()");
		eval("window.frames.menuIframe" + menuNum + ".Go()");

	}
	document.getElementById("menuContainer"+menuNum).style.display="block";

}

    function newsCollapse(newsPost) {
    var obj;
    obj = document.getElementById(newsPost);
    if (obj.style.display != "block")
        obj.style.display = "block";
    else
        obj.style.display = "none";
    }

function getexpirydate(nodays){
	var UTCstring;
	Today = new Date();
	nomilli=Date.parse(Today);
	Today.setTime(nomilli+nodays*24*60*60*1000);
	UTCstring = Today.toUTCString();
	return UTCstring;
}

function getcookie(cookiename) {
	 var cookiestring=""+document.cookie;
	 var index1=cookiestring.indexOf(cookiename);
	 if (index1==-1 || cookiename=="") return ""; 
	 var index2=cookiestring.indexOf(';',index1);
	 if (index2==-1) index2=cookiestring.length; 
	 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}
function setcookie(name,value){
	cookiestring=name+"="+escape(value)+";EXPIRES="+ getexpirydate(365)+";PATH=/";
	document.cookie=cookiestring;
}


// ----------------------------------------------
// StyleSwitcher functions written by Paul Sowden
// http://www.idontsmoke.co.uk/ss/
// - - - - - - - - - - - - - - - - - - - - - - -
// For the details, visit ALA:
// http://www.alistapart.com/stories/alternate/

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  createCookie("style", getActiveStyleSheet(), 365);
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled)return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(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 initTheme(e) {

  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}


/*
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
*/
// Copyright (c) 1996-1997 Athenia Associates.
// http://www.webreference.com/js/
// License is granted if and only if this entire
// copyright notice is included. By Tomer Shiran.

function setCookie (name, value, expires, path, domain, secure) {
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "/") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) {
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
}

function deleteCookie (name, path, domain) {
    if (getCookie(name))
        document.cookie = name + "=" + ((path) ? "; path=" + path : "/") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}

function fixDate (date) {
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}

function rememberMe (f) {
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    setCookie('mtcmtauth', f.author.value, now, '', HOST, '');
    setCookie('mtcmtmail', f.email.value, now, '', HOST, '');
    setCookie('mtcmthome', f.url.value, now, '', HOST, '');
}

function forgetMe (f) {
    deleteCookie('mtcmtmail', '', HOST);
    deleteCookie('mtcmthome', '', HOST);
    deleteCookie('mtcmtauth', '', HOST);
    f.email.value = '';
    f.author.value = '';
    f.url.value = '';
}

var menuCookie;
var tempString;
if(!(tempString = getcookie("menuCookie"))){
	setcookie('menuCookie', '0 0 0 0 0 0 0');
	menuCookie = [1, 1, 1, 1, 1, 1, 1];
} else {
	menuCookie = tempString.split(" ");
}
var menuNames = ["menuNews", "menuGameGuide", "menuInteractive", "menuCommunity", "menuAccount", "menuSupport", "menuMedia"];

function toggleMenu(menuID) {
	
	var menuNum = parseInt(menuID)+1;

	var toggleState = menuCookie[menuID];
	var menuName = menuNames[menuID]+ "-inner";
    var collapseLink = menuNames[menuID]+ "-collapse";
    var menuVisual = menuNames[menuID]+ "-icon";
    var menuHeader = menuNames[menuID]+ "-header";
    var menuButton = menuNames[menuID]+ "-button";
	
	if (toggleState == 0) {

		showMenu(menuNum);
		document.getElementById(menuName).style.visibility = "visible";
		document.getElementById(menuName).style.display = "block";		
        document.getElementById(menuButton).className = "menu-button-on";
        document.getElementById(collapseLink).className = "leftMenu-minusLink";
        document.getElementById(menuVisual).className = menuNames[menuID]+ "-icon-on";
        document.getElementById(menuHeader).className = menuNames[menuID]+ "-header-on";
		menuCookie[menuID] = 1;
	} else {
		hideMenu(menuNum);
		document.getElementById(menuName).style.visibility = "hidden";
		document.getElementById(menuName).style.display = "none";		
        document.getElementById(menuButton).className = "menu-button-off";
        document.getElementById(collapseLink).className = "leftMenu-plusLink";
        document.getElementById(menuVisual).className = menuNames[menuID]+ "-icon-off";
        document.getElementById(menuHeader).className = menuNames[menuID]+ "-header-off";
		menuCookie[menuID] = 0;
	}
		rePosition();
		var theString = menuCookie[0] + " " +menuCookie[1]+ " " +menuCookie[2]+ " " +menuCookie[3]+ " " +menuCookie[4]+ " " +menuCookie[5] + " " +menuCookie[6];
		setcookie('menuCookie', theString);	
}

/*
var newsCookie;
var tempString;
if(!(tempString = getcookie("newsCookie"))){
	setcookie('newsCookie', '-1 0 0 0 0 0');
	newsCookie = [-1, 0, 0, 0, 0, 0];
} else {
	newsCookie = tempString.split(" ");
}
var newsEntries = ["1", "2", "3", "4", "5", "6"]; // please mirror with toggleNews function
function toggleEntry(newsID) {
	var toggleState = newsCookie[newsID-1];
	var newsEntry = "news"+newsEntries[newsID-1];
    var collapseLink = "plus"+newsEntries[newsID-1];

	if (toggleState == 0) {
		document.getElementById(newsEntry).style.display = "block";		
        document.getElementById(collapseLink).className = "news-minusLink";
		newsCookie[newsID-1] = 1;
	} else {
		document.getElementById(newsEntry).style.display = "none";		
        document.getElementById(collapseLink).className = "news-plusLink";
		newsCookie[newsID-1] = 0;
	}
		var theString = newsCookie[0] + " " +newsCookie[1]+ " " +newsCookie[2] + " " +newsCookie[3]+ " " +newsCookie[4] + " " +newsCookie[5];
		setcookie('newsCookie', theString);	
}
*/

function toggleEntry(newsID) {
//alert(newsID);
//alert(document.getElementById(newsID).innerHTML)


	//var toggleState = getcookie(newsID)
	var newsEntry = "news"+newsID;
    var collapseLink = "plus"+newsID;

	if (document.getElementById(newsEntry).style.display == 'block') {
		document.getElementById(newsEntry).style.display = "none";		
        document.getElementById(collapseLink).className = "news-plusLink";
		setcookie(newsEntry, "0");	
	} else {
		document.getElementById(newsEntry).style.display = "block";		
        document.getElementById(collapseLink).className = "news-minusLink";
		setcookie(newsEntry, "1");	
	}
}
function clearFiller(menuNum) {

	//eval("window.frames.menuIframe" + menuNum + ".RePos()");
	document.getElementById("menuFiller" + menuNum).style.visibility="hidden";
}

bgTimeout = null;
function changeNavBgPos() {

    var n, e;
    e = n = document.getElementById("nav");
    y = 0;
    x = 0;
 if (e.offsetParent) {
  while (e.offsetParent) {
   y += e.offsetTop;
   x += e.offsetLeft;
   e = e.offsetParent;
        }
    } else if (e.x && e.y) {
  y += e.y;
  x += e.x;
    }
    n.style.backgroundPosition = (x*-1) + "px " + (y*-1) + "px";

}

function addEvent(obj, evType, fn) {
	
    if (obj.addEventListener) {

        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent) {

        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {

        return false;
    }
}
function goBuffer(){

	Go();

}
if(is_opera)
	addEvent(window, 'load', goBuffer);
	
if(!is_ie)
	addEvent(window, 'load', rePosition);
	addEvent(window, 'resize', rePosition);
    

//Ajax Data Loading

/*
if (is_moz) {
	var xslStylesheet;
	var myDOM;
	var xmlDoc;
	var myXMLHTTPRequest = new XMLHttpRequest();
	var myXMLHTTPRequest2 = new XMLHttpRequest();
}
*/

function xmlDataLoadListener(xmlObj, xslObj, container, loader, afterFunction){

			if (xmlObj.readyState == 4 && xslObj.readyState == 4) {
				document.getElementById(container).innerHTML = xmlObj.transformNode(xslObj);

				document.getElementById(loader).style.display = "none";
				eval(afterFunction);
				window.clearInterval(intervalHolder);
			}
			
}

function xmlDataLoadListenerMoz(xmlObj, xslObj, container, loader){

			if (xmlObj.readyState == 4 && xslObj.readyState == 4) {
					
					window.clearInterval(intervalHolder);
 					xslStylesheet = xslObj.responseXML;
					xmlDoc = xmlObj.responseXML;
				
 					var xsltProcessor = new XSLTProcessor();
					xsltProcessor.importStylesheet(xslStylesheet);
					
					xmlLoadComplete=1;
					var fragment = xsltProcessor.transformToFragment(xmlDoc, window.document);
					document.getElementById(containerGlobal).innerHTML = "";
					document.getElementById(containerGlobal).appendChild(fragment);
					document.getElementById(loader).style.display = "none";

					
			}
			
}


var xmlDataArray = new Array;
var	myXMLHTTPRequest;
var	myXMLHTTPRequest2; 
var intervalHolder;
var containerGlobal;
var loaderGlobal;

function dummyFunction(){}

function movePvpPosition(value){

	document.getElementById("pvpBoxPosition").style.top=value+"px";

}



function xmlDataLoad(xmlSource, xslSource, container, aSync, loader, afterFunction){

	if('undefined' == typeof afterFunction) {afterFunction="dummyFunction()";}

	window.clearInterval(intervalHolder);
	
	document.getElementById(loader).style.display = "block";
	if (is_ie && !is_opera) {

		
		var xml = new ActiveXObject("Microsoft.XMLDOM")
		xml.async = aSync
		xml.load(xmlSource)// Load XSL
		var xsl = new ActiveXObject("Microsoft.XMLDOM")
		xsl.async = aSync
		xsl.load(xslSource)// Transform
		
		if(!aSync){
			document.write(xml.transformNode(xsl));
		}else{

			xmlDataArray[0]=xml;
			xmlDataArray[1]=xsl;

			intervalHolder = window.setInterval("xmlDataLoadListener(xmlDataArray[0],xmlDataArray[1],'"+container+"','"+loader+"','"+afterFunction+"')",100);
			
		}
			
		return true;
		
	
	} else if (is_moz) {
			
			var xslStylesheet;
			var myDOM;
			var xmlDoc;
			myXMLHTTPRequest = new XMLHttpRequest();
			myXMLHTTPRequest2 = new XMLHttpRequest();			
			
			myXMLHTTPRequest.open("GET.html", xslSource, aSync);
			myXMLHTTPRequest.send(null);
			
			
			
			
			// load the xml file, example1.xml
			

			myXMLHTTPRequest2.open("GET.html", xmlSource, aSync);
			myXMLHTTPRequest2.send(null);
			
			
			containerGlobal=container;
			loaderGlobal=loader;
			//myXMLHTTPRequest.onreadystatechange = stateHandler;
			//myXMLHTTPRequest2.onreadystatechange = stateHandler;
			
			intervalHolder = window.setInterval("xmlDataLoadListenerMoz(myXMLHTTPRequest2,myXMLHTTPRequest,'"+container+"','"+loader+"','"+afterFunction+"')",100);
			
		  
	} 
	
	return false;


}

var pvpPage=1;
var pvpHalf=1;
var maxPvpPages=100;

function pvpNext(){

	if(pvpHalf==1){
	
		document.getElementById("pvpBoxPosition").style.top="-220px";
		pvpHalf=2;
	
	}else{
	
		if (pvpPage!=maxPvpPages)
			pvpPage++;
		else
			pvpPage=1;	
			
		pvpHalf=1;
		xmlDataLoad('../pvp/rankings2a3b.xml?r='+escape(currentRealm)+'&faction='+currentFaction+'&p='+pvpPage, '/en/new-hp/layout/pvp.xsl', 'pvpDataContainer', true, 'pvpLoadingBox', 'movePvpPosition(0)')
	}

}

function pvpPrev(){

	if(pvpHalf!=1){
	
		document.getElementById("pvpBoxPosition").style.top="0px";
		pvpHalf=1;
	
	}else{
		if (pvpPage!=1)
			pvpPage--;
		else
			pvpPage=maxPvpPages;
			
		pvpHalf=2;
		xmlDataLoad('../pvp/rankings2a3b.xml?r='+escape(currentRealm)+'&faction='+currentFaction+'&p='+pvpPage, '/en/new-hp/layout/pvp.xsl', 'pvpDataContainer', true, 'pvpLoadingBox', 'movePvpPosition(-220)')
	}

}

function changeFaction(){

	if (currentFaction == 'h') {
	
		//alert("alliance")
		document.getElementById("hordeLarge").style.display="none";
		document.getElementById("hordeSmall").style.display="block";
		xmlDataLoad('../pvp/rankings2a3b.xml?r='+currentRealm+'&amp;faction=a', '/en/new-hp/layout/pvp.xsl', 'pvpDataContainer', true, 'pvpLoadingBox'); 
		setcookie('pvpFaction','a'); 
		currentFaction='a'; 
		pvpPage=1;

	
	} else {
		//alert("horde")
		document.getElementById("hordeLarge").style.display="block";
		document.getElementById("hordeSmall").style.display="none";
		xmlDataLoad('../pvp/rankings2a3b.xml?r='+currentRealm+'&amp;faction=h', '/en/new-hp/layout/pvp.xsl', 'pvpDataContainer', true, 'pvpLoadingBox'); 
		setcookie('pvpFaction','h'); 
		currentFaction='h'; 
		pvpPage=1;
	
	}

}    


///////// OLD SCRIPTS for subpages    
function showComplete(showThis) {
	document.getElementById(showThis).style.display = "inline";
	document.getElementById(showThis).style.visibility = "visible";
}

function hideComplete(showThis) {
	document.getElementById(showThis).style.display = "none";
	document.getElementById(showThis).style.visibility = "visible";
}

// Popup script
function popUpOmega (screenshot, width, height, caption) 
{
	//Browser detection - is the user relying on the one browser where this script does not work?
//	var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;

	var name = "Sheenscrot"; 
	widthHeight = "width=" + width + ",height=" + height;
	winFeatures = "width=" + width + ",height=" + height + ",left=50,top=50,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,location=no"
	if (is_safari) spawn = window.open(screenshot,name,winFeatures);
	else
	{
		spawn = window.open("template/offlike/images/pixel.gif",name,winFeatures)
		spawn.document.write("<html> <head> <title>" + caption + "<\/title> <\/head> <body onBlur='self.close()' background= " + screenshot + "><\/body><\/html>"); 
		spawn.document.close();
	}
}

//Show layer//
function showLayer(layerName){
	obj = document.getElementById(layerName);
	obj.style.visibility="visible";
}

//Hide layer//
function hideLayer(layerName){
	obj = document.getElementById(layerName);
	obj.style.visibility="hidden";
}

function popUp (url, width, height, name) {
    widthHeight = "width=" + width + ",height=" + height;
    winFeatures = "width=" + width + ",height=" + height + ",menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,location=no"
    spawn = window.open(url,name,winFeatures);
}

function popUp_noscroll (url, width, height, name) {
    widthHeight = "width=" + width + ",height=" + height;
    winFeatures = "width=" + width + ",height=" + height + ",menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no,location=no"
    spawn = window.open(url,name,winFeatures);
}


	

