// used to find the Automation server name
function getDomDocumentPrefix() {
if (getDomDocumentPrefix.prefix)
return getDomDocumentPrefix.prefix;
var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
var o;
for (var i = 0; i < prefixes.length; i++) {
try {
// try to create the objects
o = new ActiveXObject(prefixes[i] + ".DomDocument");
return getDomDocumentPrefix.prefix = prefixes[i];
}
catch (ex) {};
}
throw new Error("Could not find an installed XML parser");
}

function getXmlHttpPrefix() {
if (getXmlHttpPrefix.prefix)
return getXmlHttpPrefix.prefix;
var prefixes = ["MSXML2", "Microsoft", "MSXML", "MSXML3"];
var o;
for (var i = 0; i < prefixes.length; i++) {
try {
// try to create the objects
o = new ActiveXObject(prefixes[i] + ".XmlHttp");
return getXmlHttpPrefix.prefix = prefixes[i];
}
catch (ex) {};
}
throw new Error("Could not find an installed XML parser");
}

//////////////////////////
// Start the Real stuff //
//////////////////////////


// XmlHttp factory
function XmlHttp() {}

XmlHttp.create = function () {
	try {
		if (window.XMLHttpRequest) {
			var req = new XMLHttpRequest();
			
			// some versions of Moz do not support the readyState property
			// and the onreadystate event so we patch it!
			if (req.readyState == null) {
				req.readyState = 1;
				req.addEventListener("load", function () {
					req.readyState = 4;
					if (typeof req.onreadystatechange == "function")
						req.onreadystatechange();
				}, false);
			}
			
			return req;
		}
		if (window.ActiveXObject) {
			return new ActiveXObject(getXmlHttpPrefix() + ".XmlHttp");
	}	
	}
	catch (ex) {}
	// fell through
	throw new Error("Your browser does not support XmlHttp objects");
};

// XmlDocument factory
function XmlDocument() {}

XmlDocument.create = function () {
	try {
		// DOM2
if (document.implementation && document.implementation.createDocument) {
	var doc = document.implementation.createDocument("", "", null);
	
	// some versions of Moz do not support the readyState property
	// and the onreadystate event so we patch it!
	if (doc.readyState == null) {
		doc.readyState = 1;
		doc.addEventListener("load", function () {
		doc.readyState = 4;
if (typeof doc.onreadystatechange == "function")
		doc.onreadystatechange();
		}, false);
	}
			
	return doc;
}
		if (window.ActiveXObject)
			return new ActiveXObject(getDomDocumentPrefix() + ".DomDocument");
	}
	catch (ex) {}
	throw new Error("Your browser does not support XmlDocument objects");
};

// Create the loadXML method and xml getter for Mozilla
if (window.DOMParser &&
	window.XMLSerializer &&
	window.Node && Node.prototype2 && Node.prototype2.__defineGetter__) {

	// XMLDocument did not extend the Document interface in some versions
	// of Mozilla. Extend both!
	XMLDocument.prototype2.loadXML = 
	Document.prototype2.loadXML = function (s) {
		
		// parse the string to a new doc	
		var doc2 = (new DOMParser()).parseFromString(s, "text/xml");
		
		// remove all initial children
		while (this.hasChildNodes())
			this.removeChild(this.lastChild);
			
		// insert and import nodes
		for (var i = 0; i < doc2.childNodes.length; i++) {
			this.appendChild(this.importNode(doc2.childNodes[i], true));
		}
	};
	
	
	/*
	 * xml getter
	 *
	 * This serializes the DOM tree to an XML String
	 *
	 * Usage: var sXml = oNode.xml
	 *
	 */
	// XMLDocument did not extend the Document interface in some versions
	// of Mozilla. Extend both!
	XMLDocument.prototype2.__defineGetter__("xml", function () {
		return (new XMLSerializer()).serializeToString(this);
	});
	Document.prototype2.__defineGetter__("xml", function () {
		return (new XMLSerializer()).serializeToString(this);
	});
}

//--------------------------------------------------------------------------
var	ie = document.all?true:false;
var	ie6strict = (document.documentElement && document.documentElement.clientHeight)?true:false;

