var genreBrowserWin;
var cal1win;
var isTemplateWithForm=false;
var playerwin;
var bookletbrowser;
var mp3playerwin;

function notImplementedYet()
{
	alert('Diese Funktion wurde noch nicht Implementiert.');
}
function manualopen() {
	var w = 800;
	var h = 600;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	manualwin = window.open("/manual/php/nbout.php?bname=manualmp_de&view=detail","Manual","toolbar=no,resizable=yes,directories=no,status=no,menubar=no,location=no,scrollbars=yes,width="+w+",height="+h+",top="+wint+",left="+winl);
}
function openbookletbrowser(productid) {
	//alert(screen.width+"/"+screen.width);

	url = baseurl.replace('https://','http://');

	// get screensize and set variable "imgsize"
	if (screen.width < 1200)
	{
		imgsize="small";
		var w = screen.width;
	}
	else
	{
		imgsize="big";
		var w = 1240;
	}
	var h = w*0.6;
	
	// popup position centered
	//var winl = (screen.width - w) / 2;
	//var wint = (screen.height - h) / 2;
	
	// popup position top/left corner (0/0):
	var winl = 0;
	var wint = 0;
	
	// default language = de
//	if(lang_path=="" || lang_path==undefined)
//		var lang_path = "de";
	
	// open window
//	bookletbrowser = window.open("/"+lang_path+"/FlashBookletBrowser?pid="+productid+"&imgsize="+imgsize,"bookletbrowser","toolbar=no,resizable=yes,directories=no,status=no,menubar=no,location=no,scrollbars=no,width="+w+",height="+h+",top="+wint+",left="+winl);
	bookletbrowser = window.open(url+"/FlashBookletBrowser?pid="+productid+"&imgsize="+imgsize,"bookletbrowser","toolbar=no,resizable=yes,directories=no,status=no,menubar=no,location=no,scrollbars=no,width="+w+",height="+h+",top="+wint+",left="+winl);
}
function openbookletpage(url) {
	// fullscreen popup
	var w = screen.width;
	var h = w*0.5;
	
	// popup position top/left corner (0/0):
	var winl = 0;
	var wint = 0;
	
	// open window
	bookletbrowser = window.open(url,"BookletPage","toolbar=no,resizable=yes,directories=no,status=no,menubar=no,location=no,scrollbars=yes,width="+w+",height="+h+",top="+wint+",left="+winl);
}
/*
function openbookletbrowser(productid) {
	var w;
	var h;
	if (screen.width < 820)
	{
		imgsize="small";
		w = 347;
		h = 500;
	}
	else
	{
		imgsize="big";
		w = 647;
		h = 720;
	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	if(lang_path=="" || lang_path==undefined)
		var lang_path = "de";
	bookletbrowser = window.open("/"+lang_path+"/BookletBrowser?pid="+productid+"&imgsize="+imgsize,"bookletbrowser","toolbar=no,resizable=no,directories=no,status=no,menubar=no,location=no,scrollbars=no,width="+w+",height="+h+",top="+wint+",left="+winl);
}
*/
function playeropen(productid,trackid,type) {
	var w = 500;
	var h = 530;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	if (type != 'editorpool' && type != 'notepad')
	{
		playersort='';
		playerorientation='';
	}
	else
	{
		playersort = escape(document.notepadlistfilter.sort.value);
		playerorientation = document.notepadlistfilter.orientation.value;
		if (playerorientation=='+')
			playerorientation='';
	}
	playerwin = window.open("/"+lang_path+"/PlayerPart/frameset/?type="+type+"&pid="+productid+"&tid="+trackid+"&sort="+playersort+"&orientation="+playerorientation,"MPNAudioPlayer","toolbar=no,resizable=no,directories=no,status=no,menubar=no,location=no,scrollbars=no,width="+w+",height="+h+",top="+wint+",left="+winl);
}
function mp3playeropen(productid,trackid,type) {
	url = baseserver.replace('https://','http://');

	var w = 840;
	var h = 540;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	mp3playerwin = window.open(url+"/player2008/?pid="+productid+"&tid="+trackid+"&type="+type,"MPNMP3Player","toolbar=no,resizable=no,directories=no,status=no,menubar=no,location=no,locationbar=no,scrollbars=no,width="+w+",height="+h+",top="+wint+",left="+winl);
	mp3playerwin.opener = self;
}
function changecolor(row,color) {
	oldcolor = document.getElementById(row).style.backgroundColor;
	document.getElementById(row).style.backgroundColor = color;
	rowselect = row;
}
function resetcolor() {
	document.getElementById(rowselect).style.backgroundColor = oldcolor;
}
function changeimg(imgname,stat,id) {
	if ((typeof id)=="string")
		imgid=imgname+"-"+id;
	else
		imgid = imgname;
	document.getElementById(imgid).src = "/bilder/base/"+imgname+"-"+stat+".gif";
}
function changeimgandborder(imgname,stat,id) {
	// change img.src
	if ((typeof id)=="string")
		imgid=imgname+"-"+id;
	else
		imgid = imgname;
	document.getElementById(imgid).src = "/bilder/base/"+imgname+"-"+stat+".gif";
	// and border
	if ("1"==stat)
		document.getElementById(imgid).style.border = "1px solid #ffffff";
	else
		document.getElementById(imgid).style.border = "1px solid #9BB1C5";
}
var calendarCBFunc = null;
function opencal1(form,field,select,cb) {
	calendarCBFunc = cb;
	sd = '';
	if (select.match(/^\d\d\.\d\d\.\d\d\d\d$/))
		sd = select.substr(6,4)+select.substr(3,2)+select.substr(0,2);
	var w = 350;
	var h = 350;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	cal1win = window.open("/"+lang_path+"/Calendar?form="+form+"&field="+field+"&select="+sd,"calendar","toolbar=no,resizable=no,directories=no,status=no,menubar=no,location=no,scrollbars=no,width="+w+",height="+h+",top="+wint+",left="+winl);
}
function opencal2(form,startfield,endfield,startselect,endselect) {
	startsd = '';
	if (startselect.match(/^\d\d\.\d\d\.\d\d\d\d$/))
		startsd = startselect.substr(6,4)+startselect.substr(3,2)+startselect.substr(0,2);
	endsd = '';
	if (endselect.match(/^\d\d\.\d\d\.\d\d\d\d$/))
		endsd = endselect.substr(6,4)+endselect.substr(3,2)+endselect.substr(0,2);
	var w = 600;
	var h = 400;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	cal2win = window.open("/"+lang_path+"/Calendar2?form="+form+"&startfield="+startfield+"&startselect="+startsd+"&endfield="+endfield+"&endselect="+endsd,"calendar","toolbar=no,resizable=no,directories=no,status=no,menubar=no,location=no,scrollbars=no,width="+w+",height="+h+",top="+wint+",left="+winl);
}
function openaddresseealiasbrowser() {
	var w = 800;
	var h = 500;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	window.open("/"+lang_path+"/AddresseeAliasBrowser","addresseealiasbrowser","toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width="+w+",height="+h+",top="+wint+",left="+winl);
}
function opengenrebrowser(max,cnt,preset) {
	if (cnt == max)
	{
		alert("Maximale Anzahl von Genres wurde erreicht.");
		return;
	}
	var w = 700;
	var h = 550;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	genreBrowserWin = window.open("/"+lang_path+"/GenreBrowser/frameset.php?genre_preset="+preset,"Genre","toolbar=no,resizable=no,directories=no,status=no,menubar=no,location=no,scrollbars=no,width="+w+",height="+h+",top="+wint+",left="+winl);
}
function add_genre(code,bez)
{
	if (code == "")
		return;

	if ('ProductList' == currentModule)
	{
		// create new option for select menu
		opt = new Option(bez,code,false,false);
		document.productlistfilter.elements["genrefilterviewer"].options[document.productlistfilter.elements["genrefilterviewer"].options.length] = opt;
		
		// number of genres in select menu
		anz = document.productlistfilter.elements["genrefilterviewer"].options.length-1;

		// save into paramter array
		document.productlistfilter.elements["genrefilter["+(anz-1)+"]"].value = code+';'+bez;

		// set first select menu item (headline)
		if (anz == 0)
			anz = 'Alle';
		document.productlistfilter.elements["genrefilterviewer"].options[0].text = 'Genre ('+anz+')';

		// new filter -> set page to 0
		document.productlistfilter.page.value=0;
		
		// close genrebrowser
		if (genreBrowserWin && !genreBrowserWin.closed)
		{
			genreBrowserWin.close();
			genreBrowserWin = null;
		}
		document.productlistfilter.submit();
		return;
	}

	if ('ProductEdit' == currentModule)
	{
		code = code.replace(/ .*/,'');
		document.producteditform.genre.value = code;
		document.producteditform.genrename.value=bez;
		if (genreBrowserWin && !genreBrowserWin.closed)
		{
			genreBrowserWin.close();
			genreBrowserWin = null;
		}
		return;
	}

	alert('genrebrowser paramter handshake error');


}

