// JavaScript Document
function segnala()
{
	document.getElementById('segnala').submit();
}
function preferiti( utente, id)
{		
CreaAjax('action/prefer.php?user='+ utente+'&id='+id, 'prefer');
}
function stampante()
{
	self.print();
}
function newsletter_form()
{
	document.getElementById('nwsltt').submit();
}
function ricerca()
{
	document.getElementById('ricerca_form').submit();
}
function login_form()
{
	document.getElementById('log_form').submit();
}
function CreaAjax(q, elemento)
{
	if (window.XMLHttpRequest)
	{
		xmlhttp = new XMLHttpRequest();
	}
	else
	{
		xmlhttp = new ActiveXObject("Microsoft.XMLMHTTP");
	}
	
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
		{
			document.getElementById(elemento).innerHTML = xmlhttp.responseText;
		}
	}
	
	xmlhttp.open("GET", q, true);
	xmlhttp.send();
}
function trim(stringa){
    while (stringa.substring(0,1) == ' '){
        stringa = stringa.substring(1, stringa.length);
    }
    while (stringa.substring(stringa.length-1, stringa.length) == ' '){
        stringa = stringa.substring(0,stringa.length-1);
    }
    return stringa;
}

function svuota( id ) 
{
	document.getElementById(id).value  = "";
}
function invia_reg(){
	password =document.getElementById('pwd').value;
	conferma =document.getElementById('conf_pwd').value;
	termini  =document.getElementById('ch1_hid').value;
	privacy  =document.getElementById('ch2_hid').value;
	cod		 =document.getElementById('cod').value;
	
	if( ( password == conferma ) && ( termini == 1 ) && ( privacy == 1 ) && (cod == 4) )
	{
		document.getElementById('form_reg').submit();
	}else{
		window.scrollTo(0,0);
		document.getElementById('ritorno').innerHTML = "Controllare tutti i campi";
	}
}
function convalida_mail(mail)
{
	CreaAjax('ajax/controllo.php?tipo=mail&mail='+mail,'ritorno');
}
function controllo_nick(nick)
{
	CreaAjax('ajax/controllo.php?tipo=nick&nick='+nick,'ritorno');
	
}
function check( x )
{
	if( x == 1 )
	{
		if( (document.getElementById('ch1_hid').value) == 0 )
		{
			document.getElementById('ch1_hid').value = 1;
			document.getElementById('ch1').src = "reg/check_on.png";
		}
		else
		{
			document.getElementById('ch1_hid').value = 0;
			document.getElementById('ch1').src = "reg/check.png";
		}
	}
	
	if( x == 2 )
	{
		if( (document.getElementById('ch2_hid').value) == 0 )
		{
			document.getElementById('ch2_hid').value = 1;
			document.getElementById('ch2').src = "reg/check_on.png";
		}
		else
		{
			document.getElementById('ch2_hid').value = 0;
			document.getElementById('ch2').src = "reg/check.png";
		}
	}
}

function radio( x )
{
	if( x == 1 )
	{
		document.getElementById('r1_hid').value=1;
		document.getElementById('radio1').src="reg/radio_on.png";
		document.getElementById('r2_hid').value=0;
		document.getElementById('radio2').src="reg/radio.png";
	}
	if( x == 2 )
	{
		document.getElementById('r2_hid').value=1;
		document.getElementById('radio2').src="reg/radio_on.png";
		document.getElementById('r1_hid').value=0;
		document.getElementById('radio1').src="reg/radio.png";
	}
}

function login()
{
	document.getElementById('log_form').submit();
}
function input_log( x )
{
	if( x == 1 )
	{
		document.getElementById('n').value="";
	}
	if( x == 2 )
	{
		document.getElementById('p').value="";
		document.getElementById('p').type="password";	
	}
}
function vetrina( x )
{
	document.getElementById('prova').innerHTML = "<p>"+x+"</p>";
}
function vetrina( cont1, cont2, ven, aq)
{	
	
	CreaAjax('ajax/vetrina.php','prima_vetrina');
	CreaAjax('ajax/vetrina.php','prova');

	CreaAjax('ajax/vetrina.php','terza_vetrina');
	
}
function vetrina_seguente( venditore,acquirente, contatore1, contatore2 ) 
{   ven=venditore++;
	aq =acquirente++;
	setTimeout("vetrina(contatore1,contatore2, ven, aq)",700);
}





















