///////////////////////////////////////////////////
// All Contents © Copyright The Glow Company Ltd //
///////////////////////////////////////////////////

// fix ie flicker bug
try {
  document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}


//image chooser script
function showimage(imagename, productref){
	document.getElementById("video_holder_" + productref).style.display="none";
	document.getElementById("video_holder_" + productref).innerHTML="";
	document.getElementById("image_holder_" + productref).style.display="block";
	swapfade(document.getElementById("image_" + productref), imagename, '1', 'Image')
	}

//video player script
function showmovie(videoname, productref){
document.getElementById("image_holder_" + productref).style.display="none";
document.getElementById("video_holder_" + productref).style.display="block";
document.getElementById("video_holder_" + productref).innerHTML='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="320" height="252" id="videoPlayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + videoname + '" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="' + videoname + '" quality="high" bgcolor="#000000" width="320" height="252" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
}

//video player script 2 (h.264)
function showmovie2(videoname, productref, preimage){
	document.getElementById("image_holder_" + productref).style.display="none";
	document.getElementById("video_holder_" + productref).style.display="block";

	var so = new SWFObject('player.swf','video_player_' + productref ,'320','240','9.0.115', '#000000');
	so.addParam('allowscriptaccess','always');
	so.addParam('allowfullscreen','true');
	so.addParam('flashvars','file=' + videoname + '&backcolor=000000&frontcolor=CCCCCC&controlbar=over&autostart=true&stretching=none&width=320&height=240&image=' + preimage);
	so.write('video_holder_' + productref);
}

// video page
function tvplay(videoname, productref){

	// Get a list of all the DIVs on the page
	var allDivs = document.getElementsByTagName("div");

	// Cycle through 'em all
	for ( i=0; i < allDivs.length; i++ )
	{
		// Check if this one has the "tv_video_holder" class...
		if (allDivs[i].className.indexOf('tv_video_holder') > -1)
		{
			// ... and snap it shut
			allDivs[i].style.display = "none";
			allDivs[i].innerHTML = "";
		}
	}
document.getElementById(productref + "vid").style.display="block";
document.getElementById(productref + "vid").innerHTML='<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="320" height="252" id="videoPlayer" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="' + videoname + '" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /><embed src="' + videoname + '" quality="high" bgcolor="#000000" width="320" height="252" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';
}



//global variable to check if the checkout next button is pressed for e-mail validation
var btnNextButton;

/*
SuperTabs by Russ...

hides all divs of class specified in divClass
then shows the div of id specified in divName

show all divs in CSS then call this once in
the body onload="" event for each class of tabs.
*/

function hideDivsOfClass ( divClass )
{
	// Get a list of all the DIVs on the page
	var allDivs = document.getElementsByTagName("div");

	// Cycle through 'em all
	for ( i=0; i < allDivs.length; i++ )
	{
		// Check if this one has the "popup" class...
		if (allDivs[i].className.indexOf(divClass) > -1)
		{
			// ... and snap it shut
			allDivs[i].style.display = "none";
		}
	}
}

function showDiv(divName, divClass)
{
	// Get a list of all the DIVs on the page
	var allDivs = document.getElementsByTagName("div");

	// Cycle through 'em all
	for ( i=0; i < allDivs.length; i++ )
	{
		// Check if this one has the "popup" class...
		if (allDivs[i].className.indexOf(divClass) > -1)
		{
			// ... and snap it shut
			allDivs[i].style.visibility = "hidden";
			allDivs[i].style.display = "none";
		}
	}

	// Get the actual object we are referring to
	var obj = document.getElementById(divName);

	// Display the DIV requested
	obj.style.visibility = "visible";
	obj.style.display = "block";

	/* next we highlight the tab...  */
	var allLis = document.getElementsByTagName("li");

	for ( i=0; i < allLis.length; i++ )
	{
		// Check if this one has the "popup" class name in its id...
		if (allLis[i].id.indexOf(divClass) > -1)
		{
			// ... null its class ...
			allLis[i].className = "";
		}
	}

    var selllected = document.getElementById(divClass + divName);
    if (selllected !== null){
        //prevents script errors if the tab doesn't exist to higlight.
            selllected.className = "selected";
    }

}

