jQuery(document).ready(function () 
{
	
	jQuery(".dashboard").datepicker({ dateFormat: 'dd/mm/yy', showOn: 'both', buttonImage: 'img/date.gif', buttonImageOnly:true, changeMonth: true, changeYear: true });
	jQuery('.jqlb').lightBox();
	
	jQuery("#formular-contnou-pf").submit(function () {
				return validari_cont_nou_pf();
			});
	jQuery("#formular-contnou-pj").submit(function () {
				return validari_cont_nou_pj();
			});
	jQuery("#formular-contmod-pf").submit(function () {
				return validari_cont_mod_pf();
			});
	jQuery("#formular-contmod-pj").submit(function () {
				return validari_cont_mod_pj();
			});
	
	jQuery("#tara").change(function () {
			  tara_sel=jQuery("select[name='tara'] option:selected").val();		
			  jQuery.ajax({
					   type: "GET",
					   url: "actions/get_orase.php",
					   cache: false,
					   data: ({tara: tara_sel}),
					   complete: function (XH, textmes) {
						  if(textmes!="success")
							{
								alert("Eroare de accesare: "+textmes);
							}
						},
					   success: function(html){
						 jQuery("#mes_oras").html(html);
						}
	
					 });
			});
	
	jQuery("#tara_adm").change(function () {
			  tara_sel=jQuery("select[name='tara'] option:selected").val();		
			  jQuery.ajax({
					   type: "GET",
					   url: "actions/get_orase_adm.php",
					   cache: false,
					   data: ({tara: tara_sel}),
					   complete: function (XH, textmes) {
						  if(textmes!="success")
							{
								alert("Eroare de accesare: "+textmes);
							}
						},
					   success: function(html){
						 jQuery("#mes_oras").html(html);
						}
	
					 });
			});
	
	jQuery("input[name='p_toatatara']").change(function () {
			 
			 	if(this.checked)
					{
						var chdomenii=jQuery("input[name^='tar_']");
						for(i=0; i<chdomenii.length; i++)
							{
								chdomenii[i].checked=true;
							}
					}
			 	else
					{
						var chdomenii=jQuery("input[name^='tar_']");
						for(i=0; i<chdomenii.length; i++)
							{
								chdomenii[i].checked=false;
							}
					}
			});
	
	jQuery("a.mes_ul_mesaj").click(function() {
				jQuery("#utile_contact").addClass("mes_invisible");
				jQuery(".mes_box_contact").removeClass("mes_invisible");
				return false;
			});
	
	jQuery("a.mes_ul_mesajrep").click(function() {
				jQuery(".mes_box_contact").removeClass("mes_invisible");
				return false;
			});
	
	jQuery("input[name^='tar_']").change(function () {
			 
			 	if(!this.checked)
					{
						jQuery("input[name='p_toatatara']").attr("checked", false);
					}
			});
	
	jQuery("#p_tara").change(function () {
			  tara_sel=jQuery("select[name='p_tara'] option:selected").val();		
			  jQuery.ajax({
					   type: "GET",
					   url: "actions/get_p_orase.php",
					   cache: false,
					   data: ({tara: tara_sel}),
					   complete: function (XH, textmes) {
						  if(textmes!="success")
							{
								alert("Eroare de accesare: "+textmes);
							}
						},
					   success: function(html){
						 jQuery("#mes_oras").html(html);
						}
	
					 });
			});
	
	
	jQuery("#formular-oferta-noua").submit(function () {
				return validari_oferta();
			});
	jQuery("#formular-profil").submit(function () {
				return validari_profil();
			});
	
	jQuery("#formular-profil_contact").submit(function () {
				return validari_profil_contact();
			});
	jQuery("#formular-mesaj_raspuns").submit(function () {
				return validari_mesaj_raspuns();
			});
	
	
	jQuery("a.askvalid").click(function () {
				var raspuns;
				raspuns=window.confirm('Sunteti sigur?'); 
				if(raspuns) {
					return true;
				}
				else {
					return false;
				}
				
			});
	

	jQuery("select[name='ca_type']").change(function () {
		
		  tipul_sel=jQuery("select[name='ca_type'] option:selected").val();		
		  cat_sel=jQuery("input[name='ca_catsel']").val();			
		  jQuery.ajax({
				   type: "GET",
				   url: "actions/adv_settype.php",
				   cache: false,
				   data: ({tipul: tipul_sel, selectata: cat_sel,}),
				   complete: function (XH, textmes) {
					  if(textmes!="success")
					  	{
					  		alert("Eroare de accesare: "+textmes);
						}
					},
				   success: function(html){
					 jQuery("#adv_cat").html(html);
				    }

				 });
			}).change();


}
);
