// Localisable content
var loc_strings = new Array(
	new Array(
		"en", "Enter search term", 
		"ga", "Cuir isteach do téarma"
	),
	new Array(
		"en", "Enter your query here", 
		"ga", "Cuir isteach do cheist anseo"
	),
	new Array(
		"en", "Enter your query here", 
		"ga", "Cuir isteach d'iarratas anseo"
	),
	new Array(
		"en", "Please type in your query",
		"ga", "Cuir isteach do cheist le do thoil"
	),
	new Array(
		"en", "Please enter a valid email address",
		"ga", "Cuir isteach ríomhsheoladh bailíoch le do thoil"
	)
);


function get_loc_string(src_str, lang_code){
	if(lang_code == ""){
		return src_str;
	}
	else{
		for(var ii in loc_strings){
			term = loc_strings[ii];
			var found_src = false;
			for(var jj = 0; jj < term.length; jj++){
				if(found_src){
					if(term[jj] == lang_code){
						return term[jj + 1];
					}
				}
				else{
					if(term[jj] == "en"){
						if(term[jj + 1] == src_str){
							found_src = true;
						}
						else{
							break;
						}
					}
				}
			}
		}
		return src_str;
	}
}


function get_lang_code(){
	var pathName = location.pathname;
	
	if(pathName == "/"){
		return "";
	}
	else{
		// Strip off path
		var parts = pathName.split("/");
		pathName = parts[parts.length - 1];
		if(pathName == "" || pathName.charAt(0) == "."){
			return "";
		}
		else{
			// Strip off file extension
			var ii = pathName.length - 1;
			while(ii >= 0){
				if(pathName.charAt(ii) == "."){
					pathName = pathName.substring(0, ii);
					break;
				}
				ii--;
			}
			// Has the filename got a language code?
			if(pathName.charAt(pathName.length - 3) == "_"){
				return pathName.substring(pathName.length - 2);
			}
			else{
				return "";
			}
		}
	}
}
var lang_code = get_lang_code();


function documentLoad() {
	document.forms[0].q.value = get_loc_string('Enter search term', lang_code);
}

function clearSearch() {
	if (document.forms[0].q.value== get_loc_string('Enter search term', lang_code)) {
		document.forms[0].q.value='';
	}
	if (document.forms[1] && document.forms[1].query) {
		if (
			(document.forms[1].query.value==get_loc_string('Enter your query here', lang_code)) ||
			(document.forms[1].query.value==get_loc_string('Enter request here', lang_code))
		) {
			document.forms[1].query.value='';
		}
	}
}

function checkMandatoryFields() {
	if (document.forms[1].query.value == "") {
		document.forms[1].query.focus();
		alert(get_loc_string("Please type in your query", lang_code));
		return false;
	} else {
	        return true;
	}
}

function checkValidEmail() {
	if (
		(document.forms[1].email.value.indexOf("@") + "" != "-1") && 
		(document.forms[1].email.value.indexOf(".") + "" != "-1")) {
		return true;
	} else {
		document.forms[1].email.focus();
		alert(get_loc_string("Please enter a valid email address", lang_code));
		return false;
	}
}

