function object_action(strType, lngID, strMethod, strPromptText) {
	var strOutputType;
	var strOutputMethod;
	var blnContinue = true;
	
	switch(strType) {
	case "lk":
		strOutputType = "Link";
		break;
	case "nt":
		strOutputType = "Note";
		break;
	case "nw":
		strOutputType = "News";
		break;
	case "od":
		strOutputType = "Order";
		break;
	case "of":
		strOutputType = "Offer";
		break;
	case "pr":
		strOutputType = "Product";
		break;
	case "sh":
		strOutputType = "Shot";
		break;
	case "sk":
		strOutputType = "Stock";
		break;
	case "sp":
		strOutputType = "System Parameter";
		break;
	case "st":
		strOutputType = "Stockist";
		break;
	case "ts":
		strOutputType = "Testimonial";
		break;
	case "us":
		strOutputType = "User";
		break;
	default:
		alert("Unknown Record Type: " + strType);
		return false;
	}
	
	switch(strMethod) {
	case "delete":
		strOutputMethod = "Delete";
		break;
	case "restore":
		strOutputMethod = "Restore";
		break;
	default:
		alert("Unknown Record Action: " + strMethod);
		return false;
	}
	
	if (strPromptText == "")
		strPromptText = "with " + strType + "ID = " + lngID;
	else
		strPromptText = "for '" + strPromptText + "'";
	if (confirm("Are you sure you wish to " + strOutputMethod + " " + strOutputType + " Record " + strPromptText + "?") == true) {
		document.forms[0].id.value = lngID;
		if (strType == "nt")
			document.forms[0].tblnotemethod.value = strMethod;
		else
			document.forms[0].method.value = strMethod;
		document.forms[0].submit();
	}
}
function validate_form(objForm) {
	var i;
	var e;
	var strTemp;
	
	for (i=0; i<objForm.length; i++) {
		e = objForm.elements[i];
		if ((e.validationprompt != undefined) && (e.style.display == "")) {
			if (e.type == 'select-one') {
				if (e.value == -42) {
					strTemp = e.validationprompt;
					if (strTemp.substr(0, 1) == '#') {
						click_tab(Number(strTemp.substr(1, 2)));
						strTemp = strTemp.substr(3);
					}
					alert('You must Select an Option from the Highlighted DropDown "' + strTemp + '"');
					e.focus();
					return false;
				}
			} else if ((e.type == 'text') || (e.type == 'file') || (e.type == 'textarea')) {
				if (e.value == '') {
					strTemp = e.validationprompt;
					if (strTemp.substr(0, 1) == '#') {
						click_tab(Number(strTemp.substr(1, 2)));
						strTemp = strTemp.substr(3);
					}
					alert('You must Enter a value for "' + strTemp + '"');
					e.focus();
					return false;
				}
			}
		}
	}
	return true;
}

