//JavaScript functions

// functie de deschidere poza in fereastra noua
function IOpen(img,w,h,titlu)
{
        //iWidth = document.images[0].width;
        //iHeight = document.images[0].height;
        //w=iWidth;
        //h=iHeight;
        //alert(w+"x"+h);

    LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;

    var win=window.open(img,"IWindow","'dependent=yes,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition+"'");

    win.document.write('<html><head><title>'+titlu+'</title></head><body onclick="javascript:window.close();" title="Click pentru a închide această fereastră" topmargin=0 leftmargin=0 rightmargin=0 bottommargin=0 onclick="javascript:window.close()"><img style="cursor:hand;cursor:pointer;" src="'+img+'" width='+w+' height='+h+'></body></html>');

    win.document.close();
}

/*begin Menu*/
function activateSubmenu(idsubmenu, button)
{
	document.getElementById(button).className = "menuhover";
	document.getElementById(idsubmenu).style.display = "block";
}
function deactivateSubmenu(idsubmenu, button)
{
	document.getElementById(button).className = "";
	document.getElementById(idsubmenu).style.display = "none";
}
function activateHover(button)
{
	document.getElementById(button).className = "menuhover";
}
function deactivateHover(button)
{
	document.getElementById(button).className = "";
}
/*end Menu*/

/*forum control*/
function forumToggle (idShow, idHide, idShowButton, idHideButton)
{
	document.getElementById(idHide).style.display = "none";
	document.getElementById(idShow).style.display = "block";
	document.getElementById(idHideButton).style.display = "none";
	document.getElementById(idShowButton).style.display = "block";
	if(document.getElementById("mesaj"))
	{
		document.getElementById("mesaj").reset();
	}
	if(document.getElementById("cauta"))
	{
		document.getElementById("cauta").reset();
	}

}

/*end forum*/

/*begin form de logare client*/
function ClientValidLogin()
{
	//valideaza campurile pe care le introduci
	var saveit = true;
	var id;
	id=document.getElementById('login_id');


     //octav   
	/*if (id.value.length ==0)
	{
		alert ('Completați câmpul cu identificatorul de licență sau numele de utilizator.');
		id.focus();
		id.select();
		return false;
	}
	*/
	
	//octav
	
	return true;
}

function SetLabelLegeNet()
{
		//document.getElementById('label_username').innerHTML = 'Utilizator';
		//document.getElementById('label_userpass').style.display='block';


        //octav
        document.getElementById('label_username').style.display='block';
        document.getElementById('label_username').innerHTML = 'Pentru acces la Lege Online apăsați butonul "Continuă"';
        
        document.getElementById('label_userpass').style.display='none';
       
        document.getElementById('login_id').style.display='none';
        //end octav
        
}

function SetLabelLege4()
{
        //octav
        document.getElementById('login_id').style.display='block';
        document.getElementById('label_username').style.display='block';
		//end octav
		
		document.getElementById('label_username').innerHTML = 'Nr. licență';
		document.getElementById('label_userpass').style.display='none';
}
/*end form de logare client*/

function OpenInNewWindow()
{
    // Change "_blank" to something like "newWindow" to load all links in the same new window
    var newWindow = window.open(this.getAttribute('href'), '_blank');
    newWindow.focus();
    return false;
}

/*begin newsletter.html*/
function NewsletterValidFormAdd()
{
	//valideaza campurile pe care le introduci
	var nume, prenume, email, domenii;
	var nDomenii=0;

	nume=document.getElementById("frm_abonat").nume_abonat;
	prenume=document.getElementById("frm_abonat").prenume_abonat;
	email=document.getElementById("frm_abonat").email_abonat;
	domenii=document.getElementById("frm_abonat").elements['domenii[]'];

	if (nume.value.length==0)
	{
		alert('Vă rugăm completați numele!');
		nume.focus();
		nume.select();
		return false;
	}
	if (prenume.value.length==0)
	{
		alert('Vă rugăm completați prenumele!');
		prenume.focus();
		prenume.select();
		return false;
	}


	if(email.value.length==0)
	{
		alert('Introduceți adresa de e-mail!');
		email.focus();
		email.select();
		return false;
	}

	if (email.value.length>0 && !(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)))
	{
		alert('Adresa de e-mail introdusă este invalidă!');
		email.focus();
		email.select();
		return false;
	}
	document.getElementById("frm_abonat").submit();
}

