



/* for image navigation in news */


// class for documents and links preview
function attachment(title,url)
{
	this.title = title;
	this.url = url;
}

// class for image preview
function newsimage(url,legend,linkname,linkurl)
{
	this.url = url;
	this.legend = legend;
	this.linkurl = linkurl;
	this.linkname = linkname;
}




function loadImage(imgarr,aktindex,nid)
{

	var img = document.getElementById("newsimg" + nid);
	
	if(img != null)
	{
	
		if(aktindex != null){


			// get data
			var aktimg = imgarr[aktindex.index];
			
			// set image
			img.src = aktimg.url;
			img.alt = "";// aktimg.legend;
			
			// set navigation status
			var nav = document.getElementById("navstatus" + nid);
			if(nav != null)
				nav.innerHTML = (aktindex.index+1) + " / " + imgarr.length;	
				
			// set link of image to big image
			var link = document.getElementById("imagelink" + nid);
			if(link != null)
				link.href = "?tid=nb&newsid=" + nid + "&aktindex=" + aktindex.index + "&allowback=" + window.location.search.replace(/&/gi,"%26");
			
			// hide imagenavigation if only one image		
			if(imgarr.length <= 1){
				var imagenav = document.getElementById("imagenavigation" + nid);
			
				if(imagenav != null)
					imagenav.style.display = "none";

			}
		}
	}
	
}

function start(imgarr,aktindex,nid)
{

	aktindex.index = 0;
	
	loadImage(imgarr,aktindex,nid);
}

function end(imgarr,aktindex,nid)
{
	aktindex.index = imgarr.length-1;
	
	loadImage(imgarr,aktindex,nid);
}

function next(imgarr,aktindex,nid)
{
	
	aktindex.index++;

	if(aktindex.index >= imgarr.length){
		aktindex.index = 0;
	}
	
	loadImage(imgarr,aktindex,nid);

}

function previous(imgarr,aktindex,nid)
{
	
	aktindex.index--;
	
	if(aktindex.index < 0){
		aktindex.index = imgarr.length-1;
		}
	
	loadImage(imgarr,aktindex,nid);
}


/* for tippboxes on the right */


function hideTippbox(cat)
{
	if(screen.height <= 768){
		if(document.getElementById("tippdiv" + cat) != null)
			document.getElementById("tippdiv" + cat).style.display = 'none';
	}
}



function ChangeNews(titel,link,newsid)
{
	this.title = titel;
	this.imgurl = link;
	this.newsid = newsid;
}


var gi = 1;

/* Automatic switching ob TippBoxes on the right side */
/* gi, tippboxarr are generated by C# */
function switchTippboxes(i){
	
	
	if(tippboxarr != null){
		
		var iold = i-1;
		if(iold < 0)
			iold = tippboxarr.length-1;
		
		
		var oldbox = document.getElementById(tippboxarr[iold]);
		if(oldbox != null)
			oldbox.style.display = 'none';
		
		var newbox = document.getElementById(tippboxarr[i]);
		if(newbox != null)
			newbox.style.display = 'block';
		
		gi = i + 1;
			
		if(gi >= (tippboxarr.length))
			gi = 0;
		
	}

	window.setTimeout("switchTippboxes(" + gi + ")",5000);
}




/* IMAGE CHANGING FOR MENUPOINTS */

var oldImageUrl = '';
var selectedImage = '';
var selectedmenu = '';
var startselmenu = null;



/* changes the url of an image */
function  changeImg(img, url)
{
	img.src = url;
}

/* changes the url of an image except of selectedImage*/
function  changeImg(img, url,id)
{
	if(id != selectedImage)
		img.src = url;
}

/* changes the url of an image */
function changeImgByName(name)
{
	var oldImageUrl = document.getElementById(name);
	oldImageUrl.className = "innermenupoint_select";
	if(document.getElementById("navimg"+name) != null)
		document.getElementById("navimg"+name).src = "../grafik/buttons/pfeil_02einzel.gif";
	startselmenu = name;
	
	/* special for uebergeordnetes personal */
	if(name == 'mbpw' || name == 'mbrw' || name == 'mbre' || name == 'mbpf')
		oldImageUrl.className = "innermenupoint2_select";
}

/* sets picture to last image */
function changeBack(name)
{
	document.images[name].src = oldImageUrl;
}

/* changes the url of an image */
function changeMenubuttonById(name)
{
	var oldImageUrl = document.getElementById(name);
	oldImageUrl.className = "menupoint_select";
}


