function invia() {
	var args = invia.arguments;
	theForm = args[args.length-1];

	//alert(theForm.substr(theForm.length - 2, 2))

	if(args.length > 1) {
		for (i=0;i<=args.length-3;i+=2) {
			el = document.forms[theForm].elements[args[i]];
			if (el.value == '') {
				switch(theForm.substr(theForm.length - 2, 2)) {
					case "es":
						alert ('Rellene el campo ' + args[i+1] );
						break;

					case "it":
						alert ('Per favore specifica il campo ' + args[i+1] );
						break;

					case "en":
						alert ('Please specify the field ' + args[i+1] );
						break;
				}
				el.focus();
				return (false);
			}
		}

		if(document.getElementById("bisognoiscrizione")) {
			lIscrizione = document.getElementById("bisognoiscrizione");
			lScuola = document.getElementById("bisognoscuola");
			lCorsi = document.getElementById("bisognoinfocorsi");
			lAltro = document.getElementById("bisognoinfoaltro");
			lContattatemi = document.getElementById("bisognocontattatemi");
			if(lIscrizione.checked == false && lScuola.checked == false && lCorsi.checked == false && lAltro.checked == false && lContattatemi.checked == false) {
				switch(theForm.substr(theForm.length - 2, 2)) {
					case "es":
						alert ('Por favor, especifique lo que necesita!');
						break;

					case "it":
						alert ('Per favore indica di cosa hai bisogno!');
						break;

					case "en":
						alert ('Please specify what you need!');
						break;
				}
				return (false);
			}
		}

		if(document.forms[theForm].elements["privacy"].checked != true) {
				switch(theForm.substr(theForm.length - 2, 2)) {
					case "es":
						alert ('Usted necesita estar de acuerdo con la política de privacidad');
						break;

					case "it":
						alert ('Devi accettare le condizioni del trattamento dei dati personali ');
						break;

					case "en":
						alert ('You need to agree to privacy policy ');
						break;
				}
				return (false);
		}
	}

	document.forms[theForm].submit();
}

function sendForm(theName) {
document.forms[theName].submit();
}


function goCountry(theVal) {
	if(theVal != "") {
		/*vVal = theVal.split("|");
		theCountry = vVal[0];
		theCountryID = vVal[1];
		theDomain = vVal[2];*/
		//location.href = theDomain + "/index.php?country=" + theCountry + "&naz=" + theCountryID;
		//go('country', theCountry, 'naz', theCountryID, theDomain + '/index.php');
		location.href = theVal;
	}
}

function goArea(theVal) {
	if(theVal != "") {
		/*vVal = theVal.split("|");
		theCountry = vVal[0];
		theCountryID = vVal[1];
		theArea = vVal[2];
		theAreaID = vVal[3];*/
		//location.href = "schools.php?country=" + theCountry + "&naz=" + theCountryID + "&locality=" + theArea + "&area=" + theAreaID;
		//go('country', theCountry, 'naz', theCountryID, 'locality', theArea, 'area', theAreaID, 'schools.php');
		location.href = theVal;
	}
}

function goCourse(theVal) {
	if(theVal != "") {
		/*vVal = theVal.split("|");
		theCourse = vVal[0];
		theCourseID = vVal[1];
		go("course", theCourse, "courseid", theCourseID, "course.php");*/
		location.href = theVal;
	}
}

var openImg = new Image();
openImg.src = "http://schools-in-italy.studyabroadworld.org/_img/open.gif";
var closedImg = new Image();
closedImg.src = "http://schools-in-italy.studyabroadworld.org/_img/closed.gif";

function showCont(theKey, theTitle, theMode) {
	vVal = theKey.split("-");
	theBox = vVal[0];
	theID = vVal[1];
	theFullSet = "|p-" + theID + "|c-" + theID + "|g-" + theID + "|l-" + theID + "|a-" + theID + "|s-" + theID + "|f-" + theID + "|d-" + theID + "|m-" + theID + "|h-" + theID + "|";
	theSetToHide = theFullSet.replace("|" + theKey + "|", "|");
	theSetToHide = theSetToHide.substr(1, theSetToHide.length);
	theSetToHide = theSetToHide.substr(0, theSetToHide.length-1);
	vSetToHide = theSetToHide.split("|");
	if(!theMode) {
		for(i=0;i<vSetToHide.length;i++) {
			if(document.getElementById("cont"+vSetToHide[i])) {
				hideBranch("cont"+vSetToHide[i]);
			}
			if(document.getElementById("img"+vSetToHide[i])) {
				closeFolder("img"+vSetToHide[i]);
			}
		}
	}
	showBranch("cont"+theKey);
	if(theTitle && theTitle != "") {
		document.getElementById("detailsTitle").innerHTML = "<h3>" + theTitle + "</h3>"
	}
	if(document.getElementById("img"+theKey)) {
		swapFolder("img"+theKey);
	}
}

function showBranch(branch){
	var objBranch = document.getElementById(branch).style;
	var theDiv = document.getElementById(branch);
	var vDiv = theDiv.getElementsByTagName("div");

	/*if(objBranch.display=="block") {
		theStyle = "none";
	} else {
		theStyle = "block";
	}*/
	theStyle = "block";

	objBranch.display=theStyle;

	for(d=0;d<vDiv.length;d++) {
		vDiv[d].setAttribute("style", "display:" + theStyle + ";");
		vDiv[d].style.display = theStyle;
	}
}

function hideBranch(branch){
	var objBranch = document.getElementById(branch).style;
	objBranch.display="none";
}

function swapFolder(img){
	objImg = document.getElementById(img);
	if(objImg.src.indexOf('closed.gif')>-1)
		objImg.src = openImg.src;
	else
		objImg.src = closedImg.src;
}

function closeFolder(img){
	objImg = document.getElementById(img);
	objImg.src = closedImg.src;
}
