﻿// JScript File
function ChangeVisible(obj)
{   
    if(obj=="ShowHotel")
    {
        document.getElementById("ShowHotel").checked="checked";
        document.getElementById("SearchAirHotel").style.display="none";
        //document.getElementById("SearchHotel").style.display="block"; 
    } 
    else
    {
        document.getElementById("ShowAirHotel").checked="checked";
        //document.getElementById("SearchHotel").style.display="none";
        document.getElementById("SearchAirHotel").style.display="block"; 
    }
}
function ClearText(obj)
{
    document.getElementById(obj).value="";
}

function SubmitPop(url)
 {
 //alert("test");
  NewWindow(url,'DestinationDetails','550','400','yes');
 }
 
 var win = null;
function NewWindow(url,myname,w,h,scroll)
{
settings ='height='+h+',width='+w+',scrollbars=' + scroll;
win = window.open(url,myname,settings)
if(win.window.focus){win.window.focus();}
}

function showPanofull(mapid)
{
var win = window.open('http://display.maxvr.com/mapviewer/fullpopup.asp?ident=248-' + mapid +'&nc=1','vrxviewer','height=470,width=796,menubar=no,top=5,scrollbars=no,resizable=no,left=0');
win.focus();
}

function SubmitPage(url)
 {
 window.location=url;
 //added new code
 /*
  document.frmdestination.target="";
  document.frmdestination.action=url;
  document.frmdestination.submit();
  */
 }
var  SearchWidgetShowHide_inObject,SearchWidgetShowHide_inTempObject;
function SearchWidgetShowHide(inObject,inTempObject)
{
    if(typeof(inObject.id)=='undefined')return;
    
    if(inObject)
    {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(SearchWidgetShowHide);
        inObject.style.display='none';
        SearchWidgetShowHide_inObject=inObject;
        if(inTempObject)
        {
            SearchWidgetShowHide_inTempObject=inTempObject;
            SearchWidgetShowHide_inTempObject.style.display='block';
        }
    }
    else
    {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(SearchWidgetShowHide);
        SearchWidgetShowHide_inObject.style.display='block';
        if(SearchWidgetShowHide_inTempObject)
            SearchWidgetShowHide_inTempObject.style.display='none';
    }
}
function registerEventOnUpdated(inVal)
{
    if(inVal==true)
    {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(registerEventOnUpdated);
    }
    else
    {
        Sys.WebForms.PageRequestManager.getInstance().remove_endRequest(registerEventOnUpdated);
        alert(document.getElementById('ctl00_RightContent_ucPreferredClubSignin1_lblerrmessage').innerHTML);
    }
}
function DisplayObjectReplace(inObject,inTempObject)
{
    if(inObject && inTempObject)
    {
        inObject.style.display='none';
        inTempObject.style.display='block';
    }
}
function ShowHideDepart(inSearchTypeID,inLabelDepartID,inDepartByAirHotelID, inDepartureTime, inReturnTime, inDepartureLabel, inReturnLable, lblDepartTime, lblReturnTime, inDummyButton)
{
    var value = "none";
    if(document.getElementById(inSearchTypeID) && document.getElementById(inSearchTypeID).checked)
        value="inline";
    
    document.getElementById(inLabelDepartID).style.display=value;
    document.getElementById(inDepartByAirHotelID).style.display=value;
    document.getElementById(inDepartureTime).style.display=value;
    document.getElementById(inReturnTime).style.display=value;
 
    if(value=="none")
    {
        document.getElementById(inDepartByAirHotelID).value="";
        document.getElementById(inDepartureTime).selectedIndex=0;
        document.getElementById(inReturnTime).selectedIndex=0;
        document.getElementById(inDepartureLabel).innerHTML="Check-In";
        document.getElementById(inReturnLable).innerHTML="Check-Out";
        if(inDummyButton!=null && document.getElementById(inDummyButton))
        {
            document.getElementById(inDummyButton).value ='Search for Hotel';
            document.getElementById(inDummyButton).style.width='120px';
        }
    }
    else
    {
        document.getElementById(inDepartureLabel).innerHTML="Departing";
        document.getElementById(inReturnLable).innerHTML="Returning";
        if(inDummyButton!=null && document.getElementById(inDummyButton))
        {
            document.getElementById(inDummyButton).value='Search for Hotel + Flight';
            document.getElementById(inDummyButton).style.width='173px';
        }
    }
    
    if(lblDepartTime)
        document.getElementById(lblDepartTime).style.display=value;
    if(lblReturnTime)
        document.getElementById(lblReturnTime).style.display=value;
}

