// JavaScript Document
function login() {
	f = document.forms[0];
	if (f.usuari.value=="soci@22network.net" && f.contrasenya.value=="22network") {
		document.location.href="socis/index.html";
	}
	else {
		alert("Dades d'accés no vàlides");
		f.usuari.value="";
		f.contrasenya.value="";
		return false;
	}
}

//	* checkbox: En cas que hi hagin varies caselles de checkbox, hi ha d'haver alguna de marcada. Crida: nomcamp[]|Nom|checkbox
//	* checkbox2: En cas que només hi hagi una casella de checkbox, esta o no marcada. Crida: nomcamp|Nom|checkbox2


function validate_submit() {
	var form_name = validate_submit.arguments[0];
	var str = "";
	for (var i = 1;i<validate_submit.arguments.length;i++) {
		var temp = validate_submit.arguments[i].split("|");
		//alert(""+temp);
		var tipo = temp[2];
		var nom = temp[0];
		var descr = temp[1];
		var nom_alternatiu = "";
		if (nom.indexOf("$") >0) {
			temp = nom.split("$");
			nom = temp[0];
			nom_alternatiu = temp[1];
		}
		switch (tipo) {
			case "text":
				ok = eval("document."+form_name+"."+nom+".value!=''");
				if (!ok && nom_alternatiu.length>0) {ok = eval("document."+form_name+"."+nom_alternatiu+".value!=''");}
			break;
			case "textarea": ok = eval("document."+form_name+"."+nom+".value!=''");
			break;
			case "radio":
				ok=false;
				for(var j=0;!ok && j<eval("document."+form_name+"."+nom+".length");j++){
				ok = eval("document."+form_name+"."+nom+"["+j+"].checked!=false");
				//if (!ok && nom_alternatiu.length>0) ok = eval("ok || ("+form_name+"."+nom_alternatiu+".value!='')");
				}
			break;
			case "checkbox":
				var j=1;
				do{
					n=nom+j;	//campX[]+num
					//alert(""+n);
					var msg = document.getElementById(n);
					ok = (msg!=null && msg.checked!=false);
					j++;
				}while(!ok && msg!=null)
			break;
			case "checkbox2":
				var msg = document.getElementById(nom);
				ok = (msg!=null && msg.checked!=false);
			break;
			default:
		}
		if (!ok) {if (str.length==0){str =descr} else if(str.indexOf(","+descr)<0){str +=","+descr}}
	}
	if (str.length>0) {alert("Has d'entrar algun valor a les següents preguntes: "+str)} else eval("document."+form_name+".submit();");
	return false;
}

function validate_not_submit() {
	var form_name = validate_not_submit.arguments[0];
	var str = "";
	for (var i = 1;i<validate_not_submit.arguments.length;i++) {
		var temp = validate_not_submit.arguments[i].split("|");
		//alert(""+temp);
		var tipo = temp[2];
		var nom = temp[0];
		var descr = temp[1];
		var nom_alternatiu = "";
		if (nom.indexOf("$") >0) {
			temp = nom.split("$");
			nom = temp[0];
			nom_alternatiu = temp[1];
		}
		switch (tipo) {
			case "text":
				ok = eval("document."+form_name+"."+nom+".value!=''");
				if (!ok && nom_alternatiu.length>0) ok = eval("ok || ("+form_name+"."+nom_alternatiu+".value!='')");
			break;
			case "textarea": ok = eval("document."+form_name+"."+nom+".value!=''");
			break;
			case "radio":
				ok=false;
				for(var j=0;!ok && j<eval("document."+form_name+"."+nom+".length");j++){
				ok = eval("document."+form_name+"."+nom+"["+j+"].checked!=false");
				//if (!ok && nom_alternatiu.length>0) ok = eval("ok || ("+form_name+"."+nom_alternatiu+".value!='')");
				}
			break;
			case "checkbox":
				var j=1;
				do{
					n=nom+j;	//campX[]+num
					//alert(""+n);
					var msg = document.getElementById(n);
					ok = (msg!=null && msg.checked!=false);
					j++;
				}while(!ok && msg!=null)
			break;
			case "checkbox2":
				var msg = document.getElementById(nom);
				ok = (msg!=null && msg.checked!=false);
			break;
			default:
		}
		if (!ok) {if (str.length==0){str =descr} else if(str.indexOf(","+descr)<0){str +=","+descr}}
	}
	if (str.length>0) {alert("Has d'entrar algun valor a les següents preguntes: "+str);return false} else return true;
}

