//Parses the url query string and returns the value of name
function getAffiliateFromQuery(name)
{
  var query = window.location.search.substring(1);
  var vars = query.split("&");

  for(var i=0;i<vars.length;i++)
  {
    var pair = vars[i].split("=");
    if(pair[0] == name)
    {
      return pair[1];
    }
  }
  return "none";
}

//Create a cookie
function createCookie(name,value,days)
{
  if(days)
  {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else
  {
    var expires = "";
  }  
  var cookie = name+"="+value+expires+"; path=/";
  document.cookie = cookie;
}

//Read cookie
function readCookie(name)
{
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i<ca.length;i++)
  {
    var c = ca[i];
    while(c.charAt(0)==' ') c = c.substring(1,c.length);
    if(c.indexOf(nameEQ) == 0)  return c.substring(nameEQ.length,c.length);
  }
  return null;
}

//Show the telephone img
function showImg(imgId)
{
  document.getElementById(imgId).style.visibility='visible';
}

function handler() //this should be called from the body tag
{
    //Process the affiliate link into the site
    var affiliate = getAffiliateFromQuery('adnetwork');
    if(affiliate != "none") 
    {
	createCookie("affiliate_networks",affiliate,3);
    }
    //The appropriate affiliate is now set

    //If there is no affiliate show telephone images
    var x = readCookie("affiliate_networks");
    //alert(x);
    if(readCookie("affiliate_networks") == null)
    {
	showImg("enq");
    }
}




//<![CDATA[
if(screen.width >= 1280) document.write("<link href='/shop/skin1/sheets/margin.css' rel='stylesheet' rel='stylesheet' type='text/css' />");
//]]>

