/** 
* Author: Hannes Schwarz 
* Suggest Version 2.1
* $Date: 2011-12-05 10:16:49 $
* $Id: exoLoader.js,v 1.1.2.10 2011-12-05 10:16:49 hschwarz Exp $
* Copyright exorbyte GmbH, 2011. All rights reserved.
*/

/*
* PLEASE CONFIGURE THE FOLLOWING URLS
*/

// URL of the GSA - parameters will be added by SAYT
// var gsaUrl = "http://www.vodafone.es/buscador/es/";
var gsaUrl = document.location.protocol + "//www.vodafone.es/buscador/es/";



// URL to the servlet reading the popular search terms of the no results SAYT
// DON'T: Please do not configure the protocol since the protocol used by the 
//		current page will be added later.
var exoPopularTermsUrl = "www.vodafone.es/popularsearchesservlet";

/*
* DO NOT CHANGE THE CODE BELOW
*/

// use the protocol of the environment
exoPopularTermsUrl = document.location.protocol + "//" + exoPopularTermsUrl;

var protocol = document.location.protocol + "//";
if(exoDomain !== undefined && exoDomain.substring(0,4) == 'http') {
	protocol = "";
}


// restore jQuery
var $exoJ = jQuery.noConflict();
if (typeof jQuery_old === "function" && jQuery_old) {
    jQuery = $ = jQuery_old;
}

var saytLabels = new Array();
var exoPopularSearchterms = new Array();

loadlanguage();
loadsntemplatejs();

// # script loader function
function loadScript(url, callback)
{
	var script = document.createElement("script");
	script.type = "text/javascript";

	if (script.readyState){  //IE
		script.onreadystatechange = function(){
			if (script.readyState == "loaded" ||
					script.readyState == "complete"){
				script.onreadystatechange = null;
				callback();
			}
		};
	} else {  //Others
		script.onload = function(){
			callback();
		};
	}
	script.src = url;
	document.getElementsByTagName("head")[0].appendChild(script);
}	


function loadlanguage() {
	var lang = "es";
	if(document.location.href.indexOf("/ga/") >= 0) {
		lang = "es_ga";
	} else if(document.location.href.indexOf("/ca/") >= 0) {
		lang = "es_ca";
	} else if(document.location.href.indexOf("/eu/") >= 0) {
		lang = "es_eu";
	}
	loadScript(protocol + exoDomain + 'lang/saytLabels_' + lang + '.js', function(){});
}

function loadsntemplatejs() {
	loadScript(protocol + exoDomain + 'sncustom/sntemplate.js', function(){exosetup();});
}

function exosetup() {
	$exoJ(document).ready(function($) {
		snSetup($exoJ,exoSearchField);
	});
}

// Load Stylesheets
document.writeln(unescape("%3Clink href='" + protocol + exoDomain + "lib/sn.css' type='text/css' rel='stylesheet'/%3E"));
document.writeln(unescape("%3Clink href='" + protocol + exoDomain + "sncustom/sntemplate.css' type='text/css' rel='stylesheet'/%3E"));

// "Conditional Comments"
if ($exoJ.browser.msie && parseInt($exoJ.browser.version, 10) <= 7) {
	document.writeln(unescape("%3Clink href='" + protocol + exoDomain + "sncustom/sntemplate_lteIE7.css' type='text/css' rel='stylesheet' /%3E"));
}





