//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 ventana(ventana,tamano){
window.open(ventana, '', tamano)
}

function mensaje(message){
    alert(message)}



/***********************************************
* Switch Content script- 
***********************************************/

var enablepersist="on" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='<img src="/ec3/_gui/iconos/icon-contract-this-14x14.gif">' //HTML for contract symbol. For image, use: <img src="whatever.gif">
//var contractsymbol='- ' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='<img src="/ec3/_gui/iconos/icon-expand-this-14x14.gif">' //HTML for expand symbol.
//var expandsymbol='+ ' //HTML for expand symbol.


if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('<\/style>')
}

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
for (i=0; i<rootobj.length; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(curobj, cid){
var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
if (ccollect.length>0){
if (collapseprevious=="yes")
contractcontent(cid)
document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"
if (showstateobj.length>0){ //if "showstate" span exists in header
if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()
}
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate

