// Hotel Advice Scripts

function validateForm(theForm){
	for (var j=0; j<(theForm.elements.length); j++){
		index = theForm.elements[j].name.indexOf('_required');
		if(index != -1){
			fieldName = theForm.elements[j].name.substring(0,index);
			if(theForm.elements[fieldName].value == 0){
				alert(theForm.elements[j].value);
				j = (theForm.elements.length);
				return false;
			}
		}
		index03 = theForm.elements[j].name.indexOf('_drop');
		if(index03 != -1){
			dropDown = theForm.elements[j].name.substring(0,index03);
			if(theForm.elements[dropDown].selectedIndex == 0){
				alert(theForm.elements[j].value);
				j = (theForm.elements.length);
				return false;
			}	
		}
		index04 = theForm.elements[j].name.indexOf('_confirm');
		if(index04 != -1){
			fieldName = theForm.elements[j].name.substring(0,index04);
			fieldName02 = "confirm" + fieldName;
			if(theForm.elements[fieldName].value != theForm.elements[fieldName02].value){
				alert(theForm.elements[j].value);
				j = (theForm.elements.length);
				return false;
			}
		}
		if(theForm.elements[j].name == 'commsData1' | theForm.elements[j].name == 'email' | theForm.elements[j].name == 'emailAddress'){
			returnVal = validateEmail(theForm.elements[j].value);
			if(returnVal == false){
				j = (theForm.elements.length);
				return false;
			}
		}
	}
	returnVal = checkChars(theForm);
	if(returnVal == false){
		return false;
	}else{
		return true;
	}
}

function validateEmail(theEmail){
	var e = theEmail;
	if((e.indexOf('@')) == -1){
		alert('Please enter a valid email address');
		return false;
	}else{
		return true;
	}
}


function standardChanger(dropdown){
	var tempURL = dropdown.options[dropdown.selectedIndex].value;
	if(tempURL!="") {
		document.location.href = tempURL;
	}
}

function matchEmails(theForm){
	var value01 = theForm.commsData1.value;
	var value02 = theForm.commsData1a.value;
	if(value01 != value02){
		alert('Please make sure your emails match');
		return false;
	}else{
		return true;
	}
}

/* for dom related stuff */
var isNav4, isNav6Plus, isIE4;

/* Returns Browser Versions */
function setBrowser(){
	if(navigator.appVersion.charAt(0) == "4"){
		if(navigator.appName.indexOf("Explorer") >= 0){
			isIE4 = true;
		}else{
			isNav4 = true;
		}
	}else if(navigator.appVersion.charAt(0) > "4"){
		isNav6Plus = true;
	}
}

/*	SET PROPERTY BY ID
	When given an ID and property (as strings), 
	sets the given property to the value provided 
*/
function setIdProperty(id, property, value){
	if(isNav6Plus){
		var styleObject = document.getElementById(id);
		if(styleObject != null){
			styleObject = styleObject.style;
			styleObject[property] = value;
		}
	}else if (isNav4){
		document[id][property] = value;
	}else if (isIE4){
		document.all[id].style[property] = value;
	}
}

function getIDProperty( id, property ){
    if (isNav6Plus){
        var styleObject = document.getElementById(id);
        if (styleObject != null){
            styleObject = styleObject.style;
            if (styleObject[property]){
                return styleObject[ property ];
            }
        }
        styleObject = getStyleBySelector( "#" + id );
        return (styleObject != null) ? styleObject[property] : null;
    }else if (isNav4){
        return document[id][property];
    }else{
        return document.all[id].style[property];
    }
}

function checkChars(form){
	var x = 0;
	var formOk  = true;
	while ((x < form.elements.length) && (formOk)){
		var str = form.elements[x].value;
		var re = /(<+)|(>+)/;
		if(re.test(str)){
			formOk = false; 
			alert("Sorry, the characters '<' and '>' are not valid in Hotel Advice\rPlease try again.");
			form.elements[x].focus()
		}
		x ++;
	}
	return formOk;
}

/*
Left-Right image slideshow Script
By Dynamic Drive (www.dynamicdrive.com)
For full source code, terms of use, and 100's more scripts, visit http://dynamicdrive.com
*/

