/*
	Simple DHTML Abstraction layer

	This file is in the public domain.
	Feel free to use it for whatever purpose you want to.
	
	If you have any questions, feel free to ask me.
	
	--Ferdinand Svehla <f dot svehla at gmail dot com>
*/

var isNS4 = (document.layers) ? true : false;
var isIE4 = (document.all && !document.getElementById) ? true : false;
var isIE5 = (document.all && document.getElementById) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;

function replace_image(image_id, to)
{
	the_image = document.getElementById(image_id);
	
	if (!the_image)
	{
		return;
	}
	
	if (the_image.tagName == "IMG")
	{
		// Es ist ein ganz normales Bild
		
		the_image.src = to;
	}
	else
	{
		// Internet Explorer mit PNG-Fix

		current_filter = (the_image.style.filter);

		srcpos = (current_filter.indexOf("src="));
		current_filter = (current_filter.substring(srcpos + 5, current_filter.length));

		tickpos = current_filter.indexOf("'");

		before = (current_filter.substring(0, tickpos));
		after = to;

		current_filter = (the_image.style.filter);
		new_filter = (current_filter.replace(before, after));

		the_image.style.filter = new_filter;
	}
}

function logout()
{
	if(parent)
	{
		parent.location = "/?action=logout";
	}
	else
	{
		window.location = "/?action=logout";
	}
}

function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function setContent(div, string)
{
	div.innerHTML = string;
}

function CBgetElementByID(id)
{
	if (isNS4)
	{
		return document.layers[id];
	}
	
	if (isIE4 || isIE5)
	{
		return document.all[id];
	}
	
	if (isNS6)
	{
		return document.getElementById(id);
	}
}

function get(id)
{
	return CBgetElementByID(id);
}

function showDIV(DIV)
{
	if (isNS4)
	{
		document.layers[DIV].visibility = "show";
	}
	
	if (isIE4 || isIE5)
	{
		document.all[DIV].style.visibility = "visible";
	}
	
	if (isNS6)
	{
		DIV = document.getElementById(DIV);
		DIV.style.visibility = "visible";
	}
}

function hideDIV(DIV)
{				
	if (isNS4)
	{
		document.layers[DIV].visibility = "hide";
	}
	
	if (isIE4 || isIE5)
	{
		document.all[DIV].style.visibility = "hidden";
	}
	
	if (isNS6)
	{
		myDIV = document.getElementById(DIV);
		myDIV.style.visibility = "hidden";
	}
}

function setDIVPos(DIV,x,y)
{
	if (isNS4)
	{
		document.layers[DIV].left = x;
		document.layers[DIV].top = y;
	}
	
	if (isIE4 || isIE5)
	{
		document.all[DIV].style.pixelLeft = x;
		document.all[DIV].style.pixelTop = y;
	}
	
	if (isNS6)
	{
		myDIV = document.getElementById(DIV);
		myDIV.style.left = x;
		myDIV.style.top = y;
	}
}

function setDIVLeft(DIV,x)
{
	if (isNS4)
	{
		document.layers[DIV].left = x;
	}
	
	if (isIE4 || isIE5)
	{
		document.all[DIV].style.pixelLeft = x;
	}
	
	if (isNS6)
	{
		myDIV = document.getElementById(DIV);
		myDIV.style.left = x;
	}
}

function setDIVwidth(DIV,width)
{
	if (isNS4)
	{
		document.layers[DIV].width = width;
	}
	
	if (isIE4 || isIE5)
	{
		document.all[DIV].style.pixelWidth = width;
	}
	
	if (isNS6)
	{
		myDIV = document.getElementById(DIV);
		myDIV.style.width = width;
	}
}

function setDIVwidth(DIV,width)
{
	if (isNS4)
	{
		document.layers[DIV].width = width;
	}
	
	if (isIE4 || isIE5)
	{
		document.all[DIV].style.pixelWidth = width;
	}
	
	if (isNS6)
	{
		myDIV = document.getElementById(DIV);
		myDIV.style.width = width;
	}
}

function setDIVTop(DIV,y)
{
	if (isNS4)
	{
		document.layers[DIV].top = y;
	}
	
	if (isIE4 || isIE5)
	{
		document.all[DIV].style.pixelTop = y;
	}
	
	if (isNS6)
	{
		myDIV = document.getElementById(DIV);
		myDIV.style.top = y;
	}
}

function getDIVLeft(DIV)
{
	if (isNS4)
	{
		return document.layers[DIV].left;
	}
	
	if (isIE4 || isIE5)
	{
		return document.all[DIV].style.pixelLeft;
	}
	
	if (isNS6)
	{
		myDIV = document.getElementById(DIV);
		return parseInt(myDIV.style.left);
	}
}