function onLoading (b) {
//	var load_div = document.getElementById("loadinfo");
//	var load_img = document.getElementById("ajaxloading");
if(b)
{
// progressOn();
/*		if(load_div)
		{
			y=0;
			if (self.innerWidth) // all except Explorer
				y = self.innerHeight;
			else if (document.documentElement && document.documentElement.clientHeight)// Explorer 6 Strict Mode
				y = document.documentElement.clientHeight;
			else if (document.body) // other Explorers
				y = document.body.clientHeight;
			
			if (self.pageYOffset) // all except Explorer
				tp = window.pageYOffset
			else if (ie6strict)// Explorer 6 Strict Mode
				tp = document.documentElement.scrollTop
			else if (document.body)//MOZILLA anche
				tp = document.body.scrollTop
			
			pad=parseInt((y-100)/2)//100=height immagine di loading
			//h=parseInt(y)-pad;
			
			if(ie)//perchè non vuole px mentre mozilla si	
			{
				//load_div.style.height=h;
				load_div.style.paddingTop=pad;
				load_div.style.top=tp;
				load_img.style.paddingTop=pad;
				load_img.style.top=tp;
			}
			else
			{
				//MOZILLA vuole anche px ie no
				load_div.style.paddingTop=pad+"px";
				load_div.style.top=tp+"px"; 
				load_img.style.paddingTop=pad+"px";
				load_img.style.top=tp+"px";
			}
		}
		
		if(ie)
			load_div.style.filter='alpha(opacity=30)'
		else
			load_div.style.MozOpacity=0.3//non va su firefox
*/		
}
else
{
//progressOff();
/*		if(ie)
			load_div.style.filter='alpha(opacity=100)'
		else
			load_div.style.MozOpacity=1//non va su firefox
*/	
}
		
  //  load_div.style.display = b ? "block" : "none";
//	load_img.style.display = b ? "block" : "none";
}


/*---------------------------------------------------------------------------------------*/
var modello = document.getElementById('idcat_modello');
var risultati = document.getElementById('risultati');
var credito = document.getElementById('credito');
var slogan = document.getElementById('slogan');
var risposta = document.getElementById('FormContatti');

function _startLoad(sSrc,obj,idrub) {
	
	if(modello)
	{
		modello.innerHTML='<select class="field" style="width:150px;" name="idcat"><option value="0">LOADING...</option></select>';	
		idcat = obj.value
		sSrc = sSrc+"?idcat="+idcat+"&idrub="+idrub;
		var xmlHttp = XmlHttp.create();
		timer_onloading=window.setTimeout("onLoading(true)","500");
		xmlHttp.open("GET", sSrc, true);	// async
		xmlHttp.onreadystatechange = function () {
			if (xmlHttp.readyState == 4) {
				_modelloLoaded(xmlHttp.responseText);
				window.clearTimeout(timer_onloading)
				onLoading(false);
			}
		};
		// call in new thread to allow ui to update
		window.setTimeout(function () {
			xmlHttp.send(null);
		}, 10);
	}
}

function _startLoadrate(sSrc,doc) {

        if(modello)
	        {
    modello.innerHTML='CALCOLANDO...';
   importo = doc.getElementById('importi').value;
   rate=doc.getElementById('rate').value;
   sSrc = sSrc+"?importo="+importo+"&rate="+rate;
   var xmlHttp = XmlHttp.create();
   timer_onloading=window.setTimeout("onLoading(true)","500");
   xmlHttp.open("GET", sSrc, true);        // async
   xmlHttp.onreadystatechange = function () {
          if (xmlHttp.readyState == 4) {
                      _modelloLoaded(xmlHttp.responseText);
                      window.clearTimeout(timer_onloading)
                       onLoading(false);
                     }
    };
 // call in new thread to allow ui to update
  window.setTimeout(function () {
  xmlHttp.send(null);
 }, 10);
 }
}

