<!--

/**
* General features used when opening windows.
* Position and size is calculated automatically
*/
//var screenX=screen.availWidth;var screenY = screen.availHeight;var width= screen.availWidth;var height=screen.availHeight;
//var popup_window_features = "'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes,width=" + width + ",height=" + height +",left=" + screenX + ",top=" + screenY + ",screenX=" + screenX + ",screenY=" + screenY + "'";

var popup_window_features = "'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes";

/**
* Text before link, and link text of popup offer message.
*/
var popupOfferPreLinkText = "Din webbläsare tillåter inte mig att öppna sidor på SAS webbplats. Klicka för att ";
var popupOfferLinkText = "öppna sidan i ett nytt fönster <p>";
//var popupOfferPreLinkText = "Your web browser has a security restriction which makes me have to open a new window for you to see information at our website.<br>";
//var popupOfferLinkText = "Open a new window.";

/**
* Sets focus of and clears entry field.
*/

function entryfieldsetfocus() {
    entryfieldfocus();
    entryfieldclear();
    }

/**
* Sets focus of entry field. Modify this function so that it works with current installation.
*/
function entryfieldfocus(){
     document.forms[0].ENTRY.focus();
}

/**
* Clears entry field. Modify this function so that it works with current installation.
*/
function entryfieldclear(){
    document.forms[0].ENTRY.value = "";
}

/**
* Used in input links to VDA.
* Modify this function so that it sends input in the right format.
*/
//function getAnswerFor(question) {
//    document.forms[0].ENTRY.value = question;
//    document.forms[0].submit();
//}




 /**
   * @param targetName the name of a window
   * @return true if a window named targetName is one of the currently available frames.
   */
function checkTarget(targetName) {
  for(var i = 0; i < parent.frames.length; i++) {
    if(parent.frames[i].name == targetName) {
      return true;
    }
    return false;
  }
}

 /**
   * opens a web page, displays an informational message with a link to open the page if it is blocked
   * @param url the web page to open
   * @param target the target name of the page to open
   * @param style attributes of the page to open
   */
function openLink(url, target, style) {

if (crossDomainOpenerAccess() && self.opener.opener && !self.opener.opener.closed && url != "") {
    self.opener.opener.location = url;
    self.opener.opener.focus();
    self.focus();
    return;
  }

if (crossDomainOpenerAccess() && self.opener && !self.opener.closed && url != "") {
    self.opener.location = url;
    self.opener.focus();
    self.focus();
    return;
  }

if(!target || target.length<2){
        target = "vda_navigator";
    }

    if (crossDomainOpenerAccess() && self.opener &&  !self.opener.closed && url != "") {
     		self.opener.location = url;
        	self.opener.focus();
        	self.focus();
        	return;
      }
    if(url.length > 3 && url != "" && url != null) {

      	if(target.length > 1 && checkTarget(target)) {
           	parent.frames[target].location.replace(url);
        	}
        else{
            var popup=null;
            var new_window_features = addWindowSizeParams(popup_window_features);
            popup = window.open(url, target, new_window_features);
//            popup = window.open(url, target, popup_window_features);
            if(windowIsOpen(popup)){
			       //remove popupoffermessage if it exists
					var el=document.getElementById("popupoffer");
					if(el){
						el.parentNode.removeChild(el);
					}
            }
            else{
                createPopupOfferDiv(url, target, popup_window_features);
            }
        }
      }

      //focus VDA, unless IE8
    if(navigator.userAgent.indexOf("MSIE 8") < 0 || ( navigator.userAgent.indexOf("MSIE 7") >-1 ) && !document.documentMode ){
        self.focus();
        }
      entryfieldfocus();
    }

 /**
   * @return true if the current browser allows pages to open in the opener window
   */
function crossDomainOpenerAccess(){
    //return true if FF and IE 6 or 7
    //otherwise false
    var ua=navigator.userAgent;

   // KALU 20091218: SAS now have the option
   // to open the VCA from an input field on their web pages.
   // To solve character encoding problems, their input field
   // uses iframe. FF have problems of opening urls in the
   // opener page, if the opener page is an iframe
   // The rows below are then commented out to get the same
   // behaviour as in IE8 - that is: open urls in a new window
   // if(ua.indexOf("Firefox") > -1){ //FF
   //     return true;
   //     }
   //  else
   if(ua.indexOf("MSIE 7") > -1 && !document.documentMode){ //IE7
        return true;
    }
    else if(ua.indexOf("MSIE 6") > -1){ //IE6
        return true;
    }
    return false;
}

 /**
   * @param win a window reference
   * @return true if the window win is open
   */