function getDIVTop(DIV)
{
	if (isNS4)
	{
		return document.layers[DIV].top;
	}
	
	if (isIE4 || isIE5)
	{
		return document.all[DIV].style.pixelTop;
	}
	
	if (isNS6)
	{
		myDIV = document.getElementById(DIV);
		return parseInt(myDIV.style.top);
	}
}

function getImageLeft(IMG)
{	
	if (isNS4)
	{
		left = document.images[IMG].x;
		return left;
	}
	
	if (isIE4 || isIE5)
	{
		return document.all[IMG].style.pixelLeft;
	}
	
	if (isNS6)
	{
		myDIV = document.getElementById(DIV);
		return parseInt(myDIV.style.left);
	}
}

function alignDIVwithImage(DIV,IMG)
{
	var left;
	var top;
		
	left = parseInt(getImageLeft(IMG));
	top = parseInt(getImageTop(IMG));
	
	setDIVPos(DIV,left,top);
}

function getImageTop(IMG)
{	
	if (isNS4)
	{
		left = document.images[IMG].y;
		return left;
	}
	
	if (isIE4 || isIE5)
	{
		return document.all[IMG].style.pixelTop;
	}
	
	if (isNS6)
	{
		myDIV = document.getElementById(DIV);
		return parseInt(myDIV.style.left);
	}
}

function getDocWidth()
{
	if (isNS4)
	{
		return self.innerWidth;
	}

	if (isIE4 || isIE5)
	{
		return document.body.offsetWidth;
	}

	if (isNS6)
	{
		return parseInt(window.innerWidth);
	}
}

function getDocHeight()
{
	if (isNS4)
	{
		return self.innerHeight;
	}

	if (isIE4 || isIE5)
	{
		return document.body.offsetHeight;
	}

	if (isNS6)
	{
		return parseInt(window.innerHeight);
	}
}

function visByClass(className, state)
{
	if (document.getElementsByTagName) { //check for obj
		 var nodes = document.getElementsByTagName("DIV");
		 for (var i = 0;i < nodes.length;i++) {
			var nodeObj = nodes.item(i);
			var attrMax = nodeObj.attributes.length
			for (var j = 0; j < attrMax; j++) {
				if (nodeObj.attributes.item(j).nodeName == 'class') {
					if (nodeObj.attributes.item(j).nodeValue == className) {
						vista = (state) ? 'block'	: 'none';
						nodeObj.style.display = vista;
					 }
				}
			 }
		}
	}
	var nodes = document.getElementsByTagName("INPUT");
		 
	var max = nodes.length
	for (var i = 0;i < max;i++) {
		var nodeObj = nodes.item(i);
		for (var j = 0; j < nodeObj.attributes.length; j++)  {
			if (nodeObj.attributes.item(j).nodeName == 'class') {
				if (nodeObj.attributes.item(j).nodeValue == className) {
					vista = (state) ? 'inline'	: 'none';
					nodeObj.style.display = vista;
			 	}
			}
		}
	}
}


	

// Pop A Window
function MM_openBrWindow(theURL,winName,features) { //v2.0
	window.open(theURL,winName,features);
}


// Redirect user with the item selected with a drop-down menu
function redirect(categoryName, selectedItem)
{	
	//window.location.href = "http://www.apple.com";
	//alert(categoryName);
	var q = selectedItem.indexOf("WONoSelectionString"); 
	//alert(q);
	if ( q == 0 ) {
		//user selected the first item, so take them back to the page listing all docs
		//you have to somehow pass in the name of the category
		//alert("../" + categoryName + "/" + categoryName + "-date.html");
		window.location.href = "../" + categoryName + "/" + categoryName + "-date.html";
	} else {
		window.location.href = selectedItem;
	}
}


function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0) 
	{
		begin = document.cookie.indexOf(NameOfCookie+"="); 
		
		if (begin != -1) 
		{
			begin += NameOfCookie.length+1;
		}
		
		end = document.cookie.indexOf(";", begin);
		
		if (end == -1)
		{
			end = document.cookie.length;
		}
		
		return unescape(document.cookie.substring(begin, end));
	} 
}



function setCookie(NameOfCookie, value, expiredays) 
{ var ExpireDate = new Date ();
 ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
 document.cookie = NameOfCookie + "=" + escape(value) + 
 ((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}



function delCookie (NameOfCookie) 
{ if (getCookie(NameOfCookie)) {
 document.cookie = NameOfCookie + "=" +
 "; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}