var region="";
if(document.location.href.indexOf("wow-europe")!=-1 || document.location.href.indexOf("10.50.4.13")!=-1 || document.location.href.indexOf("80.239.186.40")!=-1 || document.location.href.indexOf("eu.blizzard.net")!=-1 || document.location.href.indexOf("preprod")!=-1) //   80.239.186.40 = armory EU hidden prod. & eu.blizzard.net for locale machines
    region="EU"
else if(document.location.href.indexOf("armory.worldofwarcraft.co.kr")!=-1){//change by akim (add KR)
    region="KR";
}
else
    region="US"

	var IS_ENABLED_XSLT=is_moz;


function getCopyUrl() {	
	if (is_ie && IS_ENABLED_XSLT) {
		theUrl = "http://";
		theUrl += window.location.hostname;
		theUrl += "/"+ window.historyStorage.getCurrentPage();
		theUrl = theUrl.replace("?#", "");
	} else {
		theUrl = location.href;
		theUrl = theUrl.replace("#", "");
	}
	document.formCopyUrl.inputCopyUrl.value = theUrl;
}

    function toggleCopyUrl() {
        if (document.getElementById("divCopyUrl").style.display == "block")
            document.getElementById("divCopyUrl").style.display = "none";
        else
            document.getElementById("divCopyUrl").style.display = "block";      
        getCopyUrl();
    }
    
function setDualTooltipCookie() {
    if (document.getElementById('checkboxDualTooltip').checked)
        setcookie("armory.cookieDualTooltip", 1);
    else
        setcookie("armory.cookieDualTooltip", 0);
}

function setCharCookie(charName, realm, guild, guildUrl, faction, race, clazz, team2, team3, team5) {
    setcookie("armory.cookieCharProfileUrl", "cmpn="+charName+"&cmpr="+realm);
    setcookie("armory.cookieCharProfileName", charName);
    setcookie("armory.cookieCharProfileRealm", realm);
    setcookie("armory.cookieCharProfileGuildName", guild);
    setcookie("armory.cookieCharProfileGuildUrl", guildUrl);    
    setcookie("armory.cookieCharProfileFaction", faction);
    setcookie("armory.cookieCharProfileRace", race);
    setcookie("armory.cookieCharProfileClass", clazz);
    setcookie("armory.cookieCharProfileTeam2", team2);
    setcookie("armory.cookieCharProfileTeam3", team3);
    setcookie("armory.cookieCharProfileTeam5", team5);
    showPin();
    document.getElementById('checkboxDualTooltip').checked = 1;
    setDualTooltipCookie();
}

function showPin() {
    document.getElementById('showHidePin').style.display = "block"; 
    
    var charName = getcookie2("armory.cookieCharProfileName")
    document.getElementById('replacePinCharName1').innerHTML = charName;
    document.getElementById('replacePinCharName2').innerHTML = "<a href = \"javascript: ajaxLink(&quot;character-sheet.xml?r="+ encodeURI(getcookie2("armory.cookieCharProfileRealm")) +"&n="+ getcookie2("armory.cookieCharProfileName") +"&quot;)\">"+ charName + "</a>";   

    var guildName = getcookie2("armory.cookieCharProfileGuildName");
    if (guildName != "" && guildName != ";") {
        document.getElementById('replacePinGuildName1').innerHTML = "&lt; "+ guildName +" &gt;";
        document.getElementById('replacePinGuildName2').innerHTML = "<a href = \"javascript: ajaxLink(&quot;guild-info.xml?"+ getcookie2("armory.cookieCharProfileGuildUrl") +"&quot;)\">&lt; "+ guildName +" &gt;</a>";    
    } else {
        var theRace = getcookie2("armory.cookieCharProfileRace");
        var theClass = getcookie2("armory.cookieCharProfileClass");      
        document.getElementById('replacePinGuildName1').innerHTML = theRace + " " + theClass;
        document.getElementById('replacePinGuildName2').innerHTML = theRace + " " + theClass;
    }

    if (getcookie2("armory.cookieCharProfileFaction") == "1")
        document.getElementById('changeClassFaction').className = "hord";
    else
        document.getElementById('changeClassFaction').className = "alli";

    var team2Url = getcookie2("armory.cookieCharProfileTeam2");
    if (team2Url != "" && team2Url != ";")
        document.getElementById('replaceTeam2').innerHTML = "<a class='at2' href=\"javascript: ajaxLink(&quot;team-info.xml?"+ team2Url +"&quot;);\"></a>";
    else
        document.getElementById('replaceTeam2').innerHTML = "<span class='at20'></span>";
    
    var team3Url = getcookie2("armory.cookieCharProfileTeam3");
    if (team3Url != "" && team3Url != ";")
        document.getElementById('replaceTeam3').innerHTML = "<a class='at3' href=\"javascript: ajaxLink(&quot;team-info.xml?"+ team3Url +"&quot;);\"></a>";
    else
        document.getElementById('replaceTeam3').innerHTML = "<span class='at30'></span>";

    var team5Url = getcookie2("armory.cookieCharProfileTeam5"); 
    if (team5Url != "" && team5Url != ";")
        document.getElementById('replaceTeam5').innerHTML = "<a class='at5' href=\"javascript: ajaxLink(&quot;team-info.xml?"+ team5Url +"&quot;);\"></a>";
    else
        document.getElementById('replaceTeam5').innerHTML = "<span class='at50'></span>";   

	document.getElementById('idPinNavArrow').className = "pdown";

}

