	var refreshPage = true;

	function adminPriceImage(imageNumb){
		document.forms.view_order.image.value=imageNumb
			document.forms.view_order.submit();
	}

	function adminManualImagePrice(orderNumb, imageNumb){
		var price = 0;
		price = prompt("Enter new price for image " + imageNumb, "");
		if (price!=0 && price!=null) {	
			var command = "data.svt?viewpage=admin/view_order.jsp&info=&order_id="+orderNumb+"&submit=Change&image="+imageNumb+"&price="+price;
			window.location.href = command; 
		}
	}

	function resetMask(){
		if (document.forms.list_orders.orderby.value=="order_date" || document.forms.list_orders.orderby.value=="order_date desc" ) {
			document.forms.list_orders.mask.disabled="disabled";
		}
		else {
			document.forms.list_orders.mask.disabled="";
		}
	}
	
	function advancedSearchSelect(catLevel){
		switch(catLevel) {
			case 1:
				var i = document.forms.advancedsearch.category1.selectedIndex;
				if (document.forms.advancedsearch.category1[i].text.substring(0,3)=="All") {
					document.forms.advancedsearch.lastcat.value="";
					return
				}
				else {
					document.forms.advancedsearch.categorylevelonename.value=document.forms.advancedsearch.category1[i].text;
					document.forms.advancedsearch.lastcat.value=document.forms.advancedsearch.category1[i].text;
				}
				break;
			case 2:
				var i = document.forms.advancedsearch.category2.selectedIndex;
				if (document.forms.advancedsearch.category2[i].text.substring(0,3)=="All") {
					document.forms.advancedsearch.lastcat.value="";
					return
				}
				else {
					document.forms.advancedsearch.categoryleveltwoname.value=document.forms.advancedsearch.category2[i].text;
					document.forms.advancedsearch.lastcat.value=document.forms.advancedsearch.category2[i].text;
				}
				break;
			case 3:
				var i = document.forms.advancedsearch.category3.selectedIndex;
				if (document.forms.advancedsearch.category3[i].text.substring(0,3)=="All") {
					document.forms.advancedsearch.lastcat.value="";
					return
				}
				else {
					document.forms.advancedsearch.categorylevelthreename.value=document.forms.advancedsearch.category3[i].text;
					document.forms.advancedsearch.lastcat.value=document.forms.advancedsearch.category3[i].text;
				}
				break;
			case 4:
				var i = document.forms.advancedsearch.category4.selectedIndex;
				if (document.forms.advancedsearch.category4[i].text.substring(0,3)=="All") {
					document.forms.advancedsearch.lastcat.value="";
					return
				}
				else {
					document.forms.advancedsearch.categorylevelfourname.value=document.forms.advancedsearch.category4[i].text;
					document.forms.advancedsearch.lastcat.value=document.forms.advancedsearch.category4[i].text;
			}
				break;
			case 5:
				var i = document.forms.advancedsearch.category5.selectedIndex;
				if (document.forms.advancedsearch.category5[i].text.substring(0,3)=="All") {
					document.forms.advancedsearch.lastcat.value="";
					return
				}
				else {
					document.forms.advancedsearch.categorylevelfivename.value=document.forms.advancedsearch.category5[i].text;
					document.forms.advancedsearch.lastcat.value=document.forms.advancedsearch.category5[i].text;
				}
				break;
		}
		document.forms.advancedsearch.submit();
	}


	function advancedSearchReset(newLevel){
		if (document.forms.advancedsearch.category1.value=-2) {
			document.forms.advancedsearch.catlevel.value=newLevel;
			document.forms.advancedsearch.submit();
		}
	}
	
	function advancedSearch(action,categorySearchTerm, fullscreen){
		if (fullscreen=="admin") { var command = "data.svt?viewpage=admin/search_admin.jsp&source=keywords&advanced=true"; }
		else { var command = "data.svt?viewpage=search.jsp&source=keywords&advanced=true"; 	}
		var query = removeWhitespace(document.forms.advancedsearch.withinwords.value + " " + document.forms.advancedsearch.withwords.value);
		queryWords = query.split(' ');
		var i;
		query = "";
		for (i=0;i<queryWords.length;i++) {
			if (removeWhitespace(queryWords[i])!='') {
				query+=removeWhitespace(queryWords[i])+" ";
			}
		}
		var parsednotWords=removeWhitespace(document.forms.advancedsearch.notwords.value);
		notWords = parsednotWords.split(' ');
		for (i=0;i<notWords.length;i++) {
			if (removeWhitespace(notWords[i])!='') {
				query+=" not "+removeWhitespace(notWords[i]);
			}
		}
		query=removeWhitespace(query);
		if (categorySearchTerm!=null) { query=categorySearchTerm+" "+document.forms.advancedsearch.lastcat.value+" "+query; }
		query=removeWhitespace(query);
		query = escape(query);
		if (query=="") { query="ALL"; }
		command+="&query="+query;
		if (document.forms.advancedsearch.photographer.value>0) {
			command+="&artist="+document.forms.advancedsearch.photographer.value;
			var i = document.forms.advancedsearch.photographer.selectedIndex;
			command+="&artistname="+document.forms.advancedsearch.photographer[i].text;
		}	
		if (document.forms.advancedsearch.wildcard.checked) { command+="&wildcard=N"; } 
		else { command+="&wildcard=Y"; }
		if (document.forms.advancedsearch.modelreleased.checked) { command+="&modelreleased=Y"; }
		else { command+="&modelreleased=N"; }
		if (document.forms.advancedsearch.textfriendly.checked) { command+="&textfriendly=Y"; }
		else { command+="&textfriendly=N"; }
		if (document.forms.advancedsearch.notonpictures.checked) { command+="&notonpictures=Y"; }
		else { command+="&notonpictures=N"; }
		command+="&colour="+document.forms.advancedsearch.colour.value;
		command+="&format="+document.forms.advancedsearch.format.value;
		if (document.forms.advancedsearch.searchdate.value!="999") { command+="&searchdate="+document.forms.advancedsearch.searchdate.value; }
		command+="&random="+Math.floor(Math.random()*11);
		if (fullscreen==null) {
			window.opener.document.location = command;
			if (action=="close") {
				window.close();
			}
		}
		else {
			window.location = command;
		}
	}
	function removeWhitespace(s) {
		s = replaceChars(s);
		s = s.replace(/\s+/g, " ");
		s = s.replace(/^\s(.*)/, "$1");
		s = s.replace(/(.*)\s$/, "$1");
		return s;
	}
	
	function replaceChars(s) {
		replaceWords = ". , ( ) - _ { } + = ; : [ ] / | & @ ' ? ! \"".split(' ');
		var i;
		for (i=0; i<replaceWords.length; i++) {
			while (s.indexOf(replaceWords[i])>-1) {
				pos = s.indexOf(replaceWords[i]);
				s = "" + (s.substring(0, pos) + ' ' + s.substring((pos + replaceWords[i].length), s.length));
			}
		}
		return s;
	}

	function submitSearch()	{
		document.forms.searchForm.query.value=replaceChars(document.forms.searchForm.query.value);
		if(!document.forms.searchForm.check.checked) {
			document.forms.searchForm.wildcard.value="Y";
		}
		document.forms.searchForm.query.value=allTrim(document.forms.searchForm.query.value);
		if (document.forms.searchForm.query.value.length<2) {
			alert("Please enter a search term longer than one character");
			return false;
		}
		if (document.forms.searchForm.query.value.toLowerCase()=="all") {
			alert("Searching for ALL is not supported.  You may find the Advanced Search feature useful.");
			return false;
		}
		return true;
	}
	
	function allTrim(sString) {
		while (sString.substring(0,1) == ' ') {
			sString = sString.substring(1, sString.length);
		}
		while (sString.substring(sString.length-1, sString.length) == ' ') {
			sString = sString.substring(0,sString.length-1);
		}
		return sString;
	}
	
	function logIn() {
		window.opener.focus();
		window.opener.location.reload(1);
		window.opener.location=window.opener.location.href+"&reload=true&random="+Math.floor(Math.random()*11);
		self.close();
	}
	function changeColor(acol) {
		var exp = new Date();
		var nowPlusOneYear = exp.getTime() + (365 * 24 * 60 * 60);
		exp.setTime(nowPlusOneYear);
		document.cookie = "pagecolor=" + acol + "; expires=" + exp.toGMTString();
		window.location.reload();
	}
	function popupWindow(urlToOpen, window_width, window_height) {
		var window_left = (screen.availWidth/2)-(window_width/2);
		var window_top = (screen.availHeight/2)-(window_height/2);
		var winParms = "location=no,status=yes,resizable=yes,scrollbars=yes" + ",height="+window_height+",width="+window_width + ",left="+window_left+",top="+window_top;
		var newwindow = window.open(urlToOpen,'_blank',winParms);
		if (!newwindow) {
			var command = "data.svt?viewpage=picture_details_np.jsp";
			window.location = command+urlToOpen.substring(37,urlToOpen.length)+"&fullwindow=true";
		}
		newwindow.focus()
	}	
	function popWindow(jsp, url, window_width, window_height, window_options) {
		var window_left = (screen.availWidth/2)-(window_width/2);
		var window_top = (screen.availHeight/2)-(window_height/2);
		var winParms = window_options+",height="+window_height+",width="+window_width + ",left="+window_left+",top="+window_top;
		var newwindow = window.open('data.svt?viewpage='+jsp+'.jsp'+url,'_blank',winParms);
		if (!newwindow) {
			window.location = "data.svt?viewpage="+jsp+"_np.jsp"+url; // Alternative NoPopup program
		}
		newwindow.focus()
	}
	function resetCookieValue(name, value, url) {
		setCookie(name, value);
		window.location = (url);
	}
	function toggelPreview(url,value) {
		setCookie('defaultclickaction',value);
		window.location = ('data.svt?'+url);
	}
	function toggelThumb(url,value) {
		setCookie('thumbsize',value);
		window.location = ('data.svt?'+url);
	}
	function setCookie(name, value) {
		var date = new Date();
		date.setTime(date.getTime()+(365*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();	
		document.cookie = name+"="+value+expires+"; path=/";
	}
	function checkForm() {
		if(!document.forms.keyform.check.checked) {
			document.forms.keyform.wildcard.value="Y";
		}
		else {
			document.forms.keyform.wildcard.value = "N";
		}
		return true;
	}
	function register() {
		window.opener.focus();
		window.opener.document.location = "data.svt?viewpage=register.jsp&reload=true";
		self.close();
	}
	function emailPassword() { 
		document.forms.login.passwordreminder.value="yes";
		document.forms.login.submit();
	}
	function emailPasswordNP() {
		var eMailAddress = prompt("Enter your email address:", "");
		window.status="Sending you your password . . . . . ";			
		var command = "data.svt?viewpage=login_np.jsp&emailpassword=true&email="+eMailAddress;
		document.location = command;
	}
	function renameLightbox() {
		var id=document.forms.prompt.lbid.value;
		var name=escape(document.forms.prompt.name.value);
		window.opener.document.location = "data.svt?viewpage=lightbox.jsp&renamelightbox=true&lbid="+id+"&name="+name+"&page=1";
		window.close();
	}	
	function newLightbox() {
		var name=escape(document.forms.prompt.name.value);
		window.opener.document.location = "data.svt?viewpage=lightbox.jsp&newLightboxName=true&name=" +name+"&page=1";
		window.close();
	}
	function deleteLightbox(lightboxname, lightboxId) {
		var response = confirm("Are you sure you wish to delete the lightbox named: " + lightboxname);
		window.status="Deleting lightbox . . . . . ";			
		if(response)
			{
				var command = "data.svt?viewpage=lightbox.jsp&deleteLightbox=true&lbid="+lightboxId+"&page=1";
				document.location = command;
			}
	}
	function deleteUser(username, url) {
		var response = confirm("Are you sure you wish to delete the user: " + username);
		if(response)
			{
				var command = url;
				document.location = command;
			}
	}
	function verifyAction(prompt_text, url) {
		var response = confirm(prompt_text);
		if(response)
			{
				var command = url;
				document.location = command;
			}
	}
	function publish(lightboxId) {
		window.location = "data.svt?viewpage=lightbox.jsp&publish=true&page=1&lbid=" + lightboxId;
	}
	function copyLightbox(lightboxId) {
		var command = "data.svt?viewpage=lightbox.jsp&copyPublicLightbox=true&page=1&lbid="+lightboxId;
		document.location = command;
	}
	function removeImage(imageId, imgname) {
		var deleteImage = confirm("Remove image " + imgname.substr(3,9) + " from this lightbox");
		window.status="Updating your lightbox . . . . . ";			
		if(deleteImage)
			{
				window.status="Updating your lightbox . . . . . ";
				swap(imgname);
				signalServer("data.svt?viewpage=processcommands.jsp&removeimage=true&image_id=" + imageId);
				fn="window.location.reload();";
				setTimeout(fn, 600 );
			}
	}
	function removeCookieImage(imageId, imgname) {
		var deleteImage = confirm("Remove image " + imgname.substr(3,9) + " from this lightbox");
		window.status="Updating your lightbox . . . . . ";			
		if(deleteImage)
			{
				window.status="Updating your lightbox . . . . . ";
				swap(imgname);
				fop="data.svt?viewpage=lightbox_local.jsp&removeimage=true&image_id=" + imageId;
				fn="window.location = fop;";
				setTimeout(fn, 700 );
			}
	}
	function removefrombasket(imageId, imgname) {
		var deleteImage = confirm("Remove image " + imgname.substr(3,9) + " from your shopping basket");
		window.status="Updating your shopping basket . . . . . ";			
		if(deleteImage)
			{
				window.status="Updating your shopping basket . . . . . ";
				swap(imgname);
				signalServer("data.svt?viewpage=processcommands.jsp&removefrombasket=true&image_id=" + imageId);
				fn="window.location.reload();";
				setTimeout(fn, 600 );
			}
	}
	
// refreshType='S' - User logged in and does not require the minilight box to be updated
// refreshtype='R' - User logged in but requires a refresh of the screen to update the mini lightbox
// refreshType='E' - User is not logged in but is an existing user, so we will log them in
// refreshType='L' - User is not logged in nor is there any Travel Pictures cookies so we will add a Local lightbox/basket

	function addImage(imageId, imgname, revertthumb, refreshtype, imgref)	{
		window.status="Updating your lightbox . . . . . ";
		if (refreshtype=="S") {
			revertto(imgname,revertthumb);
			signalServer("data.svt?viewpage=processcommands.jsp&add=true&image_id=" + imageId);
		} 
		else if (refreshtype=="R" || refreshtype=="L") {
			document[imgname].src = "img/tick.gif";
			fop=window.location + "&addtolightbox=" + imageId;
			fn="window.location = fop;";
			setTimeout(fn, 700);
		}
		else {
			document[imgname].src = "img/tick.gif";
			fop="data.svt?viewpage=login_np.jsp&linkto=continue&linktype=lightbox&imgRef=" + imgref + "&imgId=" + imageId;
			fn="window.location = fop;";
			setTimeout(fn, 700);
		}
		return;
	}	
	function deleteImage(imageId, status)	{
		if (prompt("Enter delete code")!='743518') { return; }
		if (status=="warning") {
			if (prompt("Image has existing activity.  Replay 'override' to continue")!='override') { return; }	
		}
		signalServer("data.svt?viewpage=processcommands.jsp&delete=true&image_id=" + imageId); 
		fn="logIn()"; // reloads parent and closes current window
		setTimeout(fn, 900 );  // give the background task time to delete the image
		return;
	}	
	function deleteImages(pId, pcount)	{
		if (prompt("This will delete " + pcount + " images i.e. ALL the photographer's images - Enter delete code")!='743518') { return; }
		var command = "data.svt?viewpage=admin/photographer.jsp&deleteImages=true&pid="+pId;
		document.location = command;
		return;
	}	
	function deleteUnusedImages(pId)	{
		if (prompt("This will delete all the photographer's images that are not in an Order (new or old), a lightbox or a basket - Enter delete code")!='743518') { return; }
		var command = "data.svt?viewpage=admin/photographer.jsp&deleteUnusedImages=true&pid="+pId;
		document.location = command;
		return;
	}
	function markVisible(pId, action)	{
		if (prompt("Mark all the photographer's images as " + action)!='743518') { return; }
		var command = "data.svt?viewpage=admin/photographer.jsp&visibility="+action+"&pid="+pId;
		document.location = command;
		return;
	}	
	
// refreshType='S' - User logged in and does not require the minilight box to be updated
// refreshtype='R' - User logged in but requires a refresh of the screen to update the mini lightbox.  Not relevant for logged in Basket
// refreshType='E' - User is not logged in but is an existing user, so we will log them in
// refreshType='L' - User is not logged in nor is there any Travel Pictures cookies so we will add a Local lightbox/basket

	function addBasket(imageId, imgname, revertthumb, refreshtype, imgref) {
		if (refreshtype=="S" || refreshtype=="R") {
			window.status="Updating your shopping basket . . . . . ";
			revertto(imgname,revertthumb);
			signalServer("data.svt?viewpage=processcommands.jsp&addbasket=true&image_id=" + imageId);

		} else if (refreshtype=="E") {
			document[imgname].src = "img/tick.gif";
			fop="data.svt?viewpage=login_np.jsp&linkto=continue&linktype=basket&imgRef=" + imgref + "&imgId=" + imageId;
			fn="window.location = fop;";
			setTimeout(fn, 700);
		}
		else {
			document[imgname].src = "img/tick.gif";
			fop=window.location + "&addtobasket=" + imageId;
			fn="window.location = fop;";
			setTimeout(fn, 700);
		}
		return;
	}
	function popPicture(imageId, caption) {
		var url = "data.svt?viewpage=popup.jsp&ref=" + imageId + "&caption=" + caption;
		//var newwin = window.open(url, "_blank", "width=800,height=600,resizable,scrollbars,status");
		window.location = url;
	}
	function emailPicture(imageId, caption) {
		var url = "data.svt?viewpage=mailpop.jsp&ref=" + imageId + "&caption=" + caption;
		window.location = url;
	}
	function PopBack(keyword) {
		opener.document.forms.searchForm.query.value=keyword;
		opener.document.forms.searchForm.submit();
		close();
	}
	function PopBackCat(category) {
		opener.document.location="data.svt?viewpage=browse.jsp&source=categories&query="+category;
		close();
	}
	function PopBackURL(URL) {
		opener.document.location = "http://www.google.co.uk";
		close();
	}
	function findKeyword(keyword) {
		document.searchForm.query.value=keyword;
		document.searchForm.submit();
	}
	function swap(imgId) {
		var fn;
		fn =  "swapOnTimeout('" + imgId + "','" + document[imgId].src + "')";
		document[imgId].src = "img/tick.gif";
		setTimeout(fn, 600 );
	}
	function revertto(imgId,original) {
		var fn;
		fn =  "swapOnTimeout('" + imgId + "','" + original + "')";
		document[imgId].src = "img/tick.gif";
		setTimeout(fn, 600 );
	}
	function swapOnTimeout(imgId,imageSrc){
		document[imgId].src = imageSrc;
	}
	function signalServer(url) {
		xmlhttp=null
		// code for Mozilla, etc.
		if (window.XMLHttpRequest) {
	  		xmlhttp=new XMLHttpRequest()
	  	}
		// code for IE
		else if (window.ActiveXObject) {
	  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	  	}
		if (xmlhttp!=null) {
		  xmlhttp.onreadystatechange=state_Change
		  xmlhttp.open("GET",url + "&r=" + Math.round(100*Math.random()),true)
		  xmlhttp.send(null)
	  	}
		else {
	  		alert("Your browser does not support XMLHTTP & so can't add images to lightboxes etc.")
	  	}
	}
	function state_Change()	{
		window.status="";
	}
	
// Two functions to disable browser right clicking (along with if (document.layers) . . . --- See browse.jsp & search.jsp for details
// You need to include the following single line in the <head> section of the page to be protected																   
//	
//		document.oncontextmenu=new Function("return false")
//
																   
	function clickIE() {
		if (document.all) {
			return false;
		}
	}
	function clickNS(e) {
		if (document.layers||(document.getElementById&&!document.all)) {
			if (e.which==2||e.which==3) {
				return false;
			}
		}
	}

	function getFlashVersion(){ 
	  // ie 
	  try { 
		try { 
		  // avoid fp6 minor version lookup issues 
		  // see: http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/ 
		  var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6'); 
		  try { axo.AllowScriptAccess = 'always'; } 
		  catch(e) { return '6,0,0'; } 
		} catch(e) {} 
		return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1]; 
	  // other browsers 
	  } catch(e) { 
		try { 
		  if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){ 
			return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1]; 
		  } 
		} catch(e) {} 
	  } 
	  return '0,0,0'; 
	} 
	
	function detectFlash() {
		var version = getFlashVersion().split(',').shift();
		return version;
	}

	function detectFlashx() {
		var flashinstalled = 0;
		var flashversion = 0;
		MSDetect = "false";
		if (navigator.plugins && navigator.plugins.length)
		{
			x = navigator.plugins["Shockwave Flash"];
			if (x)
			{
				flashinstalled = 2;
				if (x.description)
				{
					y = x.description;
					flashversion = y.charAt(y.indexOf('.')-1);
				}
			}
			else
				flashinstalled = 1;
			if (navigator.plugins["Shockwave Flash 2.0"])
			{
				flashinstalled = 2;
				flashversion = 2;
			}
		}
		else if (navigator.mimeTypes && navigator.mimeTypes.length)
		{
			x = navigator.mimeTypes['application/x-shockwave-flash'];
			if (x && x.enabledPlugin)
				flashinstalled = 2;
			else
				flashinstalled = 1;
		}
		else { MSDetect = "true"; }
		if (flashversion>0) {  return flashversion; }
		if (MSDetect="true"){
			for(var i=9; i>0; i--){
				flashVersion = 0;
				try{
					var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
					return i;
				}
				catch(e){
				}
			}
			return 0;
		}
		else return 0;
	}



// Two routines to switch images on the mouse over/out event

	function over(num,name) {
	  if(document.images) {
		revert[num] = document[name].src;
		document[name].src = flipped[num].src;
	  }
	}
	
	function out(num, name) {
	  if(document.images) document[name].src = revert[num];
	}


	function xxxxxxCheckLength(field, maxlimit) {
			if (field.value.length > maxlimit) 
				field.value = field.value.substring(0, maxlimit);
			return true;
	}

function expandById(id, params, custom, type) {
	try {
		a = document.getElementById(id);
		new hs.Expander(a, params, custom, type);
		return false;
		
	} catch(e) {
		return true;
	}
	
}


