//falta imatge volver siguiente i anterior    
var result;
var nodeEval;
var desc;
var path;
var id_item;
var other_img;
var temps =1000;
var array_img =null;
var nom;
var num_items_page = 21;
var num_items_page_new =4;//contem imatge gran

var menus_list="INI,BIJ,CAB,OTR,CONTACT";

function FocusMenu(cat)
{
   var img= document.getElementById(cat+"_menu");                    
   img.src="img/"+cat+"_act.png";                        
}

function FocusMsg()
{
   var txt= document.getElementById("msg");                    
   alert(txt.value);
   if (txt.value == "Castellano/Català/English") txt.value = "";
}

function NoFocusMenu(cat)
{
   var control_hidd_cat= document.getElementById("hidd_cat");

   if (control_hidd_cat.value != cat)
   {
        var img= document.getElementById(cat+"_menu");                    
        img.src="img/"+cat+"_inact.png";                        
   }
}

function CalcTotal(cat)
{
    var xpathText= "//web/cat[@id='"+cat+"']/list_items/item";
    var xmlDoc ;					
    var total;
    
    var menus = menus_list.split(',');    
    for (var i = 0; i < menus.length ;i++) 
    {           
        var img= document.getElementById(menus[i]+"_menu");                        
        if (menus[i] == cat)    img.src="img/"+cat+"_act.png";        
        else                    img.src="img/"+menus[i]+"_inact.png";                     
    }
    
    try
    {							
        //FF
        var Loader = new XMLHttpRequest();    		  
	    Loader.open("GET", "data/list_items.xml" ,false);     	
	    Loader.send(null);
	    xmlDoc=Loader.responseXML;
        total = xmlDoc.evaluate("count("+xpathText+")", xmlDoc, null, XPathResult.ANY_TYPE, null );        
        total = total.numberValue;
    }
    catch(e)
    {				
	    //IE
	    try {    	
		    xmlDoc= new ActiveXObject("Microsoft.XMLDOM");		    			
		    xmlDoc.async="false";
		    xmlDoc.load("data/list_items.xml");	    				
		    var doc = xmlDoc.ownerDocument;									    			    
		    if (doc == null) doc = xmlDoc;						
		    doc.setProperty("SelectionLanguage", "XPath");
		    if (xmlDoc == doc) xmlDoc = doc.documentElement;		        							
    	    total =xmlDoc.selectNodes(xpathText);
            total= total.length;		    
		   }
		   catch(f)
		   {}
    }
            
    var control_hidd_total= document.getElementById("hidd_total");
    control_hidd_total.value= total;
}

function FillCat(cat)
{
    temps=1000;
    
    CalcTotal(cat);
    
    FillCatPage(cat,1);
}

function FillCatPage(cat,cont_ini)
{
    var control_hidd= document.getElementById("hidd_page");
    var control_hidd_cat= document.getElementById("hidd_cat");           
    control_hidd_cat.value= cat;
    var control_hidd_total= document.getElementById("hidd_total");        
    var cont_last = cont_ini + num_items_page;        
    control_hidd.value= cont_ini;    
    var control_hidd_item= document.getElementById("hidd_item");
    control_hidd_item.value=0;

    ContentInVisible('ini');          				                                         
    ContentInVisible('list');      
    ContentInVisible('item');      
    ContentInVisible('contacta');      
     
    
    if (cat == 'INI')
    {
        for (var i = 1; i <= num_items_page_new;i++ ) ControlInVisible('content_ini_'+i);              	                                                     
    }
    else
    {
        for (var i = 1; i <= num_items_page;i++ ) ControlInVisible('content_'+i);                       
    }            
        
    var xpathText  ="//web/cat[@id='"+cat+"']/list_items/item[position()>="+cont_ini+" and position()<"+cont_last+"]";									           								                    
    
    FilterXmlXpath(xpathText);
  
    setTimeout("ShowControl("+cont_ini+")",0); 
}				

