<!-- 
// **********************************************************************************************
//
// file			: ajax.js
// Author		: Giovambattista Fazioli (e-lementi.com)
// Web			: http://e-lementi.com
// E-mail		: info (at) e-lementi (dot) (com)
// Created		: 09/08/2006 9.49
// Modified		: 20/11/2006 11.49
//
// Copyright (C) 2002-2006 e-lementi
//
// DESCRIPTION
//	Contiene tutte le funzioni e oggetti relativi alle funzioni dell'oggetto XMLHttpRequest
//
// **********************************************************************************************

// Costruisce una stringa in formato PHP. Permette di trasformare dei parametri javascript
// in un array PHP.
// inputs:
//	a		- un array in formato javascript, normalmente arguments
//	f	- indice da cui considerare i parametri
// result:
//	Stringa in formato PHP: "array(a,b,c, ..., n);"
// examples:
//	function miaFunzione( par1, par2 ) {
//		var myString = $_P( arguments, 2 );
// 	}
function $_P ( a, f ) {
	var r = "";
	for(var i = f; i < a.length; i++) {
		r += (r == "")?"":"|*|";
		r += escape(a[i]);
	}
	return( r );
}
// Classe per la gestione Ajax
function _scoHttpRequest() {
	this.__release = "1.4";
	this._url = "gospel.php";
	// init after creating
	this.xmlHttp = (window.XMLHttpRequest)?new XMLHttpRequest():( (window.ActiveXObject)?new ActiveXObject("Microsoft.XMLHTTP"):-1 );
	//
	this.handleResponse = function() {	
		// start wait
		if(this.readyState == 4) {
			// ok...
			$G("cscoIdle").style.display = $G("cscoIdleImg").style.display = "none";
			document.body.style.cursor = "default";
			//
			var response = this.responseText;
			var xmldoc = this.responseXML;
			var root = xmldoc.getElementsByTagName('applickResponse').item(0);
			var tag;
			var id;
			var v;
			var n;
			for(var inode = 0; inode < root.childNodes.length; inode++) {
				n	= root.childNodes.item(inode);
				tag	= n.tagName;
				id	= n.attributes[0].value
				v	= unescape(n.firstChild.nodeValue);
				//alert( "TAG: "+tag+"\nID: "+id+"\nVALUE: "+v );
				//
				switch(tag) {
					case "innerHTML":
						$G( id ).style.display = "";
						$G( id ).innerHTML = v;
						break;
					case "javascript":
						var e = id+'(\''+escape(v)+'\');';
						eval(e);
						break;
					case "alert":
						alert( v );
						break;	
					default:
						alert("XML WARINING!!\n\nTAG:"+tag+"\nID:"+id+"\nVALUE:"+v);
						break;		
				}
			}
		} else { // in waiting...
			$G("cscoIdle").style.display = $G("cscoIdleImg").style.display = "";
			document.body.style.cursor = "wait";
		}
	}

	// Invia un "comando" alla pagina gospel.php tramite il canale ajax. L'invio è verso l'applick
	this.send = function( cmd ) {
		var a = arguments;
		if( typeof( cmd ) != "string" ) { a = arguments[0]; cmd = arguments[0][0]; }
		var pars = 'appCommand=' + cmd + ( (a.length > 1)?"&appParams="+$_P( a, 1 ):"" );
		this.xmlHttp.open('post', this._url );
		this.xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.xmlHttp.onreadystatechange = this.handleResponse.bind(this.xmlHttp);
		this.xmlHttp.send(pars);		
	}
	
}
// Questa è la versione short-quick di scoExecute() per il Kernel. Questa funzione invia un
// messaggio al Kernel
function scoKExecute( cmd ) {
	$F("skiFormCommand").skiCommand.value = cmd;
	$F("skiFormCommand").skiParams.value = (arguments.length > 1)?$_P( arguments, 1 ):"";
	$F("skiFormCommand").submit();
}
// to do
function scoLoad() {
	$F("skiFormCommand").skiCommand.value = "loadApplick";
	$F("skiFormCommand").skiParams.value = (arguments.length > 0)?$_P( arguments, 0 ):"";
	$F("skiFormCommand").submit();
}
// Questa è la versione short-quick di scoExecute() per la Applicazioni. Questa funzione invia un
// messaggio all'applicazione
function scoAExecute( cmd ) {
	$F("skiFormCommand").appCommand.value = cmd;
	$F("skiFormCommand").appParams.value = (arguments.length > 1)?$_P( arguments, 1 ):"";
	$F("skiFormCommand").submit();
}

//-->