/************************************************************************
 functions.js
 ------------------------------------------------------------------------
 begin     : 26.02.2009
 copyright : (C) 2009 by EDV-Service-Garz
 email     : info@edv-service-garz.de
 author    : Frank Gleichmann <f.gleichmann@edv-service-garz.de>
 ------------------------------------------------------------------------
 This document and the includet information are under copyright and can't
 duplicated, reproduced and manipulated without inscriped authorization.
 ************************************************************************/
 
//------------------------------------------------------
/**
  * variables
  **/
var nAniPos = 0;
var tAniImages = new Array();
var tAniNames = new Array();
var tPos  = new Array();
var tPics = new Array();

var lastkey=0;
//----------------------------------------------------------------------------------------------------------------
function GetEventKey (Ev) 
{
	if (!Ev)
		Ev = window.event;
	if (Ev.which) 
	{
		lastkey = Ev.which;
	}
	else if (Ev.keyCode) 
	{
		lastkey = Ev.keyCode;
	}
}
window.document.onkeydown = GetEventKey;

//----------------------------------------------------------------------------------------------------------------
function doDisplayMenue( aName, doOpen, aMaxHeigth, aMinHeigth )
{
	var tParent = document.getElementById( aName );
	if (tParent)
	{
		var sVisible = 'visible';
		var sHeigth = aMaxHeigth;
		if ( !doOpen )
		{
			sVisible = 'hidden';
			sHeigth = aMinHeigth;
		}
		tParent.style.height = sHeigth;
		var tMenue = document.getElementById( aName + '_methods' );
		if ( tMenue )
			tMenue.style.visibility = sVisible;
	}
}

//----------------------------------------------------------------------------------------------------------------
/**
  * to validate if privacy checkbox is checked .
  **/
function doValidateForm( aForm, aMessage )
{
	if ( aForm.privacy.checked )
		return true;
	else
	{
		var bCheck = confirm(aMessage);
		aForm.privacy.checked = bCheck;
		return bCheck;
	}
}

//----------------------------------------------------------------------------------------------------------------
function aniImage( aKey )
{
	this.key = aKey;
	this.images = new Array();
	this.aniPos = 0;
}

//----------------------------------------------------------------------------------------------------------------
/**
  * animate images
  **/
function doAnimateImages()
{
    var tElement;
    if ( tAniImages.length > 0 )
    {
    	/*
	    if ( nAniPos >= tAniImages.length ) 
        	nAniPos = 0;
	    tElement = document.getElementById( tAniNames[nAniPos] );
	    if ( !tElement )
        	continue;
	    tElement.src = tAniImages[nAniPos];
	    nAniPos++;*/
	    for (var i = 0; i < tAniImages.length; ++i)
	    {
	        var tImg = tAniImages[i];
	        if ( tImg.aniPos >= tImg.images.length )
	        	tImg.aniPos = 0;
	        tElement = document.getElementById( tImg.key );
		    if ( !tElement )
        		continue;
        	tElement.src = tImg.images[tImg.aniPos];
	        tImg.aniPos++; 
	    }
	    window.setTimeout( "doAnimateImages()" ,5000);
	}
}

//----------------------------------------------------------------------------------------------------------------
/**
* load resolution dependend images
**/
function loadResolutionImages()
{
	var tElement;
	var tLogo1 = document.getElementById('networkLogo1');
	var tLogo2 = document.getElementById('networkLogo2');
	if(screen.width <=1024)
	{
		//width 150
		if ( tLogo1 )
			tLogo1.src='image/business_ware_for_enterprise150.gif';
		if ( tLogo2 )
			tLogo2.src='image/business_everywhere150.gif';
	}
	else if( (screen.width >1024) && (screen.width < 1600) && (tPics.length > 1))
	{
		//width 175
		if ( tLogo1 )
			tLogo1.src='image/business_ware_for_enterprise175.gif';
		if ( tLogo2 )
			tLogo2.src='image/business_everywhere175.gif';
	}
	else if( (screen.width >= 1600) && (tPics.length > 2))
	{
		//width 200
		if ( tLogo1 )
			tLogo1.src='image/business_ware_for_enterprise.gif';
		if ( tLogo2 )
			tLogo2.src='image/business_everywhere.gif';
	}
	
    for (var i = 0; i < tPos.length; ++i)
    {
        tElement = document.getElementById( tPos[i] );
        if ( !tElement )
            continue;
    
	    if (tPics.length > 0)
	    {
			if(screen.width <=1024)
			{
				tElement.src=tPics[(i*3)+0];
			}
			else if( (screen.width >1024) && (screen.width < 1600) && (tPics.length > 1))
			{
				tElement.src=tPics[(i*3)+1];
			}
			else if( (screen.width >= 1600) && (tPics.length > 2))
			{
				tElement.src=tPics[(i*3)+2];
			}
	    }
    }
    doAnimateImages();
   
    return true;
}

//------------------------------------------------------
/**
  * load resolution depencies
  **/
function loadResolutionDepencies( withNews )
{
		if(screen.width <= 1024)
		{
			document.write("<link href='css/esg/csb_style_1024.css' rel='stylesheet' type='text/css' />");
		}
		else if(screen.width > 1024 && screen.width < 1600)
		{
			document.write("<link href='css/esg/csb_style_1280.css' rel='stylesheet' type='text/css' />");
		}
		
}