function date_Chceck(inObject)
{
    var validformat=/^\d{1,2}\/\d{1,2}\/\d{4}$/
    if (!validformat.test(inObject.value))
        return false;
    else
    {
        //Detailed check for valid date ranges
        var monthfield=inObject.value.split("/")[0]
        var dayfield=inObject.value.split("/")[1]
        var yearfield=inObject.value.split("/")[2]
        var dayobj = new Date(yearfield, monthfield-1, dayfield)
        if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
            return false;
        else
            return true;
    }
}

function LibGoDates_addDaysToDate(myDate,days)
{
    return new Date(myDate.getTime() + days*24*60*60*1000);
}

function setDeptAndRetrunDates(inDeptObject, inReturnObject, inNoOfDays)
{
    if(!inDeptObject)return false;
    if (!date_Chceck(inDeptObject))
    {
        return false;
    }
    if(inReturnObject)
    {
        var tmpDate = LibGoDates_addDaysToDate(LibGoDates_getDateObject(inDeptObject.value),inNoOfDays);
        inReturnObject.value = LibGoDates_getDateValue(tmpDate);
    }
}
function LibGoDates_getDateObject(inValue)
{
    var date_array = inValue.split('/');
    var month = date_array[0];
    var day = date_array[1];
    var year = date_array[2];
    return new Date(year,month-1,day);
}
function LibGoDates_getDateValue(inDateObject)
{
    return inDateObject.getMonth()+1 + "/" + inDateObject.getDate() + "/" + inDateObject.getFullYear();
}
function LibGoDates_getDateDiffDays(d1, d2)
{
	return Math.ceil((d2.getTime() - d1.getTime())/(1000*60*60*24));
}
String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};

/***
This function is for basic validations
***/
function LibGoSearchValidate(inDeptCity, inRtnCity, inDeptDate, inRtnDate, inMinDays)
{
    var deptCityObject = document.getElementById(inDeptCity);
    var rtnCityObject = document.getElementById(inRtnCity);
    var deptDateObject = document.getElementById(inDeptDate);
    var rtnDateObject = document.getElementById(inRtnDate);
    
    if (deptCityObject && rtnCityObject && deptDateObject && rtnDateObject)
    {
        if(deptCityObject.style.display!='none' && deptCityObject.value.trim().length<3)
        {
            if(rtnCityObject.value.trim().length<3)
                alert('Please enter the correct values for: \nCity you are leaving from\nCity you are going to');
            else
                alert('Please enter the correct value for: \nCity you are leaving from');
            return false;
        }
        if(rtnCityObject.value.trim().length<3)
        {
            alert('Please enter the correct value for : \nCity you are going to');
            return false;
        }
        if(!date_Chceck(deptDateObject) || !date_Chceck(rtnDateObject))
        {
            alert('Please check the date formats!');
            return false;
        }
        if(!(LibGoDates_addDaysToDate(new Date(),8)<LibGoDates_getDateObject(deptDateObject.value)))
        {
            alert('Booking this package requires a travel date after ' + LibGoDates_getDateValue(LibGoDates_addDaysToDate(new Date(),8)) + '\nPlease check your travel dates to continue.');
            return false;
        }
        if(LibGoDates_getDateDiffDays(LibGoDates_getDateObject(deptDateObject.value),LibGoDates_getDateObject(rtnDateObject.value))<(inMinDays-1))
        {
            alert('Booking this package requires a minimum stay of ' + (inMinDays-1) + ' nights.\nPlease check your travel dates and length of stay to continue.');
            return false;
        }
    }
    else
    {
        alert('This is unfortunate, please report it to web master!');
        return false;
    }
    return true;
}

