/*
 * Standard Functions for ParkVIS application
 * Contact Alex Fahey 0419 47 9898
 */
function popup(mylink, windowname)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=470,height=640');
return false;
}

function popUpPage(URL)
{
    newWindow = window.open(URL, "PopPage","toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=500");
    newWindow.focus();
}

function popUpImage(imagename, alttext)
{
    newWindow = window.open ("popup.aspx?image=" + imagename + "&alt=" + alttext, "mywindow","status=0,toolbar=0","PopUpImagePage");
    newWindow.focus();
}

function showElement(id)
{
    if(!document.getElementById) return; // Not Supported
    if(document.getElementById)
    {
        if(document.getElementById(id) == null )
        {
            //ID not found so do nothing
        } else {
            //Show the hidden div
            document.getElementById(id).className = "shownData";
        }
    }
}

function hideElement(id)
{
    if(!document.getElementById) return; // Not Supported
    if(document.getElementById)
    {
        if(document.getElementById(id) == null )
        {
            //ID not found so do nothing
        } else {
            //Show the hidden div
            document.getElementById(id).className = "hiddenData";
        }
    }
}

function showMap(id) {
            if (id == 'deccAppUcUc1_MapDefault') {
            document.getElementById('deccAppUcUc1_MapDefault').className = "shownData";
            document.getElementById('deccAppUcUc1_MapLocal').className = "hiddenData";
            document.getElementById('deccAppUcUc1_MapNational').className = "hiddenData";
            document.getElementById('deccAppUcUc1_MapState').className = "hiddenData";
            }
            if (id == 'deccAppUcUc1_MapLocal') {
            document.getElementById('deccAppUcUc1_MapLocal').className = "shownData";
            document.getElementById('deccAppUcUc1_MapNational').className = "hiddenData";
            document.getElementById('deccAppUcUc1_MapState').className = "hiddenData";
            document.getElementById('deccAppUcUc1_MapDefault').className = "hiddenData";
        
            }
            if (id == 'deccAppUcUc1_MapNational') {
            document.getElementById('deccAppUcUc1_MapDefault').className = "hiddenData";
            document.getElementById('deccAppUcUc1_MapNational').className = "shownData";
            document.getElementById('deccAppUcUc1_MapState').className = "hiddenData";
            document.getElementById('deccAppUcUc1_MapLocal').className = "hiddenData";
            }
            if (id == 'deccAppUcUc1_MapState') {
            document.getElementById('deccAppUcUc1_MapDefault').className = "hiddenData";
            document.getElementById('deccAppUcUc1_MapState').className = "shownData";
            document.getElementById('deccAppUcUc1_MapNational').className = "hiddenData";
            document.getElementById('deccAppUcUc1_MapLocal').className = "hiddenData";
            }
        
}

function switchImage(id, imagePath)
{
    if(!document.getElementById) return; // Not Supported
    if(document.getElementById)
    {
        if(document.getElementById(id) == null )
        {
            //ID not found so do nothing
        } else {
            //Show the hidden div
            document.getElementById(id).src = imagePath;
        }
    }
}

function nswMapRollover()
{

}

function mouseOver2(strImageID)
{
    if(!(typeof(strImageID) == "string")) // guard
    { 
        // The strImageID must be a string value of the id attribute of the menu group UL tag
        return; 
    }
    var imgCurrent = document.getElementById(strImageID)

    switch(strImageID)
    {
    case "ss1":
      imgCurrent.src = "/images/parks/nsw01_green.gif";
      document.getElementById('ssl').style.textDecoration='none';
      document.getElementById('ssl').style.backgroundColor='#CCEEFF';
      break;
    case "hn1":
      imgCurrent.src = "/images/parks/nsw02_green.gif";
      document.getElementById('hnl').style.textDecoration='none';
      document.getElementById('hnl').style.backgroundColor='#CCEEFF';
      break;
    case "nr1":
      imgCurrent.src = "/images/parks/nsw03_green.gif";
      document.getElementById('nrl').style.textDecoration='none';
      document.getElementById('nrl').style.backgroundColor='#CCEEFF';
      break;
    case "ne1":
      imgCurrent.src = "/images/parks/nsw04_green.gif";
      document.getElementById('nel').style.textDecoration='none';
      document.getElementById('nel').style.backgroundColor='#CCEEFF';
      break;
    case "sc1":
      imgCurrent.src = "/images/parks/nsw05_green.gif";
      document.getElementById('scl').style.textDecoration='none';
      document.getElementById('scl').style.backgroundColor='#CCEEFF';
      break;
    case "cw1":
      imgCurrent.src = "/images/parks/nsw06_green.gif";
      document.getElementById('cwl').style.textDecoration='none';
      document.getElementById('cwl').style.backgroundColor='#CCEEFF';
      break;
    case "ob1":
      imgCurrent.src = "/images/parks/nsw07_green.gif";
      document.getElementById('obl').style.textDecoration='none';
      document.getElementById('obl').style.backgroundColor='#CCEEFF';
      break;
    }
}

