// JavaScript Document
var fine;
function main( pag_rich ){
// alert ('main');
 if (window.XMLHttpRequest) {
   xmlhttp = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  // alert ('fa ms cat');
} else {
   alert('Impossibile continuare: il tuo browser non supporta XMLHttpRequest.');
}

//alert('main');
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

xmlhttp.open('POST', pag_rich ,false);////////////////////////////////////////
 //  xmlhttp.setRequestHeader('Cache-Control','no-cache');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send("");

document.getElementById( 'main' ).innerHTML = xmlhttp.responseText;
}

function mainprinc( zect , pag_rich ){
//alert( 'mainprinc');
                  switch(zect) {
                  case '1':
				  title_text = 'myZOO';
				  title_img = 'wip.gif';
				  break;
                  case '2':
				  title_text = 'VoIParl&agrave;';
				  title_img = 'monkeytel.gif';
				  break;
                  case '3':
				  title_text = 'myCHANNELS';
				  title_img = 'myzoobig.png';
				  break;
                  case '4':
				  title_text = 'myPREF';
				  title_img = 'myzoobig.png';
				  break;
                  case '5':
				  title_text = 'MESSAGGI';
				  title_img = 'mymessage.gif';
				  break;
                  case '6':
				  title_text = 'RUBRICA';
				  title_img = 'address.png';
				  break;
                  case '7':
				  title_text = 'OPTIONS';
				  title_img = 'system.png';
				  break;
				}
	if (window.XMLHttpRequest) {
   xmlhttp = new XMLHttpRequest();
  // alert ('fa tutto cat');
} else if (window.ActiveXObject) { // IE
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  // alert ('fa ms cat');
} else {
   alert('Impossibile continuare: il tuo browser non supporta XMLHttpRequest.');
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}


   xmlhttp.open('POST', pag_rich , false);////////////////////////////////////////
   xmlhttp.setRequestHeader('Cache-Control','no-cache');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send("request");


titl ='<font face="Comic Sans MS" size="6" color="#ff9900"><b>'+ title_text +'</b>&nbsp;&nbsp;<img src="../images/clips/'+ title_img +'" align="absmiddle" ></font>';

document.getElementById( 'h_title' ).innerHTML = titl;

document.getElementById( 'main' ).innerHTML = xmlhttp.responseText;
}




function live_open( ){
	if (window.XMLHttpRequest) {
   xmlhttp = new XMLHttpRequest();
  // alert ('fa tutto cat');
} else if (window.ActiveXObject) { // IE
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  // alert ('fa ms cat');
} else {
   alert('Impossibile continuare: il tuo browser non supporta XMLHttpRequest.');
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}


   xmlhttp.open('POST',"../myzoo/livejx.php",false);////////////////////////////////////////
   xmlhttp.setRequestHeader('Cache-Control','no-cache');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send("call=check_liveon");
//alert ('live open risp: '+ xmlhttp.responseText);
//livewin =
if ( xmlhttp.responseText == '0'){
		var livewindow;
	 	var livewindow = window.open( "../pablolive.php" , "live","width=725, height=425, resizable =no, scrollbars=yes, toolbar=0, status=1");
		livewindow.focus();
	}

//if (livewindow) 


if (xmlhttp.responseText == '1') {
toop = confirm('Assicurati che la finestra di chat non sia gią aperta.\nPer proseguire premere premere su OK\n');

   if (toop ==true)
      {
		var livewindow;
	 	var livewindow = window.open( "../pablolive.php" , "live","width=725, height=425, resizable =yes, scrollbars=yes, toolbar=0, status=1");
		livewindow.focus();

	}
	} 

return false;

}

