// common.js Funciones comunes v2.1
// Modificado 19-05-2006

// showLayer(obj)
// hideLayer(obj)
// writeObjFlash (file, width, height, bgcolor, mode)
// findObj (obj, [document])
// checkEmail (string)
// preloadImages()
// getISODate (fecha)
// getISODate2 (dia, mes, anio)
// getISODate3 (dia, mes, anio)
// bisiesto(anyo)
// fecha_correcta (dia,mes,anyo)
// fechaES (fechaEN)
// fechaESCorta (fechaEN)
// Array.prototype.in_array 
// dynContentOuter(elementid,content)
// dynContentInner(elementid,content)
// wJs (file)
// OpenBrWindow (theURL,winName,features, myWidth, myHeight, isCenter)
// goBack ()

function showLayer (ly) { findObj(ly).style.visibility="visible"; }

function hideLayer (ly) { findObj(ly).style.visibility="hidden"; }

function writeObjFlash (file, width, height, bgcolor, mode, name) { document.write ("<OBJECT id='"+name+"' name='"+name + "' codeBase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0 height=" + height + " width=" + width + " classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000><PARAM NAME='FlashVars' VALUE=''><PARAM NAME='Movie' VALUE='" + file + "'><PARAM NAME='Src' VALUE='" + file + "'><PARAM NAME='WMode' VALUE='" + mode + "'><PARAM NAME='Play' VALUE='-1'><PARAM NAME='Loop' VALUE='-1'><PARAM NAME='Quality' VALUE='High'><PARAM NAME='SAlign' VALUE=''><PARAM NAME='Menu' VALUE='0'><PARAM NAME='Base' VALUE=''><PARAM NAME='AllowScriptAccess' VALUE='0'><PARAM NAME='Scale' VALUE='ShowAll'><PARAM NAME='DeviceFont' VALUE='0'><PARAM NAME='EmbedMovie' VALUE='0'><PARAM NAME='BGColor' VALUE='" + bgcolor +"'><PARAM NAME='SWRemote' VALUE=''><PARAM NAME='MovieData' VALUE=''><PARAM NAME='SeamlessTabbing' VALUE='1'><PARAM NAME='Profile' VALUE='0'><PARAM NAME='ProfileAddress' VALUE=''><PARAM NAME='ProfilePort' VALUE='0'><embed src='" + file + "' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='" + width + "' height='" + height +"'></embed></OBJECT>"); }

function findObj(n, d) { 
  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 checkEmail (e)
{
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	
	if (e.length==0) return -1;
	
	
	for(i=0; i < e.length ;i++)
	{
		if(ok.indexOf(e.charAt(i))<0)
		{ 
			return (false);
		}	
	} 

	if (document.images)
	{
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two))
		{
			return (-1);		
		} 
	}
}

function preloadImages()
{
	if(document.images)
	{
		if(!document.aPreLoad) document.aPreLoad=new Array();
		
		var i,j=document.aPreLoad.length,a=preloadImages.arguments;
		
		for(i=0; i<a.length; i++)
		{
			if (a[i].indexOf("#")!=0)
			{
				document.aPreLoad[j]=new Image;
				document.aPreLoad[j++].src=a[i];
			}
		}
	}
}

function getISODate (fecha)
{
	var isodate;
	
	d=fecha.getDate();
	mo=fecha.getMonth()+1;
	a=fecha.getYear();
	h=fecha.getHours();
	m=fecha.getMinutes();
	s=fecha.getSeconds();
	
	if (d<10) d="0"+d;
	if (mo<10) mo="0"+mo;
	if (h<10) h="0"+h;
	if (m<10) m="0"+m;
	if (s<10) s="0"+s;
	
	isodate = a + "" +  mo + "" + d + " " + h + ":" + m + ":" + s;	
	return isodate;	
}

function getISODate2 (dia, mes, anio)
{
	hoy = new Date();
	anioactual = hoy.getYear();
	
	if (dia<10) dia="0"+eval(dia);
	if (mes<10) mes="0"+eval(mes);
	if (anio<=(anioactual-2000)) anio=eval(anio)+2000;
		else {
			if (anio<100) anio=eval(anio)+1900;
			}
		
	return anio + "" + mes + "" + dia;
}

function getISODate3 (dia, mes, anio)
{
	hoy = new Date();
	anioactual = hoy.getYear();
	
	if (dia<10) dia="0"+eval(dia);
	if (mes<10) mes="0"+eval(mes);
	if (anio<=(anioactual-2000)) anio=eval(anio)+2000;
		else {
			if (anio<100) anio=eval(anio)+1900;
			}
		
	return anio + "-" + mes + "-" + dia;
}


function bisiesto(anyo) {
	if (((anyo % 4) == 0) && ((anyo % 1000)!=0)) return true;
	else return false;
}

function fecha_correcta(dia,mes,anyo) {
	if (anyo<20) anyo=eval(anyo)+2000;
	if (anyo>=20 && anyo<100) anyo=eval(anyo)+1900;

	if (anyo<1900 || anyo>2020) {
		return false;
	} else {
		if (dia>31 || dia<1 || mes<1 || mes>12) {
			return false;
		} else {
			if (mes==2) {
				if (dia>29) { 
					return false;
				} else {
					if (dia==29 && bisiesto(anyo)==false) return false;
					else return true;
				}	
			} else {
				if ((mes==4 || mes==6 || mes==9 || mes==11) && dia==31) return false;
				else return true;
			}
		}
	}
}

function fechaES (fechaEN)
{
	if (fechaEN=="") return "";
	var array_fecha = fechaEN.split("-");
	
	return array_fecha[2]+"/"+array_fecha[1]+"/"+array_fecha[0];
}

function fechaESCorta (fechaEN)
{
	if (fechaEN=="") return "";
	var array_fecha = fechaEN.split("-");
	
	return array_fecha[2]+"/"+array_fecha[1]+"/"+array_fecha[0].substring(2,4);
}

Array.prototype.in_array = function(search_term) {
  var i = this.length;
  if (i > 0) {
	 do {
	 
		if (this[i] === search_term) {
		   return true;
		}
	 } while (i--);
  }
  return false;
}

function dynContentOuter(elementid,content){
	if (document.getElementById && !document.all){
		rng = document.createRange();
		el = document.getElementById(elementid);
		rng.setStartBefore(el);
		htmlFrag = rng.createContextualFragment(content);
		while (el.hasChildNodes())
		el.removeChild(el.lastChild);
		el.appendChild(htmlFrag);
	}
	else
		findObj(elementid).outerHTML=content;
}

function dynContentInner(elementid,content){
	if (document.getElementById && !document.all){
		rng = document.createRange();
		el = document.getElementById(elementid);
		rng.setStartBefore(el);
		htmlFrag = rng.createContextualFragment(content);
		while (el.hasChildNodes())
		el.removeChild(el.lastChild);
		el.appendChild(htmlFrag);
	}
	else
		findObj(elementid).innerHTML=content;
}

function wJs (src){
	return "<script type='text/javascript' language='javascript1.2' src='"+src+"'"+"></script>";
}

function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { //v3.0
	if(window.screen)if(isCenter)if(isCenter=="true"){
	var myLeft = (screen.width-myWidth)/2;
	var myTop = (screen.height-myHeight)/2;
	features+=(features!='')?',':'';
	features+=',left='+myLeft+',top='+myTop;
	}
	window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

function goBack ()
{
	window.history.back();
	return false;
}