/*

Aziendecom v1

� Comservices s.r.l.

info: www.comservices.it

------------------------

script page: js/Vetrina.js

started: 12-12-2008

last-modified: 24-12-2008 (Catrini)
*/


/************************** CLASSE PER GESTIRE LA VETRINA *******************************/


Vetrina = Class.create();
var map,datiSalvati=1;
Vetrina.prototype={
    id:null,
    url:null,
    indirizzo:null,
    azienda:null,
    image:null,   
    
    initialize:function(ID,URL)
    {
        this.id=ID;
        this.url=URL;
        this.indirizzo;
        try{
            /*$$("li.servizi_li").each(function(s){
                
               s.firstChild.observe("mouseover",function(j){
                   
                   s.firstChild.style.color="white";
               });
               s.firstChild.observe("mouseout",function(j){
                alert(s.getStyle("background"));
                if(("rgb(80, 145, 173)").indexOf(s.getStyle("bgColor"))<0)
                   s.firstChild.style.color="#5091AD";
               });
            });*/
            this.azienda=$("ragione_sociale").getValue();
            handler=this.modifica;
            handler1=this.inviaModifica;
            handler2=this.checkKey;
            handler4=this.modificat;
            if($("bottoni_mod")!=null)
                $$("textarea.right","textarea.left","input.right","input.left").each(function(s,handler){
                    
                    
                    if(s.id!="email")
                    {
                        s.observe("click",this.handler4.bindAsEventListener(this,s));
                        s.observe("focus",this.handler.bindAsEventListener(this,s));
                        s.observe("mouseover",function(event){
                                   
                            $$("textarea.right","textarea.left","input.right","input.left").each(function(e,handler){
                                if(e.getStyle("background-color")!="white")
                                {
                                    e.style.background="#F5F5F5";
                                    e.style.color="black";
                                }
                            });
                                
                            event.target.style.background="rgb(80,145,173)";
                            event.target.style.color="white";
                        });
                        s.observe("mouseout",function(event){
                                  
                            $$("textarea.right","textarea.left","input.right","input.left").each(function(e,handler){
                                if(e.getStyle("background-color")!="white")
                                {
                                    e.style.background="#F5F5F5";
                                    e.style.color="black";
                                }
                            });
                        });
                        s.observe("change",this.handler1.bindAsEventListener(this,s));
                        s.observe("keyup",this.handler2.bindAsEventListener(this,s));
                    /*s.observe("mouseover",function(event){
                            event.currentTarget.style.border="1px solid";
                        });*/
                    }

                });
        }catch(err){}
    },
    checkKey:function(event,s)
    {
        
        if(event.keyCode==13)
        {
            var invio=true;
            var errore="ATTENZIONE!!!\n";
            if(!isFinite($F("tel"))|| $F("tel")=="")
            {
                errore+="Il telefono può contenere solo caratteri numerici\n";
                $("tel").style.background="red";
                invio=false;
            }
            if(!isFinite($F("fax")))
            {
                errore+="Il fax può contenere solo caratteri numerici\n";
                $("fax").style.background="red";
                invio=false;
            }
            if(!isFinite($F("cap")) || $F("cap")=="")
            {
                errore+="Il CAP può contenere solo caratteri numerici\n";
                $("cap").style.background="red";
                invio=false;
            }
            if($F("indirizzo")=="")
            {
                errore+="Il campo INDIRIZZO non può essere vuoto\n";
                $("indirizzo").style.background="red";
                invio=false;
            }
            if($F("comune")=="")
            {
                errore+="Il campo COMUNE non può essere vuoto\n";
                $("comune").style.background="red";
                invio=false;
            }
            if(!invio)
                alert(errore);
            else
            {
                $("indirizzo").value=$F("indirizzo").replace("\n","");
                //alert($("form_modifica").serialize());
                var options={
                    method : "POST",
                    parameters:$("form_modifica").serialize(),
                    onSuccess:function(transport){
                        var risp=transport.responseText;

                        $$("textarea.right","textarea.left","input.right","input.left").each(function(e){
                            e.style.background="white";
                            e.style.color="black";
                        });
                        $("bottoni_mod").hide();
                        $("mod").update("Clicca su un campo e modifica i tuoi dati");
                        $("mod").style.background="rgb(80,145,173)";
                        $("mod").style.color="white";
                        datiSalvati=1;
                        if(risp!="")
                        {
                            $("www").href="http://"+risp;
                            $("www").show();
                        }
                        else
                            $("www").hide();

                    },
                    onFailure:function(transport){
                        var risp=transport.responseText;


                    }
                };
                new Ajax.Request(baseurl+"/vetrina/modifica",options);
                //$("mod").update("<img src="+baseurl+"/include/images/indicatore.gif />");
                
                $("mod").update("Salvataggio in corso ...<img src="+baseurl+"/include/images/indicatore.gif />");
                $("mod").style.background="yellow";
                $("mod").style.color="red";
            }
        }
        else if($("bottoni_mod")!=null)
            $("bottoni_mod").show();
    },

    modifica:function(event,s)
    {
        if($("bottoni_mod")!=null)
            $("bottoni_mod").show();
        datiSalvati=0;
        $$("textarea.right","textarea.left","input.right","input.left").each(function(e,handler){
       
            if(e.getStyle("background-color")=="white")
            {
                e.style.background="#F5F5F5";
                e.style.color="black";
            }
        });
        
       
  
       
        s.style.background="#F5F5F5";
        s.style.color="black";
    },
     modificat:function(event,s)
    {
        if($("bottoni_mod")!=null)
            $("bottoni_mod").show();
        datiSalvati=0;
        $$("textarea.right","textarea.left","input.right","input.left").each(function(e,handler){

            if(e.getStyle("background-color")=="white")
            {
                e.style.background="#F5F5F5";
                e.style.color="black";
            }
        });


     

        s.style.background="white";
       
        s.style.color="black";
    },

    inviaModifica:function()
    {
        
        
    //if((event.keyCode)==13 || (event.keyCode)==9)

            var invio=true;
            var errore="ATTENZIONE!!!\n";
      
            if(!isFinite($F("tel")) || $F("tel")=="")
            { 
                if($F("tel")=="")
                 errore+="Il telefono non può essere vuoto\n";
                else
                errore+="Il telefono può contenere solo caratteri numerici\n";
                $("tel").style.background="red";
                invio=false;
            }
            if(!isFinite($F("fax")))
            {
                errore+="Il fax può contenere solo caratteri numerici\n";
                $("fax").style.background="red";
                invio=false;
            }
            if(!isFinite($F("cap")) || $F("cap")=="")
            {
                errore+="Il CAP può contenere solo caratteri numerici\n";
                $("cap").style.background="red";
                invio=false;
            }
            if($F("indirizzo")=="")
            {
                errore+="Il campo INDIRIZZO non può essere vuoto\n";
                $("indirizzo").style.background="red";
                invio=false;
            }
              if(!isFinite($F("cel")))
            {
                errore+="Il campo cellulare può contenere solo caratteri numerici\n";
                $("cel").style.background="red";
                invio=false;
            }
            if($F("comune")=="")
            {
                errore+="Il campo COMUNE non può essere vuoto\n";
                $("comune").style.background="red";
                invio=false;
            }
     
            if(!invio)
                alert(errore);
            else
            {
                //alert($("form_modifica").serialize());
                var options={
                    method : "POST",
                    parameters:$("form_modific").serialize(),
                    onSuccess:function(transport){
                        var risp=transport.responseText;
             
                        datiSalvati=1;
                      
          
                        $('mod').hide();
                        window.location.href=baseurl+'/vetrina';

                    },
                    
                    onFailure:function(transport){
                        var risp=transport.responseText;
                         

                    },
                       onCreate:function(transport){
                       
                                $("mod").update("Salvataggio in corso ...<img src="+baseurl+"/include/images/indicatore.gif />");
          
                $("mod").style.color="#EF9A14";

                    }

                    
                };
                new Ajax.Request(baseurl+"/vetrina/modifica",options);
                //$("mod").update(""<img src="+baseurl+"/include/images/indicatore.gif />"");
         
      
        }
    },
    setId:function(ID)
    {
      this.id=ID;
    },
    inviaMessaggio:function(guest)
    {
       
        if(!$F("oggetto"))
            $("err_oggetto").update("Il campo OGGETTO non può essere vuoto");
        else
            $("err_oggetto").update();
        ok=0;
        if($F("oggetto"))
            ok=1

        if(guest==1)
        {
            ok=0;
        
            if(!$F("referente"))
                $("err_referente").update("Il campo REFERENTE non può essere vuoto");
            else
                $("err_referente").update();

                 
            if(!$F("emailc"))
                $("err_emailc").update("Il campo EMAIL non può essere vuoto");
            else
                $("err_emailc").update();


            if($F("referente") && $F("emailc")&& $F("oggetto"))
            {
                ok=1;
          
            }

        }
        //alert(guest);
        if(ok==1)
        {
            //alert("s");
            
            $("messaggio_posta").submit();
        }
            
               
          
    },
    mappa:function(event,indirizzo,comune)
    {
       
        if(indirizzo==null && comune==null)
        { 
            indirizzo=$F("indirizz");
            indirizzo=indirizzo.replace("/","");
            indirizzo=indirizzo.replace("'\'","");
            indirizzo=indirizzo.replace("-","");
            $("indir").value=indirizzo;
            indirizzo=$("indir").serialize();
            if($("comun").tagName=="INPUT")            
                co=$("comun").serialize();
            else
                co="comune="+encode($("comun").innerHTML);

            
      
        }
        else
        {
            indirizzo=indirizzo.replace("/","");
            indirizzo=indirizzo.replace("'\'","");
            indirizzo=indirizzo.replace("-","");
            $("i1").value=indirizzo;
            $("c1").value=comune;
            indirizzo=$("i1").serialize();          
            co=$("c1").serialize();
            
        }

        
        $("map").update("<div class='box bo' style='float:left;width:100%;'>  <div class='corner-top-left2' style='width:7px;float:left;height:7px;'></div>     <div style='width:586px;background:white;float:left;height:7px;' class='border-top'></div>\n\
        <div class='corner-top-right2' style='width:7px;float:left;height:7px;'></div> \n\
<div class='iner' style='padding:0;min-height:205px;float:left;background:white;width:100%;'>\n\
        <div id='chiud' style='width:97%;text-align:right;float:left;padding-top:10px;'><img id='x' style='cursor:pointer;' src="+baseurl+"/include/images/c_drop.png onclick='vetrina.scompari2()' alt='chiudi' /></div>\n\
<iframe frameborder=0 style='width:600px;height:400px;padding-bottom:10px;'src="+baseurl+"/vetrina/gmap/indirizzo/"+indirizzo+"/comune/"+co+"></frame></div>\n\
<div class='corner-bot-left2' style='width:7px;float:left;height:7px;'></div>\n\
        <div class='border-bot' style='width:586px;float:left;height:7px;background:white;'></div>\n\
        <div class='corner-bot-right2' style='width:7px;float:left;height:7px;'></div>\n\
</div>");
      
        $("maschera").show();
        
        $("ap").show();
    /*$('ap').appear({
            duration: 0.5
        });*/
     
    },
    
    scompari:function(){
        //RESETTO LE DIMENSIONI DEL POPUP
        $("map").style.height="403px";
        $("map").style.width="600px";
        $("ap").style.height="420px";
        $("ap").style.width="600px";
        $('ap').hide();
        $("maschera").hide();
     
    },
       scompari2:function(){
        //RESETTO LE DIMENSIONI DEL POPUP
       
        $('ap').hide();
        $("maschera").hide();

    },
    showcontent_2:function(parametri,sezione)
    {
        if(sezione=="paginaprodotto")
        {
            $("content_c").style.overflow="hidden";
            $("content_c").style.height="auto";
        }
        if(sezione=="formda")
            $("des_dati").hide();
        
        var options={
            method : "POST",
            parameters:parametri,
            onSuccess:function(transport){
                var risp=transport.responseText;
                $("content_c").update(risp);
              
                     
                     
            },
            
            onFailure:function(transport){
                var risp=transport.responseText;
                
            }
        };
        new Ajax.Request(this.url+"/vetrina/"+sezione+"/id/"+this.id,options);
        $("content_c").update("<img src="+this.url+"/include/images/indicator_medium.gif />");
    },    
    nuovoLogo:function()
    {
        $('ap').style.visibility = 'visible';
        $('maschera').style.visibility = 'visible';
        $("maschera").show();
        $("map").update("<div class='box bo' style='float:left;width:100%;'>  <div class='corner-top-left2' style='width:7px;float:left;height:7px;'></div>     <div style='width:586px;background:white;float:left;height:7px;' class='border-top'></div>\n\
        <div class='corner-top-right2' style='width:7px;float:left;height:7px;'></div> <div class='iner' style='padding:0;min-height:205px;float:left;background:white;width:100%;'>\n\
        <div id='chiud' style='width:97%;text-align:right;float:left;padding-top:10px;'><img id='x' src="+baseurl+"/include/images/c_drop.png style='cursor:pointer;' onclick='vetrina.scompari2()' alt='chiudi' /></div>\n\
        <div text-align='center' style='background:white;height:83px;width:600px'>   <h5 style='color:#3477AB;float:left;padding-left:2%;width:98%;'>Gestione Logo</h5><iframe frameborder=0 style='height:83px;width:450px' src="+this.url+"/vetrina/changelogo></iframe></div></div>\n\
    <div class='corner-bot-left2' style='width:7px;float:left;height:7px;'></div>\n\
        <div class='border-bot' style='width:586px;float:left;height:7px;background:white;'></div>\n\
        <div class='corner-bot-right2' style='width:7px;float:left;height:7px;'></div></div>" );
        $("ap").style.height="100px";
        $("map").style.height="83px";
        $("ap").appear({ 
            duration: 0.5
        });

    },
    eliminaLogo:function()
    {
        var risp=confirm("Vuoi eliminare il logo?");
        if (risp)
        {
            var options={
                method : "GET",
                parameters:null,
              
              
                onSuccess:function(transport){
                    var risp = transport.responseText;
                    //$('logo_az').style.visibility = 'hidden';
                    //$('elimina_logo').style.visibility = 'hidden';

                    $('logo_az').src=baseurl+"/data/images/logo/default_aziendecom_user_avatar_80x80.gif";
                    $('elimina_logo').hide();
                },
                onFailure:function(transport){
                    var risp = transport.responseText;
                }
            };

            new Ajax.Request(this.url+"/vetrina/eliminalogo/id/"+this.id,options);
            $("logo_az").src=baseurl+"/include/images/indicator_medium.gif";
        }
    },
    aggiungiProdotto:function()
    {
         
        var options={
            method : "GET",
            parameters:"action=add",
            onSuccess:function(transport){
            
                var risp=transport.responseText.evalJSON(true);
                $('maschera').style.visibility = 'visible';
                $("maschera").show();
                $('ap').style.visibility = 'visible';
                $("map").update(risp.form);
                $('ap').appear({
                    duration: 0.5
                });

                      
            },
            onFailure:function(transport){
            }
        };

        new Ajax.Request(this.url+"/vetrina/catalogo/id/"+this.id,options);

    },
    saveItem:function(index,page)
    {
         
        var risposta=confirm("Vuoi salvare le modifiche effettuate?");
        
        if(risposta)
        {
            var parametri;
            $$("div.error").each(function(s){
                s.hide();
            });

            $("prezzo").value=$("prezzo").value.replace(",",".");
            $("quantita").value=$("quantita").value.replace(",",".");

            if(!isFinite($("quantita").value))
                $("qt_error").show();
            if(!isFinite($("prezzo").value))
                $("prezzo_error").show();

            if($("nome").getValue()=="")
                $("nome_error").show();

            if($("foto").value=="")
                $("foto_error").show();

            if($("quantita").getValue()=="") $("quantita").value=0;
            if($("prezzo").getValue()=="") $("prezzo").value=0;
            //SE INDEX = -1 allora sto facendo un inderimento nel database
            var sel;
            for (var i=0;i<2;i++)
            {
                if ($("visibile").options[i].selected)
                    sel=$("visibile").options[i].value;

            }
             
            
            if (index==-1)
                parametri="action=save&id_azienda="+this.id+"&"+$('form').serialize()+"&visibile="+sel+"&page="+page;
            else
                parametri="action=save&id_prodotto="+index+"&id_azienda="+this.id+"&"+$("form").serialize()+"&visibile="+sel+"&page="+page;

            if($("nome").getValue()!=""&&$("foto").value!="")
            {
                $("nome_error").hide();
                $("foto_error").hide();
                
                var options={
                    method : "POST",
                    parameters:parametri,
                    onSuccess:function(transport){

                        var risp=transport.responseText;
                        $('maschera').hide()
                        $("ap").hide();
                        $("content_c").update(risp);
                        $("content_c").show();
                    },

                    onFailure:function(transport){
                        var risp=transport.responseText;
                    //alert(risp);
                    }
                };
                new Ajax.Request(this.url+"/vetrina/catalogo/id/"+this.id,options);
            }
        }
    },
    cancellaItem:function(page,index,foto)
    {
        var risposta = confirm("Vuoi eliminare il prodotto?");
        if(risposta)
        {
            var options={
                method : "GET",
                parameters:"action=delete&id_azienda="+this.id+"&index="+index+"&foto="+foto+"&page="+page,
                onSuccess:function(transport){
                    var risp=transport.responseText;
                    $("content_c").hide();
                    $("content_c").update(risp);
                    $("content_c").show();//appear({ duration: 0.5 });
                },
                onFailure:function(transport){
                }
            };
            new Ajax.Request(this.url+"/vetrina/catalogo/id/"+this.id,options);
        }
    },
    modificaItem:function(page,index)
    {
        var options={
            method : "GET",
            parameters:"action=update&index="+index+"&page="+page,
            onSuccess:function(transport){
                var risp=transport.responseText.evalJSON(true);
                $('maschera').style.visibility = 'visible';
                $("maschera").show();
                $('ap').style.visibility = 'visible';
                $("map").update(risp.form);
                $('ap').appear({
                    duration: 0.5
                });
                      
            },
            onFailure:function(transport){
            }
        };
        new Ajax.Request(this.url+"/vetrina/catalogo/id/"+this.id,options);

    },

    massimizza:function(foto)
    {
        var img=this.url+"/data/images/prodotti/big"+foto;
        $('maschera').style.visibility = 'visible';
        $('maschera').show();
        $('ap').style.visibility = 'visible';
        $('map').style.background="rgb(245,245,245)";
        $("map").update("<img id='big' name='big'  src='"+img+"' />");
        $('ap').appear({ 
            duration: 0.5
        });
    },
    gestorePagina:function(azione,pagina)
    { 
        var risp=true;
        if (azione=="cancella")
        {
            if(pagina=="ALL_PAGES")
                risp=confirm("Vuoi eliminare TUTTE le pagine?");
            else
                risp=confirm("Vuoi eliminare la pagina?");
        }
        
        if (risp)
        { 
            var options={
                method : "GET",
                parameters:azione+"="+pagina,
                onSuccess:function(transport){
                    var risp=transport.responseText;
                    $("content_c").update(risp);
                    if($("azione_pagina").value=="cancella")
                    {
                        
                        $("servizi").removeChild($("pagina_"+pagina));
                    }
                    $("content_c").appear({
                        duration: 0.5
                    });
                },
                onFailure:function(transport){
                    var risp=transport.responseText.evalJSON(true);
                
                }
            };
            new Ajax.Request(this.url+"/vetrina/pagina/id/"+this.id,options);
        }
    },
    aggiungiContatto:function()
    {
        var risp=confirm("Vuoi aggiungere questo contatto al tuo Network?");
        if(risp)
        {
            var options={
                method : "GET",
                parameters:null,
                onSuccess:function(transport){
                    var risp=transport.responseText;
                    $('maschera').style.visibility = 'visible';
                    $('maschera').show();
                    $("map").update(risp);
                    $("map").style.height="50px";
                    $("botto").update("<br><input style='display:block;margin:0 auto;' id='o'  type='button' value='Ok' onclick='vetrina.scompari();'/>");
                    $("ap").style.height="73px";
                    $('ap').appear({
                        duration: 0.5
                    });
                    $("network").update("In attesa che l'azienda scelta accetti la tua partnership...");

                    if(document.all)
                        $("network").onclick=null;
                    else
                        $("network").removeAttribute("onclick");
                },
                onFailure:function(transport){
                  
                }
            };
            new Ajax.Request(this.url+"/vetrina/aggiungicontatto/id/"+this.id,options);
        }
        
    },
    gestoreSedi:function(parametri,sez)
    {
        cont=0;
        if (parametri=="action=salva" || parametri=="action=update")
        { 
            var recapiti=new Array();
            var contatore=0
            $$("select.tipo").each(function(s){
                for (var i=0;i<2;i++)
                {
                    if (s.options[i].selected){
                        recapiti[contatore]=s.options[i].value+"-";
                        contatore++;
                  
                    }
                }
            });
            
            
            contatore=0
            $$("input.numero").each(function(s){
                if(s.getValue()!="")
                {

                    recapiti[contatore]=recapiti[contatore]+""+s.getValue();
                    contatore++;
                    
                }               
            });
            parametri=parametri+"&"+$("sedi_form").serialize()+"&recapiti="+recapiti;
                   

        }


        var path=this.url;
        var options={
            method:"post",
            parameters:parametri,
            onCreate:function(x){
                var tmp=parametri.split('&');

                if(tmp[0]=="action=salva" || (tmp[0]=="action=update"))
                {
                    $('map').style.background="rgb(245,245,245)";
                    $("map").update("<img src="+path+"/include/images/indicatore.gif />");
                }
                if(tmp[0]=="action=elimina")
                {
                    $("s"+(tmp[1].split('='))[1]).update("<img src="+path+"/include/images/indicatore.gif />");
                }
              
            },
            onSuccess:function (transport)
            {
                var risp=transport.responseText.evalJSON(true);
                if(risp.action=="aggiungi")
                {
                    $('maschera').style.visibility = 'visible';
                    $("maschera").show();
                    $("map").update(risp.output);
                    $("ap").appear({
                        duration : 0.5
                    });
                    
                }
                else
                if (risp.action=="visualizza")
                {
                    $("maschera").hide();
                    $("ap").hide();
                    $("content_c").update(risp.output);
                }
                else if (risp.action=="elimina")
                {
                    $("sedi1").removeChild($("s"+risp.output));
                }
                else if(risp.action=="modifica")
                {
                    $('maschera').style.visibility = 'visible';
                    $("maschera").show();
                    $("map").update(risp.output);
                    $("ap").appear({
                        duration : 0.5
                    });
                             
                }
                else if(risp.action=="update")
                {
            // alert(risp.output);
            }
            },
            onFailure:function(transport){
                var risp=transport.responseText;
            //alert(risp);
            }
        };
            
        new Ajax.Request(sez,options);
        
             
    },
    addInput:function(parent)
    {
        if(document.all)
        {
            $(parent).innerHTML=$(parent).innerHTML+
            "<div id=numero"+cont+">\n\
            <input class=numero type=text />\n\
            <select class='tipo' style='float:left'>\n\
                  <option value=1>Tel</option>\n\
                  <option value=2>Fax</option>\n\
            </select><input id='ad' type=button value=X onclick='vetrina.delInput("+parent+","+cont+");'\n\
            </div>";
        }
        else
        {
            var div=document.createElement('div');
            div.setAttribute("id", "numero"+cont);
            if(document.all)
                div.setAttribute('className','df');
            else
                div.setAttribute("class", "df");

           
            var input=document.createElement("input");
            input.setAttribute("type", "text");
            
            var select=document.createElement("select");
            select.setAttribute("style","float:left")
            
            var option1=document.createElement("option");
            option1.setAttribute("value","1")
            option1.innerHTML="Tel";
            
            var option2=document.createElement("option");
            option2.setAttribute("value","2")
            option2.innerHTML="Fax";
            
            select.appendChild(option1);
            select.appendChild(option2);

            var del=document.createElement("input");
            del.setAttribute("type", "button");
            del.setAttribute("value","X");
            del.setAttribute("id","ad");
            
        
            if(document.all) //IE
            {
                del.onclick = function() {
                    vetrina.delInput(parent,cont);
                    return false;
                }
                input.setAttribute("className", "numero");
                select.setAttribute("className", "tipo");
            }
            else
            {
                del.setAttribute("onclick","vetrina.delInput('"+parent+"',"+cont+");");
                input.setAttribute("class", "numero");
                select.setAttribute("class", "tipo");
            }
        
            div.appendChild(input);
            div.appendChild(select);
            div.appendChild(del);
            $(parent).appendChild(div);
        }
       
        
        cont++;       
        
    },
    
    delInput:function(parent,n)
    {
        if(document.all)
        {
            var node=$('numero'+n+'');
            node.parentNode.removeChild(node);

        }
        else $(parent).removeChild($("numero"+n));
    },

    addKey:function(parent)
    {
        $("errore_chiavi").hide();
        if($$("input.spazio").length<limite)
        {
            if(document.all)
            {
                var yu="";


                $(parent).innerHTML=$(parent).innerHTML+
                "<div style='' class='telefonia' id=div_chiavi"+cont+">\n\
                <label> Parola chiave</label><input class=spazio name=chiave["+cont+"] class='tipo' value='Inserisci una parola' /><a href='#parolachiave' onclick='vetrina.delKey("+cont+")'><image src='"+this.url+"/include/images/x.png' border='0' /></a>\n\
                 <br /><br /></div>";

            }
            else
            {
                var div=document.createElement('div');

                div.setAttribute("id", "div_chiavi"+cont);

                if(document.all)
                    div.setAttribute('className','telefonia');
                else
                    div.setAttribute('class','telefonia');


                var select=document.createElement("input");
                select.setAttribute("value","Inserisci una parola chiave");
                select.setAttribute("name","chiave["+cont+"]")
                select.setAttribute("class","spazio")


                var del=document.createElement("img");
                del.setAttribute("src", this.url+"/include/images/x.png");
                del.setAttribute("onclick","vetrina.delKey("+cont+");");
                del.setAttribute("style","cursor: pointer");
                //del.setAttribute("name", "cat["+cont+"]");

                var label=document.createElement("label");
                label.innerHTML="Parola chiave";


                div.appendChild(label);
                div.appendChild(select);
                div.appendChild(del);
                div.appendChild(document.createElement("br"));
                div.appendChild(document.createElement("br"));
                $(parent).appendChild(div);
            }
            cont++;
            $("salva").style.color="red";
        }
        else
        {
            $("errore_chiavi").show();
        }

    },
    delKey:function(n)
    {
        var risp=confirm("Vuoi eliminare la parola chiave ?")
        
        if(risp);
        {
            if(document.all)
                $("div_chiavi"+n).parentNode.removeChild($("div_chiavi"+n));
            else
                $("div_chiavi").removeChild($("div_chiavi"+n));

            $("salva").style.color="red";
        }
    },
    eliminaTutteChiavi:function()
    {
        if(confirm('Vuoi eliminare tutte le chiavi?'))
        {
            $('div_chiavi').update();
            $('salva').style.color='red';
        }
    },

    cambiaStella:function(a,tipo){
        if(tipo==1)
            for(i = 1;i<=a;i++)
                $('star'+i).src=baseurl+"/include/images/stellina.gif";
            
        else if(tipo ==0)
        {
            var c=parseInt($("voto").value);
            for(i = c+1;i<=5;i++)
                $('star'+i).src=baseurl+"/include/images/stellina1.gif";
        }
        else
        {
            for(i = 1;i<=5;i++)
                $('star'+i).src=baseurl+"/include/images/stellina1.gif";
            $("voto").value="0";
        }
    },

    pubblicaCommento:function()
    {
        
        new Ajax.Request(baseurl+"/vetrina/commentinews/",
        {
            method:"POST",
            parameters:$("form").serialize(),
            onSuccess:function(transport){

                $("areacommenti").update(transport.responseText);
            },
            onFailure:function(transport){
                $("areacommenti").update($F("areacommenti")+"<br/><b style='color:red'>Si &amp; verificato un problema. Riprovare pi&ugrave; tardi.</b>");
            },
            onCreate:function(transport){
                $("areacommenti").update("<img src='"+baseurl+"/include/images/indicator_medium.gif' alt='Attendere prego...'/>");
            }
            
        }
        );
    },
    aprichiudicommenti:function(b,news)
    {
        if(b.value=="Vedi i commenti")
        {
            
            b.value="Nascondi i commenti";
            $("asp").show();
            new Ajax.Updater("areacommenti",baseurl+"/vetrina/commentinews/id_azienda/"+this.id+"/id_news/"+news,
            {
                onSuccess:function()
                    {
                        $("spaziocommenti").show();
                        $("asp").hide();
                    }

            });

            
        }
        else
        {
            b.value="Vedi i commenti";
            $("spaziocommenti").hide();
        }
    },
    creaStelleVoto:function(voto)
    {
        var v=parseInt(voto);
        alert(volo);
        for(i=1;i<=5;i++)
            {
                if(i<=v)
                $("stellevoto").innerHTML+="<img src="+baseurl+"/include/images/stellina.gif alt=voto />" ;
            else
                $("stellevoto").innerHTML+="<img src="+baseurl+"/include/images/stellina1.gif alt=voto />" ;
            }

    },
    conta:function()
    {
          

                var lunghezza=($("textcom").value.length);


                $("errore").hide();
                valore = 300;

                if (lunghezza >= valore)
                {

                    $("textcom").value=$("textcom").value.substr(0,valore);
                    $("rimasti").value=0;
                    $("scritti").value=valore;
                    $("errore").show();

                }
                else
                {

                    $("rimasti").value = valore-lunghezza;
                    $("scritti").value=lunghezza;
                }



    }
   

};
