/*
	Java Script functions for Satnet
	written by Tobias Peter, Compustreet GmbH
	Create date August 28th, 2009
*/

function confirmAction(Question, URL) {
	Check = confirm(Question);
	if (Check) {
		window.location = URL;
	} else {
		return false;
	}
}

function Show(layer) {
	var Lay = document.getElementById(layer);
	Lay.style.display = 'block';
}
function Hide(layer) {
	var Lay = document.getElementById(layer);
	Lay.style.display = 'none';
}
function ShowHide(layer) {
	var Lay = document.getElementById(layer);
	if(Lay.style.display = 'none') {
		Lay.style.display = 'block';
	} else {
	Lay.style.display = 'none';
	}
}

function tooltip() {
  this.text = '';
  this.height = 0;
  this.obj = null;
  this.active = false;

  this.create = function(tip_class) {
    if(!this.obj) this.init();

    var t = '<table class ="tooltip"><tr><td>'+ this.text +'</td></tr></table>';

    if(DOM || IE) this.obj.innerHTML = t;
    if(DOM){
		this.width = this.obj.offsetWidth;
		this.height = this.obj.offsetHeight;
	} else if(IE){
		this.width = this.obj.style.pixelWidth;
		this.height = this.obj.style.pixelHeight;
	}
	

    this.move();
    this.show();
  }

  this.init = function() {
    if(DOM) this.obj = document.getElementById('ToolTip');
    else if(IE) this.obj = document.all.ToolTip;
  }

  this.move = function() {
    var winX = getWinX() - (((GK && !SA) || OP) ? 17 : 0);
    var winY = getWinY() - (((GK && !SA) || OP) ? 17 : 0);
    var x = mouseX;
    var y = mouseY;

    if(x + this.width + 10 > winX + getScrX())
      x -= this.width + 10;
    else x += 10;

    if(y + this.height + 10 > winY + getScrY())
      y -= this.height;
    else y += 10;

    this.obj.style.left = x + 'px';
    this.obj.style.top = y + 'px';
  }

  this.show = function() {
    this.obj.style.zIndex = 69;
    this.active = true;
    this.obj.style.visibility = 'visible';
  }

  this.hide = function() {
    this.obj.style.zIndex = -1;
    this.active = false;
    this.obj.style.visibility = 'hidden';
  }

}

function init_download(){
	/* this part shows the popunder on a onclick event at links */
	/*var aTags=document.getElementsByTagName('A');
	var dbg='';
	for(var i=0;i<aTags.length;i++){
		if(aTags[i].href.indexOf('act=view&')!=-1){
			aTags[i].onclick=popUnder;
		}
	}*/
	/*var aTags=document.getElementsByTagName('A');
	var dbg='';
	for(var i=0;i<aTags.length;i++){
		if(aTags[i].id == "download"){
			aTags[i].onclick=popUnder;
		}
	}*/
	
	$('#downloadlist').click(popUnderClick);
	
	/* added 06.10.2009 TP */
	/* this part will show the popunder on body onload event */
	/*var bodyTags = document.getElementsByTagName('body');
	var dbg='';
	for(var i=0;i<bodyTags.length;i++){
		bodyTags[i].onLoad=popUnder();
	}*/
}

function popUnderClick(){
	
	//myWindow=window.open('http://www.satnet.ch/filedb/popunder/popunder_frameset.html','popunder','width=1050,height=810,toolbar=yes,scrollbars=yes,resizable=yes');
	//myWindow.opener.focus();
	popUnderTwoClick();
	popUnderOneClick();
	return true;
	
}

function popUnder(){
	
	//myWindow=window.open('http://www.satnet.ch/filedb/popunder/popunder_frameset.html','popunder','width=1050,height=810,toolbar=yes,scrollbars=yes,resizable=yes');
	//myWindow.opener.focus();
	
	popUnderOne();
	//popUnderTwo();
}


function doOpen(url,wname, pu_w)
{
        var wFeatures = 'width=1050,height=810,toolbar=yes,scrollbars=yes,resizable=yes';
        if(navigator.userAgent.indexOf('Chrome') != -1){
           wFeatures = "scrollbar=yes";
        }
        
        if(!pu_w) {
        	var pu_window = window.open('about:blank',wname,wFeatures +  ',height=780,width=1100');	
        } else {
        	var pu_window = pu_w;
        }
        
        if (pu_window && pu_window.top) {
        	var regex = new RegExp(/rv:[2-9]/);
        	if (regex.exec(navigator.userAgent)) {
        		pu_window.ljPop = function (jsm_url) {

        			if (regex.exec(navigator.userAgent)) { // Gecko 2+
        	       				this.window.open('about:blank').close();
        	       			}
        	       			this.document.location.href = url;
        	       		};
        	       		pu_window.ljPop(url);
        	       	}
        	       	else {
        	       		pu_window.document.location.href = url;
        	       	}
        	       	setTimeout(window.focus);
        	       	window.focus();

        	        if(pu_window) {
        	            pu_window.blur();
        		        puShown = true;
        		        return pu_window;
        		        
        		     }

        	       	return false;
        }else{
	       return false;
        }
}

var clickpopunder = true;
var myWindowOneC = false;
function popUnderOneClick(){
	if(clickpopunder) {myWindowOneC=doOpen('http://www.change.ch','popunderA',myWindowOneC);}
}
var myWindowTwoC = false;
function popUnderTwoClick(){
	if (clickpopunder) {myWindowTwoC=doOpen('http://www.auto-online.ch','popunderB',myWindowTwoC);}
}

function popUnderOne(){
	
	var myWindowTwo=window.open('http://www.change.ch','popunder1','width=1050,height=810,toolbar=yes,scrollbars=yes,resizable=yes');
	
	if (typeof myWindowOne !== "undefined" && typeof myWindowTwo.href !== "undefined" && myWindowOne && myWindowOne.top) {
		myWindowOne.blur();
		myWindowOne.opener.focus();
		clickpopunder = false;
	}
}

function popUnderTwo(){
	
	var myWindowTwo=window.open('http://www.auto-online.ch','popunder2','width=1050,height=810,toolbar=yes,scrollbars=yes,resizable=yes');
	if (typeof myWindowTwo !== "undefined" && typeof myWindowTwo.href !== "undefined" && myWindowTwo && myWindowTwo.top) {
		myWindowTwo.blur();
		myWindowTwo.opener.focus();
		clickpopunder = false;
	}
}

$(function(){

});
	