function shownote_onClick() {
	if (document.forms[0].vshownote.checked == true)
		document.forms[0].shownote.value = "Y";
	else
		document.forms[0].shownote.value = "N";
	document.forms[0].submit();	
}
function editnote(lngID, lngOwnerID, strTitle) {
	document.forms[0].tblnoteid.value = lngID;
	document.forms[0].tblnoteownerid.value = lngOwnerID;
	document.forms[0].tblnotetitle.value = strTitle;
	document.forms[0].action = "./frmNote.ASP";
	document.forms[0].submit();
}
function click_tab(intTab) {
	var intTemp;
	
	if (intTab == -1)
		intTab = document.forms[0].tab.value;
	for (intTemp = 0; intTemp <= document.forms[0].tabs.value; intTemp++) {
		document.getElementById("tabbut" + intTemp).style.display = "";
		document.getElementById("tabbut" + intTemp + "x").style.display = "none";
		document.getElementById("tab" + intTemp).style.display = "none";
	}
	document.getElementById("tabbut" + intTab).style.display = "none";
	document.getElementById("tabbut" + intTab + "x").style.display = "";
	document.getElementById("tab" + intTab).style.display = "block";
	document.forms[0].tab.value = intTab;
}
function toggle_option(strField) {
	if (document.getElementById(strField + "v").checked == true)
		document.getElementById(strField).value = -1;
	else
		document.getElementById(strField).value = 0;
	document.forms[0].submit();
}
function toggle_show(strField) {
	var strDisplayStatus = "";
	if (document.getElementById(strField).style.display == "")
		strDisplayStatus = "none";
	document.getElementById(strField).style.display = strDisplayStatus;
}
function toggle_disabled(strField) {
	var strDisabledStatus = true;
	if (document.getElementById(strField).disabled == strDisabledStatus)
		strDisabledStatus = false;
	document.getElementById(strField).disabled = strDisabledStatus;
}
function toggle_userok() {
	var strDisabledStatus = true;
	if ((document.getElementById('apply').checked == false) || (document.getElementById('accept').checked == true))
		strDisabledStatus = false;
	document.getElementById('save').disabled = strDisabledStatus;
}
function check_time(strFieldID) {
	var strTime = document.getElementById(strFieldID).value;
	if (!strTime == "") {
		if (!/^([01]?[0-9]|[2][0-3])(:[0-5][0-9])?$/.test(strTime)) {
			document.getElementById(strFieldID).focus();
			document.getElementById(strFieldID).select();
			alert(strTime + " is is not a valid time!");
			return false;
		}
	}
}
function next_colour() {
	var RowCounter = document.forms[0].nextcolrow.value;
	if (Number(RowCounter) < 64) {
		document.getElementById("colrow" + RowCounter).style.display = "";
		document.forms[0].nextcolrow.value = Number(RowCounter) + 1;
	}
}
function next_size() {
	var RowCounter = document.forms[0].nextsizrow.value;
	if (Number(RowCounter) < 64) {
		document.getElementById("sizrow" + RowCounter).style.display = "";
		document.forms[0].nextsizrow.value = Number(RowCounter) + 1;
	}
}
function validate_emailaddress(strAddress) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(strAddress) == false) {
		return false;
	}
	return true;
}
function validate_password(strPassword, intMinimumPasswordLength) {
	var reg = new RegExp('([A-Za-z0-9]{' + intMinimumPasswordLength + ',})');
	if(reg.test(strPassword) == false) {
		return false;
	}
	return true;
}
function validate_postcode(strPostcode) {
	var reg = /^([a-zA-Z]{1,2}[0-9][0-9A-Za-z]? [0-9][a-zA-Z]{2})$/;
	if(reg.test(strPostcode) == false) {
		return false;
	}
	return true;
}
function validate_number(datafield) {
	var strTemp = String(datafield.value).split(',').join('');
	strTemp = String(strTemp).split('£').join('');
	strTemp = String(strTemp).split(',').join('');
	if (Trim(strTemp) == '')
		return false;
	if (isNaN(strTemp))
		return false;
	datafield.value = strTemp;
	if (Number(strTemp) < 1)
		return false;
	return true;
}
function Trim(strText) {
	if (strText == null)
		return '';
	return strText.replace(/^\s+|\s+$/g, '');
}
function check_field() {
	var blnStatus = true;
	var arrArgs = check_field.arguments;
	var datafield;
	var errorfield;

	for(i=0; i<arrArgs.length; i++) {
		datafield = document.getElementById(String(arrArgs[i]).substring(2));
		errorfield = document.getElementById("err_" + String(arrArgs[i]).substring(2));
		if ((datafield) && (errorfield)) {
			switch (String(arrArgs[i]).substring(0, 2)) {
			case "BL":
				if (Trim(datafield.value) == '') {
					errorfield.className = 'error';
					blnStatus = false;
				}
				else
					errorfield.className = 'hidden';
				break;
			case "EM":
				if (validate_emailaddress(datafield.value))
					errorfield.className = 'hidden';
				else {
					errorfield.className = 'error';
					blnStatus = false;
				}
				break;
			case "PC":
				if (document.forms[0].country.value == '826') {
					strTemp = String(datafield.value).split(' ').join('');
					if (strTemp.length > 4)
						datafield.value = strTemp.substring(0, strTemp.length - 3) + ' ' + strTemp.substring(strTemp.length - 3);
					if (validate_postcode(datafield.value))
						errorfield.className = 'hidden';
					else {
						errorfield.className = 'error';
						blnStatus = false;
					}
				} else
					errorfield.className = 'hidden';
				break;
			default:
				alert("error");
			}
		}
	}
	return blnStatus;
}
function check_frmUser(intMinimumPasswordLength) {
	var blnReturn = true;

	blnReturn = check_field('EMname','BLfirstname','BLlastname','BLaddress1','PCpostcode','BLtelephone');
	if (document.forms[0].password)
		document.getElementById("err_password").className = 'hidden';		
	if (document.forms[0].passwordx)
		document.getElementById("err_passwordx").className = 'hidden';		
	if (blnReturn == true) {
		if (document.forms[0].password) {
			if (validate_password(document.forms[0].password.value, intMinimumPasswordLength)) {
				if (document.forms[0].passwordx) {
					if (Trim(document.forms[0].password.value).toLowerCase() != Trim(document.forms[0].passwordx.value).toLowerCase()) {
						document.getElementById("err_passwordx").className = 'error';
						blnReturn = false;
					}
				}
			} else {
				document.getElementById("err_password").className = 'error';
				blnReturn = false;
			}
		}
	}
	return blnReturn;
}
function check_register(intMinimumPasswordLength) {
	var blnReturn = true;

	blnReturn = check_field('EMname','BLfirstname','BLlastname','BLaddress1','PCpostcode','BLtelephone');
	document.getElementById("err_password").className = 'hidden';		
	document.getElementById("err_passwordx").className = 'hidden';		
	if (blnReturn == true) {
		if (validate_password(document.forms[0].password.value, intMinimumPasswordLength)) {
			if (Trim(document.forms[0].password.value).toLowerCase() != Trim(document.forms[0].passwordx.value).toLowerCase()) {
				document.getElementById("err_passwordx").className = 'error';
				blnReturn = false;
			}
		} else {
			document.getElementById("err_password").className = 'error';
			blnReturn = false;
		}
	}
	return blnReturn;
}