/* SETTING HEADER */

function setHeaderPic(picpath)
{

	var tab = document.getElementById('headertable');
	
	if(tab != null)
		tab.style.backgroundImage = "url(" + picpath + ")";

}

var currentHeader = "";


/* set the small header when header is shrinked */
function makeHeaderSmall(imgurl)
{
	if(imgurl == null)
		imgurl = 'klein_net.jpg';

	var tab = document.getElementById('headertable');
	
	if(tab != null){
		tab.style.backgroundImage = "url(../grafik/header/pic/" + imgurl + ")";
		tab.style.height = '54';
	}
}

function makeHeaderBig()
{

	var tab = document.getElementById('headertable');
	if(tab != null){
		tab.style.height = 234;
	}
}


/* CALCULATING HIGH OF CONTENT */

var Hoehe = 0;



//berechnet die hoehe der divs neu bei normaler grösse des headers
function neuAufbau()
{

	if (Hoehe != Fensterhoehe())
		Hoehe = Fensterhoehe();
		
	// ie explorer can go more down
	if(navigator.userAgent.indexOf("MSIE") > -1)
		Hoehe = Hoehe + 10;
		
		
	if(document.getElementById("scrollablecontent") != null && Hoehe > 351)
		document.getElementById("scrollablecontent").style.height = Hoehe - 352;
	if(document.getElementById("fotocatdiv") != null && Hoehe > 270)
		document.getElementById("fotocatdiv").style.height = Hoehe - 332;
	if(document.getElementById("imagediv") != null && Hoehe > 200)
		document.getElementById("imagediv").style.height = Hoehe - 381;
	if(document.getElementById("subimagediv") != null && Hoehe > 200)
		document.getElementById("subimagediv").style.height = Hoehe - 430;
	if(document.getElementById("previewDiv") != null && Hoehe > 100)
		document.getElementById("previewDiv").style.height = Hoehe - 430;
	if(document.getElementById("geschichtediv") != null && Hoehe > 200)
		document.getElementById("geschichtediv").style.height = Hoehe - 432;
	if(document.getElementById("startmain") != null && Hoehe > 200)
		document.getElementById("startmain").style.height = Hoehe - 257;
	if(document.getElementById("startmaincms") != null && Hoehe > 200)
		document.getElementById("startmaincms").style.height = Hoehe - 275;
		
	
	//shopdivs
	if(document.getElementById("warenkorbdiv") != null && Hoehe > 508)
		document.getElementById("warenkorbdiv").style.height = Hoehe - 508;
	if(document.getElementById("contentdiv") != null && Hoehe > 441)
		document.getElementById("contentdiv").style.height = Hoehe - 441;
	if(document.getElementById("comparediv") != null && Hoehe > 500)
		document.getElementById("comparediv").style.height = Hoehe - 500;
	if(document.getElementById("detaildiv") != null && Hoehe > 413)
		document.getElementById("detaildiv").style.height = Hoehe - 413;
	if(document.getElementById("meinshopdiv") != null && Hoehe > 543)
		document.getElementById("meinshopdiv").style.height = Hoehe - 543;
	if(document.getElementById("contentpage") != null && Hoehe > 510)
		document.getElementById("contentpage").style.height = Hoehe - 510;
	if(document.getElementById("maindiv") != null && navigator.userAgent.indexOf("MSIE") == -1  && Hoehe > 10 )
		document.getElementById("maindiv").style.height = Hoehe-10;
		
	var Id = window.setTimeout("neuAufbau();",1000);
	
}


