// Villa Rochelle Script File - Created by KevBod@kevbod.com
// These scripts all recognise the W3c DOM

// ********************************
// *** Navigation between pages ***
// ********************************
function nav(theURL)
{
document.location.href = theURL;
}


// **********************************************
// *** Home Page Slideshow Script Starts Here ***
// **********************************************

// =================================
// set the following variables
// =================================
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 3000

// Duration of crossfade (seconds)
var crossFadeDuration = 2

// Specify the image files
var Pic = new Array() // don't touch this.

// to add more images, just continue
// the pattern, adding to the array below
Pic[0] = 'images/VilaRoch_99.jpg'
Pic[1] = 'images/VilaRoch_01.jpg'
Pic[2] = 'images/VilaRoch_02.jpg'
Pic[3] = 'images/VilaRoch_03.jpg'
Pic[4] = 'images/VilaRoch_04.jpg'
Pic[5] = 'images/VilaRoch_05.jpg'
Pic[6] = 'images/VilaRoch_06.jpg'
Pic[7] = 'images/VilaRoch_07.jpg'
Pic[8] = 'images/VilaRoch_08.jpg'
Pic[9] = 'images/VilaRoch_09.jpg'
Pic[10] = 'images/VilaRoch_10.jpg'
Pic[11] = 'images/VilaRoch_11.jpg'
Pic[12] = 'images/VilaRoch_12.jpg'
Pic[13] = 'images/VilaRoch_13.jpg'
Pic[14] = 'images/VilaRoch_14.jpg'
Pic[15] = 'images/VilaRoch_15.jpg'
Pic[16] = 'images/VilaRoch_16.jpg'
Pic[17] = 'images/VilaRoch_17.jpg'
Pic[18] = 'images/VilaRoch_18.jpg'
Pic[19] = 'images/VilaRoch_19.jpg'
Pic[20] = 'images/VilaRoch_20.jpg'
Pic[21] = 'images/VilaRoch_21.jpg'
Pic[22] = 'images/VilaRoch_22.jpg'
// =======================================
// do not edit anything below this line
// =======================================

var t;
var thisPic = 0;
var p = Pic.length;
var preLoad = new Array();
for (i = 0; i < p; i++){
   preLoad[i] = new Image();
   preLoad[i].src = Pic[i];
}

function runSlideShow(){
   if (document.images){
      thisPic++;
      if (thisPic == p){
        thisPic = 0;
      }
    if (document.all){
      document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
      document.images.SlideShow.filters.blendTrans.Apply() ;
    }   
   }
   document.images.SlideShow.src = preLoad[thisPic].src
   if (document.all){
      document.images.SlideShow.filters.blendTrans.Play()
   }
   t = setTimeout('runSlideShow()', slideShowSpeed)
}
// ********************************************
// *** Home Page Slideshow Script Ends Here ***
// ********************************************


// ***************************************
// *** Booking Form Scripts Start Here ***
// ***************************************
function isNum(passedVal) {
 if (passedVal == "") {
  return false;
 }
 for (i=0; i<passedVal.length; i++) {
  if (passedVal.charAt(i) < "0") {
   return false;
  }
  if (passedVal.charAt(i) > "9") {
   return false;
  }
 }
 return true;
}

// *************************************************************
// *** THIS SCRIPT VALIDATES & FORWARDS THE RESERVATION FORM ***
// *************************************************************
function submitIt() {
   var msg = 'You must give us the following information ....\n';
   var retn = "";
   var flag = 0;
   if (document.getElementById("orgname").value == "") {
      msg=msg+"\n - Please enter your name";
      flag = 1;
   }
   if (document.getElementById("email").value == "") {
      msg=msg+"\n - We really need your email address to respond to you.";
      if (flag == 0) {
       flag = 2;
      }
   }
   if (document.getElementById("telno").value == "" && document.getElementById("mobno").value == "")
   {
      msg=msg+" \n - Please give us at least one telephone number";
      if (flag == 0) {
        flag = 3;
      }
   }
   if (document.getElementById("date1").value == "")
   {
      msg=msg+" \n - You must tell us your proposed holiday start date";
      if (flag == 0) { 
        flag = 4;
      }
   }
   if (flag !== 0) {
      alert(msg);
      if (flag == 1) {
        retn=document.getElementById("orgname");
      }
      else if (flag == 2) {
        retn=document.getElementById("email");
      }
      else if (flag == 3) {
        retn=document.getElementById("telno");
      }
      else if (flag == 4) {
        retn=document.getElementById("date1");
      }
      retn.focus();
    return false;
   }
  var setRes=new Date();
  var setRes=Math.ceil(setRes.getTime()/60000);
  document.getElementById("theKey").value=Math.ceil(setRes/(60*24));
  document.getElementById("resNo2").value=setRes;
  setCookie();
}

// *********************************************************************************
// *** THIS SCRIPT CHECKS THE CONFIRMATION NUMBER MATCHES THE RESERVATION NUMBER ***
// *** IF TRUE THE BOOKING FORM IS LOADED.
// *********************************************************************************
function confFrm() {
 var conf2=document.getElementById("conf").value;
  if (isNum(conf2)) {
     var key=document.getElementById("resNo").value;
     var key=Math.ceil(key/(60*24));
     if (key == conf2) {
      setCookie();
      nav("zzz_bookit.htm");
      return false;
     } else {
      alert('Your Confirmation Number does not match your Reservation Number.\nPlease check your numbers and try again.\n\nRing us if you continue to have a problem.');
      document.getElementById("conf").focus();
      document.getElementById("conf").select();
      return false;
     }
  } else {
      alert('Invalid Confirmation Number .... Try Again');
      document.getElementById("conf").focus();
      document.getElementById("conf").select(); 
      return false;
  }
}

