function inicialitzacio()
{
	setStatus('');
}

function setStatus(ds){	
	defaultStatus = ds;
	tiempo = setInterval('defaultStatus = "' + ds + '"',500);	
}

function showhide_block(img, panel, image1, image2)
{
	if (panel.style.display == 'none') {
		panel.style.display = '';
		img.src = image2;
	}
	else 
	{
		panel.style.display = 'none';
		img.src = image1;
	}
}

function listIDArray(list)
{
	var i, strOut;
	strOut = "";
	
	if (list == null) {
		return strOut;
	}
	for (i = 0; i < list.length; i++)
	{
		if (list.options[i].selected == true)
		{
			if (list.options[i].value != "--$--")
			{
				if (strOut == "")
				{	
					strOut += list.options[i].value;
				}
				else
				{
					strOut += "," + list.options[i].value;
				}
			}
		}
	}
	return strOut;
}


function listIDStringArray(list)
{
	var i, strOut;
	strOut = "";
	
	if (list == null) {
		return strOut;
	}
	for (i = 0; i < list.length; i++)
	{
		if (list.options[i].selected == true)
		{
			if (strOut == "")
			{	
				strOut += "'" + list.options[i].value + "'";
			}
			else
			{
				strOut += ",'" + list.options[i].value + "'";
			}
		}
	}
	return strOut;
}

function listIDAllArray(list)
{
	var i, strOut;
	strOut = "";
	
	if (list == null) {
		return strOut;
	}
	for (i = 0; i < list.length; i++)
	{
		if (strOut == "")
		{	
			strOut += list.options[i].value;
		}
		else
		{
			strOut += "," + list.options[i].value;
		}
	}
	return strOut;
}

function alignObj(num)
  {
  // align object to positions 1-9, representing
  /*********************
  * 1       2        3 *
  *                    *
  * 4       5        6 *
  *                    *
  * 7       8        9 *
  *********************/
  this.hide();
  
  // define some variables
  if(isDOM) docHeight = document.getElementsByTagName("html").item(0).offsetHeight;
  else if(isIE4 || isIE5) var docHeight = document.body.clientHeight;
  else if(isNav4) var docHeight = window.innerHeight;

  if(isDOM) docWidth = document.getElementsByTagName("html").item(0).offsetWidth;
  else if(isIE4 || isIE5) var docWidth = document.body.clientWidth;
  else if(isNav4) var docWidth = window.innerWidth;

  // make adjustments for browser quirks determined through experimentation
  if(isGecko) { docWidth -= 3; docHeight -= 3; }
  else if(isIE6) { docWidth -= 23; docHeight -= 5; }
  else if(isIE4) docHeight -= 21;
  
  var x = 0; 
  var y = 0;

  switch(num)
  {
    case 1:
      // top-left -- don't do anything, x and y = 0
    break;
    case 2:
      // top-middle, y=0
      x = Math.round(docWidth/2 - this.w/2);
    break;
    case 3:
      // top-right, y=0
      x = docWidth - this.w;
    break;
    case 4:
      // middle-left, x=0
      y = Math.round(docHeight/2 - this.h/2);
    break;
    case 5:
      // middle-center
      x = Math.round(docWidth/2 - this.w/2);
      y = Math.round(docHeight/2 - this.h/2);
    break;
    case 6:
      // middle-right
      x = docWidth - this.w;
      y = Math.round(docHeight/2 - this.h/2);
    break;
    case 7:
      // bottom-left, x=0
      y = docHeight - this.h;
    break;
    case 8:
      // bottom-middle
      x = Math.round(docWidth/2 - this.w/2);
      y = docHeight - this.h;
    break;
    case 9:
      // bottom-right
      x = docWidth - this.w;
      y = docHeight - this.h;
    break;
    default:
      // user has inappropriately called the function
      alert("To use the align() function, you must provide a numerical\nvalue between 1 and 9, representing the position in the\nwindow to which the object will be moved.");
      this.show();
      return;
      break;
  }
  this.moveTo(x, y);
  this.show();
  }

function mostrar_noticia(elem)
{
	var x = document.getElementsByTagName('div');
	var div_noticia_trobats = 0;
	var noticia_actual;
	var str;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].className == 'noticia')
		{
			div_noticia_trobats++;
			noticia_actual = div_noticia_trobats / 2;
			if (div_noticia_trobats == elem)
			{
				x[i].style.display = 'inline';
			}
			else
			{
				x[i].style.display = 'none';
			}
		}
	}
}