/***
This function is for advanced validations like for special packages dates,min days etc ., 
***/
function LibGoSearchValidate_OverLoad(inDeptCity, inRtnCity, inDeptDate, inRtnDate, inMinDays, inPckgSDate, inPckgEDate)
{
    if(!LibGoSearchValidate(inDeptCity, inRtnCity, inDeptDate, inRtnDate, inMinDays))return false;
    
    var deptDateObject = document.getElementById(inDeptDate);
    var rtnDateObject = document.getElementById(inRtnDate);
    if(LibGoDates_getDateObject(deptDateObject.value)<LibGoDates_getDateObject(inPckgSDate) || LibGoDates_getDateObject(rtnDateObject.value)>LibGoDates_getDateObject(inPckgEDate))
    {
        if(!confirm('Your travel dates do not fall within the valid travel dates of this special offer. Prices may differ. Do you wish to continue anyway?'))
            return false;
    }
    return true;
}

/***
Cursor change functions
***/
function hourGlassCursor()
{
    //alert(inObj.checked)
    //Sys.WebForms.PageRequestManager.getInstance().add_endRequest(normalCursor);
    document.body.style.cursor = 'wait';
}
function normalCursor()
{
    document.body.style.cursor = 'auto';
}
/***
End : Cursor change functions
***/

/* Begin UpdatePanelAnimationExtender functions */
function onUpdating(){
    hourGlassCursor();
    // get the update progress div
    var panelPopup = $get('ctl00_panelPopup'); 

    //  get the gridview element        
   // var gridView = $get('<%= this.FlightHotelGrd.ClientID %>');
    
    // make it visible
    panelPopup.style.display = '';	    
    
    // get the bounds of both the gridview and the progress div
    //var gridViewBounds = Sys.UI.DomElement.getBounds(gridView);
    var panelPopupBounds = Sys.UI.DomElement.getBounds(panelPopup);
    
    var x = Math.round(documentWidth()/2) - Math.round(panelPopupBounds.width/2)
    var y = currentY() + Math.round(documentHeight()/2) - Math.round(panelPopupBounds.height/2);
    //	set the progress element to this position
    Sys.UI.DomElement.setLocation(panelPopup, x, y);           
}

function onUpdated() {

    normalCursor();
    // get the update progress div
    var panelPopup = $get('ctl00_panelPopup'); 
    // make it invisible
    panelPopup.style.display = 'none';
}
/* End UpdatePanelAnimationExtender functions */            

function currentX()
{
    if (self.pageYOffset)
    {
        return self.pageXOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    {
        return document.documentElement.scrollLeft;
    }
    else if (document.body)
    {
        return document.body.scrollLeft;
    }
}
function currentY()
{
    if (self.pageYOffset)
    {
        return self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop)
    {
        return document.documentElement.scrollTop;
    }
    else if (document.body)
    {
        return document.body.scrollTop;
    }
}
function documentHeight()
{
    if (self.innerHeight)
    {
        return self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
        return document.documentElement.clientHeight;
    }
    else if (document.body)
    {
        return document.body.clientHeight;
    }
}
function documentWidth()
{
    if (self.innerHeight)
    {
        return self.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
        return document.documentElement.clientWidth;
    }
    else if (document.body)
    {
        return document.body.clientWidth;
    } 
}

/**************Code block below is from _PrintPage.js*************/
function PrintPage()
{
    window.print()
}
/***********************End of _PrintPage.js**********************/
/**************Code block below is from popup_window.js*************/
var winpop1 = null;

function FBPopWindow(mypage,myname,w,h,scroll)
{
winposition=',left=5,top=0'
settings ='height='+h+',width='+w+',scrollbars='+scroll+',resizable' + winposition
winpop1 = window.open(mypage,myname,settings)
}

function PopWindow(mypage,myname,w,h,scroll)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	// Commented by Pramod to make it identical to ASP version
    //settings ='height='+h+',width='+w+',scrollbars='+scroll+',resizable'
	settings = 'height='+ h +',width='+ w +',top='+ TopPosition + ',left=' + LeftPosition + ',scrollbars='+ scroll + ',resizable'
    winpop1 = window.open(mypage,myname,settings)
}

