// basic back 1 history step function
function goBack() {
    window.history.back(1);
}

// basic back 2 history step function
function goBackTwo() {
    window.history.go(-2);
}

// basic show and hide functions

function hide(x){
    if (x != null) {
        var element = document.getElementById(x);
        if (element != null) {
            element.style.display='none';
        }
    }
}
function show(x){
    if (x != null) {
        var element = document.getElementById(x);
        if (element != null) {
            element.style.display='block';
        }
    }
}

/* Function to hide form elements that show through
   the search form when it is visible */
function toggleForm(frmObj, iState) // 1 visible, 0 hidden
{
	for(var i = 0; i < frmObj.length; i++) {
		if (frmObj.elements[i].type.indexOf("select") == 0) {
            frmObj.elements[i].style.visibility = iState ? "visible" : "hidden";
		}
	}
}

/* Function to hide all forms elements that show through
   the search form when it is visible */
function toggleForms(iState) // 1 visible, 0 hidden
{
	for(var i = 0; i < document.forms.length; i++) {
		toggleForm(document.forms[i], iState);
	}
}

// =========================================================================
//                          Popup Window functions
// =========================================================================

function openWin(url,winTitle,w,h) {
    var screenWidth = parseInt(screen.availWidth);
    var screenHeight = parseInt(screen.availHeight);
    var left = (screenWidth-w)/2;
    var top = (screenHeight-h)/2;
    var winParams = "width=" + w + ",height=" + h;
        winParams += ",left="+left+",top="+top+",toolbar,scrollbars,resizable,status=yes";

	  winName = window.open(url, winTitle, winParams);
    winName.focus();
}

function showproperty(property) {
   var path = '/vrtours/vrtours.php?picdir=' + property;
   window.open(path, 'gallery', 'width=400,height=580,toolbar=no,menubar=no,location=no,resizable=yes');
}

// =========================================================================
//                          Cookie functions
// =========================================================================
/* This function is used to set cookies */
function setCookie(name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

/* This function is used to get cookies */
function getCookie(name) {
	var prefix = name + "="
	var start = document.cookie.indexOf(prefix)

	if (start==-1) {
		return null;
	}

	var end = document.cookie.indexOf(";", start+prefix.length)
	if (end==-1) {
		end=document.cookie.length;
	}

	var value=document.cookie.substring(start+prefix.length, end)
    //windows.status='cookie: '+value;
	return unescape(value);
}

/* This function is used to delete cookies */
function deleteCookie(name,path,domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// =========================================================================
//                mouseOver Image swaps and preLoad script
// =========================================================================


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.01
  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 && d.getElementById) x=d.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];}
}

// =========================================================================
//                This is the greying out of the search by date fields
//                on the   A D V A N C E D    S E A R C H   form
// =========================================================================

function searchByDate() {
    disable();
    //this is to verify that the correct radio button is selected in all states
    if(document.forms[0].flexible[0] != null){
        if(document.forms[0].flexible[0].checked == false){
            document.forms[0].flexible[0].checked=true;
        }
    }
}
function disable(){
    hide('checkInDate');
    hide('checkOutDate');
    // the next two lines sets the values of the arrival date and departure date to blank so that
    // when the two files are shown again, they will be blank.
    if (document.forms[0].arrivalDate != null) {
        document.forms[0].arrivalDate.value="";
    }
    if (document.forms[0].departureDate != null) {
        document.forms[0].departureDate.value="";
    }
    hide('arrivalDate');
    hide('departureDate');
    hide('arrivalDateAnchor');
    hide('departureDateAnchor');
    show('checkInDateGreyedOut');
    show('checkOutDateGreyedOut');
    show('arrivalDateGreyedOut1');
    show('departureDateGreyedOut1');
    show('calendarInIconGreyedOut');
    show('calendarOutIconGreyedOut');
}
function enable(){
    //this is to verify that the correct radio button is selected in all states
    if(document.forms[0].flexible[0].checked == true){
        document.forms[0].flexible[0].checked=false;
    }
    hide('checkInDateGreyedOut');
    hide('checkOutDateGreyedOut');
    hide('arrivalDateGreyedOut1');
    hide('departureDateGreyedOut1');
    hide('calendarInIconGreyedOut');
    hide('calendarOutIconGreyedOut');
    show('checkInDate');
    show('checkOutDate');
    show('arrivalDate');
    show('departureDate');
    show('arrivalDateAnchor');
    show('departureDateAnchor');
}

