function showTnc(){
	var newwin = window.open("/purchase-terms--conditions.aspx","terms","width=600,height=550,scrollbars=yes,noResize=true");
}

function navOver(imgTag)
{        
	var theImage = imgTag;	
	if(theImage.src.indexOf("_off.") != -1)	
	{
		theImage.src = theImage.src.replace("_off.","_over.");		
	}
	else	
	{
		theImage.src = theImage.src.replace("_over.","_off.");	
	}
}

function enterCode()
{
	var theId = document.getElementById("promoFields");

	if((theId.style.display == "") || (theId.style.display == "none"))
	{
		theId.style.display = "block";
	}	
	else
	{
		theId.style.display = "none";	
	}
}

function addLoadEvent(func) 
{ 
	var oldonload = window.onload; 
	if (typeof window.onload != 'function') 
	{ 
		window.onload = func; 
	} 
	else 
	{ 
		window.onload = function() 
		{ 
			if (oldonload) 
			{ 
				oldonload(); 
			} 
			func(); 
		} 
	} 
} 

addLoadEvent( function() 
{
	/* initializeSubNav("scrollNav"); */

	if(document.getElementById("moreBrief") != null) 	
	{
		initMoreBrief();
	}
	
	if(document.getElementById("converterTitle") != null)	
	{
		initCurrencyConverter();			
	}

	if(document.getElementById("promoFields") != null)
	{	
		document.getElementById("promoFields").style.display = "none";
	}

})	

var storeAtts = new Array();
var inAction = new Array();
var expanded = new Array();
var moreBriefHeight = "";

function initMoreBrief()
{
	var theBtnId = document.getElementById("moreBriefBtn");	
	var theId = document.getElementById("moreBrief");
	
	moreBriefHeight = theId.offsetHeight;		
	theId.style.height = 0 + "px";		
	theBtnId.style.display = "inline";
	theBtnId.href = "#more";
	theBtnId.onclick = function() {moreBrief()};
}

function moreBrief()
{
	var theBtnId = document.getElementById("moreBriefBtn");
	var theId = document.getElementById("moreBrief");
	
	if(parseInt(theId.style.height) == 0)
	{
		theBtnId.href = "#less";
		theBtnId.title = "Less";
		theBtnId.className = "up";
		theBtnId.innerHTML = "Less";
		expandBrief();
	}
	else if(parseInt(theId.style.height) == parseInt(moreBriefHeight))
	{
		theBtnId.href = "#more";
		theBtnId.title = "More";
		theBtnId.className = "down";
		theBtnId.innerHTML = "More";
		hideBrief();
	}
}

function expandBrief()
{
	var theId = document.getElementById("moreBrief");
	var currentHeight = parseInt(theId.style.height);
	var steps;
	
	if(currentHeight < parseInt(moreBriefHeight))
	{
		if(currentHeight+10 >= parseInt(moreBriefHeight))	
		{
			steps = parseInt(moreBriefHeight) - currentHeight;			
		}
		else
		{
			steps = 5;			
		}
		
		theId.style.height = (parseInt(theId.style.height) + steps) + "px";
		setTimeout("expandBrief()",10);
	}	
}

function hideBrief()
{
	var theId = document.getElementById("moreBrief");
	var currentHeight = parseInt(theId.style.height);
		
	if(currentHeight > 0)
	{
		if(currentHeight-10 >= 0)	
		{
			steps = 5;					
		}
		else
		{
			steps = 1;								
		}
		
		theId.style.height = (parseInt(theId.style.height) - steps) + "px";
		setTimeout("hideBrief()",10);
	}
}

function checkValue(el, event, name)
{
	if((name == "name") && (event == "focus") && (el.value == "Enter First Name"))
	{
		el.value = "";
	}
	if((name == "name") && (el.value == "") && (event == "blur"))
	{
		el.value = "Enter First Name";
	}

	if((name == "email") && (event == "focus") && (el.value == "Enter Email Address"))
	{
		el.value = "";
	}
	if((name == "email") && (el.value == "") && (event == "blur"))
	{
		el.value = "Enter Email Address";
	}
}

