function CheckAll(fmobj) {
  for (var i=0;i<fmobj.elements.length;i++) {
    var e = fmobj.elements[i];
    if ( (e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled) ) {
      e.checked = fmobj.allbox.checked;
    }
  }
}

function CheckCheckAll(fmobj) {
  var TotalBoxes = 0;
  var TotalOn = 0;
  for (var i=0;i<fmobj.elements.length;i++) {
    var e = fmobj.elements[i];
    if ((e.name != 'allbox') && (e.type=='checkbox')) {
      TotalBoxes++;
      if (e.checked) {
       TotalOn++;
      }
    }
  }
  if (TotalBoxes==TotalOn) {
    fmobj.allbox.checked=true;
  }
  else {
   fmobj.allbox.checked=false;
  }
}

function do_action_all(idd) {
	mesaj = "Confirmati aplicarea actiunii pt toate comenzile selectate?";	
	if (confirm(mesaj))
	{
		document.frm_comenzi.op.value=idd;
		document.frm_comenzi.submit();
	}
}
function do_users_all(idd) {
	mesaj = "Confirmati aplicarea actiunii pt toti utiliztorii selectati?";	
	if (confirm(mesaj))
	{
		document.frm_users.op.value=idd;
		document.frm_users.submit();
	}
}

function addCommas(nStr)
{
	/*nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;*/
	return nStr.replace('.',',');
}

function schCadou(cadou, total, moneda) {
	div = document.getElementById('taxe_ambalare');	
	div2 = document.getElementById('totalul');	
	if (document.getElementById('bifa_cadou').checked==true) {
		var tot0 = parseFloat(total)+parseFloat(cadou);
		var tot=addCommas(tot0.toFixed(2));
		cd0 = addCommas((parseFloat(cadou).toFixed(2))+"");
		div.innerHTML=cd0+" "+moneda; 
	}
	else {
		var tot0 = parseFloat(total);	
		var tot=addCommas((tot0.toFixed(2))+"");	
		div.innerHTML="0,00 "+moneda; 
	}
	
	div2.innerHTML=tot+" "+moneda; 	
}

function checkVal(idd, vall) {
	div = document.getElementById(idd);	
	if (vall<=0) {
		//alert('Cantitatea nu poate fi negativa sau 0!');
		div.value=1;
	}
}

function showHide(id)
{
	div = document.getElementById(id);
	if (div.style.display=='block') { div.style.display='none'; }
	else { div.style.display='block'; }		
}

function showHide2(id)
{
	div = document.getElementById('cmd_'+id);
	if (div.style.display=='block') { div.style.display='none'; }
	else { div.style.display='block'; }	
	div = document.getElementById('sag_'+id);
	if (div.style.display=='block') { div.style.display='none'; }
	else { div.style.display='block'; }		
}

function download(img_src){
	objImage.src=images[img_src];
}

function nextimg()
{
	crt=crt + 1;
	if (images.length<=crt) {
			crt = 0;
	}
	
	document.images["im"].src = images[crt];
	var next=crt + 1;
	download(next);
}

function P7_ExpMenu(){ //v1.1.0.2 by PVII-www.projectseven.com
 if(navigator.appVersion.indexOf("MSIE")==-1){return;}
 var i,k,g,lg,r=/\s*p7hvr/,nn='',c,cs='p7hvr',bv='p7menubar';
 for(i=0;i<10;i++){g=document.getElementById(bv+nn);if(g){
 lg=g.getElementsByTagName("LI");if(lg){for(k=0;k<lg.length;k++){
 lg[k].onmouseover=function(){c=this.className;cl=(c)?c+' '+cs:cs;
 this.className=cl;};lg[k].onmouseout=function(){c=this.className;
 this.className=(c)?c.replace(r,''):'';};}}}nn=i+1;}
}

