// JavaScript Document
function loading (){
	init(); //functie definita in popcalendar.js
	document.getElementById("loading").style.display="none";
	document.getElementById("allcontent").style.display="block";
}
function show(elem){
	document.getElementById(elem).style.display="block";
}
function hide(elem){
	document.getElementById(elem).style.display="none";
}
function showHideDivTransferati(elem,selectobj){
	list = document.forms[0].transferat;
	//alert (list.options[list.selectedIndex].value);
	if (list.options[list.selectedIndex].value!=0) {
		document.getElementById(elem).style.display="block";
	} else {
		document.getElementById(elem).style.display="none";
	}
	
}
function showHideDivEliminati(elem){
	list = document.forms[0].eliminat;
	//alert (list.options[list.selectedIndex].value);
	if (list.options[list.selectedIndex].value!=0) {
		document.getElementById(elem).style.display="block";
	} else {
		document.getElementById(elem).style.display="none";
	}
	
}
function showHideDivExmatriculati(elem){
	list = document.forms[0].exmatriculat;
	//alert (list.options[list.selectedIndex].value);
	if (list.options[list.selectedIndex].value!=0) {
		document.getElementById(elem).style.display="block";
	} else {
		document.getElementById(elem).style.display="none";
	}
	
}
function showDivNepromovati(elem,idelev){
	document.getElementById(elem).style.display="block";
	document.form1.elements['idelev'].value=idelev;
	//alert (idelev);
	//document.forma.submit();	
}
function checkForm(f,must,msgval) {

   var must_arr=must.split(",");
   var msgval_arr=msgval.split(",");
   var msg;
   var empty_fields="";
   for (var i = 0; i < must_arr.length; i++) {
        e=must_arr[i];
        //alert (e);
        if (f.elements[e].value == "") {
        //if (f.elements[i].value == "") {
                empty_fields+="- "+ msgval_arr[i] + "\n";
        }
   }
/*  if (!(f.email.value.match(/\b(^(\S+@).+((\.biz)|(\.info)|(\.name)|(\.pro)|(\.aero)|(\.coop)|(\.museum)|(\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi))) {
              empty_fields+="- The email entered is invalid! \n";
  }*/
   if (empty_fields) {
        msg="____________________________________________________________________________ \n\n";
        msg+="Va rugam sa completati campurile de mai jos: \n";
        msg+=empty_fields;
        msg+="____________________________________________________________________________ \n\n";
        alert(msg);
        return false;
   }
   else {
        //return true;
                document.form1.submit();
   }

  }

function checkFormSpecial(f) {
    var isclass=0;
	var form = document.forms[0];
	//alert(form.clasa.length);
	for (var i = 0; i < form.clasa.length; i++) {
		if (form.clasa[i].checked) {
			isclass=1;
			break;
		}
	}
	if (form.clasa.checked) {
		isclass=1;
	}
	
   var msg;
   var empty_fields="";
/*   if (f.elements["anstudiu"].value == "") {
                empty_fields+="- An studiu \n";
   }*/
   if (!isclass) {
                empty_fields+="- Clasa \n";
   }
   if (empty_fields) {
        msg="____________________________________________________________________________ \n\n";
        msg+="Va rugam sa completati campurile de mai jos: \n";
        msg+=empty_fields;
        msg+="____________________________________________________________________________ \n\n";
        alert(msg);
        return false;
   }
   else {
        //return true;
                document.form1.submit();
   }

  }

function deletereg (tabel,id,start,total){
	if (tabel=="materii")
		msg="ATENTIE!!!\nVor fi sterse toate notele si absentele alocate acestei materii!\nSunteti sigur ca vreti sa stergeti?"
	else
		msg="Sunteti sigur ca vreti sa stergeti?";
	if (confirm(msg)) {
		location.href = "delete"+tabel+".php?id="+id+"&start="+start+"&total="+total;
	}
}

function deleteelev (tabel,id,clasa){
	if (confirm("Sunteti sigur ca vreti sa stergeti?")) {
		location.href = "delete"+tabel+".php?id="+id+"&clasa="+clasa;
	}
}