function windowIsOpen(win){
    if(self.window.opera){ //opera test
        try{
            if(win.opera){
                return true;
            }
            else{
                return false;
            }
        }
        catch(e){
  	return true; //window.opera only throws Xdomain
  //security error on open win
        }
    }
    //add google chrome test here
    //other browsers - just check if it is defined
    else if(win){
        return true;
    }

    else{
        return false;
    }
}


 /**
   * Creates a div element with a link that opens the window specified, and inserts it into the dom.
   */
function createPopupOfferDiv(url, target, popup_window_features){

	//remove previous popupoffer if it exists
	var el=document.getElementById("popupoffer");
	if(el){
			el.parentNode.removeChild(el);
		}

    var popupOfferDiv = document.createElement('div');
    popupOfferDiv.setAttribute("id","popupoffer");

    //MODIFY THE FOLLOWING TWO LINES TO INSERT THE DIV SOMEWHERE ELSE

    var node = document.getElementById('popupMessage');
    node.appendChild(popupOfferDiv);
//    var node = document.getElementsByTagName('input')[0];
//    node.parentNode.insertBefore(popupOfferDiv,node);

    var link = document.createElement('a');
    link.setAttribute('href','javascript:showPopup("'+url+'","'+ target+'","'+popup_window_features+'");');
    link.innerHTML = popupOfferLinkText;
    popupOfferDiv.appendChild(link);
    popupOfferDiv.innerHTML = popupOfferPreLinkText+popupOfferDiv.innerHTML;

}


 /**
   * Opens a popup using window.open. Calculates the size and position of the new window, so that it is positioned nicely relative the VDA.
   * If the current browser is not IE8, it focuses the VDA after opening the window.
   * After opening the new window, the popup offer div is removed from VDA.
   */
 function showPopup(url,target,popup_window_features){
    var allfeatures=addWindowSizeParams(popup_window_features);
    var popup = window.open(url,target,allfeatures);
    popup.focus();
    if(navigator.userAgent.indexOf("MSIE 8") < 0 || ( navigator.userAgent.indexOf("MSIE 7") > -1 ) && !document.documentMode ){
        self.focus();
    }
   var el=document.getElementById("popupoffer");
   el.parentNode.removeChild(el);
}


 /**
   * Adds window size and position parameters to the parameter string used when opening a popup window.
   * The new popup window will be placed where there is most room on the screen relative to the current window
   * @param params a string with the params for the window, excluding size and position
   * @return a string with the params for the window, including size and position
   */
 function addWindowSizeParams(params){
 	var newparams;
    try {
      var x1=getWindowLeft(window.self), y1=getWindowTop(window.self);
      if (isNaN(x1)||isNaN(y1)) newparams='';
      else {
        var w=getWindowWidth(window.self), h=getWindowHeight(window.self),
            wo=screen.availWidth-margin, ho=screen.availHeight-margin;
        var sq=getBestSquare([newSquare(margin,margin,wo,y1-margin),
                              newSquare(x1+w+margin,margin,wo,ho),
                              newSquare(margin,y1+h+margin,wo,ho),
                              newSquare(margin,margin,x1-margin,ho)]);
        if (sq==null) newparams='';
        else newparams=params + ',left='+sq.left+',width='+sq.width+
                       ',top='+sq.top+',height='+sq.height;
      }
    }
    catch (err) { newparams='';}
  return newparams;
  }



