var IDIntervalBusy;
var IDIntervalStatus;
var PayPalCustom="";
var PayPalCustomCon="";

var CounselingLogin = function (IDForm,target)
		{
			
		document.getElementById("CouLoginError").style.display="none";		
		document.getElementById("CouLoginAlert").style.display="block";
		document.getElementById("CouLoginNoMeeting").style.display="none";
		document.getElementById("CouLoginFldError").style.display="none";
		document.getElementById("CouButtonRequest").style.display="none";
		
		var SendData = new DataAjax;
		SendData.callback = function (res) {
	
			var a=WPL_JSON.decode(res); 
			if (a.success==false) 
				{
				
				
				document.getElementById("CouLoginAlert").style.display="none";
				document.getElementById("CouButtonRequest").style.display="block";

				if (a.notoken==1)document.getElementById("CouLoginError").style.display="block";
				if (a.fielderror==1)document.getElementById("CouLoginFldError").style.display="block";

				if (a.nomeeting==1)	document.getElementById("CouLoginNoMeeting").style.display="block";
				if (a.roomfull==1)	document.getElementById("CouLoginRoomFull").style.display="block";
				//IDIntervalStatus = setInterval(coucheckstatus,5000);	
				
				}
			else //Succedd true
				{
				document.getElementById("courequest").style.display="none";
				document.getElementById("courequestbusy").style.display="block";
				//clearInterval(IDIntervalStatus);	
				IDIntervalBusy=setInterval(courequestbusy,5000);
				//if (target=="new") window.open(a.joinlink,"Counseling");
				//	else location.href=a.joinlink;
				
				}
		}
		SendData.PostForm(IDForm,"FLE=GAR&PROC=COU_Login");
		}	

var courequestbusy = function ()
{
		var SendData = new DataAjax;
		SendData.callback = function (res) {
	
			var a=WPL_JSON.decode(res); 
			if (a.success==false) 
				{
					if (a.status==3) 
						{
							clearInterval(IDIntervalBusy);
							document.getElementById("courequestappointment").style.display="block";
							document.getElementById("courequestbusy").style.display="none";
						}
				}
			else //Succedd true
				{
				location.href=a.joinlink;
				
				}
		}
		SendData.LoadData("PROC=COU_OpenRoomViewer");
	}
	
var coucheckstatus = function ()
{
		var SendData = new DataAjax;
		SendData.callback = function (res) {
	
			var a=WPL_JSON.decode(res); 
			if (a.success==false) 
				{
					
				}
			else //Succedd true
				{
				document.getElementById("counselorstatusbox").style.display = "block";
				document.getElementById("counselorstatuscdw").style.display = "none";
				if (a.status==1) 
					{
						document.getElementById("coustatusclass").className="statusavailable";
						document.getElementById("couenterroom").style.display="block";
						document.getElementById("counselorstatus").innerHTML = "ON LINE (libero)";
					}
				if (a.status==2) 
					{
						document.getElementById("coustatusclass").className="statusbusy";
						document.getElementById("couenterroom").style.display="block";
						document.getElementById("counselorstatus").innerHTML = "ON LINE (occupato)";
					}
				if (a.status==3) 
					{
						document.getElementById("coustatusclass").className="statusoffline";
						document.getElementById("couenterroom").style.display="none";
						document.getElementById("counselorstatus").innerHTML = "OFF LINE";
					}
				
				}
		}
		SendData.LoadData("PROC=COU_CounselorOnLine&ccd="+ccd);
	}	

var paypalnext = function()
{
	if (document.getElementById("emailbuyer").value=="") return;
	var tt= document.getElementById("coutokentype").value;
	if (tt=="VCHAT") document.getElementById("tokenamount").value = amountvchat;
	if (tt=="PEMAIL") document.getElementById("tokenamount").value = amountpemail;
	if (PayPalCustom=="") PayPalCustom=document.getElementById("paypalcustom").value;
	document.getElementById("paypalcustom").value=PayPalCustom+"&emailbuyer="+document.getElementById("emailbuyer").value+"&tt="+tt;
	document.getElementById("paypalbuttonnext").style.display="none";
	document.getElementById("divemailbuyer").style.display="none";
	document.getElementById("paypalbuttonpay").style.display="block";
	
	}
	
var paypalnextcon = function()
{
	if (PayPalCustom=="") PayPalCustom=document.getElementById("paypalcustomcon").value;
	document.getElementById("paypalcustomcon").value=PayPalCustomCon+"&emailbuyer="+document.getElementById("emailbuyercon").value;
	document.getElementById("paypalbuttonnextcon").style.display="none";
	document.getElementById("divemailbuyercon").style.display="none";
	document.getElementById("paypalbuttonpaycon").style.display="block";
	
	}	

var CouAppRequest = function (IDForm)
	{
		var SendData = new DataAjax;
		SendData.callback = function (res) {
	
			var a=WPL_JSON.decode(res); 
			if (a.success==false) 
				{
				
				
				
				}
			else //Succedd true
				{
				alert("Richiesta Inviata");
				}
		}
		SendData.PostForm(IDForm,"FLE=GAR&PROC=COU_AppRequest");
		}
		
var CouAdviceRequest = function (IDForm)
	{
		var SendData = new DataAjax;
		SendData.callback = function (res) {
	
			var a=WPL_JSON.decode(res); 
			if (a.success==false) 
				{
				
				
				
				}
			else //Succedd true
				{
				alert("Richiesta Inviata");
				}
		}
		SendData.PostForm(IDForm,"FLE=GAR&PROC=COU_AdviceRequest");
		}		
		
var CouAdviceEmailRequest = function (IDForm)
	{
		var SendData = new DataAjax;
		SendData.callback = function (res) {
	
			var a=WPL_JSON.decode(res); 
			if (a.success==false) 
				{
				
				if (a.notoken) if (a.notoken==1) alert("Token Errato");
				if (a.fielderror) if (a.fielderror==1) alert("Compilare tutti i campi.");
				
				}
			else //Succedd true
				{
				alert("Richiesta Inviata");
				}
		}
		SendData.PostForm(IDForm,"FLE=GAR&PROC=COU_AdviceEmailRequest");
		}			
		
var CouOpenBox = function (IDBox)
	{
		document.getElementById("coubuytokenbox").style.display = "none";
		if (document.getElementById("coubuytokenconbox")) document.getElementById("coubuytokenconbox").style.display = "none";
		document.getElementById("couenterroombox").style.display = "none";
		document.getElementById("couappointmentbox").style.display = "none";
		if (document.getElementById("couappointmentanwbox")) document.getElementById("couappointmentanwbox").style.display = "none";
		document.getElementById(IDBox).style.display = "block";
	}


IDIntervalStatus = setInterval(coucheckstatus,5000);	


