﻿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 updateCookie (divIndex) {
    createCookie("opened_categories", divIndex);
} 

/*function getDivState (elem) {
if ($(elem) != null) return ($(elem).style.display == 'block') ? 1 : 0; //else throw (elem + " not found");

}
*/
//read cookie
var category_conf = readCookie("opened_categories"); 
var category_conf_vars = new Array(0);
if (category_conf) { category_conf_vars = category_conf.split(","); }


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 initialize(){
	//document.getElementById("warcraftgamebuttons").style.display = "none";
	//document.getElementById("diablogamebuttons").style.display = "none";
	//document.getElementById("arcadegamebuttons").style.display = "none";
}

function showHide(whichElement, whichArrow){
	if(document.getElementById(whichElement).style.display!="block"){
		document.getElementById(whichElement).style.display="block";
		document.getElementById(whichArrow).className="gameuniverse_arrow_up";
	} else {
		document.getElementById(whichElement).style.display="none";
		document.getElementById(whichArrow).className="gameuniverse_arrow_down";
	}
}

function showHideContact(){
	if(document.getElementById("contactcontent").style.display!="block"){
		$("contactcontent").style.display="block";
		$("contactarrow").style.backgroundImage = "url('/support/images/contactbar_arrow.gif')";
		$("contactarrow").style.backgroundPosition = "right -9px";
	} else {
		$("contactcontent").style.display="none";
		$("contactarrow").style.backgroundImage = "url('/support/images/contactbar_arrow.gif')";
		$("contactarrow").style.backgroundPosition = "right top";
	}
}

function toggleContainer (elemNumber, elem) { /*controls main categories boxes behaviour*/

    var parentDiv = elemNumber + "-parentDiv";
    var elemLink = elemNumber + "-link";
    var div = elemNumber + "-div";

    $(parentDiv).onmouseover = '';
    $(parentDiv).onmouseout = '';
    
    if ($(div).style.display != 'block') {
        $(div).style.display = 'block';
		elem.className="minus";
    } else {
        $(div).style.display = 'none';
		elem.className="plus";
    }
    var elementList = $('categories').getElementsByTagName('DIV');
    for (var i=0; i < elementList.length; i++) {
        var element = elementList[i];
        var elemId = element.id.substr(0, element.id.length-10);        
        if ((element.getAttribute("class") == "categoryContainer" || element.getAttribute("className") == "categoryContainer") && element.id != parentDiv) {
            resetContainerStyle(element);            
        } else if ((element.getAttribute("class") == "categoryContainer active" || element.getAttribute("className") == "categoryContainer active") && element.id != parentDiv) { 
            element.style.borderWidth = "1px";        
            element.style.borderStyle = "solid";        
            element.style.borderColor = "#e3e3e3";        
            element.style.backgroundColor = "#f6f6f6";
            $(elemId + '-link').className = "plus";
            $(elemId + '-div').style.display = "none";
        }
/*    updateCookie(elemNumber);*/
    }
}
function activateLink (linkElem, parentDiv) { /*makes current category bold resets other boxes*/
    var containerList = $('categories').getElementsByTagName("DIV");
    for (var i = 0; (container = containerList[i]); i++) {
        if ((container.getAttribute("class") == "categoryContainer active" || container.getAttribute("className") == "categoryContainer active") && container.id != parentDiv) { 
            resetContainerStyle(container);
        } 
    }
    $(parentDiv).className = "categoryContainer active";    
    var linkList = $('categories').getElementsByTagName("A");
    for (var i = 0; (theLink = linkList[i]); i++) {
        if (theLink.getAttribute("class") == "categoryLink" || theLink.getAttribute("className") == "categoryLink") theLink.style.fontWeight = 'normal';
    }
    if(linkElem != '') linkElem.style.fontWeight = 'bold';
    if ($('issuelisting').style.display == 'none') $('issuelisting').style.display = "block";
}

