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 checkSearch(theElement) {
	if (theElement.value != "") {
		window.location.href = "../pages/products.asp?search=" + theElement.value;
	}
}

function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) {
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById || operaVersion < 7) return;
	var imgarr = document.getElementsByTagName('img');
	var imgPreload = new Array();
	var imgSrc = new Array();
	var imgClass = new Array();
	for (i = 0; i < imgarr.length; i++) {
		if (imgarr[i].className.indexOf('domroll') != -1){
			imgSrc[i] = imgarr[i].getAttribute('src');
			imgClass[i] = imgarr[i].className;
			imgPreload[i] = new Image();
			if (imgClass[i].match(/domroll (\S+)/)) {
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover = function() {
				this.setAttribute('src', '../images/layup/' + this.className.match(/domroll (\S+)/)[1])
			}
			imgarr[i].onmouseout = function() {
				this.setAttribute('src', this.getAttribute('xsrc'))
			}
		}
	}
}

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="' + movie + '">');
	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="' + movie + '" 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,"");
	}
}

// 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 previewImage() {
	if (whichList) {
		var imageURL = 'preview_image.asp?image=../images/uploads/' + whichList.options[whichList.selectedIndex].value.substring(whichList.options[whichList.selectedIndex].value.lastIndexOf('|') + 1);
		open_window(imageURL, 'imagePreview', 50, 50, 'no', 'no')
	}
}

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 returnNumbers(field) {
	var regex = /^[0-9+\.]*$/;
    if (!regex.test(field.value)) {
       field.value = field.value.replace(/[^0-9+\.]/g,"");
	}
}

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