
stuHover = function() {
    var cssRule;
    var newSelector;
    //    for (var i = 0; i < document.styleSheets.length; i++)
    //        for (var x = 0; x < document.styleSheets[i].rules.length; x++) {
    //            cssRule = document.styleSheets[i].rules[x];
    //            if (cssRule.selectorText.indexOf("LI:hover") >= 0) {
    //                newSelector = cssRule.selectorText.replace(/LI:hover/gi, "LI.iehover");
    //                document.styleSheets[i].addRule(newSelector, cssRule.style.cssText);
    //            }
    //        }
    if (document.getElementById("nav")) {
        var getElm = document.getElementById("nav").getElementsByTagName("LI");
        for (var i = 0; i < getElm.length; i++) {
            getElm[i].onmouseover = function() {
                this.className += " iehover";
            };
            getElm[i].onmouseout = function() {
                this.className = this.className.replace(new RegExp(" iehover\\b"), "");
            };
        }
    }

};

$('document').ready(function () {
    stuHover();
    checkHistory();

    //$("ul.subnav").parent().append("&lt;span&gt;&lt;/span&gt;"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

    /**
    $("ul.topnav a").hover(function () {
    $("#main-nav li a.main-link").removeClass("subhover");
    $(this).addClass("subhover");

    $("ul.subnav").hide();
    $(this).parent().find("ul.subnav").slideDown('slow');

    });
    **/


    //    $("ul.topnav a").hover(function () { //When trigger is clicked...
    //        //Following events are applied to the subnav itself (moving subnav up and down)
    //        //$(this).parent().find(".nav_arrowdown").slideDown('fast').show(); //Drop down the subnav on click
    //        $(this).parent().find("ul.subnav").stop().slideDown('slow'); //Drop down the subnav on click


    //        //        $(this).parent().hover(function () {
    //        //        }, function () {
    //        //            $(this).parent().find("ul.subnav").stop().slideUp('fast', function () {
    //        //            }); 
    //        //            $(this).parent().find(".nav_arrowdown").stop().slideUp('fast');
    //        //        });

    //        //        //Following events are applied to the trigger (Hover events for the trigger)
    //        //    }).hover(function () {
    //        //        $(this).addClass("subhover"); //On hover over, add class "subhover"
    //        //    }, function () {	//On Hover Out
    //        //        $(this).removeClass("subhover"); //On hover out, remove class "subhover"    
    //    }, function () {	//On Hover Out
    //        //$(this).removeClass("subhover"); //On hover out, remove class "subhover"  
    //        $(this).parent().find("ul.subnav").slideUp('fast');
    //    });

});

//$(document).ready(function () {
//    $("#main-nav li a.main-link").hover(function () {
//        $("#main-nav li a.close").fadeIn();
//        $("#main-nav li a.main-link").removeClass("active");
//        $(this).addClass("active");
//        $("#sub-link-bar").animate({
//            height: "40px"
//        });
//        $(".sub-links").hide();
//        $(this).siblings(".sub-links").fadeIn();
//    });   

//});



//this is so we can track which one is selected now to close it 
var selectedReferenceId = 1; 


//open the new selection, make it's arrow point down
//close the previous selection, make its arrow point right
function toggleQuickGuideLayer( referenceId ){

 //show current selection
 toggleLayer('para' + referenceId);
 toggleQuickGuideArrow(referenceId);

 //hide previous selection
 toggleLayer('para' + selectedReferenceId);
 toggleQuickGuideArrow(selectedReferenceId);
 
 //the new selected reference
 selectedReferenceId = referenceId;
}


//change icon to point down or right
function toggleQuickGuideArrow( referenceId ){

  var element = document.getElementById('heading' + referenceId);
  if ( element ){
      element.className = (element.className == 'ItemSelected') ? 'Item' : 'ItemSelected';
      if (element.parentNode.className == "Alt" || element.parentNode.className == "") {
          element.parentNode.className = element.parentNode.className + ' ItemSelected';
      }
      else {
        if(element.parentNode.className.indexOf("Alt") != -1) {
            element.parentNode.className = 'Alt';
        }
        else {
            element.parentNode.className = '';
        }
      }
  }

}


//show/hide the search result layer and change the text on the link
function toggleSearchLayer( divId, hrefId ){

 var layerIsVisible = toggleLayer(divId);

 if ( document.getElementById(hrefId)){
    document.getElementById(hrefId).innerHTML = (layerIsVisible)?'Hide All':'Show All';
  }
}


