/**********************************************************************
	SD_GENERALE
	v. 1.0
	03/08/2011
	Alessandro Costoli - SoftDesign
**********************************************************************/


/***********************************************************************************************************************************
	OGGETTI / ARRAY
***********************************************************************************************************************************/

// oggetto di verifica stato
var readyState = {
	INATTIVO:	0,
	INIZIALIZZATO:	1,
	RICHIESTA:	2,
	RISPOSTA:	3,
	COMPLETATO:	4
};

// array descrittivo dei codici restituiti dal server
// [la scelta dell' array è per evitare problemi con vecchi browsers]
var statusText = new Array();
statusText[0] = "OK";
statusText[100] = "Continue";
statusText[101] = "Switching Protocols";
statusText[200] = "OK";
statusText[201] = "Created";
statusText[202] = "Accepted";
statusText[203] = "Non-Authoritative Information";
statusText[204] = "No Content";
statusText[205] = "Reset Content";
statusText[206] = "Partial Content";
statusText[300] = "Multiple Choices";
statusText[301] = "Moved Permanently";
statusText[302] = "Found";
statusText[303] = "See Other";
statusText[304] = "Not Modified";
statusText[305] = "Use Proxy";
statusText[306] = "(unused, but reserved)";
statusText[307] = "Temporary Redirect";
statusText[400] = "Bad Request";
statusText[401] = "Unauthorized";
statusText[402] = "Payment Required";
statusText[403] = "Forbidden";
statusText[404] = "Not Found";
statusText[405] = "Method Not Allowed";
statusText[406] = "Not Acceptable";
statusText[407] = "Proxy Authentication Required";
statusText[408] = "Request Timeout";
statusText[409] = "Conflict";
statusText[410] = "Gone";
statusText[411] = "Length Required";
statusText[412] = "Precondition Failed";
statusText[413] = "Request Entity Too Large";
statusText[414] = "Request-URI Too Long";
statusText[415] = "Unsupported Media Type";
statusText[416] = "Requested Range Not Satisfiable";
statusText[417] = "Expectation Failed";
statusText[500] = "Internal Server Error";
statusText[501] = "Not Implemented";
statusText[502] = "Bad Gateway";
statusText[503] = "Service Unavailable";
statusText[504] = "Gateway Timeout";
statusText[505] = "HTTP Version Not Supported";
statusText[509] = "Bandwidth Limit Exceeded";


/***********************************************************************************************************************************
	IsIE
	Scopo: definisce se il browser in uso è Internet Explorer
	Ritorna:	0	non è IE
				1	è IE
***********************************************************************************************************************************/
function IsIE ()
{
	var isMSIE;
	
	isMSIE = /*@cc_on!@*/0;
	if (isMSIE) {
		return 1;
	}
	else {
		return 0;
	}
}


/***********************************************************************************************************************************
	AnnoCorrente
	Scopo: stabilisce l'anno corrente
	Ritorna: anno corrente
***********************************************************************************************************************************/
function AnnoCorrente()
{
	var anno;
	
	anno=new Date();
	if (IsIE()) {
		return anno.getYear();
	}
	else {
		return (anno.getYear()+1900);
	}
}