function ShowControl(cont_ini)
{
    var control_hidd= document.getElementById("hidd_page");
    var control_hidd_cat= document.getElementById("hidd_cat");                   
    var cont_last = cont_ini + num_items_page;        
    control_hidd.value= cont_ini;    
     
    var cat = control_hidd_cat.value;
    if (cat=='INI')
    {            
        ContentVisible('ini');          				                                         
        ContentInVisible('list');      
        ContentInVisible('item');      
        ContentInVisible('contacta');      
    }
    else if (cat=='CONTACT')
    {
        ContentVisible('contacta');      
        ContentInVisible('item');      
        ContentInVisible('ini');      
        ContentInVisible('list');      
    } 
    else
    {    
        ContentVisible('list');      
        ContentInVisible('ini');     
        ContentInVisible('item');      
        ContentInVisible('contacta');      
    }
}

function ShowItemFF(cont)
{
    var NodeDesc;
    var NodePath;	    
    var NodeName;    									
    var NodeId;
    var NodeOtherImg;
    
    id_item="";
    path="";
    desc="";
    name="";
    other_img="";

    NodeDesc        = nodeEval.getElementsByTagName("desc");	
    NodePath        = nodeEval.getElementsByTagName("path");	    
    NodeName        = nodeEval.getElementsByTagName("name");		    
    NodeId          = nodeEval.getElementsByTagName("id");		    
    NodeOtherImg    = nodeEval.getElementsByTagName("other_img");		    
    
    if (NodePath[0]!= null)        path=NodePath[0].textContent;    
    if (NodeDesc[0]!= null)        desc=NodeDesc[0].textContent;				        
    if (NodeName[0]!= null)        name=NodeName[0].textContent;				        
    if (NodeId[0]!= null)          id_item = NodeId[0].textContent;			            
    if (NodeOtherImg[0]!= null)    other_img = NodeOtherImg[0].textContent;			            
    
    ShowItem(cont);
    				
    nodeEval= result.iterateNext();
    if (nodeEval)
    {
        cont++;                
        setTimeout("ShowItemFF("+cont+")",temps);
    }
}

function ShowItemIE(cont)
{	
     id_item="";
     path="";
     desc="";
     name="";
     other_img="";                                  
        
     if (result[cont].childNodes(0) != null && result[cont].childNodes(0).childNodes(0) != null) id_item=result[cont].childNodes(0).childNodes(0).xml;               
     if (result[cont].childNodes(1) != null && result[cont].childNodes(1).childNodes(0) != null) path=result[cont].childNodes(1).childNodes(0).xml;          
     if (result[cont].childNodes(2) != null && result[cont].childNodes(2).childNodes(0) != null) desc=result[cont].childNodes(2).childNodes(0).xml;          
     if (result[cont].childNodes(3) != null && result[cont].childNodes(3).childNodes(0) != null) name=result[cont].childNodes(3).childNodes(0).xml;			                  
     if (result[cont].childNodes(4) != null && result[cont].childNodes(4).childNodes(0) != null) other_img=result[cont].childNodes(4).childNodes(0).xml;			        
            
     ShowItem(cont + 1);
    
     cont++;          
     if (cont < result.length ) 
     {     
        setTimeout("ShowItemIE("+cont+")",temps);     
     }    
}
												