function mouseOut2(strImageID)
{
    if(!(typeof(strImageID) == "string")) // guard
    { 
        // The strImageID must be a string value of the id attribute of the menu group UL tag
        return; 
    }
    var imgCurrent = document.getElementById(strImageID)

    switch(strImageID)
    {
    case "ss1":
      imgCurrent.src = "/images/parks/nsw01_blue.gif";
      document.getElementById('ssl').style.textDecoration='underline';
      document.getElementById('ssl').style.backgroundColor='#FFFFFF';
      break;
    case "hn1":
      imgCurrent.src = "/images/parks/nsw02_blue.gif";
      document.getElementById('hnl').style.textDecoration='underline';
      document.getElementById('hnl').style.backgroundColor='#FFFFFF';
      break;
    case "nr1":
      imgCurrent.src = "/images/parks/nsw03_blue.gif";
      document.getElementById('nrl').style.textDecoration='underline';
      document.getElementById('nrl').style.backgroundColor='#FFFFFF';
      break;
    case "ne1":
      imgCurrent.src = "/images/parks/nsw04_blue.gif";
      document.getElementById('nel').style.textDecoration='underline';
      document.getElementById('nel').style.backgroundColor='#FFFFFF';
      break;
    case "sc1":
      imgCurrent.src = "/images/parks/nsw05_blue.gif";
      document.getElementById('scl').style.textDecoration='underline';
      document.getElementById('scl').style.backgroundColor='#FFFFFF';
      break;
    case "cw1":
      imgCurrent.src = "/images/parks/nsw06_blue.gif";
      document.getElementById('cwl').style.textDecoration='underline';
      document.getElementById('cwl').style.backgroundColor='#FFFFFF';
      break;
    case "ob1":
      imgCurrent.src = "/images/parks/nsw07_blue.gif";
      document.getElementById('obl').style.textDecoration='underline';
      document.getElementById('obl').style.backgroundColor='#FFFFFF';
      break;
    }
}

function showRow(id)
{
    if(!document.getElementById) return; // Not Supported
    if(document.getElementById)
    {
        if(document.getElementById(id) == null )
        {
            //ID not found so do nothing
        } else {
            //If the current row is an alt row then we need to add this to the class
            if(document.getElementById(id).className.indexOf("alt") != -1 )
            {
                document.getElementById(id).className = "alt shownData";
            } else {
                document.getElementById(id).className = "shownData";
            }
        }
    }
}

function hideRow(id)
{
    if(!document.getElementById) return; // Not Supported
    if(document.getElementById)
    {
        if(document.getElementById(id) == null )
        {
            //ID not found so do nothing
        } else {
            //If the current row is an alt row then we need to add this to the class
            if(document.getElementById(id).className.indexOf("alt") != -1 )
            {
                document.getElementById(id).className = "alt hiddenData";
            } else {
                document.getElementById(id).className = "hiddenData";
            }
        }
    }
}

function loadGuidedTour(strTextID)
{
    if (strTextID != '')
    {
        var divHolder = document.getElementById("tourContent")
        var divText = document.getElementById(strTextID)
        divHolder.innerHTML = divText.innerHTML
    }
}

