
function Repertoriu() {
	check = document.getElementById("concurs").checked;
	if (check) {
		document.getElementById("categdiv").style.display='block';
		document.getElementById("categoria").selectedIndex = 0;
		//alert(document.getElementById("categoria").selectedIndex);

		linie = document.getElementById('alldivs');
		linie.style.display='block';
		linie = document.getElementById('head');
		linie.style.display='block';
		linie = document.getElementById('autor222');
		linie.style.display='block';
		linie = document.getElementById('titlu222');
		linie.style.display='block';
		linie = document.getElementById('perioada222');
		linie.style.display='block';
		linie = document.getElementById('durata222');
		linie.style.display='block';
		linie = document.getElementById('nr');
		linie.style.display='block';

	} else {
		document.getElementById("categdiv").style.display='none';
		document.getElementById("categoria").selectedIndex = 0;

		linie = document.getElementById('alldivs');
		linie.style.display='none';
		linie = document.getElementById('head');
		linie.style.display='none';
		linie = document.getElementById('autor222');
		linie.style.display='none';
		linie = document.getElementById('titlu222');
		linie.style.display='none';
		linie = document.getElementById('perioada222');
		linie.style.display='none';
		linie = document.getElementById('durata222');
		linie.style.display='none';
		linie = document.getElementById('nr');
		linie.style.display='none';

		for (j = 1; j<=6; j++) {
			linie = document.getElementById('autor1'+j);
			linie.style.display='none';
			linie = document.getElementById('titlu1'+j);
			linie.style.display='none';
			linie = document.getElementById('perioada1'+j);
			linie.style.display='none';
			linie = document.getElementById('durata1'+j);
			linie.style.display='none';
			linie = document.getElementById('nr'+j);
			linie.style.display='none';
		}
	}
}

function Repertoriumc() {
	check = document.getElementById("concursmc").checked;
	if (check) {
		document.getElementById("categdivmc").style.display='block';
		document.getElementById("categoriamc").selectedIndex = 0;
		//alert(document.getElementById("categoria").selectedIndex);

		linie = document.getElementById('alldivsmc');
		linie.style.display='block';
		linie = document.getElementById('head');
		linie.style.display='block';
		linie = document.getElementById('autormc222');
		linie.style.display='block';
		linie = document.getElementById('titlumc222');
		linie.style.display='block';
		linie = document.getElementById('perioadamc222');
		linie.style.display='block';
		linie = document.getElementById('duratamc222');
		linie.style.display='block';
		linie = document.getElementById('nrmc');
		linie.style.display='block';

	} else {
		document.getElementById("categdivmc").style.display='none';
		document.getElementById("categoriamc").selectedIndex = 0;

		linie = document.getElementById('alldivsmc');
		linie.style.display='none';
		linie = document.getElementById('head');
		linie.style.display='none';
		linie = document.getElementById('autormc222');
		linie.style.display='none';
		linie = document.getElementById('titlumc222');
		linie.style.display='none';
		linie = document.getElementById('perioadamc222');
		linie.style.display='none';
		linie = document.getElementById('duratamc222');
		linie.style.display='none';
		linie = document.getElementById('nr');
		linie.style.display='none';

		for (j = 1; j<=6; j++) {
			linie = document.getElementById('autormc1'+j);
			linie.style.display='none';
			linie = document.getElementById('titlumc1'+j);
			linie.style.display='none';
			linie = document.getElementById('perioadamc1'+j);
			linie.style.display='none';
			linie = document.getElementById('duratamc1'+j);
			linie.style.display='none';
			linie = document.getElementById('nrmc'+j);
			linie.style.display='none';
		}
	}
}

function facateg(categ){
	//var i,j,linie;

	if (categ == "-") {
		for (j = 1; j<=6; j++) {
			linie = document.getElementById('autor1'+j);
			linie.style.display='none';
			linie = document.getElementById('titlu1'+j);
			linie.style.display='none';
			linie = document.getElementById('perioada1'+j);
			linie.style.display='none';
			linie = document.getElementById('durata1'+j);
			linie.style.display='none';
			linie = document.getElementById('nr'+j);
			linie.style.display='none';
		}
	} else
	if (categ == 'A' || categ == 'B' || categ == 'C') {
		linie = document.getElementById("etapa1");
		linie.style.display='none';
		linie.style.height='1px';
		linie = document.getElementById("etapa2");
		linie.style.display='none';
		linie.style.height='1px';
		for (i = 1; i<=3; i++){
			linie = document.getElementById('autor1'+i);
			linie.style.display='block';
			linie = document.getElementById('titlu1'+i);
			linie.style.display='block';
			linie = document.getElementById('perioada1'+i);
			linie.style.display='block';
			linie = document.getElementById('durata1'+i);
			linie.style.display='block';
			linie = document.getElementById('nr'+i);
			linie.style.display='block';
		}
		for (j = 4; j<=6; j++) {
			linie = document.getElementById('autor1'+j);
			linie.style.display='none';
			linie = document.getElementById('titlu1'+j);
			linie.style.display='none';
			linie = document.getElementById('perioada1'+j);
			linie.style.display='none';
			linie = document.getElementById('durata1'+j);
			linie.style.display='none';
			linie = document.getElementById('nr'+j);
			linie.style.display='none';
		}
	} else

	if (categ == 'D') {
		linie = document.getElementById("etapa1");
		linie.style.display='block';
		linie = document.getElementById("etapa2");
		linie.style.display='block';
		for (i = 1; i<=6; i++){
			linie = document.getElementById('autor1'+i);
			linie.style.display='block';
			linie = document.getElementById('titlu1'+i);
			linie.style.display='block';
			linie = document.getElementById('perioada1'+i);
			linie.style.display='block';
			linie = document.getElementById('durata1'+i);
			linie.style.display='block';
			linie = document.getElementById('nr'+i);
			linie.style.display='block';
		}
	}
}