/**
   * The minimal acceptable width of a browser window in pixels
   */
  var minWidth=128;

  /**
   * The minimal acceptable height of a browser window in pixels
   */
  var minHeight=128;

  /**
   * The auxiliary margin parameter
   */
  var margin=64;



  /**
   * Returns the width of a browser window in pixels.
   * The window can be created through a call to <tt>window.open(...)</tt>.
   * This function tries different browser-specific ways of getting this
   * parameter. If several different values can be obtained in this way,
   * the maximum value is used.
   *
   * @param w a browser window
   * @return the width of the window in pixels,
   *         or 0 in case the width cannot be calculated.
   */
  function getWindowWidth (w) {
    if (!w) return 0;
    var n=w.outerWidth;
    if (typeof(n)!='number') n=0;
    var doc=w.document, n2, n3;
    if (doc) {
      if (!doc.documentElement) n2=0;
      else if (typeof(n2=doc.documentElement.clientWidth)!='number') n2=0;
      if (!doc.body) n3=0;
      else if (typeof(n3=doc.body.clientWidth)!='number') n3=0;
    }
    else n2=n3=0;
    return (n<n2)?((n2<n3)?n3:n2):((n<n3)?n3:n);
  }



  /**
   * Returns the height of a browser window in pixels.
   * The window can be created through a call to <tt>window.open(...)</tt>.
   * This function tries different browser-specific ways of getting this
   * parameter. If several different values can be obtained in this way,
   * the maximum value is used.
   *
   * @param w a browser window
   * @return the height of the window in pixels,
   *         or 0 in case the height cannot be calculated.
   */
  function getWindowHeight (w) {
    if (!w) return 0;
    var n=w.outerHeight;
    if (typeof(n)!='number') n=0;
    var doc=w.document, n2, n3;
    if (doc) {
      if (!doc.documentElement) n2=0;
      else if (typeof(n2=doc.documentElement.clientHeight)!='number') n2=0;
      if (!doc.body) n3=0;
      else if (typeof(n3=doc.body.clientHeight)!='number') n3=0;
    }
    else n2=n3=0;
    return (n<n2)?((n2<n3)?n3:n2):((n<n3)?n3:n);
  }



  /**
   * Returns the coordinate of the left edge of a browser window in pixels.
   * The window can be created through a call to <tt>window.open(...)</tt>.
   * This function tries different browser-specific ways of getting this
   * parameter. If several different values can be obtained in this way,
   * the minimum value is used.
   *
   * @param w a browser window
   * @return the coordinate of the left edge of the window in pixels,
   *         or <tt>NaN</tt> in case the height cannot be calculated.
   */
  function getWindowLeft (w) {
    if (!w) return NaN;
    if (typeof(w.screenX)!='number')
      return (typeof(w.screenLeft)=='number')?w.screenLeft:NaN;
    if (typeof(w.screenLeft)!='number') return w.screenX;
    return (w.screenX<w.screenLeft)?w.screenX:w.screenLeft;
  }



  /**
   * Returns the coordinate of the top edge of a browser window in pixels.
   * The window can be created through a call to <tt>window.open(...)</tt>.
   * This function tries different browser-specific ways of getting this
   * parameter. If several different values can be obtained in this way,
   * the minimum value is used.
   *
   * @param w a browser window
   * @return the coordinate of the top edge of the window in pixels,
   *         or <tt>NaN</tt> in case the height cannot be calculated.
   */
  function getWindowTop (w) {
    if (!w) return NaN;
    if (typeof(w.screenY)!='number')
      return (typeof(w.screenTop)=='number')?w.screenTop:NaN;
    if (typeof(w.screenTop)!='number') return w.screenY;
    return (w.screenY<w.screenTop)?w.screenY:w.screenTop;
  }



  /**
   * Initializes a <tt>Square</tt> object representing a square space.
   * The <tt>Square</tt> object has the following internal parameters
   * whose values are expressed in pixels:
   * <ul>
   * <li><tt>left</tt>: coordinate of the left edge,</li>
   * <li><tt>top</tt>: coordinate of the top edge,</li>
   * <li><tt>right</tt>: coordinate of the right edge,</li>
   * <li><tt>bottom</tt>: coordinate of the bottom edge,</li>
   * <li><tt>width</tt>: width,</li>
   * <li><tt>height</tt>: height,</li>
   * <li><tt>minSide</tt>: size of the minimal edge,</li>
   * <li><tt>relation</tt>: height/width if height is less than width,
   *                        and width/height otherwise.</li>
   * </ul>
   *
   * @param x1 the coordinate of the left edge
   * @param y1 the coordinate of the top edge
   * @param x2 the coordinate of the right edge
   * @param y2 the coordinate of the bottom edge
   * @return the coordinate of the top edge of the window in pixels,
   *         or <tt>NaN</tt> in case the height cannot be calculated.
   */
  function Square (x1, y1, x2, y2) {
    this.left=x1; this.top=y1; this.right=x2; this.bottom=y2;
    this.surface=(this.width=x2-x1)*(this.height=y2-y1);
    if (this.width<this.height) {
      this.minSide=this.width; this.relation=this.width/this.height;
    }
    else { this.minSide=this.height; this.relation=this.height/this.width;}
  }



  /**
   * Compares two {@link Square} objects with respect to the ergonomics
   * of a browser window to be opened in the spaces represented by these
   * objects.
   *
   * @param sq1 Square object
   * @param sq2 Square object
   * @return <tt>-1</tt> if <tt>sq1</tt> is <i>less ergonomic</i> than <tt>sq2</tt>
   * @return <tt>1</tt> if <tt>sq1</tt> is <i>more ergonomic</i> than <tt>sq2</tt>
   * @return <tt>0</tt> if <tt>sq1</tt> is equal to <tt>sq2</tt> <i>with respect to ergonomics</i>
   */
  function compareSquares (sq1, sq2) {
    if (sq1==null) return (sq2==null)?0:-1;
    if (sq2==null) return 1;
    if (sq1.minSide!=sq2.minSide) return (sq1.minSide<sq2.minSide)?-1:1;
    if (sq1.surface!=sq2.surface) return (sq1.surface<sq2.surface)?-1:1;
    if (sq1.relation!=sq2.relation) return (sq1.relation<sq2.relation)?-1:1;
    return 0;
  }



  /**
   * Creates a new {@link Square} object if its specified size makes sense.
   *
   * @param x1 the coordinate of the left edge
   * @param y1 the coordinate of the top edge
   * @param x2 the coordinate of the right edge
   * @param y2 the coordinate of the bottom edge
   * @return a new <tt>Square</tt> object or <tt>null</tt> if the size is
   *         too small from the ergonomics point of view.
   */
  function newSquare (x1, y1, x2, y2) {
    if (x2-x1<minWidth||y2-y1<minHeight) return null;
    return new Square(x1,y1,x2,y2);
  }



  /**
   * Selects from an array of {@link Square} objects the one which is
   * considered to be the best from the ergonomics points of view.
   * If there are several ergonomically equal objects found, the first
   * one is selected.
   *
   * @param squares array of <tt>Square</tt> objects
   * @return the <tt>Square</tt> object found to be the best from
   *         the ergonomics points of view, or <tt>null</tt> if no
   *         such object has been found.
   */
  function getBestSquare (squares) {
    var bestSquare=null;
    for (var i=squares.length-1; i>=0; i--)
      if (compareSquares(bestSquare,squares[i])<0) bestSquare=squares[i];
    return bestSquare;
  }



