function SendHotelToFriend(iOfferID) {
	sEmail = document.getElementById('EmailForHotelInfo').value;
	if(!sEmail) {
		alert('Please enter an email address!');
	}else{
		sURL = '/includes/mailoffer.asp?id='+iOfferID+'&email='+sEmail+'&casperas';
		updateDivAJAX('divAjaxHolder',sURL,'');
		setTimeout("alert('Email sent to your friend!');document.getElementById('EmailForHotelInfo').value='';",1000);
	}
}

var SelectedOfferTab = 'offer_tab1';
function SwitchOfferSearch(id) {
	for(x=1;x<8;x++) {
		if(document.getElementById('offer_tab'+x) && x<7) {
			document.getElementById('offer_tab'+x).className = 'searchtab';
		}
		if(document.getElementById('offer'+x)) {
			document.getElementById('offer'+x).style.display = 'none';
		}
	}
	SelectedOfferTab = id;
	if(document.getElementById(id)) {
		document.getElementById(id).className = 'searchtabOver';
	}
	if(document.getElementById('offer'+Right(id,1))) {
		document.getElementById('offer'+Right(id,1)).style.display = '';
	}
	if(document.getElementById('offer_tab7')) {
		document.getElementById('offer_tab7').className = 'searchtabOrange';
	}
	if(document.getElementById('offer_tab8')) {
		document.getElementById('offer_tab8').className = 'searchtabGreen';
	}
}


function SwitchOfferTabs(id, on) {
	if(SelectedOfferTab!=id) {
		sExtra = '';
		if(on==1){
			if(document.getElementById(id).className.indexOf('Over')<0){
				document.getElementById(id).className = document.getElementById(id).className + 'Over'
			}else{
				SelectedSearchTab = id;
			}
		}else{
			if(document.getElementById(id).className.indexOf('Over') > -1) {
				document.getElementById(id).className = Left(document.getElementById(id).className,document.getElementById(id).className.length-4);
			}
		}
	}
}



// JavaScript Document
function showImageFromThumbnail(sURL) {
	grayOut(true);
	document.getElementById('thumbnailDiv').innerHTML = '<div align="right" style="padding:2px 15px 4px 0px;"><a href="#" onclick="hideImageFromThumbnail()">Close image viewer</a></div><img src="'+sURL+'" style="margin:0px 15px 15px 15px;" id="largeImage" name="largeImage" onclick="hideImageFromThumbnail()" />';
	document.getElementById('thumbnailDiv').style.display='block';
	document.getElementById('thumbnailDiv').style.marginLeft='-'+parseFloat(document.images.largeImage.width/2)+'px';
}
function hideImageFromThumbnail() {
	grayOut(false);
	document.getElementById('thumbnailDiv').innerHTML = '';
	document.getElementById('thumbnailDiv').style.display='none';
}

function showGoogleMap(iLat, iLng) {
	grayOut(true);
	document.getElementById('googleMapDiv').innerHTML = '<div align="right" style="padding:2px 15px 4px 0px;"><a href="javascript:hideGoogleMap()">Close map viewer</a></div><div id="popupMap" style="margin:0px 15px 15px 15px;"></div>';
	document.getElementById('googleMapDiv').style.display='block';
	document.getElementById('googleMapDiv').style.marginLeft='-250px';
	LoadGoogleMap('popupMap',iLat,iLng);
}
function hideGoogleMap() {
	grayOut(false);
	document.getElementById('googleMapDiv').innerHTML = '';
	document.getElementById('googleMapDiv').style.display='none';
}

var items, currentitem, currentindex, currentopacity=0, currentposition, newswidth;
 
function initNewsTicker() {
  var news = document.getElementById("newsticker");
  if (news != null) {
    items = news.getElementsByTagName("li");
    if (items != null) {
      for (i=0; i<items.length; i++) {
        items[i].style.opacity = 0;
        items[i].style.filter = "alpha(opacity=0)";
        items[i].style.display = "none";
      }
      currentindex = 0;
      currentopacity = 1;
      currentposition = 0;
      currentitem = items[currentindex];
      currentitem.style.opacity = 1;
      currentitem.style.filter = "alpha(opacity=100)";
      currentitem.style.display = "block";
      window.setTimeout(fadeout, 5000);
    }
  }
}
 
function next() {
  currentindex = ++currentindex % items.length;
  currentitem = items[currentindex];
  currentitem.style.display = "block";
  currentitem.style.opacity = 1;
  currentitem.style.filter = "alpha(opacity=100)";
  currentopacity = 1;
  fadein();
}
 
function fadein() {
  if(currentposition > 0) {
    currentposition -= 2;
    currentitem.style.margin = "0 0 0 "+currentposition+"px";
    window.setTimeout(fadein, 20);
  } else {
    currentposion = 0;
    currentitem.style.margin = "0 0 0 0";
    window.setTimeout(fadeout, 2000);
  }
}
 
