//GLOBALS
var w3c = (document.getElementById) ? 1:0
var ns4 = (document.layers) ? 1:0  //browser detect for NS4 & W3C standards

function getObject(sObj) {
	if (w3c)
		theObj = document.getElementById(sObj);
	else if (ns4)
		theObj = eval("document." + sObj);
	return theObj;
}

/*
function visual(aa) {
if (document.getElementById){
	if(document.getElementById(aa).style.display=='none'){
		document.getElementById(aa).style.display='';
	}else{
		document.getElementById(aa).style.display='none';
	}
}
}
*/

function visual(aa){
	obj=getObject(aa);
	if (obj){
		if(obj.style.display=='none'){
			obj.style.display='';
		}else{
			obj.style.display='none';
		}
	}
}

function visual_y(aa){
	obj=getObject(aa);
	obj.style.display='inline';
	return true;
}

function visual_n(aa){
	obj=getObject(aa);
	obj.style.display='none';
	return true;
}


function visual_evidenza(aa){
	if(aa=='box_dx_1'){
		visual_n('box_dx_consigli');
		visual_n('box_dx_top10');
		visual_y('box_dx_testati');
		btn1=getObject('boxdxbtn1');
		btn2=getObject('boxdxbtn2');
		btn3=getObject('boxdxbtn3');
		btn1.className="btn_u";
		btn2.className="btn_d";
		btn3.className="btn_d";
    }
	if(aa=='box_dx_2'){
		visual_n('box_dx_consigli');
		visual_n('box_dx_testati');
		visual_y('box_dx_top10');
		btn1=getObject('boxdxbtn1');
		btn2=getObject('boxdxbtn2');
		btn3=getObject('boxdxbtn3');
		btn1.className="btn_d";
		btn2.className="btn_u";
		btn3.className="btn_d";
    }
	if(aa=='box_dx_3'){
		visual_n('box_dx_testati');
		visual_n('box_dx_top10');
		visual_y('box_dx_consigli');
		btn1=getObject('boxdxbtn1');
		btn2=getObject('boxdxbtn2');
		btn3=getObject('boxdxbtn3');
		btn1.className="btn_d";
		btn2.className="btn_d";
		btn3.className="btn_u";
    }
}

function motorericerca()
  {
  var tro=document.motore.f_cerca;
  if(tro.value=="")
    {
    alert('Devi inserire un testo per la ricerca');
    tro.focus();
    return (false);
    }
  else
    {
    return(true);
    }
  }

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

function gb_inner(aaa,bbb){

	obj=getObject(aaa);
	obj.innerHTML = bbb;

}

function SetAllCheckBoxes(FormName, FieldName, CheckValue){
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}


/*************************************************/


function xmlhttpGet(strURL,funct) {
// per l'oggetto nativo XMLHttpRequest
 randomVal = Math.random()*1000000;
	if (window.XMLHttpRequest) {
		ricerca_pro = new XMLHttpRequest();
    if (funct) eval("ricerca_pro.onreadystatechange= function () { " + funct + " }");
		strURL = strURL + "&randomVal=" + randomVal;
    ricerca_pro.open("GET", strURL , true);
		ricerca_pro.send(null);
		// per IE
		} else if (window.ActiveXObject) {
			ricerca_pro = new ActiveXObject("Microsoft.XMLHTTP");
			if (ricerca_pro) {
			if (funct) eval("ricerca_pro.onreadystatechange= function () { " + funct + " }");
			strURL = strURL + "&randomVal=" + randomVal;
      		ricerca_pro.open("GET", strURL , true);
			ricerca_pro.send();
		}
	}
}

function ricevi() {
var strRes;
var arrValori;
/*
riceve una stringa in formato: testo#id|testo#id|
per popolare una select
*/
	if (ricerca_pro.readyState == 4) {
		strRes=ricerca_pro.responseText;
		arrValori=strRes.split("|");
		document.frmc.catid.options.length=0;
			for(i=0;i<arrValori.length;i++)
			{
				text = arrValori[i].split("|");
				text = text.toString();
				var str1=text;
				var str2=text;
				pos = str1.indexOf("#");
				text = str1.substring(pos,-str1.length);
				pos = str2.indexOf("#");
				val = str2.substring(pos+1,str2.length);
				document.frmc.catid.options[document.frmc.catid.options.length]= new Option(text,val);
			}
	}else{
	//	alert("Problemi con la ricerca!\r\nState:"+ ricerca_pro.readyState + " Status:" + ricerca_pro.status + " "+ ricerca_pro.statusText+"\r\n");
	}
}

function test(Thecontrol){
	if (ricerca_pro.readyState == 4) {
	  strRes=ricerca_pro.responseText;
	  document.getElementById(Thecontrol).innerHTML=strRes;
	}
}

function cambia_img(Thecontrol){
	if (ricerca_pro.readyState == 4) {
	  strRes=ricerca_pro.responseText;
	  gb_inner(Thecontrol,strRes);
	}
}

/*
//funzioni coookies
function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)
                 + ";expires="+expire.toGMTString();
}

function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return "";
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length;
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

*/