///////configure the below four variables to change the style of the slider///////
//set the scrollerwidth and scrollerheight to the width/height of the LARGEST image in your slideshow!
var scrollerwidth = '300px';
var scrollerheight = '100px';
var scrollerbgcolor = 'white';
//3000 miliseconds = 3 seconds
var pausebetweenimages = 3000;

//configure the below variable to change the images used in the slideshow. If you wish the images to be clickable, simply wrap the images with the appropriate <a> tag
var slideimages = new Array();
slideimages[0] = '<img src="http://www.hotel-barcelona.com/images/rotation/1.jpg" alt="rotatingImage" title=""><img src="http://www.hotel-barcelona.com/images/spacer.gif" width="1" height="100" alt="spacer"><img src="http://www.hotel-barcelona.com/images/rotation/2.jpg" alt="rotatingImage" title="">';
slideimages[1] = '<img src="http://www.hotel-barcelona.com/images/rotation/3.jpg" alt="rotatingImage" title=""><img src="http://www.hotel-barcelona.com/images/spacer.gif" width="1" height="100" alt="spacer"><img src="http://www.hotel-barcelona.com/images/rotation/4.jpg" alt="rotatingImage" title="">';
slideimages[2] = '<img src="http://www.hotel-barcelona.com/images/rotation/5.jpg" alt="rotatingImage" title=""><img src="http://www.hotel-barcelona.com/images/spacer.gif" width="1" height="100" alt="spacer"><img src="http://www.hotel-barcelona.com/images/rotation/6.jpg" alt="rotatingImage" title="">';
slideimages[3] = '<img src="http://www.hotel-barcelona.com/images/rotation/7.jpg" alt="rotatingImage" title=""><img src="http://www.hotel-barcelona.com/images/spacer.gif" width="1" height="100" alt="spacer"><img src="http://www.hotel-barcelona.com/images/rotation/4.jpg" alt="rotatingImage" title="">';
//extend this list

///////Do not edit pass this line///////////////////////

var ie = document.all;
var dom = document.getElementById;
var i;

if(slideimages.length > 1) {
  i = 2;
} else {
  i = 0;
}

function move1(whichlayer) {
  tlayer = eval(whichlayer);
  if((tlayer.left > 0) && (tlayer.left <= 5)) {
    tlayer.left = 0;
    setTimeout("move1(tlayer)", pausebetweenimages);
    setTimeout("move2(document.main.document.second)", pausebetweenimages);
    return;
  }
  if(tlayer.left >= (tlayer.document.width*-1)) {
    tlayer.left -= 5;
    setTimeout("move1(tlayer)", 50);
  } else{
    tlayer.left = parseInt(scrollerwidth)+5;
    tlayer.document.write(slideimages[i]);
    tlayer.document.close();
    if(i == (slideimages.length-1)) {
      i = 0;
    } else {
      i++;
    }
  }
}

function move2(whichlayer) {
  tlayer2 = eval(whichlayer);
  if((tlayer2.left > 0) && (tlayer2.left <= 5)) {
    tlayer2.left = 0;
    setTimeout("move2(tlayer2)", pausebetweenimages);
    setTimeout("move1(document.main.document.first)", pausebetweenimages);
    return;
  }
  if(tlayer2.left >= (tlayer2.document.width*-1)) {
    tlayer2.left -= 5;
    setTimeout("move2(tlayer2)", 50);
  } else{
    tlayer2.left = parseInt(scrollerwidth)+5;
    tlayer2.document.write(slideimages[i]);
    tlayer2.document.close();
    if(i == (slideimages.length-1)) {
      i = 0;
    } else {
      i++;
    }
  }
}

function move3(whichdiv) {
  tdiv = eval(whichdiv);
  if((parseInt(tdiv.style.left) > 0) && (parseInt(tdiv.style.left) <= 5)) {
    tdiv.style.left = 0+"px";
    setTimeout("move3(tdiv)", pausebetweenimages);
    setTimeout("move4(scrollerdiv2)", pausebetweenimages);
    return;
  }
  if(parseInt(tdiv.style.left) >= (tdiv.offsetWidth*-1)) {
    tdiv.style.left = (parseInt(tdiv.style.left)-5)+"px";
    setTimeout("move3(tdiv)", 50);
  } else {
    tdiv.style.left = scrollerwidth;
    tdiv.innerHTML = slideimages[i];
    if(i == (slideimages.length-1)) {
      i = 0;
    } else {
      i++;
    }
  }
}

