// Include: <script language="JavaScript" type="text/JavaScript" src="app/code/client/UI_inc.js"></script>
// Include: <script language="JavaScript" type="text/JavaScript" src="app/code/client/Search_inc.js"></script>

function processKey(e)
{
	var keyPressed;
	if (window.event) keyPressed = e.keyCode;  // IE
	else if (e.which) keyPressed = e.which  ;  // Others
	if (keyPressed==13)
	{
		document.Form.botProofing.value='activated';
		gui.onClickSubmit();
	}
}

function Search(langPar, guestPar, adminPar, formPar){
	// Inherit UI Class.
	this.inheritUI = UI; this.inheritUI(langPar, guestPar, adminPar, formPar);

	// Data members.

	// Member functions.
	this.jump = jump;
	this.appendName = appendName;
	this.onClickRandom = onClickRandom;
	this.onClickRecent = onClickRecent;
 	this.onClickClear = onClickClear;
	this.validate = validateNew;
}

	function jump(rpp, cp){
		if ((rpp != null) && (cp != null)){
			this.uiForm.RPP.value = rpp;
			this.uiForm.CP.value = cp;
			this.uiForm.submit();
		}
	}

	function appendName(field, list){
		field.value += (field.value != "" ? " " : "") + list.value;
		list.options[0].selected = true;
	}

	function onClickRandom(){
		this.uiForm.SubType.value = "Random";
		if (this.validate()) this.uiForm.submit();
	}

	function onClickRecent(){
		this.uiForm.SubType.value = "Recent";
		if (this.validate()) this.uiForm.submit();
	}

	function onClickClear(){
		for (var i = 0; i < this.uiForm.length; i++){
			var x = this.uiForm.elements[i];
			switch (x.type){
				case "text":
					x.value = "";
					break;
				case "checkbox":
					x.checked = false;
					break;
				case "select-one":
					if (x.name != "Language"){
						if (x.options[0] != null){
							x.options[0].selected = true;
							x.options[0].selected = false;
						}
					}
					break;
				case "button":
					break;			
				case "hidden":
					x.value = "";
					break;
			}
		}
	}

	function validateNew(){
		var message = "";

		// Validate form data.
		if (this.language == "fr"){
/*			if (this.uiForm.Username.value == "") message += "- [Username cannot be empty].\n";
			if (this.uiForm.Password.value == "") message += "- [Password cannot be empty].\n";
*/		}
		else {
/*			if (this.uiForm.Username.value == "") message += "- Username cannot be empty.\n";
			if (this.uiForm.Password.value == "") message += "- Password cannot be empty.\n";
*/		}

		if (message == ""){
			return true;
		}
		else {
			if (this.language == "fr"){
				window.alert("[The following must be resolved before submitting]:\n\n" + message);
			}
			else {
				window.alert("The following must be resolved before submitting:\n\n" + message);
			}
			return false;
		}
	}
