var DEBUG = 0;
var MOZILLA = 0;
var flashToClose = '';
var naviCount=0;


if(navigator.appCodeName == 'Mozilla')
{
    var MOZILLA = 1;
}
else
{
    var MOZILLA = 0;
}

/******** Mauszeigerposition ********/

var xPos=0;
var yPos=0;

if(document.layers)
{
    window.captureEvents(Event.MOUSEMOVE);
    window.onmousemove = mouseCoordinates;
}
else
{
    document.onmousemove = mouseCoordinates;
}

function mouseCoordinates(e)
{
 //   xPos = (document.layers || (document.getElementById && !document.all)) ? e.pageX : document.body.scrollLeft + event.clientX;
 //   yPos = (document.layers || (document.getElementById && !document.all)) ? e.pageY : document.body.scrollTop + event.clientY;

    xPos = (document.layers || (document.getElementById && !document.all)) ? e.pageX : document.documentElement.scrollLeft + event.clientX;
    yPos = (document.layers || (document.getElementById && !document.all)) ? e.pageY : document.documentElement.scrollTop + event.clientY;

    yPos=yPos-5;
    xPos=xPos+140;

}

function openSearch(mnogo_needle,lng,gate){
	openSearchGateway(mnogo_needle,lng,'')
}

function openSearchGateway(mnogo_needle,lng,gate)
{ 
    var wert=document.getElementById('mnogo_se').value;
    var str_url=gate+'/search.php?q='+wert+'&ps=5&ul='+mnogo_needle+'&lng='+lng; 
    var w_mnogo = window.open(str_url, 'w_mnogo', 'width=500, height=600, scrollbars=yes, resizable=yes');
    w_mnogo.focus(); 
    return true;
}

function onEnter( evt, mnogo_needle, lng ) {
    var keyCode = null;

    if( evt.which ) {
        keyCode = evt.which;
    } else if( evt.keyCode ) {
        keyCode = evt.keyCode;
    }
    if( 13 == keyCode )
        openSearch(mnogo_needle,lng)
    return true;
}


function openPopup(url,groupId,articleKey,pageIndex,width,height,sessName,sessId) {
	newwindow=window.open(url+'?groupId='+groupId+'&articleKey='+articleKey+'&pageIndex='+pageIndex+'&'+sessName+'='+sessId,'name','height='+height+',width='+width+', scrollbars=yes, resizable=yes');
	if (window.focus) {newwindow.focus()}
	return false;
}


function moveUlNaviForward(){
	if(document.getElementById('menu_navi_ul').childNodes.length -6 > naviCount){
		var i=0;
		loesch=document.getElementById("menu_navi_ul").lastChild;
	//	newInnerHTML=document.getElementById("naviA"+i+6).innerHTML;
		
		
		document.getElementById("menu_navi_ul").removeChild(loesch);
		document.getElementById("menu_navi_ul").firstChild.style.visibility='hidden';
		document.getElementById("menu_navi_ul").firstChild.style.width='0';
		document.getElementById("menu_navi_ul").firstChild.style.display='none';
	
		document.getElementById('menu_navi_ul').childNodes[i+5].style.width='137px';
		document.getElementById('menu_navi_ul').childNodes[i+5].style.display='block';
		document.getElementById('menu_navi_ul').childNodes[i+5].style.visibility='visible';
		document.getElementById('menu_navi_ul').appendChild(document.getElementById("menu_navi_ul").firstChild);
		document.getElementById("menu_navi_ul").appendChild(loesch);
		if(document.getElementById('menu_navi_ul').childNodes.length -7 == naviCount)document.getElementById("lastNaviLi").innerHTML=' ';
		else document.getElementById("lastNaviLi").innerHTML=document.getElementById("menu_navi_ul").childNodes[5].title.substr(0, 3)+'...';
		
		naviCount++;
	}
//	document.getElementById("lastNaviLi").innerHTML=newInnerHTML;
}




function moveUlNaviBackward(){
	if(naviCount>0){
		var i=0;
	
		loesch=document.getElementById("menu_navi_ul").lastChild;
		document.getElementById("menu_navi_ul").removeChild(loesch);
		document.getElementById('menu_navi_ul').insertBefore(document.getElementById("menu_navi_ul").lastChild,document.getElementById("menu_navi_ul").firstChild);
		document.getElementById("menu_navi_ul").firstChild.style.visibility='visible';
		document.getElementById("menu_navi_ul").firstChild.style.width='137px';
		document.getElementById("menu_navi_ul").firstChild.style.display='block';
	
		document.getElementById('menu_navi_ul').childNodes[5].style.width='0px';
		document.getElementById('menu_navi_ul').childNodes[5].style.display='none';
		document.getElementById('menu_navi_ul').childNodes[5].style.visibility='hidden';
		document.getElementById("menu_navi_ul").appendChild(loesch);
		document.getElementById("lastNaviLi").innerHTML=document.getElementById("menu_navi_ul").childNodes[5].title.substr(0, 3)+'...';
		naviCount--;
	}
	
}