function P8_ExpMenu(){ //v1.1.0.2 by PVII-www.projectseven.com
 if(navigator.appVersion.indexOf("MSIE")==-1){return;}
 var i,k,g,lg,r=/\s*p8hvr/,nn='',c,cs='p8hvr',bv='p8menubar';
 for(i=0;i<10;i++){g=document.getElementById(bv+nn);if(g){
 lg=g.getElementsByTagName("LI");if(lg){for(k=0;k<lg.length;k++){
 lg[k].onmouseover=function(){c=this.className;cl=(c)?c+' '+cs:cs;
 this.className=cl;};lg[k].onmouseout=function(){c=this.className;
 this.className=(c)?c.replace(r,''):'';};}}}nn=i+1;}
}

function P9_ExpMenu(){ //v1.1.0.2 by PVII-www.projectseven.com
 if(navigator.appVersion.indexOf("MSIE")==-1){return;}
 var i,k,g,lg,r=/\s*p9hvr/,nn='',c,cs='p9hvr',bv='p9menubar';
 for(i=0;i<10;i++){g=document.getElementById(bv+nn);if(g){
 lg=g.getElementsByTagName("LI");if(lg){for(k=0;k<lg.length;k++){
 lg[k].onmouseover=function(){c=this.className;cl=(c)?c+' '+cs:cs;
 this.className=cl;};lg[k].onmouseout=function(){c=this.className;
 this.className=(c)?c.replace(r,''):'';};}}}nn=i+1;}
}

function check_email(emladrs)
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	var rez = true
	if (emladrs == "")
	{
		rez=true
	}
	else
	{
		if (filter.test(emladrs))
			rez=true
		else{
			rez=false
		}
	}
	return (rez)
}

function adauga1(idd)
{
	document.form_intro.idul.value=idd;
	document.form_intro.op.value='adauga_intro';
	document.form_intro.submit();
}

function rezerva1(idd)
{
	document.form_intro.idul.value=idd;
	document.form_intro.op.value='rezerva_intro';
	document.form_intro.submit();
}

function adauga2()
{
	document.form_det.op.value='adauga_det';
	document.form_det.submit();
}

function rezerva2()
{
	document.form_det.op.value='rezerva_det';
	document.form_det.submit();
}

function delCos(idd,pers,pnume,pnumar)
{
	if (confirm('Confirmati stergerea produsului din cos?')) {
		document.form_cos.idul.value=idd;
		document.form_cos.op.value='del_cos';
		document.form_cos.submit();
	}
}

function delRezerv(idd,rez)
{
	if (confirm('Confirmati anularea rezervarii?')) {
		document.form_rezervare.idul.value=idd;
		document.form_rezervare.rezul.value=rez;
		document.form_rezervare.op.value='del_rezervare';
		document.form_rezervare.submit();
	}
}

function delRezerv2(idd,rez)
{
	if (confirm('Confirmati anularea rezervarii?')) {
		document.form_rezervare.idul.value=idd;
		document.form_rezervare.rezul.value=rez;
		document.form_rezervare.op.value='del_rezervare2';
		document.form_rezervare.submit();
	}
}

function delPers(idd,pers,pnume,pnumar,cant)
{
	if (confirm('Confirmati stergerea personalizarii produsului?')) {
		document.form_cos.idul.value=idd;
		document.form_cos.pers.value='1';
		document.form_cos.pnume.value=pnume;
		document.form_cos.pnumar.value=pnumar;
		document.form_cos.quant.value=cant;
		document.form_cos.op.value='del_pers';
		document.form_cos.submit();
	}
}

function delPers2(idd)
{
	if (confirm('Confirmati stergerea personalizarii produsului?')) {
		document.form_rezervare.rezul.value=idd;
		document.form_rezervare.op.value='del_pers2';
		document.form_rezervare.submit();
	}
}

function doSalveazaCos(idd)
{
	document.form_cos.op.value='save_cos';
	document.form_cos.submit();
}

function doSalveazaRezervari(idd)
{
	document.form_rezervare.op.value='save_rezervare';
	document.form_rezervare.submit();
}

