 window.onload=function() {
	initGooglePlusOne();
	
	if ($('.slideInBox').length) {
        var thisSlideName = $('.slideInBox:first-child').attr('id');
        var timesShown = getCookie(thisSlideName);

        if (timesShown < 1) {
            var slideInBox = $('.slideInBox');

            $('.slideInBox').delay(1000).fadeIn('slow');

            timesShown++;
            setCookie(thisSlideName, timesShown, 1);
        }
        //deleteCookie(thisSlideName);
    }
	
    
  }
  
 
  function initGooglePlusOne() {
    var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
    po.src = 'https://apis.google.com/js/plusone.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
  }



function SlideInHide() {
    var thisSlideName = $('.slideInBox:first-child').attr('id');
    var timesShown = getCookie(thisSlideName);
    timesShown++;

    $('.slideInBox').fadeOut('fast');

    setCookie(thisSlideName, timesShown, 7);
}

function SlideInSignup() {
    var pName = $('#popupName').val();
    var pEmail = $('#popupEmail').val();
/*
    if (jQuery.trim(pName) == "" || pName == "Your name.." || jQuery.trim(pEmail) == "" || pEmail == "Your email..") {
        alert('Please fill in all values');
        return true;
    }*/

    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(pEmail)) {
        alert('Please enter a valid email');
        return true;
    }
    
    $('.PopUpForm').submit();
    SlideInHide();

	/*
    var signupURL = "/Home/CreateVoucher?email=" + pEmail + "&name=" + pName +"&ran=" + Math.random();
    $('.slideInBox').fadeOut('fast');
    $.ajax({
        url: signupURL,
        context: document.body,
        success: function (data) {
            alert(data);

            var thisSlideName = $('.slideInBox:first-child').attr('id');
            var timesShown = getCookie(thisSlideName);

            timesShown++;
            setCookie(thisSlideName, timesShown, 7);
           
            return false;
        }
    });*/

}

// Cookie functions
function setCookie(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 = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}
function getCookie(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;
}

function deleteCookie(name) {
    setCookie(name, "", -1);
}



function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", sfHover);

var xmlhttp=false;
try 
{
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} 
catch (e) 
{
	try 
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (E) 
	{
		xmlhttp = false;
	}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') 
{
	try 
	{
		xmlhttp = new XMLHttpRequest();
	} 
	catch (e) 
	{
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) 
{
	try 
	{
		xmlhttp = window.createRequest();
	} 
	catch (e) 
	{
		xmlhttp=false;
	}
}

//AJAX function purely for static product pages
function GetCurrency(rrp, price)
{	
	xmlhttp.open("GET", "/Includes/getCurrency.aspx?RRP=" + rrp + "&UKPrice=" + price + "&Rand=" + Math.random() ,true);
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4) 
		{			
			ShowText("priceDiv", xmlhttp.responseText);
		}
	}
	xmlhttp.send(null)
}

//Sets the session to the same value as the "Currency" cookie
function SetSession()
{
	window.location = "/Includes/setSession.aspx?URL=" + escape(window.location) + "&Rand=" + Math.random();
}

//Called everytime the NoMetaHeader page is loaded
function GetCurrencyFlag()
{	
	var curr = getCookie("Currency");

	if(curr == null || curr == "")
	{
		SetCurrencyFlag("GBP");
	}
	else
	{
		setFlagsDiv(curr);
	}
}

//Changes the current currency
function SetCurrencyFlag(currency)
{	
	createCookie("Currency", currency);
	SetSession();
	refreshPage();
}

function addQueryString(url, addition)
{
	if(url.indexOf('?') > -1)
	{
		url = url + "&" + addition;	
	}
	else
	{
		url = url + "?" + addition;
	}
	return url;
}

function removeHash(url)
{
	if(url.lastIndexOf('#') == url.length - 1)
	{
		url = url.substring(0, url.length-1)
	}
	return url;
}

function ShowText(element, theText)
{			
	document.getElementById(element).innerHTML = theText;					
}

function refreshPage()
{
	window.location.reload(true);
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=")
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1 
			c_end=document.cookie.indexOf(";",c_start)
			if (c_end==-1) c_end=document.cookie.length
			{
				return unescape(document.cookie.substring(c_start,c_end))
			}
		} 
	}
	return ""
}


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 = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
 