/*
function _closeSpyhole()
{
    if(mySpyhole)
    {
        mySpyhole.close();
    }
}








/*
function _loadPageContainer(pageID, paging, scale, session)
{
    this.closeSpyhole();

    this.logMessage('loadPageContainer > pageID: ' + pageID + ' / scale: ' + scale + ' / paging: ' + paging);

    var getElementID    = 'elementID=pageContainer';
    var getControl      = 'control=page';
    var getSession      = 'smart42SID=' + session;
    var getPageID       = 'pageID=' + pageID;
    var getScale        = scale != null ? 'scale=' + scale : 'scale=' + ($('com_param_scale') ? $('com_param_scale').innerHTML : '1');
    var getPaging       = paging != null ? 'paging=' + paging : 'paging=' + ($('com_param_paging') ? $('com_param_paging').innerHTML : '2');

    $('pageContainer').innerHTML = '...';
    $('pageContainer').innerHTML = '<div style="padding-top: 300px; text-align: center;"><img src="/img/icon/loading.gif" alt="Noch ein wenig Geduld..." /></div>';

    ajaxEngine.sendRequest('mainEntryPoint', this.getRequestMode, this.getType, getElementID, getControl, getPageID, getScale, getPaging, getSession);
}

function _loadPageBrowserContainer(issueID, paging, scale, view)
{
    this.closeSpyhole();
    this.logMessage('loadPageBrowserContainer > issueID: ' + issueID + ' / scale: ' + scale + ' / paging: ' + paging + ' / view: ' + view);

    var getElementID    = 'elementID=pageBrowserContainer';
    var getControl      = 'control=pageBrowser';
    var getPageID       = 'issueID=' + issueID;
    var getScale        = 'scale=' + scale;
    var getPaging       = 'paging=' + paging;
    var getView         = 'view=' + view;
    
    $('pageBrowserContainer').innerHTML = '...';
    $('pageBrowserContainer').innerHTML = '<div style="padding-top: 300px; text-align: center;"><img src="/img/icon/loading.gif" alt="..." /></div>';

    ajaxEngine.sendRequest('mainEntryPoint', this.getRequestMode, this.getType, getElementID, getControl, getPageID, getScale, getPaging, getView);
}

function _loadSearchResultContainer()
{
    this.closeSpyhole();
    this.logMessage('loadSearchResultContainer > ' + contentURL);
}

function _logMessage(message)
{
    if(MOZILLA && DEBUG)
    {
       // console.log(message);
    }
}

function ContentManager()
{
    this.contentURL                 = 'index.php';
    this.getRequestMode             = 'requestMode=snippet';
    this.getType                    = 'type=element';
    this.loadPageContainer          = _loadPageContainer;
    this.loadPageBrowserContainer   = _loadPageBrowserContainer;
    this.loadSearchResultContainer  = _loadSearchResultContainer;
    this.logMessage                 = _logMessage;
    this.closeSpyhole               = _closeSpyhole;

    this.logMessage('construct > ');
}*/

function setFlash(swf,flv,width,height,id,size,schliessen){
	

//	videoPlayer();
	for(i=0;i<size;i++){
		document.getElementById('flashdiv'+i).innerHTML=' ';
	}
	
	if(document.getElementById('flashdiv'+id).innerHTML==' ' || document.getElementById('flashdiv'+id).innerHTML=='')document.getElementById('flashdiv'+id).innerHTML='<div type="submit"  class="close_flash2" onclick="removeChilds(\'flashdiv'+id+'\');" />'+schliessen+'</div><br/><div style="border:0px solid black;z-index:100000001;width:'+(width)+'px" class="videoDiv"><embed  src="'+swf+'?derfilmfilm='+flv+'" quality="high" scale="exactfit" menu="true" wmode="opaque"    loop="false"  width="'+width+'"  height="'+height+'"    bgcolor="#FFFFFF" swLiveConnect="false"    type="application/x-shockwave-flash"    pluginspage="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"></embed></div>';

}


