google_ad_client = "pub-4075216157019612";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_channel ="";

aWindows = new Object();

aWindows['identity'] = 1;
aWindows['newposts'] = 0;
aWindows['latestnews'] = 0;
aWindows['links'] = 1;
aWindows['quicklink'] = 0;
aWindows['award'] = 1;
aWindows['glossary'] = 1;
aWindows['casemod'] = 1;
aWindows['poll'] = 1;

initWindowSystem();

function initWindowSystem()
{
	var szWindows = readCookie('windows');
	if (!szWindows)
		return;

	szWindows = URLDecode(szWindows);

	szWindows = unescape(szWindows.replace(/\+/g," "));

	var aSavedWins = szWindows.split('|');

	szWindows = "";
	for (var i = 0;i < aSavedWins.length;i+=2)
	{
		szWindows += aSavedWins[i]+" => "+aSavedWins[i+1]+"\n";
		aWindows[aSavedWins[i]] = aSavedWins[i+1];
	}
}

function saveWindowSettings()
{
	var szWindows = '';
	var oWin      = null;

	for (var i in aWindows)
	{
		if (szWindows != "")
			szWindows += '|';

		szWindows += i+'|'+aWindows[i];
	}

	createCookie('windows',szWindows);
}

function switchWindow(szName,nFixed)
{
	nFixed = (nFixed == null) ? -1 : nFixed;

	var oWin = document.getElementById(szName);
	if (!oWin)
		return true;

	var oIcon = document.getElementById(szName+'_img')
	if (!oIcon)
		return true;

	if ((oWin.style.display != "none" && nFixed == -1) || nFixed == 0)
	{
		oWin.style.display = "none";
		oWin.style.borderBottom = "1px solid #545F73";

		oIcon.src = '/images/win_open.gif';

		aWindows[szName] = 0;
	}
	else
	{
		oWin.style.display = "block";
		oWin.style.borderBottom = "0px";

		oIcon.src = '/images/win_close.gif';

		aWindows[szName] = 1;
	}

	saveWindowSettings();

	return false;
}

function createCookie(name,value)
{
	value = escape(value);

	var date = new Date();
	date.setTime(date.getTime()+500*24*60*60*1000);

	document.cookie = name+"="+value+"; expires="+date.toGMTString()+"; path=/; domain=.overclockers.at";
}

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 URLDecode(szEncoded)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = szEncoded;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while

   return plaintext;
}

function setFormAction(szAction,szForm,szVarString)
{
	if (typeof szVarString == "undefined")
		szVarString = "";

	var form = document.forms[szForm ? szForm : 0];
	if (!form)
	{
		alert("Error: Could not find form ["+szForm+"]");
		return false;
	}

	var nodeAction = form.elements['the_action'];
	if (!nodeAction)
	{
		alert("Error: Could not set action value [form: "+form.name+" ("+szForm+"), action: "+szAction+"], action formelement not found!");
		return false;
	}

	if (szVarString != '' && form.action.match('\\?') == null)
		form.action += '?' + szVarString;

	nodeAction.value = szAction;

	return true;
}

function assembleMailLink(szMail)
{
	var szRMail = szMail.replace(/@/i,'&#64;').replace(/\./i,'&#46;');

	return '<a href="mailto:'+szRMail+'">'+szRMail+'</a>';
}

function copyToClipboard(szText)
{
	szRealText = szText.replace(/\+/g," ");

	// IE: Function integrated!
	if (window.clipboardData && clipboardData.setData)
	{
		clipboardData.setData("Text",unescape(szRealText));
		return true;
	}

	// Else: Copy with Flash Object
	if (!document.getElementById('idFlashCopy'))
	// => Flash Object exists?
	{
		var oDiv = document.createElement('div');

		oDiv.id = 'idFlashCopy';

		document.body.appendChild(oDiv);
	}

	document.getElementById('idFlashCopy').innerHTML = '<embed src="/flashcopy.swf" FlashVars="clipboard='+szRealText+'" width="30" height="30" type="application/x-shockwave-flash"></embed>';

	return true;
}

function toogleExpandArea(oButton,szAreaID)
{
	var oArea = document.getElementById(szAreaID);
	if (!oArea)
		return;

	if (oButton.src.indexOf('collapse.gif') != -1)
	{
		oArea.style.display = 'none';

		oButton.src = '/images/expand.gif';
	}
	else
	{
		oArea.style.display = 'block';

		oButton.src = '/images/collapse.gif';
	}
}

function hideExpandArea(szAreaID)
{
	var oArea = document.getElementById(szAreaID);
	if (!oArea)
		return;

	oArea.style.display = 'none';
}

function submitToAdvanced(szForm)
{
	var oForm = document.forms[szForm];
	if (!oForm)
	{
		alert("Quick reply form could not be found!");
		return;
	}

	oForm.elements["preview"].value = 1;
	oForm.elements["action"].value = "postreply";

	oForm.submit();
}

function removeSpoiler(oSpoiler)
{
	oSpoiler.className = 'nospoiler';
}