function ShowItem(cont)
{           
    var control_hidd_cat= document.getElementById("hidd_cat");           
    var cat_hidd =control_hidd_cat.value;
    var control_hidd_item= document.getElementById("hidd_item");
    var hidd_item =control_hidd_item.value;
    var control_hidd= document.getElementById("hidd_page");
    var control_hidd_total= document.getElementById("hidd_total");        
    
    var tmp ='';
    if (cat_hidd=='INI')  tmp='ini_';  else if (hidd_item != "0")   tmp='item_';

    var control_name ='content_'+tmp+cont;
    var control =  document.getElementById(control_name);  
        
    ControlInVisible(control_name);
                
    if (cat_hidd=='INI')
    {                
       if (cont == 1)
       {                                   
            var img_in = document.createElement("img");                        
            img_in.src='img_items/'+path;
            img_in.alt='';
            img_in.title='';         
            control.appendChild(img_in);         
                                                                   
       }
       else
       {
            var link_nova_img = document.createElement("a");                                     
                                
            var txt =id_item;
            link_nova_img.onclick = function() {ShowOneItem(txt);}
            
            path = path.split('.')[0]+'_mini.'+path.split('.')[1];                 
            link_nova_img.appendChild(BuildImg('img_items/'+path,''));
            
            var p = document.createElement("p");                
            p.innerHTML = name;                                
            
            control.appendChild(p); 
                        
            control.appendChild(link_nova_img);                                                                      
                                                                     
       }
              
    }
    else if (hidd_item == "0") 
    {    
                                    
        path = path.split('.')[0]+'_mini.'+path.split('.')[1];                          
       
        var link_nova_img = document.createElement("a");                                        
        
        var txt =id_item;
        link_nova_img.onclick = function() {ShowOneItem(txt);}        
        
        link_nova_img.appendChild(BuildImg('img_items/'+path,'')); 
        
        
        var p = document.createElement("p");                
        p.innerHTML = name;        
        control.appendChild(p)
        
        control.appendChild(link_nova_img);                                                                      
                
        var num =new Number(control_hidd.value);
        var num_total =new Number(control_hidd_total.value);    
                   
        if ( cont == 1 )
        {            
            if ( (num - num_items_page ) > 0 )
            {            
                var p_link_prev = document.createElement("p");                
                var a_link_prev = document.createElement("a");                                
                
                a_link_prev.onclick = function() {PrevPage();}     
            
                var img_link_prev = document.createElement("img");                
                img_link_prev.src="img/letArr.png";                
                var classe =document.createAttribute("class");            
                classe.value="img_nav";                        
                img_link_prev.setAttributeNode(classe);            
                img_link_prev.title='Anterior';
                img_link_prev.alt='Anterior';                
                
                a_link_prev.appendChild(img_link_prev);
                p_link_prev.appendChild(a_link_prev);
    
                control.appendChild(p_link_prev);                
            }    
            
        }
        else if (cont == num_items_page)
        {        
            if ( (num + num_items_page) <= num_total )
            {        
                var p_link_next = document.createElement("p");                
                var a_link_next = document.createElement("a");                
                
                a_link_next.onclick = function() {NextPage();}     
                var img_link_next = document.createElement("img");                
                img_link_next.src="img/rigArr.png";
                var classe =document.createAttribute("class");            
                classe.value="img_nav";      
                img_link_next.setAttributeNode(classe);
                img_link_next.title='Siguiente';
                img_link_next.alt='Siguiente';
                a_link_next.appendChild(img_link_next);
                p_link_next.appendChild(a_link_next);
    
                control.appendChild(p_link_next);                                         
            }
        }        
    }
    else
    {
        var titul = document.createElement("p");                
        titul.innerHTML = name;                             
                               
        var p_img =document.createElement("p");                
        p_img.appendChild(BuildImg('img_items/'+path,name));
        
        var desc_item = document.createElement("p");                
                
        desc= desc.replace("Materiales","<br/><br/>Materiales");
        desc= desc.replace("Gracias a","<br/>Gracias a");                 
        desc= desc.replace("Precios","<br/>Precios (aprox. seg&uacute;n modelo sin gastos de env&iacute;o)");                 
        
        desc_item.innerHTML = desc;                                                                          
        
        var p2_link_back = document.createElement("p");                
        var a2_link_back = document.createElement("a");                     
        
        a2_link_back.onclick = function() {BackToCatPage();}     
        
        var img2_link_back = document.createElement("img");                
        img2_link_back.src="img/letArr.png";        
        var classe =document.createAttribute("class");            
        classe.value="img_nav";                        
        img2_link_back.setAttributeNode(classe);                
        img2_link_back.title='Volver a la categoria';
        img2_link_back.alt='Volver a la categoria';
        
        a2_link_back.appendChild(img2_link_back);
        p2_link_back.appendChild(a2_link_back);                       
        
        control.appendChild(titul);
        control.appendChild(p_img);
        control.appendChild(desc_item);        
        
        control.appendChild(p2_link_back);    
        
        if (other_img!='')
        {            
            var otros_titul = document.createElement("p");                
            otros_titul.innerHTML = '\<BR\>Otras Im&#225;genes: (p&#250;lsalas para verlas m&#225;s grandes)\<BR\>\<BR\>';        
            var otro_p = document.createElement("p");                
            var llista_img = document.createElement("div");                
            llista_img.id="otras";
            
            array_img =other_img.split(',');
            if (array_img.length > 0)
            {              
                for (var k= 0;k < array_img.length;k++)
                {                                        
                  var link_nova_img = document.createElement("a");
                  link_nova_img.num = k;                                     
                                                      
                  link_nova_img.onclick = function() {ShowOtraFoto(this.num);}
                                              
                  link_nova_img.appendChild(BuildImg('img_items/'+array_img[k],name));            
                  llista_img.appendChild(link_nova_img);                                                                                                                            
                }
            }            
            control.appendChild(otros_titul);                
            otro_p.appendChild(llista_img);        
            control.appendChild(otro_p);                        
        }
                            
    }       
    
    ControlVisible(control_name);             
}

