var menuids=["suckertree1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus(){
for (var i=0; i<menuids.length; i++){
  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
    for (var t=0; t<ultags.length; t++){
    ultags[t].parentNode.getElementsByTagName("a")[0].className="subfolderstyle"
		if (ultags[t].parentNode.parentNode.id==menuids[i]) //if this is a first level submenu
			ultags[t].style.left=ultags[t].parentNode.offsetWidth+"px" //dynamically position first level submenus to be width of main menu item
		else //else if this is a sub level submenu (ul)
		  ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth+"px" //position menu to the right of menu item that activated it
    ultags[t].parentNode.onmouseover=function(){
    this.getElementsByTagName("ul")[0].style.display="block"
    }
    ultags[t].parentNode.onmouseout=function(){
    this.getElementsByTagName("ul")[0].style.display="none"
    }
    }
		for (var t=ultags.length-1; t>-1; t--){ //loop through all sub menus again, and use "display:none" to hide menus (to prevent possible page scrollbars
		ultags[t].style.visibility="visible"
		ultags[t].style.display="none"
		}
  }
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus)


////////////////////////////////////////////////////////////////////

function check_rame(tip) {
	mesaj="";
	var i=0;
	if(document.formular.categorie.value == "") {
		mesaj=mesaj+"Categoria este obligatorie!\n";
		i++;
	}
	
	
	if(document.formular.cod.value == "") {
		mesaj=mesaj+"Codul produsului este obligatoriu!\n";
		i++;
	}

	
	if(document.formular.producator.value == "") {
		mesaj=mesaj+"Producatorul este obligatoriu!\n";
		i++;
	}
	
	if(document.formular.pret_catalog.value == "") {
		mesaj=mesaj+"Pretul de catalog este obligatoriu!\n";
		i++;
	}
	
	if(document.formular.pret_online.value == "") {
		mesaj=mesaj+"Pretul online este obligatoriu!\n";
		i++;
	}
	
	
	if(document.formular.id_material.value == "") {
		mesaj=mesaj+"Materialul produsului este obligatorie!\n";
		i++;
	}
	
	if(document.formular.gen.value == "") {
		mesaj=mesaj+"Genul produsului este obligatoriu!\n";
		i++;
	}
	
	if(document.formular.stoc.value == "") {
		mesaj=mesaj+"Stocul produsului este obligatoriu!\n";
		i++;
	}
	
	
	if(tip == "edit") {}
	else {
		if(document.formular.imagine_mica.value == "") {
			mesaj=mesaj+"Imaginea mica este obligatorie!\n";
			i++;
		}
		
		if(document.formular.imagine_mare.value == "") {
			mesaj=mesaj+"Imaginea mare este obligatorie!\n";
			i++;
		}
		
	}
	
	
	if(document.formular.vizibil.value == "") {
		mesaj=mesaj+"Nu ati setat daca sa fie vizibil in bara de derulare sau nu!\n";
		i++;
	}
	
		if(i==0) {
			document.formular.submit();
		}
		else {
			alert(mesaj);
		}
}

function verifica_cod(cod) {
	new Ajax.Request('ajax/verificari.php?act=verifica_cod&cod='+cod+'',
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      document.getElementById('mesaj').innerHTML = response;
    }
  });
}


function verifica_cod_lentile(cod) {
	new Ajax.Request('ajax/verificari.php?act=verifica_cod_lentile&cod='+cod+'',
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      document.getElementById('mesaj').innerHTML = response;
    }
  });
}

function solutii(valoare) {
	if(valoare=='solutii') {
		$('sol_cod').hide();
		$('sol_culoare').hide();
		$('sol_buc').hide();
		$('sol_rc').hide();
		$('sol_diametru').hide();
		$('sol_cilindru').hide();
		$('sol_dioptrii').hide();
		$('sol_aditie').hide();
		$('sol_grad').hide();
		$('sol_purtare').hide();
		$('sol_apa').hide();
		$('sol_oxigen').hide();
	}
	else {
		$('sol_cod').show();
		$('sol_culoare').show();
		$('sol_buc').show();
		$('sol_rc').show();
		$('sol_diametru').show();
		$('sol_cilindru').show();
		$('sol_dioptrii').show();
		$('sol_aditie').show();
		$('sol_grad').show();
		$('sol_purtare').show();
		$('sol_apa').show();
		$('sol_oxigen').show();
	}
	
}

function check_lentile(tip) {
	mesaj="";
	var i=0;

	if(document.formular.categorie.value == "") {
		mesaj=mesaj+"Categoria este obligatorie!\n";
		i++;
	}
	if(document.formular.denumire.value == "") {
		mesaj=mesaj+"Denumirea este obligatorie!\n";
		i++;
	}
	
	if(document.formular.producator.value == "") {
		mesaj=mesaj+"Producatorul este obligatoriu!\n";
		i++;
	}
	
	if(document.formular.pret_catalog.value == "") {
		mesaj=mesaj+"Pretul de catalog este obligatoriu!\n";
		i++;
	}
	
	if(document.formular.pret_online.value == "") {
		mesaj=mesaj+"Pretul online este obligatoriu!\n";
		i++;
	}
	if(document.formular.bucati_set.value == "") {
		mesaj=mesaj+"Nr. de bucati este obligatoriu!\n";
		i++;
	}	
	
	if(document.formular.stoc.value == "") {
		mesaj=mesaj+"Stocul produsului este obligatoriu!\n";
		i++;
	}

////////////////////////////
   	var da1=0;
   	var a=document.getElementsByName("rc[]");
    
      for (var k=0; k<a.length; k++) {
         if (a[k].checked) {
           da1=1
         }
      }
	if(da1== 0) {
		mesaj=mesaj+"Raza de curbura este obligatorie!\n";
		i++;
	}
	
   	var da2=0;
   	var a=document.getElementsByName("diametru[]");
    
      for (var k=0; k<a.length; k++) {
         if (a[k].checked) {
           da2=1
         }
      }
	if(da2== 0) {
		mesaj=mesaj+"Diametru este obligatoriu!\n";
		i++;
	}

   	var da3=0;
   	var a=document.getElementsByName("dioptrii[]");
    
      for (var k=0; k<a.length; k++) {
         if (a[k].checked) {
           da3=1
         }
      }
	if(da3== 0) {
		mesaj=mesaj+"Campul 'Dioptrie sferica' este obligatoriu!\n";
		i++;
	}	
////////////////////////////	
	if(document.formular.termen_livrare.value == "") {
		mesaj=mesaj+"Termenul de livrare este obligatoriu!\n";
		i++;
	}	
	
	
	if(tip == "edit") {}
	else {
		if(document.formular.imagine.value == "") {
			mesaj=mesaj+"Imaginea este obligatorie!\n";
			i++;
		}
	}
	
		if(document.formular.categorie.value == "solutii") {i=0;} else {}
		if(i==0) {
			document.formular.submit();
		}
		else {
			alert(mesaj);
		}
}

