/* preloading hover images */
function imgpreload(gfxurl,zone) {
	if (zone != "all") {
		pic1 = new Image();
		pic1.src = gfxurl+zone+"/zbuttonallon.jpg";
	}
	if (zone != "ps3") {
		pic2 = new Image();
		pic2.src = gfxurl+zone+"/zbuttonps3on.jpg";
	}
	if (zone != "psp") {
		pic3 = new Image();
		pic3.src = gfxurl+zone+"/zbuttonpspon.jpg";
	}
	if (zone != "ps2") {
		pic4 = new Image();
		pic4.src = gfxurl+zone+"/zbuttonps2on.jpg";
	}
	pic5 = new Image();
	pic5.src = gfxurl+zone+"/tbuttonbgon.jpg";
}

/* top form functions */
function tsearch_focus() {
	if(document.tsearchform.stxt.value == "Suche nach..."){
		document.tsearchform.stxt.value = "";
	}
}
function tsearch_blur() {
	if(document.tsearchform.stxt.value == ""){
		document.tsearchform.stxt.value = "Suche nach...";
	}
}
function tloginun_focus() {
	if(document.tloginform.username.value == "Benutzername"){
		document.tloginform.username.value = "";
	}
}
function tloginun_blur() {
	if(document.tloginform.username.value == ""){
		document.tloginform.username.value = "Benutzername";
	}
}
function tloginpw_focus() {
	if(document.tloginform.passwrd.value == "Password"){
		document.tloginform.passwrd.value = "";
	}
}
function tloginpw_blur() {
	if(document.tloginform.passwrd.value == ""){
		document.tloginform.passwrd.value = "Password";
	}
}


/* open pic / vid win / dl win*/
function open_img_win (page,width,height) {
nw = window.open(page, 'imgwin', 'location=0,menubar=0,statusbar=0,toolbar=0,resizable=1,scrollbars=0,width=660,height=540,left=0,top=0');
}
function open_dl_win (page) {
nw2 = window.open(page, 'dlwin', 'location=0,menubar=0,statusbar=0,toolbar=0,resizable=1,scrollbars=0,width=352,height=382,left=0,top=0');
}

/*check for side ad */
function checkss (ele) {
	if (document.getElementById(ele) && document.getElementById('leftmenu') && !document.getElementById('leftadbox')) {
	if (document.getElementById(ele).offsetHeight-300 >= 600) {
		document.getElementById('leftmenu').innerHTML += '<div id="leftadbox"><iframe id="a916fe96" name="a916fe96" src="http://as.2play.ch/www/delivery/afr.php?zoneid=3&amp;cb=293852335" framespacing="0" frameborder="no" scrolling="no" width="120" height="600"><a href="http://as.2play.ch/www/delivery/ck.php?n=afcdab13&amp;cb=792384523" target="_blank"><img src="http://as.2play.ch/www/delivery/avw.php?zoneid=3&amp;cb=98234569235&amp;n=afcdab13" border="0" alt="" /></a></iframe></div>';
	}
	}
}

/* resize avatar in box */
var avatar_w = 68;
var avatar_h = 92;
function resizeava() {
	var imgEle=document.getElementById('avatar');
	if(imgEle) {
	if (avatar_w == 0) { tmpuserpic_width = imgEle.width; } else {tmpuserpic_width = avatar_w;}
	if (avatar_h == 0) { tmpuserpic_height = imgEle.height; } else {tmpuserpic_height = avatar_h;}
	var ratio = imgEle.width / imgEle.height;
	for(z=0;z<2;z++) { 
		if (imgEle.width > tmpuserpic_width) { imgEle.width = tmpuserpic_width; imgEle.height = parseInt(imgEle.width / ratio); }    
		if (imgEle.height > tmpuserpic_height) { imgEle.height = tmpuserpic_height; imgEle.width = parseInt(imgEle.height * ratio); }
	}
	}
}

/* comment functions */
function getcp() {
	if (document.getElementById("cpd") && document.getElementById("cps") && document.getElementById("cpc")) {
		var seed = new Array("A","B","C","D","E","F","G","H","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");
		var s = "";
		while(s.length < 20) {
			s += seed[parseInt(Math.random()*seed.length)];
		}
		document.getElementById("cps").value = s;
		var o1 = parseInt(Math.random()*10);
		var o2 = parseInt(Math.random()*10);
		document.getElementById("cpd").innerHTML = o1+s.substr(o1,1)+o2+s.substr(o2,1);		
	}	
}


/* get rating word */
function getrateword(val) {
if (0 <= val && 2.5 >= val) {return ('W&uuml;rg');}
if (2.6 <= val && 4.9 >= val) {return ('Schlecht');}
if (5 <= val && 6.5 >= val) {return ('Naja');}
if (6.6 <= val && 7.5 >= val) {return ('OK');}
if (7.6 <= val && 7.9 >= val) {return ('Gut');}
if (8.0 <= val && 8.9 >= val) {return ('Sehr Gut');}
if (9 <= val && 9.5 >= val) {return ('Genial');}
if (9.6 <= val && 10 >= val) {return ('Exzellent');}
}
/* get preview rating word */
function getprateword(val) {
if (val <= 4) {return ('Schlecht');}
if (val == 5) {return ('Naja');}
if (val == 6) {return ('Naja - OK');}
if (val == 7) {return ('OK - Gut');}
if (val == 8) {return ('Gut - Sehr gut');}
if (val == 9) {return ('Sehr gut - Genial');}
if (val == 10) {return ('Exzellent');}
}