function change_whered() {
	var strDisplayStatus = "none";
	if (document.forms[0].whered.value == 'Other')
		strDisplayStatus = "";
	document.getElementById("whererow").style.display = strDisplayStatus;
}

function reset_background(datafield) {
	datafield.style.backgroundColor = '#ffffff';
}

function check_payment() {
	var blnReturn = true;
	var strMessage = 'Please correct the errors highlighted above';
	var strTemp = '';
	document.getElementById("errormessage").innerText = '';
	blnReturn = check_field('BLfirstname','BLlastname','BLaddress1','BLaddress4','BLtelephone','EMemail');

	document.getElementById("err_postcode").className = 'hidden';
	if ((blnReturn) && (document.forms[0].country.value == '826'))
		blnReturn = check_field('PCpostcode');

	document.getElementById("err_where").className = 'hidden';
	if (blnReturn) {
		if (document.forms[0].whered.value == '-42') {
			document.getElementById("err_where").className = 'error';
			blnReturn = false;
		} else if ((document.forms[0].whered.value == 'Other') && (Trim(document.forms[0].where.value) == '')) {
			document.getElementById("err_where").className = 'error';
			blnReturn = false;
			document.forms[0].where.style.backgroundColor = '#ff69b4';
		}
	}
	
	document.getElementById("err_cctype").className = 'hidden';
	document.getElementById("err_ccnumber").className = 'hidden';
	document.getElementById("err_cctodate").className = 'hidden';
	document.getElementById("err_cccode").className = 'hidden';
	document.getElementById("err_ccaddress1").className = 'hidden';
	document.getElementById("err_ccaddress4").className = 'hidden';
	document.getElementById("err_ccpostcode").className = 'hidden';
	if ((blnReturn) && (document.forms[0].payment[1].checked)) {
		if (document.forms[0].cctype.value == '-42') {
			document.getElementById("err_cctype").className = 'error';
			blnReturn = false;
		}
		strTemp = String(document.forms[0].ccnumber.value).split('-').join('');
		strTemp = String(strTemp).split(' ').join('');
		strTemp = Trim(strTemp);
		if ((strTemp.length != 16) || (isNaN(strTemp))) {
			document.getElementById("err_ccnumber").className = 'error';
			blnReturn = false;
		}
		document.forms[0].ccnumber.value = strTemp;
		if ((document.forms[0].cctomonth.value == '-42') || (document.forms[0].cctoyear.value == '-42')) {
			document.getElementById("err_cctodate").className = 'error';
			blnReturn = false;
		}		
		if (document.forms[0].cccode.value == '') {
			document.getElementById("err_cccode").className = 'error';
			blnReturn = false;
		}
		if (document.forms[0].ccaddress1.value == '') {
			document.getElementById("err_ccaddress1").className = 'error';
			blnReturn = false;
		}
		if (document.forms[0].ccaddress4.value == '') {
			document.getElementById("err_ccaddress4").className = 'error';
			blnReturn = false;
		}
		if (document.forms[0].cccountry.value == '826') {
			strTemp = String(document.forms[0].ccpostcode.value).split(' ').join('');
			if (strTemp.length > 4)
				document.forms[0].ccpostcode.value = strTemp.substring(0, strTemp.length - 3) + ' ' + strTemp.substring(strTemp.length - 3);
			if (validate_postcode(document.forms[0].ccpostcode.value) == false) {
				document.getElementById("err_ccpostcode").className = 'error';
				blnReturn = false;
			}
		}
	}

	if ((blnReturn) && (document.forms[0].band.value == '0') && (document.forms[0].accept.checked == false)) {
		strMessage = "You must accept breastvest's Terms and Conditions";
		blnReturn = false;	
	}
	if (!blnReturn) {
		document.getElementById("errormessage").innerText = strMessage;
		return false;
	}
}

