function reset_form(){
	for (i = 0; i < document.search_form.length; i++)
		document.search_form[i].checked = false ;
		
	
	with(document.search_form){
		
		for (i = 0; i < marca.options.length; i++){
			marca.options[i].selected = false ;
		}
		
		for (i = 0; i < meccanica.options.length; i++){
			meccanica.options[i].selected = false ;
		}
		
		for (i = 0; i < usertype_id.options.length; i++){
			usertype_id.options[i].selected = false ;
		}
		
		for (i = 0; i < km.options.length; i++){
			km.options[i].selected = false ;
		}
		
		for (i = 0; i < modello.options.length; i++){
			modello.options[i].selected = false ;
		}
		
		for (i = 0; i < data_immatricolazione.options.length; i++){
			data_immatricolazione.options[i].selected = false ;
		}
		
		marca.options[0].selected = true ;
		meccanica.options[0].selected = true ;
		km.options[0].selected = true ;
		modello.options[0].selected = true ;
		data_immatricolazione.options[0].selected = true ;
	}


}



function getPageSize() {
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}


function overlay_on() {
	var arrayPageSize = this.getPageSize();	
	document.getElementById('overlay').style.width= arrayPageSize[0] + 'px';
	document.getElementById('overlay').style.height= arrayPageSize[1] + 'px';
	document.getElementById('overlay').style.visibility='visible';
	document.getElementById('overlay').style.display='block';
}

function vis_on(id) {
	document.getElementById(id).style.display='block';
}


function vis_off(id) {
	document.getElementById(id).style.display='none';
}



function vis_scheda_prodotto(codice,usertype) {

	$.post('/scheda_usato.php','codice='+codice+'&usertype_id='+usertype,
		   function(msg){
				$('#contenitore_stampa').html(msg);
			}
		)
}

function vis_richiesta_contatti(codice,usertype) {

	$.post('/richiestainfo.php','codice='+codice+'&usertype_id='+usertype,
		   function(msg){
				$('#contenitore_richiesta').html(msg);
			}
		)
}


function getScrollX(id) {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
 
 
  document.getElementById(id).style.top = scrOfY+"px";
}


function chk_txt(o,v){
	if(o.value.search('[a-zA-Z0-9]') == -1){
		if(arguments.length==1) alert('Campo ' + o.name + ' errato');
		else if(arguments.length==2) alert(v);
		o.focus();
		return false;
	}
	return true;
}



function chk_email(o,d){
	if(o.value.search("^[0-9a-zA-Z]([-_.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-.]?[0-9a-zA-Z])*\\.[a-zA-Z]{2,4}$") == -1){
		alert(d);
		o.focus();
		return false;
	}
	return true;
}

function chk_box(o,d){
	if(!o.checked){
		alert(d);
	    //document.registrazione.focus();
	    return false;
	}else{
	 return true;
	}
}

function chk_aut(){
	if(!document.contatti2.check_privacy.checked){
		alert("E' necessario fornire il proprio consenso");
	    //document.registrazione.focus();
	    return false;
	}else{
	 return true;
	}
}

function non_selezionare(){
	alert('Attenzione, il testo non  selezionabile');
	return false;
}