//----------------------------------------------------------------------------------------------------------------
/**
* write resultion depended css files
*
* @param string aBaseName of the css file
* @param optional bool isDebug true to alert results
*/
function writeResolutionCssFiles(aBaseName, isDebug, withNews)
{
        if(isDebug)
            alert("css/"+aBaseName+".css");
        if(withNews==1)
			document.write("<link href='css/"+aBaseName+".css' rel='stylesheet' type='text/css' />");
		else
			document.write("<link href='css/"+aBaseName+".css' rel='stylesheet' type='text/css' />");
}

function uebertragen(i)
{
	document.klar.hiddenid.value=i;
	document.klar.submit();
}

function presse(i,seite)
{
	document.von.hiddenid.value=i;
	if(seite==50)
	{
		document.von.action=document.von.action+ '&page=Presse/Pressemitteilungen';
	}
	if(seite==51)
	{
		document.von.action=document.von.action+ '&page=Presse/Presseveroeffentlichungen';
	}
	document.von.submit();
}

function selectEvent( aEventID, aPageKey, aLang , aFormName )
{
	var sLang = "&" + aLang;
	var sFormName = "newsCol";
	if ( aFormName != "" )
		sFormName = aFormName;
		
	var tForm = document.getElementById( sFormName );
	if ( tForm )
	{
		tForm.hiddenid.value= aEventID;
		if ( tForm.action.indexOf('landessprache') >= 0 )
			sLang = '';
		
		if ( aPageKey > 0 )
		{
			switch ( aPageKey )
			{
				case 50: tForm.action=tForm.action+"&page=Presse/Pressemitteilungen"+sLang; break;
				case 51: tForm.action=tForm.action+"&page=Presse/Presseveroeffentlichungen"+sLang; break;
				case 56: tForm.action=tForm.action+"&page=Termine/Messen"+sLang; break;
				case 57: tForm.action=tForm.action+"&page=Termine/Tagungen"+sLang; break;
			    case 58: tForm.action=tForm.action+"&page=Termine/Seminare"+sLang; break;
			    case 59: tForm.action=tForm.action+"&page=Termine/Highlights"+sLang; break;
			    case 119: tForm.action=tForm.action+"&page=Termine/webcasts"+sLang; break;
			    default: tForm.action=tForm.action+"&page=Termine/Messen"+sLang; break;
			}
		}
		tForm.submit();
	}
}

function doGlobalSearch( aSelector, aBasePath, aLang )
{
    var tSearchForm = document.getElementById('globalSearch');
    var tResultForm = document.getElementById('searchResultForm');
    var tTerm = document.getElementById('term');
    
    if ( !tSearchForm )
    	return;	
    	
    if ( ( aSelector == 1 ) && ( tResultForm ))
    {
    	tTerm.value = tResultForm.newTerm.value;
    }
    
    if (tTerm.value != '' )
    {
        tSearchForm.action ='http://'+aBasePath+'?page=search&'+aLang;
        if ( tResultForm )
        {                                                       
	        if ( tResultForm.withContent && !tResultForm.withContent.checked )
            	tSearchForm.withContent.value = 0;
	        if ( tResultForm.withPress && !tResultForm.withPress.checked )
            	tSearchForm.withPress.value = 0;
	        if ( tResultForm.withEvents && !tResultForm.withEvents.checked )
            	tSearchForm.withEvents.value = 0;
            if ( tResultForm.withReferences && !tResultForm.withReferences.checked )
            	tSearchForm.withReferences.value = 0;
            
	        if ( tResultForm.wholeWord && tResultForm.wholeWord.checked )
            	tSearchForm.wholeWord.value = 1;
	        if ( tResultForm.caseSensitive && tResultForm.caseSensitive.checked )
            	tSearchForm.caseSensitive.value = 1;
            if ( tResultForm.regExp && tResultForm.regExp.checked )
            	tSearchForm.regExp.value = 1;
        }
        tSearchForm.submit();
    }
    return false;
}

function setNext( aPageCount )
{
    var tSearchForm = document.getElementById('globalSearch');
    tSearchForm.foundCount.value	= aPageCount;
    tSearchForm.nextResults.value = 'next';
    tSearchForm.prevResults.value = '';
}

function setPrev( aPageCount )
{
    var tSearchForm = document.getElementById('globalSearch');
    tSearchForm.foundCount.value	= aPageCount
    tSearchForm.nextResults.value = '';
    tSearchForm.prevResults.value = 'prev';
}

function doSetCountryLang(aObj, aBasePath)
{
    var sKey=aObj.options[aObj.selectedIndex].value;
    var sPath = 'http://'+aBasePath;
    if ( sPath.indexOf('?') >= 0 )
    {
        sPath +='&landessprache='+sKey;
	}
	else
	{
		sPath +='?landessprache='+sKey;
	}
    window.open(sPath,'_parent','location=yes,toolbar=yes');
    parent.NameDesFrames = sPath;
}

function doSetLang(aObj, aBasePath)
{
    var sProp = document.getElementById('onlyLang');
    var tSearchForm = document.getElementById('globalSearch');
    if ( sProp )
    {
    	tSearchForm.action = 'http://'+aBasePath;
    	sProp.value = aObj.options[aObj.selectedIndex].value;
	    tSearchForm.submit();
	}
	else
	{
		aObj.style.visibility = 'hidden';
	}
}
      
function clearOptions(aOpt, from)
{
	for (i=aOpt.length-1; i>=from ; i--)
	{
		aOpt[aOpt.length - 1] = null;
	}
}
