function inArray(elarray, value) {
	var i;
	for (i=0; i < elarray.length; i++) {
		if (elarray[i] === value) {
			return true;
		}
	}
	return false;
};


function replacehtml(el, html) {
	var oldEl = typeof el === "string" ? document.getElementById(el) : el;
	/*@cc_on // Pure innerHTML is slightly faster in IE
		oldEl.innerHTML = html;
		return oldEl;
	@*/
	var newEl = oldEl.cloneNode(false);
	newEl.innerHTML = html;
	oldEl.parentNode.replaceChild(newEl, oldEl);
	/* Since we just removed the old element from the DOM, return a reference
	to the new element, which can be used to restore variable references. */
	return newEl;
};

function permissions_install(elcheck, agrupador){
	
	var divs = document.getElementsByTagName('div');
	for(i=0;i<divs.length;i++){
			if(divs[i].id.match("_"+agrupador) ){ //if they are 'see' divs
			
				//OCULTAR SI ESTA VISIBLE						
				if (document.getElementById)
					if(divs[i].style.display=="" )
						divs[i].style.display='none';
					else
						divs[i].style.display='';
				else
					if (document.layers) // Netscape 4
						document.layers[divs[i]].style.display = '';
					else // IE 4
						document.all.hideShow.divs[i].style.display = '';				
			}
	}		


	/* AHORA CAMBIO EL VALOR DEL CAMPO OCULTO */
	var l = document.getElementById(agrupador);
	if(l.value==1){
		l.value = 0;
	}else{
		l.value=1;
	}



}


function imagesize(ancho, alto){
 	document.images["slideshow"].width=ancho;
 	document.images["slideshow"].height=alto;

}
function sethref(elid, elurl){
	
 	var l = document.getElementById(elid);
 	l.setAttribute("href",elurl);
}

function checkAll_share(form, num) {

	box_all = eval("document."+form+".to_all");
	if (box_all.checked == false){
		for (var j = 0; j <= num; j++) {
		
			box = eval("document."+form+".share" + j);
			
			if (box.checked == true) box.checked = false;
	   }
	}else{
		for (var j = 0; j <= num; j++) {
			box = eval("document."+form+".share" + j);
			if (box.checked == false) box.checked = true;
		}
	}
}

function showmedios(elurl){
	document.images["slideshow"].src = elurl;
}

function setmediosinfo(title, desc){

	var titid = document.getElementById("medios_title");
	var descid = document.getElementById("medios_desc");

	titid.innerHTML=title;	
	descid.innerHTML=desc;

	//tit.appendChild(document.createTextNode(title));
	//desc.appendChild(document.createTextNode(desc));
	//alert(title+" "+desc);	

}

function ChangeColor(tableRow, bgcolor){


      tableRow.style.backgroundColor = bgcolor;

}

function showdiv(pass) {
	
	var divs = document.getElementsByTagName('div');
	for(i=0;i<divs.length;i++){					
			if(divs[i].id.match(pass) ){//if they are 'see' divs
			
				if (document.getElementById)
					if(divs[i].style.display=="" )
						divs[i].style.display='none';
					else
						divs[i].style.display='';
				else
					if (document.layers) // Netscape 4
						document.layers[divs[i]].style.display = '';
					else // IE 4
						document.all.hideShow.divs[i].style.display = '';														
			}
		
	}
}

function hidediv(pass) {
	
	var divs = document.getElementsByTagName('div');
	for(i=0;i<divs.length;i++){
						
			if(divs[i].id.match(pass) ){//if they are 'see' divs
											
				if (document.getElementById)
					if(divs[i].style.display=="")
						divs[i].style.display='none';
					
				else
					if (document.layers) // Netscape 4
						document.layers[divs[i]].style.display = 'none';
					else // IE 4
						document.all.hideShow.divs[i].style.display = 'none';							
			}
		
	}
}