function FilterXmlXpath(xpathText)
{
    var xmlDoc ;	    
    
    try{							
        //FF
	    var Loader = new XMLHttpRequest();    	    
	    Loader.open("GET", "data/list_items.xml" ,false);     	
	    Loader.send(null);
	    xmlDoc=Loader.responseXML;
    	    	
    	result =xmlDoc.evaluate(xpathText, xmlDoc, null,XPathResult.ANY_TYPE, null );						    	
	    nodeEval = result.iterateNext();																	        	
                
        if (nodeEval) ShowItemFF(1);    					
    }
    catch(e)
    {				
	    // IE
	    try {
    	
		    xmlDoc= new ActiveXObject("Microsoft.XMLDOM");		    			
		    xmlDoc.async="false";
		    xmlDoc.load("data/list_items.xml");	    				    							    
		    var doc = xmlDoc.ownerDocument;									    				   
		    if (doc == null) doc = xmlDoc;						    			    
		    doc.setProperty("SelectionLanguage", "XPath");
		    if (xmlDoc == doc) xmlDoc = doc.documentElement;		    
		    
		    result =xmlDoc.selectNodes(xpathText);	        
		    
            if (result.length >0)  ShowItemIE(0);																																								
	    }
	    catch(e) {	
		    // If the IE API doesn't work, we just give up
		    throw "XPath not supported by this browser.";
	    }
    }
}

function ShowOneItem(item)
{    

    ContentVisible('item');
    ContentInVisible('list');      
    ContentInVisible('ini');                     
    ContentInVisible('contacta');                     
    
    ControlInVisible('content_item_1');
    
    var control_hidd_item= document.getElementById("hidd_item");
    control_hidd_item.value=item;
    
    var control_hidd_cat= document.getElementById("hidd_cat");
        
    control_hidd_cat.value  = FindCat(item);
         
    var xpathText  ="//web/cat/list_items/item[ id ='"+item+"']";									           								                        
    
    FilterXmlXpath(xpathText);
}



function FindCat(item)
{    
    var control_hidd_cat= document.getElementById("hidd_cat");
    var xpathText  ="//web/cat[./list_items/item/id ='"+item+"']/@id";									           								                        
        
    if (control_hidd_cat.value =='INI') //buscar categoria i posar al hidd
    {         
        var xmlDoc ;					
        var cat;
        try{							
            //FF
	        var Loader = new XMLHttpRequest();    	    
	        Loader.open("GET", "data/list_items.xml" ,false);     	
	        Loader.send(null);
	        xmlDoc=Loader.responseXML;
        	    	
    	    result =xmlDoc.evaluate(xpathText, xmlDoc, null,XPathResult.ANY_TYPE, null );						    	
	        nodeEval = result.iterateNext();																	        	

                    
            if (nodeEval) 
            {
                cat =nodeEval.textContent;                                                                
            }
        }
        catch(e)
        {				
	        // IE
	        try {
        	
		        xmlDoc= new ActiveXObject("Microsoft.XMLDOM");		    			
		        xmlDoc.async="false";
		        xmlDoc.load("data/list_items.xml");	    				    							    
		        var doc = xmlDoc.ownerDocument;									    				   
		        if (doc == null) doc = xmlDoc;						    			    
		        doc.setProperty("SelectionLanguage", "XPath");
		        if (xmlDoc == doc) xmlDoc = doc.documentElement;		    
    		    
		        result =xmlDoc.selectNodes(xpathText);            	 
		        
                if (result.length >0) 
                {                    
                    cat=result[0].childNodes(0).xml;                         
                }
	        }
	        catch(e) {	
		        // If the IE API doesn't work, we just give up
		        throw "XPath not supported by this browser.";
	        }
        }                
        
        var menus = menus_list.split(',');    
        for (var i = 0; i < menus.length ;i++) 
        {           
            var img= document.getElementById(menus[i]+"_menu");                        
            if (menus[i] == cat)    img.src="img/"+cat+"_act.png";        
            else                    img.src="img/"+menus[i]+"_inact.png";                     
        }
        
        return cat;
    }    
    else
    {
        return control_hidd_cat.value;
    }
}

