jQuery(document).ready(function(){
	hinter_el=jQuery("#hinter");
	if(hinter_el.length)
		{
			hintarr=new Array();
			hintarr=hinter_el.val().split(",");
			for(i=0; i<hintarr.length; i++)
				{
					alexh_init(hintarr[i]);
				}
		}

	//calendare
	jQuery(".dashboard").datepicker({ dateFormat: 'dd/mm/yy', showOn: 'both', buttonImage: 'img/date.gif', buttonImageOnly:true, changeMonth: true, changeYear: true });






		
	jQuery("#jq_marca").change(function () { 
		  marca_sel=jQuery("#jq_marca option:selected").val();			
          jQuery("#jq_profilul").html('Se incarca... Va rugam sa asteptati!<br /><img src="img/ajax.gif" border="0" />');
		  jQuery.ajax({
				   type: "GET",
				   url: "actions/req_profilul.php",
				   cache: false,
				   data: ({marca: marca_sel}),
				   complete: function (XH, textmes) {
					  if(textmes!="success")
					  	{
					  		alert("Eroare de accesare: "+textmes);
						}
					},
				   success: function(html){
					 jQuery("#jq_profilul").html(html);
				    }

				 });
        });
});


function save_pret()
{
  id_off=jQuery("#id_oferta").val();	
  pr_off=jQuery("#price_oferta").val();	
  jQuery.ajax({
	   type: "POST",
	   url: "actions/save_pret.php",
	   cache: false,
	   data: ({id: id_off, price: pr_off}),
	   success: function(html){
	     pretarr=html.split(":::");
		 jQuery("#pretfurnizor_"+id_off).html(pretarr[0]);
		 jQuery("#price_"+id_off).html(pretarr[1]);
		 jQuery("#prredus_"+id_off).html(pretarr[2]);
		 tb_remove();
		}

	 });
  return false;
}
function save_adaosp()
{
  id_off=jQuery("#id_oferta").val();	
  ad_off=jQuery("#adaosp_oferta").val();	
  jQuery.ajax({
	   type: "POST",
	   url: "actions/save_adaosp.php",
	   cache: false,
	   data: ({id: id_off, adaosp: ad_off}),
	   success: function(html){
	     pretarr=html.split(":::");
		 jQuery("#adaosp_"+id_off).html(pretarr[0]);
		 jQuery("#price_"+id_off).html(pretarr[1]);
		 jQuery("#prredus_"+id_off).html(pretarr[2]);
		 tb_remove();
		}

	 });
  return false;
}

function save_pretlista()
{
  id_off=jQuery("#id_oferta").val();	
  pr_off=jQuery("#price_oferta").val();	
  jQuery.ajax({
	   type: "POST",
	   url: "actions/save_pretlista.php",
	   cache: false,
	   data: ({id: id_off, price: pr_off}),
	   success: function(html){
	     pretarr=html.split(":::");
		 jQuery("#pretlista_"+id_off).html(pretarr[0]);
		 jQuery("#price_"+id_off).html(pretarr[1]);
		 jQuery("#prredus_"+id_off).html(pretarr[2]);
		 tb_remove();
		}

	 });
  return false;
}


function save_codpret()
{
  id_off=jQuery("#id_oferta").val();	
  pr_off=jQuery("#codpret").val();	
  jQuery.ajax({
	   type: "POST",
	   url: "actions/save_codpret.php",
	   cache: false,
	   data: ({id: id_off, codpret: pr_off}),
	   success: function(html){
		 
		 jQuery("#codpr_"+id_off).html(html);
		 tb_remove();
		}

	 });
  return false;
}


function filtru_latime()
{
  camp_sel=jQuery("#filt_latime option:selected").val();		
  jQuery.ajax({
		   type: "GET",
		   url: "actions/get_inaltime.php",
		   cache: false,
		   data: ({upperf: camp_sel}),
		   success: function(html){
			 jQuery("#div_inaltime").html(html);
			}

		 });
  jQuery("#div_diametru").html('<select class="aj_rounded_sel" name="diametru" id="filt_diametru" disabled="disabled"><option value="">Diametru</option></select>');
}
function filtru_inaltime()
{

  camp_sel=jQuery("#filt_inaltime option:selected").val();
  camp_sel2=jQuery("#filt_latime option:selected").val();	
  
  jQuery.ajax({
		   type: "GET",
		   url: "actions/get_diametru.php",
		   cache: false,
		   data: ({upperf: camp_sel, upperf2: camp_sel2,}),
		   success: function(html){
			 jQuery("#div_diametru").html(html);
			}

		 });
}
function filtru_marcaauto()
{

  camp_sel=jQuery("#filt_marcaauto option:selected").val();

  jQuery.ajax({
		   type: "GET",
		   url: "actions/get_diametru_jante.php",
		   cache: false,
		   data: ({upperf: camp_sel}),
		   success: function(html){
			 jQuery("#div_diametru").html(html);
			}

		 });
}
function filtru_diametru()
{
	jQuery("#filt_form").submit();
}

function alexh_init(numecamp)
{
	jQuery("#"+numecamp).keydown(function(){ hintthis(numecamp, 'div_hint_'+numecamp, 'doblur_'+numecamp) });
	jQuery("#"+numecamp).keyup(function(){ hintthis(numecamp, 'div_hint_'+numecamp, 'doblur_'+numecamp) });
	jQuery("#"+numecamp).keypress(function(){ hintthis(numecamp, 'div_hint_'+numecamp, 'doblur_'+numecamp) });
	jQuery("#"+numecamp).focus(function(){ hintthis(numecamp, 'div_hint_'+numecamp, 'doblur_'+numecamp) });
	jQuery("#"+numecamp).blur(function(){ hide_hintthis(numecamp, 'div_hint_'+numecamp, 'doblur_'+numecamp) });
	jQuery("#"+numecamp).blur();
}