//Show hide Fire Descriptions functions
var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name)
{
  if (document.getElementById)
  {
    this.obj = document.getElementById(name);
    this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
    this.obj = document.all[name];
    this.style = document.all[name].style;
  }
  else if (document.layers)
  {
    this.obj = document.layers[name];
    this.style = document.layers[name];
  }
}

function showSingleDescription(div_id) 
{
//Update the visibility
if (!DHTML) return;
var x = new getObj(div_id);
var y = new getObj('link'+div_id);
x.style.display = 'block';
y.style.display = 'none';
}

function showAllDescription() 
{
//Update the visibility for all div tags
if (!DHTML) return;
var div_id = 0;
var a =  new getObj('showAll');
var b =  new getObj('hideAll');
a.style.display = 'none';
b.style.display = 'block';
var x = new getObj('t' + div_id);
var y = new getObj('linkt'+div_id);
    do
    {
        x.style.display = 'block';
        y.style.display = 'none';
        div_id ++;
        x = new getObj('t' + div_id);
        y = new getObj('linkt'+div_id);
    }
    while (x && typeof x == 'object')
}

function showAllDescription100() 
{
//Update the visibility for all div tags
if (!DHTML) return;
var div_id = 101;
var a =  new getObj('showAllThreat');
var b =  new getObj('hideAllThreat');
a.style.display = 'none';
b.style.display = 'block';
var x = new getObj('t' + div_id);
var y = new getObj('linkt'+div_id);
    do
    {
        x.style.display = 'block';
        y.style.display = 'none';
        div_id ++;
        x = new getObj('t' + div_id);
        y = new getObj('linkt'+div_id);
    }
    while (x && typeof x == 'object')
}

function hideSingleDescription(div_id) 
{
//Update the visibility
if (!DHTML) return;
var x = new getObj(div_id);
var y = new getObj('link'+div_id);
x.style.display = 'none';
y.style.display = 'block';
}

function hideAllDescription() 
{
//Update the visibility for all div tags
if (!DHTML) return;
var div_id = 0;
var a =  new getObj('showAll');
var b =  new getObj('hideAll');
a.style.display = 'block';
b.style.display = 'none';
var x = new getObj('t' + div_id);
var y = new getObj('linkt'+div_id);
    do
    {
        x.style.display = 'none';
        y.style.display = 'block';
        div_id ++;
        x = new getObj('t' + div_id);
        y = new getObj('linkt'+div_id);
    }
    while (x && typeof x == 'object')
}

function hideAllDescription100() 
{
//Update the visibility for all div tags
if (!DHTML) return;
var div_id = 101;
var a =  new getObj('showAllThreat');
var b =  new getObj('hideAllThreat');
a.style.display = 'block';
b.style.display = 'none';
var x = new getObj('t' + div_id);
var y = new getObj('linkt'+div_id);
    do
    {
        x.style.display = 'none';
        y.style.display = 'block';
        div_id ++;
        x = new getObj('t' + div_id);
        y = new getObj('linkt'+div_id);
    }
    while (x && typeof x == 'object')
}

// Javascript to implement map window functionality using grey box - start
var tHgt = 680;
tHgt = 650;
if (screen.availHeight < 700) {
    tHgt        = 580;
}

function GB_show(url) {
    jQuery("lblHeader").addClass("hiddenData");
    jQuery("#GB_caption").hide();
    
    jQuery("#GB_frame").hide();

    jQuery("#GB_overlay").css({ height: jQuery(document.page).height() + "px" });
    jQuery("#GB_overlay").show();

    var iFrame = document.getElementById("GB_frame");
    //jQuery("#GB_window").append("<iframe frameborder='0' id='GB_frame' src='" + url + "'></iframe>");
    if (iFrame == undefined) {
        jQuery("#GB_window").append("<iframe frameborder='0' id='GB_frame' src=''></iframe>");
        iFrame = document.getElementById("GB_frame");
    } else {
        jQuery("#GB_frame").hide();
    }
    jQuery("#GB_window").css({ left: (jQuery(window).scrollLeft() + (jQuery(document.page).width() / 2) - 337) + "px", top: jQuery(window).scrollTop() + "px" });
    jQuery("#GB_window").css({ height: tHgt + "px" });
    
   
    if (iFrame != undefined) {
        iFrame.src = url;
    }
    jQuery("#GB_window").show();
    jQuery("#GB_frame").css({ height: (tHgt - 32) + "px" });
    jQuery("#GB_frame").show();
}