function showcomentarios(pass) {
	
	var divs = document.getElementsByTagName('div');

	for(i=0;i<divs.length;i++){
			if(divs[i].id.match(pass) ){ //if they are 'see' divs
				//alert(i+"SHOWING "+divs[i].id);
				if (document.getElementById)					
						divs[i].style.display='';
				else
					if (document.layers) // Netscape 4
						document.layers[divs[i]].style.display = '';
					else // IE 4
						document.all.hideShow.divs[i].style.display = '';					
			}else{				
				s1 = new String(divs[i].id);
				if(s1.search('FORO')>=0){
				//	alert(i+"HIDING "+divs[i].id);
							divs[i].style.display='none';		
				}
			}
	}
}

function showhide(pass, hiders) {
	var divs = document.getElementsByTagName('div');

	for(i=0;i<divs.length;i++){
			if(divs[i].id.match(pass) ){ //if they are 'see' divs
			
				//OCULTAR SI ESTA VISIBLE
				
			
				if (document.getElementById)
					if(divs[i].style.display==""  && pass!="-1")
						divs[i].style.display='none';
					else
						divs[i].style.display='';
				else
					if (document.layers) // Netscape 4
						document.layers[divs[i]].style.display = '';
					else // IE 4
						document.all.hideShow.divs[i].style.display = '';				
			}else{				
				s1 = new String(divs[i].id);
				if(s1.search(hiders)>=0){
							divs[i].style.display='none';		
				}
			}
	}
}

function showcontrol(pass) {

	
	var divs = document.getElementsByTagName('div');

	for(i=0;i<divs.length;i++){
			if(divs[i].id.match(pass) ){ //if they are 'see' divs
				//alert(i+"SHOWING "+divs[i].id);
				if (document.getElementById)					
						divs[i].style.display='';
				else
					if (document.layers) // Netscape 4
						document.layers[divs[i]].style.display = '';
					else // IE 4
						document.all.hideShow.divs[i].style.display = '';					
			}else{				
				s1 = new String(divs[i].id);
				if(s1.search('SLIDESHOW')>=0){
					//alert(i+"HIDING "+divs[i].id);
							divs[i].style.display='none';		
				}
			}
	}
}

function hidecontrols() {

	
	var divs = document.getElementsByTagName('div');

	for(i=0;i<divs.length;i++){

				s1 = new String(divs[i].id);
				if(s1.search('SLIDESHOW')>=0){
							divs[i].style.display='none';		
				}

	}
}



function togglediv(pass) {
	
	var divs = document.getElementsByTagName('div');
	for(i=0;i<divs.length;i++){

		if( ((divs[i].id.toString()).substring(0,2))==("id")){			
			
			
			
			if(divs[i].id.match(pass) || pass=="-1"){//if they are 'see' divs
			

			
			
			
				if (document.getElementById)
					if(divs[i].style.display==""  && pass!="-1")
						divs[i].style.display='none';
					else
						divs[i].style.display='';
				else
					if (document.layers) // Netscape 4
						document.layers[divs[i]].style.display = '';
					else // IE 4
						document.all.hideShow.divs[i].style.display = '';
				

			}else if(divs[i].id!="id0"){					

				if (document.getElementById) // DOM3 = IE5, NS6
					divs[i].style.display="none";// show/hide
				else
					if (document.layers) // Netscape 4
						document.layers[divs[i]].style.display = 'none';
					else // IE 4
						document.all.hideShow.divs[i].style.display = 'none';



			}
		}
	}
}

function submitform(theForm){	
	  theForm.submit();
}


function enter(entry){
      var e = document.getElementById('entry');
      e.value = entry;

      var f = document.getElementById('entry_form');

	 f.submit();


      return false;
}



function new_galeria()
{
  if (document.getElementById('nombreGaleria').style.visibility=='hidden'){
    document.getElementById('nombreGaleria').style.visibility = 'visible';
    document.getElementById('descGaleria').style.visibility = 'visible';
    document.getElementById('urlGaleria').style.visibility = 'visible';
    document.getElementById('listFolder').style.visibility = 'visible';
    document.getElementById('botonGaleria').style.visibility = 'visible';
  }else{
    document.getElementById('nombreGaleria').style.visibility = 'hidden';
    document.getElementById('descGaleria').style.visibility = 'hidden';
    document.getElementById('urlGaleria').style.visibility = 'hidden';
    document.getElementById('listFolder').style.visibility = 'hidden';
    document.getElementById('botonGaleria').style.visibility = 'hidden';
  }
}
var upload_miLastID = 0; //default of input element already written

