/***** funcion TRIM agregada al objeto String *****/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
/*************************************************/

function vChat(){
window.open('chateo/', 'Chat', 'toolbar=0,location=1,scrollbars=0,menubar=0,resizable=0,width=680,height=490');
}

function cambiavalor(obj){
   if (obj.value=='0')
      obj.value='1';
   else
      obj.value='0';
}

function verfotos1(){
   document.getElementById('cajadirec').style.display = 'none';
   document.getElementById('fotosdjp').style.display = 'block';
}

function verfotos2(){
   document.getElementById('fotosdjp').style.display = 'none';
   document.getElementById('cajadirec').style.display = 'block';
}

function abrirBiografia(idn){
window.open('ver.php?i=3&idn='+idn, 'biografia'+idn, 'toolbar=0,location=1,scrollbars=1,menubar=0,resizable=1,width=680,height=490');
}

function abrirEvento(idn){
window.open('ver.php?i=2&idn='+idn, 'Evento'+idn, 'toolbar=0,location=1,scrollbars=1,menubar=0,resizable=1,width=680,height=490');
}

function abrirNoticia(idn){
window.open('ver.php?i=1&idn='+idn, 'Noticia'+idn, 'toolbar=0,location=1,scrollbars=1,menubar=0,resizable=1,width=680,height=490');
}

var winfotos;
function vGaleria(){
   var ancho = 160;
   if (document.body.clientWidth > 757)
      ancho = Math.round((document.body.clientWidth - 757) / 2) + 25;
   if (winfotos != null)
      winfotos.destroy();
   winfotos = new Window(Application.getNewId(), {className: 'Alphacube' , title: 'Galeria Imagenes de DJ Club Magazine', 
                 zIndex:1030, top:142, left:ancho, width:700, height: 408, minimizable: false, maximizable: false, closable: true, draggable: false, 
                 resizable: true, url:'galerias.php', showEffectOptions: {duration:1}})
   winfotos.toFront();
   winfotos.show();
}

var winnoticias;
function vNoticias(){
   var ancho = 160;
   if (document.body.clientWidth > 757)
      ancho = Math.round((document.body.clientWidth - 757) / 2) + 25;
   if (winnoticias != null)
      winnoticias.destroy();
   winnoticias = new Window(Application.getNewId(), {className: 'Alphacube' , title: 'Noticias DJ Club Magazine', 
                 zIndex:1030, top:142, left:ancho, width:700, height: 408, minimizable: false, maximizable: false, closable: true, draggable: false, 
                 resizable: true, url:'noticias.php', showEffectOptions: {duration:1}})
   winnoticias.toFront();
   winnoticias.show();
}

var wineventos;
function vEventos(){
   var ancho = 160;
   if (document.body.clientWidth > 757)
      ancho = Math.round((document.body.clientWidth - 757) / 2) + 35;
   if (wineventos != null)
      wineventos.destroy();
   wineventos = new Window(Application.getNewId(), {className: 'alphacube', title: 'Lista de Eventos', 
                 zIndex:1020, top:142, left:ancho, width:700, height: 408, minimizable: false, maximizable: false, closable: true, draggable: false, 
                 resizable: true, url:'eventos.php', showEffectOptions: {duration:1}})
   wineventos.toFront();
   wineventos.show();
}

var wincontacto;
function vContacto(){
   var ancho = 160;
   if (document.body.clientWidth > 757)
      ancho = Math.round((document.body.clientWidth - 757) / 2) + 30;
   if (wincontacto != null)
      wincontacto.destroy();
   wincontacto = new Window(Application.getNewId(), {className: 'alphacube', title: 'Informacion para Contactarnos', 
                    zIndex:1010, top:285, left:ancho, width:700, height: 265, minimizable: false, maximizable: false, draggable: false, 
                 resizable: true, url:'contacto.html', showEffectOptions: {duration:1}});
   wincontacto.toFront();
   wincontacto.show();
}

