var _dom=document.all?3:(document.getElementById()?1:(document.layers?2:0));
//----------------------------------------------------------------
function sendNewsGo(i,t){d=document.sendNews;d.idn.value=i;d.titulo.value=t;return}
//----------------------------------------------------------------
$(function() {$("#dialog").dialog("destroy");
var name = $("#name"), yourname = $("#yourname"), email = $("#email"), allFields = $([]).add(yourname).add(name).add(email),tips = $(".validateTips");

function updateTips(t) {
tips
.text(t)
.addClass('ui-state-highlight');
setTimeout(function() {tips.removeClass('ui-state-highlight', 1500);}, 500);}

function checkLength(o,n,min,max) {
if ( o.val().length > max || o.val().length < min ) {
o.addClass('ui-state-error');
updateTips("El tamaño del " + n + " debe estar entre "+min+" y "+max+".");
return false;} else {return true;}}

function checkRegexp(o,regexp,n) {
if ( !( regexp.test( o.val() ) ) ) {o.addClass('ui-state-error');updateTips(n);return false;} else {return true;}}
		
$("#dialog-form").dialog({
autoOpen: false,
height: 350,
width: 350,
modal: true,
buttons: {
'Enviar mail': function() {var bValid = true;allFields.removeClass('ui-state-error');
bValid = bValid && checkLength(yourname,"nombre",3,80);
bValid = bValid && checkLength(name,"nombre",3,80);
bValid = bValid && checkLength(email,"email",6,80);
bValid = bValid && checkRegexp(name,/^([a-zA-Z]|\s)+$/i,"En su nombre sólo se permiten letras.");
bValid = bValid && checkRegexp(yourname,/^([a-zA-Z]|\s)+$/i,"En destinatario sólo se permiten letras.");
bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"ej. ui@jquery.com");

if (bValid) {d=document.sendNews;document.ifr.location.href="/u_email.asp?yn="+d.yourname.value+"&n="+d.name.value+"&e="+d.email.value+"&t="+d.titulo.value+"&i="+d.idn.value+"";
$(this).dialog('close');
$("#dialog-message").dialog({modal: true,buttons: {Ok: function() {	$(this).dialog('close');}}});
}
},
Cancel: function() {$(this).dialog('close');}
},
close: function() {allFields.val('').removeClass('ui-state-error');}
});
		
		
$('.enviar-noticia')
.button()
.click(function() {$('#dialog-form').dialog('open');});
});
//----------------------------------------------------------------
setInterval("settime()", 60000);var subactivo="";
function settime () { var curtime = new Date(); var curhour = curtime.getHours(); var curmin = curtime.getMinutes(); var time = "";  if(curhour == 0) curhour = 12; time = curhour + ":" + (curmin < 10 ? "0" : "") + curmin; document.getElementById('hora').innerHTML=time; }
function setSubMenu(estado,boton,submenu,xx,yy) {
div = document.getElementById(boton);
if (estado) {
	setPosition(submenu,div,xx,yy); document.getElementById(submenu).style.display = "block";
	div.href = "javascript:setSubMenu(false,'"+boton+"','"+submenu+"',"+xx+","+yy+");";
	if (subactivo!=""&&subactivo!=submenu){document.getElementById(subactivo).style.display = "none";}
	subactivo = submenu;
} else {
	document.getElementById(submenu).style.display = "none";
	div.href = "javascript:setSubMenu(true,'"+boton+"','"+submenu+"',"+xx+","+yy+");";
}
}
function setPosition(layer,objeto,offX,offY){var eDiv = document.getElementById(layer);	var cursorleft = cursortop = 0;	if (objeto.offsetParent) {	cursorleft = objeto.offsetLeft;	cursortop = objeto.offsetTop;while (objeto = objeto.offsetParent) {				cursorleft += objeto.offsetLeft;cursortop += objeto.offsetTop;}}eDiv.style.zIndex=20;eDiv.style.left = (cursorleft - offX) + "px";eDiv.style.top = (cursortop + offY) + "px";}
//----------------------------------------------------------------
function SH(act,id) { var obj = getElems(id); if(obj) { if(act == "") { if(obj.style.visibility == "hidden" || obj.style.visibility == "") { obj.style.visibility = "visible"; if(obj.tagName != "TR") { obj.style.display = "block"; } else { obj.style.display = ""; } } else { obj.style.visibility = "hidden"; obj.style.display = "none"; } } else if(act.toUpperCase() == "S") { obj.style.visibility = "visible"; if(obj.tagName != "TR") { obj.style.display = "block"; } else { obj.style.display = ""; } } else if(act.toUpperCase() == "H") { obj.style.visibility = "hidden"; obj.style.display = "none"; } } }
//----------------------------------------------------------------
function getElems(id) { if (window.parent.document.getElementById) { return document.getElementById(id); } else if (window.parent.document.all) { return document.all(id); } else if (window.parent.document.layers) { return document.layers(id); } }
//----------------------------------------------------------------
function checkAno(year) { return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0; }