function displayFlash(path, width, height)
{
	document.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedios.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,22,0" WIDTH="' + width);
	document.write('" HEIGHT="' + height + '" id="FlashContent">');
	document.write('<PARAM NAME="movie" VALUE="' + path + '"><PARAM NAME="quality" VALUE="high">');
	document.write('<PARAM NAME="AllowScriptAccess" VALUE="never"><EMBED src="' + path + '"');
	document.write(' quality="high" WIDTH="' + width + '" HEIGHT="' + height + '" NAME="FlashContent"');
	document.write(' AllowScriptAccess="never" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedios.com/go/getflashplayer">');
	document.write('</EMBED></OBJECT>');
}


//VALIDADORES DE LA FORMA DE REMIND PASSWORD
function pass_FormValidator(theForm)
{

  if (theForm.pass1.value == "" || theForm.pass2.value == ""){
    alert("PASSWORD MISSING.");
    theForm.pass1.focus();
    return (false);
  }

  if (theForm.pass1.value != theForm.pass2.value){

    alert("PASSWORDS DO NOT MATCH.");
    theForm.pass1.focus();
    return (false);
  }
}

function clickclear(thisfield, defaulttext) {
  if (thisfield.value == defaulttext) {
    thisfield.value = "";
  }
}

function clickrecall(thisfield, defaulttext) {
  if (thisfield.value == "") {
    thisfield.value = defaulttext;
  }
}

function insertAfter(newElement,targetElement) {
  var parent = targetElement.parentNode;
  if (parent.lastChild == targetElement) {
    parent.appendChild(newElement);
  } else {
    parent.insertBefore(newElement,targetElement.nextSibling);
  }
}
function clickclear(thisfield, defaulttext) {
  if (thisfield.value == defaulttext) {
    thisfield.value = "";
  }
}

function clickrecall(thisfield, defaulttext) {
  if (thisfield.value == "") {
    thisfield.value = defaulttext;
  }
}


function nuevoFolder_list(){
	var mylist=document.getElementById("listFolder")
	document.getElementById("queFolder").value=document.getElementById("listFolder").value
	if(document.getElementById("listFolder").value=="carpeta nueva"){		
		document.getElementById("listFolder").disabled=true;
		document.getElementById("queFolder").value="Nombre de la carpeta";
		document.getElementById("listFolder").style.visibility = 'hidden';
		document.getElementById("queFolder").style.visibility = 'visible';
	}

}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
		alert("Max "+maxlimit+" chars.");
	}else{
		countfield.value = maxlimit - field.value.length;

	}
}

function isEmailAddr(email){
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0){
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
        result = true;
  }
  return result;
}

function setup_FormValidator(theForm){

  if (theForm.nombre.value == ""){
    alert("NAME MISSING.");
    theForm.nombre.focus();
    return (false);
  }
  if (theForm.url.value == ""){
    alert("URL MISSING.");
    theForm.url.focus();
    return (false);
  }  
  if (theForm.email_moderador.value == ""){
    alert("EMAIL MISSING.");
    theForm.email_moderador.focus();
    return (false);
  }
  if (theForm.lang.value == ""){
    alert("LANGUAGE MISSING.");
    theForm.lang.focus();
    return (false);
  }
  if (theForm.max_width.value == ""){
    alert("MAX WIDTH MISSING.");
    theForm.max_width.focus();
    return (false);
  }
  if (theForm.tipo.value == ""){
    alert("TYPE MISSING.");
    theForm.tipo.focus();
    return (false);
  }
}


