
	//functions.js

	//Function to set a loading status.
	function setStatus (theStatus, showImgID){
		theobj = document.getElementById(showImgID);
		if (theobj){
			theobj.oldInnerHTML = theobj.innerHTML;
			theobj.innerHTML = "<div class=\"bold\">" + theStatus + "</div>";
		}
	}
	
	function resetStatus (showImgID){
		
		theobj = document.getElementById(showImgID);
		if (theobj&&theobj.oldInnerHTML){
			theobj.innerHTML = theobj.oldInnerHTML;
		}
	}
	
	function changesize (img, sml, showImgID){
		
		//The display a loading message to the user.
		//alert("changing: "+sml+" imgid: "+showImgID);
		theobj = document.getElementById(showImgID);
		if (theobj){
			setStatus ("Resizing...",showImgID);
			var loc = "thumb.php?img=" + img + "&sml=" + sml + "&imageID=" + showImgID;
			processajax (showImgID,loc);
		}
	}
	
	//Function to determine when the process_upload.php file has finished executing.
	function doneloading(theframe, thefile, showImgID, imagesize){	

		// resize the image		
		if (imagesize!=null) {
			// 'w' - website image size
			// 'd' - design image thumbnail
			// 'h' - homepage image size	
			// 'm' - midsized image 
			theframe.changesize (thefile, imagesize, showImgID); 
			
			// if this is a design image also create a large/fulllarge image
			if (imagesize=='d') {
				theframe.changesize (thefile, 'l', showImgID); 
				theframe.changesize (thefile, 'f', showImgID); 				
			}
		}
		
		// always create a small thumbnail - for backend
		theframe.changesize (thefile, 's', showImgID); // small thumbnail

			
		//var theloc = "showimg.php?thefile=" + thefile + "&showImgID=" + showImgID;
		//theframe.processajax (showImgID, theloc);
	}

	function uploadimg (theform, showImgID){
		//Submit the form.
		theform.submit();
		//Then display a loading message to the user.
		setStatus ("Loading...",showImgID);

	}
	
	function validateForm(formID) {
	
		// form is valid unless it fails a check
		valid = true;
		validmsg = "";
	
		for (i=document.forms[formID].elements.length-1; i>-1; i--) {

			switch (document.forms[formID].elements[i].validation) {
				
				case "NONEMPTY": 
					if (document.forms[formID].elements[i].value == "") {
						validmsg = document.forms[formID].elements[i].label + " requires a value.\n";
						valid = false;
					}
					break;
			
				default:
					// no validataion
					break;
			}

						
		}
		
		// if validmsg non-empty - pop-up an alert
		if (validmsg != "") alert(validmsg);
		
		// should we proceed?
		return valid;
		
	}
	
	function emailQuery(sItem) {

	  // SET MESSAGE VALUES
	  var to = "sara@saxum.co.uk";
	  var subject = "Direct Enquiry: " + sItem;
	  var body = 
		  "Direct Enquiry re: \'" + sItem + "\'\n\n\n"  +
		  "Enquiry Details: (Please Complete)\n\n\n\n\n\n" +
		  "Your Name and Contact Details: (Please Complete)\n\n\n\n";
	
	  // BUILD MAIL MESSAGE COMPONENTS 
	  var doc = "mailto:" + to + 
		  "&subject=" + escape(subject) + 
		  "&body=" + escape(body); 
	
	  // POP UP EMAIL MESSAGE WINDOW
	  window.location = doc;
	}
	
	function swapDesignImage(theImageID) {
	
		// hide text
		var designText = MM_findObj('designtext');
		designText.style.visibility = "hidden";
		designText.style.height = "0px";		

		// get images and anchors
		var designImage = MM_findObj('designimage');
		var designHREF = MM_findObj('designhref');
		var curImage = MM_findObj(theImageID);
		var curImageURL = curImage.src.replace(/_thd./,"_thl.");
		var curImageHREF = curImage.src.replace(/_thd./,".");
		
		// swap images
		designImage.src = curImageURL;
		designHREF.href = "fullimage.php?image=" + curImageHREF;
	
	}

	function showDesignText() {
		
		var designImage = MM_findObj('designimage');
		designImage.src = "";
		var designText = MM_findObj('designtext');
		designText.style.visibility = "visible";
	
	}

