sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

eye = {
	incepe : function(event){
		var i;
		if (window.attachEvent)
			sfHover();
			
		grupeTaburi = document.getElementsByTagName("UL");
		for(i=0; i< grupeTaburi.length; i++){
			if(grupeTaburi[i].className == "tabs"){
				eye.taburi(grupeTaburi[i]);
			}
		}
		
		tabele = document.getElementsByTagName("TABLE");
		for(i=0; i< tabele.length; i++){
			if(tabele[i].className == "tableGrid"){
				eye.griduri(tabele[i]);
			}
		}
		eyeSelect.incepe();
		eroare = document.getElementById("eroare");
	},
	
	griduri : function(elem){
		var i;
		if (elem.rows.length > 0){
			for(i=1; i<elem.rows.length; i++){
				if(i%2 == 0)
					elem.rows[i].className += "tableGridPar";
				elem.rows[i].onmouseover = function() {
					this.className+=" tableGridHover";
				}
				elem.rows[i].onmouseout = function() {
					this.className = this.className.replace(new RegExp(" tableGridHover"), "");
					this.className = this.className.replace(new RegExp("tableGridHover"), "");
				}
				elem.rows[i].onclick = function(){
					if(this.className.indexOf("tableGridActive") > -1) {
						verificat = "";
						this.className = this.className.replace(new RegExp(" tableGridActive"), "");
						this.className = this.className.replace(new RegExp("tableGridActive"), "");
					}else{ 
						verificat = "checked";
						this.className += " tableGridActive";
					}
					if(this.getElementsByTagName("INPUT").length > 0)
						this.getElementsByTagName("INPUT")[0].checked = verificat + "";
				}
			}
			for(i=1; i< elem.rows[0].cells.length; i++){
				if(elem.rows[0].cells[i].firstChild.nodeName == "A"){
					if(elem.rows[0].cells[i].getAttribute("title") != null){
						elem.rows[0].cells[i].className = elem.rows[0].cells[i].getAttribute("title");
					}
					elem.rows[0].cells[i].onmouseover = function(){
						this.className += " tableGridTh";
					}
					elem.rows[0].cells[i].onmouseout = function(){
						this.className = this.className.replace(new RegExp(" tableGridTh\\b"), "");
						this.className = this.className.replace(new RegExp("tableGridTh\\b"), "");
					}
					elem.rows[0].cells[i].onclick = function(){
						window.location.href = this.getElementsByTagName("A")[0].href;
					}
				}
			}
		}
		selecturi = elem.getElementsByTagName("INPUT");
		primul = false;
		for(i=0; i<selecturi.length; i++){
			if(selecturi[i].type == "checkbox"){
				if(primul == false){
					primul = true;
					selecturi[i].onclick = function(event){
						parinte = this.parentNode;
						while(parinte.className != "tableGrid"){
							parinte = parinte.parentNode;
						}
						selecturi = parinte.getElementsByTagName("INPUT");
						for(i=0; i<selecturi.length; i++){
							if(selecturi[i].type == "checkbox"){
								selecturi[i].checked = this.checked;
								parinte = selecturi[i].parentNode;
								while(parinte.nodeName != "TR"){
									parinte = parinte.parentNode;
								}
								if(this.checked == true){
									parinte.className += " tableGridActive";
								}else{
									parinte.className = parinte.className.replace(new RegExp(" tableGridActive"), "");
									parinte.className = parinte.className.replace(new RegExp("tableGridActive"), "");
								}
							}
						}
					}
				}else{
				}
			}
		}
		//TinyMCE.onload();
	},
	
	taburi : function(elem){
		var i;
		toate = elem.getElementsByTagName("LI");
		for(i=0; i< toate.length; i++){
			toate[i].indicator = i;
			toate[i].onmouseover = function(){
				if(this.className != "tabActiv")
					this.className = "tabHover";
			}
			toate[i].onmouseout = function(){
				if(this.className != "tabActiv")
					this.className = "";
			}
			toate[i].getElementsByTagName("A")[0].onclick = function(){
				this.blur();
				return false;
			};
			toate[i].onclick = function(){
				var i;
				parinte = this.parentNode;
				toate = parinte.getElementsByTagName("LI");
				for(i=0; i< toate.length; i++){
					if(toate[i].className == "tabActiv"){
						toate[i].className = "";
						break;
					}
				}
				this.className = "tabActiv";
				vecin = parinte.nextSibling;
				while(vecin.className != "zonaTab"){
					vecin = vecin.nextSibling;
				}
				zone = new Array();
				
				copii = vecin.getElementsByTagName("DIV");
				for(i=0;i<copii.length;i++){
					if(copii[i].className == "componentaTab" || copii[i].className == "zonaTabActiva"){
						zone[zone.length] = copii[i];
						copii[i].className = "componentaTab";
					}
				}
				if(zone[this.indicator])
					zone[this.indicator].className = "zonaTabActiva";
			}
			if(toate[i].className == "tabActiv"){
				parinte = toate[i].parentNode;
				vecin = parinte.nextSibling;
				while(vecin.className != "zonaTab"){
					vecin = vecin.nextSibling;
				}
				//vecin.getElementsByTagName("DIV")[i].className = "zonaTabActiva" ;
				copil = vecin.getElementsByTagName("DIV");
				pas = 0;
				for(j=0; j< copil.length; j++){
					if(copil[j].className == "componentaTab"){
						if(pas == i){
							copil[j].className = "zonaTabActiva";
							break;
						}
						pas++;
					}
				}
			}
			
		}
		return null;
	},
	
	popup : function(camp, operatie, valoare){
		var x = parseInt(screen.width / 2.0) - (580 / 2.0);
		var y = parseInt(screen.height / 2.0) - (400 / 2.0);
		var win = window.open("editor.htm", "editor", "top=" + y + ",left=" + x + ",scrollbars=no,dialog=yes,minimizable=no,modal=yes,width=580,height=400,resizable=no");
		eye.actiuni = new Object();
		eye.actiuni.camp = camp;
		eye.actiuni.operatie = operatie;
		eye.actiuni.valoare = valoare;
		win.focus();
		win.onblur = function(){
			this.focus();
		}
	},
	
	calendar : function(camp){
		data = document.getElementById(camp).value;
		mediaWin = window.open("lib/calendar.php?data=" + data + "&camp=" + camp + "", "__ha_dialog", "toolbar=no,menubar=no,personalbar=no,width=280,height=300, scrollbars=yes,resizable=no");
		mediaWin.moveTo((screen.width-280)/2,(screen.height-300)/2);
	},
	
	curataFiltrarea : function(elem){
		parinte = elem.parentNode;
		while(parinte.nodeName != "FORM"){
			parinte = parinte.parentNode;
		}
		campuri = parinte.getElementsByTagName("INPUT");
		for(i=0; i<campuri.length; i++){
			if(campuri[i].getAttribute("type") == "text"){
				campuri[i].value = "";
			}
		}
	}
}

