/*===============
Name: popupVillkor
Purpose: Hide return value from openWindow for href="javascript: can't handle it
Return value: none
===============*/
function openWin(pseWinType, url, width, height, title, top, left) {
	openWindow(pseWinType, url, width, height, title, top, left);
}

/*===============
Name: openWin
Purpose: Open windows of different types.
         Can be called with optional nr of parameters (except for mandatory pseWinType and url).
Parameters:
    pseWinType (Object) - type of window that should be opened
    url (String) - url in new window
    width (Number)
    height (Number)
    title (String) unique name for window if it's important not to reuse eventual previously opened windows
    top (Number)
    left (Number)
Example of usage:
    onclick="openWin(pseWin.SCROLLRESIZE,'/elin_v2/main_do.jsp',500,400,'elinWinPopup',10,10);"
Return value: if window was opened or not, inverse, so it can stop an normal open
===============*/
var pseWin = new Object();
pseWin.SIMPLE = 1;
pseWin.SCROLL = 2;
pseWin.SCROLLRESIZE = 3;
pseWin.FULLSIZE = 4;
pseWin.COMPLETE = 5;
// Complete is like _blank on anchor.. Scroll, resize, menubar,location and statusbar.

function openWindow(pseWinType, url, width, height, title, top, left) {
    var prefs = "";

    if (title == null) {
        //window title is null, set default
        title = "winTitle";
    }
    if (pseWinType == pseWin.FULLSIZE && window.screen) {
        //If window should be of type FULLSIZE, set width and height highest possible (according to screen)
        prefs = "width=" + (screen.availWidth - 10) + ",height=" + (screen.availHeight - 30);
    } else if (width == null || height == null) {
        //Width or height not specified, set default values.
        prefs = "width=500,height=300";
    } else {
        //Width and height specified.
        prefs = "width=" + width + ",height=" + height;
    }

    if (pseWinType == pseWin.FULLSIZE) {
        //If window should be of type FULLSIZE, set position to 0,0.
        top = 0;
        left = 0;
    }
	//Set Top pref if it's supplied
	if( top != null ){
		prefs += ",screenY=" + top + ",top=" + top;
	}
	//Set Left pref if it's supplied
	if( left != null ){
		prefs += ",screenX=" + left + ",left=" + left;
	}

    switch (pseWinType) {
        case 1: //SIMPLE
            prefs += ',toolbar=0,scrollbars=no,status=no,resizable=no';
            break;
        case 2: //SCROLL
            prefs += ',toolbar=0,scrollbars=yes,status=no,resizable=no';
            break;
        case 3: //SCROLLRESIZE
            prefs += ',toolbar=0,scrollbars=yes,status=no,resizable=yes';
            break;
        case 4: //FULLSIZE
            prefs += ',toolbar=0,scrollbars=yes,status=no,resizable=yes';
            break;
        case 5: //COMPLETE, ALL FEATURES
            prefs += ',location=1,toolbar=1,scrollbars=yes,status=yes,resizable=yes';
    }

    var newWin = window.open(url, title, prefs);
	// Check if pop-up was blocked
	if( newWin ){
		//Put focus on opened window.
		newWin.focus();
		// return false so the browser don't follows the link
		return false;
	} else {
		// return true so the browser will follow the link
		return true;
	}
}

/*===============
Name: popupVillkor
Purpose: Opens window from href on anchor
Return value: if window was opened or not inverse
===============*/
function popupVillkor(e) {
	if (!e) e = window.event;
	return openWindow(3, getTargetElement(e).href, 450, 600);
}


/*===============
Name: printWin
Purpose: Trigger print of document (and allows future changes if necessary, not using window.print directly in html).
Return value: none
===============*/
function printWin(){
    window.print();
}

/*============================================================
Name:    goSelectedURL
Purpose:
         Use as onclick-event on a button together with a selectlist.
         The different options in the selectlist contains different URLs.
         First the user select an option then he/she clicks on a button.. and
         get directed to the selected url.
Parameters:
         selectFieldId (String) The id of the selectlist.
Example of usage:
         <form action="">   //surrounding form-tag
         <select id="mySelectList" ...
              //options containing URLs
         </select>
         <input type="button" onclick="goSelectedURL('mySelectList')" ...
         </form>   //surrounding form-tag

         ( Important! Remember never to nest form-tags. ie <form><form></form></form> )

Return value:
         none
============================================================*/
function goSelectedURL(selectFieldId){
    //get reference to selectlist
    var objSelectField = document.getElementById(selectFieldId);
    //set loction to selected option-url
    window.location = objSelectField.options[objSelectField.selectedIndex].value;
}
