function delete_genre()
{
	if (document.productlistfilter.elements["genrefilterviewer"].length == 1)
	{
		//alert('Es befindet sich kein Genre im Filter');
		alert(lang_genrefilter_empty);
		return;
	}

	// do nothing when no genre selected
	if (document.productlistfilter.elements["genrefilterviewer"].selectedIndex < 1)
	{
		//alert('Bitte zuerst links ein Genre auswählen');
		alert(lang_genrefilter_select_genre);
		return;
	}

	// remove genre form parameter array
	for (i=document.productlistfilter.elements["genrefilterviewer"].selectedIndex-1; i<9; i++)
		document.productlistfilter.elements["genrefilter["+i+"]"].value=document.productlistfilter.elements["genrefilter["+(i+1)+"]"].value;
	document.productlistfilter.elements["genrefilter[9]"].value='';

	// remove genre from select menu
	document.productlistfilter.elements["genrefilterviewer"].options[document.productlistfilter.elements["genrefilterviewer"].selectedIndex] = null;
	anz = document.productlistfilter.elements["genrefilterviewer"].options.length-1;


	// update first open of select menu (headline)
	if (anz == 0)
		anz = 'Alle';
	document.productlistfilter.elements["genrefilterviewer"].options[0].text = 'Genre ('+anz+')';

	// set page to 0 for resultlist
	document.productlistfilter.page.value=0;
	document.productlistfilter.submit();
}
// CLEAR QUICKSEARCH TRANFERRED TO NAVIGATION TPL FOR MULTILANGUAGE SUPPORT
function selectDate(d,selcolor,stdcolor,cd)
{
	rowselect = 'cal-'+d;
	oldcolor = selcolor;
	if (document.calendarform.select.value.substr(0,6) == cd)
		document.getElementById('cal-'+document.calendarform.select.value).style.backgroundColor = stdcolor;
	document.calendarform.select.value=d;
	if (d != '')
		document.calendarform.showdate.value = d.substr(6,2)+'.'+d.substr(4,2)+'.'+d.substr(0,4);
	else
		document.calendarform.showdate.value = '';
	
	document.getElementById('cal-'+d).style.backgroundColor = selcolor;
}
function selectStartDate(d,selcolor,stdcolor,cd)
{
	rowselect = 'startcal-'+d;
	oldcolor = selcolor;
	if (document.calendarform.startselect.value.substr(0,6) == cd || document.calendarform.startselect.value == '')
		document.getElementById('startcal-'+document.calendarform.startselect.value).style.backgroundColor = stdcolor;
	document.calendarform.startselect.value=d;
	if (d != '')
		document.calendarform.startshowdate.value = d.substr(6,2)+'.'+d.substr(4,2)+'.'+d.substr(0,4);
	else
		document.calendarform.startshowdate.value = '';
	
	document.getElementById('startcal-'+d).style.backgroundColor = selcolor;
}

