// search form javacript
function clearFields()
{
	if (document.search_form.search_string) {
		document.search_form.search_string.value = "";
	}
	if (document.search_form.s_tit) {
		document.search_form.s_tit.checked = true;
	}
	if (document.search_form.s_sds) {
		document.search_form.s_sds.checked = false;
	}
	if (document.search_form.s_fds) {
		document.search_form.s_fds.checked = false;
	}
	var prQty = document.search_form.pq.value;
	for(var i = 0; i <= prQty; i++) {
		if(document.search_form.elements["pv_" + i]) {
			document.search_form.elements["pv_" + i].value = "";
		}
	}
	var fQty = document.search_form.fq.value;
	for(var i = 0; i <= fQty; i++) {
		if(document.search_form.elements["fv_" + i]) {
			document.search_form.elements["fv_" + i].value = "";
		}
	}
	if (document.search_form.search_category_id) {
		document.search_form.search_category_id.selectedIndex = 0;
	}
	if (document.search_form.manf) {
		document.search_form.manf.selectedIndex = 0;
	}
	if (document.search_form.lprice) {
		document.search_form.lprice.value = "";
	}
	if (document.search_form.hprice) {
		document.search_form.hprice.value = "";
	}
	if (document.search_form.lweight) {
		document.search_form.lweight.value = "";
	}
	if (document.search_form.hweight) {
		document.search_form.hweight.value = "";
	}
}

// Following function added by Oliver Pereira, Nov 2008
function addDesign(startingInputID, entrantID, imageLocation) {
	if (startingInputID != '') {
		window.opener.document.getElementById(startingInputID + '_img').src = imageLocation + '?' + (new Date()).getTime();
		window.opener.document.getElementById(startingInputID).value = entrantID;
		window.opener.document.getElementById(startingInputID + '_disp').innerHTML = entrantID;
	}
	
	// Close the window
	window.close();
}

// Following function added by Oliver Pereira, Fri 18 Jun 2010
function addPhoto(startingInputID, entrantID, imageLocation) {
	if (startingInputID != '') {
		window.opener.document.getElementById(startingInputID + '_img').src = imageLocation + '?' + (new Date()).getTime();
		window.opener.document.getElementById(startingInputID).value = entrantID;
		window.opener.document.getElementById(startingInputID + '_disp').innerHTML = entrantID;
	}
	
	// Close the window
	window.close();
}

// Function to toggle the display of an element on a page
function toggleElementByID(elementID) {
	var elem, vis;
	if (document.getElementById) {
		// Standards-compliant
		elem = document.getElementById(elementID);
	} else if (document.all) {
		// Old versions of Internet Explorer
		elem = document.all[elementID];
	} else if (document.layers) {
		// Netscape Navigator 4
		elem = document.layers[elementID];
	}
	vis = elem.style;
	// If the style.display value is blank, try to work it out here.
	if (vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined) {
		vis.display = (elem.offsetWidth != 0 && elem.offsetHeight != 0) ? 'block' : 'none';
	}
	vis.display = (vis.display == '' || vis.display == 'block') ? 'none' : 'block';
}

// Function to alert customer and direct them to search
function firstSearchForADesign() {
	alert('To buy this product, first search for a design using the search form above.');
	if (itemForm.elements['search_string'].style.visibility != 'hidden') {
		//itemForm.elements['search_string'].focus();
	}
	return false;
}


// Function to switch the mode of the search page.
function switchSearchModeTo(mode) {
	var b1, b2, sm, as, fs;
	if (document.getElementById) {
		// Standards-compliant
		b1 = document.getElementById('back_link1');
		b2 = document.getElementById('back_link2');
		sm = document.getElementById('search_messages');
		as = document.getElementById('artwork_search');
		fs = document.getElementById('football_search');
	} else if (document.all) {
		// Old versions of Internet Explorer
		b1 = document.all['back_link1'];
		b2 = document.all['back_link2'];
		sm = document.all['search_messages'];
		as = document.all['artwork_search'];
		fs = document.all['football_search'];
	} else if (document.layers) {
		// Netscape Navigator 4
		b1 = document.layers['back_link1'];
		b2 = document.layers['back_link2'];
		sm = document.layers['search_messages'];
		as = document.layers['artwork_search'];
		fs = document.layers['football_search'];
	}
	if (mode == 'artwork') {
		b1.style.display = 'block';
		b2.style.display = 'block';
		sm.style.display = 'none';
		as.style.display = 'block';
		fs.style.display = 'none';
	} else if (mode == 'football') {
		b1.style.display = 'block';
		b2.style.display = 'block';
		sm.style.display = 'none';
		as.style.display = 'none';
		fs.style.display = 'block';
	} else {
		b1.style.display = 'block';
		b2.style.display = 'block';
		sm.style.display = 'block';
		as.style.display = 'none';
		fs.style.display = 'none';
	}
}

// The following function was copied here on Thu 29/10/2009 by Oliver Pereira from:
// http://webdevtips.co.uk/webdevtips/js/jsbackbutton.shtml
// (At the time of writing, it is not used.)
function checkUrl() {
	var myurl = 'http://www.my-fundraising-project.co.uk';
	if (document.referrer.substring(0, 39) == myurl) {
		document.location.href = document.referrer;
	} else {
		document.location.href = myurl;
	}
}