/***********************************************************************************************************************************
	HTMLEncode
	Scopo: convertire i caratteri speciali di una stringa nel formato HTML
	Ritorna: stringa convertita
***********************************************************************************************************************************/
function HTMLEncode(str)
{

	var s;
	
	s=str;
	s.replace(/&/g, "&amp;");
	s.replace(/</g, "&lt;");
	s.replace(/>/g, "&gt;");
	s.replace(/&/g, "&amp;");
	s.replace(/"/g, "&quot;");
	s.replace(/à/g, "&agrave;");
	s.replace(/À/g, "&Agrave;");
	s.replace(/â/g, "&acirc;");
	s.replace(/Â/g, "&Acirc;");
	s.replace(/ä/g, "&auml;");
	s.replace(/Ä/g, "&Auml;");
	s.replace(/å/g, "&aring;");
	s.replace(/Å/g, "&Aring;");
	s.replace(/æ/g, "&aelig;");
	s.replace(/Æ/g, "&AElig;");
	s.replace(/ç/g, "&ccedil;");
	s.replace(/Ç/g, "&Ccedil;");
	s.replace(/é/g, "&eacute;");
	s.replace(/É/g, "&Eacute;");
	s.replace(/è/g, "&egrave;");
	s.replace(/È/g, "&Egrave;");
	s.replace(/ê/g, "&ecirc;");
	s.replace(/Ê/g, "&Ecirc;");
	s.replace(/ë/g, "&euml;");
	s.replace(/Ë/g, "&Euml;");
	s.replace(/ï/g, "&iuml;");
	s.replace(/Ï/g, "&Iuml;");
	s.replace(/ô/g, "&ocirc;");
	s.replace(/Ô/g, "&Ocirc;");
	s.replace(/ö/g, "&ouml;");
	s.replace(/Ö/g, "&Ouml;");
	s.replace(/ø/g, "&oslash;");
	s.replace(/Ø/g, "&Oslash;");
	s.replace(/ß/g, "&szlig;");
	s.replace(/ù/g, "&ugrave;");
	s.replace(/Ù/g, "&Ugrave;");
	s.replace(/û/g, "&ucirc;");
	s.replace(/Û/g, "&Ucirc;");
	s.replace(/ü/g, "&uuml;");
	s.replace(/Ü/g, "&Uuml;");
	s.replace(/®/g, "&reg;");
	s.replace(/©/g, "&copy;");
	s.replace(/€/g, "&euro;");
	
	return s;
}


/***********************************************************************************************************************************
	getXMLHttpRequest
	
	Scopo: stabilisce una connessione HTTP per l'apertura di un file.
	Ritorna: 
***********************************************************************************************************************************/
function getXMLHttpRequest()
{
	// variabile di ritorno, nulla di default
	var XHR = null;
 	
	// informazioni sul nome del browser
	var browserUtente = navigator.userAgent.toUpperCase();
	
	// IE
	if (window.ActiveXObject) {
	
		// la versione 6 di IE ha un nome differente per il tipo di oggetto ActiveX
		if (browserUtente.indexOf("MSIE 5") < 0)
			XHR = new ActiveXObject("Msxml2.XMLHTTP");
		
		// le versioni 5 e 5.5 invece sfruttano lo stesso nome
		else 
			XHR = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	// browser standard con supporto nativo non importa il tipo di browser
	else {
		if((typeof(XMLHttpRequest) == "function") || (typeof(XMLHttpRequest) == "object"))
  			XHR = new XMLHttpRequest();
	}
	
	return XHR;
}


/***********************************************************************************************************************************
	IsLocationHTTP
	Scopo: definisce se il sito è su web o in locale
	Ritorna:	0	è in locale
				1	è su web
***********************************************************************************************************************************/
function IsLocationHTTP()
{
	var location;
	
	location=String(window.location);
	location=location.toLowerCase().substring(0, 4);
	
	if (location=="http")
		return 1;
	else
		return 0;
	
}


/***********************************************************************************************************************************
	IsWebHTTP
	Scopo: definisce se l'HTTP è sul web o in locale
	Ritorna:	0	è locale
				1	è su web
***********************************************************************************************************************************/
function IsWebHTTP()
{
	var location;
	
	location=String(window.location);
	location=location.toLowerCase().substring(7, 10);
	
	if (location=="www")
		return 1;
	else
		return 0;
	
}


/***********************************************************************************************************************************
	IsDate
	Scopo: definisce se la stringa passata è in formato data
	Ritorna:	0	non è una data
				1	è una data
***********************************************************************************************************************************/
function IsDate (x) 
{ 
  return (null != x) && !isNaN(x) && ("undefined" !== typeof x.getDate); 
}