function NewsletterValidFormMod()
{
	//valideaza campurile pe care le introduci
	var saveit = true;

	email=document.getElementById("frm_confirm").email_abonat;
	if((email.value.length==0) && saveit)
	{
		alert('Vă rugăm completați e-mailul!');
		email.focus();
		email.select();
		return false;
	}
	else
	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)))
	{
		alert('Adresa de e-mail introdusă este invalidă!');
		email.focus();
		email.select();
		return false;
	}

	document.getElementById("frm_confirm").submit();
}
/*end newsletter.html*/

/*begin formSuportOnline.html*/
function Populate(onLoad)
{
	var data = new Date();
	var dayPg = document.getElementById('suport').day;
	var yearPg = document.getElementById('suport').year;
	var monthPg = document.getElementById('suport').month;
	timeA = new Date(yearPg.options[yearPg.selectedIndex].text, monthPg.options[monthPg.selectedIndex].value,1);
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	var daysInMonth = timeB.getDate();
	for (var i = 0; i < dayPg.length; i++)
		dayPg.options[1] = null;

	for (var i = 0; i < daysInMonth; i++)
	{
		dayPg.options[i] = new Option(i+1);
		dayPg.options[i].value=i+1;
	}

	if(onLoad==0)
		dayPg.options[data.getDate()-1].selected = true;
	else
		dayPg.options[0].selected = true;
}

function GetYears()
{
	// punem ultimii 10 ani in "years"; vor aparea in combo-ul cu ani din data
	var dayPg = document.getElementById('suport').day;
	var yearPg = document.getElementById('suport').year;
	var monthPg = document.getElementById('suport').month;
	var data=new Date();
	var years = new Array();
	var maxyear = data.getFullYear();

	for (var i=maxyear-10; i<=maxyear; i++) years.push(i);

	for (var i = 0; i < yearPg.length; i++)
		yearPg.options[0] = null;

	var pos;

	for (var i=0; i < years.length;i++)
		if(years[i]==data.getUTCFullYear())
			pos=i;

	for (var i=0; i < years.length; i++)
		yearPg.options[i] = new Option(years[years.length-i-1]);

	yearPg.options[years.length-pos-1].selected=true;

	var months = new Array('Ianuarie','Februarie','Martie','Aprilie','Mai','Iunie','Iulie','August','Septembrie','Octombrie','Noiembrie','Decembrie');

	for (var i = 0; i < months.length; i++)
	{
		monthPg.options[i] = new Option(months[i].substring(0, 3)); // am scurtat lunile ca sa incapa toata data in coloana
		monthPg.options[i].value = i+1;
	}

	monthPg.options[data.getMonth()].selected=true;
	Populate(0);
}

function ValidareForm()
{
	var saveit = true;
	var produs,os,nume,email,text;

 		produs=document.getElementById('suport').produs;
  		os=document.getElementById('suport').os;
  		nume=document.getElementById('suport').nume;
  		email=document.getElementById('suport').email;
  		text=document.getElementById('suport').text;

  		if(produs.value.length ==0)
		{
   			alert ('Introduceți denumirea produsului!');
   			produs.focus();
    		produs.select();
   			return;
		}
  		if (nume.value.length ==0)
  		{
   			alert ('Introduceți numele Dumneavoastră!');
   			nume.focus();
    		nume.select();
			return;
  		}

  		 if(email.value.length >0 && email.value.length <31)
  			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)))
  			{
  				alert("Adresa de e-mail nu este validă!");
				email.focus();
				email.select();
  				return;
  			}
  		if(email.value.length==0 || email.value.length >30)
  		{
  			alert("Adresa de e-mail nu este validă!");
			email.focus();
			email.select();
  			return;
  		}

  		if(text.value.length ==0)
   		{
    		alert ('Introduceți textul articolului!');
    		text.focus();
    		text.select();
    		return;
   		}
   		if (saveit)
   			document.getElementById('suport').submit();
}
/*end formSuportOnline.html*/