function ControlVisible(control_name)
{    
    new Effect.Opacity(control_name, {duration:2, from: 0, to: 1 });
}

function ControlInVisible(control_name)
{
    var control =document.getElementById(control_name);        

    if (control != null)
    {
        while( control.hasChildNodes())
        { 
            control.removeChild(control.lastChild);                            
        }
        
         new Effect.Opacity(control_name, {duration: 0.01, from: 1, to: 0 });
     }
}

function ContentVisible(control_name)
{
    var control =document.getElementById(control_name)
    
    
    if (control != null)
    {
        control.style.visibility ='visible';             
        control.style.display ='block';                				                                    				                                            
        control.style.height ='auto';                				                          
        control.style.overflow ='auto';                				                          
    }
}

function ContentInVisible(control_name)
{
    var control =document.getElementById(control_name)
    
    if (control != null)
    {
        control.style.visibility ='hidden';  
        control.style.display ='none';                				                          
        control.style.height ='0px'; 
        control.style.overflow ='hidden';                				                          
    }
}

function PrevPage()
{     
    var control_hidd= document.getElementById("hidd_page");
    var control_hidd_cat= document.getElementById("hidd_cat");
            
    var cont_ini =new Number(control_hidd.value);            
    cont_ini = cont_ini - num_items_page;    
    
    temps=1;
               
    FillCatPage(control_hidd_cat.value,cont_ini);
}

function NextPage()
{     
    var control_hidd= document.getElementById("hidd_page");
    var control_hidd_cat= document.getElementById("hidd_cat");
            
    var cont_ini =new Number(control_hidd.value);                    
    cont_ini = cont_ini + num_items_page;    
            
    temps=1000;
       
    FillCatPage(control_hidd_cat.value,cont_ini);
}

function BackToCatPage()
{
    var control_hidd_cat= document.getElementById("hidd_cat");
    var control_hidd= document.getElementById("hidd_page");                
    var cont_ini =new Number(control_hidd.value);  
          
    var cat =control_hidd_cat.value;

    CalcTotal(cat);
    
    temps=1;
    
    FillCatPage(cat,cont_ini);
}


function BuildImg(src,title)
{ 
      if (title == '') title = 'Pulsa la imagen para ver su ficha y otras fotos con detalles.';                 
      var div_out = document.createElement("div");
      var classe_out =document.createAttribute("class");            
      classe_out.value="out image";      
      div_out.setAttributeNode(classe_out);         
      
      var div_in = document.createElement("div");
      var classe_in =document.createAttribute("class");            
      classe_in.value="in rtin tpin";      
      div_in.setAttributeNode(classe_in);       
      
      var img_in = document.createElement("img");                        
      img_in.src=src;
      img_in.alt=title;
      img_in.title=title;         
      
      div_in.appendChild(img_in);
      div_out.appendChild(div_in);              
              
      return div_out;
}


function validateEmail ( emailField ) {
 emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
 if( !emailpat.test( emailField.value ) ) {
  
  emailField.focus();
  emailField.select();
  return false;
 }
 return true;
}