function fadeout() {
  currentopacity -= 0.02;
  currentopacity = parseInt(currentopacity*100)/100;
  if (currentopacity > 0) {
    currentitem.style.opacity = currentopacity;
    currentitem.style.filter = "alpha(opacity="+(currentopacity*100)+")";
    window.setTimeout(fadeout, 20);
  }
  else {
    currentitem.style.opacity = 0;
    currentitem.style.filter = "alpha(opacity=0)";
	currentitem.style.display = "none";
	currentposition = 250;
	currentopacity = 0;
    next();
  }
}


var TAFurl = '';
var TAFFromTop, TAFFromLeft;
function TellAFriendNews(sAction, sValues, bFromTop, bFromLeft) {
	if(bFromTop){
		TAFFromTop = true;	
	}else{
		TAFFromTop = false;	
	}
	if(bFromLeft){
		TAFFromLeft = true;	
	}else{
		TAFFromLeft = false;	
	}
	if(document.getElementById('divTellAFriendNews')) {
		PlaceHolder = document.getElementById('divTellAFriendNews');
		FramePlaceHolder = document.getElementById('frameTellAFriendNews');
		if(!sAction) {
			TAFurl = location.href;
			grayOut(true);
			FramePlaceHolder.style.display='block';
			PlaceHolder.style.display='block';
			if(bFromLeft) {
				FramePlaceHolder.style.left = MouseXPosition+'px';
				PlaceHolder.style.left = MouseXPosition+'px';

			}else{
				FramePlaceHolder.style.left = MouseXPosition-370+'px';
				PlaceHolder.style.left = MouseXPosition-370+'px';
			}
			if(bFromTop) {
				FramePlaceHolder.style.top = MouseYPosition-330+'px';
				PlaceHolder.style.top = MouseYPosition-330+'px';
			}else{
				FramePlaceHolder.style.top = MouseYPosition+'px';
				PlaceHolder.style.top = MouseYPosition+'px';
			}
		}
		PlaceHolder.innerHTML = '<div align="center" style="padding-top:50px; font-weight:bold;"><img src="/images/animations/ajax-loader-white.gif"/><br/><br/>Please wait...</div>';
		sURL = "/includes/tellafriend/tellafriendnews.asp?action=" + sAction + "&test=casptae&values=" + sValues
		if(sURL!='') {
			if(bDebug) {
				if(confirm('Open '+ sURL)) {
					window.open(sURL);
				}
			}
			setTimeout("loadTAFDocNews('"+sURL+"')", 500);
		}else{
			alert('No url defined');	
		}
	}
}

function CloseTAFNews() {
	if(document.getElementById('divTellAFriendNews')) {
		FramePlaceHolder = document.getElementById('frameTellAFriendNews');
		FramePlaceHolder.style.display='none';
		PlaceHolder = document.getElementById('divTellAFriendNews');
		PlaceHolder.style.display='none';
		grayOut(false);
	}
}

function loadTAFDocNews(url) {
    // branch for native XMLHttpRequest object
	if (window.XMLHttpRequest) {
        reqTAF = new XMLHttpRequest();
		reqTAF.onreadystatechange = processTAFNews;
        reqTAF.open("GET", url, true);
        reqTAF.send(null);
    // branch for IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        reqTAF = new ActiveXObject("Microsoft.XMLHTTP");
        if (reqTAF) {
            reqTAF.onreadystatechange = processTAFNews;
            reqTAF.open("GET", url, true);
            reqTAF.send();
        }
    }
}
function processTAFNews() {
	if (reqTAF.readyState == 4) {
		if (reqTAF.status == 200){
			PlaceHolder = document.getElementById('divTellAFriendNews');
			PlaceHolder.innerHTML = reqTAF.responseText;
		}
	}
}

function SubmitTAFNews(oFrm) {
	var e='';
	sYourName = oFrm.yourname.value;
	sYourEmail = oFrm.youremail.value;
	sFriendName = oFrm.friendname.value;
	sFriendEmail = oFrm.friendemail.value;
	//sNote = encodeURIComponent(oFrm.note.value);
	var iSendCopy = 0;
	if(oFrm.sendcopy.checked==true){
		iSendCopy = 1;
	}
	if(!sYourName){e+='- Please enter your name\n'}
	if(!/.+@[^.]+(\.[^.]+)+/.test(sYourEmail) || isValidField(sYourEmail,2) == false || sYourEmail=='Enter your email'){e+='- Please enter your valid email address\n'}
	if(!sFriendName){e+='- Please enter your friends name\n'}
	if(!/.+@[^.]+(\.[^.]+)+/.test(sFriendEmail) || isValidField(sFriendEmail,2) == false || sFriendEmail=='Enter your email'){e+='- Please enter your friends valid email address\n'}
	if(e) {
		alert('The following errors occurred!\n\n'+e);
	}else{
		TellAFriendNews('sendemail',sYourName + '|' + sYourEmail + '|' + sFriendName + '|' + sFriendEmail + '|' + iSendCopy + '|' + TAFurl, TAFFromTop);
	}
	return false;
}

function bookmark(url, title){
	if (window.sidebar){ // firefox
		window.sidebar.addPanel(title, url, "");
	}else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}else if(document.all){// ie
		window.external.AddFavorite(url, title);
	}
}