var winbooking;
function vBooking(){
   var ancho = 160;
   if (document.body.clientWidth > 757)
      ancho = Math.round((document.body.clientWidth - 757) / 2) + 30;
   if (winbooking != null)
      winbooking.destroy();
   winbooking = new Window(Application.getNewId(), {className: 'alphacube', title: 'Booking Dj ClubMagazine Radio Intercontinental', 
                    zIndex:1010, top:285, left:ancho, width:700, height: 265, minimizable: false, maximizable: false, draggable: false, 
                 resizable: true, url:'booking.php', showEffectOptions: {duration:1}});
   winbooking.toFront();
   winbooking.show();
}

var winagregar;
function vRegistrar(){
   var ancho = 160;
   if (document.body.clientWidth > 757)
      ancho = Math.round((document.body.clientWidth - 757) / 2) + 30;
   if (winagregar != null)
      winagregar.destroy();
   winagregar = new Window(Application.getNewId(), {className: 'alphacube', title: 'Registro Participantes', 
                 zIndex:1010, top:142, left:ancho, width:700, height: 408, minimizable: false, maximizable: false, closable: true, draggable: false,
                 resizable: true, url:'registro.php', showEffectOptions: {duration:1}})
   winagregar.toFront();
   winagregar.show();
}

function vLuego(){
   alert('Opcion pronto Disponible');
}

function vradio(){
   window.open('radio.html', 'Radio', 'toolbar=0,location=1,scrollbars=0,menubar=0,resizable=0,width=320,height=200');
}

var oldLink = null;
function setActiveStyleSheet(link, title) {
 
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}

function selected(cal, date) {
  cal.sel.value = date;
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
    cal.callCloseHandler();
}

function closeHandler(cal) {
  cal.hide();
  _dynarch_popupCalendar = null;
}

function showCalendar(id, format, showsTime, showsOtherMonths) {
 
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
    _dynarch_popupCalendar.hide();
  } else {
    var cal = new Calendar(1, null, selected, closeHandler);
 
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;	
    }
    _dynarch_popupCalendar = cal;
    cal.setRange(1900, 2070);
    cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);
  _dynarch_popupCalendar.parseDate(el.value);
  _dynarch_popupCalendar.sel = el;

  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");

  return false;
}
var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;

function isDisabled(date) {
  var today = new Date();
  return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
}

function flatSelected(cal, date) {
  var el = document.getElementById("preview");
  el.innerHTML = date;
}

function showFlatCalendar() {
  var parent = document.getElementById("display");
  var cal = new Calendar(0, null, flatSelected);  
  cal.weekNumbers = false;

  cal.setDisabledHandler(isDisabled);
  cal.setDateFormat("%A, %B %e");
  cal.create(parent);
  cal.show();
}


function limpianom(vactual, vdescp){
   if (vactual.value.length==0)
      vdescp.value="";
}

function verificafecha (campo)
{
	
	if (campo.value.length > 0)
	{
		if (campo.value.length == 10)
		{
			return true;
		}
		if (campo.value.length == 8)
		{
			var dia,mes,anno;
			dia=campo.value.substr(0,2);
			mes=campo.value.substr(2,2);
			anno=campo.value.substr(4);
			campo.value = dia + '/' + mes + '/' + anno;
			return true;
		}
		else
		{
			alert ('Debe ingresar la fecha en formato ddmmyyyy');
			return false;
		}
	}
	else
	{
		alert ('Debe ingresar la fecha en formato ddmmyyyy');
		return false;
	}
}

function ingresaconformato(campofecha)
{
   if ((window.event.keyCode!=8)&&(window.event.keyCode!=16)&&(window.event.keyCode!=46)&&(window.event.keyCode!=32)&&(window.event.keyCode!=39)&&(window.event.keyCode!=35)&&(window.event.keyCode!=36))
   {
	if ((campofecha.value.charAt(2)!="/") && (campofecha.value.length==3))
           campofecha.value = campofecha.value.substring(0,2) + '/' + campofecha.value.substring(2,campofecha.value.length);
	else
	{
	if ((campofecha.value.charAt(5)!="/") && (campofecha.value.length==6))
		campofecha.value = campofecha.value.substring(0,5) + '/' + campofecha.value.substring(5,campofecha.value.length);
	else
		{
		if ((campofecha.value.length == 2) || (campofecha.value.length == 5))
			campofecha.value = campofecha.value + '/'
		if (campofecha.value.length == 10) 
			return true;
		else
			return false;
		}
	}
   }
}

