﻿function showAdvancedSearch()
{
    document.getElementById('advanced-search-content').style.display = "inline";
}

function hideAdvancedSearch()
{
    document.getElementById('advanced-search-content').style.display = "none";
}

function EndRequestHandler(sender, args) 
{
   if (args.get_error() == undefined)
   {
    document.getElementById("basket-totals").style.color="rgb(204,4,104)";
    document.getElementById("basket-totals").style.fontWeight = 
    fadetext();
   }
   else
       alert("There was an error" + args.get_error().message);
}

function load() 
{
   Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
}

var hex1=204; 
var hex2=4; 
var hex3=104;
                                
function fadetext()
{
    if ((hex1 < 205) && (hex2 < 204) && (hex3 < 204)) 
    {
        hex2 += 2;
        hex3 += 1;
        document.getElementById("basket-totals").style.color = "rgb(" + hex1 + "," + hex2 + "," + hex3 + ")";
        setTimeout("fadetext()", 20); 
    }
    else
    {
        hex1 = 204;
        hex2 = 4;
        hex3 = 104;
    }
}

//This sets a hidden field in the page in preperation for being deleted if the user choses to
function DeleteItem(cartId) 
{
    document.getElementById(_hiddenField).value = cartId;
}

//Validate the login, checking that all fields are complete
function ValidateLogin() 
{
}

$(document).ready(function() {
    initImageLoader();
});

var intv = null;

function initImageLoader() {
//    $('img.loading').load(function() {
//        $(this).siblings(".progress").remove(); //.hide();
//        $(this).show();
//    });

    intv = setInterval(checkImages, 200);
    setTimeout(finalImageCheck, 6000);
    $('img.loading').hide();
}

//just in case .load function is missed
function finalImageCheck() {
  clearInterval(intv);
    $("img.loading").show();
    $("img.progress").remove();
}

function checkImages()
{
    var tmbs = $('img.loading');

    for (var ix = 0; ix < tmbs.length; ix++) {
      if (isImageLoaded(tmbs[ix])) {
        var ii = $($('img.loading')[ix])
        ii.show();
        ii.siblings(".progress").remove();
      }
    }  
}

function isImageLoaded(img) {

  //ie
  if (!img.complete) return false;

  //ns4 + gecko etc
  if (img.naturalWidth != 'undefined' && img.naturalWidth == 0) return false;

  return true;
}