//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function OpenInFrame (sUrl) {
  //Be sure that your frame is now called pubMain
  //parent.pubMain.location = sUrl
  //window.opener.parent.pubMain.location = surl;
  window.opener.parent.frames['pubMain'].location.href=sUrl;
}


//Opens a link in the window that opened the popup
function setOpenerWindowLocation (dirrectToThisUrl) {
  window.opener.location=dirrectToThisUrl;
  self.focus();
}

//function entryfieldsetfocus() {
//  document.forms[0].ENTRY.focus();
//  document.forms[0].ENTRY.value = "";
//}

//function checkTarget(targetName) {
//  for(var i = 0; i < parent.frames.length; i++) {
//    if(parent.frames[i].name == targetName) {
//      return true;
//    }
//    return false;
//  }
//}

// Browser Window Size and Position
function pageWidth() {return window.innerWidth != null? window.innerWidth: document.body != null? document.body.clientWidth:null;}
function pageHeight() {return window.innerHeight != null? window.innerHeight: document.body != null? document.body.clientHeight:null;}
function posLeft() {return window.pageXOffset != null? window.pageXOffset: document.body.scrollLeft != null? document.body.scrollLeft:0;}
function posTop() {return window.pageYOffset != null? window.pageYOffset: document.body.scrollTop != null? document.body.scrollTop:0;}
function posRight() {return posLeft()+pageWidth();}
function posBottom() {return posTop()+pageHeight();}

