// top of page
function backToTop() {
    var x1 = x2 = x3 = 0;
    var y1 = y2 = y3 = 0;

    if (document.documentElement) {
        x1 = document.documentElement.scrollLeft || 0;
        y1 = document.documentElement.scrollTop || 0;
    }

    if (document.body) {
        x2 = document.body.scrollLeft || 0;
        y2 = document.body.scrollTop || 0;
    }

    x3 = window.scrollX || 0;
    y3 = window.scrollY || 0;

    var x = Math.max(x1, Math.max(x2, x3));
    var y = Math.max(y1, Math.max(y2, y3));

    window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

    if (x > 0 || y > 0) {
        window.setTimeout("backToTop()", 25);
    }
}

//Suckerfish JavaScript menu
sfHover = function() {
	if (document.getElementById("nav")) {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) 			
			{
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}	
			
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover); 

// Show full image
function showFullImage(imgPath,imgHeight,imgWidth,imgAlt){
	var image = document.getElementById('photo');
	// Change image attributes
	if(document.getElementById && image != null){
		image.src=imgPath;
		image.height=imgHeight;
		image.width=imgWidth;
		image.alt=imgAlt;
		image.title=imgAlt;
	}
}


// Open print page using _print extension.
function showPrint(strPage) {
	//var strPage = window.location.pathname;
	
	var strQuery = strPage.substr(strPage.indexOf("?"));
	var strPage = strPage.substring(0, strPage.indexOf("_1.aspx"));
	
	if(strPage.toLowerCase().indexOf("chalet_search") != -1) {
		strPage = "chalet_search";	
	}
	else if(strPage.toLowerCase().indexOf("document_features") != -1) {
			strPage = "document_features";	
	}
	else if(strPage.toLowerCase().indexOf("document_alt_features") != -1) {
		strPage = "document_features";	
	}
	else if(strPage.toLowerCase().indexOf("resort") != -1) {
		strPage = "resort";	
	}
	else if(strPage.toLowerCase().indexOf("specials") != -1) {
		strPage = "specials";	
	}
	else if(strPage.toLowerCase().indexOf("chalet_prices") != -1) {
		strPage = "chalet_prices";	
	}
	else if(strPage.toLowerCase().indexOf("chalet") != -1) {
		strPage = "chalet";	
	}
	else if(strPage.toLowerCase().indexOf("papers") != -1) {
		strPage = "papers";	
	}
	else if(strPage.toLowerCase().indexOf("press") != -1) {
		strPage = "press";	
	}
	else if(strPage.toLowerCase().indexOf("news") != -1) {
		strPage = "news";	
	}
	else if(strPage.toLowerCase().indexOf("vacancies") != -1) {
			strPage = "vacancies";	
	}
	else if(strPage.toLowerCase().indexOf("menu") != -1) {
		strPage = "menu";	
	}
	else if(strPage.toLowerCase().indexOf("search") != -1) {
		strPage = "search";	
	}
	else {
		// set document as default
		strPage = "document";
	}
	/*window.location = strPage + "_print_1.aspx" + window.location.search;*/
	//window.open(strPage + "_print_1.aspx" + window.location.search);
	window.open(strPage + "_print_1.aspx" + strQuery);
	
	
}

// Print page dialog
function printpage() {
  window.print();
}

// Search site
function checkSearchFields(objForm)
{	

		if(trim(objForm.keywords.value) == "" || objForm.keywords.value == " Search the site...") {
			alert("Please enter your keyword(s)");
			objForm.keywords.value='';
			objForm.keywords.focus();
			return false;
		}
		else {
			return true;
		}
}

// Expand menu open/close
function toggle_menu(c) {	
  var el = document.getElementById(c);
  if (el.style.display != 'none' ) {
    el.style.display = 'none';
  }
  else {
    el.style.display = 'block';
  }
}


// Show & Hide
function show(c) {
	if (document.getElementById && document.getElementById(c)!= null) 
		node = document.getElementById(c).style.display='block'; 
	else if (document.layers && document.layers[c]!= null) 
		document.layers[c].display = 'block'; 
	else if (document.all && document.all(c)!= null) 
		document.all[c].style.display = 'block';
} 

function hide(c) {	
	if (document.getElementById && document.getElementById(c)!= null)
		node = document.getElementById(c).style.display='none';
	else if (document.layers && document.layers[c]!= null) 
		document.layers[c].display = 'none';
	else if (document.all && document.all(c)!= null) 
		document.all[c].style.display = 'none';
}

//Trim string
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}
//End Function

//Right Trim string
function rtrim(str)
{
	return str.replace(/\s*$/, ""); 
}
//End Function

//Left Trim string
function ltrim(str)
{
	return str.replace(/^\s*/, ""); 
}
//End Function


// Macromedia
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// IPIXS window
var viewer;

function ipixs(theURL) {
  w = 325;
  h = 270;
  LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
  TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  viewer = window.open('map_ipix.asp?ipix=' + theURL,'Viewer','top='+TopPosition+',left='+LeftPosition+',width='+w+',height='+h+',menubar=0,resizable=0,toolbar=0,location=0,status=0,scrollbars=0');
}
function ipixs_close()
{
 if(viewer && !viewer.closed) 
 {
    viewer.close();
 }
}

/*** keep alive ***/
document.write("<script type=\"text/javascript\" src=\"assets/scripts/EdeptiveAjax.js\"></script>");
var goAjax = null;
function keepAlive() {
	var strUrl = "";
	var sTiming = document.lastChild.lastChild.innerHTML;
	var sParams = "";

	sTiming = sTiming.substring(sTiming.lastIndexOf("<!--"));
	sTiming = sTiming.substring(5, sTiming.indexOf(" -->"));
	strUrl = window.location.protocol + "//" + window.location.host + "/webservices/keep_alive.asmx/PingWithTiming";
	sParams = "Timing=" + sTiming;
	try {
		goAjax = new EdeptiveAjax();
		goAjax.postRequest(strUrl, sParams, onKeepAliveResponse);
	} catch(e) {
		setTimeout("keepAlive()", 1000*1);
	}
}
function onKeepAliveResponse() {
	if(goAjax.checkReadyState("keepAlive", "ping.", "ping..", "ping...") == "OK") {
		if(document.getElementById("keepAlive")) {
			var response = goAjax.request.responseXML.documentElement;
			document.getElementById("keepAlive").innerText = "sid=" + getText(response.firstChild);
		}
		setTimeout("keepAlive()", 1000*60);
	}
}
setTimeout("keepAlive()", 1000*2);
