<!-- RCSid: $Header: /opt1/utm/dump101119/src/plattform/infra/docs/js/window2.js,v 1.1.2.2 2006-09-28 11:59:51 mape051 Exp $ -->
/**
ANVÄND INTE VID NYUTVECKLING
FINNS HÄR FÖR ATT admin/cc KRÄVER DET
**/

function wbsniff(){ //Browsercheck
	this.ver=navigator.appVersion.toLowerCase();
	this.agent=navigator.userAgent.toLowerCase();
	this.dom=document.getElementById?1:0
	this.opera5=(navigator.userAgent.indexOf("opera")>-1 && document.getElementById)?1:0
	this.ie5=(this.ver.indexOf("msie 5")>-1 && this.dom && !this.opera5)?1:0;
	this.ie6=(this.ver.indexOf("msie 6")>-1 && this.dom && !this.opera5)?1:0;
	this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
	this.ie=this.ie4||this.ie5||this.ie6
	this.mac=this.agent.indexOf("mac")>-1
	this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
	this.ns4=(document.layers && !this.dom)?1:0;
	this.wb=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5)
	return this
}

function unescape_aa_ae_oe(URL)
{
    var re = /å/;
    while (re.test(URL)) {
        URL = URL.replace(re, escape('å'));
    }
    var re = /ä/;
    while (re.test(URL)) {
        URL = URL.replace(re, escape('ä'));
    }
    var re = /ö/;
    while (re.test(URL)) {
        URL = URL.replace(re, escape('ö'));
    }
	 var re = /Å/;
    while (re.test(URL)) {
        URL = URL.replace(re, escape('Å'));
    }
    var re = /Ä/;
    while (re.test(URL)) {
        URL = URL.replace(re, escape('Ä'));
    }
    var re = /Ö/;
    while (re.test(URL)) {
        URL = URL.replace(re, escape('Ö'));
    }
    var re = /&ouml;/;
    while (re.test(URL)) {
        URL = URL.replace(re, escape('ö'));
    }
    var re = /&auml;/;
    while (re.test(URL)) {
        URL = URL.replace(re, escape('ä'));
    }
    var re = /&aring;/;
    while (re.test(URL)) {
        URL = URL.replace(re, escape('å'));
    }
    return URL;
}

function OpenWindow(URL,Width,Height,WinTitle)
{
    URL = unescape_aa_ae_oe(URL);
	if(WinTitle == null){
		WinTitle="Ord";
	}
	newWin=window.open(URL,WinTitle,'toolbar=0,scrollbars=no,status=no,resize=no,width='+Width+',height='+Height);
}
function OpenWindow_scroll(URL,Width,Height,WinTitle)
{
    URL = unescape_aa_ae_oe(URL);
	if (WinTitle == null){
		WinTitle="Ord";
	}
	newWin=window.open(URL,WinTitle,'toolbar=0,scrollbars=yes,status=no,resize=no,width='+Width+',height='+Height);
	newWin.focus();
}

function OpenWindow_scroll_resizable(URL,Width,Height,WinTitle)
{
    URL = unescape_aa_ae_oe(URL);
	if (WinTitle == null){
		WinTitle="Ord";
	}
    newWin=window.open(URL,WinTitle,'toolbar=0,location=0,scrollbars=yes,status=no,resizable=yes,width='+Width+',height='+Height);
	newWin.focus();
}

function OpenWindow_scroll_resizable_pos(URL,Width,Height,fromLeft,fromTop,WinTitle)
{
    URL = unescape_aa_ae_oe(URL);
	if (WinTitle == null){
		WinTitle="Ord";
	}
	if (fromLeft == null){
		fromLeft = 100;
	}
	if (fromTop == null){
		fromTop = 100;
	}
	newWin=window.open(URL,WinTitle,'toolbar=0,scrollbars=yes,status=no,resizable=yes,width='+Width+',height='+Height+',left='+fromLeft+',top='+fromTop);
	newWin.focus();
}

function OpenWindow_all_include(URL, Width, Height, WinTitle, FromLeft, FromTop)
{
    URL = unescape_aa_ae_oe(URL);
	if (WinTitle == null){
		WinTitle="Ord";
	}
	var prefs = "toolbar=yes,menubar=yes,location=yes,scrollbars=yes,resizable=yes,directories=yes,status=yes";
	if(Width != null && Height != null){
		prefs += ",width=" + Width + ",height=" + Height;
	}
	if(FromLeft != null && FromTop != null){
		prefs += ",screenX=" + FromLeft + ",screenY=" + FromTop + ",left="+ FromLeft +",top="+ FromTop;
	}
	newWin=window.open(URL, WinTitle, prefs);
	newWin.focus();
}

function fullWindow(url) {
    var str = "left=0,screenX=0,top=0,screenY=0,resizable,scrollbars=yes";
    if (window.screen) {
      var ah = screen.availHeight - 30;
      var aw = screen.availWidth - 10;
      str += ",height=" + ah;
      str += ",innerHeight=" + ah;
      str += ",width=" + aw;
      str += ",innerWidth=" + aw;
    }
    win=window.open(url, "w", str);
}