function do_stergeuser(idd)
{
	document.frm_users.idul.value=idd;
	mesaj = "Confirmati stergerea utilizatorului?";	
	if (confirm(mesaj))
	{
		document.frm_users.submit();
	}
}

function do_stergeprod(idd)
{
	document.frm_produse.idul.value=idd;
	mesaj = "Confirmati stergerea produsului?\nVor fi sterse si toate variantele acestuia!";	
	if (confirm(mesaj))
	{
		if (confirm('SIGUR SIGUR?')) {
			document.frm_produse.op.value="stergeprod";
			document.frm_produse.submit();
		}
	}
}

function do_saveprods()
{
	mesaj = "Confirmati salvarea modificarilor?";	
	if (confirm(mesaj))
	{
		document.frm_produse.op.value="saveprods";
		document.frm_produse.submit();
	}
}

function do_sterge(idd,care)
{
	document.frm_categs.idul.value=idd;
	document.frm_categs.care.value=care;
	if (care==1) mesaj = "Confirmati stergerea categoriei?\nToate subcategoriile vor fi de asemenea sterse!";
	if (care==2) mesaj = "Confirmati stergerea subcategoriei?";	
	if (confirm(mesaj))
	{
		document.frm_categs.submit();
	}
}

function do_sterge_user(idd)
{
	document.frm_users.idul.value=idd;
	mesaj = "Confirmati stergerea contului?";	
	if (confirm(mesaj))
	{
		document.frm_users.op.value="deluser";
		document.frm_users.submit();
	}
}

function do_valideaza_user(idd)
{
	document.frm_users.idul.value=idd;
	mesaj = "Confirmati validare contului?";	
	if (confirm(mesaj))
	{
		document.frm_users.op.value="validareuser";
		document.frm_users.submit();
	}
}

function do_stergevarianta(idd)
{
	mesaj = "Confirmati stergerea variantei?";	
	if (confirm(mesaj))
	{
		document.frm_savetot.valoare.value=idd;
		document.frm_savetot.op.value="DelVar";
		document.frm_savetot.submit();
	}
}

function do_stergeAsocs(idd)
{
	mesaj = "Confirmati renuntarea la asocierea cu acest produs?";	
	if (confirm(mesaj))
	{
		document.frm_savetot.valoare.value=idd;
		document.frm_savetot.op.value="DelAsocs";
		document.frm_savetot.submit();
	}
}

function do_stergeImg(idd)
{
	mesaj = "Confirmati stergerea imaginii detaliu?";	
	if (confirm(mesaj))
	{
		document.frm_savetot.valoare.value=idd;
		document.frm_savetot.op.value="DelImgs";
		document.frm_savetot.submit();
	}
}

function do_savetot()
{
	if (document.frm_savetot.prCod.value  == "")
	{
		alert("Produsul trebuie sa aiba un cod intern!");
	}
	else {
		document.frm_savetot.op.value="savetot";
		conf = confirm("Confirmati salvarea modificarilor?");
		if (conf)
		{
			document.frm_savetot.submit();
		}
	}
	
}

function anuleazaCmd(idd)
{
	mesaj = "Confirmati anularea comenzii?";	
	if (confirm(mesaj))
	{
		document.frm_comenzi.idul.value=idd;
		document.frm_comenzi.op.value="anuleazaCmd";
		document.frm_comenzi.submit();
	}
}

function stergeCmd(idd)
{
	mesaj = "Confirmati stergerea comenzii?";	
	if (confirm(mesaj))
	{
		document.frm_comenzi.idul.value=idd;
		document.frm_comenzi.op.value="stergeCmd";
		document.frm_comenzi.submit();
	}
}

function confirmaCmd(idd)
{
	mesaj = "Confirmati preluarea comenzii?";	
	if (confirm(mesaj))
	{
		document.frm_comenzi.idul.value=idd;
		document.frm_comenzi.op.value="confirmaCmd";
		document.frm_comenzi.submit();
	}
}

function livreazaCmd(idd)
{
	mesaj = "Confirmati livrarea comenzii?";	
	if (confirm(mesaj))
	{
		document.frm_comenzi.idul.value=idd;
		document.frm_comenzi.op.value="livreazaCmd";
		document.frm_comenzi.submit();
	}
}