function initializeSubNav(el)
{
	var theEl = document.getElementsByClassName(el);
	var linkNode = "";
	var divNode = "";
	
	for(i=0;i< theEl.length; i++)
	{			
		for(j=0;j<theEl[i].childNodes.length;j++)
		{
			if(theEl[i].childNodes[j].tagName == "DIV")	
			{
				divNode = j;
			}
			
			if(theEl[i].childNodes[j].tagName == "A")	
			{
				linkNode = j;							
			}
		}
		
		storeAtts.push(["subUl" + i,theEl[i].childNodes[divNode].offsetHeight]);		
		
		if(navigator.userAgent.indexOf("MSIE") != -1)
		{
			
			theEl[i].childNodes[linkNode].setAttribute("href","javascript:toggleSubNav('subUl"+i+"','SubDiv"+i+"')");						
		}
		else
		{			
			theEl[i].childNodes[linkNode].setAttribute("href","#toggle");						
			theEl[i].childNodes[linkNode].setAttribute("onclick","toggleSubNav('subUl"+i+"','SubDiv"+i+"')");																									
		}	
		
		/* (Phillip: 29/6/2010)  I've changed the ID to SubDiv[i] (It was div[i]) because of a conflict with the product personalisation script... mumbles */				
		theEl[i].childNodes[linkNode].id = "SubDiv" + i;		
		
		if((document.getElementById("onHomepage") != null) && (theEl[i].className.indexOf("favCategory") != -1))	
		{			
			theEl[i].childNodes[divNode].style.height = theEl[i].childNodes[divNode].offsetHeight + "px";
			swap("SubDiv"+i);	
		}
		else
			theEl[i].childNodes[divNode].style.height = 0 + "px";	
		
		
		theEl[i].childNodes[divNode].id = "subUl" + i;		
	}
}	
	
function swap(el)
{
	var theImage = document.getElementById(el);		
	if(theImage.className == "m")	
	{	
		theImage.className = "mOn";			
	}
	else			
	{
		theImage.className = "m";
	}
}

function toggleSubNav(el,div)
{		
	var theId = document.getElementById(el);
	var elHeight = "";
	var inLoop = false;
	
	for(i=0;i<storeAtts.length;i++)	
	{
		if(storeAtts[i][0] == el)		
		{
			elHeight = storeAtts[i][1];
		}
	}
	
	for(i=0;i<inAction.length;i++)
	{
		if(inAction[i] == el)
		{
			inLoop = true;
		}
   }
	
	if(inLoop == false)
	{		
		if(parseInt(theId.style.height) == 0)
		{	
			swap(div);		
			inAction.push(el);
			expandUl(el,elHeight);					
		}
		else if(parseInt(theId.style.height) >= elHeight)	
		{
			swap(div);
			inAction.push(el);
			hideUl(el,elHeight);					
		}
	}
}

function expandUl(el,maxHeight)
{	
	var theId = document.getElementById(el);	
	var exists = false;
	var currentHeight = parseInt(theId.style.height);
	var steps;
			
	if(currentHeight < maxHeight)
	{
		if(currentHeight+10 >= maxHeight)	
		{
			steps = maxHeight - currentHeight;					
		}
		else
		{
			steps = 10;			
		}
		
		theId.style.height = (parseInt(theId.style.height) + steps) + "px";
		setTimeout("expandUl('"+el+"','"+maxHeight+"')",10);
	}
	
	if(currentHeight == maxHeight)
	{	
		for(i=0;i<inAction.length;i++)
		{
			if(inAction[i] == el)			
			{
				inAction.splice(i,1);					
			}
		}
	}
	
	for(i=0;i<expanded.length;i++)
	{
		if(expanded[i] == el)
		{
			exists = true;
		}
	}
	
	if(exists == false)
	{		
		expanded.push(el);	
	}

}

function hideUl(el,maxHeight)
{	
	var theId = document.getElementById(el);	

	var currentHeight = parseInt(theId.style.height);
		
	if(currentHeight > 0)
	{		
		if(currentHeight-10 >= 0)	
		{
			steps = 10;		
		}
		else
		{
			steps = 1;								
		}
		
		theId.style.height = (parseInt(theId.style.height) - steps) + "px";
		// setTimeout("hideUl('"+el+"','"+maxHeight+"')",1*0.5);
		setTimeout("hideUl('"+el+"','"+maxHeight+"')",10);	
	}

	if(currentHeight == 0)	
	{
		for(i=0;i<inAction.length;i++)
		{
			if(inAction[i] == el)					
			{
				inAction.splice(i,1);	
			}
		}
		
		for(i=0;i<expanded.length;i++)
		{
			if(expanded[i] == el)					
			{
				expanded.splice(i,1);									
			}
		}
	}						
}

function initCurrencyConverter()
{
	var converterTitle = document.getElementById("converterTitle");
	var curCanada = document.getElementById("can");
	var curAus = document.getElementById("aus");
	var curPound = document.getElementById("pound");
	var curEuro = document.getElementById("euro");
	var curYen = document.getElementById("yen");
	
	converterTitle.style.display = "block";
	
	curCanada.className = "curIcon";
	curCanada.onmouseover = function(){curShow('canOver')};
	curCanada.onmouseout = function(){curHide('canOver')};
	
	curAus.className = "curIcon";
	curAus.onmouseover = function(){curShow('ausOver')};
	curAus.onmouseout = function(){curHide('ausOver')};	
	
	curPound.className = "curIcon";
	curPound.onmouseover = function(){curShow('poundOver')};
	curPound.onmouseout = function(){curHide('poundOver')};		
	
	curEuro.className = "curIcon";	
	curEuro.onmouseover = function(){curShow('euroOver')};
	curEuro.onmouseout = function(){curHide('euroOver')};	
	
	curYen.className = "curIcon";
	curYen.onmouseover = function(){curShow('yenOver')};
	curYen.onmouseout = function(){curHide('yenOver')};		
}

