//get a global copy of the full list of reosrts for all countries

dateSeasonStart= new Date("2007/11/24");
dateSeasonEnd = new Date("2008/05/03");
var sr_cookiestring = extractSRCookie("snowrental");
var sr_cookie = new Hash()
if (sr_cookiestring){
    sr_cookiestring.split("&").each(function (i){
    var x = i.split("=");
    sr_cookie[unescape(x[0])]=unescape (x[1]);
    });
}

function getCookie(name, subname) {
    var cs = extractSRCookie(name);
    var r;
    var begin=0;
    //subname = subname.replace ('_','%5F')
    var prefix = subname + '=';
    if (cs==null) return null;
    begin = cs.indexOf(prefix);
    if (begin == -1) return null;
    end = cs.indexOf("&", begin);
    if (end == -1) {
        end = cs.length;
    }
    r= decodeURIComponent(cs.substring(begin + prefix.length, end));
    return r;
}

Event.observe(window, 'load', function(event) {

  
   try{ 
    if($('cihioB')){
        var sehioB=document.createElement("script");
        var l = $$('meta[http-equiv="content-language"]')[0].content
        sehioB.type="text/javascript";
        var sehioBs=(location.protocol.indexOf("https")==0?"https://secure.providesupport.com/image":"http://image.providesupport.com")+"/js/snowrental/safe-standard.js?ps_h=hioB\u0026ps_t="+new Date().getTime();
        sehioB.src=sehioBs;
        $('sdhioB').appendChild(sehioB);
        var t=setTimeout("fnLH('"+l+"')",2000)
    }
   }catch(e){};
});
function fnLH(l){
    $$('IMG[name="pshioBimage"]')[0].src='/images/deco/2007/livehelp-online-'+ l +'.gif';
    if (l=='de'){
        $('schioB').down().removeAttribute("onclick");
        $('schioB').down().onclick = null;
        Event.observe($('schioB').down(), 'click', function(event){
            if (confirm ("Wir können Sie in Englischer oder Französischer Sprache beraten")){
                pshioBow(); return false;
            }
        })
    }
}
function setCookie(name, subname, newval, expiredays) {
	//var dc = document.cookie;
	//subname = subname.replace ('_','%5F');
	var dc = extractSRCookie(name);
	if (dc==null) dc="";
	var oldval = getCookie(name, subname);
	if (oldval!=null) {
		//cookie "name" exists and subkey "subname" exists
		dc = dc.replace( subname+'='+oldval, (subname+'='+newval));
	} else {
		//new subvalue
		if (dc.indexOf(name + '=')==-1) {
			//newval is first value of cookie "name"
			dc= subname+'='+ newval+';'
		} else {
			//cookie "name" exists but subkey "subname" does not
			var prefix = name + "=";
			var begin = dc.indexOf("; " + prefix);
			if (begin == -1) {
				begin = dc.indexOf(prefix);
				if (begin != 0) return null;
			} else {
				begin += 2;
			}
			var end = document.cookie.indexOf(";", begin);
			if (end == -1) {
				end = dc.length;
			}
		    
			var cookieString = dc.substring(begin + prefix.length, end);
			dc= subname +'='+ newval +'&'+ cookieString 
		}
	}
	var exdate=new Date()
	exdate.setDate(exdate.getDate()+expiredays)
	var CS = name+'='+ dc +';'+ ((expiredays==null) ? '' : ' expires='+exdate.toGMTString());
	CS+='; path=/';
	document.cookie = CS;
}

function extractSRCookie(name){
    var dc = document.cookie;
    if (!dc){return false;}
    var prefix = encodeURI(name) + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    
    return decodeURIComponent(dc.substring(begin + prefix.length, end)) ;
}



function fnConfirmRestart() {
	return confirm (aryErr["progRestart"])
}