function reparaCmd(idd)
{
	mesaj = "Confirmati repararea comenzii?";	
	if (confirm(mesaj))
	{
		document.frm_comenzi.idul.value=idd;
		document.frm_comenzi.op.value="reparaCmd";
		document.frm_comenzi.submit();
	}
}


function addCosRez(idd)
{
	document.form_rezervare.idul.value=idd;
	document.form_rezervare.op.value="addCosRezerv";
	document.form_rezervare.submit();
}

function valideaza(vall)
{
		switch (vall)
		{
		case "AdgImgs":
			if (document.frm_savetot.prImgDet.value  == "")
			{
				alert("Nu ati selectat imaginea!");
			}
			else {
					conf = confirm("Confirmati adaugarea imaginii detaliu?");
					if (conf)
					{
						document.frm_savetot.op.value="AdgImgs";
						document.frm_savetot.submit();
					}
			}
		break;			
		case "AdgVar":
			if (document.frm_savetot.var_cod.value  == "")
			{
				alert("Nu ati introdus codul de bare!");
			}
			else {
					conf = confirm("Confirmati adaugarea variantei?");
					if (conf)
					{
						document.frm_savetot.op.value="AdgVar";
						document.frm_savetot.submit();
					}
			}
		break;			
		case "AdgAsocs":
			if (document.frm_savetot.asocs_den.value  == "")
			{
				alert("Nu ati selectat nici un produs pt asociere!");
			}
			else {
					conf = confirm("Confirmati asocierea cu acest produs?");
					if (conf)
					{
						document.frm_savetot.op.value="AdgAsocs";
						document.frm_savetot.submit();
					}
			}
		break;			
		case "useradg":
		if ((document.frm_useradg.ua_nume.value  == "") ||
				(document.frm_useradg.ua_eml.value  == "") ||
				(document.frm_useradg.ua_pass1.value  == ""))
			{
				alert("Nu ati completat toate campurile obligatorii!");
			}
			else {
				if (document.frm_useradg.ua_pass1.value!=document.frm_useradg.ua_pass2.value) {
					alert("Parola nu a fost confirmata corect!");
				}
				else {
					x = check_email(document.frm_useradg.ua_eml.value);
					if (x)
					{
						conf = confirm("Confirmati adaugarea userului?");
						if (conf)
						{
							document.frm_useradg.submit();
						}
					}
					else 
					{
						alert("Adresa de email este incorecta!");
					}
				}
			}
		break;	
		case "usermodf":
		if (document.frm_usermodf.um_eml.value  == "")
			{
				alert("Nu ati completat toate campurile obligatorii!");
			}
			else {
				if (document.frm_usermodf.um_pass1.value!=document.frm_usermodf.um_pass2.value) {
					alert("Parola nu a fost confirmata corect!");
				}
				else {
					x = check_email(document.frm_usermodf.um_eml.value);
					if (x)
					{
						conf = confirm("Confirmati salvarea modificarilor?");
						if (conf)
						{
							document.frm_usermodf.submit();
						}
					}
					else 
					{
						alert("Adresa de email este incorecta!");
					}
				}
			}
		break;
		case "modf":
			conf = confirm("Confirmati salvarea modificarilor?");
			if (conf)
			{
				document.frm_modf.submit();
			}
		break;		
		case "adg1":
			conf = confirm("Confirmati adaugarea categoriei?");
			if (conf)
			{
				document.frm_adg1.submit();
			}
		break;	
		case "adg2":
			if ((document.frm_adg2.ad2_cod.value  == "") ||
				 (document.frm_adg2.ad2_belong.value  == ""))
			{
				alert("Nu ati completat toate campurile obligatorii!");
			}
			else {
					conf = confirm("Confirmati adaugarea subcategoriei?");
					if (conf)
					{
						document.frm_adg2.submit();
					}
			}
		break;		
	}
}