function MyAccount(mypage,myname,w,h,scroll)
{
settings ='height='+h+',width='+w+',scrollbars='+scroll+',resizable'
winpop1 = window.open(mypage,myname,settings)
window.navigate("MyAccount.html")
}
/***********************End of popup_window.js**********************/
/********Code block below is from ClientKeypressFunctions.js********/
function allowNoKey(e)
{
 // IE
 if (window.event)
  {  
    var key = window.event.keyCode;
    if (key != 9)
    {window.event.returnValue = false;}
  }
 else
 {
  var key = e.which
  if (key != 0)
  {e.preventDefault();}
  
 }
}
/*****************End of ClientKeypressFunctions.js*****************/
/*****************Code block below is from iframe.js****************/
/***********************************************
* IFrame SSI script II- © Dynamic Drive DHTML code library (http://www.dynamicdrive.com)
* Visit DynamicDrive.com for hundreds of original DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Input the IDs of the IFRAMES you wish to dynamically resize to match its content height:
//Separate each ID with a comma. Examples: ["myframe1", "myframe2"] or ["myframe"] or [] for none:
var iframeids=["myframe", "ctl00_MainContent_myframe"]

//Should script hide iframe from browsers that don't support this script (non IE5+/NS6+ browsers. Recommended):
var iframehide="yes"

var getFFVersion=navigator.userAgent.substring(navigator.userAgent.indexOf("Firefox")).split("/")[1]
var FFextraHeight=parseFloat(getFFVersion)>=0.1? 16 : 0 //extra height in px to add to iframe in FireFox 1.0+ browsers

function resizeCaller() {
var dyniframe=new Array()
for (i=0; i<iframeids.length; i++){
if (document.getElementById)
resizeIframe(iframeids[i])
//reveal iframe for lower end browsers? (see var above):
if ((document.all || document.getElementById) && iframehide=="no"){
var tempobj=document.all? document.all[iframeids[i]] : document.getElementById(iframeids[i])
tempobj.style.display="block"
}
}
}

function resizeIframe(frameid){
var currentfr=document.getElementById(frameid)
if (currentfr && !window.opera){
currentfr.style.display="block"
if (currentfr.contentDocument && currentfr.contentDocument.body.offsetHeight) //ns6 syntax
currentfr.height = currentfr.contentDocument.body.offsetHeight+FFextraHeight;
else if (currentfr.Document && currentfr.Document.body.scrollHeight) //ie5+ syntax
currentfr.height = currentfr.Document.body.scrollHeight;
if (currentfr.addEventListener)
currentfr.addEventListener("load", readjustIframe, false)
else if (currentfr.attachEvent){
currentfr.detachEvent("onload", readjustIframe) // Bug fix line
currentfr.attachEvent("onload", readjustIframe)
}
}
}

function readjustIframe(loadevt) {
var crossevt=(window.event)? event : loadevt
var iframeroot=(crossevt.currentTarget)? crossevt.currentTarget : crossevt.srcElement
if (iframeroot)
resizeIframe(iframeroot.id);
}

function loadintoIframe(iframeid, url){
if (document.getElementById)
document.getElementById(iframeid).src=url
}

if (window.addEventListener)
window.addEventListener("load", resizeCaller, false)
else if (window.attachEvent)
window.attachEvent("onload", resizeCaller)
else
window.onload=resizeCaller

/***********************End of iframe.js**********************/

/*****************Following are for modelpopup****************/
function showModalPopupViaClient()
{
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.show();
}

function hideModalPopupViaClient()
{
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.hide();
}
/**********************End for modelpopup*********************/

function desableReturnKey(e)
{
    if(e.which != null) 
	{
	    if(e.which == 13)
	    {
	        return false;
        }
	}
	else
	{
	    if(e.keyCode == 13)
	    {
	        e.keyCode=null;
	        return false;
	    }
	}
}
function CloseCal()
{
    if(document.getElementById('CalFrame'))
            parent.frames['CalFrame'].CloseCal();
}