function hidePin() {

	document.getElementById('pinprofile').style.visibility = 'hidden';	
	document.getElementById('idPinNavArrow').className = "pdown0";
    document.getElementById('replaceTeam2').innerHTML = "<span class='at20'></span>";	
    document.getElementById('replaceTeam3').innerHTML = "<span class='at30'></span>";	
    document.getElementById('replaceTeam5').innerHTML = "<span class='at50'></span>";		
    document.getElementById('replacePinCharName1').innerHTML = textNone;
    document.getElementById('replacePinCharName2').innerHTML = "<a>"+ textNone +"</a>";   	
	
	document.getElementById('replacePinGuildName1').innerHTML = "&lt; "+ textLearnMore +" &gt;";
	document.getElementById('replacePinGuildName2').innerHTML = "<a href = '/updates.xml#anchorpinprofile' target = '_blank' onMouseOver = \"javascript: showTip(textLearnMoreHover);\" onMouseOut = 'hideTip();'>&lt; "+ textLearnMore +" &gt;</a>";

    document.getElementById('changeClassFaction').className = "non";



    //document.getElementById('showHidePin').style.display = "none";      
}

function hoverPinOption() {
	  if (getcookie2("armory.cookieCharProfileUrl") !=0) {
		  document.getElementById('pinprofile').style.visibility = 'visible';
	  }
}

function unsetCharCookie() {
    setcookie("armory.cookieCharProfileUrl", 0);
    setcookie("armory.cookieDualTooltip", 0);	
    hidePin();
}

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 dropdownMenuToggle(whichOne){
    theStyle = document.getElementById(whichOne).style;

    if (theStyle.display == "none") {
        theStyle.display = "block"; 
    } else
        theStyle.display = "none";
}


//flash detection
var MM_contentVersion = 8;
var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
if ( plugin ) {
        var words = navigator.plugins["Shockwave Flash"].description.split(" ");
        for (var i = 0; i < words.length; ++i)
        {
        if (isNaN(parseInt(words[i])))
        continue;
        var MM_PluginVersion = words[i]; 
        }
    var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;
}
else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
   && (navigator.appVersion.indexOf("Win") != -1)) {
    document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n'); //FS hide this from IE4.5 Mac by splitting the tag
    document.write('on error resume next \n');
    document.write('MM_FlashCanPlay = ( IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & MM_contentVersion)))\n');
    document.write('</SCR' + 'IPT\> \n');
}


function showNoflashMessage(){
    document.getElementById("noflash-message").style.display="block";
}
    
var flashString;
var tempObj;
var flashCount=1;
//printFlash uses innerHTML to render flash objs to get around the IE flash rendering issue
function printFlash(id, src, wmode, menu, bgcolor, width, height, quality, base, flashvars, noflash){
    
    if(MM_FlashCanPlay){
        
        flashString = '<object id= "' + id + 'Flash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + width + '" height="' + height + '"><param name="movie" value="' + src + '"></param><param name="quality" value="' + quality + '"></param>';
        if(base){
        flashString+='<param name="base" value="' + base + '"/>';
        }
        
        flashString+='<param name="flashvars" value="' + flashvars + '" ></param><param name="bgcolor" value="' + bgcolor + '" ></param><param name="menu" value="' + menu + '" ></param><param name="wmode" value="' + wmode + '" ></param><param name="salign" value="tl" ></param><embed name= "' + id + 'Flash" src="' + src + '" wmode="' + wmode + '" menu="' + menu + '" bgcolor="' + bgcolor + '" width="' + width + '" height="' + height + '" quality="' + quality + '" pluginspage="http://www.macromedia.com/go/getflas/new-hplayer" type="application/x-shockwave-flash" salign="tl" base="' + base + '" flashvars="' + flashvars + '" /></object>';
        
    }else{
    
        flashString=noflash;

    }
    
    if(id=="loader" && !is_moz)
        flashString=noflash;
    
    document.getElementById(id).innerHTML = flashString;
    document.getElementById(id).style.display="block";
        
}



//Begin Martin's Tooltip Code
mouseY = false;
windowWidth = false;
is_safari = ((navigator.userAgent.indexOf("Safari")!=-1))?true:false;
isShowing = false;
visibilityOverride = false;
var defaultWidth=300;

function showTip(toolTipContent,defaultWidthOverride)
{
	windowHeight = document.documentElement.clientHeight;
	windowWidth = document.documentElement.clientWidth;
	emergencyPurge();

	isShowing = true;
	document.getElementById("tooltipcontainer").style.visibility = "visible";
  document.getElementById("toolBox").innerHTML = toolTipContent;
  document.getElementById("tooltipcontainer").style.display = "block";
	if(document.getElementById("tool1container").offsetWidth > 299)
	{
		document.getElementById("tool1container").style.width="300px";
		document.getElementById("tool1container").style.display="block";
	}
	if(_SARISSA_IS_SAFARI || window.opera) document.getElementById("tooltipcontainer").style.width = "300px";
	/* initial positioning */
	adjustTooltipPosition();
	/* end initial positioning */
	if (!visibilityOverride) document.getElementById("tooltipcontainer").style.visibility = "visible";
}

