function checkSearch(theElement) {
	if (theElement == "") {
		alert("Please enter a value for the \"Search\" field.");
		return false;
	} else {
		window.location.href = '../pages/range.asp?content_area=3&keyword_search=' + theElement;
	}
}

function showSubNavi(theArea) {
	theArea = document.getElementById('content_area' + theArea);
	if (theArea) {
		theArea.style.display = 'block';
	}
}

function changeImage(element) {
	element = document.getElementById('thumb' + element).src;
	document.getElementById('mainImage').src = element.replace("th_", "");
}

function checkSignup(theForm) {
	if (theForm.register_name.value == "" || theForm.register_name.value == "Name") {
		alert("Please enter a value for the \"Name\" field.");
		theForm.register_name.focus();
		return false;
	}
	
	if (email_regex.test(theForm.register_email.value) == false) {
		alert("You must provide a valid e-mail address, please try again");
		theForm.register_email.focus();
		return false;
	}

	return true;
}

function postcodeMap(postcode) {
	if (navigator.javaEnabled() == true) {
		return 'http://link2.map24.com/?lid=03763162&amp;maptype=JAVA&amp;width0=1500&amp;zip0=' + postcode.replace(' ', '+') + '&amp;country0=GB';
	} else {
		return 'http://www.multimap.com/map/browse.cgi?client=public&amp;db=pc&amp;cidr_client=none&amp;pc=' + postcode.replace(' ', '+');
	}
}

function theflash(movie, width, height) {
	document.writeln('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + width + '" height="' + height + '">');
    document.writeln('<param name="movie" value="../%27%20+%20movie%20+%20%27">');
	document.writeln('<param name="quality" value="high" />');
	document.writeln('<param name="menu" value="false">');
	document.writeln('<param name="wmode" value="transparent">');
	document.writeln('<embed src="../%27%20+%20movie%20+%20%27" width="' + width + '" height="' + height + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" menu="false" wmode="transparent"></embed>');
    document.writeln('</object>');
}

//Set Cookie Function
function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) + 
	((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	((secure == null) ? "" : "; secure");
}

function open_window(fileName, windowName, windowWidth, windowHeight, scrollbars, resizable) {
	window.open(fileName, windowName, 'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=' + scrollbars + ', resizable=' + resizable + ', left=' + centre(windowWidth, screen.availWidth) + ', top=' + centre(windowHeight, screen.availHeight) + ', width=' + windowWidth + ', height=' + windowHeight);
}

function centre(size,area) {
	return (area/2)-(size/2);
}

function returnNumbers(field) {
	var regex = /^[0-9+\.]*$/;
    if (!regex.test(field.value)) {
       field.value = field.value.replace(/[^0-9+\.]/g,"");
	}
}

function changeVisibility(element, action) {
	if (document.getElementById(element)) {
		switch (action) {
			case "show":
				document.getElementById(element).style.visibility = "visible";
				break;
			case "hide":
				document.getElementById(element).style.visibility = "hidden";
				break;
			default:return;
		}
	}
}

function toggleOverflow(element) {
	if (document.getElementById('sector_' + element).style.overflow != "visible") {
		document.getElementById('sector_' + element).style.overflow = "visible";
		document.getElementById('sector_' + element).style.height = "auto";
		document.getElementById('sectora_' + element).title = "Collapse";
		document.getElementById('sectora_' + element).innerHTML = "Collapse";
	} else {
		document.getElementById('sector_' + element).style.overflow = "hidden";
		document.getElementById('sector_' + element).style.height = "160px";
		document.getElementById('sectora_' + element).title = "Expand";
		document.getElementById('sectora_' + element).innerHTML = "Expand";
	}
}

// Admin Functions //
var whichList;

function changeHidden(theElement, theHidden) {
	//whichList = theElement;
	theHidden.value += theElement.options[theElement.selectedIndex].value.substring(0, theElement.options[theElement.selectedIndex].value.indexOf('|'));
}

function colourBars() {
	var even = false;
	var evenColor = "#FFFFFF";
	var oddColor = "#ECECEC";
	var thearea = document.getElementById('1table');
	var trs = thearea.getElementsByTagName('tr');
	for (var i = 0; i < trs.length; i++) {
		trs[i].style.backgroundColor = even ? evenColor : oddColor;
		even =  ! even;
	}
}

function checkLogout() {
	if (confirm('Are you sure you want to logout?') == true) {
		window.location.href = '../edit/index.asp?logout=true';
	}
}


function checkALL(checkbox, theElement) {
	for (i = 0; i < document.getElementsByName('' + theElement + '').length; i++) {
		document.getElementsByName('' + theElement + '')[i].checked = checkbox.checked;
	}
}

function checkCancel(theLink) {
	if (confirm('Are you sure you want to cancel these changes?') == true) {
		window.location.href = theLink;
	}
}

function getFCKContent() { 
	var api = FCKeditorAPI.GetInstance("richMessage"); 
	return api.GetHTML(); 
}

function previewEditor(theForm) {
	var theAction = theForm.action;
	theForm.action = '../edit/preview_content.asp';
	theForm.target = 'previewWindow';
	theForm.submit();
	theForm.action = theAction;
	theForm.target = '_top';
}

function submitOnEnter(theEvent, theAction) {
	theEvent = (theEvent) ? theEvent : event;
	var charCode = (theEvent.charCode) ? theEvent.charCode :
		((theEvent.which) ? theEvent.which : theEvent.keyCode);
	if (charCode == 13 || charCode == 3) {
		document.getElementById(theAction).click();
	}
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
} // Ends the "getSelectedRadioValue" function

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // Ends the "getSelectedCheckbox" function

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
} // Ends the "getSelectedCheckBoxValue" function