jQuery(document).ready(function () 
{
	
	jQuery(".dashboard").datepicker({ dateFormat: 'dd/mm/yy', showOn: 'both', buttonImage: 'img_mt/date.gif', buttonImageOnly:true, changeMonth: true, changeYear: true });
	
	jQuery("#search_field_word").autocomplete("actions/hint_word.php");	
	jQuery("#search_field_cat").autocomplete("actions/hint_cat.php");	
	jQuery("#search_field_loc").autocomplete("actions/hint_loc.php");	
	
	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("input.textform, textarea.textform").focus(function () {
				jQuery(this).addClass("textform_focus");
			});
	jQuery("input.textform, textarea.textform").blur(function () {
				jQuery(this).removeClass("textform_focus");
			});
	
	
	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}),
					   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}),
					   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("#lead_tara").change(function () {
			  tara_sel=jQuery("select[name='tara'] option:selected").val();		
			  jQuery.ajax({
					   type: "GET",
					   url: "actions/get_lead_orase.php",
					   cache: false,
					   data: ({tara: tara_sel}),
					   success: function(html){
						 jQuery("#mes_oras").html(html);
						}
	
					 });
			});
	
	jQuery("#admin_tara").change(function () {
			  tara_sel=jQuery("select[name='tara'] option:selected").val();		
			  jQuery.ajax({
					   type: "GET",
					   url: "actions/get_admin_orase.php",
					   cache: false,
					   data: ({tara: tara_sel}),
					   success: function(html){
						 jQuery("#admin_oras_div").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("#abonare_newsletter").submit(function () {
				return validari_abonare_newsletter();
			});
	
	

	

	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,}),
				   success: function(html){
					 jQuery("#adv_cat").html(html);
				    }

				 });
			}).change();


}
);

function get_profil_zona()
{
  oras_sel=jQuery("select[name='p_oras'] option:selected").val();		
  jQuery.ajax({
		   type: "GET",
		   url: "actions/get_p_zone.php",
		   cache: false,
		   data: ({oras: oras_sel}),
		   success: function(html){
			 jQuery("#mes_zona").html(html);
			 if(jQuery("input[name='p_add_oras']").attr("id")=="p_add_oras")
			 	{
					get_profil_oras();
				}
			}

		 });
}

function get_profil_tara()
{

  jQuery.ajax({
		   type: "GET",
		   url: "actions/get_p_tari.php",
		   cache: false,
		  
		   success: function(html){
			 jQuery("#mes_tara").html(html);
			 get_profil_oras();
			}

		 });
}

function get_profil_oras()
{  
	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}),
		   success: function(html){
			 jQuery("#mes_oras").html(html);
			 get_profil_zona();
			 if(jQuery("input[name='p_add_tara']").attr("id")=="p_add_tara")
			 	{
					get_profil_tara();
				}
			}

		 });
}