function attachEvents(inObject)
{
    if(inObject)
    {
        var newDate = LibGoDates_addDaysToDate(new Date(),6);
        inObject.onfocus=function ()
        {
            ShowCalendar(inObject,inObject,inObject,newDate);
            if(inObject.value=='mm/dd/yyyy')this.value='';
        }
        inObject.onkeydown=function ()
        {
            if ((event.keyCode||event.which) == 9){CloseCal();}
        }
        //inObject.onblur=CloseCal;
        inObject.onclick=function ()
        {
            ShowCalendar(inObject,inObject,inObject,newDate);
            if(inObject.value=='mm/dd/yyyy')this.value='';
        }
    }
}
function launchViewer(url, mapId)
{
    var w = screen.width;
    var winwidth;
    var winurl;
    
    if (w >= 1000)
    {
        winwidth=890;
        if(url)
            winurl=url;
        else
            winurl = 'http://delivery.vrxstudios.com/destinations/vrxfullviewer.asp?ident=AA3322-' + mapId;
    }
    else
    {
        winwidth=546;
        if(url)
            winurl=url;
        else
            winurl = 'http://delivery.vrxstudios.com/destinations/vrxmap.asp?ident=AA3322-' + mapId;
    }
    var win = window.open(winurl,'vrxmap','width=' + winwidth + ',height=520,top=5,left=5,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
    win.focus();
}
function ModelPopUp(title, URL, Width, Height)
{
    var dom = $get("ctl00_programmaticPopup");
    dom.style.width = Width + 'px';
    dom.style.height = Height + 'px';
    $get("ctl00_genericIFrameTitle").innerHTML=title;
    
    $get("ctl00_genericIFrameClose1").style.display="none";
    $get("ctl00_genericIFrameClose2").style.display="none";
    
    dom = $get("ctl00_genericIFrameUpdateProgress");
    dom.style.height = (Height-78) + 'px';
    dom.style.display="block";
    
    dom = $get("ctl00_genericIFrameUpdateProgressPadding");
    dom.style.height = (Height-90)/2 + 'px';
    dom.style.display="block";
    
    dom = $get("ctl00_genericIFrame");
    dom.style.display="none";
    dom.style.height = (Height-78) + 'px';
    $get("ctl00_genericIFrame").src=URL;
    
    showModalPopupViaClient();
    return false;
}
function ModelPopUpLoaded()
{
    $get("ctl00_genericIFrame").style.display="block";
    $get("ctl00_genericIFrameClose1").style.display="block";
    $get("ctl00_genericIFrameClose2").style.display="block";
    $get("ctl00_genericIFrameUpdateProgress").style.display="none";
    $get("ctl00_genericIFrameUpdateProgressPadding").style.display="none";
    return false;
}

function MakeClearText(field, val)
{
    if (field.value == val )
    {
        field.value='';
    }
}
function isBlankText(field,defaultvalue)
{
    with (field)
    {
	    if (field.value==null||field.value.trim()=="")
	    {
		    field.value = defaultvalue;
	    }
    }
}

function attachZipCodeEvents(inObject,inDefaultText)
{
    if(inObject)
    {
        inObject.onfocus=function ()
        {
            MakeClearText(inObject, inDefaultText);
        }
        inObject.onblur=function ()
        {
            isBlankText(this, inDefaultText);
        }
        inObject.onkeyup=function ()
        {
            if (inObject.value.length>5)
            {
                inObject.value = inObject.value.substring(0,5);
                return false;
            }
            if (!/^\d*$/.test(inObject.value))
            {
                inObject.value = inObject.value.replace(/[^\d]/g,"");
            }
        }
    }
}
function validateZip(inObj,inDefaultValue,inErrorMsg)
{
    if(inObj)
    {
        if(inObj.value.trim()==inDefaultValue ||  inObj.value.trim()=='')
        {
            alert(inErrorMsg);
            return false;
        }
        if(inObj.value.trim().length<5)
        {
            inValidZipCode();
            return false;
        }
        return true;
    }
    return false;
}
function inValidZipCode()
{
    alert('Invalid zip code.');
}