function as_above() {
	document.forms[0].ccaddress1.value = document.forms[0].address1.value;
	document.forms[0].ccaddress2.value = document.forms[0].address2.value;
	document.forms[0].ccaddress3.value = document.forms[0].address3.value;
	document.forms[0].ccaddress4.value = document.forms[0].address4.value;
	document.forms[0].ccpostcode.value = document.forms[0].postcode.value;
	document.forms[0].cccountry.selectedIndex = document.forms[0].country.selectedIndex;
}

function check_contact() {
	var strMessage = '';

	if (Trim(document.forms[0].email.value) != '') {
		if (validate_emailaddress(document.forms[0].email.value) == false) {
			strMessage = document.forms[0].email.value + ' is not a valid Email address';
		}
	}
	
	if ((Trim(document.forms[0].feedback.value) == '') && (Trim(document.forms[0].message.value) == '')) {
		strMessage = 'You must enter something into Feedback or General Message';
	}

	if ((Trim(document.forms[0].telephone.value) == '') && (Trim(document.forms[0].mobile.value) == '') && (Trim(document.forms[0].email.value) == '')) {
		strMessage = 'You must enter at least one of Telephone, Mobile or Email';
	}

	if (Trim(document.forms[0].name.value) == '') {
		strMessage = 'You must enter your Name';
	}
	
	if (strMessage == '')
		return true;
	else {
		document.getElementById('errormessage').innerText = strMessage + '!';
		return false;
	}
}

function update_productcode() {
	var intProduct = 0;
	var strProductCode = '';
	var strProductPrice = jsDefaultPrice;
	var strProductDescription = '032';
	var strProductImage = './images_general/BV-product-link.jpg';
	
	for (i = 0; i < jsID.length; i++) {
		if ((jsSize[i] == document.forms[0].size.value) && (jsColour[i] == document.forms[0].colour.value)) {
			intProduct = jsID[i];
			strProductCode = jsCode[i] + ' - ';
			strProductPrice = '£' + jsPrice[i];
			strProductDescription = jsDescription[i];
			strProductImage = jsImage[i];
			i = jsID.length;
		}
	}
	document.forms[0].product.value = intProduct;
//	document.getElementById('productcode').innerText = strProductCode;
	document.getElementById('productprice').innerText = strProductPrice;
	if (intProduct == 0) {
		if ((document.forms[0].size.value == 'sizes...') || (document.forms[0].colour.value == 'colours...'))
			intProduct = 0;
		else
			strProductCode = 'Sorry, this product is not available in the size/colour combination you have selected';
	}
	document.getElementById('productdescription').innerText = strProductCode + decodeASCII(strProductDescription);
	document.images['productpicture'].src = strProductImage;
}

function check_productdetails() {
	var errorcolour = '#ff69b4';
	var blnReturn = true;
	var blnLocal = false;
	var strTemp = document.forms[0].number.value;
	if (document.forms[0].size.value == 'sizes...') {
		document.forms[0].size.style.backgroundColor = errorcolour;
		blnReturn = false;
	}
	if (document.forms[0].colour.value == 'colours...') {
		document.forms[0].colour.style.backgroundColor = errorcolour;
		blnReturn = false;
	}
	if ((blnReturn == true) && (document.forms[0].product.value == 0)) {
		document.forms[0].size.style.backgroundColor = errorcolour;
		document.forms[0].colour.style.backgroundColor = errorcolour;
		blnReturn = false;
	}

	if (Trim(strTemp) == '')
		blnLocal = true;
	else if (isNaN(strTemp))
		blnLocal = true;
	else if (Number(strTemp) < 1)
		blnLocal = true;
	if (blnLocal) {
		document.forms[0].number.style.backgroundColor = errorcolour;
		blnReturn = false;
	}
	return blnReturn;
}