function checkFecha(dia,mes,ano) { if(!checkAno(ano.value*1)) { var dias = 28; } else { var dias = 29; } if (((mes.value*1 == 4 || mes.value*1 == 6 || mes.value*1 == 9 || mes.value*1 == 11) && dia.value*1 > 30) || (mes.value*1 == 2 && dia.value*1 > dias)) { dia.focus(); alert("La fecha ingresada es incorrecta"); return false; } else { return true; } }
//----------------------------------------------------------------
function Left(str, n) { if(n <= 0) { return ""; } else if(n > String(str).length) { return str; } else { return String(str).substring(0,n); } }
function Right(str, n) { if(n <= 0) { return ""; } else if(n > String(str).length) { return str; } else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } }
//----------------------------------------------------------------
function validaNumeros(valor,texto,minimo) { numero = new String(valor.value); ok = 1; var validos = "0123456789"; for (i=0;i<numero.length;i++){ if (validos.indexOf(numero.charAt(i)) == "-1") { ok = 0; } } if (ok == 0) { if (texto == "") { alert("Ingrese sólo números."); } else { alert(texto); } valor.focus(); return false; } if (numero.length < minimo) { alert("Ingrese como mínimo " + minimo + " dígitos."); valor.focus(); return false; } return true; }
//----------------------------------------------------------------
function validaNumerosGuion(valor,texto,minimo, minimotexto){
numero = new String(valor.value);var ok = 1;var validos = "0123456789- ";
for (i=0;i<numero.length;i++){if (validos.indexOf(numero.charAt(i)) == "-1") ok = 0;}
if (ok == 0) {alert(texto);valor.focus(); return false}
if (numero.length<minimo){alert(minimotexto);valor.focus(); return false}
return true;
}
//----------------------------------------------------------------
function validaMatricula(valor){
numero = new String(valor.value);
msg = "Ingrese su matrícula en el siguiente formato\n00-00000-0, donde 0 sea un número;\n por ejemplo: 10-03507-6."
var ok = 1;var validos = "0123456789-";
for (i=0;i<numero.length;i++){if (validos.indexOf(numero.charAt(i)) == "-1") ok = 0;}
if (ok == 0) {alert(msg);valor.focus(); return false}
if (numero.charAt(2)!="-" || numero.charAt(8)!="-"){ alert(msg); valor.focus(); return false;}
return true;
}
//----------------------------------------------------------------
function addMATRICULAdash(c){
var a = c.value.split ("-").join("");
if ( a.length > 7 ){c.value = a.substr(0,2) + "-" + a.substr(2,5) + "-" + a.substr(7,1);}
else if ( a.length > 1 ){c.value = a.substr(0,2) + "-" + a.substr(2); }}
//----------------------------------------------------------------
function validateNumKey (evt){
var inputKey = ''; var e = evt; 
if (_dom==3) { inputKey += event.keyCode; var e = window.event;}
else if (_dom==1) { inputKey += evt.charCode; }
else { inputKey += evt.which; }
if(inputKey>47 && inputKey<58 ) return;
if (e.stopPropagation) {e.stopPropagation();e.preventDefault();}else{e.cancelBubble = true;e.returnValue = false;}
return false;}
//----------------------------------------------------------------
function estaVacio(s,texto){
var len = s.value.length;
for (i=0;i<len;++i){if (s.value.charAt(i)!=" ") {return false;}}
alert(texto); s.focus();return true;
}
//----------------------------------------------------------------
var activeDialog = 0;
function OpenDialog(strURL, properties) {
window.onfocus = WindowFocus; activeDialog = window.open(strURL, "dialog", properties);return true;
}
function WindowFocus(event) {
if (activeDialog) { try {activeDialog.focus(); }
catch (e) { activeDialog = 0; }
}}
//----------------------------------------------------------------
function OW(page,winName,width,height,options) { var posTop = screen.availHeight / 2 - (height / 2) - 30; var posLeft = screen.availWidth / 2 - (width / 2); var ventana = window.open(page,winName,"width=" + width + ", height=" + height + ", status=no, top=" + posTop + ", left=" + posLeft + ", " + options); ventana.focus(); }
//----------------------------------------------------------------
function trimJS(cadena) { cadena.value = cadena.value.replace(/^\s*|\s*$/g,""); }
//----------------------------------------------------------------
function validaEmail(emails) {
trimJS(emails);emails.value = emails.value.toLowerCase();email = new String(emails.value);
if(email == "" || email.indexOf("@", 0) == -1 || email.indexOf(".", 0) == -1 || email.length <= 9) {
alert("La dirección de eMail proporcionada no es válida");emails.focus();return false;
} else {var ok = 1;var validos = "abcdefghijklmnopqrstuvwxyz0123456789-_@.";
for (i=0;i<email.length;i++) {if (validos.indexOf(email.charAt(i)) == "-1") { ok = 0; }}
if (ok == 0) {alert("La dirección de eMail proporcionada no es válida"); emails.focus(); return false;}}
return true;
}
//----------------------------------------------------------------
function selectedRadio(radiogroup){
for(i=0;i<radiogroup.length;i++){
if(radiogroup[i].checked) return i;}}
//----------------------------------------------------------------
function validEmail(elementValue) {      
	var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	var validEmailResult = emailPattern.test(elementValue);
	if(!validEmailResult) { alert("La dirección de eMail proporcionada no es válida"); }
	return validEmailResult;
}
//----------------------------------------------------------------
function popVideo(h, a, t) { posTop = screen.availHeight / 2 - (h / 2) - 30; posLeft = screen.availWidth / 2 - (380 / 2); window.open("/videos_pop.asp?a=" + a + "&t=" + t + "","","width=380, height=415, status=no, top=" + posTop + ", left=" + posLeft + ";"); }
//----------------------------------------------------------------
function popCV(page) { var w = 450; var h = 300; posTop = screen.availHeight / 2 - (h / 2) - 30; posLeft = screen.availWidth / 2 - (w / 2); ventana = window.open("/" + page,"","width=" + w + ", height=" + h + ", status=no, top=" + posTop + ", left=" + posLeft + ";"); ventana.focus(); }
//----------------------------------------------------------------
function popPrv(page) {//w=350; h=300; Lp=(screen.availWidth)?(screen.availWidth-w)/2:50;
//Tp=(screen.availHeight)?(screen.availHeight-h)/2:50;
win=window.open(page,'myWin','toolbars=0,width=350,height=300,top=100,left=100,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
return true}
//----------------------------------------------------------------
function isDate(p_Expression){
return !isNaN(new Date(p_Expression));}
//----------------------------------------------------------------
function dateAdd(p_Interval, p_Number, p_Date){
if(!isDate(p_Date)){return "fecha inválida: '" + p_Date + "'";}
if(isNaN(p_Number)){return "número inválido: '" + p_Number + "'";}

p_Number = new Number(p_Number);
var dt = new Date(p_Date);
switch(p_Interval.toLowerCase()){
case "yyyy": {// year
dt.setFullYear(dt.getFullYear() + p_Number);break;}
case "q": {// quarter
dt.setMonth(dt.getMonth() + (p_Number*3));break;}
case "m": {// month
dt.setMonth(dt.getMonth() + p_Number);break;}
case "y":// day of year
case "d":// day
case "w": {// weekday
dt.setDate(dt.getDate() + p_Number);break;}
case "ww": {// week of year
dt.setDate(dt.getDate() + (p_Number*7));break;}
case "h": {// hour
dt.setHours(dt.getHours() + p_Number);break;}
case "n": {// minute
dt.setMinutes(dt.getMinutes() + p_Number);break;}
case "s": {// second
dt.setSeconds(dt.getSeconds() + p_Number);break;}
case "ms": {// second
dt.setMilliseconds(dt.getMilliseconds() + p_Number);break;}
default: {
return "intervalo inválido: '" + p_Interval + "'";}
}
return dt;
}
//----------------------------------------------------------------
function weekdayName(p_Date, p_abbreviate){
if(!isDate(p_Date)){return "fecha inválida: '" + p_Date + "'";}
var dt = new Date(p_Date);
var retVal = dt.toString().split(' ')[0];
var retVal = Array('Domingo','Lunes','Martes','Miércoles','Jueves','Viernes','Sábado')[dt.getDay()];
if(p_abbreviate==true){retVal = retVal.substring(0, 3)}// abbr to 1st 3 chars
return retVal;
}
//----------------------------------------------------------------
function monthName(p_Date, p_abbreviate){
if(!isDate(p_Date)){return "invalid date: '" + p_Date + "'";}
var dt = new Date(p_Date);
var retVal = Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agost','Septiembre','Octubre','Noviembre','Diciembre')[dt.getMonth()];
if(p_abbreviate==true){retVal = retVal.substring(0, 3)}// abbr to 1st 3 chars
return retVal;
}
//----------------------------------------------------------------
function datePart(p_Interval, p_Date, p_firstdayofweek, p_firstweekofyear){
if(!isDate(p_Date)){return "fecha inválida: '" + p_Date + "'";}

var dtPart = new Date(p_Date);
switch(p_Interval.toLowerCase()){
case "yyyy": return dtPart.getFullYear();
case "q": return parseInt(dtPart.getMonth()/3)+1;
case "m": return dtPart.getMonth()+1;
case "y": return dateDiff("y", "1/1/" + dtPart.getFullYear(), dtPart);// day of year
case "d": return dtPart.getDate();
case "w": return dtPart.getDay();// weekday
case "ww":return dateDiff("ww", "1/1/" + dtPart.getFullYear(), dtPart);// week of year
case "h": return dtPart.getHours();
case "n": return dtPart.getMinutes();
case "s": return dtPart.getSeconds();
case "ms":return dtPart.getMilliseconds();// millisecond// 
default: return "intervalo inválido: '" + p_Interval + "'";
}
}
//----------------------------------------------------------------
function dateDiff(p_Interval, p_Date1, p_Date2, p_firstdayofweek, p_firstweekofyear){
if(!isDate(p_Date1)){return "fecha inválida: '" + p_Date1 + "'";}
if(!isDate(p_Date2)){return "fecha inválida: '" + p_Date2 + "'";}
var dt1 = new Date(p_Date1);
var dt2 = new Date(p_Date2);

var iDiffMS = dt2.valueOf() - dt1.valueOf();
var dtDiff = new Date(iDiffMS);
var nYears  = dt2.getUTCFullYear() - dt1.getUTCFullYear();
var nMonths = dt2.getUTCMonth() - dt1.getUTCMonth() + (nYears!=0 ? nYears*12 : 0);
var nQuarters = parseInt(nMonths/3);
var nMilliseconds = iDiffMS;
var nSeconds = parseInt(iDiffMS/1000);
var nMinutes = parseInt(nSeconds/60);
var nHours = parseInt(nMinutes/60);
var nDays  = parseInt(nHours/24);
var nWeeks = parseInt(nDays/7);

// return requested difference
var iDiff = 0;
switch(p_Interval.toLowerCase()){
case "yyyy": return nYears;
case "q": return nQuarters;
case "m": return nMonths;
case "y": // day of year
case "d": return nDays;
case "w": return nDays;
case "ww":return nWeeks;// week of year// 
case "h": return nHours;
case "n": return nMinutes;
case "s": return nSeconds;
case "ms":return nMilliseconds;// millisecond
default: return "intervalo inválido: '" + p_Interval + "'";
}
}