function sterge_valoare(div_id) {
	document.getElementById(div_id).innerHTML = '';
}

function culoare_noua(tip) {
	dest = document.getElementById('generate_culoare');
	mesaj='<input type="text" id="culoare" size="10"/> <input type="hidden" id="tip" value="'+tip+'"><input type="button" value="Adauga" onclick="add_culoare_noua(\''+tip+'\',\'not\');"/> <a href="javascript:add_culoare_noua(\''+tip+'\',\'kleampa\');">[lista culori]</a></span>';
	dest.innerHTML = mesaj
}

function add_culoare_noua(var_tip,kleampa) {
	if(kleampa == "not") {
		culoare = document.getElementById('culoare').value;
		tip = document.getElementById('tip').value;
		urlus = 'ajax/verificari.php?act=culoare_noua&culoare='+culoare+'&kleampa='+kleampa+'&tip='+tip+'';
	}
	else {
		urlus = 'ajax/verificari.php?act=culoare_noua&kleampa='+kleampa+'&tip='+var_tip+'';
	}
	
	new Ajax.Request(urlus,
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      document.getElementById('generate_culoare').innerHTML = response;
    }
  });
}

function material_nou() {
	dest = document.getElementById('generate_material');
	mesaj='<input type="text" id="material" size="10"/> <input type="button" value="Adauga" onclick="add_material_nou(\'not\');"/> <a href="javascript:add_material_nou(\'kleampa\');">[lista materiale]</a></span>';
	dest.innerHTML = mesaj
}

function add_material_nou(kleampa) {
	if(kleampa == "not") {
		material = document.getElementById('material').value;
		urlus = 'ajax/verificari.php?act=material_nou&material='+material+'&kleampa='+kleampa+'';
	}
	else {
		urlus = 'ajax/verificari.php?act=material_nou&kleampa='+kleampa+'';
	}
	
	new Ajax.Request(urlus,
  {
    method:'get',
    onSuccess: function(transport){
      var response = transport.responseText || "no response text";
      document.getElementById('generate_material').innerHTML = response;
    }
  });
}

////////////////////////////////////////////////////////////////////

function check_montaj() {
	mesaj="";
	var i=0;

	if(document.formular.titlu.value == "") {
		mesaj=mesaj+"Titlul este obligatoriu!\n";
		i++;
	}
	
	if(document.formular.pret_catalog.value == "") {
		mesaj=mesaj+"Pretul de catalog este obligatoriu!\n";
		i++;
	}
	
	if(document.formular.pret_online.value == "") {
		mesaj=mesaj+"Pretul online este obligatoriu!\n";
		i++;
	}
	
		if(i==0) {
			document.formular.submit();
		}
		else {
			alert(mesaj);
		}
}


////////////////////////////////////////////////////////////////

// moveOptionsAcross
//
// Move selected options from one select list to another
//
function moveOptionsAcross(fromSelectList, toSelectList) {
  var selectOptions = fromSelectList.getElementsByTagName('option');
  for (var i = 0; i < selectOptions.length; i++) {
     var opt = selectOptions[i];
     if (opt.selected) {
      fromSelectList.removeChild(opt);
      toSelectList.appendChild(opt);

 // originally, this loop decremented from length to 0 so that you
 // wouldn't have to worry about adjusting the index.  However, then
 // moving multiple options resulted in the order being reversed from when
 // was in the original selection list which can be confusing to the user.
 // So now, the index is adjusted to make sure we don't skip an option.
      i--;
     }
   }
}

function adauga_culoare() {
	tip = $('tip_culoare').value
	culoare = $('culoare_noua').value
	// tip 1 - lentile de contact , 0 - rame
	if(culoare == '') {
		alert('Scrieti o culoare!');
	}
	else {
		urlus = 'ajax/verificari.php?act=adauga_culoare&tip='+tip+'&culoare='+culoare+'';
		new Ajax.Request(urlus,
	  {
	    method:'get',
	    onSuccess: function(transport){
	      var response = transport.responseText || "no response text";
	      elemente = response.split('|');
	      if(elemente[1] == '') {}
	      else {
	      	  info = elemente[1].split(',');
		      lungime =$('lista_culori').length;
			  $('lista_culori').options[lungime]= new Option(info[1], info[0]);
	      }
	      document.getElementById('mesaj_culoare').innerHTML = elemente[0];
	      $('culoare_noua').value=''
	      
	    }
	  });
	}
}