function live_open_try( ){
	if (window.XMLHttpRequest) {
   xmlhttp = new XMLHttpRequest();
  // alert ('fa tutto cat');
} else if (window.ActiveXObject) { // IE
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  // alert ('fa ms cat');
} else {
   alert('Impossibile continuare: il tuo browser non supporta XMLHttpRequest.');
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}


   xmlhttp.open('POST',"../myzoo/livejx.php",false);////////////////////////////////////////
   xmlhttp.setRequestHeader('Cache-Control','no-cache');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send("call=check_liveon");
//alert ('live open risp: '+ xmlhttp.responseText);
//livewin =
if ( xmlhttp.responseText == '0'){
		var livewindow;
	 	var livewindow = window.open( "../pablolivetry.php" , "live","width=725, height=425, resizable =no, scrollbars=yes, toolbar=0, status=1");
		livewindow.focus();
	}

//if (livewindow) 


if (xmlhttp.responseText == '1') {
toop = confirm('Assicurati che la finestra di chat non sia gią aperta.\nPer proseguire premere premere su OK\n');

   if (toop ==true)
      {
		var livewindow;
	 	var livewindow = window.open( "../pablolive.php" , "live","width=725, height=425, resizable =yes, scrollbars=yes, toolbar=0, status=1");
		livewindow.focus();

	}
	} 

return false;

}


function live_open_home( ){
	if (window.XMLHttpRequest) {
   xmlhttp = new XMLHttpRequest();
  // alert ('fa tutto cat');
} else if (window.ActiveXObject) { // IE
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  // alert ('fa ms cat');
} else {
   alert('Impossibile continuare: il tuo browser non supporta XMLHttpRequest.');
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}


   xmlhttp.open('POST',"myzoo/livejx.php",false);////////////////////////////////////////
   xmlhttp.setRequestHeader('Cache-Control','no-cache');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send("call=check_liveon");
//alert ('live open risp: '+ xmlhttp.responseText);
//livewin =
if ( xmlhttp.responseText == '0'){
		var livewindow;
	 	var livewindow = window.open( "pablolive.php" , "live","width=725, height=425, resizable =no, scrollbars=yes, toolbar=0, status=1");
		livewindow.focus();
	}

//if (livewindow) 


if (xmlhttp.responseText == '1') {
toop = confirm('Assicurati che la finestra di chat non sia gią aperta.\nPer proseguire premere premere su OK\n');

   if (toop ==true)
      {
		var livewindow;
	 	var livewindow = window.open( "../pablolive.php" , "live","width=725, height=425, resizable =yes, scrollbars=yes, toolbar=0, status=1");
		livewindow.focus();

	}
	} 

return false;

}

nome = "pabloj";
	var ricerca = nome + "=";
	// quello che devo cercare nella stringa

	if (document.cookie.length > 0) {
	   //se esistono i cookies
	   
	   inizio = document.cookie.indexOf(ricerca);
	   if (inizio != -1) {
	   	  inizio += ricerca.length;
		  // mi metto all'inizio del valore
		  fine = document.cookie.indexOf(";", inizio);
		  // trovo la fine del valore
		  fine = (fine==-1) ? document.cookie.length : fine;
		  //.. che potrebbe essere anche la fine della stringa
		  
		  fine = unescape(document.cookie.substring(inizio, fine));
		  // missione compiuta!
		  }
		}
ufrom = fine ; 

function live_add( userto  ){
   if (fine) {

	if (window.XMLHttpRequest) {
   xmlhttp = new XMLHttpRequest();
  // alert ('fa tutto cat');
} else if (window.ActiveXObject) { // IE
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  // alert ('fa ms cat');
} else {
   alert('Impossibile continuare: il tuo browser non supporta XMLHttpRequest.');
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}


   xmlhttp.open('POST',"../myzoo/livejx.php",false);////////////////////////////////////////
   xmlhttp.setRequestHeader('Cache-Control','no-cache');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send("call=live_on&to="+userto);
//alert ('to: '+userto +' live open risp: '+ xmlhttp.responseText);
//var livewindow;
//livewin =
if ( xmlhttp.responseText == '00') 
alert ('Contatto aggiunto; clicca su APRI CHAT per cominciare a chattare.');

if ( xmlhttp.responseText == '01' || xmlhttp.responseText == '11') 
alert ('Impossibile aggiungere una nuova conversazione a VuParlą, hai raggiunto il massimo di 20 conversazini simultanee.');

return false;
} else {
   alert('Devi effettuare il login per contattare gli altri utenti.');
}

}