function _start2Load(sSrc,obj) {
if(risultati)  {
risultati.innerHTML='';
risultati.setAttribute("class", "loading");
catmer=obj.catmer.value;
pagina=obj.pagina.value;
titolo=obj.titolo.value;
conten=obj.conten.value;
//alert(annoto+annofrom+marca+cilindrata+prezzofrom+prezzoto);
sSrc = sSrc+"?catmer="+catmer+"&pagina="+pagina+"&titolo="+titolo+"&conten="+conten;
    var xmlHttp = XmlHttp.create();
    timer_onloading=window.setTimeout("onLoading(true)","500");
    xmlHttp.open("GET", sSrc, true); // async
            xmlHttp.onreadystatechange = function () {
            if (xmlHttp.readyState == 4) {
            _risultatiLoaded(xmlHttp.responseText);
	    window.clearTimeout(timer_onloading)
            onLoading(false);
         }
       };
       // call in new thread to allow ui to update
       window.setTimeout(function () {
       xmlHttp.send(null);
       }, 10);
      }
}

function _start2Loadlocation(sSrc,obj) {
if(locationselect) {
locationselect.innerHTML='';
//risultati.setAttribute("class", "loading");
catmer=obj.value;
alert(catmer);
//pagina=obj.pagina.value;
//titolo=obj.titolo.value;
//conten=obj.conten.value;
//alert(annoto+annofrom+marca+cilindrata+prezzofrom+prezzoto);
sSrc = sSrc+"?catmer="+catmer;
 var xmlHttp = XmlHttp.create();
   timer_onloading=window.setTimeout("onLoading(true)","500");
   xmlHttp.open("GET", sSrc, true); // async
       xmlHttp.onreadystatechange = function () {
       if (xmlHttp.readyState == 4) {
       _locationLoaded(xmlHttp.responseText);
       window.clearTimeout(timer_onloading)
       onLoading(false);
      }
      };
      // call in new thread to allow ui to update
      window.setTimeout(function () {
      xmlHttp.send(null);
      }, 10);
  }
}


function _start2Load_tabs(sSrc,obj,tabs) {
catmer=obj.catmer.value;
pagina=obj.pagina.value;
titolo=obj.titolo.value;
conten=obj.conten.value;
tipologia=obj.tipologia.value;
misure=obj.misure.value;

if(risultati) {
risultati.innerHTML='';
risultati.setAttribute("class", "loading");
sSrc = sSrc+"?catmer="+catmer+"&pagina="+pagina+"&titolo="+titolo+"&conten="+conten+"&tipologia="+tipologia+"&misure="+misure;
var xmlHttp = XmlHttp.create();
timer_onloading=window.setTimeout("onLoading(true)","500");
xmlHttp.open("GET", sSrc, true); // async
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
_risultatiLoaded_tabs(xmlHttp.responseText,tabs);
window.clearTimeout(timer_onloading)
onLoading(false);
}
};



// call in new thread to allow ui to update
window.setTimeout(function () {
xmlHttp.send(null);
}, 10);
}
}

function inviaForm() {
par = document.getElementById('parametri').value;
if (par!='cf') {
nome = document.getElementById('nome_Req').value;
corpo = document.getElementById('corpo').value;
cognome = document.getElementById('cognome_Req').value;
email = document.getElementById('email_Req_Email').value;
testo = document.getElementById('testo').value;
//par = document.getElementById('parametri').value;
soggetto = document.getElementById('soggetto').value;
tel = document.getElementById('tel').value;
//cc = document.getElementById('cc').value;
var params= "parametri="+par+"&email=" + email + "&testo=" + testo +"&nome="+nome+"&cognome="+cognome+"&corpo="+corpo+"&soggetto="+soggetto+"&tel="+tel; 
sSrc = "/inviaForm.php";
} else {
cf = document.getElementById('cf_Req').value;
var params= "cf="+cf;
sSrc = "/inviaLogin.php";




}
if(risposta) {
//risposta.innerHTML='';
risposta.innerHTML='INVIO IN CORSO ...';
risposta.setAttribute("class", "loading");
//risposta.setAttribute("class", "loading");
var xmlHttp = XmlHttp.create();
timer_onloading=window.setTimeout("onLoading(true)","500");
xmlHttp.open("POST", sSrc, true); // asynci
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
_rispostaLoaded(xmlHttp.responseText);
window.clearTimeout(timer_onloading)
onLoading(false);
}
};
// call in new thread to allow ui to update
window.setTimeout(function () {
xmlHttp.send(params);
}, 10);
}

}