function selectEndDate(d,selcolor,stdcolor,cd)
{
	rowselect = 'endcal-'+d;
	oldcolor = selcolor;
	if (document.calendarform.endselect.value.substr(0,6) == cd || document.calendarform.endselect.value == '')
		document.getElementById('endcal-'+document.calendarform.endselect.value).style.backgroundColor = stdcolor;
	document.calendarform.endselect.value=d;
	if (d != '')
		document.calendarform.endshowdate.value = d.substr(6,2)+'.'+d.substr(4,2)+'.'+d.substr(0,4);
	else
		document.calendarform.endshowdate.value = '';
	document.getElementById('endcal-'+d).style.backgroundColor = selcolor;
}
function addCalDays(startdate_missing_error)
{
	if (document.calendarform.period.value == 0)
		return; 
		
	if (document.calendarform.startselect.value == '')
	{
		alert(startdate_missing_error);
		return;
	}
	document.calendarform.submit();
}

function setDate1(form,field,d)
{
	document.forms[form].elements[field].value=d;
	if (calendarCBFunc) {
		var temp = calendarCBFunc;
		calendarCBFunc = null;
		temp();
	}
}
function linkWithWarning(url)
{
	if (isTemplateWithForm==true && isModified())
	{
		if (!confirm('Die Eingabe wurde noch nicht gespeichert. Sind sie sicher, dass sie dieses Formular verlassen möchten?'))
			return false;
	}
	self.location.href=url;
}
function htmlencode(s)
{
	s = String(s);
	s = s.replace(/"/,'&quot;');
	s = s.replace(/</,'&lt;');
	s = s.replace(/>/,'&gt;');
	return s;
}
	function resetAliasUser(id)
	{
		document.cookie="useralias=";
	}