Date.prototype.toSR = function(){ //returns date in YYYY-MM-DD format
    var sr = this.toJSON().replace(/"/g,'');
    return sr.substring(0,sr.indexOf('T'));
}
Date.prototype.toSS = function(){ //returns date in YYYY-MM-DD format as used by skyscanner
    var sr = this.toSR().replace(/-/g,'');
    return sr.substring(2,sr.length);
}
// the date format prototype
Date.prototype.format = function(f)
{
    if (!this.valueOf())
        return '&nbsp;';

    var d = this;
    return f.replace(/(yyyy|mmmm|mmm|mm|dddd|ddd|dd|hh|nn|ss|a\/p)/gi,
        function($1)
        {
            switch ($1.toLowerCase())
            {
            case 'yyyy': return d.getFullYear();
            case 'mmmm': return gsMonthNames[d.getMonth()];
            case 'mmm':  return gsMonthNames[d.getMonth()].substr(0, 3);
            case 'mm':   return (d.getMonth() + 1).zf(2);
            case 'dddd': return gsDayNames[d.getDay()];
            case 'ddd':  return gsDayNames[d.getDay()].substr(0, 3);
            case 'dd':   return d.getDate();
            case 'hh':   return ((h = d.getHours() % 12) ? h : 12);
            case 'nn':   return d.getMinutes();
            case 'ss':   return d.getSeconds();
            case 'a/p':  return d.getHours() < 12 ? 'a' : 'p';
            }
        }
    );
}

function fnToggleVis (obj){
	obj.style.display = (obj.style.display=="none")?"block":"none";
}


function fnEquipPopUp(strBody, objParent, intCount) {
	var oPopup = window.createPopup();
	oPopup.document.createStyleSheet("/style/popup.css");
	var oPopBody = oPopup.document.body;
    oPopBody.innerHTML = strBody;
    oPopup.document.className = "sr_equipPopUp";
    oPopup.show(0, 20, 280, 15+15*intCount, objParent);
}


function fnSearchTerm ( strText ) {
	strTerm = strText.split(" ").join("-")
	strTerm = "/search/" + strTerm + "/" + strTerm + ".html"
	document.location.href=strTerm
}

function fnCheckout ( objForm ) {
	strErr = (priv_fnGetObject("sr_clientfname").value=="") ? aryErr["ch_fname"]+"\n" : "";
	strErr += (priv_fnGetObject("sr_clientsname").value=="") ? aryErr["ch_sname"]+"\n" : "";
	strErr += (priv_fnGetObject("sr_clientemail").value=="") ? aryErr["ch_email"]+"\n" : "";
	if (strErr!="") { 
		alert (aryErr["ch_intro"]+"\n"+"\n"+strErr);
		return false;
	} else {
		return fnAcceptTerms;
	}
}

function fnSetHelmet( objRadio, strID ) {
	objHref = priv_fnGetObject( strID+"_href" );
	objButton = priv_fnGetObject( strID );
	strHRef = objHref.value;
	strHRef = fnPriv_UpdateQS ( strHRef, "sr_he", objRadio.value );
	objHref.value = strHRef;
	objButton.onclick = function () {document.location.href=strHRef};
}
function fnSetModel( objRadio, strID ) {
	objHref = priv_fnGetObject( strID+"_href" );
	objButton = priv_fnGetObject( strID );
	strHRef = objHref.value;
	strHRef = fnPriv_UpdateQS ( strHRef, "sr_eid", objRadio.value );
	alert (strHRef)
	objHref.value = strHRef;
	objButton.onclick = function () {document.location.href=strHRef};
}
function fnSetInsurance( objBox, strID ) {
	objHref = priv_fnGetObject( strID+"_href" );
	objButton = priv_fnGetObject( strID );
	strHRef = objHref.value;
	if (objBox.checked) {
		strHRef = fnPriv_UpdateQS ( strHRef, "sr_in", "true" );
	} else {
		strHRef = fnPriv_UpdateQS ( strHRef, "sr_in", "false" );
	}
	objHref.value = strHRef;
	objButton.onclick = function () {document.location.href=strHRef};
}
function fnSetChooseModel( objBox, intShopID ) {
	objForm = document.getElementById( "sr_shop_"+ intShopID )
	if (objBox.checked) {
		objForm.sr_m.value=""
		objForm.sr_view.value="list"
		//strHRef = fnPriv_UpdateQS ( strHRef, "sr_se", "true" );
		//strHRef = fnPriv_UpdateQS ( strHRef, "sr_m", "" );
	} else {
		objForm.sr_m.value="1"
		objForm.sr_view.value="basket"
		//strHRef = fnPriv_UpdateQS ( strHRef, "sr_m", "1" );
		//strHRef = fnPriv_UpdateQS ( strHRef, "sr_view", "basket" );
	}
	//objHref.value = strHRef;
	//objButton.onclick = function () {document.location.href=strHRef};
}
function PopUp(doc){
	width=600
	height=450
	scrll="yes"
	toolbar="no"
	//status="yes"
	if (arguments.length>1){
		width=arguments[1]
		height=arguments[2]
		scrll=arguments[3]
		toolbar=arguments[4]
	}
	properties="width="+width+",height="+height+",scrollbars="+scrll+",toolbar="+toolbar
		doc=window.open (doc,"SnowRentalInfoPopup",properties)
		doc.focus();
}

function fnBasket_Item_Add( elem, strEquipLevel, strEquipCat, strEquipName, ShopID, OnlinePrice, FullPrice ) {
	objSnowRental = priv_fnGetFormObject();
	objSnowRental.m.value=1;
	objSnowRental.view.value='basket';
	objSnowRental.category.value = strEquipCat;
	objSnowRental.level.value = strEquipLevel;
	objSnowRental.equipmentname.value = strEquipName;
	objSnowRental.shopid.value=ShopID;
	objSnowRental.onlineprice.value=OnlinePrice;
	objSnowRental.fullprice.value=FullPrice;
	objSnowRental.submit();
}
function fnBasket_More( ) {
	objSnowRental = priv_fnGetObject("frmSnowRental");
	priv_fnGetObject("sr_view").value="list"
	priv_fnGetObject("sr_m").value=""
	objSnowRental.action="/rent-skis.asp?page=shop"
	objSnowRental.submit();
}

function fnPayment_Submit () {
	objSnowRental = priv_fnGetObject("frmSnowRental");
	objSnowRental.submit();
}

function priv_fnGetFormObject() {
	//test for browser and use appropriate method to get form
	//IE 5+
	return priv_fnGetObject ("frmSnowRental")
}
function priv_fnGetObject( strID ) {
	//test for browser and use appropriate method to get form
	if (document.getElementById) {
		return document.getElementById (strID)
	} else {
		return document.all[strID]
	}
}


function fnPriv_UpdateQS ( strHref, strName, strValue ) {
	//strHref = document.location.href;
	if (strHref.indexOf("?")<1) {
		strStub= strHref
		strNewQS = strName +"="+ strValue
	} else {
		strStub = strHref.slice (0, strHref.indexOf("?")) 
		strQS = strHref.slice (strHref.indexOf("?")+1);

		aryPairs = strQS.split("&");
		aryQS = new Array();
		for (i=0; i<aryPairs.length; i++) {
			aryNameValue = aryPairs[i].split("=");
			aryQS[aryNameValue[0]] = aryNameValue[1];
		}
		if (strName!="") { aryQS[strName] = strValue ;}
		aryNewQS = new Array();
		for (element in aryQS) {
			strNameValue = element +"="+ aryQS[element]
			aryNewQS = aryNewQS.concat ( Array(strNameValue) );
		}
		strNewQS = aryNewQS.join("&");
	}
	
	return (strStub +"?"+ strNewQS) 
}

function fnPriv_GetListValue ( objList ) {
	if (objList == null ) {return "";}
	if (objList.options == null ) {return "";}
	if (objList.disabled == true ) {return "";}
	strValues = objList.options[objList.selectedIndex].value
	return strValues;
}

function fnPriv_GetRadioValue ( objRadio ) {
    strValue = "";
	for (i=0; i< objRadio.length; i++) {
      if (objRadio[i].checked) {strValue = objRadio[i].value}
    }
	return strValue;
}
function fnPriv_CopyObj(obj) {
    var i;
    var newObj = new Object();
    for (i in obj) {
        newObj[i] = obj[i];
        }
    return newObj;
}
function fnLimitKeys(control){
//limit to only numbers
	IE4 = (document.all);
	NS4 = (document.layers);
	if (NS4) document.captureEvents(Event.KEYPRESS);
	control.onkeypress = doKey;
	
	function doKey(e) {
		whichASC = (NS4) ? e.which : event.keyCode;
		whichKey = String.fromCharCode(whichASC).toLowerCase();
		if (whichKey.match(/[1234567890]/)){
			return true
		}
		else{
			return false
		}
	}
}

function listHeadlines(root) {
    var feed = root.feed;
    var entries = feed.entry || [];
    var html = [''];

    for (var i = 0; i < feed.entry.length; ++i) {
      var entry = feed.entry[i];
      var title = entry.title.$t;
      var url = entry.link[0].href;
      //var start = entry['gd$when'][0].startTime;

      html.push('<a href="'+ url +'">',title, '</a> | ');
    }
    document.getElementById("sr_headlines").innerHTML = html.join("");
  }
  
  
Date.prototype.getWeek = function (dowOffset) {/*getWeek() was developed by Nick Baicoianu at MeanFreePath: http://www.meanfreepath.com */	
    dowOffset = typeof(dowOffset) == 'int' ? dowOffset : 0; 
    //default dowOffset to zero	
    var newYear = new Date(this.getFullYear(),0,1);	
    var day = newYear.getDay() - dowOffset; 
    //the day of week the year begins on	
    day = (day >= 0 ? day : day + 7);	
    var daynum = Math.floor((this.getTime() - newYear.getTime() - 	(this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;	
    var weeknum;	//if the year starts before the middle of a week	
    if(day < 4) {
        weeknum = Math.floor((daynum+day-1)/7) + 1;
        if(weeknum > 52) {
            nYear = new Date(this.getFullYear() + 1,0,1);
            nday = nYear.getDay() - dowOffset;
            nday = nday >= 0 ? nday : nday + 7;
            /*if the next year starts before the middle of
            the week, it is week #1 of that year*/
            weeknum = nday < 4 ? 1 : 53;		}	}
        else {
            weeknum = Math.floor((daynum+day-1)/7);
        }	
        return weeknum+1; //+1 added as out by one and I havent figured out why
    };