function inviaLogin() {
cf = document.getElementById('cf_Req').value;
//cc = document.getElementById('cc').value;

var params= "cf="+cf;
if(risposta) {
//risposta.innerHTML='';
risposta.innerHTML='LOGIN IN CORSO ...';
risposta.setAttribute("class", "loading");
//risposta.setAttribute("class", "loading");
sSrc = "/inviaLogin.php";
var xmlHttp = XmlHttp.create();
timer_onloading=window.setTimeout("onLoading(true)","500");
xmlHttp.open("POST", sSrc, true); // asynci
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {_rispostaLoaded(xmlHttp.responseText);
window.clearTimeout(timer_onloading)
onLoading(false);
}
};
// call in new thread to allow ui to update
window.setTimeout(function () {
xmlHttp.send(params);
}, 10);
}
}

/*
function inviaForm2() {
nome = document.getElementById('nome_Req').value;
corpo = document.getElementById('corpo').value;
cognome = document.getElementById('cognome_Req').value;
email = document.getElementById('email_Req_Email').value;
testo = document.getElementById('testo').value;
par = document.getElementById('parametri').value;
//cc = document.getElementById('cc').value;

var params= "parametri="+par+"&email=" + email + "&testo=" + testo +"&nome="+nome+"&cognome="+cognome+"&corpo="+corpo;
if(risposta) {
//risposta.innerHTML='';
risposta.innerHTML='INVIO IN CORSO ...';
risposta.setAttribute("class", "loading");
//risposta.setAttribute("class", "loading");
sSrc = "/inviaForm2.php";
var xmlHttp = XmlHttp.create();
timer_onloading=window.setTimeout("onLoading(true)","500");
xmlHttp.open("POST", sSrc, true); // asynci
xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
_rispostaLoaded(xmlHttp.responseText);
window.clearTimeout(timer_onloading)
onLoading(false);
}
};
// call in new thread to allow ui to update
window.setTimeout(function () {
xmlHttp.send(params);
}, 10);
}
}
*/
function _start2Loadhref_tabs(order,ascdesc,sSrc,catmer,pagina,tabs) {
if(risultati)  {
risultati.innerHTML='';
risultati.setAttribute("class", "loading");
sSrc = sSrc+"?catmer="+catmer+"&pagina="+pagina+"&order="+order+"&ascdesc="+ascdesc;
var xmlHttp = XmlHttp.create();
timer_onloading=window.setTimeout("onLoading(true)","500");
xmlHttp.open("GET", sSrc, true); // async
xmlHttp.onreadystatechange = function () {
if (xmlHttp.readyState == 4) {
_risultatiLoaded_tabs(xmlHttp.responseText,tabs);
window.clearTimeout(timer_onloading)
onLoading(false);
}
};

// call in new thread to allow ui to update
window.setTimeout(function () {
xmlHttp.send(null);
}, 10);
}
}


function _start2Loadhref(order,ascdesc,sSrc,catmer,pagina) {
if(risultati)  {
risultati.innerHTML='';
risultati.setAttribute("class", "loading");
sSrc = sSrc+"?catmer="+catmer+"&pagina="+pagina+"&order="+order+"&ascdesc="+ascdesc;
var xmlHttp = XmlHttp.create();
timer_onloading=window.setTimeout("onLoading(true)","500");
 xmlHttp.open("GET", sSrc, true); // async
 xmlHttp.onreadystatechange = function () {
 if (xmlHttp.readyState == 4) {
   _risultatiLoaded(xmlHttp.responseText);
   window.clearTimeout(timer_onloading)
   onLoading(false);
 }
};
  // call in new thread to allow ui to update
  window.setTimeout(function () {
  xmlHttp.send(null);
  }, 10);
 }
}


function _modelloLoaded(oXmlDoc) 
{
 //alert(oXmlDoc)
 if(modello)
 modello.innerHTML = oXmlDoc;
}
function _creditoLoaded(oXmlDoc)
{
//alert(oXmlDoc)
if(credito){
credito.innerHTML = oXmlDoc;
}
}
function _risultatiLoaded(oXmlDoc)
{
if(risultati) {
	risultati.setAttribute("class", "");;
        risultati.innerHTML = oXmlDoc;
}
}

function _locationLoaded(oXmlDoc)
{
if(locationselect) {
//   locationselect.setAttribute("class", "");;
locationselect.innerHTML = oXmlDoc;
}
}