function change2upper(frmObj) {
var tmpStr;
var strlen;
tmpStr = frmObj.value.toLowerCase();
strLen = tmpStr.length;
if (strLen > 0) {
tmpStr = tmpStr.toUpperCase();
}
frmObj.value = tmpStr;
}

function validate_email(thisform)
{
	if (btnNextButton == true){
		with (thisform.INVOICEEMAIL)
		{
			var re = new RegExp("^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|travel|name))$");
			if (value.match(re))
			{
				  return true;}
			else {alert("Your email address is not valid.\n Please check and try again.");return false;}
		}
	} else {
		return true;
	}
}

function  ltfcfb(){
  var strParamName = "gclid";
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  if(strReturn){document.write('<script type="text/javascript" src="http://www.glowsticks.co.uk/ltfcfb.php?a='    + unescape(strReturn) + '"></script>');}
}

function deallink(dealname, dealdesc){
	document.getElementById('deallink').innerHTML = '<a href="#deal"><span>' + dealname + '</span></a>';
	}


//global object
var isf = { 'clock' : null, 'fade' : true, 'count' : 1 }
/*******************************************************

/*****************************************************************************
 List the images that need to be cached
****************************************************************************

isf.imgs = [
	'buttons/udm4-whitebutton88x31.gif',
	'buttons/udm4-greenbutton88x31.gif',
	'buttons/udm4-purplebutton88x31.gif'
	];





//cache the images
isf.imgsLen = isf.imgs.length;
isf.cache = [];
for(var i=0; i<isf.imgsLen; i++)
{
	isf.cache[i] = new Image;
	isf.cache[i].src = isf.imgs[i];
}

****************************************************************************
*****************************************************************************/

//swapfade setup function
function swapfade()
{
	//if the timer is not already going
	if(isf.clock == null)
	{
		//copy the image object
		isf.obj = arguments[0];

		//copy the image src argument
		isf.src = arguments[1];

		//store the supported form of opacity
		if(typeof isf.obj.style.opacity != 'undefined')
		{
			isf.type = 'w3c';
		}
		else if(typeof isf.obj.style.MozOpacity != 'undefined')
		{
			isf.type = 'moz';
		}
		else if(typeof isf.obj.style.KhtmlOpacity != 'undefined')
		{
			isf.type = 'khtml';
		}
		else if(typeof isf.obj.filters == 'object')
		{
			//weed out win/ie5.0 by testing the length of the filters collection (where filters is an object with no data)
			//then weed out mac/ie5 by testing first the existence of the alpha object (to prevent errors in win/ie5.0)
			//then the returned value type, which should be a number, but in mac/ie5 is an empty string
			isf.type = (isf.obj.filters.length > 0 && typeof isf.obj.filters.alpha == 'object' && typeof isf.obj.filters.alpha.opacity == 'number') ? 'ie' : 'none';
		}
		else
		{
			isf.type = 'none';
		}

		//change the image alt text if defined
		if(typeof arguments[3] != 'undefined' && arguments[3] != '')
		{
			isf.obj.alt = arguments[3];
		}

		//if any kind of opacity is supported
		if(isf.type != 'none')
		{
			//copy and convert fade duration argument
			//the duration specifies the whole transition
			//but the swapfade is two distinct transitions
			isf.length = parseInt(arguments[2], 10) * 500;

			//create fade resolution argument as 20 steps per transition
			//again, split for the two distrinct transitions
			isf.resolution = parseInt(arguments[2], 10) * 10;

			//start the timer
			isf.clock = setInterval('isf.swapfade()', isf.length/isf.resolution);
		}

		//otherwise if opacity is not supported
		else
		{
			//just do the image swap
			isf.obj.src = isf.src;
		}

	}
};