function iDontNeed() {
    document.forms[0].flexible[0].checked=true;
    disable();
}

function iNeed() {
    document.forms[0].flexible[1].checked=true;
    enable();
}

// =========================================================================
//                This is the greying out of the search by date fields
//                on the    S I M P L E    S E A R C H    form
// =========================================================================

function simpleSearchByDate() {
    simpleSearchDisable();
    //this is to verify that the correct radio button is selected when the page loads
    if(document.forms[0].flexible[0] != null){
        if(document.forms[0].flexible[0].checked == false){
            document.forms[0].flexible[0].checked=true;
        }
    }
}
function simpleSearchDisable(){
    hide('checkInDateIndex');
    hide('checkOutDateIndex');
    // the next two lines sets the values of the arrival date and departure date to blank so that
    // when the two files are shown again, they will be blank.
    if (document.forms[0].arrivalDate != null) {
        document.forms[0].arrivalDate.value="";
    }
    if (document.forms[0].departureDate != null) {
        document.forms[0].departureDate.value="";
    }
    hide('arrivalDate');
    hide('departureDate');
    hide('arrivalDateAnchor');
    hide('departureDateAnchor');
    show('checkInDateIndexGreyedOut');
    show('checkOutDateIndexGreyedOut');
    show('arrivalDateGreyedOut1');
    show('departureDateGreyedOut1');
    show('calendarInIconGreyedOut');
    show('calendarOutIconGreyedOut');
}
function simpleSearchEnable(){
    //this is to verify that the correct radio button is selected in all states
    if(document.forms[0].flexible[0].checked == true){
        document.forms[0].flexible[0].checked=false;
    }
    hide('checkInDateIndexGreyedOut');
    hide('checkOutDateIndexGreyedOut');
    hide('arrivalDateGreyedOut1');
    hide('departureDateGreyedOut1');
    hide('calendarInIconGreyedOut');
    hide('calendarOutIconGreyedOut');
    show('checkInDateIndex');
    show('checkOutDateIndex');
    show('arrivalDate');
    show('departureDate');
    show('arrivalDateAnchor');
    show('departureDateAnchor');
}
function simpleSearchIDontNeed() {
    document.forms[0].flexible[0].checked=true;
    simpleSearchDisable();
}
function simpleSearchINeed() {
    document.forms[0].flexible[1].checked=true;
    simpleSearchEnable();
}

// =========================================================================
//                This is the greying out of the search by date fields
//                on the    S I M P L E    S E A R C H    form When there is more than 1 form on the page
// =========================================================================