function _sloganLoaded(oXmlDoc)
{
if(slogan) {
slogan.setAttribute("class", "");;
slogan.innerHTML = oXmlDoc;
}
}


function _risultatiLoaded_tabs(oXmlDoc,tabs)
{
if(risultati) {
risultati.setAttribute("class", "");
risultati.innerHTML = oXmlDoc;
 //ActivateTabs('tabs');
var MyTabs= new mt('tabs','div.my_tab');
MyTabs.removeTabTitles('h5.tab_title');
//MyTabs.addTab('t1','tabi\' diofa 1');
//MyTabs.addTab('t2','tab 2');
//MyTabs.addTab('t3','tab 3');
//MyTabs.addTab('t4','tab 4');
//MyTabs.addTab('t5','tab 5');
//MyTabs.makeActive('t1');

for (i=0; i<tabs.length; i++) {
//inizio blocco di istruzioni
MyTabs.addTab('t'+(i+1),tabs[i]);
}

}
}



function _risultati2Loaded(oXmlDoc)
{
  if(risultati2) {
     risultati2.setAttribute("class", "");
     risultati2.innerHTML = oXmlDoc;
}
}
function _rispostaLoaded(oXmlDoc)
{
  if(risposta) {
       risposta.setAttribute("class", "");
            risposta.innerHTML = oXmlDoc;
	}
}

function _news(pagina) {
// menu = document.getElementById('active_menu').setAttribute("class", "nonactive");
if(risultati)  {
risultati.innerHTML='';
risultati.setAttribute("class", "loading");
//alert(annoto+annofrom+marca+cilindrata+prezzofrom+prezzoto);
sSrc = "news_ajax?n="+pagina;
var xmlHttp = XmlHttp.create();
timer_onloading=window.setTimeout("onLoading(true)","500");
xmlHttp.open("GET", sSrc, true); // async
xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4) {
      _risultatiLoaded(xmlHttp.responseText);
          window.clearTimeout(timer_onloading)
           onLoading(false);
           }
      };
  // call in new thread to allow ui to update
  window.setTimeout(function () {
  xmlHttp.send(null);
  }, 10);
  }
}

function _cat(pagina) {
// menu = document.getElementById('active_menu').setAttribute("class", "nonactive");
if(risultati)  {
slogan.innerHTML='';
slogan.setAttribute("class", "loading");
risultati.innerHTML='';
risultati.setAttribute("class", "loading");
//alert(annoto+annofrom+marca+cilindrata+prezzofrom+prezzoto);
sSrc = "cont_ajax?n="+pagina;
sSrc2 = "cont_ajax_slogan?n="+pagina;

var xmlHttp = XmlHttp.create();
var xmlHttp2 = XmlHttp.create();

timer_onloading=window.setTimeout("onLoading(true)","500");
xmlHttp.open("GET", sSrc, true); // async
xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4) {
         _risultatiLoaded(xmlHttp.responseText);
	 window.clearTimeout(timer_onloading)
onLoading(false);
}
};
xmlHttp2.open("GET", sSrc2, true); // async
xmlHttp2.onreadystatechange = function () {
    if (xmlHttp2.readyState == 4) {
             _sloganLoaded(xmlHttp2.responseText);
	              window.clearTimeout(timer_onloading)
		      onLoading(false);
		      }
		      };


// call in new thread to allow ui to update
window.setTimeout(function () {
xmlHttp.send(null);
xmlHttp2.send(null);

}, 10);
}


}


function _reseller(pagina) {
// menu = document.getElementById('active_menu').setAttribute("class", "nonactive");
if(risultati)  {
risultati.innerHTML='';
risultati.setAttribute("class", "loading");
//alert(annoto+annofrom+marca+cilindrata+prezzofrom+prezzoto);
sSrc = "reseller_ajax?regione="+pagina;
var xmlHttp = XmlHttp.create();
timer_onloading=window.setTimeout("onLoading(true)","500");
xmlHttp.open("GET", sSrc, true); // async
xmlHttp.onreadystatechange = function () {
    if (xmlHttp.readyState == 4) {
             _risultatiLoaded(xmlHttp.responseText);
	              window.clearTimeout(timer_onloading)
		      onLoading(false);
		      }
		      };

// call in new thread to allow ui to update
window.setTimeout(function () {
xmlHttp.send(null);
}, 10);
}
}