function validaFecha(field){		
			var checkstr = "0123456789";
			var DateField = field;
			var Datevalue = "";
			var DateTemp = "";
			var seperator = "/";
			var day;
			var month;
			var year;
			var leap = 0;
			var err = 0;
			var i;
		   err = 0;
		   DateValue = DateField.value;
		   /* Delete all chars except 0..9 */
		   for (i = 0; i < DateValue.length; i++) {			  			   
			  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
			     DateTemp = DateTemp + DateValue.substr(i,1);			     			     
			  }
		   }
		   
		   var let;
		   if (DateTemp=="")
		       let=0;
		   else
		       let=1;
		           
		   
		   DateValue = DateTemp;  
		   		   
		   /* Always change date to 8 digits - string*/
		   /* if year is entered as 2-digit / always assume 20xx */
		   if (DateValue.length == 6) {
		      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
		   if (DateValue.length != 8) {
		      err = 19;}
		   /* year is wrong if year = 0000 */
		   year = DateValue.substr(4,4);
		   if (year == 0) {
		      err = 20;
		   }
		   /* Validation of month*/
		   month = DateValue.substr(2,2);
		   if ((month < 1) || (month > 12)) {
		      err = 21;
		   }
		   /* Validation of day*/
		   day = DateValue.substr(0,2);
		   if (day < 1) {
		     err = 22;
		   }
		   /* Validation leap-year / february / day */
		   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
		      leap = 1;
		   }
		   if ((month == 2) && (leap == 1) && (day > 29)) {
		      err = 23;
		   }
		   if ((month == 2) && (leap != 1) && (day > 28)) {
		      err = 24;
		   }
		   /* Validation of other months */
		   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
		      err = 25;
		   }
		   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
		      err = 26;
		   }
		   /* if 00 ist entered, no error, deleting the entry */
		   if ((day == 0) && (month == 0) && (year == 00)) {
		      err = 0; day = ""; month = ""; year = ""; seperator = "";
		   }
	   	   
		   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */		  
		   if (err == 0) {
		      DateField.value = day + seperator + month + seperator + year;		      
		      if (DateField.value==""){
			     //return false;   
			     if (let!=0)
		            return(false);
		         else
		            return (true);		            
		      }else
		      	 return(true);
		   }
		   
		   /* Error-message if err != 0 */		      
	       else {
		      alert("La fecha es Incorrecta");
		      return (false);
		      //DateField.select();
			  //DateField.focus();
		   }	
		   
	}