function showInMainWin(theUrl){
	if (window.opener){
		if(window.opener.closed){
			window.open(theUrl);
		}else{
			window.opener.location.href=theUrl;
		}
	}else{
		window.open(theUrl);
	}
}

// Stänger popup när man klickar i en länk i den som leder till huvudfönstret
//start
function closeAndShowInMainWin(theUrl){
    var objWO = window.opener;
	if ((!objWO) || (objWO == null) || (objWO.closed)){
		window.open(theUrl);
	}else{
	    objWO.location.href=theUrl;
        objWO.focus();
	}
    setTimeout("window.close()",500);
}
//end
//Det här scriptet öppnar en popup och stänger samtidigt ner befintliga popuper
//start
openWins = new Array();
curWin = 0;
function close_all(){
	for(i=0; i<openWins.length; i++) if (openWins[i] && !openWins[i].closed) openWins[i].close();
}

function url_open(openurl,width,height){
	openWins[curWin++] = photoWindow = window.open(openurl,curWin,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,topmargin=0,left=500,top=150,width='+width+',height='+height);
}
//end
//en variant av ovanstående funktion men nu kan man bestämma var varje fönster ska vara placerade
function url_open(openurl,width,height,left,top){
	openWins[curWin++] = photoWindow = window.open(openurl,curWin,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,topmargin=0,width='+width+',height='+height+',left='+left+',top='+top);
}

//denna funktion öppnar sida via en droplist
//anropet bör se ut så här onChange="droplist(this);"
function droplist(form2){
	window.location=form2.options[form2.selectedIndex].value;
}
//denna funktion öppnar en ny sida via en droplist
//anropet bör se ut så här onChange="droplist(this,610,450,100,100);"
function droplist_window(form2,width,height,left,top){
	url=form2.options[form2.selectedIndex].value;
	window.open(url,curWin,'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,topmargin=0,width='+width+',height='+height+',left='+left+',top='+top);
}
//denna funktion öppnar en ny sida via en droplist
//anropet bör se ut så här onChange="droplist(this,610,450,100,100);"
function droplist_window_all_include(form2,width,height,left,top){
	url=form2.options[form2.selectedIndex].value;
	window.open(url,curWin,'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,topmargin=0,width='+width+',height='+height+',left='+left+',top='+top);
}
//Öppnar i nytt fönster från droplista alternativt i samma sida beroende på
//vad man skickar in för filändelse i redirextensions.
function droplist_destinationcontrol(form2,redirextensions,width,height,left,top){
	var whatUrl = form2.options[form2.selectedIndex].value;
	var ext = redirextensions;
	var arrExt;
	var doRedirect = false;
	if(ext != null){
		arrExt = ext.split(",");
	}
	for(i = 0; i<arrExt.length;i++){
		tmpExLen = arrExt[i].length;
		doRedirect = (whatUrl.indexOf(arrExt[i]) > -1)?true:false;
	}
	if(doRedirect){
		window.location.href = whatUrl;
	}else{
		droplist_window(form2,width,height,left,top);
	}
}
function printPage(lang){
	if(lang==null){
		lang="sv";
	}else{
		lang=lang.toLowerCase();
	}
	var wb=new wbsniff();
	var tmpPrintStr = "";
	if(wb.mac){
		//MAC
		if(lang == "sv"){
			tmpPrintStr += 'H&aring;ll ned ';
			tmpPrintStr += '<img src="/img/mackringla.gif" width="9" height="9" border="0"> + P ';
			tmpPrintStr += 'f&ouml;r att skriva ut sidan';
		}else if(lang == "en"){
			tmpPrintStr += 'Press ';
			tmpPrintStr += '<img src="/img/mackringla.gif" width="9" height="9" border="0"> + P ';
			tmpPrintStr += 'to print page';
		}
	}else{
		//PC
		//Maska bort NN4 eftersom det blir problem efter en formulärpostning.
		if(!(wb.ns4)){
			if(lang == "sv"){
				tmpPrintStr += '<a href="javascript:window.print();" class="actionlink"><img align="absbottom" src="/img/pil2002.gif" width="16" height="12" border="0" alt="Skriv ut">';
				tmpPrintStr += 'Skriv ut</a>';
			}else if(lang == "en"){
				tmpPrintStr += '<a href="javascript:window.print();" class="actionlink"><img align="absbottom" src="/img/pil2002.gif" width="16" height="12" border="0" alt="Print">';
				tmpPrintStr += 'Print</a>';
			}
		}
	}
	writeIt(tmpPrintStr);
}
function writeIt(whatString){
	document.open;
	document.write(whatString);
	document.close;
}

function showInMainWinWithFocus(theUrl){
    var objWO = window.opener;
	if ((!objWO) || (objWO == null) || (objWO.closed)){
		window.open(theUrl);
	}else{
	    objWO.location.href=theUrl;
        objWO.focus();
	}

}