//berechnet die hoehe der divs neu wenn header minimiert ist
function neuAufbauSmall()
{

	if (Hoehe != Fensterhoehe())
		Hoehe = Fensterhoehe();
		
	// ie explorer can go more down
	if(navigator.userAgent.indexOf("MSIE") > -1)
		Hoehe = Hoehe + 10;
		
	if(document.getElementById("scrollablecontent") != null && Hoehe > 185)
		document.getElementById("scrollablecontent").style.height = Hoehe - 194;
	if(document.getElementById("fotocatdiv") != null && Hoehe > 270)
		document.getElementById("fotocatdiv").style.height = Hoehe - 361;
	if(document.getElementById("imagediv") != null && Hoehe > 150)
		document.getElementById("imagediv").style.height = Hoehe - 234;
	if(document.getElementById("previewdiv") != null && Hoehe > 150)
		document.getElementById("previewdiv").style.height = Hoehe - 234;
	if(document.getElementById("geschichtediv") != null && Hoehe > 200)
		document.getElementById("geschichtediv").style.height = Hoehe - 272;
	if(document.getElementById("maindiv") != null && navigator.userAgent.indexOf("MSIE") == -1  && Hoehe > 10 )
		document.getElementById("maindiv").style.height = Hoehe-10;

	//shopdivs
	if(document.getElementById("warenkorbdiv") != null && Hoehe > 334)
		document.getElementById("warenkorbdiv").style.height = Hoehe - 334;
	if(document.getElementById("contentdiv") != null && Hoehe > 267)
		document.getElementById("contentdiv").style.height = Hoehe - 267;
	if(document.getElementById("comparediv") != null && Hoehe > 200)
		document.getElementById("comparediv").style.height = Hoehe - 200;
	if(document.getElementById("detaildiv") != null && Hoehe > 235)
		document.getElementById("detaildiv").style.height = Hoehe - 235;
	if(document.getElementById("meinshopdiv") != null && Hoehe > 243)
		document.getElementById("meinshopdiv").style.height = Hoehe - 243;
	if(document.getElementById("contentpage") != null && Hoehe > 310)
		document.getElementById("contentpage").style.height = Hoehe - 310;
		
		
	var Id = window.setTimeout("neuAufbauSmall();",1000);
}

function Fensterhoehe() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myHeight = document.documentElement.clientHeight;
  } else if( document.body &&  document.body.clientHeight ) {
    //IE 4 compatible
    myHeight = document.body.clientHeight;
  }
  
  return myHeight;
}

function popup(querystring,x,y)
{
	var nwl = (screen.width-x)/2;
	var nwh = (screen.height-y)/2;		
	popup=window.open('http://www.gmg.biz/popup.aspx?id='+querystring, 'Lageplan', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+x+',height='+y+',left='+nwl+',top='+nwh+''); 
}

/* FOR POPUPS */

var wmtt = null;


function fly_move(e) {

	if(navigator.userAgent.toLowerCase().indexOf('firefox') < 0){
		if (wmtt != null) {
			wmtt.style.left = (window.event.clientX +  document.body.scrollLeft + 12);
			wmtt.style.top 	= (window.event.clientY +  document.body.scrollTop + 12);
		}
	}
}



/* 
text ==> text that will be written into the div 
divname ==> name of div that will be shown 
*/

function fly_start(text, divname) {
	if(text != ""){
		if (document.layers){
			//Netscape 4 specific code
			pre = 'document.';
			post = '';
			post1 = '';		
			scr_h = window.innerHeight;
		}
		if (document.getElementById){
			//Netscape 6 specific code
			pre = 'document.getElementById("';
			post = '").style';
			post1 = '")';		
			scr_h = window.innerHeight;

		}
		if (document.all){
			//IE4+ specific code
			pre = 'document.all.';
			post = '.style';
			post1 = '';		
			scr_h = document.body.clientHeight;
		}
		
		// standard is overdiv
		if(divname == "")
			divname = "overDiv";
			
		wmtt = null;
		wmtt = eval(pre + divname + post1);	
		
		
		if (wmtt != null) 
		{

			wmtt.innerHTML = text;	
			wmtt.style.display = "block";	
		}
	}
}


function fly_stop() {
	if (wmtt != null) {
		wmtt.style.display = "none";
		wmtt = null;
		}
}


function selectMenu(menuid)
{
	selectedmenu = menuid;
	document.getElementById(menuid).className = "innermenupoint_select";
	document.getElementById("navimg"+menuid).src = "../grafik/buttons/pfeil_02.gif";
}

function deselectMenu()
{
	if(startselmenu != selectedmenu && selectedmenu != "")
	{
		document.getElementById(selectedmenu).className = "innermenupoint";
		document.getElementById("navimg"+selectedmenu).src = "../grafik/buttons/pfeil_01.gif";
	}
	else if(selectedmenu == startselmenu){
		document.getElementById("navimg"+startselmenu).src = "../grafik/buttons/pfeil_02einzel.gif";
	}
}


var gAutoPrint = false; // Flag for whether or not to automatically call the print function

