function remove_product(loc)
{
	var accept= confirm("Are you sure you want to delete this product?!");
  		if( accept== true)
	{
		 window.location.href = loc;
	}
	else
	{
		return false;
	}
}

function confirm_order(loc)
{
	var accept= confirm("Are you sure you want to confirm this order?!");
  		if( accept== true)
	{
		 window.location.href = loc;
	}
	else
	{
		return false;
	}
}

function empty_basket(loc)
{
	var accept= confirm("Are you sure you want to empty your basket?!");
  		if( accept== true)
	{
		 window.location.href = loc;
	}
	else
	{
		return false;
	}
}

function reorder(loc)
{
	var accept= confirm("Are you sure you want to re-order?!\n\n(Note: Clicking OK will add all the items from this order to your current basket)");
  	if( accept== true)
	{
		 window.location.href = loc;
	}
	else
	{
		return false;
	}
}

function personalMessage(dropdown)
{
	
	if(!dropdown)
	{
		var elem = document.getElementById("product_message");
		elem.checked = true;
	}
	else
	{
		var elem = document.getElementById("product_message");
		elem.value = 0;
	}
}

function AddToBookmarks()
{
	title = "School Stickers - Creating 50 Million Smiles A Year"; 
	url = "http://www.schoolstickers.co.uk";
	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) 
	{ 
		alert('If you are using a MAC please press Command + D to bookmark this page. If you are using a PC please press CTRL+D');
		return true; 
	}
	else
	{
		alert('If you are using a MAC please press Command + D to bookmark this page. If you are using a PC please press CTRL+D');
	}
}  

function toggleDisplay(elem)
{
	var display =(elem.style.display == 'none') ? 'block' : 'none';
	elem.style.display = display;
}

function toggleClass(elem)
{
	var current_class = elem.className.split(' ');
	var new_class =(current_class[0] == 'active') ? 'inactive' : 'active';
	elem.className = new_class + ' ' + current_class[1];
}


var lastActive;
var expanding = new Array();
var maxHeight = 432;
var minHeight = 24;

function accordian(item) {

	if(item != null) {

		if(lastActive != null && lastActive.id != item.id && lastActive.className.match(" active")) {
			accordian(lastActive);
			//lastActive.className = lastActive.className.replace(" active", " inactive");
			//expanding[expanding.length] = {n:oH, o:nH, i:lastActive, d:false};
		}

		// TOGGLE THE ACTIVE VALUE
		if(item.className.match(" active")) {
			item.className = item.className.replace(" active", " inactive");
			var nH = minHeight;
			var oH = maxHeight;
		} else {
			item.className = item.className.replace(" inactive", " active");
			var nH = maxHeight;
			var oH = minHeight;
		}

		expanding[expanding.length] = {n:nH, o:oH, i:item, d:true};

		lastActive = item;

		doExpand = true;
		expand();
	}
}

var doExpand = true;

function expand() {

	doExpand = false;
	var stepInc = 3;

	for(var i = 0; i < expanding.length; i++) {

		var curr = expanding[i];

		if(curr.d == false) {

			//alert(curr.o + " > " + curr.n);
			//alert(curr.i.style.overflow);

			doExpand = true;
			if(curr.o > curr.n) {
				curr.o -= Math.ceil((curr.o - curr.n)/stepInc);
				curr.i.style.height = curr.o + "px";
				//curr.i.setAttribute("style", "height: " + curr.o + "px");
				curr.i.style.height = curr.o + "px";
			} else if(curr.o < curr.n) {
				curr.o += Math.ceil((curr.n - curr.o)/stepInc);
				curr.i.style.height = curr.o + "px";
				//curr.i.setAttribute("style", "height: " + curr.o + "px");
//				alert(var_export(curr.i.getAttribute("style")));
//				alert(curr.i.style.height);
			} else {
				curr.d = true;
				if(curr.r) {
					accordianEmpty(false, curr.i);
				}
			}
		}
	}

	if(doExpand) setTimeout("expand()", 50);

}

var openProduct = true;