function move4(whichdiv) {
  tdiv2 = eval(whichdiv);
  if((parseInt(tdiv2.style.left) > 0) && (parseInt(tdiv2.style.left) <= 5)) {
    tdiv2.style.left = 0+"px";
    setTimeout("move4(tdiv2)", pausebetweenimages);
    setTimeout("move3(scrollerdiv1)", pausebetweenimages);
    return;
  }
  if(parseInt(tdiv2.style.left) >= (tdiv2.offsetWidth*-1)) {
    tdiv2.style.left = (parseInt(tdiv2.style.left)-5)+"px";
    setTimeout("move4(scrollerdiv2)", 50);
  } else {
    tdiv2.style.left = scrollerwidth;
    tdiv2.innerHTML = slideimages[i];
    if(i == (slideimages.length-1)) {
      i = 0;
    } else {
      i++;
    }
  }
}

function startscroll() {
  if(slideimages.length > 1) {
    i = 2;
  } else {
    i = 0;
  }
  if(ie || dom) {
    if(document.getElementById("first2") && document.getElementById("second2")) {
      scrollerdiv1 = ((ie) ? first2 : document.getElementById("first2"));
      scrollerdiv2 = ((ie) ? second2 : document.getElementById("second2"));
      move3(scrollerdiv1);
      scrollerdiv2.style.left = scrollerwidth;
    }
  } else if(document.layers) {
    document.main.visibility = 'show';
    move1(document.main.document.first);
    document.main.document.second.left = parseInt(scrollerwidth)+5;
    document.main.document.second.visibility = 'show';
  }
}

function changeLayer(elm) {
  var description = document.getElementById('description_layer');
  var tldesc = document.getElementById('tldesc');
  var photos = document.getElementById('photos_layer');
  var tlphoto = document.getElementById('tlphoto');
  var locationMap = document.getElementById('locationMap_layer');
  var tlmap = document.getElementById('tlmap');

  if(elm == 'tldesc') {
    description.style.display = 'block';
    tldesc.className = 'current';
    tldesc.blur();
    photos.style.display = 'none';
    tlphoto.className = '';
    locationMap.style.display = 'none';
    tlmap.className = '';
  } else if(elm == 'tlphoto') {
    description.style.display = 'none';
    tldesc.className = '';
    photos.style.display = 'block';
    tlphoto.className = 'current';
    tlphoto.blur();
    locationMap.style.display = 'none';
    tlmap.className = '';
  } else if(elm == 'tlmap') {
    description.style.display = 'none';
    tldesc.className = '';
    photos.style.display = 'none';
    tlphoto.className = '';
    locationMap.style.display = 'block';
    tlmap.className = 'current';
    tlmap.blur();
    if(window.loadMap) {
      loadMap();
    }
  }
}

function expandTableList(elm) {
  var elay = document.getElementById(elm+'Layer');
  var erow = document.getElementById(elm+'Row');
  if(elay != undefined && erow != undefined) {
    if(erow.className == "tableListHidden") {
      erow.className = "tableListExpanded";
    } else {
      erow.className = "tableListHidden";
    }
    if(elay.className == "tableListHidden") {
      elay.className = "tableListExpanded";
    } else {
      elay.className = "tableListHidden";
    }
  }
}

function expandAllInTableList() {
  var divs = document.getElementsByTagName('tr');
  var t, row;
  for(c in divs) {
    if(divs[c].id != undefined) {
      if(divs[c].id.search('Layer') >= 0) {
        divs[c].className = "tableListExpanded";
      } else if(divs[c].id.search('Row') >= 0) {
        divs[c].className = "tableListHidden";
      }
    }
  }
}

function hideAllInTableList() {
  var divs = document.getElementsByTagName('tr');
  var t, row;
  for(c in divs) {
    if(divs[c].id != undefined) {
      if(divs[c].id.search('Layer') >= 0) {
        divs[c].className = "tableListHidden";
      } else if(divs[c].id.search('Row') >= 0) {
        divs[c].className = "tableListExpanded";
      }
    }
  }
}

