	// Used to fill listboxes
	function addOption(selectID, sText, nValue)
	{
		var bDefault = (addOption.arguments[3])?addOption.arguments[3]: false;
		var bSelected = (addOption.arguments[4])?addOption.arguments[4]: false;
		
		oSelect = document.getElementById(selectID);
		oOption = new Option(sText, nValue, bDefault, bSelected);
		oSelect.options[oSelect.length] = oOption;
	}
	
	function check_creditcard(oCCNum, oCCType, oCCXMo, oCCXYr, oCCCCv)
	{
		var ccnum = oCCNum.value;
		var cctype = oCCType.options[oCCType.selectedIndex].value; 
		var ccxmo = parseInt(oCCXMo.options[oCCXMo.selectedIndex].value,10); 
		var ccxyr = parseInt(oCCXYr.options[oCCXYr.selectedIndex].value,10); 
		var ccccv = oCCCCv.value;

		if (!valid_ccnumber(ccnum)) {
			set_message("Invalid Credit Card number"); 
			set_class(document.getElementById('l' + oCCNum.id), 'labelWarn');
			return false; 
		}
		if (!valid_cctype(ccnum, cctype)) {
			set_class(document.getElementById('l' + oCCNum.id), 'labelWarn');
			set_class(document.getElementById('l' + oCCType.id), 'labelWarn');
			set_message("Card type doesn't match card number"); 
			return false; 
		}
		if (!valid_expiry(ccxmo, ccxyr)) {
			set_class(document.getElementById('lcust_ccexp'), 'labelWarn');
			set_message("Invalid Expiration Date"); 
			return false; 
		}
		if (!valid_ccv(ccccv)) {
			set_class(document.getElementById('lcust_ccccv'), 'labelWarn');
			set_message("Invalid CCV"); 
			return false; 
		}
		
		return true;		
	}
	
	function check_email(oEmail)
	{
  	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
    var regex = new RegExp(emailReg);
    if (!regex.test(oEmail.value)) {
			set_message("Invalid Email"); 
			set_class(document.getElementById('l' + oEmail.id), 'labelWarn');
			return false; 
		}	
		return true;	
	}

	function load_page(sPage)
	{
		var shref = document.location.href;
		var sCurrPage = shref.substr(shref.lastIndexOf("/")+1);
		switch (sPage)
		{
			case "AddTour":
				if (sCurrPage == 'tour_edit.php')
					form_reset();
				else
					document.location = "tour_edit.php";
				break;
			case "EditTour":
				if (sCurrPage != "tour_edit.php?edit=true")
					document.location = "tour_edit.php?edit=true";
				break;
			case "DisplayTours":
				if (sCurrPage != "tour_list.php")
					document.location = "../tour_list.php";
				break;
			case "EditCustomers":
				if (sCurrPage != "customer_edit.php")
					document.location = "customer_edit.php";
				break;
			case "ListPassengers":
				if (sCurrPage != "passengers_list.php")
					document.location = "passengers_list.php";
				break;
		}
	}

	function missing_input(oForm, aFields)
	{
		var bMissing = false;
		
		for (i=0; i<aFields.length; i++) {
			oElement = oForm.elements[aFields[i]];
			switch (oElement.type)
			{
				case "text":
				case "textarea":
					if (oElement.value == '') {
						set_class(document.getElementById('l' + oElement.id), 'labelWarn');
						bMissing = true;
					}
					break;
					
				case "select-one":
					if (oElement.selectedIndex == 0) {
						set_class(document.getElementById('l' + oElement.id), 'labelWarn');
						bMissing = true;
					}
					break;
				
			}
		}			// End of for loop
			
		if (bMissing)
			set_message("Please fill-in the missing information");
		else
			set_message('');
			
		return bMissing;		
	}

	function reset_labels()
	{
		// Reset Message
		oMsg = document.getElementById('message');
		if (oMsg != null)
			document.getElementById('message').innerHTML = '';
		
		oSpan = document.getElementsByTagName("SPAN");
		for (i=0; i<oSpan.length; i++)
		{
			if (oSpan[i].className == 'labelWarn')
				set_class(oSpan[i], "label");
		}
	}

	function run_code(sCode)
	{		
		if (document.all)
			window.frames["runCode"].location = sCode;
		else
			top.document.getElementById('runCode').contentDocument.location = sCode;
	}

	function set_class(obj, sName)
	{
		if (document.all)
			obj.setAttribute('className',sName, 0);
		else
			obj.className = sName;
	}
	
	function set_message(sMsg)
	{
		document.getElementById('message').innerHTML = sMsg;
	}
	