function resetContainerStyle (element) {

    var elemId = element.id.substr(0, element.id.length-10);
/*    alert(elemId);*/
    element.className = "categoryContainer";
    element.style.borderWidth = "1px";        
    element.style.borderStyle = "solid";        
    element.style.borderColor = "#ffffff";        
    element.style.backgroundColor = "#ffffff";
/*    alert("childnode0:" + element.childNodes[0].id + "\n\rchildnode1:" + element.childNodes[1].id);*/
    $(elemId + '-link').className = "plus";
    $(elemId + '-div').style.display = "none";
    element.onmouseover = function (event) {this.style.backgroundColor ='#f6f6f6'; this.style.borderStyle = 'solid'; this.style.borderWidth = '1px'; this.style.borderColor = '#e3e3e3';}
    element.onmouseout = function (event) {this.style.backgroundColor = '#ffffff'; this.style.borderWidth = '1px'; this.style.borderStyle = 'solid'; this.style.borderColor = '#ffffff';}
}


function langSelectOn(){
	document.getElementById("countryDropDown").style.display="block";	
}

function langSelectOff(){
	document.getElementById("countryDropDown").style.display="none";	
}

var suggestedTimeout;
var itsOn = false;

function initEventTimeout(element){
	itsOn = true;
	window.setTimeout('fadeInElement("' + element + '")', 100);
	if(suggestedTimeout != null) window.clearTimeout(suggestedTimeout);
}
function clearEventTimeout(element) {
	itsOn = false;
	suggestedTimeout = window.setTimeout('fadeOutElement("' + element + '")', 300);
}

function fadeInElement(elem){ $(elem).style.display="block"; }
function fadeOutElement(elem){ if(!itsOn){ $(elem).style.display="none"; } }

function changeFlag(whichFlag){
	document.getElementById("langselectflag").style.backgroundImage='url(images/'+whichFlag+')';
}

function $ (elem) {
	return document.getElementById(elem);
}

function addValues1 () {
	var aList = $('productlisttop').getElementsByTagName('A');
	var counter = 0;
		for (var i=0; i < aList.length; i++){
			aList[i].onclick = function () {
                document.forms['searchForm1'].gameId.value = this.getAttribute("gameId");
				document.forms['searchForm1'].categoryId.value = this.getAttribute("categoryId");
				$('allProducts_productlisttop').innerHTML = "";
				$('allProducts_productlisttop').innerHTML = this.firstChild.nodeValue;
				if(this.getAttribute("prefix")) $('allProducts_productlisttop').innerHTML = this.getAttribute("prefix") + " - " + $('allProducts_productlisttop').innerHTML;
				if($('allProducts_productlisttop').innerHTML.length > 28) $('allProducts_productlisttop').innerHTML = ($('allProducts_productlisttop').innerHTML).substring(0,28)+"...";
				$('productlisttop').style.display = "none";
				return false;
			}
		counter++;
		}
}
function addValues2 () {
	var aList = $('productlistbottom').getElementsByTagName('A');
	var counter = 0;
		for (var i=0; i < aList.length; i++){
			aList[i].onclick = function () {
                document.forms['searchForm2'].gameId.value = this.getAttribute("gameId");
				document.forms['searchForm2'].categoryId.value = this.getAttribute("categoryId");
				$('allProducts_productlistbottom').innerHTML = "";
				$('allProducts_productlistbottom').innerHTML = this.firstChild.nodeValue;
				if(this.getAttribute("prefix")) $('allProducts_productlistbottom').innerHTML = this.getAttribute("prefix") + " - " + $('allProducts_productlistbottom').innerHTML;
				if($('allProducts_productlistbottom').innerHTML.length > 28) $('allProducts_productlistbottom').innerHTML = ($('allProducts_productlistbottom').innerHTML).substring(0,28)+"...";
				$('productlistbottom').style.display = "none";
				return false;
			}
		counter++;
		}
}

var myWin;
function openWin (url) {
  myWin = window.open(url, "print", "width=800,height=400,scrollbars=yes");
  myWin.focus();
}


var xmlDataArray = new Array;
var	myXMLHTTPRequest;
var	myXMLHTTPRequest2; 
var intervalHolder;
var containerGlobal;
var loaderGlobal;

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", xslSource, aSync);
			myXMLHTTPRequest.send(null);

			// load the xml file, example1.xml

			myXMLHTTPRequest2.open("GET", 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);
		  
	} else {
		var safariXmlRequest = new XMLHttpRequest;
		function safariReadystateHandler()
		{
			if(safariXmlRequest.readyState == 4)
			{

				document.getElementById(container).innerHTML = safariXmlRequest.responseText;
				document.getElementById(loader).style.display = "none";
				if($('hotLink')) document.getElementById('hotLink').style.display='block';
				
/*				checkJSLoad(container)*/
				eval(afterFunction);
				adjustInfoBox();
			}
		}
		safariXmlRequest.onreadystatechange = safariReadystateHandler;
		safariXmlRequest.open("GET", xmlSource, true);
		safariXmlRequest.send(null);
	}
	//return false;
}