function checkRutField(rut)
{
	 
	var tmpstr = "";
	for ( i=0; i < rut.length ; i++ )
		if ( rut.charAt(i) != ' ' && rut.charAt(i) != '.' && rut.charAt(i) != '-' )
			tmpstr = tmpstr + rut.charAt(i);
	rut = tmpstr;
	largo = rut.length;
// [VARM+]
	tmpstr = "";
	for ( i=0; rut.charAt(i) == '0' ; i++ );
		for (; i < rut.length ; i++ )
			tmpstr = tmpstr + rut.charAt(i);
	rut = tmpstr;
	largo = rut.length;
// [VARM-]
	if ( largo < 2 )
	{
		alert("Debe ingresar el rut completo.");
		//document.frm.rut_aux.focus();
		//document.frm.rut_aux.select();
		return false;
	}
	for (i=0; i < largo ; i++ )
	{
		if ( rut.charAt(i) != "0" && rut.charAt(i) != "1" && rut.charAt(i) !="2" && rut.charAt(i) != "3" && rut.charAt(i) != "4" && rut.charAt(i) !="5" && rut.charAt(i) != "6" && rut.charAt(i) != "7" && rut.charAt(i) !="8" && rut.charAt(i) != "9" && rut.charAt(i) !="k" && rut.charAt(i) != "K" )
		{
			alert("El valor ingresado no corresponde a un R.U.T valido.");
			//document.frm.rut_aux.focus();
			//document.frm.rut_aux.select();
			return false;
		}
	}
	var invertido = "";
	for ( i=(largo-1),j=0; i>=0; i--,j++ )
		invertido = invertido + rut.charAt(i);
	var drut = "";
	drut = drut + invertido.charAt(0);
	drut = drut + '-';
	cnt = 0;
	for ( i=1,j=2; i<largo; i++,j++ )
	{
		if ( cnt == 3 )
		{
			drut = drut + '.';
			j++;
			drut = drut + invertido.charAt(i);
			cnt = 1;
		}
		else
		{
			drut = drut + invertido.charAt(i);
			cnt++;
		}
	}
	invertido = "";
	for ( i=(drut.length-1),j=0; i>=0; i--,j++ )
		invertido = invertido + drut.charAt(i);
	//document.frm.rut_aux.value = invertido;
	if ( checkDV(rut) )
		return true;
	return false;
}
function checkDV( crut )
{
	largo = crut.length;
	if ( largo < 2 )
	{
		alert("Debe ingresar el rut completo.");
		//document.frm.rut_aux.focus();
		//document.frm.rut_aux.select();
		return false;
	}
	if ( largo > 2 )
		rut = crut.substring(0, largo - 1);
	else
		rut = crut.charAt(0);
	dv = crut.charAt(largo-1);
	checkCDV( dv );
	if ( rut == null || dv == null )
	return 0;
	var dvr = '0';
	suma = 0;
	mul = 2;
	for (i= rut.length -1 ; i >= 0; i--)
	{
		suma = suma + rut.charAt(i) * mul;
		if (mul == 7)
			mul = 2;
		else
			mul++;
	}
	res = suma % 11;
	if (res==1)
		dvr = 'k';
	else if (res==0)
		dvr = '0';
	else
	{
		dvi = 11-res;
		dvr = dvi + "";
	}
	if ( dvr != dv.toLowerCase() )
	{
		alert("EL rut es incorrecto.");
		//document.frm.rut_aux.focus();
		//document.frm.rut_aux.value = "";
		return false;
	}
	return true;
}
function checkCDV( dvr )
{
	dv = dvr + "";
	if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')
	{
		alert("Debe ingresar un digito verificador valido.");
		//document.frm.rut_aux.focus();
		//document.frm.rut_aux.select();
		return false;
	}
	return true;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   return IsNumber;
}
function cambiar_color_over(celda){ 
   celda.style.backgroundColor="#003366"; // #9FA8FF
   celda.style.color="#FFFFFF";
} 
function cambiar_color_out(celda,color){
   celda.style.backgroundColor=color;
   celda.style.color="#000000";
}
function cambiar_color_out(celda){
   celda.style.backgroundColor="";
   celda.style.color="";
}
function cambiar_letra_over(celda){ 
   celda.style.backgroundColor="#003399"; // #9FA8FF
   celda.style.color="#FFFFFF";
} 
function cambiar_letra_out(celda){
   celda.style.backgroundColor="";
   celda.style.color="#ffffff";
}

function cambiar_link_over(links){ 
   links.style.backgroundColor="#003399";
   links.style.color="#FFFFFF";
} 
function cambiar_link_out(links){
   links.style.backgroundColor=""; //#000000
   links.style.color="#ffffff";
}

function right(e) {
/*if (navigator.appName == 'Netscape' && 
(e.which == 3 || e.which == 2)) {
alert("Uds. no posee permisos para utilizar el botón derecho.");
return false;
}
else if (navigator.appName == 'Microsoft Internet Explorer' && 
(event.button == 2 || event.button == 3)) {
alert("Uds. no posee permisos para utilizar el botón derecho.");
return false;
}
return true;
*/
}
 