function adjustTooltipPosition()
{
	if(!mouseY) return false;
	else
	{
		var ttipOvershoot = (!is_safari) ? document.getElementById("tooltipcontainer").offsetHeight + mouseY + 10 : document.getElementById("tooltipcontainer").offsetHeight + mouseY + 10 - window.pageYOffset;
		var ttipSideOvershoot = document.getElementById("tooltipcontainer").offsetWidth + mouseX + 10;
		if(ttipOvershoot > windowHeight)
		{
			document.getElementById("tooltipcontainer").style.top = (!is_safari) ? windowHeight - document.getElementById("tooltipcontainer").offsetHeight + document.documentElement.scrollTop + 2 + "px" : windowHeight - document.getElementById("tooltipcontainer").offsetHeight + window.pageYOffset + "px";
		}
		else
		{
			document.getElementById("tooltipcontainer").style.top = (!is_safari) ? mouseY+10+document.documentElement.scrollTop+"px" : mouseY+5+"px";
		}
		if(ttipSideOvershoot > windowWidth)
		{
			document.getElementById("tooltipcontainer").style.left = windowWidth - document.getElementById("tooltipcontainer").offsetWidth+"px";
		}
		else
		{
			document.getElementById("tooltipcontainer").style.left = mouseX+10+"px";
		}
	}
}

function showTipTwo(toolTipContent)
{
    document.getElementById("toolBox_two").innerHTML = toolTipContent;
    document.getElementById("tool2container").style.display = "block";
		if(document.getElementById("tool2container").offsetWidth > 299)
		{
			document.getElementById("tool2container").style.width="300px";
		}
}

function showTipThree(toolTipContent)
{
    document.getElementById("toolBox_three").innerHTML = toolTipContent;
    document.getElementById("tool3container").style.display = "block";
		if(document.getElementById("tool3container").offsetWidth > 299)
		{
			document.getElementById("tool3container").style.width="300px";
		}
}
function emergencyPurge()
{
	document.getElementById("tooltipcontainer").style.display = "none";
	document.getElementById("tooltipcontainer").style.visibility = "hidden";
	document.getElementById("tooltipcontainer").style.width = "auto";
	document.getElementById("tool1container").style.diplay = "block";
	document.getElementById("tool1container").style.width = "auto";
	document.getElementById("tool2container").style.display = "none";
	document.getElementById("tool2container").style.width = "auto";
	document.getElementById("tool3container").style.display = "none";
	document.getElementById("tool3container").style.width = "auto";

	isShowing = false;
}

function hideTip()
{
	if(!windowWidth || ((mouseX-15) > (windowWidth - document.getElementById("tooltipcontainer").offsetWidth) && (mouseY-15) > (windowHeight - document.getElementById("tooltipcontainer").offsetHeight)))
	{
		return false;
	}
	else
	{
		document.getElementById("tooltipcontainer").style.display = "none";
		document.getElementById("tooltipcontainer").style.visibility = "hidden";
		document.getElementById("tooltipcontainer").style.width = "auto";
		document.getElementById("tool1container").style.diplay = "block";
		document.getElementById("tool1container").style.width = "auto";
		document.getElementById("tool2container").style.display = "none";
		document.getElementById("tool2container").style.width = "auto";
		document.getElementById("tool3container").style.display = "none";
		document.getElementById("tool3container").style.width = "auto";
	
		isShowing = false;
	}
}

function tipPosition(callingEvent)
{
	if (!callingEvent) callingEvent = window.event;
  mouseX = callingEvent.clientX;
  mouseY = callingEvent.clientY-1;
	if (isShowing)
	{
//      document.getElementById("tooltipcontainer").style.left = mouseX+10+"px";
		var ttipSideOvershoot = document.getElementById("tooltipcontainer").offsetWidth + mouseX + 10;
		var ttipOvershoot = (!is_safari) ? document.getElementById("tooltipcontainer").offsetHeight + mouseY + 10 : document.getElementById("tooltipcontainer").offsetHeight + mouseY + 10 - window.pageYOffset;
		if(ttipOvershoot > windowHeight)
		{
				document.getElementById("tooltipcontainer").style.top = (!is_safari) ? windowHeight - document.getElementById("tooltipcontainer").offsetHeight + document.documentElement.scrollTop + 2 + "px" : windowHeight - document.getElementById("tooltipcontainer").offsetHeight + window.pageYOffset + "px";
		}
		else
		{
				document.getElementById("tooltipcontainer").style.top = (!is_safari) ? mouseY+10+document.documentElement.scrollTop+"px" : mouseY+5+"px";
		}
		if(ttipSideOvershoot > windowWidth)
		{
				document.getElementById("tooltipcontainer").style.left = windowWidth - document.getElementById("tooltipcontainer").offsetWidth+"px";
//          document.getElementById("tooltipcontainer").style.right = "0px";
		}
		else
		{
				document.getElementById("tooltipcontainer").style.left = mouseX+10+"px";
		}
	}
}
document.onmousemove = tipPosition;

//End Martin's Tooltip Code


var resultsSideState="middle";

function resultsSideRight(){

    if(resultsSideState=="middle"){
        document.getElementById("results-side-switch").className = "results-side-collapsed";
        //document.getElementById("teamIconBox-results").style.display = "none";
        
        resultsSideState="right";
    }

}

function resultsSideLeft(redirectUrl){

    if(resultsSideState=="right"){
        document.getElementById("results-side-switch").className = "results-side-expanded";
        resultsSideState="middle";
    } else {
        if (redirectUrl) {
            ajaxLink(redirectUrl);
        }
    }
}



function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  } else {
    return document[movieName]
  }
}

function popIconLarge(movieName,mcName) {

    if(MM_FlashCanPlay){
        try {
            if(is_ie)
                try {thisMovie(movieName).TGotoFrame(mcName,1);}catch(e){throw e;}
            
            else
                if(!is_opera && thisMovie(movieName) && thisMovie(movieName).TGotoFrame) //exclude opera
                    thisMovie(movieName).TGotoFrame(mcName,1);
        }catch(e){
            throw e;
        }
    }
  
}

