var ie = (document.all) ? true : false;
var ie6 = (navigator.appVersion.indexOf("MSIE 6.")==-1) ? false : true;
var nova = "nova-ombra", vella = "ombra-cont";

function marca_resize() {
  setStyleById("oculta1","background",1);
}

function ajusta_pantalla() {
  var b = document.getElementById("senyal").style["width"];
  var p = pageWidth(); 

  if (p < 783 && b!="1px") {
    setStyleById("senyal","width","1px");
    mostraLogoCurt();
    alliberaAmplada();
  } else if (p > 782 && p < 1201 && b!="2px") {
    setStyleById("senyal","width","2px");
    mostraLogoLlarg();
    alliberaAmplada();
  } else { // Fixar amplada
    if (p > 1200 && b!="3px") {
      setStyleById("senyal","width","3px");
      mostraLogoLlarg();
      fixaAmplada();
    }
  }
}


function ajusta_pantalla_intranet() {
    var b = document.getElementById("senyal").style["width"];
    var p = pageWidth();

    if (p < 1201 && b != "1px") {
      setStyleById("senyal", "width", "1px");
      alliberaAmplada_intranet();
    } else if (p > 1200 && b != "2px") {
      setStyleById("senyal", "width", "2px");
      fixaAmplada_intranet(94);
    }
}


function mostraLogoCurt() {
  setStyleById("logo_img","display","none");
  setStyleById("logo_curt","display","block");
  setStyleById("header1-right","width","75%");
  setStyleById("Body","margin","0em");
}

function mostraLogoLlarg() {
  setStyleById("logo_img","display","block");
  setStyleById("logo_curt","display","none");
  setStyleById("header1-right","width","55%");
  setStyleById("Body","margin","0em 2.5em");
}

function fixaAmplada() {
  if(ie6) {
    if (document.getElementById(nova) != null) {
      setStyleById(nova,"width","1200px");
      setStyleByClass("div","footer","width","1185px");
    } else setStyleById(vella,"width","1200px");

    var amplada = String((pageWidth()-1200)/2);
    setStyleById("Body","margin","0em "+amplada+"px");
  }
}

function alliberaAmplada() {
  if(ie6) {
    if (document.getElementById(nova) != null) {
      setStyleById(nova,"width","auto");
      setStyleByClass("div","footer","width","auto");
    } else setStyleById(vella,"width","auto");
  }
}

function fixaAmplada_intranet(a) {
  if (ie6) 
    setStyleById("Body", "margin", "0em " + String((100 - a) / 2) + "%");
  else 
    setStyleById("marc", "width", String(a) + "%"); 
}

function alliberaAmplada_intranet() {
  if (ie6) 
    setStyleById("Body", "margin", "0em  0em" );
  else
    setStyleById("marc", "width",  "100%");
}



// setStyleById: given an element id, style property and 
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
  var n = document.getElementById(i);
  n.style[p] = v;
}

// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value


function setStyleByClass(t,c,p,v){
  var elements;
  if(t == '*') {
    // '*' not supported by IE/Win 5.5 and below
    elements = (ie) ? document.all : document.getElementsByTagName('*');
  } else {
    elements = document.getElementsByTagName(t);
  }
  for(var i = 0; i < elements.length; i++){
    var node = elements.item(i);
    for(var j = 0; j < node.attributes.length; j++) {
      if(node.attributes.item(j).nodeName == 'class') {
        if(node.attributes.item(j).nodeValue == c) {
          eval('node.style.' + p + " = '" +v + "'");
        }
      }
    }
  }
}

function pageWidth() 
{return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;} function pageHeight() {return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;} function posLeft() {return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;} function posTop() {return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;} function posRight() {return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();}


function element(vid) {
  if (document.getElementById) {
    var obj = document.getElementById("eines");
  }  
  else if (document.all) {
    var obj = document.all("eines");
  }
  return obj;
}