// ****************************************************
// *** THIS SCRIPT MANAGES THE INITIAL BOOKING PAGE ***
// ****************************************************
function frmchoose() {
 var check = document.getElementById("resNo").value;
  if (isNum(check)) {
     var backstop=new Date(2004,0,1);
     var backstop=Math.ceil(backstop.getTime()/60000);
     var today=new Date();
     var todaycount=Math.ceil(today.getTime()/60000);

     if (check<backstop||check>todaycount) {
      alert('Invalid Reservation Number .... Try Again');
      document.getElementById("resNo").focus();
      document.getElementById("resNo").select(); 
      return false;
     }
     if (todaycount-check<10080) {
        document.getElementById("expired").style.display = "none";
        document.getElementById("resform").style.display = "none";
        document.getElementById("bookOK").style.display = "block";
     } else {
        document.getElementById("expired").style.display = "block";
        document.getElementById("resform").style.display = "block";
        document.getElementById("bookOK").style.display = "none";
     }
   } else {
      if (check == ""){
        document.getElementById("haveRes").style.display = "none";
        document.getElementById("resform").style.display = "block";
        document.getElementById("bookOK").style.display = "none";
      } else {
        alert('Invalid - Must be a number .... Try Again');
        document.getElementById("resNo").focus();
        document.getElementById("resNo").select(); 
        return false;
      }
   }
}

// ****************************************************************************
// *** CALCULATES THE DEPOSIT REQUIRED IF NIGHTS ARE CHANGED ON BOOKING FORM ***
// ****************************************************************************
function deposit() {
 var pay=document.getElementById("nights").value;
 if (pay>0 && pay<8){
     pay=100;
 } else if (pay>7 && pay<15){
     pay=200;
 } else if (pay>14){
     pay=300;
 }
 return pay;
}
function payit() {
 var pay=deposit();
 if(pay>0){
   document.getElementById("deposit").value = pay;
   } else {
   document.getElementById("deposit").value = "";
   }
}

function cookieVal(cookieName) {
 var thisCookie = document.cookie.split("; ");
 for (i=0; i<thisCookie.length; i++) {
   if (cookieName == thisCookie[i].split("=")[0]) {
     return thisCookie[i].split("=")[1];
   }
 }
 return "";
}

function getCookie() {
 if(document.cookie !="") {
   var passedNo=cookieVal("passedNo");
   document.getElementById("resNo").value=passedNo;
   var passedDate=cookieVal("passedDate");
   document.getElementById("date1").value=passedDate;
   var passedNight=cookieVal("passedNight");
   document.getElementById("nights").value=passedNight;
   var passedLeader=cookieVal("passedLeader");
   document.getElementById("orgname").value=passedLeader;
   if(document.getElementById("book")) {
     var passedDeposit=cookieVal("passedDeposit");
     document.getElementById("deposit").value=passedDeposit;
   }
 } else {
  if(document.getElementById("book")) {
   alert('Sorry, your browser settings will not let us pass the Reservation Number\nto our booking form. You will have to input it again.');
  }
 }
}

function setCookie() {
 var expireDate=new Date();
 expireDate.setHours(expireDate.getHours()+(17*24));
 var passedNo=document.getElementById("resNo2").value;
 var passedDate=document.getElementById("date1").value;
 var passedNight=document.getElementById("nights").value;
 var passedDeposit=deposit();
 document.cookie="passedDate="+passedDate+";expires="+expireDate.toGMTString();
 document.cookie="passedNight="+passedNight+";expires="+expireDate.toGMTString();
 document.cookie="passedDeposit="+passedDeposit+";expires="+expireDate.toGMTString();
 if(document.getElementById("orgname")) {
   var passedLeader=document.getElementById("orgname").value;
   document.cookie="passedLeader="+passedLeader+";expires="+expireDate.toGMTString();
 }
 if(isNum(passedNo)) {
  document.cookie="passedNo="+passedNo+";expires="+expireDate.toGMTString();
 }
}

// *************************************
// *** Booking Form Scripts End Here ***
// *************************************



// ****************************************************
// ***  MENU BAR - Show & hide Booking Info Submenu ***
// ****************************************************
function showHide(obj, visibility) {
  thisMenu = document.getElementById(obj).style
  thisMenu.visibility = visibility;
}



// ****************************************************
// ***  Virtual Tour - Scripts to control panoramas ***
// ****************************************************
function NewPano(i) {
  document.ptviewer.newPanoFromList(i);
}

function DoAutoRotLeftStart() {
  document.ptviewer.startAutoPan( -0.2, 0.0, 1.0 );
}
function DoAutoRotRightStart() {
  document.ptviewer.startAutoPan( 0.2, 0.0, 1.0 );
}
function DoAutorotationStop() {
  document.ptviewer.stopAutoPan();
}
function DoZoomIn() {
  document.ptviewer.startAutoPan( -0.2, 0.0, 1.0/1.03 );
}
function DoZoomOut() {
  document.ptviewer.startAutoPan( -0.2, 0.0, 1.03 );
}

function mousehs(n) {
  if( n== -1 )
     document.cn.hsnum.value = "---" ;
  else
     document.cn.hsnum.value = n ;
}
function getview(p,t,f) {
   document.cn.pan.value = p ;
   document.cn.tilt.value = t ;
   document.cn.fov.value = f ;
}

// **** Villa Rochelle scripts end here ****

