// JScript source code


var isIE = (document.all) ? true : false;
var isNS6 = (!document.all && document.getElementById) ? true : false;
var isIE4 = isIE && !isNS6;
var isNAV4 = (document.layers) ? true : false;
var isOpera = (navigator.userAgent.toUpperCase().indexOf('OPERA')>-1);
var isAppleWebKit = (navigator.userAgent.toUpperCase().indexOf('APPLEWEBKIT')>-1);
var isWin =	(navigator.userAgent.toUpperCase().indexOf("WIN") > -1) ? true : false; 

var PopUpWin;
var PopUpWin2;

//  Variables for handling layer (FastHelp) state
var VisibleLayerID = '';
var HooverImageClickedID = '';
var StickyLayerID = '';
var DownImageCtrlID='';

//Norton Internet Security workaround - reclaim control over windows.open       
var SymRealWinOpen;
if(SymRealWinOpen) window.open = SymRealWinOpen ;   

/******************************************
 Create and open general pupose popup window
*******************************************/
function PopUpWindow(page, wWidth, wHeight,wScroll){
	if (null != PopUpWin)
	{	
		if (!PopUpWin.closed)
			PopUpWin.close();		
	}

	if (wWidth == null){ wWidth = 350;}
	if (wHeight == null){wHeight = 500;}
	if (wScroll != 'no'){wScroll = 'yes';}
	
	attribs = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars="+wScroll+",resizable=1,height="+wHeight+",width="+wWidth
	
	PopUpWin=open(page,"PopUpWin",attribs);

	if (!PopUpWin.opener)
		PopUpWin.opener = top;
	return false;
}

function PopUpWindow2(url, winName, width, height, wScroll ){

	if (width == null){ width = 780;}
	if (height == null){height = 550;}
	if (wScroll != 'no'){wScroll = 'yes';}

	attribs = "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars="+wScroll+",resizable=yes,height="+height+",width="+width
	
	PopUpWin2 = window.open(url,winName,attribs);

	if ( PopUpWin2 != null) 
		PopUpWin2.focus();
	
}

function PopUpWindow3(page, wWidth, wHeight,wScroll,controlID){
	if (null != PopUpWin)
	{	
		if (!PopUpWin.closed)
			PopUpWin.close();		
	}

	if (wWidth == null){ wWidth = 350;}
	if (wHeight == null){wHeight = 500;}
	if (wScroll != 'no'){wScroll = 'yes';}
	
	var ev;
	var posx;
	var posy;
	posx=0;posy=0;
	
	if(isIE)//IE or compatible
    {
        ev=window.event;
        posx=ev.screenX;posy=ev.screenY
    }
    else if (document.getElementById)
    {
        el = document.getElementById(controlID);
        posx=getAbsLeft(el);
        posy=getAbsTop(el);
        if(window.screenX)
        {
            posx+=190+window.screenX;
            posy+=190+window.screenY;
        }
    }
    else if (document.all)
    {
        el = document.all[controlID];
        posx=getAbsLeft(el);
        posy=getAbsTop(el);
        if(window.screenX)
        {
            posx+=190+window.screenX;
            posy+=190+window.screenY;
        }
    }
    
	attribs = "toolbar=no,location=no,directories=no,status=no,menubar=no,top="+posy+",left="+posx+",scrollbars="+wScroll+",resizable=1,height="+wHeight+",width="+wWidth
	
	PopUpWin=open(page,"PopUpWin",attribs);

	if (!PopUpWin.opener)
		PopUpWin.opener = top;
}

function getAbsLeft(el){
var l=el.offsetLeft;
  while((el=el.parentNode) && el!=document)
    l+=el.offsetLeft;
  return l;
}

function getAbsTop(el){
var l=el.offsetTop;
  while((el=el.parentNode) && el!=document)
    l+=el.offsetTop;
  return l;
}


/******************************************
De-select radio buttons within the same group (.net defect renders unique names)
*******************************************/
function SetUniqueRadioButton(grpName, currentControl)  {
	re = new RegExp(grpName);  
	for(i = 0; i < document.forms[0].elements.length; i++) {
		elm = document.forms[0].elements[i]
		if (elm.type == 'radio') 	{
			if (re.test(elm.name)) 	{
				elm.checked = false;
			}
		}
	}
	currentControl.checked = true;
} 


/******************************************
Show or Hide all Select Tags
*******************************************/
function SetSelectVisibility(visibility){
	var allSelects=document.getElementsByTagName("Select");
	for(var i = 0; i < allSelects.length; i++) {
		allSelects[i].style.visibility=visibility;
	}
}

/******************************************
Show or Hide all Ancor Tags
*******************************************/
function SetAncorVisibility(TagRefToSearch, visibility){
	var allAncors=TagRefToSearch.getElementsByTagName("A");
	for(var i = 0; i < allAncors.length; i++) {
		allAncors[i].style.visibility=visibility;
	}
}


