// JavaScript Document
function CercaAffitto(){
	
$("#aff input[value='1']").attr('checked', 'checked');	
$("#aff input[value='1']").click();
AvviaRicerca()
}

function CercaXFra(ID){
	
$("#FraRicerca option[value='"+ID+"']").attr('selected', 'selected');
$("#AssRicerca option[value='']").attr('selected', 'selected');
$("#AgeRicerca option[value='']").attr('selected', 'selected');
$('#Ricerca_Avanzata').show()
$('#RicercaSemplice_btn').hide()
AvviaRicerca()
$("#FraRicerca").change()
$("#AssRicerca").change()
$("#AgeRicerca").change()
}
function CercaXAss(ID){
	
$("#AssRicerca option[value='"+ID+"']").attr('selected', 'selected');
$("#FraRicerca option[value='']").attr('selected', 'selected');
$("#AgeRicerca option[value='']").attr('selected', 'selected');
$('#Ricerca_Avanzata').show()
$('#RicercaSemplice_btn').hide()
AvviaRicerca()
$("#AssRicerca").change()
$("#FraRicerca").change()
$("#AgeRicerca").change()
}
function CercaXAge(ID){
	
$("#AgeRicerca option[value='"+ID+"']").attr('selected', 'selected');
$("#FraRicerca option[value='']").attr('selected', 'selected');
$("#AssRicerca option[value='']").attr('selected', 'selected');
$('#Ricerca_Avanzata').show()
$('#RicercaSemplice_btn').hide()
AvviaRicerca()
$("#AgeRicerca").change()
$("#AssRicerca").change()
$("#FraRicerca").change()

}

function AvviaRicerca(IDForm){
if (IDForm == '')	{
	IDForm = 'ricerca';
}
getajaxPost(IDForm,'RisultatoRicerca.asp','Contenitore_Sinistro');
$('#Content_Banner_inLine').hide();
$('#Contenitore_Scheda').hide();
$('#Contenitore_Scheda').html(''); 
$('#Contenitore_Sinistro').show();
$('#Contenitore_Destro').show();
$('#SalvataggioInCorso').show()	;
	
}

function ApriScheda(ID){
	
	
	getajax('Scheda.asp?ID='+ID,'Contenitore_Scheda');
	$('#Content_Banner_inLine').hide();
	$('#Contenitore_Scheda').show();
	$('#Contenitore_Sinistro').hide();
	$('#Contenitore_Destro').hide();
	$('#SalvataggioInCorso').show();
	

	
}

function ChiudiScheda(){


//getajaxPost('ricerca','RisultatoRicerca.asp?Page=<%=nPage%>','Contenitore_Sinistro');
$('#Contenitore_Scheda').hide();
$('#Contenitore_Sinistro').show();
$('#Contenitore_Destro').show();
$('#Contenitore_Scheda').html('')


	
}
function ForzaRicerca(Categoria, sottocat,stato){
	
	$("#Cat option[value='"+ Categoria+ "']").attr('selected', 'selected')
	$("#Cat").change();
	if (sottocat != null) {
		//$("#Cat").change()
		getajax('selectCategoriaCerca.asp?categoria='+Categoria+'&sub='+sottocat,'categoriaCerca')
		//alert(sottocat)
		//$("#subcCerca option[value='"+ sottocat+ "']").attr('selected', 'selected')
		
		}
	if (stato != null) {
		//$("#SottCat option[value='"+ sottocat+ "']").attr('selected', 'selected')
	
		}
	
	$('#Content_Banner_inLine').hide()
	$('#BtnRicerca').click()

}

function vediInputASP(NomeForm){
	Temp = ''
	
	$('#'+ NomeForm +' input').each(function(){	
		Temp += $(this).attr('name') + '= request.Form("' + $(this).attr('name') + '")  <br>' 
	
	});
	$('#'+ NomeForm +' select').each(function(){	
		Temp +=$(this).attr('name') + ' = request.Form("' +  $(this).attr('name') + '")  <br>' 
	
	});
	
	$('#'+ NomeForm +' textarea').each(function(){	
		Temp +=$(this).attr('name') + ' = request.Form("' +  $(this).attr('name') + '")  <br>' 
	
	});
	
	$("#divresult").html(Temp)
}

function vediInput(NomeForm){
	Temp = ''
	
	$('#'+ NomeForm +' input').each(function(){	
		Temp += $(this).attr('name') + '<br>' 
	
	});
	$('#'+ NomeForm +' select').each(function(){	
		Temp +=$(this).attr('name') + ' <br>' 
	
	});
	
	$('#'+ NomeForm +' textarea').each(function(){	
		Temp +=$(this).attr('name') + ' <br>' 
	
	});
	
	$("#divresult").html(Temp)
}
		
		
//se clicchi un intestazione campo cambia ordine con cambio freccia per indicare il verso
function 	Ordina(campo,NomeForm){
			switch (document.forms[NomeForm].elements[campo].value){
			
			
			case "up":
				document.forms[NomeForm].elements[campo].value = "down";
				break;
			
			case "down":
				document.forms[NomeForm].elements[campo].value = "up";
				break;
			default:
				document.forms[NomeForm].elements[campo].value = "up";
				break;
			}
			document.forms[NomeForm].submit();
			
							
}

function ControlloInvio(Div_ID){
	
	if(event.keyCode == 13)
		{
			
				$('#' + Div_ID).show('slow');
		}
	}
	
	



// caricamento pagina in ajax
function getajax(strurl,ndiv) {
                $.ajax({
                  type: "GET",
      			  cache: false,
                  url: strurl,
                  success: function(msg){
                           $("#"+ndiv).html(msg);
                  }
                });
 //alert(strurl)
 //return false
 }
 
 // caricamento pagina in ajax
function getajaxPost(NomeForm,strurl,ndiv) {

                $.ajax({	
                  type: "POST",
      			  cache: false,
				  
				  data: $('#'+ NomeForm).serialize(),
                  url: strurl,
				  success: function(msg){			
 							   
                           $("#"+ndiv).html(msg);
                  },
				   error: function()
					  {
						alert("Chiamata fallita, si prega di riprovare..." );
					  }
                });
 //return false
 }
 
 function getDiv(DivContenuto,DivContenitore){
	
	
	$('#' + DivContenitore).html($('#' + DivContenuto).html())	
	
}


function UnCheckBox (field){
	for (i = 0; i < field.length; i++)
				field[i].checked = false ;	
}

	
	
function CkCheckBox (field){
	for (i = 0; i < field.length; i++)
				field[i].checked = true ;	
}




function Evidenzia (Campo, Trigger)
{
	Campo = Campo.replace(' ', '')
	if(Trigger == 'on')
	{
		$('#' + Campo).addClass('Evidenziatore');
	}
	else
	{
		
		$('#' + Campo).removeClass('Evidenziatore');
	}
}


function Invia(Valore,NomeForm){
	document.forms[NomeForm].PostBack.value = Valore;
	
	document.forms[NomeForm].submit();
}



function TuttiSelCheck(classe,value){
	if (value.checked){
		$('.' + classe).attr('checked', true);

	}
	else{
		$('.' + classe).attr('checked', false);

	}
}


function InviaConConferma(NomeForm){
	
	
	if (confirm("Sicuro di ?")) {
		
		document.forms[NomeForm].submit();
		
	}
	}


function AbilitaSelect(ValoreVero,ValoreConf,IDCampo){
	if (ValoreVero == ValoreConf){
		$('#' + IDCampo).removeAttr('disabled');
		
	}
		
	else{
		
		$('#' + IDCampo).attr('disabled', 'disabled');
		
	}
	
	
}
	