function formatFecha(valor) {
	var str=valor;
	
	if(str.indexOf(":")>0){		//Conte el caracter :
		fecha=str.split(":");			//Splita en 2 parts
		var hora=fecha[0];
		var minuts=fecha[1];
		if((parseInt(hora)>=24) || (isNaN(parseInt(hora)))) { alert("Hora incorrecte: "+hora); }
		if((parseInt(minuts)>=60) || (minuts.length!=2) || (isNaN(parseInt(minuts)))) { alert("Minuts incorrectes: "+minuts); }
		if(hora.length!=2) {
			var zero="0"
			hora.concat(zero)
		}
	}
	else	{ if (str!="") alert("Format HH:MM"); }
}
// xScrollTop r4, Copyright 2001-2009 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xScrollTop(e, bWin)
{
  var w, offset=0;
  if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
    w = window;
    if (bWin && e) w = e;
    if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
    else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
  }
  else {
    e = xGetElementById(e);
    if (e && xNum(e.scrollTop)) offset = e.scrollTop;
  }
  return offset;
}

// xGetElementById r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xGetElementById(e)
{
  if(typeof(e)=='string') {
    if(document.getElementById) e=document.getElementById(e);
    else if(document.all) e=document.all[e];
    else e=null;
  }
  return e;
}

// xNum r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xNum()
{
  for(var i=0; i<arguments.length; ++i){if(isNaN(arguments[i]) || typeof(arguments[i])!='number') return false;}
  return true;
}

// xDef r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}


// xTop r2, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xTop(e, iY)
{
  if(!(e=xGetElementById(e))) return 0;
  var css=xDef(e.style);
  if(css && xStr(e.style.top)) {
    if(xNum(iY)) e.style.top=iY+'px';
    else {
      iY=parseInt(e.style.top);
      if(isNaN(iY)) iY=xGetComputedStyle(e,'top',1);
      if(isNaN(iY)) iY=0;
    }
  
  }
  else if(css && xDef(e.style.pixelTop)) {
    if(xNum(iY)) e.style.pixelTop=iY;
    else iY=e.style.pixelTop;
  }
  return iY;
}

// xGetComputedStyle r7, Copyright 2002-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xGetComputedStyle(e, p, i)
{
  if(!(e=xGetElementById(e))) return null;
  var s, v = 'undefined', dv = document.defaultView;
  if(dv && dv.getComputedStyle){
    s = dv.getComputedStyle(e,'');
    if (s) v = s.getPropertyValue(p);
  }
  else if(e.currentStyle) {
    v = e.currentStyle[xCamelize(p)];
  }
  else return null;
  return i ? (parseInt(v) || 0) : v;
}

// xCamelize r1, Copyright 2007-2009 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xCamelize(cssPropStr)
{
  var i, c, a, s;
  a = cssPropStr.split('-');
  s = a[0];
  for (i=1; i<a.length; ++i) {
    c = a[i].charAt(0);
    s += a[i].replace(c, c.toUpperCase());
  }
  return s;
}


// xStr r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xStr(s)
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])!='string') return false;}
  return true;
}

// xOffsetTop r1, Copyright 2001-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xOffsetTop(e)
{
  if (!(e=xGetElementById(e))) return 0;
  if (xDef(e.offsetTop)) return e.offsetTop;
  else return 0;
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function showhide(layer_ref) {
	obj = MM_findObj(layer_ref);
	loading_state = obj.style.visibility;
	if (loading_state == 'visible') {
		loading_state = 'hidden';
	}
	else {
		loading_state = 'visible';
	}
	if (document.all) { //IS IE 4 or 5 (or 6 beta)
		eval( "document.all." + layer_ref + ".style.visibility = loading_state");
		
	}
	if (document.layers) { //IS NETSCAPE 4 or below
		document.layers[layer_ref].visibility = loading_state;
	}
	if (document.getElementById && !document.all) {
		maxwell_smart = document.getElementById(layer_ref);
		maxwell_smart.style.visibility = loading_state;
	}
	//xTop(layer_ref,xOffsetTop(layer_ref)+document.documentElement.scrollTop);


}