function addoption (){
	var fromlist = document.forms[0].elevi;
	var tolist = document.forms[0].elevi_clasa;	
	var elevi_sel = document.forms[0].selelevi;
		
	//alert(tolist.options.length)
	//alert(fromlist.options[fromlist.selectedIndex].text);

	//verific daca exista
	var found="false";
	//alert (tolist.options.length);
	for (var i=0;i<tolist.options.length;i++) {
		if (fromlist.options[fromlist.selectedIndex].value==tolist.options[i].value) {
			found="true";
			break;
		}
	}
	//alert (found);
	if (found=="false") {
		tolist.options[tolist.options.length] = new Option(fromlist.options[fromlist.selectedIndex].text,fromlist.options[fromlist.selectedIndex].value);
		allvals.push(fromlist.options[fromlist.selectedIndex].value);
	}
	x=allvals.join(",");
	alert(x);
	elevi_sel.value=allvals.join(",");
}

function removeoption (){
	var tolist = document.forms[0].elevi_clasa;	
	var elevi_sel = document.forms[0].selelevi;
	
	allvals=Array();
	for (var j=0;j<tolist.options.length;j++) {
		if (tolist.options[tolist.selectedIndex].value!=tolist.options[j].value) {
		//alert (tolist.options[tolist.selectedIndex].value+"-----"+tolist.options[j].value);			
			allvals.push(tolist.options[j].value);
		} else {
			rem=j;
		}
	}

	tolist.options[rem]=null;

	//x=allvals.join(",");
	//alert(x);
	elevi_sel.value=allvals.join(",");
}

function stergenota (idnota){
	//alert (idnota);
	if (confirm("Sunteti sigur ca vreti sa stergeti nota?")) {
		//location.href = "delete"+tabel+".php?id="+id+"&start="+start+"&total="+total;
		document.forma.elements['deletenota'].value=idnota;
		document.forma.submit();
	}
}

function stergeobservatie (idobs){
	//alert (idnota);
	if (confirm("Sunteti sigur ca vreti sa stergeti nota?")) {
		//location.href = "delete"+tabel+".php?id="+id+"&start="+start+"&total="+total;
		document.forma.elements['deleteobservatie'].value=idobs;
		document.forma.submit();
	}
}

function puneoptiuni (datacur) {
	//alert(datacur);
	var ref=document.forms[0].terminal;
	//alert (ref.selectedIndex);
	if (ref.selectedIndex==2) {
		document.getElementById("textterminal").innerHTML='Va rugam sa introduceti in partea dreapta textul care va fi afisat la &quot;observatii&quot; pentru fiecare elev promovat<br><strong>Ex</strong>: Bac1 - IUNIE';
		document.getElementById("dataterminal").innerHTML='Data adaugarii observatiei (AAAA-MM-ZZ)<br><input name="dataterminal" type="text" id="dataterminal" value="'+datacur+'" size="15"><IMG src="img/calender.gif" width="20" height="16" onclick="popUpCalendar(this,document.form1.dataterminal, \'yyyy-mm-dd\');">';
		document.getElementById("obsterminal").innerHTML='<textarea name="obs" cols="25" rows="4" id="obs"></textarea>';	
	} else {
		document.getElementById("textterminal").innerHTML='';
		document.getElementById("dataterminal").innerHTML='';
		document.getElementById("obsterminal").innerHTML='';			
	}
	
}

function nepromovati (f) {
   var ref=document.forms[0];
   var msg;
   var empty_fields="";
   if (ref.elements['nouaclasa'].value == "") {
         empty_fields+="- Clasa \n";
   }
   if (ref.elements['noulprofil'].value == "") {
         empty_fields+="- Profil \n";
   }
   if (empty_fields) {
        msg="____________________________________________________________________________ \n\n";
        msg+="Va rugam sa completati campurile de mai jos: \n";
        msg+=empty_fields;
        msg+="____________________________________________________________________________ \n\n";
        alert(msg);
        return false;
   }
   else {
        //return true;
                document.form1.submit();
   }   
   
}