function campoRequerido(obj, nombre) {
    //-- Valido que se ingrese algo ---------------
    if (obj.value.trim().length == 0 ) {
        
        alert("Debe ingresar " + nombre + "");
        obj.focus();
        return false;
    } else {
        return true;
    }
}

function largoCampo(obj, nombre, requerido, min, max) {
    //-- Si se ingresa un valor... ---------------
    if (obj.value.trim().length == 0 && requerido) {
        obj.focus();
        alert("Debe ingresar " + nombre + "");
        return false;
    }
    //-- Se valida el mínimo... ---------------
    if (obj.value.trim().length != 0 && obj.value.trim().length < min) {
        obj.focus();
        alert("" + nombre + " debe tener al menos " + min + " caracteres.\nActualmente posee " + obj.value.trim().length);
        return false;
    }
    //-- Se valida el máximo ---------------
    if (max && obj.value.trim().length > max) {
        obj.focus();
        alert("" + nombre + " debe tener como máximo " + max + " caracteres.\nActualmente posee " + obj.value.trim().length);
        return false;
    }
    return true;
}

 // Valida el ingreso de un email
function campoEmail(obj, nombre) {
    // Valida la sintaxis correcta del email
    // si el largo es 0 se considera que la sintaxis es correcta
    if (obj.value.trim().length > 0 && (obj.value.indexOf('@') == -1 || obj.value.indexOf('.') == -1)) {
        obj.focus();
        alert("" + nombre + " mal ingresado");
        return false;
    } else {
        return true;
    }
}

/// @param obj referencia al objeto SELECT
/// @return valor seleccionado
function getValorSelect(obj) {
    if (!obj) {
        alert('No existe el objeto');
    } else if (obj.selectedIndex == -1) {
        alert('No hay ninguna opción seleccionada');
    } else {
        return obj.options[obj.selectedIndex].value;
    }
    return false;
}
// Verifica opción seleccionada de un SELECT
function campoSelectRequerido(obj, nombre) {	 
    if (!obj) {
        alert("No existe el campo " + nombre + "");
        return false;
    }
    if (obj.disabled) {
        return true; 
    }
    if (obj.selectedIndex == -1 || getValorSelect(obj) == 'NULL' || getValorSelect(obj) == '0') {
        obj.focus();
        alert("Debe seleccionar " + nombre + "");
        return false;
    }
    return true;
}

function comparaPassword(p1, p2, nombre, largoMin)
    {    
	
    if (p1.value == '********' && p2.value == '********')
        return true;


   ok = true;
    if (ok) { ok = validaLargo(p1, nombre, true, largoMin,50); }
//    if (ok) { ok = validaLargo(p2, nombre + ' 2', largoMin); }

    if (ok)
        {
        if (p1.value != p2.value)
            {
            p1.value = "";
            p2.value = "";
            p1.focus();
            alert("'" + nombre + "' no coincide, ingreselo nuevamente");
            return false;
            }
        return true;
        }
    return false;
    }

function validaLargo(obj, nombre, requerido, min, max) {
    //-- Valido que se ingrese algo ---------------
    if (obj.value.length == 0 && requerido) {
        obj.focus();
        alert("Debe ingresar '" + nombre + "'");
        return false;
    }
    //-- Valido el largo minimo ---------------
    if (obj.value.length != 0 && obj.value.length < min) {
        obj.focus();
        alert("'" + nombre + "' debe tener al menos " + min + " caracteres.\nActualmente posee " + obj.value.length);
        return false;
    }
    //-- Valido el largo maximo ---------------
    if (max && obj.value.length > max) {
        obj.focus();
        alert("'" + nombre + "' debe tener como máximo " + max + " caracteres.\nActualmente posee " + obj.value.length);
        return false;
    }
    return true;
}


document.onmousedown=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
window.onmousedown=right;


