
/*----------------------------------------------------------------------------
 *       JSlint, settings for the javascript code verifier jslint.com
 *
 * Run from the commandline using rhino, or:
 * 1. go to jslint.com
 * 2. click clear all options at the bottom (we define the options below)
 * 3. paste in the code
 *
 *----------------------------------------------------------------------------*/
/*jslint
		adsafe: false,			// if ADsafe.org rules widget pattern should be enforced.
		bitwise: true, 			// if bitwise operators should not be allowed
		browser: true, 			// if the standard browser globals should be predefined
		cap: false,				// if upper case HTML should be allowed
		newcap: false, 			// if Initial Caps must be used with constructor functions
		css: false, 				// if CSS workarounds should be tolerated
		debug: false, 			// if debugger statements should be allowed
		eqeqeq: true, 			// if === should be required
		evil: false, 				// if eval should be allowed
		forin: false, 			// if unfiltered for in statements should be allowed
		fragment: true,			// if HTML fragments should be allowed
		laxbreak: true,			// if statement breaks should not be checked
		nomen: false, 			// if names should be checked for initial underbars
		on: false, 				// if HTML event handlers should be allowed
		onevar: false, 			// if only one var statement per function should be allowed
		passfail: false,			// if the scan should stop on first error
		plusplus: true,			// if ++ and -- should not be allowed
		regexp: true, 			// if . should not be allowed in RegExp literals
		rhino: false, 			// if the Rhino environment globals should be predefined
		safe: false, 				// if the safe subset rules are enforced. These rules are used by ADsafe.
		sidebar: false,			// if the Windows Sidebar Gadgets globals should be predefined
		strict: false, 			// if the ES3.1 "use strict"; pragma is required.
		sub: false, 				// if subscript notation may be used for expressions better expressed in dot notation
		undef: true, 			// if undefined global variables are errors
		white: false, 			// if strict whitespace rules apply
		widget: false			// if the Yahoo Widgets globals should be predefined
*/

// Deprecated but used browser function
/*global unescape, escape*/

// Prototype globals
/*global $, $$, $A, $H, Event, Class, Hash, Ajax, Template, Position, Element, Form, Prototype */

//----------------------------------------------------------------------------

/**
 * Common and global functions  
 */


/************************************************************************
Cookie handlers
************************************************************************/
function setCookie(name, value, expires, path, domain, secure) {
  if (domain === -1) {
  // Set a default domain if the domain was not set (i.e. domain = -1)
    domain = document.location.host;
    domain = domain.substring(domain.indexOf('.') + 1 , domain.length); // remove subdomain
  }
  var curCookie = name + "=" + escape(value) +
  ((expires) ? "; expires=" + expires.toGMTString() : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i<ca.length;i+=1){
    var c = ca[i];
    while (c.charAt(0)===' '){ c = c.substring(1,c.length); }
    if (c.indexOf(nameEQ) === 0){ return c.substring(nameEQ.length,c.length); }
  }
  return 1; //if cookie doesn't exist return value 1, in this case swedish
}
function getCookie(NameOfCookie){
  if (document.cookie.length > 0) {              
    var begin = document.cookie.indexOf(NameOfCookie+"=");       
    if (begin !== -1) {           
      begin += NameOfCookie.length+1;       
      var end = document.cookie.indexOf(";", begin);
      if (end === -1){ end = document.cookie.length; }
      return unescape(document.cookie.substring(begin, end));
    } 
  }
  return null;
}

/*
 * The following functions were previously located in eniroSearchTeam.js:
 *   getHeadings, getAreas, setSik
 * Copyright (c) 2006 Eniro Sverige AB - CIT Search Team
 * peter.gustafsson@eniro.com
*/
function getHeadings(){
	var ga = document.getElementById("where");
	var form = $("search");
	var lang="";
	if (form!==null) {
		lang = form.lang; 
	}
	var location = "/query/what/hs/search_word/A";
	if (ga!==null) {
		location+="/geo_area/"+escape(ga.value);
	}
	if (lang) {
		location+="/lang/"+lang.value;
	}
	window.location=location;
}
function getAreas(){
	var location = "/area/?";

	var fobj = document.getElementById("search") || document.getElementById("ypAdvancedForm") || document.getElementById("peopleAdvancedForm");

	var hasSearchWord = 0;

	for (var i=0; i< fobj.elements.length; i+=1) {
		if (fobj.elements[i].value !== '' && fobj.elements[i].name && fobj.elements[i].name!=='geo_area' ) {
			location += "&" + fobj.elements[i].name + "=" + escape(fobj.elements[i].value);
			if(fobj.elements[i].name.indexOf("search_word") !== -1) {
				hasSearchWord = 1;
			}
		}
	}

	//If no search_word, we have to add geo_area=A for the swedish area search to work.
	if((hasSearchWord === 0 || document.getElementById("ypAdvancedForm")) && window.location.toString().indexOf("gulasidorna.eniro.se") !== -1) {
		location += "&geo_area=A";
	}
	location = location.replace(/\+/g,'%2B');
	window.location=location;
}

/**
  * @filename Should be in a file with the name: set-sik.js
  * @fileoverview Creates 0-size images used for statistics.
  */

/**
  * Creates 0-size images used for statistics.
  * @param {String} qStr Query string
  */
function setSik(qStr, host) {
	host = window.location.toString();
	if(host.indexOf("eniro.se") !== -1){
		host = "http://www.eniro.se";
	} else if(host.indexOf("eniro.dk") !== -1){
		host = "http://www.eniro.dk";
	} else if(host.indexOf("eniro.fi") !== -1){
		host = "http://www.eniro.fi";
	} else if(host.indexOf("krak.dk") !== -1){
		host = "http://www.krak.dk";
	} else if(host.indexOf("krakteknik.dk") !== -1){
		/*host = "http://www.krakteknik.dk";*/
		host = "http://www.krak.dk";
	} else {
		host = "";
	}
	var sikImg = document.createElement('img');
	sikImg.width = 0; sikImg.height = 0;
	sikImg.src = host + "/img/sik.gif?" + qStr;
	document.getElementsByTagName('body')[0].appendChild(sikImg);
	
	return true;
}

/*******************************************************************
 *
 * Extensions to js-core for old crappy browsers
 *
 *******************************************************************/

// Array support for the push method
if(typeof Array.prototype.push !== "function"){
	function ArrayPush(value){
		this[this.length] = value;
	}
	Array.prototype.push = ArrayPush;
}
// Array support for the pop method
if(typeof Array.prototype.pop !== "function"){
	function ArrayPop() {
		var lastItem = undefined;
		if (this.length > 0 ) {
			lastItem = this[this.length - 1];
			this.length -=1;
		}
		return lastItem;
	}
	Array.prototype.pop = ArrayPop;
}
//Default printout
function printOut(url) {
	window.open(url, 'print', 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=670,height=' + Math.max(window.outerHeight ? window.outerHeight - 100 : document.viewport.getHeight(), 600) + ',top=0,left=0');
}