function init() {
  startscroll();
  setBrowser();
}

//Skype Scripts

var activex = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));
var CantDetect = ((navigator.userAgent.indexOf('Safari')  != -1) || (navigator.userAgent.indexOf('Opera')  != -1));

function oopsPopup() {
    if((navigator.language && navigator.language.indexOf("ja") != -1) || (navigator.systemLanguage && navigator.systemLanguage.indexOf("ja") != -1) || (navigator.userLanguage && navigator.userLanguage.indexOf("ja") != -1)) {
        var URLtoOpen = "http://download.skype.com/share/skypebuttons/oops/oops_ja.html";
    } else {
        var URLtoOpen = "http://download.skype.com/share/skypebuttons/oops/oops.html";
    }
	var windowName = "oops";
	var popW = 540, popH = 305;
	var scrollB = 'no';
	w = screen.availWidth;
	h = screen.availHeight;
	var leftPos = (w-popW)/2, topPos = (h-popH)/2;
	oopswindow = window.open(URLtoOpen, windowName,'width=' + popW + ',height=' + popH + ',scrollbars=' + scrollB + ',screenx=' +leftPos +',screeny=' +topPos +',top=' +topPos +',left=' +leftPos);
	return false;
}

if(typeof(detected) == "undefined" && activex) {
    document.write(
        ['<script language="VBscript">',
        'Function isSkypeInstalled()',
        'on error resume next',
        'Set oSkype = CreateObject("Skype.Detection")',
        'isSkypeInstalled = IsObject(oSkype)',
        'Set oSkype = nothing',
        'End Function',
        '</script>'].join("\n")
    );
}

function skypeCheck() {
    if(CantDetect) {
        return true;
    } else if(!activex) {
        var skypeMime = navigator.mimeTypes["application/x-skype"];
        detected = true;
        if(typeof(skypeMime) == "object") {
            return true;
        } else {
            return oopsPopup();
        }
    } else {
        if(isSkypeInstalled()) {
            detected = true;
            return true;
        }
    }
    
    detected = true;
    return oopsPopup();
}

function loadDetection() {
    if(document.getElementById && document.getElementsByTagName) {
        if (window.addEventListener) window.addEventListener('load', addDetection, false);
        else if (window.attachEvent) window.attachEvent('onload', addDetection);
    }
}

function addDetection() {
    var pageLinks = document.getElementsByTagName("a");
    for (var i=0; i < pageLinks.length; i++) {
        if(pageLinks[i].childNodes[0] && pageLinks[i].childNodes[0].src) {
            if((pageLinks[i].childNodes[0].src.indexOf('download.skype.com\/share\/skypebuttons') != -1 || pageLinks[i].childNodes[0].src.indexOf('mystatus.skype.com') != -1) && (typeof(pageLinks[i].onclick) == "undefined" || pageLinks[i].onclick == null)) {
                pageLinks[i].onclick = function sChk() { return skypeCheck(); }
            }
        }
    }
}

loadDetection();

   function addzero( value )
   {
      while( value.length<2 ) value = String("0") + value;
      return value;
   }

// booking.com scripts

function checkDateOrder(frm, ci_day, ci_month_year, co_day, co_month_year) {
	if (document.getElementById) {
		var frm = document.getElementById(frm);
		// create date object from checkin values
		// set date to 12:00 to avoid problems with one
		// date being wintertime and the other summertime
		var my = frm[ci_month_year].value.split("-");
	    var ci = new Date (my[0], my[1]-1, frm[ci_day].value, 12, 0, 0, 0);

        // create date object from checkout values
	    my = frm[co_month_year].value.split("-");
	    var co = new Date (my[0], my[1]-1, frm[co_day].value, 12, 0, 0, 0);

		// if checkin date is at or after checkout date,
		// add a day full of milliseconds, and set the
		// selectbox values for checkout date to new value
	    if (ci >= co){
    	    co.setTime(ci.getTime() + 1000 * 60 * 60 * 24);
	        frm[co_day].value =  co.getDate();
    	    var com = co.getMonth()+1;
	        frm[co_month_year].value = co.getFullYear() + "-" + com;
    	}
	}
}