function img_resize(amplada_max, alcada_max, codi_elem) {
	img_resize(amplada_max, alcada_max, codi_elem, 0, 0, 0);
}

function img_resize(amplada_max_1, alcada_max_1, codi_elem_1, amplada_max_2, alcada_max_2, codi_elem_2) {
	img_resize(amplada_max_1, alcada_max_1, codi_elem_1, amplada_max_2, alcada_max_2, codi_elem_2, 0, 0, 0)
}

function img_resize(amplada_max_1, alcada_max_1, codi_elem_1, amplada_max_2, alcada_max_2, codi_elem_2, amplada_max_3, alcada_max_3, codi_elem_3) {
	prog = "img_resize_retardat(" + amplada_max_1 + ", " + alcada_max_1 + ", " + codi_elem_1 + ", " + amplada_max_2 + ", " + alcada_max_2 + ", " + codi_elem_2 + ", " + amplada_max_3 + ", " + alcada_max_3 + ", " + codi_elem_3 + ")";
	setTimeout(prog, 5);
}
//************************************************************************************************
function img_resize_retardat(amplada_max_1, alcada_max_1, codi_elem_1, amplada_max_2, alcada_max_2, codi_elem_2, amplada_max_3, alcada_max_3, codi_elem_3) {
	if ((amplada_max_1 > 1) && (alcada_max_1 > 1))
		ajustar_dimensions(amplada_max_1, alcada_max_1, codi_elem_1);
	if ((amplada_max_2 > 1) && (alcada_max_2 > 1))
		ajustar_dimensions(amplada_max_2, alcada_max_2, codi_elem_2);
	if ((amplada_max_3 > 1) && (alcada_max_3 > 1))
		ajustar_dimensions(amplada_max_3, alcada_max_3, codi_elem_3);
}

function ajustar_dimensions(amplada_max, alcada_max, codi_elem) {
	var elem = "";
	if (codi_elem == 1) elem = "imgLogo";
	if (codi_elem == 2) elem = "imgImatge";
	if (codi_elem == 3) elem = "imgProducte";
	if (codi_elem == 4) elem = "imgReferencia";
	
	ajustar_dimensions_elem(amplada_max, alcada_max, elem);
}

function ajustar_dimensions_elem(amplada_max, alcada_max, elem) {
	var factor_reduccio_amplada = 0;
	var factor_reduccio_alcada = 0;
	
	//pillem les dimensions actuals de les imatges
	amplada = eval("document.Form1." + elem + ".width");
	alcada = eval("document.Form1." + elem + ".height");

	if ((amplada > amplada_max) || (alcada > alcada_max)) {
		factor_reduccio_amplada = amplada / amplada_max;
		factor_reduccio_alcada = alcada / alcada_max;
		
		//apliquem el valor màxim en la dimensió on haguem obtingut el factor de reducció més gran. L'altra dimensió farà un resize automàtic, però segur q serà més petit q el seu màxim valor permès
		if (factor_reduccio_amplada > factor_reduccio_alcada)
			eval("document.Form1." + elem + ".width = amplada_max");
		else
			eval("document.Form1." + elem + ".height = alcada_max");
	}
}

function img_resize_num_elems(amplada_max, alcada_max, numElems) {
	step = 0;
	while (step < numElems) {
		num_elem = step + 2;
		elem = "dbgLlistaModificacions__ctl" + num_elem + "_Image";
		ajustar_dimensions_elem(amplada_max, alcada_max, elem);
		step++;
	}
}

/********************************************************************************************************/
/***   FUNCIONS PER AL CHECKBOX DE "TOTES LES OPCIONS"   ************************************************/
/********************************************************************************************************/
function checkClicat(elem_clicat, id_totes, id_elems, num_elems) {
	if (elem_clicat == id_totes) { //s'ha clicat la opció totes
		totes = document.getElementById(id_totes);
		for (step = 0; step < num_elems; step++) {
			id_elem = id_elems + "_" + step;
			objecte = document.getElementById(id_elem);
			objecte.checked = false;
		}
		totes.checked = true;
	} else {//s'ha clicat un element
		var count = 0;
		for (step = 0; step < num_elems; step++) {
			if (eval("document.Form1." + id_elems + "_" + step + ".checked == true"))
				count++;
		}
		if (count == 0)
			eval("document.Form1." + id_totes + ".checked = true");
		else
			eval("document.Form1." + id_totes + ".checked = false");
	}
}