/***************************************************
Preload button images
**************************************************/
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];
		}
	}
}


/*******************************************
Rollover 
*******************************************/
function rolloverButton(elementRef,action,imageName, imageStyle){
	if (elementRef.style.backgroundImage.indexOf("Click")>0){
		return true; // Current image name contains %Click%, do nothing, is should be shown until next postback
		
	}
	
	if (elementRef.style.backgroundImage=="url('" + imageName + "')"){
		return true; // Current image is same as imageName param, do nothing, we're already home
	}

	// Set new image 
	elementRef.style.backgroundImage="url('" + imageName + "')";

	// Clear text value for 'click' action if button style is 'arrow'
	//if (action=='click'&&imageStyle=='arrow'){
	if (action=='click'){
		elementRef.setAttribute('value','');
		displayLoadingImage();
	}
	
	return true;	
}




/***********************************************************
Show candybar while loading and keep layer in position when scrolling
***********************************************************/
function displayLoadingImage(offsettop) {
	if (offsettop==null){
		offsettop=378;
	}
	
	if (isIE) {
		layerCoverApp.style.visibility="visible";
		layerWaitImage.style.visibility="visible";
		//layerWaitImage.style.pixelTop=document.body.scrollTop+offsettop;
		tblFooter.style.visibility="hidden";
	}else if (isNAV4) {
		document.layerCoverApp.visibility="show";
		document.layerWaitImage.visibility="show";
		//eval(document.layerWaitImage.top=eval(window.pageYOffset+offsettop));
	}else {
	
		document.getElementById("layerCoverApp").style.visibility="visible";
		document.getElementById("layerWaitImage").style.visibility="visible";
		//document.getElementById("layerWaitImage").style.top=window.pageYOffset+offsettop;
		document.getElementById("tblFooter").style.visibility="hidden";
		
	}
	//setTimeout("displayLoadingImage()",0);
}

/***********************************************************
Show candybar while loading and keep layer in position when scrolling
***********************************************************/
function displayLoadingImageForDeleteReservation(offsettop) {
	if (offsettop==null){
		offsettop=150;
	}
	
	if (isIE) {
		layerCoverApp.style.visibility="visible";
		layerWaitImage.style.visibility="visible";
		//layerWaitImage.style.pixelTop=document.body.scrollTop+offsettop;
	}else if (isNAV4) {
		document.layerCoverApp.visibility="show";
		document.layerWaitImage.visibility="show";
		//eval(document.layerWaitImage.top=eval(window.pageYOffset+offsettop));
	}else {
		document.getElementById("layerCoverApp").style.visibility="visible";
		document.getElementById("layerWaitImage").style.visibility="visible";
		//document.getElementById("layerWaitImage").style.top=window.pageYOffset+offsettop;
		
	}
	//setTimeout("displayLoadingImage()",0);
	return true;
}
/*********************************************************
Show Please Wait image while loading scandlines
*********************************************************/
function waitForMe(){
document.getElementById("waitLayer").style.visibility="visible";
}

/********************************************************/

function showWaitcursor(inItem,parentItem){
	document.getElementById(parentItem).style.cursor="wait";
	document.getElementById(inItem.id).style.cursor="wait";
	
}

function fnTrapEnterKey(ctrlID){
	if (event.keyCode == 13){
		var ctrl=document.getElementById(ctrlID);
		if (ctrl!=null){
			event.returnValue=false;
			event.cancel = true;
			ctrl.click();
		}
	}
}

function doClick(buttonName,e)
{
    //allow the enter key to point to the correct button to click.
    var key;
    if(window.event) 
        key = window.event.keyCode;     //IE
    else
        key = e.which;     //firefox

    if (key == 13)
    {
        var btn = document.getElementById(buttonName);

        if (btn != null)
        { 
            btn.click();
			event.returnValue=false;
			event.cancel = true;
        }
    }
}

function getFormObject(inObjName){ 
	var retObj = null;
	// Browser check: DOM compliant browser
	if (document.getElementById)
	{
		inObjName = inObjName.replace(new RegExp ('\:', 'gi'), '_');
		retObj = document.getElementById(inObjName);
	}
	// Browser check: IE DHTML compliant browser 
	else if (document.all)
	{
		retObj = document.all.inObjName;
	}
	// Browser check: NS (4.x) DHTML compliant browser 
	else if (document.layers)
	{
		retObj = document.inObjName;
	}
	// Desperate last resort 
	else
	{ 
		var regEx = new RegExp (':', 'gi') ;
		inObjName = inObjName.replace(regEx, '_');
		retObj = document.forms[0].elements[inObjName];
	 }   
	return retObj;
}