//will show or hide a div
function toggleLayer( divId ){

    var elem, vis;
    elem = document.getElementById(divId);

    elem.className = (elem.className == 'hidden') ? 'shown' : 'hidden';

//  if( document.getElementById ) // this is the way the standards work    
//    elem = document.getElementById( divId );  
//  else if( document.all ) // this is the way old msie versions work      
//    elem = document.all[divId];  
//  else if( document.layers ) // this is the way nn4 works    
//    elem = document.layers[divId];  vis = elem.style;  // if the style.display value is blank we try to figure it out here


//  if (vis.className == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined)    
//    vis.className = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'shown':'hidden';
//  vis.className = (vis.className == 'hidden' || vis.className == 'shown') ? 'hidden' : 'shown';

//  alert(vis.className);
  //return (vis.className == 'shown') ? true : false;
 
}  
  
  
  
//because the document links are generated with the cms we provide this method
//the master page call this for all the site markers that download 
//this 
function makeLinkTargetBlank( url ){
    var links = document.getElementsByTagName("a");
    for( var i=0; i < links.length; i++ ){
        if ( url == links[i] )
            links[i].target = "_blank";
    }

}  

function endsWith(testString, endingString){
    if(endingString.length > testString.length)return false;
    return testString.lastIndexOf(endingString)==(testString.length-endingString.length);
}
  
  
//Used by NavControls.ascx
function SearchOnBlur( inputBox ){
  inputBox.value = inputBox.value || inputBox.defaultValue; 
  if ( inputBox.value == inputBox.defaultValue ){
    
  }
  else{
  }
  
}

//Used by NavControls.ascx
//Clear the text if it's the default value so they can write something
function SearchOnFocus( inputBox ){
  if ( inputBox.value == inputBox.defaultValue ){
    //they're writing something
     inputBox.value=''; 
  }
}
  

//Used by NavControls.ascx
//submit the form if you click on the > arrow
function SearchClick( formID ){
    alert(formID + ' = ctl00_ctrlSearchSmall_HeaderSearch')
    var searchForm = document.getElementById(formID); 
    alert(searchForm);
    searchForm.submit();
}  

function SearchClickIe6( formID ){
     var searchText = document.getElementById('adxSearchText');  
     if ( searchText )
         window.location.href = searchUrl + "?adxSearchText=" + encodeURIComponent(searchText.value);
     return false;    
}  

function HideFlash()
{
    swfobject.removeSWF("flashContent");
//    var flashContent = document.getElementById('flashContent');  
//    flashAdSoundOff();
//    if ( flashContent )
//    {
//        flashContent.style.width = "0"; //display = 'none';
//        flashContent.style.height = "0"; //visibility = 'hidden';
//    }   
}

function ShowFlash()
{
    var flashContent = document.getElementById('flashContent');  
    if ( flashContent )
    {
        //if(flashContent.style.display == 'none')
        //{
            //flashContent.style.display = 'block';
            //flashContent.style.visibility = 'visible';
            flashContent.style.width = "980px";
            flashContent.style.height = "550px";
        //}
    }
}

function flashAdSoundOff()
{
    try
    {
        var flashContent = document.getElementById("flashContent");
        if ( flashContent )
        {
            flashContent.flashAdSoundOff();
        }
    }
    catch(err)
    {
    //Handle errors here
    }
}

function flashAdSoundOn()
{
    try
    {
        var flashContent = document.getElementById("flashContent");
        if ( flashContent )
        {
            flashContent.flashAdSoundOn();
        }
    }
    catch(err)
    {
    //Handle errors here
    }
    
}

function pageLoad(sender, args) 
{
    LogRoundtripTime();   
    $addHandler(document, "keydown", OnKeyPress);
}

function LogRoundtripTime() {
  var img = new Image();
  img.id = "imgRTT";
  var start = (new Date()).getTime();
  img.src = ONE_PX;
  img.onload = GetRoundtripTimeFunction(start);
}

var userSpeed = 0;

function GetRoundtripTimeFunction(start) {
    return function () {
        var end = (new Date()).getTime();
        //alert(strURL + "Pages/Image.aspx?t=" + ((end - start) / 1000));
        var urlToLoad = strURL + "Pages/Image.aspx?t=" + ((end - start) / 1000) + '&addToWebInteractionAudit=false';
        document.getElementById("tmpImagePlacement").src = urlToLoad;
        userSpeed = ((10000 / ((end - start) / 1000)) / 1000) * 8;
    } 
}


