function increase_quantity(myname,dosub,button)
{
	var thing=myGetElementById(myname);
	thing.value=parseInt(thing.value);
	if(thing.value < 1 || isNaN(thing.value))
	{
		thing.value=0;
	}
	thing.value++;
	// add in action
	if(dosub==1)
	{
		var a = document.createElement('input');
		a.setAttribute('type', 'hidden');
		a.setAttribute('value', button);
		a.setAttribute('name', 'action');
		document.forms['basket_form'].appendChild(a);
		document.forms['basket_form'].submit();
	}
}

function decrease_quantity(myname,dosub,button)
{
	var thing=myGetElementById(myname);
	thing.value=parseInt(thing.value);
	if(thing.value > 0)
	{
		thing.value--;
	}
	else
	{
		thing.value=0;
	}
	if(dosub==1)
	{
		var a = document.createElement('input');
		a.setAttribute('type', 'hidden');
		a.setAttribute('value', button);
		a.setAttribute('name', 'action');
		document.forms['basket_form'].appendChild(a);
		document.forms['basket_form'].submit();
	}
}

function remove_item(myname,button)
{
	var thing=myGetElementById(myname);
	thing.value=parseInt(thing.value);
	thing.value=0;

	// add in action
	var a = document.createElement('input');
	a.setAttribute('type', 'hidden');
	a.setAttribute('value', button);
	a.setAttribute('name', 'action');
	document.forms['basket_form'].appendChild(a);
	document.forms['basket_form'].submit();
}

function doPopUp(myUrl,winWidth,winHeight)
{
	newWindow=window.open(myUrl,'productImageDetail','height='+winHeight+',width='+winWidth+',toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
	newWindow.resizeTo(winWidth+2,winHeight+30);
	newWindow.focus();
}

// check what key was entered to trigger the form submission and if necessary add
// form variable
function check_keycode(myname)
{
	var keycode = window.event.keyCode;
	function kH(e)
	{
		var pK = e ? e.which : window.event.keyCode;
		return pK != 13;
	}
}

function genUniqID()
{
	var id = 'u_';
	for(x=0; x < 30; x++)
	{
		id = id + String.fromCharCode(Math.floor(Math.random() * 26) + 65);
	}
	return id;
}

function myGetElementById(divID)
{
	if( document.getElementById )
	{
    		return document.getElementById(divID);
    	}
	if( document.all )
	{
		return document.all[divID];
	}
	if( !oDoc ) { oDoc = document; }
	if( document.layers ) {
		if( oDoc.layers[divID] ) { return oDoc.layers[divID]; }
		else
		{
			//repeatedly run through all child layers
			for( var x = 0, y; !y && x < oDoc.layers.length; x++ )
			{
			//on success, return that layer, else return nothing
				y = getRefToDiv(divID,oDoc.layers[x].document);
			}
			return y;
		}
	}
	return false;
}

function showDiv(divID_as_a_string)
{
  	//get a reference as above ...
	myReference = getRefToDiv(divID_as_a_string);
	if( !myReference )
	{
		window.alert('Nothing works in this browser');
		return; //don't go any further
	}
	//now we have a reference to it
	if( myReference.style ) {
		//DOM & proprietary DOM
		myReference.style.visibility = 'visible';
	}
	else
	{
		//layers syntax
		myReference.visibility = 'show';
	}
}

function hideDiv(divID_as_a_string)
{
  	//get a reference as above ...
	myReference = getRefToDiv(divID_as_a_string);
	if( !myReference )
	{
		window.alert('Nothing works in this browser');
		return; //don't go any further
	}
	//now we have a reference to it
	if( myReference.style ) {
		//DOM & proprietary DOM
		myReference.style.visibility = 'hidden';
	}
	else
	{
		//layers syntax
		myReference.visibility = 'hide';
	}
}


Array.prototype.find = function (s)
{
	for(var i=0;i<this.length;i++) if(this[i] == s) return true;
	return false;
};