function xmlDataLoadListener(xmlObj, xslObj, container, loader, afterFunction){
			if (xmlObj.readyState == 4 && xslObj.readyState == 4) {
/*				alert(xmlObj.responseText);*/
                
                document.getElementById(container).innerHTML = xmlObj.transformNode(xslObj);
/*				checkJSLoad(container)*/
				document.getElementById(loader).style.display = "none";
				if($('hotLink')) document.getElementById('hotLink').style.display='block';
				eval(afterFunction);
				window.clearInterval(intervalHolder);
				adjustInfoBox();
			}
			
}

function xmlDataLoadListenerMoz(xmlObj, xslObj, container, loader, afterFunction){

			if (xmlObj.readyState == 4 && xslObj.readyState == 4) {
/*					alert(xmlObj.responseText);*/
					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);
                    window.setTimeout('fadeOutElement("' + loader + '")', 300);
					if($('hotLink')) window.setTimeout('fadeInElement("hotLink")', 0);
/*					document.getElementById(loader).style.display = "none";*/
					eval(afterFunction);
					adjustInfoBox();
			}
}

function dummyFunction(){}

function toggleMenu(elem) {
    classOn = elem.id+ "-ovr";
    classOff = elem.id+ "-off";
    elemDrop = elem.id+ "-drop";
    var obj;
    var obj2;
    if (document.getElementById(elemDrop)) {
        obj = document.getElementById(elemDrop);
        if (obj.style.visibility != "visible" || obj.style.display == "none") {
            obj.style.visibility = "visible";
            obj.style.display = "block";
            obj.parentNode.className = classOn;
        } 
        else { 
            obj.style.visibility = "hidden";
            obj.style.display = "none";
            obj.parentNode.className = classOff;
//            obj.style.height = "0px";
        }
    } else {
        obj2 = document.getElementById(elem.id);
        if (obj2.className != classOn) {
            obj2.className = classOn;
        } else obj2.className = classOff;
    }
}

// Get maxlength of longest linkname in the unordered list and resize the list -->
function resizeList() { 
    var maxLength = 0;
    var lists = document.getElementsByTagName("ul"); 
    for (x = 0; x < lists.length; x++) { 
        var list = lists[x]; 
		if (list.getAttribute("class") == "linkList" || list.getAttribute("className") == "linkList") { 
            maxLength = 0;
            parentDiv = list.parentNode.parentNode.parentNode;
            var listitems = list.childNodes;
			for (j = 0; j < listitems.length; j++) {
				node = listitems[j];
                if (node.nodeName == "LI") {
					linkitems = node.childNodes;
                    for (k = 0; k < linkitems.length; k++) {
						linkitem = linkitems[k];
		                if (linkitem.nodeName == "SPAN") {
                            subHeader = linkitem.childNodes[0].nodeValue;
							if ((subHeader.length*1.5) > maxLength) { 
                                maxLength = subHeader.length * 1.5;
                            }
                        }
                        if (linkitem.nodeName == "UL") {
                            reallist = linkitem.childNodes;
                            for (f = 0; f < reallist.length; f++) {
                                reallistitems = reallist[f];
                                if (reallistitems.nodeName == "LI") { 
                                    reallistlinks = reallistitems.childNodes;
                                    for (g = 0; g < reallistlinks.length; g++) {
                                        reallink = reallistlinks[g];
                                        if (reallink.nodeName == "A") { 
                                            linkValue = reallink.childNodes[0].nodeValue;
                                            if (linkValue.length > maxLength) {
                                                maxLength = linkValue.length;
                                            }
                                        }
                                    }
                                }
                            }
                        }
					}
	            }
            }
        if (maxLength > parentDiv.style.width) parentDiv.style.width = ((maxLength/5)*2+2) + "em";
		}
    } 
}

function stretchContainer () {
    var normalWidthArticleContainer = 688;    

    var maxWidth = 0;
    var imgList = $('articlecontent').getElementsByTagName('IMG');
    for (var i = 0; i < imgList.length; i++) {
        if(imgList[i].width > maxWidth) maxWidth = imgList[i].width;
    }
    if (maxWidth > normalWidthArticleContainer) $('articlecontent').style.width = (maxWidth) + "px";
}