//function openLink(url, target, style) {
//  var screenX=screen.availWidth/2;var screenY = screen.availHeight/4;var width=(screen.availWidth/2.25);var height=screen.availHeight/2;
//  var features = "'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes,width=" + width + ",height=" + height +",left=" + screenX + ",top=" + screenY + ",screenX=" + screenX + ",screenY=" + screenY + "'";
//
//if (self.opener.opener && !self.opener.opener.closed && url != "") {
//    self.opener.opener.location = url;
//    self.opener.opener.focus();
//    self.focus();
//    return;
//  }
//
//if (self.opener && !self.opener.closed && url != "") {
//    self.opener.location = url;
//    self.opener.focus();
//    self.focus();
//    return;
//  }
//
//  if(url.length > 3 && url != "" && url != null) {
//    if(target.length > 2 && checkTarget(target))
//      parent.frames[target].location.replace(url);
//    else if(target.length > 2 && target != null)
//      var popup = window.open(url, target, features);
//    else
//      var popup = window.open(url, url, features);
//  }
//}

function OpenWin(popSetts) {

//-- Check function calls ----------------------------
  if (!popSetts['name']) {    popSetts['name']    = 'Popup';}
  if (!popSetts['w']) {       popSetts['w']       = 600;}
  if (!popSetts['h']) {       popSetts['h']       = 700;}
  if (!popSetts['scroll']) {  popSetts['scroll']  = 'No';}
  if (!popSetts['loc']) {     popSetts['loc']     = 'No';}
  if (!popSetts['l']) {       popSetts['l']       = 0;}
  if (!popSetts['t']) {       popSetts['t']       = 0;}
  if (!popSetts['menu']) {    popSetts['menu']    = 'No';}
  if (!popSetts['resiz']) {   popSetts['resiz']   = 'No';}
  if (!popSetts['tools']) {   popSetts['tools']   = 'No';}

  /*
  status = popSetts['name']+' '+
           popSetts['w']+' '+
           popSetts['h']+' '+
           popSetts['scroll']+' '+
           popSetts['loc']+' '+
           popSetts['l']+' '+
           popSetts['t']+' '+
           popSetts['menu']+' '+
           popSetts['resiz']+' '+
           popSetts['tools'];
  */

  //---if i and t = 0 calculate center of screen for popup
  if(popSetts['l'] == 0 && popSetts['t'] == 0){
        var swh = screen.height;
        var sww = screen.width;
        sww = (sww/2)-(popSetts['w']/2);
        swh = (swh/2)-(popSetts['h']/2);
        popSetts['l'] = sww;
        popSetts['t'] = swh;
  }
  //-----------------------------------------------------

  //-- Popps the new window if url is set----------------
  if (popSetts['url']){
    oWin = window.open(popSetts['url'], popSetts['name'],
                      'width='        + popSetts['w'] +
                      ',height='      + popSetts['h'] +
                      ',scrollbars='  + popSetts['scroll'] +
                      ',location='    + popSetts['loc'] +
                      ',left='        + popSetts['l'] +
                      ',top='         + popSetts['t'] +
                      ',menubar='     + popSetts['menu'] +
                      ',alwaysRaised=Yes'+
                      ',resizable='   + popSetts['resiz'] +
                      ',toolbar='     + popSetts['tools']);



    agent = navigator.userAgent;

    if ((agent.indexOf('Mozilla') != -1) && ((agent.indexOf('Spoofer') == -1) && (agent.indexOf('compatible') == -1))) {
      oWin.focus();
    }
  }
}
function getAnswerFor(question) {
  document.forms[0].ENTRY.value = question;
  document.forms[0].clicked_question.value = "true";
  document.forms[0].submit();
}


function externalUrl(sUrl) {
	if(sUrl.length > 3){
		window.open(sUrl,'external_url','width=1008,height=630,toolbar=yes,scrollbars=yes,menubar=yes,location=yes,resizable=yes').focus();
	}
}
//-->