function thisMovie(movieName) {
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	return (isIE) ? window[movieName] : document[movieName];
}

function fileSelect() {
	flashPlayer = thisMovie("fpUploader");
	flashPlayer.doFileSelect();
	// alert("fileSelect");
}

function doUpload() {
	if ( document.getElementById("uploadFileList").firstChild ) {
		document.getElementById("btnAddToBasket").value="Please wait - uploading";
		document.getElementById("btnAddToBasket").disabled=true;
		flashPlayer = thisMovie("fpUploader");
		flashPlayer.setQuantity(document.getElementById("quantity").value);
		flashPlayer.setProduct(document.getElementById("productCode").value);
		flashPlayer.doUploadFiles();
	} else {
		alert("You have no files selected - please pick some images to order.");
	}
}

function clearInnerHTML(obj) {
	// so long as obj has children, remove them
	while(obj.firstChild)
		obj.removeChild(obj.firstChild);
}

function doneUpload(txtFilename,remaining) {
	document.getElementById("up_"+txtFilename+"_fn").style.backgroundColor="#e0ffe0";
	var txtBlock=document.createTextNode(txtFilename+" sent");
	clearInnerHTML(document.getElementById("up_"+txtFilename+"_fn"));
	document.getElementById("up_"+txtFilename+"_fn").appendChild(txtBlock);

	if ( remaining == 0 ) {
		document.location.href="/cart/full.php";
	}
}

function doProgressFail(txtFilename) {
	document.getElementById("up_"+txtFilename+"_st").firstChild.nodeValue="Upload failed";
}

function doProgressStart(txtFilename) {
	document.getElementById("up_"+txtFilename+"_st").firstChild.nodeValue="Waiting";
}

function doProgress(txtFilename,sentBytes,totalBytes) {
	var percentValue=Math.round((sentBytes/totalBytes)*100)+"%";
	var txtBlock=document.createTextNode(txtFilename+" "+percentValue);
	clearInnerHTML(document.getElementById("up_"+txtFilename+"_fn"));
	document.getElementById("up_"+txtFilename+"_fn").appendChild(txtBlock);
}

function doneSelect(txtFilename) {
	var tdFilenameItem=document.createElement('span');
	tdFilenameItem.id="up_"+txtFilename+"_fn";
	tdFilenameItem.className="upFilename";
	var tdFilenameA=document.createElement('a');
	tdFilenameA.id="a_"+txtFilename+"_fn";
	tdFilenameA.href="#remove"; // remove

	var txtFilename=document.createTextNode(txtFilename+" ");
	var txtA=document.createTextNode("X");

	tdFilenameItem.appendChild(txtFilename);
	tdFilenameA.appendChild(txtA);
	tdFilenameItem.appendChild(tdFilenameA);

	document.getElementById("uploadFileList").appendChild(tdFilenameItem);
}

function clearSelect() {
	clearInnerHTML(document.getElementById("uploadFileList"));
}