function toggleByProduct() {
	var bp = getElementsByClass(document.getElementById("product-nav"), "by-product", "li");
	for(var i = 0; i < bp.length; i++) {
		if(openProduct) {
			bp[i].className = bp[i].className.replace(" inactive", " active");
			maxHeight = bp[i].parentNode.offsetHeight + minHeight + 4;

			//if(lastActive != null && maxHeight < lastActive.offsetHeight) {
			//	maxHeight = lastActive.offsetHeight;
			//}
		} else {
			bp[i].className = bp[i].className.replace(" active", " inactive");
			maxHeight = bp[i].parentNode.offsetHeight + minHeight + 4;
			//if(lastActive != null && maxHeight > lastActive.offsetHeight) {
			//	maxHeight = lastActive.offsetHeight;
			//}
		}
	}
	openProduct = !openProduct;
	if(lastActive != null) {
		expanding[expanding.length] = {n:maxHeight, o:lastActive.offsetHeight, i:lastActive, d:true};
	}
	expand();
	//reExpand();
}

var openSubject = true;

function toggleBySubject() {
	var bp = getElementsByClass(document.getElementById("product-nav"), "by-subject", "li");
	for(var i = 0; i < bp.length; i++) {
		if(openSubject) {
			bp[i].className = bp[i].className.replace(" inactive", " active");
			maxHeight = bp[i].parentNode.offsetHeight + minHeight + 4;
//			if(lastActive != null && maxHeight < lastActive.offsetHeight) {
//				maxHeight = lastActive.offsetHeight;
//			}
		} else {
			bp[i].className = bp[i].className.replace(" active", " inactive");
			maxHeight = bp[i].parentNode.offsetHeight + minHeight + 4;
//			if(lastActive != null && maxHeight > lastActive.offsetHeight) {
//				maxHeight = lastActive.offsetHeight;
//			}
		}
	}
	openSubject = !openSubject;
	if(lastActive != null) {
		expanding[expanding.length] = {n:maxHeight, o:lastActive.offsetHeight, i:lastActive, d:true};
	}
	expand();
	//reExpand();
}

function getElementsByClass(where, className, tagName, limit) {

	if(tagName == null) tagName = '*';

	var elems = new Array();
	var elCount = 0;
	var all = where.getElementsByTagName(tagName);

	for(var i = 0; i < all.length; i++) {
		if(all[i].className.match(className) != null) {
			if(limit == null) {
				elems[elCount] = all[i];
				elCount++;
			} else if(elems.length == 0) {
				elems = all[i];
			}
		}
	}

	return elems;
}

function var_export ( mixed_expression, bool_return ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Philip Peterson
    // -    depends on: echo
    // *     example 1: var_export(null);
    // *     returns 1: null

    var __pad_lines = function ( x ) {
        return x.split("\n").join("\n  ");
    };

    var retstr = "";

    if(mixed_expression instanceof Array) {
        var iret = "";
        for(i in mixed_expression) {
            iret=iret+"\n"+var_export(i,true)+" => "+var_export(mixed_expression[i], true)+",";
        }
        retstr = "array ("+__pad_lines(iret)+"\n)";
    } else if( mixed_expression === null) {
        retstr = "NULL";
    } else {
        retstr = (!isNaN( mixed_expression )) ? mixed_expression : "'" + mixed_expression.replace('/(["\'\])/g', "\\$1").replace('/\0/g', "\\0") + "'";
    }

    if(bool_return != true) {
        alert(retstr);
        return null;
    }
    else {
        return retstr;
    }
}

$(document).ready(function() {
	$('#date-ordered-start').calendar();
	$('#date-ordered-end').calendar();
});

