//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='block';
	return true;
}

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

function visual_evidenza(aa){
	if(aa=='video_evidenza'){
		visual_n('gallery_evidenza');
		visual_y('video_evidenza');
		btnvideo=getObject('bottone_video_evidenza');
		btnvideo.className="bottoneattivo";
		btnfoto=getObject('bottone_gallery_evidenza');
		btnfoto.className="bottone";
    }
	if(aa=='gallery_evidenza'){
		visual_n('video_evidenza');
		visual_y('gallery_evidenza');
		btnvideo=getObject('bottone_video_evidenza');
		btnvideo.className ="bottone";
		btnfoto=getObject('bottone_gallery_evidenza');
		btnfoto.className ="bottoneattivo";
    }
}

function visual_areamedia(aa){
	if(aa=='video_areamedia'){
		visual_n('gallery_areamedia');
		visual_y('video_areamedia');

		btnvideo=getObject('a_btnvideo');
		btnvideo.style.backgroundImage="url(http://www.arredamento.it/img/btn_video_on.gif)";
		btnfoto=getObject('a_btnfoto');
		btnfoto.style.backgroundImage="url(http://www.arredamento.it/img/btn_foto_off.gif)";
    }
	if(aa=='gallery_areamedia'){
		visual_n('video_areamedia');
		visual_y('gallery_areamedia');

		btnvideo=getObject('a_btnvideo');
		btnvideo.style.backgroundImage='url(http://www.arredamento.it/img/btn_video_off.gif)';
		btnfoto=getObject('a_btnfoto');
		btnfoto.style.backgroundImage='url(http://www.arredamento.it/img/btn_foto_on.gif)';
    }
}


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;

}

/*
funzione che assegna id del marchio nell'input hidden nel form ricerca negozi
*/    
function assegna_id(val_id){
  document.frm2.id_mark.value=val_id;
}

function window_open(theurl,w_width,w_height){
  window.open(theurl, '', 'width='+w_width+',height='+w_height+',left=0,top=0,resizable=yes,menubar=no,toolbar=no, scrollbars=yes,locations=no,status=no');
}

/*************************************************/
function xmlhttpPost(strURL, Theform, Thecontrol) {
	var xmlHttpReq = false;
	var self=this;
	//xmlhttprequest x mozilla/ie7
	if (window.XMLHttpRequest){
	  self.xmlHttpReq= new XMLHttpRequest();
	}
	//xmlhttprequest x ie6
	else if (window.ActiveXObject){
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	self.xmlHttpReq.open('POST',strURL,true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function() {
		if (self.xmlHttpReq.readyState==4){
	    	updatepage(self.xmlHttpReq.responseText,Theform,Thecontrol);
		}
	}
	self.xmlHttpReq.send(getquerystring(Theform));
}


  function getquerystring(Theform) {
    var form = document.forms[Theform];
    formNb = document.forms.length;
    qstr='';
    
  	if (formNb < 1) { 
  		alert ("La pagina non contiene form !");
  		return;
  	}else if (formNb > 1 && !Theform) {
  			alert ("La pagina contiene pił di 1 form. Dare un nome alla form");
  			return;
  		}else {
  			formPath = formNb ? document.forms[Theform] : document.forms[0];
  			with (formPath) {
  				for (i=0; i<formPath.length; i++) {			
  					 qstr += elements[i].name + "=" + escape(elements[i].value) + "&";
  				}
  			}
  		}
  	qstr += "end=1";
    return qstr;  
  }
  
  function updatepage(str,Theform,Thecontrol) {
  	var msg='';
  	var test;
    var form = document.forms[Theform];
    test=str.split("|");
    if (test[0]=='ok') {
      form.reset();
    }

		for(i=1;i<test.length;i++)
		{
     msg+= test[i].split("|")+'<br />';
    }      

    document.getElementById(Thecontrol).innerHTML=msg; //div dove mostrare il risultato    
  	
  }

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

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;
  }
}

/**/


/***********************************************
* Bookmark site script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
function bookmarksite(title,url){
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print){ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}


/***********************************************
 *  GEOCOD DI GOOGLE MAPS
 ***********************************************/
    

    var map;
    var geocoder;


    function initialize(indirizzo) {
      geocoder = new GClientGeocoder();

      map = new GMap2(document.getElementById("map_canvas"));
      map.addControl(new GLargeMapControl());
      map.addControl(new GMapTypeControl());
      geocoder.getLocations(indirizzo, addAddressToMap);

    }

    // addAddressToMap() is called when the geocoder returns an
    // answer.  It adds a marker to the map with an open info window
    // showing the nicely formatted version of the address and the country code.
    function addAddressToMap(response) {

      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Sorry, we were unable to geocode that address");
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);

	     map.setCenter(point, 16);
        marker = new GMarker(point);
        map.addOverlay(marker);
//        marker.openInfoWindowHtml(place.address + '<br>' +
//          '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
      }

    }

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);
	}
}