function popIconSmall(movieName,mcName) {
    if(MM_FlashCanPlay){
        try {
            if(is_ie)
                try {thisMovie(movieName).TGotoFrame(mcName,2);}catch(e){throw e;}
            else
                if(!is_opera && thisMovie(movieName) && thisMovie(movieName).TGotoFrame) //exclude opera
                    thisMovie(movieName).TGotoFrame(mcName,2);
        }catch(e){
            throw e;
        }
    }
}

var currentFaq=1;

function faqSwitch(faqId){

    classSwitch('faqlink'+currentFaq,'faq-off');
    classSwitch('faqlink'+faqId,'faq-over');
    currentFaq=faqId;
    document.getElementById('faq-container').innerHTML=document.getElementById("faq"+faqId).innerHTML;
}


    
function classSwitch(obj,className){

    document.getElementById(obj).className = className;

}

var prevRightSideImage;
var rightSideImage;
var rightSideImageReady=0;

function changeRightSideImage(theImage){
    if(rightSideImageReady){
        if(rightSideImage!=prevRightSideImage){
            document.getElementById('imageLeft').className = theImage+'-image';
            document.getElementById('imageRight').className = 'rcol section-'+theImage;
        }
        prevRightSideImage=rightSideImage;
    }
}



var pageChangerXsltProcessor;

function initXsltProcessor(xsltProc, xslUrl) {
    var xslDoc = Sarissa.getDomDocument();
    xslDoc.async = true;
    if(is_ie)
        xslDoc.async = false;
    xslDoc.load(xslUrl);
    xsltProc.importStylesheet(xslDoc);
}


function xmlDataLoadSarissa(xmlSource, xslSource, container){

    pageChangerXsltProcessor = new XSLTProcessor();
    initXsltProcessor(pageChangerXsltProcessor, xslSource);
    
    //code added to apend the language of the xml request.  Use to fight rouge caching.
    if(xmlSource.indexOf('?')==-1)
        xmlSource+='?';
    
    xmlSource+="&lang="+getcookie2("cookieLangId");
    
    fetchXmlData(xmlSource, container, pageChangerXsltProcessor);
    //move the search box if it's the index
    var urlSplit = xmlSource.split('?');
    var xmlName = urlSplit[0].split('.')[0];    
    if(xmlName.indexOf("index")>-1 && !document.location.hash)
        document.getElementById('indexChange1').className="home";
    else
        document.getElementById('indexChange1').className="other";

}

var ajaxOverride=false;


	
      function initialize() {

        // initialize the DHTML History

        
        var urlObj=parseXMLurl(document.location.href);
        if(!pathnameParse || pathnameParse=="?"){
            // framework
            dhtmlHistory.initialize();
            
            // subscribe to DHTML history change
            // events
            dhtmlHistory.addListener(historyChange);
                
            // if this is the first time we have
            // loaded the page...
 
            
            if(!dhtmlHistory.isFirstLoad()){
                //do nothing
            }else{ 
              // start adding history


                var initKey = document.location.href;
                if(initKey.lastIndexOf('/')!=initKey.length-1 && initKey.lastIndexOf('?')!=initKey.length-1){
                
                    initKey = initKey.substring(initKey.lastIndexOf('/'),initKey.length)
                    initKey = initKey.split('?')[0];
                
                }else
                    initKey = "index.xml";
                
				addHistory(initKey)
             
            }
        
        }else{

            ajaxOverride=true;
            window.historyStorage.setCurrentPage(urlObj.escapeUrl);
        }
        
      }
     
         
      /** Our callback to receive history change
          events. */
    var historyChangeBool=0;

    function historyChange(newLocation, historyData) {

        if((!historyChangeBool && window.historyStorage.getCurrentPage() == parseXMLurl(document.location.href).escapeUrl) || (!document.location.hash && historyChangeBool==1) || (window.historyStorage.getCurrentPage()=="index.xml")){
            //DO NOTHING
        }else{
            
            if(!newLocation)
                newLocation=window.historyStorage.getCurrentPage();
            
            var urlObj=parseXMLurl(newLocation);
            window.historyStorage.setCurrentPage(urlObj.url);
            xmlDataLoadSarissa(newLocation,urlObj.xsl,'dataElement')
            
        }
    }


function parseXMLurl(xmlUrl, xslUrl, escapeBool){

    if(xmlUrl.lastIndexOf('/')>=0)
        xmlUrl=xmlUrl.substring(xmlUrl.lastIndexOf('/')+1,xmlUrl.length)
    var urlSplit = xmlUrl.split('?');
    xmlUrl = urlSplit[0];
    xml=xmlUrl;

    if (xslUrl) {
        xsl = xslUrl;
    } else {
        xsl = 'layout/' + xml.split('.')[0] + '-ajax.xsl';
    }
    query = urlSplit[1];
    
    var pageObject = new Object();
    pageObject.xml = xml;
    pageObject.xsl = xsl;
    pageObject.query=query;
    pageObject.url = xml;
    if(query)pageObject.url+="?"+query;
    
    pageObject.escapeUrl=xml;
    pageObject.escapeQuery="";
    
    
    if (query){
        
            var queryConstructor = new PageQuery("?"+query);
            var queryParams = queryConstructor.getParameters();
        
            for(i=0; i<queryParams.length; i++){
                


				if(escapeBool || is_ie)
					pageObject.escapeQuery +=  queryParams[i] + "=" + encodeURI(Utf8.decode(queryConstructor.getValue(queryParams[i])));
				else{
					pageObject.escapeQuery +=  queryParams[i] + "=" + encodeURI(queryConstructor.getValue(queryParams[i]));//alert(pageObject.escapeQuery);
				}


				
    			if(region == 'KR'){
					var krValue = queryConstructor.getValue(queryParams[i]);

					if(escapeBool || is_ie)
						pageObject.escapeQuery = pageObject.escapeQuery.replace(queryParams[i] + "=" + escape(krValue), queryParams[i] + "=" + escape(krValue));
					else
						pageObject.escapeQuery = pageObject.escapeQuery.replace(queryParams[i] + "=" + escape(Utf8.encode(krValue)), queryParams[i] + "=" + encodeURI(krValue));
				}


                if(i!=queryParams.length-1)
                    pageObject.escapeQuery += "&";
        
            }
			
			//alert(pageObject.escapeQuery)
			
			pageObject.escapeQuery = pageObject.escapeQuery.replace("'","%27");//escape single quote
			
			pageObject.escapeQuery = pageObject.escapeQuery.replace("%25","%");
			//alert(pageObject.escapeQuery)
            pageObject.escapeQuery = pageObject.escapeQuery.replace("%20","+");

        	pageObject.escapeUrl += "?" + pageObject.escapeQuery;
    }
    return pageObject;  

}