/************************************************************************************************************
(C) www.dhtmlgoodies.com, November 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/
	
var slideTimeBetweenSteps = 30;	// General speed variable (Lower = slower)


var scrollingContainer = false;
var scrollingContent = false;
var containerHeight;
var contentHeight;	

var contentObjects = new Array();
var originalslideSpeed = false;
function slideContent(containerId)
{
	var topPos = contentObjects[containerId]['objRef'].style.top.replace(/[^\-0-9]/g,'');
	topPos = topPos - contentObjects[containerId]['slideSpeed'];
	if(topPos/1 + contentObjects[containerId]['contentHeight']/1<0)topPos = contentObjects[containerId]['containerHeight'];
	contentObjects[containerId]['objRef'].style.top = topPos + 'px';
	setTimeout('slideContent("' + containerId + '")',slideTimeBetweenSteps);
	
}

function stopSliding()
{
	var containerId = this.id;
	contentObjects[containerId]['slideSpeed'] = 0;	
}

function restartSliding()
{
	var containerId = this.id;
	contentObjects[containerId]['slideSpeed'] = contentObjects[containerId]['originalSpeed'];
	
}
function initSlidingContent(containerId,slideSpeed)
{
	scrollingContainer = document.getElementById(containerId);
	scrollingContent = scrollingContainer.getElementsByTagName('DIV')[0];
	
	scrollingContainer.style.position = 'relative';
	scrollingContainer.style.overflow = 'hidden';
	scrollingContent.style.position = 'relative';
	
	scrollingContainer.onmouseover = stopSliding;
	scrollingContainer.onmouseout = restartSliding;
	
	originalslideSpeed = slideSpeed;
	
	scrollingContent.style.top = '0px';
	
	contentObjects[containerId] = new Array();
	contentObjects[containerId]['objRef'] = scrollingContent;
	contentObjects[containerId]['contentHeight'] = scrollingContent.offsetHeight;
	contentObjects[containerId]['containerHeight'] = scrollingContainer.clientHeight;
	contentObjects[containerId]['slideSpeed'] = slideSpeed;
	contentObjects[containerId]['originalSpeed'] = slideSpeed;
	
	slideContent(containerId);
	
}

function addNavFields(elem)
{
	// IE specific broken way
	var count = document.getElementsByTagName("tr");
	count = count.length;
	try 
	{
		var trelement = document.createElement('<tr>');
		
		var labelelement = document.createElement('<input id="last_nav_item" type="text" style="width: 100px;" name="data['+count+'][label]" value=""/>');
		var labeltdelement = document.createElement('<td>');
		
		var urlelement = document.createElement('<input type="text" name="data['+count+'][url]" value=""/>');
		var urltdelement = document.createElement('<td>');
		
		var positionelement = document.createElement('<input type="text" style="width: 20px;" maxlength="2" name="data['+count+'][position]" value=""/>');
		var positiontdelement = document.createElement('<td>');
		
		var onlineelement = document.createElement('<input type="text" style="width: 20px;" maxlength="2" name="data['+count+'][online]" value=""/>');
		var onlinetdelement = document.createElement('<td>');
		
		var activeelement = document.createElement('<input type="text" style="width: 75px;" name="data['+count+'][active_area]" value=""/>');
		var activetdelement = document.createElement('<td>');
	} 
	catch (e) 
	{ //Standards way
		var labelelement = document.createElement("input");
		labelelement.setAttribute("name", "data["+count+"][label]");
		labelelement.setAttribute("type", "text");
		labelelement.setAttribute("style", "width: 100px;");
		
		var urlelement = document.createElement("input");
		urlelement.setAttribute("name", "data["+count+"][url]");
		urlelement.setAttribute("type", "text");
		
		var positionelement = document.createElement("input");
		positionelement.setAttribute("name", "data["+count+"][position]");
		positionelement.setAttribute("type", "text");
		positionelement.setAttribute("style", "width: 20px;");
		positionelement.setAttribute("maxlength", "2");
		
		var onlineelement = document.createElement("input");
		onlineelement.setAttribute("name", "data["+count+"][online]");
		onlineelement.setAttribute("type", "text");
		onlineelement.setAttribute("style", "width: 20px;");
		onlineelement.setAttribute("maxlength", "2");
		
		var activeelement = document.createElement("input");
		activeelement.setAttribute("name", "data["+count+"][active_area]");
		activeelement.setAttribute("type", "text");
		activeelement.setAttribute("style", "width: 75px;");
		
		var labeltdelement = document.createElement('td');
		var urltdelement = document.createElement('td');
		var positiontdelement = document.createElement('td');
		var onlinetdelement = document.createElement('td');
		var activetdelement = document.createElement('td');
		
		var trelement = document.createElement('tr');
	}
	
	labeltdelement.appendChild(labelelement);
	urltdelement.appendChild(urlelement);
	positiontdelement.appendChild(positionelement);
	onlinetdelement.appendChild(onlineelement);
	activetdelement.appendChild(activeelement);
	
	trelement.appendChild(labeltdelement);
	trelement.appendChild(urltdelement);
	trelement.appendChild(positiontdelement);
	trelement.appendChild(onlinetdelement);
	trelement.appendChild(activetdelement);
	
	// Insert the element into the document.
	$(elem).append(trelement);
};

