function xmlhttpPost(strURL,formname,responsediv,responsemsg,errormsg)
{
    var xmlHttpReq = false;
    var self = this;
    try
    {
    	self.xmlHttpReq = new XMLHttpRequest();
    }
    catch (e)
    {
    	try
    	{
    		self.xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
    	}
    	catch(e)
    	{
	    	try
	    	{
	    		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	    	}
	    	catch(e)
	    	{
	    		alert("Il tuo browser non supporta la tecnologia AJAX!");
	    	}
	    }
    }
    
    self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
        	if(self.xmlHttpReq.status == 200)
        	{
            	//hideLoader();
            	updatepage(self.xmlHttpReq.responseText,responsediv);
            	alert("Il tuo browser non supporta la tecnologia AJAX!");
            }
            else
            {
            	//hideLoader();
            	updatepage(errormsg,responsediv);
            }
        }
		else
		{
			showLoader();
			//updatepage(responsemsg,responsediv);
		}
    }
    
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'multipart/form-data');
    self.xmlHttpReq.send(getquerystring(formname));
}

function xmlhttpGET(strURL,responsediv,errormsg,Loader)
{
    var xmlHttpReq = false;
    var self = this;
    try
    {
    	self.xmlHttpReq = new XMLHttpRequest();
    }
    catch (e)
    {
    	try
    	{
    		self.xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
    	}
    	catch(e)
    	{
	    	try
	    	{
	    		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	    	}
	    	catch(e)
	    	{
	    		alert("Il tuo browser non supporta la tecnologia AJAX!");
	    	}
	    }
    }
	
	self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
        	if(self.xmlHttpReq.status == 200)
        	{
            	updatepage(self.xmlHttpReq.responseText,responsediv);
				hideLoader(Loader);
            }
            else
            {
            	updatepage(errormsg,responsediv);
				hideLoader(Loader);
            }
        }
		else
		{
			showLoader(Loader);
		}
    }
    
    self.xmlHttpReq.open('GET', strURL + '&t=' + Math.random(), true);
    self.xmlHttpReq.send();
}

function xmlhttpGETEsteso(strURL,responsediv,errormsg,Loader)
{
    var xmlHttpReq = false;
    var self = this;
    try
    {
    	self.xmlHttpReq = new XMLHttpRequest();
    }
    catch (e)
    {
    	try
    	{
    		self.xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
    	}
    	catch(e)
    	{
	    	try
	    	{
	    		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	    	}
	    	catch(e)
	    	{
	    		alert("Il tuo browser non supporta la tecnologia AJAX!");
	    	}
	    }
    }
	
	self.xmlHttpReq.onreadystatechange = function()
    {
        if (self.xmlHttpReq.readyState == 4)
        {
        	if(self.xmlHttpReq.status == 200)
        	{
            	updatepage(self.xmlHttpReq.responseText,responsediv);
				hideLoaderEsteso(Loader,responsediv);
            }
            else
            {
            	updatepage(errormsg,responsediv);
				hideLoaderEsteso(Loader,responsediv);
            }
        }
		else
		{
			showLoaderEsteso(Loader,responsediv);
		}
    }
    
    self.xmlHttpReq.open('GET', strURL + '&t=' + Math.random(), true);
    self.xmlHttpReq.send();
}

function getquerystring(formname) {
    var form = document.forms[formname];
	var qstr = "";

    function GetElemValue(name, value) {
        qstr += (qstr.length > 0 ? "&" : "")
            + escape(name).replace(/\+/g, "%2B") + "="
            + escape(value ? value : "").replace(/\+/g, "%2B");
			//+ escape(value ? value : "").replace(/\n/g, "%0D");
    }

	var elemArray = form.elements;
    for (var i = 0; i < elemArray.length; i++) {
        var element = elemArray[i];
        var elemType = element.type.toUpperCase();
        var elemName = element.name;
        if (elemName) {
            if (elemType == "TEXT" || elemType == "TEXTAREA" || elemType == "PASSWORD" || elemType == "BUTTON" || elemType == "RESET" || elemType == "SUBMIT" || elemType == "FILE" || elemType == "IMAGE" || elemType == "HIDDEN")
                GetElemValue(elemName, element.value);
            else if (elemType == "CHECKBOX" && element.checked)
                GetElemValue(elemName, element.value ? element.value : "On");
			else if (elemType == "RADIO" && element.checked)
                GetElemValue(elemName, element.value);
            else if (elemType.indexOf("SELECT") != -1)
                for (var j = 0; j < element.options.length; j++) {
                    var option = element.options[j];
                    if (option.selected)
                        GetElemValue(elemName, option.value ? option.value : option.text);
                }
        }
    }
    return qstr;
}

function updatepage(str,responsediv){
    document.getElementById(responsediv).innerHTML = str;
}