/*begin clientLegeNet.html*/
function WindowPropClientLegeNet(text)
{
	newWindow = window.open('','newWin','width=300,height=100');
	newWindow.document.write(text);
}

function ValidMsgClientLegeNet(titlu)
{
	//valideaza campurile pe care le introduci
		var saveit = true;
		var text,email;
		text=document.trimite.text;
		email=document.trimite.email;

		if(text.value.length ==0 )
		{
			alert ('Introduceți textul mesajului');
			text.focus();
			text.select();
			saveit = false;
		}
		if((email.value.length ==0 ) && saveit)
		{
			alert("Introduceți adresa de email");
			email.focus();
			email.select();
			saveit = false;
		}


		if(email.value.length >0)
			if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)))
			{
				alert("Adresa de email nu este valida");
				email.focus();
				email.select();
				saveit = false;
			}

		if (saveit)
		{
			WindowPropClientLegeNet("<html><head><title>Indaco Systems</title></head><body style=\"background-color: #EBEBEB; color: black;font-family: Arial; font-size: 10px; font-style: normal; line-height: 11px; font-weight: 100; \"><p>Vă mulțumim pentru opinia exprimată!</p><p class=main_produse_descriere align=right>Indaco Systems</p></body></html>");
			document.trimite.submit();
		}
	}
/*end clientLegeNet.html*/


/*begin clientIntrebari.html*/
function ValidateQuestionText()
{
    var saveit = true;
    var text;
    text = document.getElementById("text_nou");

    if(text.value.length ==0  )
    {
        alert ('Introduceți textul întrebării');
        text.focus();
        text.select();
        saveit = false;
    }

    if (saveit)
        {document.getElementById("adauga").submit();}
}
/*end clientIntrebari.html*/


/*begin comandaOnline.html*/
function CheckPhone(tel)
{
	allowed="1234567890.-/";
	for (i = 0; i < tel.length; i++)
	{
		var c=tel.charAt(i);
		if(allowed.indexOf(c)==-1)
		return false;
	}
	return true;
}
function checkFormValid() {
	$("#IF_FORM").submit(function(){
		
		
		return false;
	});
}

$(document).ready(function(){
	checkFormValid();

});