eyeSelect = {
	surse : new Array("sursa", "sursa2"),
	destinatii : new Array("destinatie","destinatie2"),
	
	curentValori : null,
	curentTexte : null,
	deSortat : null,
	
	incepe : function(){
		var lungime = Math.min(eyeSelect.surse.length, eyeSelect.destinatii.length);
		var i;
		for(i=0; i<lungime; i++){
			sursa = eyeSelect.surse[i];
			destinatie = eyeSelect.destinatii[i];
			elemSursa = document.getElementById(sursa);
			if(elemSursa){
				elemDestinatie = document.getElementById(destinatie);
				elemSursa.geaman = destinatie;
				elemDestinatie.geaman = sursa;
				eyeSelect.sorteaza(sursa);
				eyeSelect.sorteaza(destinatie);
			}
		}
	},
	
	muta : function(nume){
		sursa = document.getElementById(nume);
		if(sursa.selectedIndex > -1){
			destinatie = document.getElementById(sursa.geaman);
			valoare = sursa.options[sursa.selectedIndex].value;
			text = sursa.options[sursa.selectedIndex].text;
			sursa.options[sursa.selectedIndex] = null;
			destinatie.options[destinatie.options.length] = new Option(text, valoare);
			eyeSelect.sorteaza(nume);
			eyeSelect.sorteaza(sursa.geaman);
		}
	},
	
	mutaTot : function(nume){
		sursa = document.getElementById(nume);
		if(sursa.options.length > 0){
			destinatie = document.getElementById(sursa.geaman);
			var i;
			var lungime = sursa.options.length;
			for(i=0; i<lungime ; i++){
				valoare = sursa.options[0].value;
				text = sursa.options[0].text;
				sursa.options[0] = null;
				destinatie.options[destinatie.options.length] = new Option(text, valoare);
			}
			eyeSelect.sorteaza(sursa.geaman);
		}
	},
	
	sorteaza : function(nume){
		this.deSortat = document.getElementById(nume);
		lungime = this.deSortat.options.length;
		if(lungime > 1){
			this.curentValori = new Array();
			this.curentTexte = new Array();
			var i;
			var j;
			for(i=0; i<lungime; i++){
				valoare = this.deSortat.options[i].value;
				text = this.deSortat.options[i].text;
				this.curentValori.push(valoare);
				this.curentTexte.push(text);
			}
			for(i=1; i<lungime; i++){
				j = i;
				b = this.curentTexte[i];
				c = this.curentValori[i];
				while( j > 0 && this.curentTexte[j-1] > b){
					this.curentValori[j] = this.curentValori[j-1];
					this.curentTexte[j] = this.curentTexte[j-1];
					j--;
				}
				this.curentValori[j] = c;
				this.curentTexte[j] = b;
			}
			for(i=0; i<lungime; i++){
				this.deSortat.options[i].text = this.curentTexte[i];
				this.deSortat.options[i].value = this.curentValori[i];
			}
		}
	}
}

function redirect(url, msg)
{
   var TARG_ID = "redirectare";
   var DEF_MSG = "";

   if( ! msg )
   {
      msg = DEF_MSG;
   }

   if( ! url )
   {
      throw new Error('You didn\'t include the "url" parameter');
   }


   var e = document.getElementById(TARG_ID);

   if( ! e )
   {
      throw new Error('"redirectare" element id not found');
   }

   var cTicks = parseInt(e.innerHTML);

   var timer = setInterval(function()
   {
      if( cTicks )
      {
         e.innerHTML = --cTicks;
      }
      else
      {
         clearInterval(timer);
         document.body.innerHTML = msg;
         location = url;	  
      }

   }, 1000);
}


window.onload = eye.incepe;

