//Función para validar el tamaño y formato de los Archivos que se van a subir

function isImage(file,tipo){
	//Get a file extension
	var ext = file.substr(file.lastIndexOf('.')).toLowerCase()
	
	//Check extension to image types.
	if ((tipo == 1) || (tipo == 5)) {
		ext = '.gif,.jpg,.jpeg,.png,.swf,.bmp,'.indexOf(ext+',')
		if (ext >= 0) {
			return true
		} else {
			msg = 'Por favor, seleccione el tipo de Foto correcto (.gif,.jpg,.jpeg,.bmp,.png,.swf)'
			alert(msg)
			return false
		}
	}
	
	if (tipo == 2) {
		ext = '.mov,.avi,.mpg,.mpeg,.asf,.wmv,'.indexOf(ext+',')
		if (ext >= 0) {
			return true
		} else {
			msg = 'Por favor, seleccione el tipo de Video correcto (.mov,.avi,.mpg,.mpeg,.asf,.wmv)'
			alert(msg)
			return false
		}
	}
	
	if (tipo == 3) {
		ext = '.mp3,.wav,'.indexOf(ext+',')
		if (ext >= 0) {
			return true
		} else {
			msg = 'Por favor, seleccione el tipo de Música o Sonido correcto (.mp3,.wav)'
			alert(msg)
			return false
		}
	}
	
	if (tipo == 4) {
		ext = '.doc,.txt,.pdf,.xls,.htm,.html,.ppt,'.indexOf(ext+',')
		if (ext >= 0) {
			return true
		} else {
			msg = 'Por favor, seleccione el tipo de Documento correcto (.doc,.txt,.pdf,.xls,.ppt,.htm,.html)'
			alert(msg)
			return false
		}
	}
};


var lastfieldname = ''
var filenamechecked = ''

function preview(i,j,tipo) {
	var file = i.value
	var sw = false
	
	if (file.length <=0 ) return;
	
	var ipreview = document.all('ipreview' + j)
	
	if (tipo == 1) {
		pic = '../_gui/multimedia_fotos.gif'
	}
	
	if (tipo == 2) {
		pic = '../_gui/multimedia_videos.gif'
	}
	
	if (tipo == 3) {
		pic = '../_gui/multimedia_musica.gif'
	}
	
	if (tipo == 4) {
		pic = '../_gui/multimedia_documentos.gif'
	}
	
	if (tipo == 5) {
		pic = '../articulos/articulos/imagenes/noimage.gif'
	}
		
	if (isImage(file,tipo)) {
		
		if (tipo == 1) {
			ipreview.src = 'file://' + file
		} else {
			ipreview.src = pic
		}
			
	} else {

		ipreview.src = pic
	};

	lastfieldname = i.name
}


//Validar el Ancho de las Fotos
function isPictureSize(dir,tipo,msg) {
	myImage = new Image()
	myImage.src = dir
	
	if ((myImage.width > 510) && (tipo == 1)) {
		alert(msg)
		return false
	}
	
	if ((myImage.width > 210) && (tipo == 5)) {
		alert(msg)
		return false
	}
	
	return true
}


//Solo valores numericos

function esInteger(e) {
	var charCode

	charCode = e.keyCode 
	status = charCode 
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		return false
	}
	return true
}

//Seleccionar los Checksbox
var checkflag = "false";

function CheckAll(field) {
	if (checkflag == "false") {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;
		}
			checkflag = "true";
	} else {
		for (i = 0; i < field.length; i++) {
			field[i].checked = false; 
		}
		checkflag = "false";
	}
}


//Bloquear las Comillas Dobles y Simples (" ')
function comillas() {
	if (event.keyCode==34 || event.keyCode==39) event.returnValue = false;
}

function ninguncaracter() {
	if (event.keyCode >= 0) event.returnValue = false;
}

function validarfecha() {
	if (event.keyCode != 48 && event.keyCode != 49 && event.keyCode != 50 && event.keyCode != 51 && event.keyCode != 52 && event.keyCode != 53 && event.keyCode != 54 && event.keyCode != 55 && event.keyCode != 56 && event.keyCode != 57 && event.keyCode != 47) event.returnValue = false;
}


function show(wm) {
	  wm.visibility = "show";
	  wm.style.display = "";
}

function hide(wm){
	  wm.visibility = "hide";
	  wm.style.display = "none";
}


function nosesion(){
    alert('No estás registrado\no no has comenzado tu sesión!\nSolo para usuarios registrados!');
}

function GenerarTexto(objeto, textsize) {
	var letras = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9'];
	var palabra = "";
	if ((textsize < 0) || (textsize == "")) {
		textsize = 10;
	}
	
	for(i=1; i<textsize;i++) {
		palabra = palabra + letras[Math.floor(Math.random() * letras.length)];
	}
	
	eval(objeto).value = palabra;
}


function OpenDialog(strUrl) {
	var myText = showModalDialog(strUrl, "", "center:yes; help:no; resizable:no; status:no; scroll:no;");
	return myText
}


function actualizaReloj(){ 
	marcacion = new Date();
	Hora = marcacion.getHours();
	Minutos = marcacion.getMinutes();
	Segundos = marcacion.getSeconds();
	
	if (Hora >= 12) {
		var Horario = "P.M."
	} else {
		var Horario = "A.M."
	}
	
	switch (Hora) {
		case 0:
			Hora = 12;
			break;
		case 13:
			Hora = 1;
			break;
		case 14:
			Hora = 2;
			break;
		case 15:
			Hora = 3;
			break;
		case 16:
			Hora = 4;
			break;
		case 17:
			Hora = 5;
			break;
		case 18:
			Hora = 6;
			break;
		case 19:
			Hora = 7;
			break;
		case 20:
			Hora = 8;
			break;
		case 21:
			Hora = 9;
			break;
		case 22:
			Hora = 10;
			break;
		case 23:
			Hora = 11;
			break;
	}
	
	if (Hora<=9) 
	Hora = "0" + Hora;
	
	if (Minutos<=9) 
	Minutos = "0" + Minutos;
	
	if (Segundos<=9) 
	Segundos = "0" + Segundos ;
	
	var Script = Hora + ":" + Minutos + " " + Horario;
	
	document.getElementById('Reloj').innerHTML = Script;
	setTimeout("actualizaReloj()",1000) 
} 

function openWin(eURL,eName,features) {
  window.open(eURL,eName,features);
}