// JavaScript Document
/* ---------------------------------------------------- */
function validateForm(whichform){
	ret=true;
	for(var i=0; i<whichform.elements.length; i++){
		var element = whichform.elements[i];
		
		
		if(element.className.indexOf("required")!= -1){
			if(whichform.elements[i].value=="") ret=false;
		}
		
	}
 
 	if(!ret) alert("Please fill in all of the required fields");
 	return ret;
	
}
/* ----------------------------------------------------------- */
function changeColour(productID,retURL){
	// this routine is used in the more information section when a user selects a colour from the select box
	// ************************ USED IN ROUTINES FROM THE PRODUCT.PHP CLASS ***************************
	colourID = document.productInfo.colour.value;
	self.location = retURL + "?cid=" + colourID + "&id=" + productID;
	return false;
}
function changeSize(productID,retURL){
	colourID = document.productInfo.colour.value;
	sizeID = document.productInfo.size.value;
	self.location = retURL + "?cid=" + colourID + "&id=" + productID + "&sid=" + sizeID;
	return false;	
}
function updateCart(retURL,cartID){
	value = "document.cart.tval" + cartID + ".value";
	value2 = eval(value);
	self.location = retURL + "?update="+cartID+"&qty="+value2;
	return false;
}
function updateCart2(e,retURL,cartID){
	if(window.event) // IE
  { keynum = e.keyCode; }
  	else if(e.which) // Netscape/Firefox/Opera
  { keynum = e.which; }
  
  if(keynum==13) updateCart(retURL,cartID);
}
function showLargeImage(source,wid,hgt){
	sourceID = source;
	NewWindow = window.open("Image","LargeImage","resizable=yes,width="+wid+",height="+hgt+",resizable=no");
	NewWindow.location.href = "fullimage.html";	
	if (NewWindow.opener == null) NewWindow.opener = window;
	NewWindow.setfocus();
	
}
/* ===============================================================*/


/* this function gives the user the ability to scroll an serires of imagse to the left */
/* element ID , restart position (usually -step) , interval between each iteration (usually 60), width of image , no of images */
function moveElement(elementID, sponsorleft, interval, step, pause , qty){

	if(!document.getElementById) return false;
	if(!document.getElementById(elementID)) return false;
	var elem = document.getElementById(elementID);
	
	if(elem.movement) clearTimeout(elem.movement);
	
	if(!elem.style.left) elem.style.left="0px";
	if(!elem.style.top) elem.style.top="0px";
	
	
	var xpos = parseInt(elem.style.left);
	var ypos = parseInt(elem.style.top);
	var repeat = "moveElement('" + elementID + "'," + sponsorleft + "," + interval + "," + step + "," + pause + "," + qty + ")";
	
	
	if(document.getElementById("shadow")){
		var sd = document.getElementById("shadow").style;
		if(sd.display=="block") {
			setTimeout(repeat,interval); /* interval is self explanitory */
			return false;
		}
	}
	
	endvalue = (qty * step);
	
	if(sponsorleft < -endvalue) { /* this value is 1*width less than all the widths added together */
				sponsorleft=-step;
				xpos=0;
				elem.style.left = "0px";
				var repeat = "moveElement('" + elementID + "'," + sponsorleft + "," + interval + "," + step + "," + pause + "," + qty + ")";
				setTimeout(repeat,interval);
				return false
		}
	
	if(xpos == sponsorleft) {
		sponsorleft = sponsorleft - step; /* step is the image width */
		var repeat = "moveElement('" + elementID + "'," + sponsorleft + "," + interval + "," + step + "," + pause + "," + qty + ")";
		setTimeout(repeat,pause);
		return false
	}
	
	if(xpos > sponsorleft) {
		var dist = Math.ceil((xpos - sponsorleft)/10);
		xpos=xpos-dist;
	}
	elem.style.left = xpos + "px";
	
	elem.movement = setTimeout(repeat,interval);
}

/* ===============================================================*/


/* this function sets the width to a style */
function setWidth(elementID,width){
	var elem = document.getElementById(elementID);
	elem.style.width= width +"px";
}