function hintthis(id_input, id_output, id_blur)
{
	
	el_input=jQuery("#"+id_input);
	el_tid=jQuery("#tableid");
	
	var XHT=GetXmlHttpObjectdum();
	if (XHT==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  }
	
	var url="actions/hintthis.php";
	url=url+"?text="+el_input.val();
	url=url+"&id_input="+id_input;
	url=url+"&table="+el_tid.val();
	url=url+"&id_output="+id_output;
	url=url+"&id_blur="+id_blur;
	url=url+"&sid="+Math.random();
	
	XHT.onreadystatechange=function() {
		hintthis_fill(XHT, id_input, id_output, id_blur);
	}
	
	
	XHT.open("GET",url,true);
	XHT.send(null);
}

function hintthis_fill(XHT, id_input, id_output, id_blur) 
{
if (XHT.readyState==4)
{
	response=XHT.responseText;
	if(response!='')
		{
			jQuery("#"+id_output).css("visibility","visible");
			jQuery("#"+id_output).parent().css("z-index","1000");
			jQuery("#"+id_output).html(response);
		}
	else
		{
			jQuery("#"+id_output).css("visibility","hidden");
			jQuery("#"+id_output).parent().css("z-index","999");
		}
}
}


function hide_hintthis(id_input, id_output, id_blur)
{
	if(jQuery("#"+id_blur).val()=="1")
		{			
			jQuery("#"+id_output).css("visibility","hidden");
			jQuery("#"+id_output).parent().css("z-index","999");
		}
}

function choose_hint(hintvalue, id_input, id_output, id_blur)
{
	el_obj=locate_el(id_input);
	el_obj.value=hintvalue;
	
	el_doblur=locate_el(id_blur);
	el_doblur.value="1";
	hide_hintthis(id_input, id_output, id_blur);
	return false;
}

function ch_do_blur(id_blur, vdb)
{
	el_doblur=locate_el(id_blur);
	el_doblur.value=vdb;
	return false;
}


jQuery(document).ready(function(){
	formcaut=jQuery("#form_cautare_avansata");
	if(formcaut.length)
		{
			jQuery("#latime").change(function(){ change_inaltime(); change_diametru(); });
			jQuery("#inaltime").change(function(){ change_diametru() });
			jQuery("#diametru").change(function(){ check_avansata_submit() });
		}
});

function change_inaltime()
{
	latime_selectata=jQuery("#latime option:selected").val();
		
	jQuery("#sel_inaltime").html('<img src="img/ajax.gif" border="0" />');
	
	
	jQuery.ajax({
	   type: "GET",
	   url: "actions/req_inaltimi.php",
	   cache: false,
	   data: ({latime: latime_selectata}),
	   complete: function (XH, textmes) {
		  if(textmes!="success")
			{
				alert("Eroare de accesare: "+textmes);
			}
		},
	   success: function(html){
			 jQuery("#sel_inaltime").html(html);
			 jQuery("#inaltime").change(function(){ change_diametru() });
			}
	});
}

function change_diametru()
{
	latime_selectata=jQuery("#latime option:selected").val();
	inaltime_selectata=jQuery("#inaltime option:selected").val();
		
	jQuery("#sel_diametru").html('<img src="img/ajax.gif" border="0" />');
	
	
	jQuery.ajax({
	   type: "GET",
	   url: "actions/req_diametre.php",
	   cache: false,
	   data: ({inaltime: inaltime_selectata, latime: latime_selectata}),
	   complete: function (XH, textmes) {
		  if(textmes!="success")
			{
				alert("Eroare de accesare: "+textmes);
			}
		},
	   success: function(html){
			 jQuery("#sel_diametru").html(html);
			 jQuery("#diametru").change(function(){ check_avansata_submit() });
			}
	});
}






function check_avansata_submit()
{
	amsub=1;
	if((jQuery("select#latime option:selected").val()!="") && (jQuery("select#inaltime option:selected").val()!="") && (jQuery("select#diametru option:selected").val()!=""))
		{
			jQuery("form#form_cautare_avansata").submit();
		}

}


jQuery(document).ready(function(){
	scrolldiv_el=jQuery("#scrolldiv");
	if(scrolldiv_el.length)
		{
			if(scrolldiv_el.html().length>157)
				{
					setTimeout("rotate_text()", 200);
				}
		}
});


function rotate_text()
{
	scrolldiv_el=jQuery("#scrolldiv");
	texta=scrolldiv_el.html();
	
	ntexta=texta.slice(1);
	ntexta=ntexta+texta.slice(0,1);
	
	scrolldiv_el.html(ntexta);
	setTimeout("rotate_text()", 200);
}


function reordoneaza()
{
	newl=jQuery("#wheretg").val();
	newl=newl+"&o_par_1="+jQuery("select#o_par_1 option:selected").val();
	newl=newl+"&o_par_2="+jQuery("select#o_par_2 option:selected").val();
	newl=newl+"&o_par_3="+jQuery("select#o_par_3 option:selected").val();
	newl=newl+"&o_par_4="+jQuery("select#o_par_4 option:selected").val();
	newl=newl+"&o_par_5="+jQuery("select#o_par_5 option:selected").val();
	newl=newl+"&reord_admin=da";
	
	window.location=newl;
}