var gamesArray = new Array();

var searchNeedsUpdate = true;

function updateSearchbar(){
	if(jsGameWorldId != -1 && searchNeedsUpdate){
        getSearchLabel();
    	var jsGameWorld = gamesArray[jsGameWorldId];
		document.forms['searchForm1'].gameId.value = jsGameWorldId;
		$('allProducts_productlisttop').innerHTML = jsGameWorld;
		if(document.forms['searchForm2']) document.forms['searchForm2'].gameId.value = jsGameWorldId;
		if(document.forms['searchForm2']) $('allProducts_productlistbottom').innerHTML = jsGameWorld;
		if(jsRootCategoryId){
			document.forms['searchForm1'].categoryId.value = jsRootCategoryId;
			var aList = $('productlisttop').getElementsByTagName('A');
			for (var i=0; i < aList.length; i++){
				if(aList[i].getAttribute("categoryId") == jsRootCategoryId){
					$('allProducts_productlisttop').innerHTML = aList[i].innerHTML;
					if(aList[i].getAttribute("prefix")) $('allProducts_productlisttop').innerHTML = aList[i].getAttribute("prefix") + " - " + $('allProducts_productlisttop').innerHTML;
					if($('allProducts_productlisttop').innerHTML.length > 28) $('allProducts_productlisttop').innerHTML = ($('allProducts_productlisttop').innerHTML).substring(0,28)+"...";
				}
			}
			if(document.forms['searchForm2']){
				document.forms['searchForm2'].categoryId.value = jsRootCategoryId;
				aList = $('productlistbottom').getElementsByTagName('A');
				for (var i=0; i < aList.length; i++){
					if(aList[i].getAttribute("categoryId") == jsRootCategoryId){
						$('allProducts_productlistbottom').innerHTML = aList[i].innerHTML;
						if(aList[i].getAttribute("prefix")) $('allProducts_productlistbottom').innerHTML = aList[i].getAttribute("prefix") + " - " + $('allProducts_productlistbottom').innerHTML;
						if($('allProducts_productlistbottom').innerHTML.length > 28) $('allProducts_productlistbottom').innerHTML = ($('allProducts_productlistbottom').innerHTML).substring(0,28)+"...";
					}
				}
			}
		}
	}
}

/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/

var Utf8 = {

    // public method for url encoding
    encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // public method for url decoding
    decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

} 

function getElementsByName_ie(thisName){
	var el = document.getElementsByTagName("*");
	var newEl = new Array();
	j=0;
	for(var i = 0; i < el.length; i++) {
		att = el[i].getAttribute("name");
		if(att == thisName) {
			 newEl[j] = el[i];
			 j++;
		}
	}
	return newEl;
}

var currentStep = 0;
var tempStep = 0;
var allStepsShown = false;

function setSteps(){
	currentStep = stepId;
	updateSteps();
}

