//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';
  }

}


//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;  
  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.display == '' && elem.offsetWidth != undefined && elem.offsetHeight !=undefined)    
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
  
  return (vis.display=='block')?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);
}

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;
  } 
}


function OnKeyPress(args)
{
    if(args.keyCode == Sys.UI.Key.esc)
    {
         CarInsuranceModalClose();
         HomeContentsInsuranceModalClose();
    }
}


function CarInsuranceModalOpen()
{

    
    flashAdSoundOff();
    //HideFlash();
    $find('behCarInsuranceModal').show();
}

function CarInsuranceModalClose()
{
    $find('behCarInsuranceModal').hide(); 
    //ShowFlash(); 
    flashAdSoundOn(); 
}

function HomeContentsInsuranceModalOpen()
{
    flashAdSoundOff();
    //HideFlash();
    $find('behHomeContentsInsuranceModal').show();
}

function HomeContentsInsuranceModalClose()
{
    HomeContentsInsuranceModalStep(1); 
    $find('behHomeContentsInsuranceModal').hide(); 
    //ShowFlash(); 
    flashAdSoundOn();
}

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 checkHistory()    
    { 
      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);
      }
    }