function setFlash4(swf,flv,width,height,id,size,schliessen){
	/*


	for(i=0;i<size;i++){
		document.getElementById('flashdiv'+i).innerHTML=' ';
	}
	*/
	smallVideoPlayer();

	if(document.getElementById('flashdiv'+id).innerHTML==' ' || document.getElementById('flashdiv'+id).innerHTML==''){ 
//		document.getElementById('flashdiv'+id).style.height='300px;'
//		document.getElementById('flashdiv'+id).style.width='400px;'
		document.getElementById('flashdiv'+id).innerHTML='<div  class="close_flash" style="z-index:1000" value="'+schliessen+'" onclick="removeChilds(\'flashdiv'+id+'\');" style="cursor:pointer"/>'+schliessen+'</div><div style="border:15px solid black;width:'+(width)+'px"><embed src="'+swf+'?derfilmfilm='+flv+'" quality="high" scale="exactfit" menu="true" wmode="opaque"    loop="false"  width="'+width+'"  height="'+height+'"    bgcolor="#FFFFFF" swLiveConnect="false"    type="application/x-shockwave-flash"    pluginspage="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"></embed></div>'; 
	}

}



function setFlash3(url,swf,flv,width,height,id,size,issueid,schliessen,groupId){
	
	
	
	/*


	for(i=0;i<size;i++){
		document.getElementById('flashdiv'+i).innerHTML=' ';
	}
	*/
	videoPlayer();
	if(document.getElementById('flashdiv'+id).innerHTML==' ' || document.getElementById('flashdiv'+id).innerHTML==''){ 
//		document.getElementById('flashdiv'+id).style.height='300px;'
//		document.getElementById('flashdiv'+id).style.width='400px;'
		document.getElementById('flashdiv'+id).innerHTML='<div id="player" class="player" style="visibility: visible;">    <div class="playerBack">    <a class="PlayerLink" style="float: right;" onclick="removeChilds(\'flashdiv'+id+'\');">close</a>            <object height="400" width="550" type="application/x-shockwave-flash" data="videoPlayer.swf" id="videoPlayer" style="visibility: visible;"><param name="allowFullScreen" value="true"/><param name="flashvars" value="htmlPage=http://'+url+'/?mode=mediapdf&amp;settingsFile=http://'+url+'/settings.php?issueid='+issueid+'&amp;groupId='+groupId+'"/></object>        </div></div>';



/*<div  class="close_flash" style="z-index:1000" value="'+schliessen+'" onclick="removeChilds(\'flashdiv'+id+'\');" style="cursor:pointer"/>'+schliessen+'</div><div style="border:15px solid black;z-index:1000;width:'+(width)+'px"><embed src="'+swf+'?derfilmfilm='+flv+'" quality="high" scale="exactfit" menu="true" wmode="opaque"    loop="false"  width="'+width+'"  height="'+height+'"    bgcolor="#FFFFFF" swLiveConnect="false"    type="application/x-shockwave-flash"    pluginspage="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"></embed></div> */
	}

}

function setFlash2(url,issueid,groupId){ 
	
				var flashvars = {
				  htmlPage: document.location,
				  settingsFile: 'http://'+url+'/settings.php?issueandgroupid='+issueid+'-'+groupId
				};
				var params = {
				  allowFullScreen: "true"
				};
				
				swfobject.embedSWF("http://"+url+"/videoPlayer.swf", "videoPlayer", "550", "400", "9.0.115", "js/expressInstall.swf", flashvars, params);

	videoPlayer();




	

}


function removeChilds(id){ 
	flashToClose=id;
	window.setTimeout("removeChilds2()", 300); 
	
//	document.getElementById(id).style.height='1px;'
//	document.getElementById(id).style.width='1px;'
	return false;
}

function removeChilds2(){ 
	if(flashToClose!=0){
		
		obj = document.getElementById(flashToClose);	
			if(obj.hasChildNodes()){
				while(obj.hasChildNodes()){
					firstChild = obj.firstChild;
					obj.removeChild(firstChild);
				}
			
			
			
			
		}
	}
	if(document.getElementById('layerBlack')){
		document.getElementById('layerBlack').style.display = 'none';
	}else{
		document.getElementById("darkNight").style.display = 'none';
	}
}
/*
function setFlash(swf,flv,width,height,id,size,schliessen){
	
	for(i=0;i<size;i++){
		document.getElementById('flashdiv'+i).innerHTML='';
	}
	
	
	document.getElementById('flashdiv'+id).innerHTML='<input type="submit" class="close_flash" value="'+schliessen+'" onclick="document.getElementById(\'flashdiv'+id+'\').innerHTML=\'\';" /><br/><embed  src="'+swf+'?derfilmfilm='+flv+'" quality="high" scale="exactfit" menu="true" wmode="opaque"    loop="false"  width="'+width+'"  height="'+height+'"    bgcolor="#FFFFFF" swLiveConnect="false"    type="application/x-shockwave-flash"    pluginspage="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"></embed>';
}*/