function validate_contact()
{
    var validat = true;
       
    var nom = document.getElementById('nom');
    var val_nom = document.getElementById('val_nom');
    
    var email = document.getElementById('email');
    var val_email = document.getElementById('val_email');
    var formato_email = document.getElementById('formato_email');
        
    var msg = document.getElementById('msg');
    var val_msg = document.getElementById('val_msg');    
        
    if (nom.value == '')    {   val_nom.style.visibility='visible';     validat=false; } else val_nom.style.visibility  ='hidden';
    if (msg.value == '')    {   val_msg.style.visibility='visible';     validat=false; } else val_msg.style.visibility  ='hidden';
    if (email.value == '')  {   val_email.style.visibility='visible';   validat=false; } else val_email.style.visibility='hidden';
 
    var email_value=email.value;        
    
    var emailpat = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9])+(\.[a-zA-Z0-9_-]+)+$/;
    if( !emailpat.test( email_value ) ) 
    {
        formato_email.style.display='block';
        formato_email.style.visibility='visible'; validat=false; 
    }
    else
    {
        formato_email.style.display='none';
        formato_email.style.visibility='hidden';
    }       
    
    //if (email_value.match(re))  formato_email.style.visibility='hidden';  else { formato_email.style.visibility='visible'; validat=false; }         
    return validat;
}



function ShowOtraFoto(index)
{
   if (array_img.length > 0)
   {
       var num = new Number(index);
       
       var OtrasFotosOpac= document.getElementById('OtrasFotosOpac');
       var OtrasFotos= document.getElementById('OtrasFotos');
       var otra_img= document.getElementById('otra_img');
       var btn_cerrar= document.getElementById('close'); 
       var prev_otr_img= document.getElementById('prev_otr_img'); 
       var next_otr_img= document.getElementById('next_otr_img'); 
       var hidd_otra_img= document.getElementById('hidd_otra_img'); 

       hidd_otra_img.value=num;              
       otra_img.src='img_items/'+array_img[num];
       
       OtrasFotosOpac.style.display='block';
       OtrasFotos.style.display='block';
       btn_cerrar.style.display='block';
       otra_img.style.display='block';
       
       if (num > 0)
        prev_otr_img.style.display='block';
       else 
        prev_otr_img.style.display='none';
       
       if (num < (array_img.length - 1))
        next_otr_img.style.display='block';
       else
        next_otr_img.style.display='none';
     
   }
      
}

function ShowNextOtraImg()
{
    var hidd_otra_img= document.getElementById('hidd_otra_img'); 
    var num =new Number(hidd_otra_img.value);   
    var index=num + 1;
    
    ShowOtraFoto(index);    
}


function ShowPrevOtraImg()
{
    var hidd_otra_img= document.getElementById('hidd_otra_img'); 
    var num =new Number(hidd_otra_img.value);   
    var index=num - 1;
    
    ShowOtraFoto(index);    
}


function CloseOtraFoto()
{
   var OtrasFotosOpac= document.getElementById('OtrasFotosOpac');
   var OtrasFotos= document.getElementById('OtrasFotos');
   var otra_img= document.getElementById('otra_img');
   var otra_img= document.getElementById('otra_img');
   var btn_cerrar= document.getElementById('close'); 
   var prev_otr_img= document.getElementById('prev_otr_img'); 
   var next_otr_img= document.getElementById('next_otr_img'); 
   
    
   otra_img.src='';
   
   OtrasFotosOpac.style.display='none';
   OtrasFotos.style.display='none';      
   otra_img.style.display='none';         
   btn_cerrar.style.display='none';    
   prev_otr_img.style.display='none';
   next_otr_img.style.display='none';  
}



function getURLVar(urlVarName) 
{
    var urlHalves = String(document.location).split('?');
    var cat= "INI";
    if (urlHalves.length > 1)
    {        
        if(urlHalves[1])
        {
            var urlVars = urlHalves[1].split('&');

            for(i=0; i<=(urlVars.length); i++)
            {
                if(urlVars[i])
                {                    
                    var urlVarPair = urlVars[i].split('=');
                    if (urlVarPair[0] && urlVarPair[0] == urlVarName)   cat = urlVarPair[1];
                }
            }
        }
    } 
    FillCat(cat);
}