//initialize current page cookie and call DHTML init on page load
if(IS_ENABLED_XSLT){
    
	//if(!hashParse){
		//var urlObj=parseXMLurl(document.location.href);
		//setcookie("currentPage",urlObj.escapeUrl,"session");
	//}
	addEvent(window, 'load', initialize);
}


//function which takes xml, xsl, and query params and transforms them into a format the dhtml history library can understand    
function addHistory(url){
    
    dhtmlHistory.add(url,"a");
    window.historyStorage.setCurrentPage(url);
}

function ajaxLink(fichier)
{
     if(window.XMLHttpRequest) // FIREFOX
          xhr_object = new XMLHttpRequest();
     else if(window.ActiveXObject) // IE
          xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
     else
          return(false);
     xhr_object.open("GET", fichier, false);
     xhr_object.send(null);
     if(xhr_object.readyState == 4) return(xhr_object.responseText);
     else return(false);
}

/*
function ajaxLink(xmlUrl, xslUrl, appendRandomNumber){
    
    var urlObj=parseXMLurl(xmlUrl, xslUrl);
    
    if (IS_ENABLED_XSLT && !ajaxOverride){
		addHistory(urlObj.escapeUrl);
		document.getElementById(document.formSearch.name + '_errorSearchLength').style.visibility = "hidden"; //clear the error box if it is visible
		showLoader();
		if (appendRandomNumber) {
			xmlDataLoadSarissa(urlObj.escapeUrl + "&amp;rid=" + Math.floor(Math.random()*2147483647), urlObj.xsl, 'dataElement');
		} else {
			xmlDataLoadSarissa(urlObj.escapeUrl, urlObj.xsl, 'dataElement');
		}
	} else if (IS_ENABLED_XSLT && ajaxOverride) {
	
		
		var hashControl="#"
		if(is_ie)
			hashControl="?"+hashControl;
	
		window.location.href="/"+hashControl+urlObj.escapeUrl;
		showLoader();
	
	}else{

		window.location.href=urlObj.escapeUrl;
		showLoader();

    }
    
}
*/
var ajaxXmlUrl;
var ajaxDataElementName;
var ajaxXsltProcessor;

function fetchXmlData(xmlUrl, dataElementName, xsltProcessor) {
    historyChangeBool=1;
    ajaxXmlUrl = xmlUrl;
    ajaxDataElementName = dataElementName;
    ajaxXsltProcessor = xsltProcessor;
    showLoader();
    window.setTimeout("fetchXmlData2()",50);
}

function fetchXmlData2() {
    if (!IS_ENABLED_XSLT) {
        //alert(ajaxXmlUrl);
        window.location.replace(ajaxXmlUrl);
		showLoader();
        return;
    }

    updateDataContent(ajaxXmlUrl, document.getElementById(ajaxDataElementName), ajaxXsltProcessor); 
}

function ieFix(){

    var tempDiv = document.createElement("div");
    tempDiv.style.position="absolute";
    tempDiv.style.top="-100px";
    document.body.appendChild(tempDiv);

}

var head;
var numHeadNodes=0;

function initHead(){

    head = document.getElementsByTagName("head");
    numHeadNodes = head[0].childNodes.length;

}
addEvent(window, 'load', initHead);

var jsLoaded=true;
var jsLoadCount=1;
var tempString;
var jsArrayLength;

function checkJSLoad(){

    while(jsLoadCount<jsArrayLength && jsLoaded){
        
        
        scriptString=tempArray[jsLoadCount].split('</SCRIPT>')[0];
        theSrc="";
        theScript="";
        srcStartLoc=scriptString.substring(0,6).indexOf(" src=");//look for a src attribute in the script tag within the first 7 characters
        scriptTagEndLoc=scriptString.indexOf(" type=text/javascript>");

        if(srcStartLoc!=-1)
            theSrc=scriptString.substring(srcStartLoc+6,scriptTagEndLoc-1)
    
        theScript=scriptString.substring(scriptTagEndLoc+22,scriptString.length);
        
        script = document.createElement("script");
        head[0].appendChild(script);
        
        if(theSrc)jsLoaded=false;
        
        script.type = "text/javascript";
        if(theSrc)script.src = theSrc;
        if(theScript)script.text = theScript;
        
        jsLoadCount++;
        
        if(theSrc)
            return false;
    
    }
                    
    if(jsLoadCount>=jsArrayLength){
        jsLoaded=true;
        jsLoadCount=1;
        hideLoader();
        rePosition(); //reposition menu after contents change           
        clearInterval(checkLoadInterval)
    }

}

var checkLoadInterval;