function FormValidator(theForm){
  if (theForm.name_pag.value == ""){
    alert("NAME MISSING.");
    theForm.name_pag.focus();
    return (false);
  }
  
  if(theForm.tipo_pag.value == "evento"){
  
  
	  if (theForm.fecha_ini_year.value == "0000" || theForm.fecha_ini_month.value == "00" || theForm.fecha_ini_day.value == "00" ){
	    alert("START DATE MISSING.");
	    theForm.fecha_ini_day.focus();
	    return (false);
	  }    
	  if (theForm.fecha_fin_year.value == "0000" || theForm.fecha_fin_month.value == "00" || theForm.fecha_fin_day.value == "00" ){
	    alert("END DATE MISSING.");
	    theForm.fecha_fin_day.focus();
	    return (false);
	  }    
	  
	  var fecha_ini=new Date(theForm.fecha_ini_year.value, theForm.fecha_ini_month.value, theForm.fecha_ini_day.value, theForm.fecha_ini_hour.value, theForm.fecha_ini_minute.value, 00); 
	  var fecha_fin=new Date(theForm.fecha_fin_year.value, theForm.fecha_fin_month.value, theForm.fecha_fin_day.value, theForm.fecha_fin_hour.value, theForm.fecha_fin_minute.value, 00); 
	  
	  //FECHA FIN > FECHA INICIO
	  if (fecha_ini > fecha_fin) {
	    alert("END DATE HAS TO BE AFTER START DATE");
	    theForm.fecha_fin_day.focus();
	    return false;
	  }
	  
  }
  
  
  return (true);
}

//VALIDADORES DE LA FORMA DE COMENTAR
function comment_FormValidator(theForm)
{

  if (theForm.quien.value == ""){
    alert("NAME MISSING.");
    theForm.quien.focus();
    return (false);
  }

  if (theForm.comentario.value == ""){
    theForm.comentario.focus();
    return (false);
  }

}
//VALIDADORES DE LA FORMA DE REGISTRO0
function reg0_FormValidator(theForm)
{

  if (theForm.reg0_login.value == ""){
    alert("USERNAME MISSING.");
    theForm.reg0_login.focus();
    return (false);
  }

  if (theForm.reg0_pass1.value == ""){
    alert("PASSWORD MISSING");
    theForm.reg0_pass1.focus();
    return (false);
  }

}
//VALIDADORES DE LA FORMA DE NUEVO GRUPO
function newgrupo_FormValidator(theForm)
{

  if (theForm.nombreGrupo.value == ""){
    alert("GROUP NAME MISSING.");
    theForm.nombreGrupo.focus();
    return (false);
  }
  if (theForm.urlGrupo.value == ""){
    alert("URL MISSING.");
    theForm.urlGrupo.focus();
    return (false);
  }

}
//VALIDADORES DE LA FORMA DE EDITAR GRUPO
function editgrupo_FormValidator(theForm)
{

  if (theForm.nombreGrupo_edit.value == ""){
    alert("GROUP NAME MISSING.");
    theForm.nombreGrupo_edit.focus();
    return (false);
  }
  if (theForm.urlGrupo_edit.value == ""){
    alert("URL MISSING.");
    theForm.urlGrupo_edit.focus();
    return (false);
  }

}

//VALIDADORES DE LA FORMA DE CONTACTO
function contacto_FormValidator(theForm)
{

  if (theForm.nombre.value == ""){
    alert("NAME MISSING.");
    theForm.nombre.focus();
    return (false);
  }

  if (!isEmailAddr(theForm.contacto_email.value))
  {
    alert("EMAIL MISSING");
    theForm.contacto_email.focus();
    return (false);
  }
  return (true);
}

//VALIDADORES DE LA FORMA DE EMAIL
function email_FormValidator(theForm)
{

  if (!isEmailAddr(theForm.email_to.value))
  {
    alert("EMAIL MISSING");
    theForm.email_to.focus();
    return (false);
  }

  if (!isEmailAddr(theForm.email_from.value))
  {
    alert("EMAIL MISSING");
    theForm.email_from.focus();
    return (false);
  }
  return (true);
}