function facategmc(categ){
	//var i,j,linie;

	if (categ == "-") {
		for (j = 1; j<=5; j++) {
			linie = document.getElementById('autormc1'+j);
			linie.style.display='none';
			linie = document.getElementById('titlumc1'+j);
			linie.style.display='none';
			linie = document.getElementById('perioadamc1'+j);
			linie.style.display='none';
			linie = document.getElementById('duratamc1'+j);
			linie.style.display='none';
			linie = document.getElementById('nrmc'+j);
			linie.style.display='none';
		}
	} else
	if (categ == 'A mc') {
		for (i = 1; i<=2; i++){
			linie = document.getElementById('autormc1'+i);
			linie.style.display='block';
			linie = document.getElementById('titlumc1'+i);
			linie.style.display='block';
			linie = document.getElementById('perioadamc1'+i);
			linie.style.display='block';
			linie = document.getElementById('duratamc1'+i);
			linie.style.display='block';
			linie = document.getElementById('nrmc'+i);
			linie.style.display='block';
		}
		j = 3;
		linie = document.getElementById('autormc1'+j);
		linie.style.display='none';
		linie = document.getElementById('titlumc1'+j);
		linie.style.display='none';
		linie = document.getElementById('perioadamc1'+j);
		linie.style.display='none';
		linie = document.getElementById('duratamc1'+j);
		linie.style.display='none';
		linie = document.getElementById('nrmc'+j);
		linie.style.display='none';
	} else

	if (categ == 'B mc') {
		for (i = 1; i<=3; i++){
			linie = document.getElementById('autormc1'+i);
			linie.style.display='block';
			linie = document.getElementById('titlumc1'+i);
			linie.style.display='block';
			linie = document.getElementById('perioadamc1'+i);
			linie.style.display='block';
			linie = document.getElementById('duratamc1'+i);
			linie.style.display='block';
			linie = document.getElementById('nrmc'+i);
			linie.style.display='block';
		}
	}
}

function UnCheck() {
	document.getElementById("concurs").checked=false;
	document.getElementById("categoria").selectedIndex = 0;
}

function Verifica() {
	nume = document.getElementById("nume").value;
	obj  = document.getElementById("categoria");
	val = obj.options[obj.selectedIndex].value;
	capt = document.getElementById("captcha").value;
	if (!capt) {
		alert("Please fill in the security code!");
		return false;
	}
	var nr = 3;
	if (val == "D") {
		nr = 4;
	}
	if (nume == "") {
		alert("'Name' is compulsory!");
		return false;
	}
	localitate = document.getElementById("localitate").value;
	if (localitate == "") {
		alert("'City, Country' is compulsory!");
		return false;

	}
	mail = document.getElementById("mail").value;
	if (mail == "") {
		alert("'E-mail' is compulsory!");
		return false;
	}
	if (!Validate_Email_Address(mail)) {
		alert("Invalid e-mail address!");
		return false;
	}

	date = document.getElementById("luna").value+"/";
	date += document.getElementById("zi").value+"/";
	date += document.getElementById("an").value;

	if (!isDate(date)) {
		alert("Invalid date of birth!");
		return false;
	}

	master  = document.getElementById("masterclass");
	concurs = document.getElementById("concurs");
	concursmc = document.getElementById("concursmc");

	ok = 1;
	if (!concurs.checked && !concursmc.checked && !master.checked) {
		alert("Please select at least one category: contest, chmaber music contest or master class courses!");
		return false;
	}
	if (concurs.checked) {
		if (val == "-") {
			alert("Please select a contest category!");
			return false;
		}
		for (i = 1; i<=nr; i++) {
			autor = document.getElementById("autor"+i);
			//alert(autor.value);
			titlu = document.getElementById("titlu"+i);
			perioada = document.getElementById("perioada"+i);
			durata = document.getElementById("durata"+i);

			if (autor.value=="") {
				alert("'Author' is compulsory!");
				return false;
			}
			if (titlu.value=="") {
				alert("'Title' is compulsory!");
				return false;
			}
			if (perioada.value=="") {
				alert("'Period' is compulsory!");
				return false;
			}
			if (durata.value=="") {
				alert("'Duration' is compulsory!");
				return false;
			}
		}

	}
	if (concursmc.checked) {
		obj  = document.getElementById("categoriamc");
		val = obj.options[obj.selectedIndex].value;
		if (val == "-") {
			alert("Please select a chamber music contest category! ");
			return false;
		}
		nr = 3;
		if (val == "A mc") {
			nr = 2;
		}
		for (i = 1; i<=nr; i++) {
			autor = document.getElementById("autormc"+i);
			//alert(autor.value);
			titlu = document.getElementById("titlumc"+i);
			perioada = document.getElementById("perioadamc"+i);
			durata = document.getElementById("duratamc"+i);

			if (autor.value=="") {
				alert("'Author' is compulsory!");
				return false;
			}
			if (titlu.value=="") {
				alert("'Title' is compulsory!");
				return false;
			}
			if (perioada.value=="") {
				alert("'Period' is compulsory!");
				return false;
			}
			if (durata.value=="") {
				alert("'Duration' is compulsory!");
				return false;
			}
		}

		if (!document.getElementById("numemc1")) {
			alert("Please specify the members of the chamber music formation!");
			return false;

		}
	}
	document.getElementById("form").submit();
}

