//<!--

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

  
    function openHelp() {
      window.open('help.html', '', 'height=510,width=266,status=yes,toolbar=no,menubar=no,scrollbars=yes,location=no');
    }
    
    
//--- START IE8 SCRIPTING ---
/** 
* General features used when opening windows. 
* Position and size is calculated automatically 
*/
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 att jag öppnar en länk. ";
var popupOfferLinkText = "Klicka här för att öppna fönstret </p>" ;

/**
* 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].CLICKED_QUESTION.value = "true";
  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(!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;
            popup = window.open(url, target, popup_window_features);
            if(windowIsOpen(popup)){
                //
            }
            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;    
    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){

    var popupOfferDiv = document.createElement('div');
    popupOfferDiv.setAttribute("id","popupoffer");
    
    //MODIFY THE FOLLOWING TWO LINES TO INSERT THE DIV SOMEWHERE ELSE
    //var node = document.getElementsByTagName('input')[0];
     var node = document.getElementsByTagName('span')[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;
  }


// --- SLUT IE8 scripting ---


     function handleKeyPress(event)
        {
            if(event.keyCode == 13 && event.shiftKey != 1)
            {
                document.getElementById('assistentForm').submit();
            }
        }
        
              

function styleAbbr() {
  var oldBodyText, newBodyText, reg
  if (isIE) {
    oldBodyText = document.body.innerHTML;
    reg = /<ABBR([^>]*)>([^<]*)<\/ABBR>/g;
    newBodyText = oldBodyText.replace(reg, '<ABBR $1><SPAN class=\"abbr\" $1>$2</SPAN></ABBR>');
    document.body.innerHTML = newBodyText;
  }
}

window.onload = function(){
  styleAbbr()
};

isIE = (document.all) ? true:false;


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();
   }
}

  //-->