/******** Tooltip ********/

function showTooltip(tooltipID)
{
    if(MOZILLA && DEBUG)
    {
        //console.log('showTooltip > ' + tooltipID);
    }
    if(document.getElementById('tooltipContainer').hasChildNodes)
    {
        var node = document.getElementById('tooltipContainer').firstChild;
        var next = null;

        while(node)
        {
            next = node.nextSibling;
            node.style.display = 'none';
            node = next;
        }
    }
    document.getElementById('tooltipContainer').appendChild(document.getElementById(tooltipID));

    //console.log('tooltip width: ' + $(tooltipID).width);
    document.getElementById(tooltipID).style.left = (xPos - 130) + 'px';
    document.getElementById(tooltipID).style.top = (yPos + 25) + 'px';
    document.getElementById(tooltipID).style.display = 'block';
    
}

function hideTooltip(tooltipID)
{
    if(MOZILLA && DEBUG)
    {
        //console.log('hideTooltip > ' + tooltipID);
    }
    document.getElementById(tooltipID).style.display = 'none';
}

function checkCheckboxes(lang){
	checkboxList = document.getElementsByName('articleKey[]');
	
	var i=0;
	while(checkboxList[i]){
		if(checkboxList[i].checked == true) return true;
		i++;
	}
	if(lang=='de')alert('Bitte markieren Sie mindestens einen Beitrag');
	else alert('Please choose at least one article');
	return false;
}

function checkCheckboxes(lang){
	checkboxList = document.getElementsByName('articleKey[]');
	
	var i=0;
	while(checkboxList[i]){
		if(checkboxList[i].checked == true) return true;
		i++;
	}
	if(lang=='de')alert('Bitte markieren Sie mindestens einen Beitrag');
	else alert('Please choose at least one article');
	return false;
}



function checkPageKeyCheckboxes(){
	checkboxList = document.getElementsByName('articleKey[]');
	
	var i=0;
	while(checkboxList[i]){
		if(checkboxList[i].checked == true) return true;
		i++;
	}
	if(lang=='de')alert('Bitte markieren Sie mindestens eine Seite');
	else alert('Please choose at least one page');
	return false;
}

function selectAllCheckboxes(obj){
/*	obj.checked == (false) ? status = false : status = 'true';
	checkboxList = document.getElementsByName('articleKey[]');
	for (checkboxIndex in checkboxList){
		checkboxList[checkboxIndex].checked = status;
	}*/
	obj.checked == ('false') ? status = 'false' : status = 'true'; 
	checkboxList = document.getElementsByName('articleKey[]');
	var i=0;
	while(checkboxList[i]){
		checkboxList[i].checked = obj.checked;
		i++;
	}
}

function checkAllCheckboxes(){	
	var urlPages = '';
	var selectedPages = document.getElementsByName('pageIdList[]');
	
	for(var i = 0;i<selectedPages.length;i++){
		if(selectedPages[i].checked == true){
			urlPages = urlPages + '&pageIdList[]=' +  selectedPages[i].value;
		}
	}
	

	
	if(urlPages==''){
		document.getElementById('create_pdf_link').href='JavaScript:alert("Bitte markieren Sie mindestens eine Seite!");';
		document.getElementById('create_pdf_link').target='';
	}else{
		urlPages = urlPages + '&journalKey=' + document.getElementById('journalKey').value + '&volumeKey=' + document.getElementById('volumeKey').value+ '&issueKey=' + document.getElementById('issueKey').value;
		document.getElementById('create_pdf_link').href='pagepdf.php?'+document.getElementById('sessionName').value+'='+document.getElementById('sessionValue').value+'1'+urlPages;
		document.getElementById('create_pdf_link').target='_blank';
	}
}

function checkIfAllCheckboxesAreSelected(){
	var selectedPages = document.getElementsByName('pageIdList[]');
	var count=0;
	for(var i = 0;i<selectedPages.length;i++){
		if(selectedPages[i].checked == true){
			count++;
		}
	}
	if(count==selectedPages.length)return true;
	else return false;
}

