//------------------------- operazioni ripetute per live assist
function sendmymsg(){
 var msg=document.getElementById('mymsg').value;
 ajax_post('liveassist/aj_chatwrite','ajax_loader','mymsg#'+msg,0);
 document.getElementById('mymsg').value="";
}
//---------------------------
function checkopen(){
 var winclosed=document.getElementById('winclosed').value;
	if(winclosed==1)
		{
		ajax_post('liveassist/aj_checkopen','liveass_checkopen','',0);
    	var ihtm=document.getElementById('liveass_checkopen').innerHTML;
	    if(ihtm==1){
	    //alert('apre'+ihtm)
		openassist();
		ajax_post('liveassist/aj_chatread','chatinside','',0);
		//scrolla();
		document.getElementById('liveass_checkopen').innerHTML="";
				   }
		}
}
function scrolla(){
var x=document.getElementById('chatinside');
if(x!= null){
 	var winclosed=document.getElementById('winclosed').value;
 	if(winclosed==0){
 	document.getElementById('chatinside').scrollTop = 10000;
 					}
	}
}
function liveassist(conta){
var conta=conta+1;	
if(conta>=3)
	{
	conta=0;
	}
var winclosed=document.getElementById('winclosed').value;
	if(winclosed==0)
		{
		ajax_post('liveassist/aj_chatread','chatinside','',0);
		scrolla();
		}
		else
		{
		if(conta==0){checkopen();}
		}

setTimeout("liveassist("+conta+")", 2000);
}
function closeassist(){
ajax_post('liveassist/aj_onoff','ajax_loader','stato#0',0);
document.getElementById('winclosed').value=1;
}
function openassist(){
ajax_post('liveassist/aj_onoff','ajax_loader','stato#1',0);
openmypage(); 
document.getElementById('winclosed').value=0;
return false;
}
function openmypage(){ //Define arbitrary function to run desired DHTML Window widget codes
livewin=dhtmlwindow.open("ajaxbox", "ajax", "liveassist/user_interface.php", "PALLET.COM Live Assistant", "width=450px,height=250px,left=300px,top=100px,resize=0,scrolling=1")
centerpage();
livewin.onclose=function()
	{ 
 	var retu=window.confirm("Close Live Assist?")
	if(retu==true){closeassist();}
	return retu;
 	} //Run custom code when window is about to be closed
}
function centerpage(){
livewin.moveTo('middle', 'middle'); 
return false;
}

