// Window - PopUp Script
// IE und NS kompatibel
// by TVC The Virtual Company, www.tvc.at

var IsOpen = false;
var wHnd;
var PopUpName = "tvcPopUp";

function PopUpIsOpen() {
// Liefert zurück, ob bereits ein PopUp geöffnet ist.
	
	return IsOpen;
}

function PopUpSetName(PName) {
// Setzt den PopUp-Name, falls ein weiteres geöffnet werden soll.
	
	if (PName.length < 1) { PName = "tvcPopUp"; }
	
	return PopUpName = PName;
}

function PopUp(u,w,h) {
	
	cmd = "resizable=yes,scrollbars=no";
	PopUpVar(u,w,h,cmd);
}

function PopUpScrollBar(u,w,h) {
	
	cmd = "resizable=yes,scrollbars=yes";
	PopUpVar(u,w,h,cmd);
}

function PopUpScroll(u,w,h) {
	
	cmd = "resizable=no,scrollbars=yes";
	PopUpVar(u,w,h,cmd);
}

function PopUpFix(u,w,h) {
	
	cmd = "resizable=no,scrollbars=no";
	PopUpVar(u,w,h,cmd);
}

function PopUpAVStream(u) {
	
	cmd = "resizable=yes,scrollbars=no";
	PopUpVar(u,400,460,cmd);
}

function PopUpAStream(u) {
	
	cmd = "resizable=no,scrollbars=no";
	PopUpVar(u,400,200,cmd);
}

function PopUpVar(u,w,h,cmd) {

	var TheURL = "";
	cmd = "width=" + w + ",height=" + h + ",alwaysRaised=yes,depend=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,copyhistory=no," + cmd;
	TheURL = fixIEMacCharProblem(u); // Setzt TheURL (wegen IE-Fehler)
	wHnd = window.open(TheURL, PopUpName, cmd);

        if (!document.layers) { // IE resizes outerHeight

                w=parseInt(w);
                h=parseInt(h);
                w+=12;
                h+=30;
        }
	wHnd.resizeTo(w,h);  // geht leider nicht weil von ns und ie verschieden behandelt (outer/inner size problem)
	wHnd.focus();
	
	IsOpen = true;
	PopUpSetName('');  // Setzt den Namen zurück (falls gesetzt)
	
}

// IE (Version 5) für MAC hat Probleme mit Sonderzeichen wie ü,ä, ... in JavaScript,
// es passiert offensichtlich ein Überlauf aufgrund von signed char
function fixIEMacCharProblem(str) {

	var newstr="";
	for (i = 0; i < str.length; i++){
		theChar = str.charCodeAt(i);
		if(theChar < 0){

			newstr = newstr + String.fromCharCode(theChar+256);
		}
		else {
			newstr = newstr + str.charAt(i);
		}
	}
	return newstr;
}