function curShow(theId)
{
	if(document.getElementById(theId) != null)
	{
		document.getElementById(theId).style.display = "block";
	}
}
	
function curHide(theId)
{
	if(document.getElementById(theId) != null)
	{
		document.getElementById(theId).style.display = "none";
	}
}

function toggleAdd(el)
{
	if(el.id == "rbSameAdd")	
	{		
		document.getElementById("additional").style.display = "none";	
	}
	else if(el.id == "rbDiffAdd")	
	{		
		document.getElementById("additional").style.display = "block";
	}
}

function doSwftype(swftypeTag, swftypeSrc, cssSrc, swftypeWidth, swftypeHeight, txtUpper, txtSelect, resizeType, debug)
{
	var elClassName = "";

	if(swftypeTag.indexOf(".") != -1)
	{	
		elClassName = swftypeTag.substring(swftypeTag.indexOf(".")+1, swftypeTag.length);
		swftypeTag = swftypeTag.substring(0, swftypeTag.indexOf("."));
		if(swftypeTag.length==0)
		{
			swftypeTag=elClassName;
		}
	}		
	
	if((document.getElementsByTagName(swftypeTag) != "") || (document.getElementsByClassName(swftypeTag) != ""))
	{	
		if(document.getElementsByTagName(swftypeTag).length > 0)											
			var theSwftypeTag = document.getElementsByTagName(swftypeTag);												
		else if(document.getElementsByClassName(swftypeTag).length > 0 )
			var theSwftypeTag = document.getElementsByClassName(swftypeTag);			
	
		if(theSwftypeTag != null)
		{
			for(var i=0; i<theSwftypeTag.length; i++)
			{			
				var obj = theSwftypeTag[i];
				var tagName = obj.tagName;	
				var className= obj.className;	
				
				if(obj.className.indexOf(elClassName) != -1)
				{
					className = obj.className;
					obj.setAttribute('id', 'Swftype'+swftypeTag+i);			
					if(obj.innerHTML != null)
					{
						/* Swftype Content */
						var pageTxt = obj.innerHTML;			
						// search and add ' in classNames 
						if(pageTxt.indexOf('class=') != -1){			
							var firstQuote = (pageTxt.indexOf('class=') + 6);
							var spanCloseTag = pageTxt.indexOf('>');
							var className = pageTxt.substr(firstQuote, (spanCloseTag - firstQuote));				
							if(pageTxt.charAt(firstQuote) != '"'){
								pageTxt = pageTxt.replace(className,'"'+className+'"');
							}
						}			
						var printAlt = document.createElement("span");				
						// printAlt.setAttribute("class", "printSwfType");   
						printAlt.className = "printSwfType";				
						printAlt.innerHTML = pageTxt;   
						obj.parentNode.insertBefore(printAlt, obj);					
						pageTxt = pageTxt.replace(/"/g, "'");
						pageTxt = pageTxt.replace(/\+/g, "&#43;");
						pageTxt = pageTxt.replace(/%/g, "&#37;");	
						pageTxt = pageTxt.replace(/&/g, "{and}");	
					}
					else
					{
						var pageTxt = "DEFAULT";
					}
				}
				/* */
				/* swfobject2 */
				var flashvars = {};
				flashvars.cssURL = cssSrc;
				flashvars.txtUpper = txtUpper;
				flashvars.tagName = tagName;
				flashvars.className = className;
				flashvars.txtWidth = swftypeWidth;
				flashvars.txtHeight = swftypeHeight;
				flashvars.txtSelect = txtSelect;
				flashvars.resizeType = resizeType;
				flashvars.debug = debug;
				var params = {};
				params.allowScriptAccess = "always";
				params.menu = "false";
				params.wmode = "transparent";
				var attributes = {};
				swfobject.embedSWF(swftypeSrc + "?pageTxt=" + pageTxt + "&swftypeID=Swftype"+swftypeTag+i, "Swftype" + swftypeTag + i, swftypeWidth, swftypeHeight, "8", "false", flashvars, params, attributes);			
			}
		}
	}

}

/* Swftype Resize */
function resizeSwftype(SwftypeId, textHeight, textWidth)
{		
	document.getElementById(SwftypeId).style.width = textWidth + "px";	
	document.getElementById(SwftypeId).style.height = textHeight + "px";
}

document.getElementsByClassName = function(elClassName)
{
    var arrayList = new Array();
    var elements = document.getElementsByTagName("*");
    for(var i = 0;i < elements.length;i++)
	 {
        if(elements[i].className.indexOf(" ") >= 0)
		  {
            var classes = elements[i].className.split(" ");
            for(var j = 0;j < classes.length;j++)
				{
               if(classes[j] == elClassName)
					{
                  arrayList.push(elements[i]);
					}
            }
        }
			else if(elements[i].className == elClassName)
			{
				arrayList.push(elements[i]);
			}		
    }
    return arrayList;
}