function OnKeyPress(args)
{
    if(args.keyCode == Sys.UI.Key.esc)
    {
         CarInsuranceModalClose();
         HomeContentsInsuranceModalClose();
         OutOfHoursModalClose();
    }
}


function CarInsuranceModalOpen()
{
    $('#divCarInsuranceModal').reveal({
        animation: 'fade', //fade, fadeAndPop, none
        animationspeed: 300, //how fast animtions are
        closeonbackgroundclick: false, //if you click background will modal close?
        dismissmodalclass: 'close-reveal-modalNone' //the class of a button or element that will close an open modal
    });
}

function CarInsuranceModalClose()
{
    $('#divCarInsuranceModal').trigger('reveal:close');
}

function HomeContentsInsuranceModalOpen()
{
    //flashAdSoundOff();
    //HideFlash();
    //$find('behHomeContentsInsuranceModal').show();

    if ($('#divHomeContents').hasClass('CarInsuranceModal')) {
        $('#divHomeContents').reveal({
            animation: 'fade', //fade, fadeAndPop, none
            animationspeed: 300, //how fast animtions are
            closeonbackgroundclick: true, //if you click background will modal close?
            dismissmodalclass: 'close-reveal-modalNone' //the class of a button or element that will close an open modal
        });
    }
    else {
        $('#divHomeContents').reveal({
            animation: 'fade', //fade, fadeAndPop, none
            animationspeed: 300, //how fast animtions are
            closeonbackgroundclick: false, //if you click background will modal close?
            dismissmodalclass: 'close-reveal-modalNone' //the class of a button or element that will close an open modal
        });
    }
    
  
}

function HomeContentsInsuranceModalClose()
{
    $('#divHomeContents').trigger('reveal:close');
    HomeContentsInsuranceModalStep(1);
}

function OutOfHoursModalOpen() {
    $('#divOutOfHoursModal').reveal({
        animation: 'fade', //fade, fadeAndPop, none
        animationspeed: 300, //how fast animtions are
        closeonbackgroundclick: true, //if you click background will modal close?
        dismissmodalclass: 'close-reveal-modalNone' //the class of a button or element that will close an open modal
    });
}

function OutOfHoursModalClose() {
    $('#divOutOfHoursModal').trigger('reveal:close');
}

function QuoteOnlineModalOpen() {
    $find('behQuoteOnlineModal').show();
}

function QuoteOnlineModalClose() {
    $find('behQuoteOnlineModal').hide();
}


function PromotionModalClose()
{
    $find('behPromotionModal').hide();     
}

function CommentsModalOpen()
{
    document.getElementById("divAddComment").style.display = "block";
}