function printscreen(name,url)
{
	if (document.layers){
	//Netscape 4 specific code
		pre = 'document.';
		post1 = '';
	}
	if (document.getElementById){
		//Netscape 6 specific code
		pre = 'document.getElementById("';
		post1 = '")';
	}
	if (document.all){
		//IE4+ specific code
		pre = 'document.all.';
		post1 = '';		
	}
	
	var pic = "gmgverlag_logo.jpg";
	if(name.indexOf("uchhandl") > -1)
		pic = "gmgbuchhandlung_logo.jpg";
	else if(name.indexOf("omputer") > -1)
		pic = "gmgcomputer_logo.jpg";
	else if(name.indexOf("edia") > -1)
		pic = "gmgmedia_logo.jpg";
	else if(name.indexOf("et") > -1)
		pic = "gmgnet_logo.jpg";

	if (eval(pre+'fo_pnlPicture'+post1)!=null)
	{
		var myLayer = eval(pre+'imagediv'+post1);
	}
	else
	{
		var myLayer = eval(pre + 'scrollablecontent' + post1);
	}
	
	var myLayerhead = eval(pre + 'printdiv' + post1);
	
	today = new Date();
	var strDateTime = today.getDate() + "." + (today.getMonth()+1) + "." + today.getFullYear() + ", " + today.toLocaleTimeString() + " Uhr";
		
	var parameter = "menubar=yes,toolbar=yes,scrollbars=yes,statusbar=no,location=no,resizable=yes,width=750px,height=520px";
	var printWin = window.open("","print",parameter);
	var text = "<img src=\"../grafik/"+pic+"\" border=\"0\"><br><br><table width=100%><tr><td class=printheader style=\"padding-bottom:4px\"><b>"+name+" - "+myLayerhead.innerText+"</b></td></tr><tr><td align=right style=\"font-size:10px\">"+strDateTime+"</td></table><br>";
	text += "<br>"+myLayer.innerHTML.replace(/<< back/,"").replace(/&lt;&lt; back/,"");
	text = text.replace(/<a/,"<a style='disable:true'").replace(/<A/,"<a style='disable:true'");

	printWin.document.open();	
	printWin.document.write("<html><head><link href='../gmg.css' rel='stylesheet' type='text/css'></link></head><style> body {background-color:white;margin:10px 10px 10px 10px;}</style><body><div class='text'><form onsubmit='return false;'>" + text + "</form></div><br><table width=100%><tr><td class=printheader style=\"padding-bottom:4px\">" + document.URL + "</td></tr><tr><td align=right style=\"font-size:10px;margin-top:0px\">&copy; 2005 Copyright GMG AG</td></tr></table></body></html>");
	printWin.document.close();
	if (gAutoPrint)
		printWin.print();
}




// enable scrolling for mozilla with mousewheel
function enableScrolling()
{
	if(navigator.userAgent.toLowerCase().indexOf("mozilla") > -1){
		if (document.body.addEventListener) {
			var divs = document.getElementsByTagName('DIV');
			for (var d in divs) {
				if (divs[d].className && divs[d].className == 'scroll') { // all divs mit classname "scroll"
					try {
						divs[d].addEventListener('DOMMouseScroll', scrollMe, false);
					} catch (ex) {}
				}
			}
		}
	}

}

// enable scrolling for overflow:auto elements in Mozilla
	function scrollMe(event)
	{
		var st = event.currentTarget.scrollTop + (event.detail * 12);
		event.currentTarget.scrollTop = st < 0 ? 0 : st;
		event.preventDefault();
	}

// CMS POPUP
function getDocWidth()
		{
					if (document.body)
					{
						docWidth = document.body.clientWidth;
						if (!isNaN(docWidth)) return document.body.clientWidth;
						else
						{
							return self.innerWidth;
						}
					}
					else if (self)
					{
						return self.innerWidth + 4; // NS Korrekturfaktor (+/- 1)
					}
		}

		// function returns the document - height (pixel)
		function getDocHeight()
		{
			if (document.body)
					{
						docHeight = document.body.clientHeight;
						if (!isNaN(docHeight)) return docHeight;
						else
							return self.innerHeight;
					}
					else if (self)
					{
						return self.innerHeight + 4; // NS Korrekturfaktor (+/- 1)

					}
		}
		
	function openCMS()
	{
	
		link = "http://login.gmgnet.li/cmsv3/protected/selectproject1.aspx?h="+getDocWidth()+"&v="+getDocHeight();

		window.open(link,"GMG_Management_System","Toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1, width=" + screen.width + ",height=" + screen.height);	
	}

