function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}

function navigateToAnchor(){
   var anchor = document.getElementById("anchor");
   if (anchor != null) {
      if (anchor.value != ""){
         location.hash = anchor.value;
      }
   }
}

function incrementQtyBox() {
	var x=document.forms["productInfo"]["productInfo:qtybox"].value;
	var y = Number(x);
	if (y==null) {
		y=0;
	}
	y=y+1;
	document.forms["productInfo"]["productInfo:qtybox"].value=y;
}

function decrementQtyBox() {
	var x=document.forms["productInfo"]["productInfo:qtybox"].value;
	var y = Number(x);
	if (y==null) {
		y=0;
	} else {
		if (y>0) {
			y=y-1;
		}
	}
	document.forms["productInfo"]["productInfo:qtybox"].value=y;
}

function incrementQtyBoxProductList(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) {
		targ = e.target;
	} else if (e.srcElement) {
		targ = e.srcElement;
	}
	if (targ.nodeType == 3) {
		// defeat Safari bug
		targ = targ.parentNode;
	}
	var targId=targ.id;
	var newTargId=targId.replace("incrementButton","qtybox");
	var x=document.forms["productList"][newTargId].value;
	var y = Number(x);
	if (y==null) {
		y=0;
	}
	y=y+1;
	document.forms["productList"][newTargId].value=y;
}

function decrementQtyBoxProductList(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) {
		targ = e.target;
	} else if (e.srcElement) {
		targ = e.srcElement;
	}
	if (targ.nodeType == 3) {
		// defeat Safari bug
		targ = targ.parentNode;
	}
	var targId=targ.id;
	var newTargId=targId.replace("decrementButton","qtybox");
	var x=document.forms["productList"][newTargId].value;
	var y = Number(x);
	if (y==null) {
		y=0;
	} else {
		if (y>0) {
			y=y-1;
		}
	}
	document.forms["productList"][newTargId].value=y;
}

function checkZoomify() {
	var playerVersion = swfobject.getFlashPlayerVersion();
	if (playerVersion.major == 0) {
		var url = window.location.toString();
		var startpos = url.lastIndexOf("catalogueCode=");
		if (startpos >= 0) {
			var catCode = url.substring(startpos+14);
			if (catCode != null) {
				var container = document.getElementById("theMovie");
				imagetag = document.createElement("img");
				imagetag.id = catCode;
				imagetag.height = 300;
				imagetag.width = 300;
				imagetag.src = "https://static.prolog.co.uk/client/ecom_tearfund/images/" + catCode + ".jpg";
				container.parentNode.replaceChild(imagetag,container);
			}
		}
		var youtubeContainer = document.getElementById("youtubeSection");
		divtag = document.createElement("div");
		youtubeContainer.parentNode.replaceChild(divtag,youtubeContainer);
	}
}