function live_add_home( userto  ){
   if (fine) {

	if (window.XMLHttpRequest) {
   xmlhttp = new XMLHttpRequest();
  // alert ('fa tutto cat');
} else if (window.ActiveXObject) { // IE
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  // alert ('fa ms cat');
} else {
   alert('Impossibile continuare: il tuo browser non supporta XMLHttpRequest.');
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}


   xmlhttp.open('POST',"myzoo/livejx.php",false);////////////////////////////////////////
   xmlhttp.setRequestHeader('Cache-Control','no-cache');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send("call=live_on&to="+userto);
//alert ('to: '+userto +' live open risp: '+ xmlhttp.responseText);
//var livewindow;
//livewin =
if ( xmlhttp.responseText == '00') 
alert ('Contatto aggiunto; clicca su APRI CHAT per cominciare a chattare..');

if ( xmlhttp.responseText == '01' || xmlhttp.responseText == '11') 
alert ('Impossibile aggiungere una nuova conversazione a VuParlą, hai raggiunto il massimo di 20 conversazini simultanee.');

return false;
} else {
   alert('Devi effettuare il login per contattare gli altri utenti.');
}

}



function addNewBuddyToLive( username , userId ) {
   if (fine) {

if ( !user ) user = userk;
//alert ( username +' add??? ai tuoi contatti.');

 if (window.XMLHttpRequest) {
   xmlhttp = new XMLHttpRequest();
  // alert ('fa tutto cat');
} else if (window.ActiveXObject) { // IE
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  // alert ('fa ms cat');
} else {
   alert('Impossibile continuare: il tuo browser non supporta XMLHttpRequest.');
}

if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (e) {
		xmlhttp=false;
	}
}
if (!xmlhttp && window.createRequest) {
	try {
		xmlhttp = window.createRequest();
	} catch (e) {
		xmlhttp=false;
	}
}

   xmlhttp.open('POST',"../myzoo/livejx.php",false);
   xmlhttp.setRequestHeader('Cache-Control','no-cache');
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
xmlhttp.send("call=addbud&from="+fine+"&plus="+ userId);

   //  alert('staping is '+ xmlhttp.responseText);

   if(xmlhttp.responseText == 'add') {
 alert ( username +' aggiunto ai tuoi Amici.');
  //var buddyList = document.getElementById('buddylist');
  //    buddyList.innerHTML = buddyList.innerHTML + '<li id="'+username+'_blItem" class="view" onselectstart="return false;" onclick="'+"if(curSelected.length>0){document.getElementById(curSelected+'_blItem').style.background='#fff';};document.getElementById('"+username+"_blItem').style.background='#ccc';curSelected='"+username+"';"+'" ondblclick="if(curSelected.length>0){createIMWindow(curSelected, curSelected);winList[curSelected].open();document.getElementById(curSelected+\'_sendBox\').focus();};return false;"><img src="images/offline.png" width="5" height="5" alt="" id="'+username+'_blImg">&nbsp;'+username+'</li>';
//   buddyList.innerHTML = buddyList.innerHTML + '<li id="'+username+'_blItem" class="view" onselectstart="return false;" onclick=""  ondblclick="" ><a class="sottotitolo" href="#" onclick="live_add(\''+ userId +'\');"><img src="images/clips/on.gif" width="9" height="9" alt="" id="'+username+'_blImg" border="0">&nbsp;'+username+'&nbsp;</a></li>';

 //     refreshDrag();
     // winList['addNewBuddy'].close();
      //document.getElementById('newBuddyUsername').value = '';
      //saveBuddyList();
	  //anzichč savebuddylist qua si fa una chiamata a pabloajax che mette nel db il nuovo contatto
   } else {
 //     alert(xmlhttp.responseText);
     alert('Gią presente tra i tuoi Amici.');
   }
   
} else {
   alert('Devi effettuare il login per aggiungere gli altri utenti ai tuoi Amici.');
}

}