//VALIDADORES DE LA FORMA DE REGISTRO
function reg_FormValidator(theForm)
{	
  if (theForm.captcha_code.value=="")
  {
    alert("TYPE THE CHARACTERS IN THE PICTURE");
    theForm.captcha_code.focus();
    return (false);
  } 
  if (theForm.reg_login.value == ""){
    alert("USER NAME MISSING.");
    theForm.reg_login.focus();
    return (false);
  }

  if (theForm.reg_pass1.value == "" || theForm.reg_pass2.value == ""){
    alert("PASSWORD MISSING.");
    theForm.reg_pass1.focus();
    return (false);
  }

  if (theForm.reg_pass1.value != theForm.reg_pass2.value){

    alert("PASSWORDS DO NOT MATCH.");
    theForm.reg_pass1.focus();
    return (false);
  }

  if (theForm.reg_nombre.value == "")
  {
    alert("NAME MISSING.");
    theForm.reg_nombre.focus();
    return (false);
  }

  if (!isEmailAddr(theForm.reg_email1.value))
  {
    alert("VALID EMAIL MISSING");
    theForm.reg_email1.focus();
    return (false);
  }

  if (theForm.reg_email1.value.length < 3)
  {
    alert("VALID EMAIL MISSING");
    theForm.reg_email1.focus();
    return (false);
  }
  
 
}
//FORMA ARCHIVO
function file_FormValidator(theForm)
{


  if (theForm.listFolder.value == "0" ){
    alert("FOLDER MISSING.");
    theForm.listFolder.focus();
    return (false);
	

  }
  
  if (theForm.file_name.value == ""){
    alert("FILE NAME MISSING.");
    theForm.file_name.focus();
    return (false);
  }
  if (theForm.userfile.value == ""){
    alert("FILE MISSING.");
    theForm.userfile.focus();
    return (false);
  }
}

//FORMA medios
function photo_FormValidator(theForm)
{

  if (theForm.id_gal.value == "0"){
    alert("ALBUM MISSING.");
    theForm.id_gal.focus();
    return (false);
  }
  if (theForm.myfile0.value == ""){
    alert("PHOTO MISSING.");
    theForm.myfile0.focus();
    return (false);
  }
}

//FORMA NEW FOLDER
function folder_FormValidator(theForm)
{

  if (theForm.nombreFolder.value == ""){
    alert("FOLDER MISSING.");
    theForm.nombreFolder.focus();
    return (false);
  }
}

//FORMA NEW FOLDER
function curso_FormValidator(theForm)
{

  if (theForm.nombreCurso.value == ""){
    alert("COURSE NAME MISSING.");
    theForm.nombreCurso.focus();
    return (false);
  }
}


//FORMA EDITAR FOLDER
function edit_folder_FormValidator(theForm)
{

  if (theForm.folder_editar_nombre.value == ""){
    alert("FOLDER NAME MISSING.");
    theForm.folder_editar_nombre.focus();
    return (false);
  }
}

//FORMA NEW GALERIA
function galeria_FormValidator(theForm)
{

  if (theForm.nombreGaleria.value == "" || theForm.nombreGaleria.value == "nombre"){
    alert("ALBUM NAME MISSING.");
    theForm.nombreGaleria.focus();
    return (false);
  }
  
  if (theForm.queFolder.value == "Nombre de la carpeta"){
    alert("FOLDER NAME MISSING.");
    theForm.queFolder.focus();
    return (false);
  }  
}

//FORMA EDIT FOLDER
function edit_galeria_FormValidator(theForm)
{

  if (theForm.edit_nombreGaleria.value == ""){
    alert("ALBUM NAME MISSING.");
    theForm.edit_nombreGaleria.focus();
    return (false);
  }
}

//FORMA NEW GRUPO
function grupo_FormValidator(theForm)
{

  if (theForm.nombreGrupo.value == ""){
    alert("GROUP NAME MISSING.");
    theForm.nombreGrupo.focus();
    return (false);
  }
}

//FORMA NEW TEMA
function tema_FormValidator(theForm)
{

  if (theForm.titulo.value == ""){
    alert("TOPIC NAME MISSING.");
    theForm.titulo.focus();
    return (false);
  }
}