function updateDataContent(sFromUrl, oTargetElement, xsltproc) {
    //alert(sFromUrl);
    try {
        if(!loadingObj || loadingObj.style.display=="none"){
            showLoader();
        }
        oTargetElement.style.cursor = "wait";
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open("GET", sFromUrl, true);
        function sarissa_dhtml_loadHandler() {
            if (xmlhttp.readyState == 4) {

                
                
                oTargetElement.style.cursor = "auto";

                //alert(xmlhttp.responseText);

                if (xmlhttp.responseXML != null) {
                    var procer = xsltproc;

                    if(is_ie){
                        
                        //purge any scripts that have been loaded into Head via ajax
                        while(numHeadNodes!=head[0].childNodes.length)
                            head[0].removeChild(head[0].lastChild)
                    }                   
                    
                    var newFrag = procer.transformToFragment(xmlhttp.responseXML,window.document);
                    oTargetElement.innerHTML="";
                    oTargetElement.appendChild(newFrag);

                    //alert(oTargetElement.innerHTML)

                    if(is_ie){
                        
                        
                        //load any new embedded stylesheets into head
                        embeddedStyles=oTargetElement.getElementsByTagName("link");
                        for(count=0;count<embeddedStyles.length;count++){
                                embeddedStyle = document.createElement("link");
                                head[0].appendChild(embeddedStyle);
                                embeddedStyle.type = embeddedStyles[count].type
                                embeddedStyle.rel = embeddedStyles[count].rel;
                                embeddedStyle.href = embeddedStyles[count].href;
                                embeddedStyle.media = embeddedStyles[count].media;
                        }
                        
                        tempString=document.getElementById("dataElement").innerHTML;
                        tempArray=tempString.split('<SCRIPT');
                        jsArrayLength=tempArray.length;
                                        
                        window.setTimeout("ieFix()",100)
                        checkLoadInterval=window.setInterval("checkJSLoad()",100)
                    } else {
                    
                        hideLoader();
                        rePosition(); //reposition menu after contents change
                    
                    }
                    

                    //endTime=new Date().getTime();
                    //alert('Elapsed time: '+((endTime-startTime)/1000)+' seconds.');
                } else {
                    //xml load failed. May want to add code here to remove latest history change.
                    hideLoader();
                    //alert(sFromUrl)
                    //alert("xmlhttp.responseXML = null");
                }
            }
        }
        xmlhttp.onreadystatechange = sarissa_dhtml_loadHandler;
        xmlhttp.send(null);
        oTargetElement.style.cursor = "auto";
    } catch(e) {
        oTargetElement.style.cursor = "auto";
        throw e;
    }
}



var loadingObj;
function showLoader() {
    loadingObj = document.getElementById("loadingDivInner");
    loadingObj.style.top=10+document.documentElement.scrollTop+"px";
    loadingObj = document.getElementById("loadingDiv");
    loadingObj.style.height=document.documentElement.scrollHeight+"px";
    loadingObj.style.visibility="visible";
}

function hideLoader(){
    loadingObj.style.visibility="hidden";
    loadingObj.style.height="0px";
    var dataElementObj = document.getElementById("dataElement");
  
}


function arenaLadderLink(battlegroup, teamSize) {
    var URL_XML = "arena-ladder.xml";
    var URL_BATTLEGROUP_SELECT = "battlegroups.xml";
    var XSL_URL_BATTLEGROUP_SELECT = "layout/battlegroups-ajax.xsl";
    var URL_TEAMSIZE_SELECT = "select-team-type.xml";

    var selectedBG;
    if (battlegroup) {
        selectedBG = battlegroup;
        setcookie("armory.cookieBG", battlegroup);
    } else {
        selectedBG = getcookie2("armory.cookieBG");
    }

    var selectedTS;
    if (teamSize) {
        selectedTS = teamSize;
        setcookie("armory.cookieTS", teamSize);
    } else {
        selectedTS = getcookie2("armory.cookieTS");
    }

    if (!selectedBG) {
        ajaxLink(URL_BATTLEGROUP_SELECT, XSL_URL_BATTLEGROUP_SELECT);
        return;
    }
    if (!selectedTS) {
        ajaxLink(URL_TEAMSIZE_SELECT);
        return;
    }

    var arenaLadderUrl = URL_XML + "?b=" + escape(selectedBG) + "&ts=" + selectedTS;

    if(region == "KR"){//change by akim (encoding UTF-8)
		if(is_ie){
			selectedBG=Utf8.encode("" + selectedBG)
		}

        arenaLadderUrl = URL_XML + "?b=" + selectedBG + "&ts=" + selectedTS;
    }
    ajaxLink(arenaLadderUrl);
}

//Icon validity testing

function IsImageOk(img) {
    // During the onload event, IE correctly identifies any images that
    // weren't downloaded as not complete. Others should too. Gecko-based
    // browsers act like NS4 in that they report this incorrectly.


    if(!is_safari){
        if (!img || !img.complete) {
            return false;
        }
    
        // However, they do have two very useful properties: naturalWidth and
        // naturalHeight. These give the true size of the image. If it failed
        // to load, either of these should be zero.
        if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
            return false;
        }
    }


    // No other way of checking: assume it's ok.
    return true;
}
  
function checkImage(thisImage,iconSize){
  thisImage=document.getElementById(thisImage)
  fileType=".jpg";
  if(iconSize=="21x21" || iconSize=="43x43")
    fileType=".png";

  if(!IsImageOk(thisImage))
    thisImage.src="images/icons/"+iconSize+"/inv_misc_questionmark"+fileType;
}