function updateSteps(){
	var theSteps = getElementsByName_ie("articleStep");
	var theStepNavi = getElementsByName_ie("stepNavi");
	var theIndexSteps = getElementsByName_ie("indexStep");
	var theOnlySteps = getElementsByName_ie("onlyThisStep");
	if(currentStep>theSteps.length) currentStep=theSteps.length;
	if(currentStep<0) currentStep=1;
	if(currentStep==0) allStepsShown=true;
	if(allStepsShown==false){
		if(document.getElementById("showAllSteps")) document.getElementById("showAllSteps").style.display="block";
	} else {
		if(document.getElementById("showAllSteps")) document.getElementById("showAllSteps").style.display="none";
		if(document.getElementById("printStep")) document.getElementById("printStep").style.display="none";
		for(i=0;i<theSteps.length;i++){
			if(theOnlySteps[i]) theOnlySteps[i].style.display="block";
		}
	}
	if(currentStep>0){
		for(i=0;i<theSteps.length;i++){
			if(allStepsShown==false){
				theSteps[i].style.display="none";
			} else {
				theSteps[i].style.display="block";
			}
			if(theIndexSteps[i]) theIndexSteps[i].className="indexStep";
			if(theStepNavi[i]) theStepNavi[i].style.display="none";
			//if(theOnlySteps[i]) theOnlySteps[i].style.display="block";
		}
		theSteps[currentStep-1].style.display="block";
		if(theStepNavi[currentStep-1] && allStepsShown==false) theStepNavi[currentStep-1].style.display="block";
		if(theOnlySteps[currentStep-1] && allStepsShown==false) theOnlySteps[currentStep-1].style.display="none";
		if(theIndexSteps[currentStep-1] && allStepsShown==false) theIndexSteps[currentStep-1].className="currentIndexStep";
		if(document.getElementById("printStep") && allStepsShown==false) document.getElementById("printStep").style.display="inline";
		if(document.getElementById("stepIndex")) document.getElementById("stepIndex").style.display="block";
	} else {
		for(i=0;i<theSteps.length;i++){
			theSteps[i].style.display="block";
			if(theStepNavi[i]) theStepNavi[i].style.display="none";
		}
		if(document.getElementById("printStep")) document.getElementById("printStep").style.display="none";
		//if(document.getElementById("stepIndex")) document.getElementById("stepIndex").style.display="none";
	}
}
/*
function updateSteps(){
	var theSteps = getElementsByName_ie("articleStep");
	var theStepNavi = getElementsByName_ie("stepNavi");
	var theIndexSteps = getElementsByName_ie("indexStep");
	if(currentStep>theSteps.length) currentStep=theSteps.length;
	if(currentStep<0) currentStep=0;
	if(currentStep==0) allStepsShown=true;
	for(i=0;i<theSteps.length;i++){
		if(theIndexSteps[i]) theIndexSteps[i].className="indexStep";
	}
	if(currentStep>0 && allStepsShown==false){
		for(i=0;i<theSteps.length;i++){
			theSteps[i].style.display="none";
			if(theStepNavi[i]) theStepNavi[i].style.display="none";
		}
		theSteps[currentStep-1].style.display="block";
		if(theStepNavi[currentStep-1]) theStepNavi[currentStep-1].style.display="block";
		if(theIndexSteps[currentStep-1]) theIndexSteps[currentStep-1].className="currentIndexStep";
		if(document.getElementById("printStep")) document.getElementById("printStep").style.display="inline";
		if(document.getElementById("stepIndex")) document.getElementById("stepIndex").style.display="block";
	} else {
		for(i=0;i<theSteps.length;i++){
			theSteps[i].style.display="block";
			if(theStepNavi[i]) theStepNavi[i].style.display="none";
		}
		if(document.getElementById("printStep")) document.getElementById("printStep").style.display="none";
		//if(document.getElementById("stepIndex")) document.getElementById("stepIndex").style.display="none";
	}
}
*/
function previousStep(){
	currentStep--;
	updateSteps();
}

function nextStep(){
	currentStep++;
	updateSteps();
}

function allSteps(){
	//currentStep="0";
	allStepsShown=true;
	updateSteps();
}

function gotoStep(stepNr){
	currentStep=stepNr;
	updateSteps();
}

function printEntireArticle(){       
	var cssPrintAllNode = document.createElement("link");
	cssPrintAllNode.type = "text/css";
	cssPrintAllNode.rel = "stylesheet";
	cssPrintAllNode.href = "css/support_css_print_entire_article.css";
	cssPrintAllNode.media = "print";
	cssPrintAllNode.id = "printentirearticle";
	document.getElementsByTagName("head")[0].appendChild(cssPrintAllNode);
	window.print();
}

function printStep(){
	if(document.getElementById("printentirearticle")){
		var cssPrintAllNode = document.getElementById("printentirearticle");
		document.getElementsByTagName("head")[0].removeChild(cssPrintAllNode);
	}
	window.print();
}

function rateArticle(whichArticle){
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      //alert("Your browser does not support AJAX!");
      //return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      ratingSent();
      }
    }
	xmlHttp.open("POST",whichArticle,true);
  xmlHttp.send(null);
  sendingRating();
}

function sendingRating(){
	if(document.getElementById("sendingRating")) document.getElementById("sendingRating").style.display="block";
	if(document.getElementById("pleaseRate")) document.getElementById("pleaseRate").style.display="none";
	if(document.getElementById("articleComment")) document.getElementById("articleComment").style.display="none";

}

function ratingSent(){
	if(document.getElementById("sendingRating")) document.getElementById("sendingRating").style.display="none";
	if(document.getElementById("ratingSent")) document.getElementById("ratingSent").style.display="block";
	var ratedArticle = "article_"+articleId+"_rated";
	createCookie(ratedArticle,1,1);
}