/* reader rating slider */
function rrslider(trackId, sliderId, handleId, dispId, rwordid) {          
    this.track = document.getElementById(trackId);
    this.slider = document.getElementById(sliderId);
    this.handle = document.getElementById(handleId);
    this.display = document.getElementById(dispId);
    if (rwordid) {this.rword = document.getElementById(rwordid);}

    this.track.onmousedown = this.onmousedown;
    this.track.onmousewheel = this.onmousewheel;
    this.track.slider = this;
    
    this.track.onselectstart = this.slider.onselectstart =	
        this.handle.onselectstart = function() { return false };
    
    this.style = this.slider.style;
}

rrslider.prototype.startDrag = function(e) {
    rrslider.currentInstance = this;
    if (!e) e = window.event;
    if (!this.handleWidth) {
	    this.handleWidth = this.handle.offsetWidth;
	    this.initialWidth = this.slider.offsetWidth;
	    this.width = this.initialWidth;
	    this.maxWidth = this.track.offsetWidth;
    }
    this.screenX = e.screenX;
    var el = e.target || e.srcElement;
    if (el != this.handle) {
        var x = e.offsetX? e.offsetX : e.layerX;
        x += Math.round(this.handleWidth / 2);
        this.moveTo(x);
    }
    this.initialWidth = this.width;
}

rrslider.prototype.onmousedown = function(e) {
    var s = this.slider;
    s.startDrag(e);
    var d = document;
    if (d.addEventListener) {
        d.addEventListener("mousemove", s.onmousemove, true);
        d.addEventListener("mouseup", s.onmouseup, true);
    }
    else if (d.attachEvent) {
        d.attachEvent("onmousemove", s.onmousemove);
        d.attachEvent("onmouseup", s.onmouseup);
        d.attachEvent("onlosecapture", s.onmouseup);
    }
}

rrslider.prototype.onmouseup = function(e) {
    var s = rrslider.currentInstance;
    s.initialWidth = s.width;
    var d = document;
    if (d.removeEventListener) {
        d.removeEventListener("mousemove", s.onmousemove, true);
        d.removeEventListener("mouseup", s.onmouseup, true);
    }
    else if (d.detachEvent) {
        d.detachEvent("onmousemove", s.onmousemove);
        d.detachEvent("onmouseup", s.onmouseup);
        d.detachEvent("onlosecapture", s.onmouseup);
    }
}

rrslider.prototype.onmousemove = function(e) {
    if (!e) e = window.event;
    var s = rrslider.currentInstance;
    var x = s.initialWidth + (e.screenX - s.screenX);
    s.moveTo(x);
}

rrslider.prototype.onmousewheel =	function (e) {
    if (!e) e = window.event;
    var s = this.slider;
    s.moveBy(Math.round(e.wheelDelta / 10));
    return false;
}

rrslider.prototype.moveTo = function(x) {
    var s = rrslider.currentInstance;
    if (x < this.handleWidth) x = this.handleWidth;
    else if (x > this.maxWidth) x = this.maxWidth;
    this.width = x;
    this.style.width = '' + x + 'px';
    this.display.innerHTML = (s.getValue()).toFixed(1);
    if (this.rword) {this.rword.innerHTML = getrateword(this.display.innerHTML);}
}

rrslider.prototype.moveBy = function(x) {
    this.moveTo(this.width + x);
}

rrslider.prototype.getValue = function() {
    return Math.round((this.width-this.handleWidth) / 
    	(this.maxWidth-this.handleWidth) * 100)/10;
}

/* update side rating box routine */
function updaterr (xmlob) {
	var pobj = xmlob.getElementsByTagName('rrdata').item(0);
	if (pobj.getElementsByTagName('nr').item(0).firstChild.nodeValue != 0) {
	document.getElementById('rrvotenr').innerHTML = 'Bisher '+pobj.getElementsByTagName('nr').item(0).firstChild.nodeValue+' Leserwertungen';
	document.getElementById('rrvalue').innerHTML = pobj.getElementsByTagName('rating').item(0).firstChild.nodeValue;
	document.getElementById('rrword').innerHTML = getrateword(pobj.getElementsByTagName('rating').item(0).firstChild.nodeValue);
	} else {
	document.getElementById('rrvotenr').innerHTML = 'Keine Doppelwertungen!';
	}
	document.getElementById('rrbutton').innerHTML = 'Schon Bewertet';
	document.getElementById('rrbdisp').innerHTML = '';
	document.getElementById('rrtrack').style.display = 'none';
}






/* ajax request routine */
function ajaxrequest(func, url, mode, data, rettyp) {
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	httpRequest = new XMLHttpRequest();
	if (httpRequest.overrideMimeType) {
	//set mimetype (ff 1.5 bug)
	httpRequest.overrideMimeType('text/xml');
	}
} 
else if (window.ActiveXObject) { // IE
	try {
		httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) {
	try {
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (e) {} 
	}
}


//check for failed request
if (!httpRequest) {
            return false;
}
//call function
httpRequest.onreadystatechange = function() {
	if (httpRequest.readyState == 4) {
		if (httpRequest.status == 200) {
                if (rettyp == 'xml') {
                	func(httpRequest.responseXML);
                } else {
                	func(httpRequest.responseText);
                }
		} else {
		}
        }
};
httpRequest.open(mode, url, true);
if(mode == 'POST') {
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	httpRequest.send(data);
} else {
	httpRequest.send(null);
}
}