function selectItem(inTxt, inVal ) {
	this.txt = inTxt;
	this.val = inVal;
}

function populateSelectObject(inSelectObjectName, inSelectItemArray) {
	var selectObj = getFormObject( inSelectObjectName );
	if (selectObj != null ) {   
		for (var i = 0; i < inSelectItemArray.length; i++) { 
			selectObj.options[ selectObj.options.length ] = new Option( inSelectItemArray[i].txt, inSelectItemArray[i].val);
		}
		if (selectObj.options.length >= 1) {
			selectObj.options[0].selected = true;
		}
	}
}

function clearSelectObject(inSelectObjectName, inSelectOption) {
	var selectObj = getFormObject( inSelectObjectName );
	if (selectObj != null ) {   
		while (selectObj.options.length >= 1 ) {
			selectObj.options[ selectObj.options.length -1 ] = null;
		}
		if (inSelectOption) {
			selectObj.options[0] = inSelectOption;
			selectObj.options[0].selected = true;
		}
	}
}

function setInnerTextOnLabel(clientId, clientIdDdl) {

    var lbl = getFormObject(clientId);
    var ddl = getFormObject(clientIdDdl);
    if (ddl != null) {
        var index = ddl.selectedIndex;

        var text = ddl.options[index].text;

        if (lbl != null) {
            lbl.innerText = text.substring(text.indexOf("|") + 1);
            lbl.innerHTML = text.substring(text.indexOf("|") + 1);
        }
    }
}



function setTextOnObjValue( inObjClientIDOut,inObjClientIDHome, newValue) {

    var txtObjOut = getFormObject(inObjClientIDOut);  
	if (txtObjOut != null)
		txtObjOut.value = newValue;
	var txtObjHome = getFormObject(inObjClientIDHome);
	if (txtObjHome != null)
		txtObjHome.value = newValue; 	
}

function SetElementDisplayMode(elmtID, vis) {
    var visibility = 'hidden';
    var el = document.getElementById(elmtID); 
    if (vis == 1) 
        visibility = 'visible';
    if (el) {
        el.style.visibility = visibility;
    }
    return void(0);
}

function SetElementDisplayModeBlock(elmtID, vis) {
    var d = 'none';
    if (vis != undefined) { 
        if (vis == 1)
            d = 'block';
    }
    else {
        if (document.getElementById(elmtID).style.display == 'none')
            d = 'block';
    }
    document.getElementById(elmtID).style.display = d;
        
    return void(0);
}
          
    
    /**********************************************************
New loader, will replace candybar in EFP, Cruise and Daytrip

************************************************************/      
function ajaxLoader(id) { 

    var el = document.getElementById(id); 
    if (isNS6){
        el.style.display='block'; 
        document.getElementById('imgFFImgLoader').style.display='block';
    }
    else {

        var COMMENT = '<!--imgIsLoaded-->';
        var imgTag = '<img src="Img/ajax-loader.gif" style="padding:20px; vertical-align: center" alt=" "/><br/><br/>'
        if (el.style.display!='block'){ 
            if (el.innerHTML.indexOf(COMMENT) == -1) {
                el.innerHTML += imgTag + COMMENT;
            }
            el.style.display='block';                              
        }
    }
} 

function StopAjaxLoader() {
    var el = document.getElementById('divLoader'); 
    if (el)
        el.style.display='none';
    el = document.getElementById('imgFFImgLoader'); 
    if (el)
        el.style.display='none';
       
}
function StartAjaxLoader() {
    ajaxLoader('divLoader');
}

var _pageViewName; 
function TrackPageView(pageName) {
    try {
        _pageViewName = pageName;
        setTimeout(TrackPageViewAsync, 50); 
    }
    catch (e) {
    }
}
function TrackPageViewAsync() {
    try {
        TrackGAPageView(_pageViewName); // Assume available from cms script block linked in.
    }
    catch (e) {    }
}

/**********************************************************
Refresh parent window from popup
************************************************************/ 
function refreshParent() {
    window.opener.location.href = window.opener.location.href;

    if (window.opener.progressWindow) {
        window.opener.progressWindow.close()
    }
    window.close();
}

/**********************************************************
Display LightBox
************************************************************/      
    function ShowLightBox() {                 
         var _closeText = "Close";                                               
         
         $.ajax({
         type: "POST",
         url: urlStr,
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         async:   false,           
         data: "{}",
         success: function(msg) {
                    
            $("a[rel^='popupLayer']").prettyPhoto({
                animationSpeed: 'normal',
                padding: 40,
                opacity: 0.6,
                showTitle: false,
                allowresize: true,
                CloseText: _closeText,
                theme: 'light_square'
            });
            $('#lnkModalPopup').trigger("click");  
            }
        });

    }