function setUpRating(){
	if(typeof articleId != "undefined"){
		var ratedArticle = "article_"+articleId+"_rated";
		if(document.getElementById("ratingDisabled")) document.getElementById("ratingDisabled").style.display="none";
		if(document.getElementById("pleaseRate")) document.getElementById("pleaseRate").style.display="block";
		if(readCookie(ratedArticle)){
			if(document.getElementById("pleaseRate")) document.getElementById("pleaseRate").style.display="none";
			if(document.getElementById("ratingSent")) document.getElementById("ratingSent").style.display="block";
		}
	}
}

function commentArticle(){
	var articleComment = encodeURI(document.forms["commentForm"].articleComment.value);
	var articleRating = 0;
	for(var i= 0; i < document.forms["commentForm"].articleRating.length; i++){
		if(document.forms["commentForm"].articleRating[i].checked){
			var articleRating = document.forms["commentForm"].articleRating[i].value;
		}
	}
	var ratingAddress = "/support/articleRating.xml?articleId="+articleId+"&rating="+articleRating+"&comment="+articleComment;
	rateArticle(ratingAddress);
}

function limitLength(limitField, limitNum) {
    if (limitField.value.length > limitNum) {
        limitField.value = limitField.value.substring(0, limitNum);
    } 
}

function hoverTab(thisTab){
	thisTab.className = "hoverTab";
	thisTab.previousSibling.className = "hoverTabLeft";
	thisTab.nextSibling.className = "hoverTabRight";
}

function unhoverTab(thisTab){
	thisTab.className = "greyTab";
	thisTab.previousSibling.className = "greyTabLeft";
	thisTab.nextSibling.className = "greyTabRight";
}

function adjustInfoBox(){
	//if(typeof boxAdjuster != "undefined") window.clearTimeout(boxAdjuster);
	//boxAdjuster = window.setTimeout("adjustInfoBoxTimer()", 100);
}

function adjustInfoBoxTimer(){
	if($("categoryInfoMargin")){
		var categoryInfoHeight = $("categoryInfo").offsetHeight;
		var margin=(($("rightcontent").offsetHeight-$("topitems").offsetHeight) - $("articlecontent").offsetHeight) + ($("articlecontent").offsetHeight - ($("categoryInfo").offsetTop + categoryInfoHeight))-30;
		if(margin<0)margin=0;
		$("categoryInfoMargin").style.height = margin+"px";
	}
}

function changeClass(element, newClass){
	element.className = newClass;
}

function preloadImages(){
	for (var i = 0; i < preloadImages.arguments.length; i++){
		var preimg = new Array();
		preimg[i] = new Image();
		preimg[i].src = "/support/images/"+preloadImages.arguments[i];
	}
}

function hotTitle(){
	if($("issueGrpHeader")) $("issueGrpHeader").firstChild.nodeValue += " - " + hotString;
}

function loadScript(src, id) {
    var head = document.getElementsByTagName('head')[0];
    var script = createElement('script', {'type': 'text/javascript', 'src': src} );
    if(id) {
        var old = document.getElementById(id);
        if(old)
            old.parentNode.removeChild(old);
        script.id = id;
    }
    head.appendChild(script);
}


function createElement(name, attrs, doc, xmlns) {
      var doc = doc || document;
      var elm;
      if(doc.createElementNS)
            elm = doc.createElementNS(xmlns || "http://www.w3.org/1999/xhtml", name);
      else
            elm = doc.createElement(name);
      if(attrs)
            for(attr in attrs)
                  elm.setAttribute(attr, attrs[attr]);
      return elm;
}

addEvent(window, 'load', resizeList);
addEvent(window, 'load', updateSearchbar);
addEvent(window, 'load', setSteps);
addEvent(window, 'load', setUpRating);

function btoggle(targ,obj)
{ 	targ = document.getElementById(targ)
    if(!obj.parentNode.mfocus)
	{ targ.style.display = 'none'; }
}

function dtoggle(targ)
{ targ = document.getElementById(targ); 
  targ.style.display = (targ.style.display == "block")?"none":"block";
}

function clearDefault(el) { if (defsearch==el.value) el.value = ""; }

function setDefault(el) { if (el.value == "") el.value = defsearch; }