function GB_hide() {
    jQuery("#GB_frame").hide();
    jQuery("#GB_window, #GB_overlay").hide();
    jQuery("#GB_frame").attr("src", '');
}

jQuery(document).ready(function() {

try {
        var re = new RegExp("\\/mapwindow\\.aspx","gi");
  
    if (!window.location.href.match(re)) {
        //
        // Not map window
        //
            jQuery(document.body).append("<div id='GB_overlay' style='display:none;'></div><div id='GB_window'><div id='GB_caption'></div><img src='/images/parkvis/admin/close.gif' alt='Close window'/></div>");
            jQuery("#GB_window img").click(GB_hide);
            jQuery("#GB_overlay").click(GB_hide);
            GB_hide();
        }

        //
        // Set the onclick event to handle the href popup
        //
        jQuery.each(jQuery('a.location'), function() {
            var url;
            url = "'" + jQuery(this).attr("href") + "'";
            jQuery(this).click(function(e) {
                e.preventDefault();
                GB_show(eval(url));
                return false;
            });
        });

        //
        // Clear the href setting
        //
        jQuery.each(jQuery('a.location'), function() {
            jQuery(this).attr("href", 'javascript:void(null);');
        });

    }
    catch (err) {
        alert("js ready1" + err.description);
    }
});


function RebindMapLinks() {
    //
    // Rebing the map links
    //
    //
    // Set the onclick event to handle the href popup
    //
    jQuery.each(jQuery('a.location'), function() {
        var url;
        url = "'" + jQuery(this).attr("href") + "'";
        jQuery(this).click(function(e) {
            e.preventDefault();
            GB_show(eval(url));
            return false;
        });
    });

    //
    // Clear the href setting
    //
    jQuery.each(jQuery('a.location'), function() {
        jQuery(this).attr("href", 'javascript:void(null);');
    });
}

function setCaption(caption) {
    jQuery("#GB_caption").html(caption);
    jQuery("#GB_caption").show();
}

function changeLocation(url) {
    try {
        window.location = url;
    } catch (err) {
    alert("changeLocation:" + err.description);
    }
}
// Javascript to implement map window functionality using grey box - end

// Javascript to implement map selected sector redirection on home page - start
jQuery(document).ready(function() {
    try {
        jQuery.each(jQuery('#map .rectangular a.selected'), function(i) {
           jQuery(this).click(function(e) {
                e.preventDefault()

                var tabs = $$('.tab');
                if (tabs[0]) {
                    tabs[0].fireEvent('click');
                }
            });

        });

    } catch (err) {
        alert("js ready2" + err.description);
    }

});
// Javascript to implement map selected sector redirection on home page - end

// Javascript to open seat advisor window - start
function popUpSeatAdvisor(URL) {
    newWindow = window.open(URL, "SeatAdvisor","toolbar=yes,location=yes,scrollbars=yes,resizable=yes,copyhistory=no,width=850,height=600");
    newWindow.focus();
}

jQuery(document).ready(function() {
    try {
        jQuery.each(jQuery('a.seatadvisor'), function() {
        jQuery(this).click(function(e) {
                e.preventDefault();
                popUpSeatAdvisor(jQuery(this).attr("href"));
            });
        });
    } catch (err) {
    alert("js ready3" + err.description);
    }
});
// Javascript to open seat advisor window - end

// Javascript to retrieve URL parameters - start

// Function to get variables passed through URL
function getURLparameter(variable) {
    if (window.location) {
        variable = variable.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + variable + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(window.location.href);
        if (results == null)
            return "";
        else
            return results[1];
    } else {
        return "";
    }
}
// Javascript to retrieve URL parameters - end

function ShowAccomodationRegionItems() {
    var regionList = document.getElementById("region");

    var region = regionList.value;
    if (region.substring(0, 7) == "region-") {
        region = region.substring(7);
    }
    if (region == '') {
        alert("You must select a region from the drop down list.");
    } else {
        window.location = 'SearchAccommodation.aspx?region=' + region + "#accommodation";
    }
}