function ValidFormCommand()
{
	var nume,prenume,obj,tel,email,site,judet,localitate;
	var ok,produse;
	/*nume=document.getElementById("adauga").nume;
	prenume=document.getElementById("adauga").prenume;
	obj=document.getElementById("adauga").produse;
	tel=document.getElementById("adauga").tel;
	email=document.getElementById("adauga").email;
	site=document.getElementById("adauga").site;
	judet=document.getElementById("adauga").judet;
	localitate=document.getElementById("adauga").localitate;
	produse=document.getElementById("adauga").produse;*/
	
	
	
	ok = true;
	//if (nume.value.length==0)
	if($("input[name='nume']").val().length==0)
	{
		//alert ('Introduceti numele dvs.!');
		/*nume.removeClass('input-good');
		nume.addClass('input-bad');
		nume.focus();
		nume.select();*/
		$("input[name='nume']").removeClass('input-good');
		$("input[name='nume']").addClass('input-bad');
		ok = false;
	}
	else
	{
		$("input[name='nume']").removeClass('input-bad');
		$("input[name='nume']").addClass('input-good');
	}

	//if (prenume.value.length==0)
	if($("input[name='prenume']").val().length==0)
	{
		//alert ('Introduceti prenumele dvs.!');
		$("input[name='prenume']").removeClass('input-good');
		$("input[name='prenume']").addClass('input-bad');		
		ok = false;
	}
	else
	{
		$("input[name='prenume']").removeClass('input-bad');
		$("input[name='prenume']").addClass('input-good');
	}

	//if (localitate.value.length==0)
	if($("input[name='localitate']").val().length==0)
	{
		//alert ('Introduceti localitatea!');
		$("input[name='localitate']").removeClass('input-good');
		$("input[name='localitate']").addClass('input-bad');		
		ok = false;
	}
	else
	{
		$("input[name='localitate']").removeClass('input-bad');
		$("input[name='localitate']").addClass('input-good');
	}

	if ($("input[name='judet']").val().length==0)
	{
		//alert ('Introduceti judetul!');
		$("input[name='judet']").removeClass('input-good');
		$("input[name='judet']").addClass('input-bad');
		
		ok = false;
	}
	else
	{
		$("input[name='judet']").removeClass('input-bad');
		$("input[name='judet']").addClass('input-good');
	}

	if($("select[name='produse[]'] option:selected").length == 0)
	{
		//alert('Alegeti cel putin un produs!');
		$("select[name='produse[]']").removeClass('input-good');
		$("select[name='produse[]']").addClass('input-bad');
		ok = false;
	}
	else
	{
		$("select[name='produse[]']").removeClass('input-bad');
		$("select[name='produse[]']").addClass('input-good');
	}
	
	if ($("input[name='tel']").val().length==0)
	{
		//alert ('Introduceti numarul de telefon!');
		$("input[name='tel']").removeClass('input-good');
		$("input[name='tel']").addClass('input-bad');		
		ok = false;
	}
	else
	{
		$("input[name='tel']").removeClass('input-bad');
		$("input[name='tel']").addClass('input-good');
	}

	//if(!CheckPhone($("input[name='tel']").val()))
	if(!(/^[0-9+]{1}[0-9. ]*[0-9]{1}$/.test($("input[name='tel']").val())))
	{
		//alert ('Introduceti cu atentie numarul de telefon!');
		$("input[name='tel']").removeClass('input-good');
		$("input[name='tel']").addClass('input-bad');
		
		ok = false;
	}
	else
	{
		$("input[name='tel']").removeClass('input-bad');
		$("input[name='tel']").addClass('input-good');
	}
	

	if ($("input[name='email']").val().length==0)
	{
		//alert ('Introduceti adresa de email!');
		$("input[name='email']").removeClass('input-good');
		$("input[name='email']").addClass('input-bad');		
		ok = false;
	}
	else
	{
		$("input[name='email']").removeClass('input-bad');
		$("input[name='email']").addClass('input-good');
	}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($("input[name='email']").val())))
	{
		//alert('Adresa de e-mail invalida!');
		$("input[name='email']").removeClass('input-good');
		$("input[name='email']").addClass('input-bad');		
		ok = false;
	}
	else
	{
		$("input[name='email']").removeClass('input-bad');
		$("input[name='email']").addClass('input-good');
	}
	if(!ok)
	{
		alert('Nu ati completat campurile obligatorii!');
		return;
	}
	document.getElementById("adauga").operatie.value='add';
	document.getElementById("adauga").submit();
}
/*end comandaOnline.html*/


/*begin comandaCard.html*/
function ValidFormCommandCard()
{
	var nume,prenume,obj,tel,email,site,localitate,judet;

	nume=document.getElementById("adauga").nume;
	tel=document.getElementById("adauga").tel;
	email=document.getElementById("adauga").email;

	if (nume.value.length==0)
	{
	        alert ('Introduceți numele dvs.!');
	        nume.focus();
	        nume.select();
	        return;
	}

	if (tel.value.length==0)
	{
	        alert ('Introduceți numărul de telefon!');
	        tel.focus();
	        tel.select();
	        return;
	}

	if (email.value.length==0)
	{
	        alert ('Introduceți adresa de e-mail!');
	        email.focus();
	        email.select();
	        return;
	}

	if (!(/^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$/.test(email.value)))
	{
	        alert('Adresă de e-mail invalidă!');
	        email.focus();
	        email.select();
	        return;
	}
	document.getElementById("adauga").operatie.value='add';
	document.getElementById("adauga").submit();
}
/*end comandaCard.html*/