function decodeASCII(strData) {
	var strOutput = '';
	while (strData.length > 2) {
		strOutput = strOutput + String.fromCharCode(Number(strData.substring(0, 3)));
		strData = strData.substring(3);
	}
	return strOutput;
}
function calculate_ShippingVAT() {
// now defunct but might be useful in the future
	var intPostRate = 0;
	var intVATRate = 0;
	var intTotalItems = 0;
	var intTotalValue = 0;
	var intShipping = 0;
	var intVAT = 0;
	var intPosition = -1;
	var strCountryData = document.forms[0].countrydata.value;
	var intPostGroup = 3;
	var intVATGroup = 1;
	
	intPosition = strCountryData.search(document.forms[0].country.value);
	if (intPosition > -1) {
		intPostGroup = Number(strCountryData.substr(intPosition + 2, 1));
		intVATGroup = Number(strCountryData.substr(intPosition + 3, 1));
	}
	switch (intPostGroup) {
	case 1:
		intPostRate = 100;
		break;
	case 2:
		intPostRate = 150;
		break;
	default:
		intPostRate = 300;
		break;
	}
	switch (intVATGroup) {
	case 1:
		intVATRate = 2000;
	}
	intTotalItems = Number(document.forms[0].totalitems.value);
	intTotalValue = Number(document.forms[0].totalvalue.value);
	intShipping = intPostRate * intTotalItems;
	document.forms[0].shipping.value = intShipping;
	intTotalValue = Number(intTotalValue) + Number(intShipping);
	intShipping = intShipping / 100;
	document.getElementById("shippingv").innerText = intShipping.toFixed(2);
	
	if (intVATRate > 0) {
		document.getElementById("vatrow").style.display = '';
		intVAT = intVATRate / 10000 * intTotalValue;
	} else
		document.getElementById("vatrow").style.display = 'none';
	document.forms[0].vat.value = intVAT;
	intTotalValue = Number(intTotalValue) + Number(intVAT);
	intVAT = intVAT / 100;
	document.getElementById("vatv").innerText = intVAT.toFixed(2);
	intTotalValue = intTotalValue / 100;
	document.getElementById("invoice").innerText = intTotalValue.toFixed(2);
}

function GLoad(strXMLFile) {
	if (document.getElementById("map_canvas")) {
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("map_canvas"));

			map.addControl(new GMapTypeControl());
			map.addControl(new GLargeMapControl());
			map.addControl(new GScaleControl());

			map.setCenter(new GLatLng(document.forms[0].latitude.value, document.forms[0].longitude.value), Number(document.forms[0].zoom.value));

			GDownloadUrl(strXMLFile, function(data, responseCode) {
				var xml = GXml.parse(data);
				var markers = xml.documentElement.getElementsByTagName("marker");
				for (var i = 0; i < markers.length; i++) {
					var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng")));
					map.addOverlay(createMarker(map, point, markers[i]));
				}
			});
		}
	}
}

function createMarker(map, point, xmlnode) {
	var PWCicon = new GIcon(G_DEFAULT_ICON);
	//PWCicon.shadow = '';
	//PWCicon.iconSize = new GSize(30, 43);
	//PWCicon.image = "http://davenportschocolates.co.uk/images_general/stockists_map_pin2.png";
	
	var marker = new GMarker(point, {icon:PWCicon, title:xmlnode.getAttribute("name")});
	GEvent.addListener(marker, "click", function() {
		//var myHtml = "Longitude is " + xmlnode.getAttribute("lng");
		//map.openInfoWindowHtml(point, myHtml);
		var strAddress = "<span class='mapbubble'><b>" + xmlnode.getAttribute("name") + "</b><br />" + xmlnode.getAttribute("address") + "</span>";
		var strOther = "";
		if (xmlnode.getAttribute("tel") != "")
			strOther += "<span class='mapbubble'><b>Telephone:&nbsp;</b>" + xmlnode.getAttribute("tel") + "</span><br />";
		if (xmlnode.getAttribute("web") != "")
			strOther += "<span class='mapbubble'><b>Website:&nbsp;</b></span><span class='maplink'><a href='http://" + xmlnode.getAttribute("web") + "' target='_blank'>" + xmlnode.getAttribute("web") + "</a></span>";
          marker.openInfoWindowTabs([new GInfoWindowTab("Address", 
strAddress), new GInfoWindowTab("Tel, etc.", strOther)]);   });
		
	return marker;
}

function geoCode(strPostcode) {
	var localSearch = new GlocalSearch();
	
	localSearch.setSearchCompleteCallback(null, function() {
		if (localSearch.results[0]) {
			setLatitudeLongitude(localSearch.results[0].lat, localSearch.results[0].lng);
		} else {
			document.forms[0].geocodestatus.value = 0;
			alert("Unable to locate: " + strPostcode);
		}
	});
	localSearch.execute(strPostcode + ", UK");
}

function setLatitudeLongitude(dblLatitude, dblLongitude) {
	document.forms[0].latitude.value = dblLatitude;
	document.forms[0].longitude.value = dblLongitude;
	document.forms[0].geocodestatus.value = -1;
}