function replaceLink(siteUrl){
    var replaceUrl="";

    //if(IS_ENABLED_XSLT)
       // replaceUrl=siteUrl+"/"+window.historyStorage.getCurrentPage();
    //else
      //  replaceUrl=document.location.href;
        
   // document.getElementById("reportLink").href=document.getElementById("reportLink").href.replace("REPLACEURL",replaceUrl.replace('&','%26')).replace("REPLACEBROWSER",agt+" - "+appVer)
}

function guildLink() {
   ajaxLink(guildUrl);
}

function forumLink(forumName, lang){

    var forumsUrl="";
    if(region=="EU")
        forumsUrl="http://forums.wow-europe.com/";
    else
        forumsUrl="http://forums.worldofwarcraft.com/";
        
    window.open(forumsUrl+"board.html?forumName="+forumName)

}

function styleLoader(cssHref){

        newStyle = document.createElement("link");
        newStyle.type = "text/css";
        newStyle.rel = "stylesheet";
        newStyle.href = cssHref;
        newStyle.media = "screen, projection";
		document.getElementsByTagName("head")[0].appendChild(newStyle);
}



function setColSelected(whichCol) {
    globalColSelected[whichCol] = ' class = "rating"';
}

function clearColSelected() {
  for (var i = 0; i <= arrayCol.length; i++) {
    globalColSelected[i] = "";
  }
}


var elemRST = document.getElementById('replaceSearchTable');
var elemRPT = document.getElementById('replacePagesTop');


function setResultsPage(whichPage) {
     flashVarsString="initScale=35&#38;overScale=100&#38;overModifierX=0&#38;overModifierY=0&#38;startPointX=43&#38;";	  
  if ((typeof eval(whichPage)) != 'number' || whichPage > globalPages || whichPage <= 0)
    return false;

  globalWhichPage = whichPage;

  whichCol = globalSort[0];
  upDown = globalSort[1];

  replaceSearchTop = printSearchCol(arrayCol, whichCol, upDown);

  replaceSearchMid = "";
  theStart = (whichPage - 1) * globalResultsPerPage;

  for (var x = 0; x < globalResultsPerPage && theArray[theStart]; x++) {
	replaceSearchMid += printMid(theArray[theStart], x);
	theStart++;
  }

  elemRST.innerHTML = replaceSearchTop + replaceSearchMid +replaceStringGuildBot;
  
  var stringPrintPage = printPage(whichPage);
  
  elemRPT.innerHTML = stringPrintPage;
  if (window.elemRPB)
	  elemRPB.innerHTML = stringPrintPage;
  setcookie("cookieLeftPage", whichPage);
  setcookie("cookieRightPage", whichPage);
  
  if (window.isArenaTeams) {
    var theHeight = theStart%20;
    if (theHeight == 0)
  	  theHeight = 20;	  
	var heightCalc=(theHeight*28)+10;
	if(heightCalc < 100)heightCalc=100;
	printFlash('teamIconBox', 'images/icons/team/pvpemblems.swf', 'transparent', '', '#000000', '76', heightCalc, 'high', '', flashVarsString + '&#38;totalIcons='+theHeight, '');  
  }
  
}

function value(a,b) {
if (is_moz) {
	a = a[globalSort[0]] + "zz" + a[0][0];
	b = b[globalSort[0]] + "zz" + b[0][0];
} else {
	a = a[globalSort[0]];
	b = b[globalSort[0]];	
}
return a == b ? 0 : (a < b ? -1 : 1)
}

function valueAs(a,b) {
if (is_moz) {
a = a[globalSort[0]] + "zz" + a[0][0];
b = b[globalSort[0]] + "zz" + b[0][0];
} else {
a = a[globalSort[0]];
b = b[globalSort[0]];	
}
return a == b ? 0 : (a < b ? 1 : -1)
}

function sortNumber(a, b) {
	var theValue = b[globalSort[0]][0] - a[globalSort[0]][0];
	if (theValue)
		return b[globalSort[0]][0] - a[globalSort[0]][0];
	else {
		a = a[0][0];
		b = b[0][0];
		return a == b ? 0 : (a < b ? -1 : 1)		
	}
}

function sortNumberAs(a, b) {


	var theValue = b[globalSort[0]][0] - a[globalSort[0]][0];
	if (theValue)
		return a[globalSort[0]][0] - b[globalSort[0]][0];
	else {
		a = a[0][0];
		b = b[0][0];
		return a == b ? 0 : (a < b ? 1 : -1);
	}

}

function sortSearch(whichElement, useCookie) {

  var lengthArrayCol = arrayCol.length;
  if (whichElement > lengthArrayCol)
	  whichElement = lengthArrayCol;
	  
  clearColSelected();
  setColSelected(whichElement);
  
  if (theArray[0] && (typeof theArray[0][whichElement][0]) == 'string') {
    sortAs = valueAs;
	sortDe = value;
  } else {
    sortAs = sortNumberAs;
	sortDe = sortNumber;
  }

  if (useCookie) {
	if (getcookie2("cookieLeftSortUD") == 'u')
	  globalSort[1] = 'd';
	else
	  globalSort[1] = 'u';	
  }

  if (whichElement == globalSort[0] && globalSort[1] == 'd') {
    theArray.sort(eval(sortAs));
	globalSort[1] = 'u';
  } else {
    globalSort[0] = whichElement;  
    theArray.sort(eval(sortDe));
	globalSort[1] = 'd';	
  }

  setResultsPage(globalWhichPage);
  if (whichElement == lengthArrayCol)
  	whichElement = 0 - lengthArrayCol;
	
  setcookie("cookieLeftSort", whichElement);
  setcookie("cookieLeftSortUD", globalSort[1]);
}