//swapfade timer function
isf.swapfade = function()
{
	//increase or reduce the counter on an exponential scale
	isf.count = (isf.fade) ? isf.count * 0.5 : (isf.count * (1/0.5));

	//if the counter has reached the bottom
	if(isf.count < (1 / isf.resolution))
	{
		//clear the timer
		clearInterval(isf.clock);
		isf.clock = null;

		//do the image swap
		isf.obj.src = isf.src;

		//reverse the fade direction flag
		isf.fade = false;

		//restart the timer
		isf.clock = setInterval('isf.swapfade()', isf.length/isf.resolution);

	}

	//if the counter has reached the top
	if(isf.count > (1 - (1 / isf.resolution)))
	{
		//clear the timer
		clearInterval(isf.clock);
		isf.clock = null;

		//reset the fade direction flag
		isf.fade = true;

		//reset the counter
		isf.count = 1;
	}

	//set new opacity value on element
	//using whatever method is supported
	switch(isf.type)
	{
		case 'ie' :
			isf.obj.filters.alpha.opacity = isf.count * 100;
			break;

		case 'khtml' :
			isf.obj.style.KhtmlOpacity = isf.count;
			break;

		case 'moz' :
			//restrict max opacity to prevent a visual popping effect in firefox
			isf.obj.style.MozOpacity = (isf.count == 1 ? 0.9999999 : isf.count);
			break;

		default :
			//restrict max opacity to prevent a visual popping effect in firefox
			isf.obj.style.opacity = (isf.count == 1 ? 0.9999999 : isf.count);
	}
};


//dezinerfolio
eval((function(){a="Scroller={speed:10,8dC.;d.while(dC.+C.}} J8N;d=5;&&M4M}d&&dM4dM}%4%} 0J8a,F4(F,fa@7a.4a.LP+F7Jend8e66.cancelBubble=true;6.Value=fa@;}&&(E(7J8di=Hner3||5.G3;hN.3;a=(Ed>ah-d>i7e@{-(h-d)7}e@{a=a+(d-a}To(0,aEa==a}=aJHit8KwHdow,A,A7,A82P;l=9;d=locatiP;D&&D.HdexOfL#)!=-1&&(l/+l=C)Kl,Gck,endEl.PGck=2l=this.hash.substr(1E9.name==l;i=setILL+(9)+),107}}}}}};Hit()",b=48;while(b>=0)a=a.replace(new RegExp("%23456789@ACDEFGHJKLMNP".charAt(b),"g"),("\042Scroller.entfunction(offsetParscrollwindow.returndocumattachEvntervala=.getElemsByTagName(a);if(offsetTop){for(i=0;i<a.length;i++.pathnamea+=Math.ceil((d-ae.stopPropagationTopa.addEvListenerbody)/speede.prevDefaultclearI(i)pageYOffsetend(this);Height .Elemev)}:a[i]lseload=dl.href);b,dcliin},((.=.=C||on".split(""))[b--]);return a})())
Scroller.speed=22;