/*begin checkout.html*/
function ValidFormCheckout()
{
    var user,passwd;
    user=document.getElementById("adauga").user;
    passwd=document.getElementById("adauga").passwd;

    if (user.value.length==0)
    {
        alert ('Introduceți un nume de utilizator!');
        user.focus();
        user.select();
        return;
    }

    if (passwd.value.length==0)
    {
        alert ('Introduceți o parolă validă!');
        passwd.focus();
        passwd.select();
        return;
    }
    document.getElementById("adauga").submit();
}
/*end checkout.html*/

/*begin produseLegeStart.html*/
function ValidFormLegeStart()
{
	//valideaza campurile pe care le introduci
	var saveit = true;
	var id;
	id=document.getElementById("password");

	if( id.value.length == 0 )
	{
		alert ('Introduceți parola de LegeStart');
		id.focus();
		id.select();
		saveit = false;
	}
	else
	{
	    document.getElementById("logareLS").submit();
	}
}
/*end produseLegeStart.html*/

/*begin forum.html*/
function ValidFormForum()
{
	//valideaza campurile pe care le introduci
	var saveit = true;
	var nume, email, subj, text, security_code ;

	nume  = document.getElementById("nume1");
	email = document.getElementById("email");;
	subj  = document.getElementById("subj");;
	text  = document.getElementById("text");;
	security_code  = document.getElementById("security_code");;

	if (security_code.value.length==0)
	{
		alert("Introduceți codul din imagine!");
		security_code.focus();
		security_code.select();
		saveit = false;
	}

	if (nume.value.length==0)
	{
		alert("Nume necompletat!");
		nume.focus();
		nume.select();
		saveit = false;
	}

	if(email.value.length >0)
	{
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)))
		{
			alert("Adresă de email în format incorect!");
			email.focus();
			email.select();
			saveit = false;
	  	}
	}
	if(subj.value.length ==0 )
	{
	    if(saveit)
	    {
	        alert("Subiectul mesajului este obligatoriu!");
	        subj.focus();
	        subj.select();
	        saveit = false;
	    }
	}
	if(text.value.length ==0 )
	{
	    if(saveit)
	    {
	        alert("Textul mesajului este obligatoriu!");
	        text.focus();
	        text.select();
	        saveit = false;
	    }
	}
	if (saveit)
	{
	    document.getElementById("mesaj").submit();
	}
}
/*end forum.html*/

/*search form*/
	function ValidateSearch()
	{

		word = TrimBlank(document.getElementById("searchText").value);
		var obj = document.getElementById('searchText');
		var encoded = obj.value;
		obj.value = unescape(encoded.replace(/\+/g,  " "));
		document.getElementById("searchTextH").value = obj.value;
		document.getElementById("searchText").value = "";
		//alert(document.getElementById("searchTextH").value);
		if(word.length < 4)
		{
	        	alert("Textul căutat trebuie să conțină minim 4 caractere");
	        	return;
	    	}
	    document.getElementById("searchForm").submit();
	}
	function TrimBlank(text)
	{

		while(text.charAt(0)==' ')
		{
			text = text.substring(1,text.length );
		}

		while(text.charAt(text.length - 1) == ' ')
		{
			text = text.substring(0,text.length - 1)
		}
		return text;
	}
/*end search form*/