function setFlagsDiv(curr)
{
	var alt1 = "";
	var alt2 = "";
	var alt3 = "";
	var alt4 ="";
	var alt5 = "";
	var alt6 = "";
	var alt7 = "";
	var img1 = "";
	var img2 = "";
	var img3 = "";
	var img4 = "";
	var img5 = "";
	var img6 = "";
	var img7 = "";
	var img8 = "";
	var img9 = "";
	

	if(curr == "EURO")
	{
		alt1 = "EURO Currency";
		alt2 = "GBP Currency";
		alt3 = "USA Currency";
		alt4 = "JPY Currency";
		alt5 = "AUD Currency";
		alt6 = "NZD Currency";
		alt7 = "CAN Currency";
		img1 = "/smallflags/eu.jpg";
		img2 = "/smallflags/gb.jpg";
		img3 = "/smallflags/us.jpg";
		img4 = "/smallflags/jp.jpg";
		img5 = "/smallflags/au.jpg";
		img6 = "/smallflags/nz.jpg";
		img7 = "/smallflags/can.jpg";

	}
	else if(curr == "GBP")
	{
		alt1 = "EURO Currency";
		alt2 = "GBP Currency";
		alt3 = "USA Currency";
		alt4 = "JPY Currency";
		alt5 = "AUD Currency";
		alt6 = "NZD Currency";
		alt7 = "CAN Currency";
		img1 = "/smallflags/eu.jpg";
		img2 = "/smallflags/gb.jpg";
		img3 = "/smallflags/us.jpg";
		img4 = "/smallflags/jp.jpg";
		img5 = "/smallflags/au.jpg";
		img6 = "/smallflags/nz.jpg";
		img7 = "/smallflags/can.jpg";
	}
	else if(curr == "USD")
	{
		alt1 = "EURO Currency";
		alt2 = "GBP Currency";
		alt3 = "USA Currency";
		alt4 = "JPY Currency";
		alt5 = "AUD Currency";
		alt6 = "NZD Currency";
		alt7 = "CAN Currency";
	img1 = "/smallflags/eu.jpg";
		img2 = "/smallflags/gb.jpg";
		img3 = "/smallflags/us.jpg";
		img4 = "/smallflags/jp.jpg";
		img5 = "/smallflags/au.jpg";
		img6 = "/smallflags/nz.jpg";
		img7 = "/smallflags/can.jpg";
	}
	else if(curr == "JPY")
	{
		alt1 = "EURO Currency";
		alt2 = "GBP Currency";
		alt3 = "USA Currency";
		alt4 = "JPY Currency";
		alt5 = "AUD Currency";
		alt6 = "NZD Currency";
		alt7 = "CAN Currency";
	img1 = "/smallflags/eu.jpg";
		img2 = "/smallflags/gb.jpg";
		img3 = "/smallflags/us.jpg";
		img4 = "/smallflags/jp.jpg";
		img5 = "/smallflags/au.jpg";
		img6 = "/smallflags/nz.jpg";
		img7 = "/smallflags/can.jpg";
	}
	else if(curr == "AUD")
	{
		alt1 = "EURO Currency";
		alt2 = "GBP Currency";
		alt3 = "USA Currency";
		alt4 = "JPY Currency";
		alt5 = "AUD Currency";
		alt6 = "NZD Currency";
		alt7 = "CAN Currency";
		img1 = "/smallflags/eu.jpg";
		img2 = "/smallflags/gb.jpg";
		img3 = "/smallflags/us.jpg";
		img4 = "/smallflags/jp.jpg";
		img5 = "/smallflags/au.jpg";
		img6 = "/smallflags/nz.jpg";
		img7 = "/smallflags/can.jpg";
	}
	else if(curr == "NZD")
	{
		alt1 = "EURO Currency";
		alt2 = "GBP Currency";
		alt3 = "USA Currency";
		alt4 = "JPY Currency";
		alt5 = "AUD Currency";
		alt6 = "NZD Currency";
		alt7 = "CAN Currency";
		img1 = "/smallflags/eu.jpg";
		img2 = "/smallflags/gb.jpg";
		img3 = "/smallflags/us.jpg";
		img4 = "/smallflags/jp.jpg";
		img5 = "/smallflags/au.jpg";
		img6 = "/smallflags/nz.jpg";
		img7 = "/smallflags/can.jpg";
		}
	else if(curr == "CAN")
	{
		alt1 = "EURO Currency";
		alt2 = "GBP Currency";
		alt3 = "USA Currency";
		alt4 = "JPY Currency";
		alt5 = "AUD Currency";
		alt6 = "NZD Currency";
		alt7 = "CAN Currency";
		img1 = "/smallflags/eu.jpg";
		img2 = "/smallflags/gb.jpg";
		img3 = "/smallflags/us.jpg";
		img4 = "/smallflags/jp.jpg";
		img5 = "/smallflags/au.jpg";
		img6 = "/smallflags/nz.jpg";
		img7 = "/smallflags/can.jpg";
	}
				
	var flagsDiv = document.getElementById("flagsDiv");
	flagsDiv.innerHTML = "<a href='#' onClick='javascript:SetCurrencyFlag(\"EURO\");'><img height='26' src='" + img1 + "' alt='" + alt1 + "' border='0' /></a>&nbsp;";
	flagsDiv.innerHTML += "<a href='#' onClick='javascript:SetCurrencyFlag(\"GBP\");'><img height='26' src='" + img2 + "' alt='" + alt2 + "' border='0' /></a>&nbsp;";
	flagsDiv.innerHTML += "<a href='#' onClick='javascript:SetCurrencyFlag(\"USD\");'><img height='26' src='" + img3 + "' alt='" + alt3 + "' border='0' /></a>&nbsp;";
	flagsDiv.innerHTML += "<a href='#' onClick='javascript:SetCurrencyFlag(\"JPY\");'><img height='26' src='" + img4 + "' alt='" + alt4 + "' border='0' /></a>&nbsp;";
	flagsDiv.innerHTML += "<a href='#' onClick='javascript:SetCurrencyFlag(\"AUD\");'><img height='26' src='" + img5 + "' alt='" + alt5 + "' border='0' /></a>&nbsp;";
	flagsDiv.innerHTML += "<a href='#' onClick='javascript:SetCurrencyFlag(\"NZD\");'><img height='26' src='" + img6 + "' alt='" + alt6 + "' border='0' /></a>&nbsp;";
	flagsDiv.innerHTML += "<a href='#' onClick='javascript:SetCurrencyFlag(\"CAN\");'><img height='26' src='" + img7 + "' alt='" + alt7 + "' border='0' /></a>&nbsp;";
}

