var SizeArray			= Array(4);
SizeArray[0]			= "XSmall";
SizeArray[1]			= "Small";
SizeArray[2]			= "Medium";
SizeArray[3]			= "Large";

function SetSize(SelectedSize)
{

for (i=0; i<SizeArray.length; i++)
{
SizeBox				= document.getElementById(SizeArray[i]);
SizeButton			= document.getElementById("Button" + SizeArray[i]);

if ((SizeBox) && (SizeBox != SelectedSize))
{
SizeBox.value		= 0;
SizeButton			= SizeButton.getElementsByTagName("a");
SizeButton[0].style.backgroundPosition = "0px -25px";
}

}

document.getElementById(SelectedSize).value	= 1;
SizeButton			= document.getElementById("Button" + SelectedSize).getElementsByTagName("a");
SizeButton[0].style.backgroundPosition = "0 0";
}

function AddCart()
{
URL					= "/AddToCart.php";
URL					+= "?ProductID=" + document.getElementById("ProductID").value;

if (document.getElementById("AvailableSizes"))
{
FoundSize			= 0;

URL					+= "&Size=";

for (i=0; i<SizeArray.length; i++)
{
SizeBox				= document.getElementById(SizeArray[i]);

if ((SizeBox) && (SizeBox.value == 1))
{
URL					+= SizeArray[i];
FoundSize			= 1;
break;
}

}

if (!FoundSize)
{
alert("Please select a size");
}

else
{
ajax.requestFile	= URL;
ajax.onCompletion	= RunAJAX;
ajax.runAJAX();
}

}

else
{
ajax.requestFile	= URL;
ajax.onCompletion	= RunAJAX;
ajax.runAJAX();
}

}

function AddedToCart(Quantity, Size, Product, CartTotal)
{
addElement("AddedItem");

AddedItemDiv	= document.getElementById("AddedItem");

AddedItemText	= "<p>" + Quantity + " x " + Product + " ";

if (Size)
{
AddedItemText	+= "(" + Size + ") ";
}

AddedItemText	+= "<br />\nhas been added to your basket</p>\n";
AddedItemText	+= "<ul>\n";
AddedItemText	+= "<li><a href=\"/view_basket.php\">View Basket</a></li>\n";
AddedItemText	+= "<li><a href=\"javascript:removeElement()\">Close</a></li>\n";
AddedItemText	+= "</ul>\n";

document.getElementById("BasketItems").innerHTML	= "<a href=\"/view_basket.php\" title=\"(" + CartTotal + ")\">(" + CartTotal + ")</a>";


AddedItemDiv.innerHTML	= AddedItemText;
}

function SubmitForm(FormName)
{
document.getElementById(FormName).submit();
}

function Remove(CartItem)
{
QuanBox		= "Quantity" + CartItem;
document.getElementById(QuanBox).value = "0";

document.getElementById("ProcessType").value = "remove";
SubmitForm("Basket");
}

function UpdateCart()
{
document.getElementById("ProcessType").value = "update";
SubmitForm("Basket");
}

function array_search( needle, haystack, strict ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
    // *     returns 1: 'surname'
 
    var strict = !!strict;
 
    for(var key in haystack){
        if( (strict && haystack[key] === needle) || (!strict && haystack[key] == needle) ){
            return key;
        }
    }
 
    return false;
}

function ProductImages()
{
ProductImageHolder	= document.getElementById("ProductImage").getElementsByTagName("img");
ProductImageSrc		= ProductImageHolder[0].src;
ImageSrc			= ProductImageSrc.split("/");
ImageSrc			= ImageSrc[ImageSrc.length-1];

ImageLocation		= parseInt(array_search(ImageSrc, ImageNames)) + 1;

if (ImageLocation >= ImageNames.length)
{
ImageLocation		= 0;
}

ProductImageHolder[0].src		= "/images/products/large/" + ImageNames[ImageLocation];
}

function NextTab()
{
TabContent.cycleit("next");
}