function EmptyMsg()
{
   var txt= document.getElementById("msg");                    
      
   if (txt.value="Castellano/Català/English")                          
   {
    txt.value="";
   }
}

function ChangePhoto(img_origen)
{
    var img_desti =document.getElementById('imgitem_0');
    
    var tmp=img_desti.src;
    img_desti.src=img_origen.src;
        
}


function ILikePhoto(cb_like)
{
    var id=cb_like.id;
    var img =document.getElementById('imgitem_'+id.split('_')[1]);    
    var tmp=img.src;
    var img_base =document.getElementById('imgMeGusta');            
    var div_parent =img_base.parentNode;
    var hidden =document.getElementById('hiddenMeGusta');
    var contMeGusta =document.getElementById('contMeGusta');        
          
    if (cb_like.checked)    
    {      
        if (hidden.value.indexOf(tmp) == -1)
        {
            var new_img=img_base.cloneNode(true);
            new_img.id="imgMeGusta_"+img_base.parentNode.childNodes.length;
            new_img.style.display="";
            new_img.childNodes[0].id="newimg_"+img_base.parentNode.childNodes.length;
            new_img.childNodes[0].src=tmp;
            new_img.childNodes[1].id="delimg_"+img_base.parentNode.childNodes.length;
            img_base.parentNode.appendChild(new_img);
                    
            hidden.value = hidden.value+new_img.childNodes[0].src+",";
                    
            if (!contMeGusta.innerHTML)
            {
                contMeGusta.innerHTML = 1;
            }
            else 
            {
                contMeGusta.innerHTML = parseInt(contMeGusta.innerHTML) + 1;
            }
        }
    }
    else
    {    
        for( var x = 0; img_base.parentNode.childNodes.length; x++ )
        {               
            if (img_base.parentNode.childNodes[x].nodeType == 1) 
            {
                if (img_base.parentNode.childNodes[x].childNodes[0].src == tmp)
                {                                                        
                    hidden.value = hidden.value.replace(img_base.parentNode.childNodes[x].childNodes[0].src+",","");    
                    
                    if (parseInt(contMeGusta.innerHTML)>0)
                    {
                        contMeGusta.innerHTML = parseInt(contMeGusta.innerHTML) - 1;
                    }
                    img_base.parentNode.removeChild(img_base.parentNode.childNodes[x]);                    
                }
            }
        }
    }        
    document.getElementById('formHidden').submit();    
    
        
}

function IDontLikePhoto(cb_dontlike)
{
    var id=cb_dontlike.parentNode.id;
    
    var img =document.getElementById('imgMeGusta_'+id.split('_')[1]);    

    var hidden =document.getElementById('hiddenMeGusta');
    
    hidden.value = hidden.value.replace(img.childNodes[0].src+",","");

    img.parentNode.removeChild(img);                

    var contMeGusta =document.getElementById('contMeGusta');

    if (parseInt(contMeGusta.innerHTML)>0)
        contMeGusta.innerHTML = parseInt(contMeGusta.innerHTML) - 1;

   document.getElementById('formHidden').submit();            
}



function ILikePhotoList()
{   
   var hidden =document.getElementById('hiddenMeGusta');
   var contMeGusta =document.getElementById('contMeGusta');       
   var cont =hidden.value.split(',');      
   var img_base =document.getElementById('imgMeGusta');               
   var div_parent =img_base.parentNode;   
   
   for(i=0; i<(cont.length); i++)
   {
      if (hidden.value.split(',')[i]!='')
      {
         var new_img=img_base.cloneNode(true);
         new_img.id="imgMeGusta_"+img_base.parentNode.childNodes.length;
         new_img.style.display="";
         new_img.childNodes[0].id="newimg_"+img_base.parentNode.childNodes.length;
         new_img.childNodes[0].src=hidden.value.split(',')[i];
         new_img.childNodes[1].id="delimg_"+img_base.parentNode.childNodes.length;
         img_base.parentNode.appendChild(new_img);
      
         if (!contMeGusta.innerHTML)
        {
            contMeGusta.innerHTML = 1;
        }
        else 
        {
            contMeGusta.innerHTML = parseInt(contMeGusta.innerHTML) + 1;
        }
      }
   }
    
}