function printSearchCol(inputArray, whichCol, upDown) {

	var truncateVar = 0;

	if (inputArray.length > 6);
		truncateVar = 6;

	var theString = '<table class="data-table"><tr class="masthead"><td><div><p><img src="images/pixel.gif" width="1" height="1" /></p></div></td>';
	
	if (window.isItems)
		theString += '<td width = "1"><div><p><img src="images/pixel.gif" width="1" height="1" /></p></div></td>';
	
	if (upDown == 'u')
	  theArrow = "up";
	else
	  theArrow = "down";	
	
	for (var i = 0; i < inputArray.length; i++) {
	  var theBool;
	  if (window.isItems && i > 3 && i != inputArray.length -1)
	  	theBool = 1;
	  else
	    theBool = 0;
	  theString += '<td';
	  if (window.isItems && i == 0)
	  	theString += ' width = "1%"';
	  if (inputArray[i][3] && !window.isItems)
	    theString += ' width = "'+ inputArray[i][3] +'"';
	  if (inputArray[i][1])
	  	theString += ' align = "'+ inputArray[i][1] +'"';
	  if (inputArray[i][2])
		  theString += ' class = "'+ inputArray[i][2] +'"';
	  theString += '><a';
	  if (i == (whichCol - 1))
	    theString += ' class = "mastSort"';
	  if (theBool && inputArray[i][0].length > truncateVar) {
	    theString += ' onMouseOver = "javascript: showTip('+ inputArray[i][0] +');" onMouseOut = "javascript: hideTip();"';
	  }
	  theString += ' href = "#" onClick = "sortSearch('+ eval(i + 1) +'); return false;">';
	  if (theBool)
		  theString += truncateString(eval(inputArray[i][0]), truncateVar);
	  else
		  theString += eval(inputArray[i][0]);
	  if (i == (whichCol - 1))
	    theString += '<span class="sort '+ theArrow +'"></span>';
	  theString += '</a>';
	  if (window.isArenaTeams && i == 0)
		theString += '<div id="teamIconBoxContainer" style = "height: 0px;"><div id="teamIconBox" style = "height: 0px;"></div></div>';
	  theString += '</td>';	
	}
	theString += '<td align="right"><div><b><img src="images/pixel.gif" width="1" height="1" /></b></div></td></tr>';
	
	return theString;
}



function printPage(currentPage) {
		
  var lowerLimit = eval(currentPage) - 2;
  var upperLimit = eval(currentPage) + 2;

  var totalPages = globalPages;
  var arrowsFirst = "";
  var arrowsLast = "";
  var arrowsFirstLink = "";
  var arrowsPrevLink = "";  
  
  var arrowsLastLink = "";
  var arrowsNextLink = "";    
  
  if (currentPage == 1)
    arrowsFirst = "-off";
  else {
    arrowsFirstLink = ' href = "#" onClick="setResultsPage(1); return false;"';
    arrowsPrevLink = ' href = "#" onClick="setResultsPage('+ eval(currentPage - 1) +'); return false;"';
  }

  if (currentPage == totalPages)
    arrowsLast = "-off";
  else {
    arrowsLastLink = ' href = "#" onClick="setResultsPage('+ totalPages +'); return false;"';
    arrowsNextLink = ' href = "#" onClick="setResultsPage('+ eval(currentPage + 1) +'); return false;"';
  }	
	
	
	if(theLang != "ko_kr") {
	  var theString = '<div class="returned"><span>'+ tPage +' <input type="text" value="'+ currentPage +'" onkeyup="setResultsPage(this.value)" size="3" class="pagesInput" onfocus="this.value=\'\'" onblur="if (this.value==\'\') this.value=\''+ currentPage +'\'"/> '+ textOf +' '+ totalPages +'</span></div><div class = "pnav"><ul><li><a class="prev-first'+ arrowsFirst +'"'+ arrowsFirstLink +'><img src="images/pixel.gif" height="1" width="1" /></a></li>';
	  theString += '<li><a class="prev'+ arrowsFirst +'"'+ arrowsPrevLink +'><img src="images/pixel.gif" height="1" width="1" /></a></li>';
	} else {
	  var theString = '<div class="returned"><span>'+ totalPages +' '+ textOf +' <input type="text" value="'+ currentPage +'" onkeyup="setResultsPage(this.value)" size="3" class="pagesInput" onfocus="this.value=\'\'" onblur="if (this.value==\'\') this.value=\''+ currentPage +'\'"/> '+ tPage +'</span></div><div class = "pnav"><ul><li><a class="prev-first'+ arrowsFirst +'"'+ arrowsFirstLink +'><img src="images/pixel.gif" height="1" width="1" /></a></li>';
	  theString += '<li><a class="prev'+ arrowsFirst +'"'+ arrowsPrevLink +'><img src="images/pixel.gif" height="1" width="1" /></a></li>';		
	}
	


  for (var i=1; i <= totalPages; i++) {
    if (i == 1 || i == totalPages || (lowerLimit <= i && i <= upperLimit)) {
      if (i == currentPage)
	    theString += '<li><a class="sel">'+ i +'</a></li>';
	  else
        theString += '<li><a class="p" href="#" onClick="setResultsPage('+ i +'); return false;">'+ i +'</a></li>';
	}
  }
  
  theString += '<li><a class="next'+ arrowsLast +'"'+ arrowsNextLink +'><img src="images/pixel.gif" height="1" width="1" /></a></li><li>';
  theString += '<a class="next-last'+ arrowsLast +'"'+ arrowsLastLink +'><img src="images/pixel.gif" height="1" width="1" /></a></li></ul></div>';
  
  return theString;
}