/**
 * Funciones
 */

function fitxers(url)
{
	obret(url,750,500,'no','ficheros');
}


function imatges(projecte)
{
	obret(projecte+'backoffice/ficheros/images',750,500,'no','imatges');
}


/**
  * Switch given value of ID's from 1 to 0, or vice versa.
*/
function switchActive(id)
{
	el = document.getElementById(id);
	el.value = (el.value != 1) ? 1 : 0 ;
}
	
	
var allPageTags = new Array(); 
function hideFlash()
{
    var allPageTags=document.getElementsByTagName("div");
 
    for (i=0; i<allPageTags.length; i++)
    {
    	if (allPageTags[i].className=='message' || allPageTags[i].className=='messageOK' || allPageTags[i].className=='messageFALSE')
    	{
    		allPageTags[i].style.display='none'; 
    	}
    }
}

function showFlashRepositori()
{
	var allPageTags=parent.frames['list'].document.getElementsByTagName("div");
    //var allPageTags=document.getElementsByTagName("div");
 
    for (i=0; i<allPageTags.length; i++)
    {
    	if (allPageTags[i].className=='message' || allPageTags[i].className=='messageOK' || allPageTags[i].className=='messageFALSE')
    	{
    		allPageTags[i].style.display=''; 
    	}
    }
}



function obret(pagina,ample,alt,scroll,finestrapagina)
{
	/* <a href="#" onClick="obret('contacte.htm',460,370,'no','contacte');" class="txtPeu">contacte</a> */	
	if (scroll=="si")d=1;
	if (scroll=="no")d=0;
	if (scroll=="")d=0;
	
	LeftPosition = (screen.width) ? (screen.width-ample)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-alt)/2 : 0;

	settings='width='+ample+',height='+alt+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+d+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=yes';
	win=window.open(pagina,finestrapagina,settings);
	//Focus de la finestra
	win.focus();	
}


function adjunts(pagina,ample,alt,scroll,finestrapagina)
{
	/* <a href="#" onClick="obret('contacte.htm',460,370,'no','contacte');" class="txtPeu">contacte</a> */	
	if (scroll=="si")d=1;
	if (scroll=="no")d=0;
	if (scroll=="")d=0;
	
	LeftPosition = (screen.width) ? (screen.width-ample)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-alt)/2 : 0;

	settings='width='+ample+',height='+alt+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+d+',location=yes,directories=no,status=no,menubar=yes,toolbar=no,resizable=yes';
	win=window.open(pagina,finestrapagina,settings);
	//Focus de la finestra
	win.focus();	
}


// FITXERS LLISTAT ---------------------------------------------------------
function mira_nav()
{
	var Nav=navigator.appName;
	//alert (Nav);
	return Nav;
}

// TEURE FITXERS
function ext_act(camp,camp_preview,preview,ruta)
{
	nav=mira_nav(); //Alert (nav);

	//numact = eval("document.editor."+camp+".options.length");
	numact = camp.length;
	nomcamp = camp;

	//alert (numact);
	//alert (document.editor.grup_activitat.selectedIndex);
	//Si no hi ha cap activitat, no fem res
	if ((numact == 0) || ((numact != 0) && (nomcamp.selectedIndex==-1)))
	{
		document.editor.elimina.disabled;
		return numact;
	}	
	else
	{
		if (nav=="Netscape")
		{
			//document.editor.grup_activitat.options[document.editor.grup_activitat.selectedIndex].value="";
			//document.editor.grup_activitat.options[document.editor.grup_activitat.selectedIndex]=null;
			nomcamp.options[nomcamp.selectedIndex].value="";
			nomcamp.options[nomcamp.selectedIndex]=null;
		}
		else
		{
			//document.editor.grup_activitat.options.remove(document.editor.grup_activitat.selectedIndex);
			nomcamp.options.remove(nomcamp.selectedIndex);
		}	
		
		if(preview==1) document.getElementById(camp_preview).src=ruta+"img/backoffice/preview.gif";
		//if (numact == document.editor.activitat.options.length) numact--;
		return numact;
	}
}

// INSERTAR FITXERS
function insertaFile(camp, name, file, multiple)
{
	//var nomcamp = document.editor.elements['data[Noticia][img]'];
	var nomcamp = document.editor.elements[camp];
	file = file.substr(1)	

	Nav=mira_nav();

	if(nomcamp.type=="text")
	{
		// text
		document.getElementById(camp).value = file;
	}
	else
	{
		// select-multiple
		if (Nav=="Netscape")
		{
			var opcion = new Option(name,file,false,false);
			//opcion.setAttribute("ruta", file);
			if(multiple=="multiple") nomcamp.options[nomcamp.options.length]=opcion;
			else nomcamp.options[0]=opcion;
		}
		else
		{			
			var nou_camp=document.createElement("OPTION");
			nou_camp.text=name;
			nou_camp.value=file;
			//nou_camp.setAttribute("ruta", file);
			
			if(multiple=="multiple") nomcamp.options.add(nou_camp);
			else
			{
				nomcamp.remove(0);
				nomcamp.options.add(nou_camp);
			}
		}
	}
}

// FITXERS LLISTAT ---------------------------------------------------------


// Selección de los desplegables de imágenes y ficheros, todos los select-multiple
function seleccionaTots()
{
	camps = document.editor.length;

	for(var i=0;i<camps;i++)
	{
		if(document.editor[i].type=="select-multiple")
		{
			if(document.editor[i].getAttribute("seleccionaTot"))
			{
				for(var j=0;j<document.editor[i].length;j++)
				{
					nom = document.getElementById(document.editor[i].id);
					nom.options[j].selected=true;
				}
			}
		}
	}
}


// Obrir finestra amb la imatge exacte
function PopupPic(sPicURL,path)
{ 
	window.open(path+"popup.htm?"+sPicURL, "", "resizable=1,HEIGHT=200,WIDTH=200");
}