function simpleSearchByDateWhenSecondFormOnPage() {
    simpleSearchDisableMultiple();
    //this is to verify that the correct radio button is selected when the page loads
    if(document.forms[1].flexible[0] != null){
        if(document.forms[1].flexible[0].checked == false){
            document.forms[1].flexible[0].checked=true;
        }
    }
}
function simpleSearchDisableMultiple(){
    hide('checkInDateIndex');
    hide('checkOutDateIndex');
    // the next two lines sets the values of the arrival date and departure date to blank so that
    // when the two files are shown again, they will be blank.
    if (document.forms[1].arrivalDate != null) {
        document.forms[1].arrivalDate.value="";
    }
    if (document.forms[1].departureDate != null) {
        document.forms[1].departureDate.value="";
    }
    hide('arrivalDate');
    hide('departureDate');
    hide('arrivalDateAnchor');
    hide('departureDateAnchor');
    show('checkInDateIndexGreyedOut');
    show('checkOutDateIndexGreyedOut');
    show('arrivalDateGreyedOut1');
    show('departureDateGreyedOut1');
    show('calendarInIconGreyedOut');
    show('calendarOutIconGreyedOut');
}
function simpleSearchEnableMultiple(){
    //this is to verify that the correct radio button is selected in all states
    if(document.forms[1].flexible[0].checked == true){
        document.forms[1].flexible[0].checked=false;
    }
    hide('checkInDateIndexGreyedOut');
    hide('checkOutDateIndexGreyedOut');
    hide('arrivalDateGreyedOut1');
    hide('departureDateGreyedOut1');
    hide('calendarInIconGreyedOut');
    hide('calendarOutIconGreyedOut');
    show('checkInDateIndex');
    show('checkOutDateIndex');
    show('arrivalDate');
    show('departureDate');
    show('arrivalDateAnchor');
    show('departureDateAnchor');
}
function simpleSearchIDontNeedMultiple() {
    document.forms[1].flexible[0].checked=true;
    simpleSearchDisableMultiple();
}
function simpleSearchINeedMultiple() {
    document.forms[1].flexible[1].checked=true;
    simpleSearchEnableMultiple();
}

//****************************************************************************************************************
//****************************************************************************************************************
//****************************************************************************************************************
//****************************************************************************************************************
//****************************************************************************************************************
//****************************************************************************************************************
//this is for the flexible form on the Email A Reservation Request for in the Property Details section of each site

function emailResDisable(){
    hide('checkInDate');
    hide('checkOutDate');
    // the next two lines sets the values of the arrival date and departure date to blank so that
    // when the two files are shown again, they will be blank.
    if (document.emailResReqActionForm.arrivalDate != null) {
        document.emailResReqActionForm.arrivalDate.value="";
    }
    if (document.emailResReqActionForm.departureDate != null) {
        document.emailResReqActionForm.departureDate.value="";
    }
    hide('arrivalDate1');
    hide('departureDate1');
    hide('arrivalDateAnchor');
    hide('departureDateAnchor');
    show('checkInDateGreyedOut');
    show('checkOutDateGreyedOut');
    show('arrivalDateGreyedOut1');
    show('departureDateGreyedOut1');
    show('calendarInIconGreyedOut');
    show('calendarOutIconGreyedOut');
}
function emailResEnable(){
    hide('checkInDateGreyedOut');
    hide('checkOutDateGreyedOut');
    hide('arrivalDateGreyedOut1');
    hide('departureDateGreyedOut1');
    hide('calendarInIconGreyedOut');
    hide('calendarOutIconGreyedOut');
    show('checkInDate');
    show('checkOutDate');
    show('arrivalDate1');
    show('departureDate1');
    show('arrivalDateAnchor');
    show('departureDateAnchor');
}

function emailResIDontNeed() {
    if (document.emailResReqActionForm.emailResFormFlexible[0] !=null){
        if (document.emailResReqActionForm.emailResFormFlexible[1].checked == true){
            document.emailResReqActionForm.emailResFormFlexible[0].checked=true;
        }
    }
    emailResDisable();
}

function emailResINeed() {
    if (document.emailResReqActionForm.emailResFormFlexible[1] !=null){
        if (document.emailResReqActionForm.emailResFormFlexible[0].checked == true){
            document.emailResReqActionForm.emailResFormFlexible[1].checked=true;
        }
    }
    emailResEnable();
}

//****************************************************************************************************************
//******************************************** END ***************************************************************
//****************************************************************************************************************
//****************************************************************************************************************
//****************************************************************************************************************
//****************************************************************************************************************

function hideSelects(){
    hide('emailResSelects1');
    hide('emailResSelects2');
}

function showSelects(){
    show('emailResSelects1');
    show('emailResSelects2');
}

function isUndefined(v) {
	return typeof v === "undefined";
}
