
// ===== Forms =====================================================================================

function currentPage () {
	var id = document.createAttribute("id");
	id.nodeValue = "here"; 
	//
	for (var i = 0; i < document.links.length; i++) {
		if (document.links[i].search == window.location.search) {
			document.links[i].setAttributeNode(id);
		}
	}
}

// Check all

function checkAll (index) {
	lengthOfElements = document.forms[index].elements.length;
	for (var i = 0; i <= lengthOfElements; i++) {
		document.forms[index].elements[i].checked = true;
	}
}


// Check non-empty fields only

function checkNonEmpty (index) {
	lengthOfElements = document.forms[index].elements.length;
	for (var i = 0; i <= lengthOfElements; i++) {
		if (document.forms[index].elements[i].value) {
			document.forms[index].elements[i].checked = true;
		}
	}
}


// Check none

function checkNone (index) {
	lengthOfElements = document.forms[index].elements.length;
	for (var i = 0; i <= lengthOfElements; i++) {
		if (document.forms[index].elements[i].value) {
			document.forms[index].elements[i].checked = false;
		}
	}
}


// Reset form

function resetForm (index) {
	document.forms[index].reset();
}


// Submit form

function submitForm (form) {
	document.forms[form].submit();
}


// Submit an action

function submitAction (form,action) {
	document.forms[form].setAttribute("action", action);
	document.forms[form].submit();
}

//===== Strings ====================================================================================

// Converts a string into an ASCII string.

function stringToASCII (string) {
	// Unicode of non ASCII chars.
	codes = new Array(
	'224','225','226','227','228','229', // ˆ, ‡, ‰, ‹, Š, Œ
	'232','233','234','235',             // , Ž, , ‘
	'236','237','238','239',             // “, ’, ”, •
	'242','243','244','245','246',       // ˜, —, ™, ›, š
	'249','250','251','252',             // , œ, ž, Ÿ
	'223','231','241','32'               // §, , –, Space
	);
	// Maps non ASCII chars to ASCII chars.
	chars = new Array(
	'a','a','a','a','ae','a',
	'e','e','e','e',
	'i','i','i','i',
	'o','o','o','o','oe',
	'u','u','u','ue',
	'ss','c','n',''
	);
	//
	var newString = "";
	//
	for(var i = 0; i < string.length; i++) {
		var code = string.charCodeAt(i);
		//
		if(code == 45 || (code > 64 && code < 91) || (code > 96 && code < 123)) {
			newString += string.charAt(i);
		}
		else {
			for(var j = 0; j < codes.length; j++) {
				if(code == codes[j]) {
					newString += chars[j];
					break;
				}
			}
		}
	}
	//
	return newString;
}


// Auto short name

function shortName (shortNames) {
	var arrShortNames = shortNames.toLowerCase().split(",");
	var firstName = document.forms[0].first_name.value.toLowerCase();
	//
	var shortName = stringToASCII(firstName);
	for(var i = 0; i <= arrShortNames.length; i++) {
		var j = 0;
		if(shortName == arrShortNames[i]) {
			j++;
			var shortName = stringToASCII(firstName)+j;
		}
	}
	//
	document.forms[0].short_name.value = shortName;
}