/*begin traduceri form*/
function ValidFormTraduceri()
{
		nume = document.getElementById("nume");
		if(nume.value.length == 0)
		{
		alert ('Introduceți numele');
		nume.focus();
		nume.select();
		return false;
		}

		prenume=document.getElementById("prenume");
		if(prenume.value.length == 0)
		{
		alert ('Introduceți prenumele');
		prenume.focus();
		prenume.select();
		return false;
		}

		email=document.getElementById("email");
		if(email.value.length ==0)
		{
			alert("Introduceți adresa de e-mail");
		email.focus();
		email.select();
		return false;
		}

	if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value)))
	{
		alert("Adresa de e-mail nu este valida");
		email.focus();
		email.select();
		return false;
	}

		telfax=document.getElementById("telfax");
		if(telfax.value.length==0)
		{
			alert("Introduceți nr. de telefon sau fax");
		telfax.focus();
		telfax.select();
		return false;
		}

		companie=document.getElementById("companie");
		if(companie.value.length==0)
		{
			alert("Introduceți numele firmei");
		companie.focus();
		companie.select();
		return false;
		}

		adresa=document.getElementById("adresa");
		if(adresa.value.length==0)
		{
			alert("Introduceți adresa firmei");
		adresa.focus();
		adresa.select();
		return false;
		}

		id_tip_act=document.getElementById("id_tip_act");
		if(id_tip_act.value.length==0)
		{
			alert("Alegeți tipul actului");
		id_tip_act.focus();
		return false;
		}

		nr_act=document.getElementById("nr_act");
		if(nr_act.value.length==0)
		{
			alert("Introduceți numărul actului");
		nr_act.focus();
		nr_act.select();
		return false;
		}

		id_emitent=document.getElementById("id_emitent");
		if(id_emitent.value.length==0)
		{
			alert("Alegeți emitentul actului");
		id_emitent.focus();
		return false;
		}

		an_act=document.getElementById("an_act");
		if(an_act.value.length==0)
		{
			alert("Introduceți anul actului");
		an_act.focus();
		an_act.select();
		return false;
		}

		limba=document.getElementById("limba");
		if(limba.value.length==0)
		{
			alert("Alegeți limba în care doriți traducerea");
		limba.focus();
		return false;
		}

		document.getElementById("solicitare").submit();
		return true;
	}
	
	function ValidareFormChestionar()
	{
		document.getElementById("chestionar").submit();
		return true;
	}
	
/*begin seminarii/inregistrare.html*/
function ValidFormSeminarii()
{
	//valideaza campurile pe care le introduci
	var saveit = true;

	field=document.getElementById("companie");
	if (field.value.length==0)
	{
		alert("Denumire companie/nume si prenume necompletat!");
		field.focus();
		field.select();
		saveit = false;
		return;
	}

	field=document.getElementById("cif_cnp");
	if (field.value.length==0)
	{
		alert("Certificat de inregistrare fiscala/C.N.P. necompletat!");
		field.focus();
		field.select();
		saveit = false;
		return;
	}

	field=document.getElementById("adresa");
	if (field.value.length==0)
	{
		alert("Adresa necompletată!");
		field.focus();
		field.select();
		saveit = false;
		return;
	}

	field=document.getElementById("nr_participanti");
	if (field.value.length==0)
	{
		alert("Numarul participantilor necompletat!");
		field.focus();
		field.select();
		saveit = false;
		return;
	}

	field=document.getElementById("nume_participanti");
	if (field.value.length==0)
	{
		alert("Numele participantilor necompletat!");
		field.focus();
		field.select();
		saveit = false;
		return;
	}

	field=document.getElementById("pers_contact");
	if (field.value.length==0)
	{
		alert("Persona de contact necompletată!");
		field.focus();
		field.select();
		saveit = false;
		return;
	}

	field=document.getElementById("telefon_fax");
	if (field.value.length==0)
	{
		alert("Telefon/fax necompletat!");
		field.focus();
		field.select();
		saveit = false;
		return;
	}

	field=document.getElementById("email");
	if(field.value.length==0)
	{
		alert("Email necompletat!");
		field.focus();
		field.select();
		saveit = false;
		return;
	}

	field=document.getElementById("email");
	if(field.value.length >0)
	{
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(field.value)))
		{
			alert("Adresă de email în format incorect!");
			field.focus();
			field.select();
			saveit = false;
			return;
	  	}
	}
	
	if (saveit)
	{
	    document.getElementById("seminarii").submit();
	}
}
/*end seminarii/inregistrare.html*/