function selectAllPageIdCheckboxes(obj){
/*	obj.checked == (false) ? status = false : status = 'true';
	checkboxList = document.getElementsByName('articleKey[]');
	for (checkboxIndex in checkboxList){
		checkboxList[checkboxIndex].checked = status;
	}*/
	obj.checked == ('false') ? status = 'false' : status = 'true'; 
	checkboxList = document.getElementsByName('pageIdList[]');
	var i=0;
	while(checkboxList[i]){
		checkboxList[i].checked = obj.checked;
		i++;
	}
}

function setYoutube(src,width,height,id,size,schliessen){

	for(i=0;i<size;i++){
		document.getElementById('flashdiv'+i).innerHTML='';
	}	
	
	document.getElementById('flashdiv'+id).innerHTML='<div  class="close_flash" style="z-index:1000" value="'+schliessen+'" onclick="removeChilds(\'flashdiv'+id+'\');" style="cursor:pointer;z-index:100000001"/>'+schliessen+'</div><div style="border:0px solid black;z-index:1000;width:'+(width)+'px"><object width="'+width+'" height="'+height+'"><param name="movie" value="'+src+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+src+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+width+'" height="'+height+'"></embed></object></div>';
}

function setYoutube2(src,width,height,id,size,schliessen){
	videoPlayer();
	for(i=0;i<size;i++){
		document.getElementById('flashdiv'+i).innerHTML='';
	}	
	
	document.getElementById('flashdiv'+id).innerHTML='<div  class="close_flash" style="z-index:1000" value="'+schliessen+'" onclick="removeChilds(\'flashdiv'+id+'\');" style="cursor:pointer;z-index:100000001"/>'+schliessen+'</div><div style="border:15px solid black;z-index:1000;width:'+(width)+'px"><object width="'+width+'" height="'+height+'"><param name="movie" value="'+src+'"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="'+src+'" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="'+width+'" height="'+height+'"></embed></object></div>';
}


function addbookmark(bookmarkurl,bookmarktitle){
    if (document.all)
    window.external.AddFavorite(bookmarkurl,bookmarktitle)//IE
    else window.sidebar.addPanel( bookmarktitle, bookmarkurl, '' );//Moz
}

function videoPlayer() {
	
	document.getElementById("videoPlayer").style.visibility = "visible";
	document.getElementById("player").style.visibility = "visible";
	if(document.getElementById('layerBlack')){
		pageSize = getThisPageSize();
		
		document.getElementById('layerBlack').style.width=pageSize[0] + 'px';
		document.getElementById('layerBlack').style.height=pageSize[1] + 'px';
		document.getElementById('layerBlack').style.display = '';
	}else{
		document.getElementById("darkNight").style.height = document.body.clientHeight+"px";
		document.getElementById("darkNight").style.display = "block";
	}
	document.getElementById("player").style.top=(yPos-200)+'px';
	return false;
	
}

function smallVideoPlayer() {
	if(document.getElementById('layerBlack')){
		//document.getElementById('layerBlack').style.display = '';
	}else{
		document.getElementById("darkNight").style.height = document.body.clientHeight+"px";
		document.getElementById("darkNight").style.display = "block";
	}
	return false;
	
}

function videoPlKill() {
	document.getElementById("videoPlayer").style.visibility = "hidden";
	document.getElementById("player").style.visibility = "hidden";
	if(document.getElementById('layerBlack')){
		document.getElementById('layerBlack').style.display = 'none';
	}else{
		document.getElementById("darkNight").style.display = "none";
	}
	var flashvars = {
		htmlPage: document.location,
		settingsFile: '/emptySettings.xml'
	};
		var params = {
		allowFullScreen: "true"
	};
				
	swfobject.embedSWF("videoPlayer.swf", "videoPlayer", "550", "400", "9.0.115", "swfobject/expressInstall.swf", flashvars, params);

}

function writeWithTimeout(id,ord){
	string='<script language="JavaScript" src="http://ad.de.doubleclick.net/adj/'+id+'/home;pos=1;sz=300x250;tile=2;ord=' + ord + '?" type="text/javascript"></scr' + 'ipt>';
	setTimeout('document.write(\''+string+'\')',0);
}

function openConfirmPopup(url) {
	fenster = window.open(url,"_blank", "toolbars=no,menubar=no,width=400,height=100,status=yes,scrollbars=no,resizable=no");
	fenster.focus();
}


