function getXMLHttp()
{
  var xmlHttp

  try
  {
    //Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    //Internet Explorer
    try
    {
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
      try
      {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)
      {
        alert("Your browser does not support AJAX!")
        return false;
      }
    }
  }
  return xmlHttp;
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features,'scrollbars=yes','resizable=yes','top=0','left=0');
}

function checkstag(pid)
{
var xmlHttp = getXMLHttp();
//document.write(cid);

xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      checks(xmlHttp.responseText, pid);
    }
  }
  
  xmlHttp.open("GET", "funzioni/functions_adm.php?a=activestag&pid="+pid, true);
  xmlHttp.send(null);
}

function checks(response, pid)
{	
	//document.write(cid);
	var rowag = document.getElementById('row_'+pid);
	
	if(response==1){
		rowag.style.backgroundColor="#a8ee69";
	}
	else if(response==0){
		rowag.style.backgroundColor="#ee6969";
	}
}


function checkroom(cid)
{
var xmlHttp = getXMLHttp();
//document.write(cid);

xmlHttp.onreadystatechange = function()
  {
    if(xmlHttp.readyState == 4)
    {
      checkr(xmlHttp.responseText, cid);
    }
  }
  
  xmlHttp.open("GET", "funzioni/functions_adm.php?a=activeroom&cid="+cid, true);
  xmlHttp.send(null);
}

function checkr(response, cid)
{	
	//document.write(cid);
	var rowag = document.getElementById('row_'+cid);
	
	if(response==1){
		rowag.style.backgroundColor="#a8ee69";
	}
	else if(response==0){
		rowag.style.backgroundColor="#ee6969";
	}
}


function descrooms(cidst) {
	$("#descrooms_"+cidst).slideToggle("10")
 	return false;
}

function opendescroom(cid) {
	$("#descroom_"+cid).slideToggle("10")
 	return false;
}

function editprices(cid) {
	$("#editprices_"+cid).slideToggle("10")
 	return false;
}
 
function editofferta(offid) {
	$("#editofferta_"+offid).slideToggle("10")
 	return false;
}
 
function openimgroom(cid) {
	$("#imgroom_"+cid).slideToggle("10")
 	return false;
 }

function editallotment(cid) {
	$("#editallotment_"+cid).slideToggle("10")
 	return false;
 }

function newlm()
{
	$("#newlm").slideToggle("200")
 	return false;
}

function newroom()
{
	$("#newr").slideToggle("200")
 	return false;
}

function ricerca()
{
	$("#ric").slideToggle("200")
 	return false;
}

function editroom(cid)
{
	$("#editroom_"+cid).slideToggle("200")
 	return false;
}

function newstagionalita()
{
	$("#newstag").slideToggle("200")
 	return false;
}

function editstag(pid)
{
	$("#editstag_"+pid).slideToggle("200")
 	return false;
}


function check(input, num_min) {

	e = document.getElementById(input);
	d = document.getElementById(input+'_1');
	s = document.getElementById('send');
	err = document.getElementById('error');
	
	n=document.getElementById('nome');
	c=document.getElementById('cognome');
	i=document.getElementById('indirizzo');
	ci=document.getElementById('citta');
	co=document.getElementById('cap');
	num=document.getElementById('telefono');
	cel=document.getElementById('cellulare');
	ma=document.getElementById('mail');
	re=document.getElementById('remail');
	con=document.getElementById('condizioni');
	

if(input=='send'){
	if ( (n.value=='') || (c.value=='') || (i.value=='') || (ci.value=='') || (co.value=='') || (num.value=='') || (cel.value=='') || (ma.value=='') || (re.value=='') ){
		err.innerHTML = 'Mi dispiace ma hai lasciato dei campi incompleti.'; 
		err.style.color='red';
		check('nome');
		check('cognome');
		check('indirizzo');
		check('citta');
		check('cap');
		check('telefono');
		check('cellulare');
		check('mail');
		check('remail');
		return false;
	}
	
else if(input=='send' && document.getElementById('condizioni').checked==false){
		err.innerHTML = 'Mi dispiace ma devi accettare le condizioni.'; 
		err.style.color='red';
		return false;
	}
	else{
		if(ma.value!=re.value){
			document.getElementById('mail').style.border='1px solid red';
			document.getElementById('remail').style.border='1px solid red';
			err.innerHTML = 'Mi dispiace ma le mail non coincidono.'; 
			err.style.color='red';
			return false;
		}
		else{
			return true;
		}		
	}
}
else{	
	if(e.value==''){
		d.innerHTML = '<img src="images/del.png" border="0">';    
		e.style.border='1px solid red';
		}
	else{
		d.innerHTML = '<img src="images/ok.png" border="0">';    
		e.style.border='1px solid green';
		}
}
}