function CommentsModalClose()
{
    document.getElementById("divAddComment").style.display = "none";
}


    function ShowHideComments(divID)
    {
        if(document.getElementById('divComments_' + divID).style.display == "none")
        {
            document.getElementById('divComments_' + divID).style.display = "block"
            document.getElementById('divCommentsShowText_' + divID).style.display = "none";
            document.getElementById('divCommentsHideText_' + divID).style.display = "block";
        }
        else
        {
            document.getElementById('divComments_' + divID).style.display = "none"
            document.getElementById('divCommentsShowText_' + divID).style.display = "block";
            document.getElementById('divCommentsHideText_' + divID).style.display = "none";
        }
    }


    function scrollWin(divID) {        
        var offset = $(divID).offset();        
        $('html, body').animate({
            scrollTop: $(divID).offset().top - 120
        }, 2000);
    }

    function scrollToTop() {
        $('html, body').animate({
            scrollTop: 0
        }, 1000);
    }


    function UpdateCommentCount(divID, intCount) {
        document.getElementById(divID).innerHTML = "(" + intCount + ") Comments";        
    }


    function checkHistory() {

        try {
            var websites = [
        "http://www.aami.com.au/",
        "http://www.aami.com.au/insurance-quotes/insurance-quote.aspx",
        "http://www.aami.com.au/insurance-quotes/insurance-quote-terms.aspx?type=Car",
        "https://nb.aami.com.au/nb/cs?entry=motornew&cn=1",
        "http://www.budgetdirect.com.au/",
        "https://ecommerce.disconline.com.au/pc/apply?hPID=PCRQIC&hSty=BUDD&pref=G&",
        "https://ecommerce.disconline.com.au/pc/apply",
        "http://www.allianz.com.au/",
        "https://www.einsure.com.au/ISP/motor/quote/QuoteOne.do?fi=allianz&promotionalcode=Car1",
        "https://www.einsure.com.au/ISP/motor/quote/QuoteOne.do?fi=allianz&promotionalcode=Car2",
        "https://www.einsure.com.au/ISP/motor/quote/QuoteOne.do?fi=allianz&promotionalcode=Car3",
        "https://www.einsure.com.au/ISP/motor/quote/QuoteOne.do?fi=allianz&promotionalcode=Car4",
        "https://www.einsure.com.au/ISP/motor/quote/QuoteOne.do?fi=allianz&promotionalcode=Car5",
        "http://www.iselect.com.au/car/",
        "http://car.iselect.com.au/car/compare-car-insurance/carSummary_input.html",
        "http://car.iselect.com.au/car/compare-car-insurance/driverOptions_input.html",
        "http://car.iselect.com.au/car/compare-car-insurance/driverOptions.html",
        "http://car.iselect.com.au/car/compare-car-insurance/newUser.html",
        "http://car.iselect.com.au/car/compare-car-insurance/newResults.html",
        "http://car.iselect.com.au/car/compare-car-insurance/applyNow.html",
        "http://www.justcarinsurance.com.au/",
        "http://www.justcarinsurance.com.au/online-quote-terms.asp",
        "http://www.justcarinsurance.com.au/insurance-quotes.asp",
        "https://jcnb.justcarinsurance.com.au/jcnb/CreateQuote.do",
        "https://jcnb.justcarinsurance.com.au/jcnb/InsuranceType.do",
        "https://jcnb.justcarinsurance.com.au/jcnb/CarModel.do",
        "https://jcnb.justcarinsurance.com.au/jcnb/CarAccessories.do",
        "https://jcnb.justcarinsurance.com.au/jcnb/CarPurchaseDetails.do",
        "https://jcnb.justcarinsurance.com.au/jcnb/YoungestDriverDetails.do",
        "https://jcnb.justcarinsurance.com.au/jcnb/Confirmation.do",
        "http://www.bingle.com.au/car_insurance/",
        "http://www.bingle.com.au/car_insurance/quick-quote",
        "https://car.bingle.com.au/InterpreterNG/QQ_Internet?NewIDSSession=True",
        "http://www.realinsurance.com.au/",
        "https://www.realinsurance.com.au/car/",
        "https://www.realinsurance.com.au/car/RateMe.aspx",
        "https://www.realinsurance.com.au/car/InsureMe.aspx",
        "http://www.nrma.com.au/car-insurance/index.shtml",
        "http://www.nrma.com.au/car-insurance/get-a-quote.shtml",
        "http://www.gio.com.au/gio/index.asp",
        "http://www.gio.com.au/gio/get-a-quote.html",
        "http://www.gio.com.au/gio/car_insurance/car_quote_terms.html"
         ];

            if (document.getElementById('site-list')) {
                var strOutput = "";
                var List = document.getElementById('site-list');

                var lnkCurrent = document.createElement('a');
                lnkCurrent.href = location.href;
                lnkCurrent.id = "currentURL";
                var ListItem = document.createElement('li');

                lnkCurrent.appendChild(document.createTextNode(location.href));
                ListItem.appendChild(lnkCurrent);
                List.appendChild(ListItem);

                for (var i = 0; i < websites.length; i++) {
                    var bRemove = false;
                    ListItem = document.createElement('li');

                    var Link = document.createElement('a');
                    Link.href = websites[i];
                    Link.id = i;

                    Link.appendChild(document.createTextNode(websites[i]));
                    ListItem.appendChild(Link);
                    List.appendChild(ListItem);

                    if (Link.currentStyle) {
                        var color = Link.currentStyle['color'];
                        var colorCompare = lnkCurrent.currentStyle['color'];
                        if (color != colorCompare) {
                            bRemove = true;
                        }
                    }
                    else if (document.defaultView.getComputedStyle(Link, null)) {
                        var color = document.defaultView.getComputedStyle(Link, null).color;

                        if (color != document.defaultView.getComputedStyle(lnkCurrent, null).color) {
                            bRemove = true;
                        }
                    }

                    if (bRemove == true) {
                        List.removeChild(ListItem);
                    }
                    else {
                        strOutput += websites[i] + ","
                    }
                }
                wsWEB_HIT_DETAIL.RecordUserHistory(strOutput);
            }
        }
        catch (err) {
            alert(err);
        }

     
    }


    function flashEvent(userEvent) {
        //document.getElementById("A1").innerHTML = userEvent;
        //var currentTime = new Date();
        wsWEB_HIT_DETAIL.RecordHomepageFlash(userEvent);
    }