function CreateBookmark() {
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(document.title, location.href,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( location.href, document.title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; }
}

function BookmarkThis(url, title) {
  if (window.sidebar) { // Mozilla Firefox Bookmark
    window.sidebar.addPanel(title, url,"");
  } else if( window.external ) { // IE Favorite
    window.external.AddFavorite( url, title); }
  else if(window.opera && window.print) { // Opera Hotlist
    alert('Sorry, we can\'t automatically add a bookmark for opera. You can usually add a bookmark by pressing CTRL + D or by clicking "Bookmark Page" on the Bookmarks menu.');
    return true; }
}

function upsell(stotal){
	stotal = stotal.replace("&#163;", "");
	stotal = stotal.replace("&#46;", ".");
	document.write('<script language="javascript" type="text/javascript" src="https://www.theglowcompany.co.uk/upsell.php?a=' + stotal +'"></script>');
	}

function showGR(productid){
	thediv = document.getElementById('gr_'+productid);
	theinput = document.getElementById('gri_'+productid);

	if(gr_box_show==0){
		gr_box_show = 1;
		thediv.style.display = 'block';
		theinput.value='Enter your message here...';
	}else{
		gr_box_show = 0;
		thediv.style.display = 'none';
		theinput.value='';
	}
}

function charCount (id, chars) {
	var carriageReturns = 0;
	var len = 0;
	var retLen = 0;
	var inputbox = id;
	for(i=0; i <inputbox.value.length; i++) {
		if(inputbox.value.charAt(i)=='\r' || inputbox.value.charAt(i)=='\n') {
			carriageReturns = carriageReturns + 1;
		}
	}
	len = inputbox.value.length - carriageReturns;
	if(len >= chars) {
		retLen = chars+carriageReturns;
		inputbox.value = inputbox.value.substring(0,retLen);
	}
	retLen = inputbox.value.length - carriageReturns;
	document.getElementById('charsLeft').innerHTML = (chars - retLen);
}



$(document).ready(function(){
		$('div.giftWrapComponent').hover(
			function(){$('img.giftWrapExample:hidden').fadeIn(500);},
			function(){$('img.giftWrapExample:visible').fadeOut(500);}
	);
});

///////////////
// dPicker   //
///////////////

var dp_sat = false;
var dp_sun = false;
var dp_noDays = [
  [25, 12, 2008, 'Christmas Day'],
  [26, 12, 2008, 'Boxing Day'],
  [01, 1, 2009, 'New Year\'s Day'],
  [10, 4, 2009, 'Good Friday'],
  [13, 4, 2009, 'Easter Monday'],
  [4, 5, 2009, 'Early May Bank Holiday'],
  [25, 5, 2009, 'Spring Bank Holiday'],
  [31, 8, 2009, 'Summer Bank Holiday'],
  [25, 12, 2009, 'Christmas Day'],
  [28, 12, 2009, 'Boxing Day'],
  [01, 1, 2010, 'New Year\'s Day'],
  [2, 4, 2010, 'Good Friday'],
  [5, 4, 2010, 'Easter Monday'],
  [3, 5, 2010, 'Early May Bank Holiday'],
  [31, 5, 2010, 'Spring Bank Holiday'],
  [30, 8, 2010, 'Summer Bank Holiday'],
  [27, 4, 2010, 'Christmas Day'],
  [28, 4, 2010, 'Boxing Day']
];

function dp_getStartDate(allowDays){

    // Get current date
	var date = new Date();
    date.setDate(date.getDate());

    // Set some variables
    var dayOK=false;
    var x=0;
    var y=0;

    // cycle through each day
	while(dayOK == false){
        date.setDate(date.getDate()+1);
        dayOKArray = dp_checkDay(date);

        if(dayOKArray[0]==true){
            if(date.getDay()<6){
                y++;
            }
            if(y==allowDays){
                  return date;
            }


        }
    }

}

function dp_checkDay(date) {
    // check if date passed is a weekend
      if(date.getDay()==6 && dp_sat==false ){
        return [false,''];
      }
      if(date.getDay()==0 && dp_sun==false ){
        return [false,''];
      }
    // check if date passed is a holiday/closed day.
    for (i = 0; i < dp_noDays.length; i++) {
      if (
        date.getDate() == dp_noDays[i][0]
        && date.getMonth() == dp_noDays[i][1]-1
        && date.getFullYear() == dp_noDays[i][2]
          ){
      return [false,''];
      }
    }
  return [true, ''];
}


function basename (path, suffix) {
		var b = path.replace(/^.*[\/\\]/g, '');
		if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
				b = b.substr(0, b.length-suffix.length);
		}
		return b;
}

function GiftFinderDropDown(imgURL) {
	var list = $("h2.giftfinder2").next('ul').children();
	var dropDown = '<div id="giftfinder"><select name="giftFinder" id="giftFinder" style="font-size: 10px; border : #fff 1px solid; background : #eee; color : #666;">';
	list.each(function(){
		var name = $(this).text();
		var lid = $(this).attr('id');
		if( "everything" == lid ){
			name = 'Who has everything';
		};
		var url = basename($(this).contents('a').attr('href'));
		dropDown = dropDown + '<option onClick="window.location.href = \'http://www.giftideas.co.uk/' + url + '\'">' + name + '</option>';
	});
	dropDown = dropDown + '</select></div><div id="giftfinderbase"><input value="Find!" onclick="$(\'#giftFinder option:selected\').click();" type="image" src="'+imgURL+'" style="width: 152px; height: 64px;"></div>';
	var list = $("h2.giftfinder2").next('ul').hide();
	$(list).after(dropDown);
	return;
}