function showhide(layer_ref, state) {

	if (state == 'visible') {
		state = 'hidden';
	}
	else {
		state = 'visible';
	}
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.visibility = " + state);
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].visibility = state;
	}
	if (document.getElementById && !document.all) {
		maxwell_smart = document.getElementById(layer_ref);
		maxwell_smart.style.visibility = state;
	}
}

/*
* date validation script
*/

function isInteger(s){
	var i;
	for (i = 0; i < s.length; i++){
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}

function stripCharsInBag(s, bag){
	var i;
	var returnString = "";
	// Search through string's characters one by one.
	// If character is not in bag, append to returnString.
	for (i = 0; i < s.length; i++){
		var c = s.charAt(i);
		if (bag.indexOf(c) == -1) returnString += c;
	}
	return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	}
	return this
}

function isDate(dtStr){
	var dtCh= "/";
	var minYear=1941;
	var maxYear=2005;
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format is: dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Specify a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Specify a valid day")
		return false
	}
	if (strYear.length != 4 || year==0){
		alert("Specify an year between "+minYear+" and "+maxYear)
		return false
	}
	if (year<minYear) {
		alert("Invalid year");
		return false
	}
	if (year>maxYear) {
		alert("Invalid year");
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Invalid date of birth")
		return false
	}
	return true;
}

/*
* valideaza e-mail
*/
function Validate_String(string, return_invalid_chars)
{
	valid_chars = '1234567890-_.^~abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	invalid_chars = '';

	if(string == null || string == '')
	return(true);

	//For every character on the string.
	for(index = 0; index < string.length; index++)
	{
		char_ = string.substr(index, 1);

		//Is it a valid character?
		if(valid_chars.indexOf(char_) == -1)
		{
			//If not, is it already on the list of invalid characters?
			if(invalid_chars.indexOf(char_) == -1)
			{
				//If it's not, add it.
				if(invalid_chars == '')
				invalid_chars += char_;
				else
				invalid_chars += ', ' + char_;
			}
		}
	}

	//If the string does not contain invalid characters, the function will return true.
	//If it does, it will either return false or a list of the invalid characters used
	//in the string, depending on the value of the second parameter.
	if(return_invalid_chars == true && invalid_chars != '')
	{
		last_comma = invalid_chars.lastIndexOf(',');

		if(last_comma != -1)
		invalid_chars = invalid_chars.substr(0, $last_comma) +
		' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);

		return(invalid_chars);
	}
	else
	return(invalid_chars == '');
}


function Validate_Email_Address(email_address) {
	//Assumes that valid email addresses consist of user_name@domain.tld
	at = email_address.indexOf('@');
	dot = email_address.indexOf('.');

	if(at == -1 ||
	dot == -1 ||
	dot <= at + 1 ||
	dot == 0 ||
	dot == email_address.length - 1)
	return(false);

	user_name = email_address.substr(0, at);
	domain_name = email_address.substr(at + 1, email_address.length);

	if(Validate_String(user_name) === false ||
	Validate_String(domain_name) === false)
	return(false);

	return(true);
}

function moremc() {
	var obj = document.getElementById("moremc");
	disp = "";
	if (obj.style.display == "none") {
		disp = "block";
	} else {
		disp = "none";
	}
	obj.style.display = disp;
}

function solicit_cazaref(disp) {
	document.getElementById("cazare_div").style.display = disp;
}

function generate_image() {
	/*document.getElementById("captcha_img").src = "captcha.png";//"generate_image.php";
	document.getElementById("captcha_img").src = "generate_image.php";*/
	if (document.images)
        parent.frames[0].location.reload();
    else
        parent.frames[0].location.href = parent.frames[0].location.href
}