var agt = navigator.userAgent.toLowerCase();
var is_ie5 = (agt.indexOf('msie 5') != -1);

function CreateXmlHttpReq(handler)
{
  var xmlhttp = null;
  try
  {
	xmlhttp = new XMLHttpRequest();
	try
	{ xmlhttp.overrideMimeType('text/xml'); }
	catch(e)
	{ xmlhttp.onreadystatechange = handler; }
    
	xmlhttp.onload = handler;
    xmlhttp.onerror = handler;
  }
  catch(e)
  {
	var control = (is_ie5) ? 'Microsoft.XMLHTTP' : 'Msxml2.XMLHTTP';
	xmlhttp = new ActiveXObject(control);
	xmlhttp.onreadystatechange = handler;
  }
  
  return xmlhttp;
}

function AXGetData(url, handler)
{
 var a = new Array('placeholder');
 var objxmlhttp;
 
 for (var j=2; j<arguments.length; j++)
 {
	a[a.length] = arguments[j];
	if(document.getElementById(arguments[j]))
	{
		if(document.getElementById(arguments[j]).nodeName.toLowerCase() == 'div')
		{
			if(arguments[3] == null || arguments[3] == '')
			{
				img = 'loading'; vspace = 30;
			}
			else
			{
				img = arguments[3];
				vspace = 0;
			}
			
			document.getElementById(arguments[j]).innerHTML = '<center><IMG src="/images/'+ img +'.gif" border=0 vspace='+ vspace +'></center>';
		}
	}
 }

 var myhandler = function() {
	var content = AXRequestOk(objxmlhttp);
	if (content != false)
	{
		a[0] = content;
		try
		{ return handler.apply(this, a); }			
		catch(e)
		{ return myDummyApply(handler, a); }
	}
 }
 
 url += (url.indexOf("?") == -1) ? '?' : '&';
 qstring = url.substring(url.indexOf("?")+1 , url.length);
 url = url.substring(0, url.indexOf("?")) +'?rand='+ escape(Math.random());	
  
 objxmlhttp = CreateXmlHttpReq(myhandler);
 objxmlhttp.open("POST", url, true);
 objxmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
 objxmlhttp.send(qstring); 
}

function myDummyApply(funcname, args)
{
 var e = "funcname(";
 for (var i = 0; i < args.length; i++)
 {
	e += "args["+i+"]";
	if (i+1 != args.length)
		e += ",";
 }

 e += ");"
 return eval(e);
}

function AXRequestOk(objxmlhttp)
{
 if (objxmlhttp.readyState == 4 && objxmlhttp.status == 200)
	return objxmlhttp.responseText;    
 else
	return false;
  
}
function AXObjForm(text, nameform, objform, initelementselect){
	if(document.forms[nameform].elements[objform].type.indexOf('select') > -1){
		arrSelect = text.split("||");
		arrValue = arrSelect[0].split("|");
		arrText = arrSelect[1].split("|");
		arrSel = arrSelect[2].split("|");
		objform = document.forms[nameform].elements[objform];
		objformlen = objform.options.length;
		for(j=initelementselect; j<objformlen; j++)
			objform.options[0] = null;
		objformlen = objform.options.length;
		for(j=0; j<objformlen; j++)
			objform.options[0] = null;
		for(i=0; i<arrValue.length; i++){
			objform.options[objform.options.length] = new Option(arrText[i], arrValue[i]);        
			if(arrSel[i]=='selected')
				objform.options[i].selected = true;
		}
	}else if(objform.type == 'text'){
		objform.value = text;
	}else if(objform.type == 'checkbox'){
		objform.checked = text;
	}  
}
function AXResponse(text)
{	
 for(j=1; j<arguments.length; j++)
 {
	if(document.getElementById(arguments[j]))
 		document.getElementById(arguments[j]).innerHTML = text;
	else
		alert('Dati non reindirizzati correttamente.')
 }
}

function AXCheckLogin(text)
{	
 if(text == 'accesslogin')
	location.href = 'b2b.asp';
 else
 	document.getElementById(arguments[1]).innerHTML = text;

}
