/*utilitarios.js  v0.0000..(hasta que te canses)..01 escrito por Mr. X-ecutor, cualquier consulta o aporte puedes escribirme a:zergraynor@hotmail.com.
Aqui estaran ubicadas todas las funciones js que se nos ocurran para mantener limpia nuestras paginas que hagamos, probadas en 3 navegdores: Internet Explorer 7.0, Mozilla 3.0, Safari 3(algunos scripts aun fallan). Por favor trata de seguir el orden impuesto aca, no mezcles funciones de un tipo con otro, sin mas que decir disfrutalo .. que aprendas y enseñes.
/**/
/********/
/*NOTAS:*/
/********/
/**/
/*1. Probaremos con effects.js si podemos realizar los efectos para animar la pagina web si no tendremos que subir la libreria scriptaculous y hacerla funcionar desde ahi.
2. Recuerda que el problema de la franja negra en las ventanas creadas con protype window en Internet Explorer es un problema que ni los mismos creadores saben que es, por lo tanto la solucion esta en crear un div dentro de el trataremos de cargar la ventana y a ese div darle el efecto de appear o hide.*/
/**/
/****************/
/*UTILITARIOS.JS*/
/****************/
/**/

var eScrollY = 0;
var navego = getNaveg();
var ventana_c;
var paginact;
var calmsg;
var largopag;
var page;

/*Sí, la clasica función de la ventanita o pestaña nueva, simple pero util, puede usarse desde un boton flash también... simplemente pones en el actionscript del boton:
on(Press){
	getURL("javascript:abrir_ventana('http://www.sacooliveros.com/portal/index2.php', '', '')");
}
*/


function abre_impresion(x) {
	window.open(x, '', 'width=731, height=500, scrollbars=YES');
}

function abrir_ventana(loc, nam, opc){
	window.open(loc, nam, opc);
}

function busqueda(){
	with(buscando){
	a=txtbusqueda.value;
	if(a==""){
	}else{
		submit();	
	}
	}
}
//detecta navegador en el que el usuario esta viendo la pagina, valor util cuando se trata de las diferencias entre navegadores
function getNaveg() {
	//detectando Mozilla, Netscape, Safari u Opera
	if (window.clientInformation == undefined) {
		data_naveg = window.navigator.appName;
	}else{ //sino es internet explorer
		data_naveg = window.clientInformation.appName;
	}
	return data_naveg;
}

function mlat() {
	activeTab(1);
}

function llamar(endpage) {
	if (endpage == undefined) {
		endpage = null;
	}
	navego = getNaveg();
	goingTime();
	nombre = window.location.pathname;
	arrcad = nombre.split("/");
	tam = arrcad.length;
	if ((arrcad[tam-1] == "colegio.php") || (arrcad[tam-1] == "academia.php")) {
		//tabsMult(1);
		//div_loader_ca();
	}else if(arrcad[tam-1] == "novedades.php"){
		callNotice(mesg[0],mesg[1]);
		setTimeout(mlat, 100);
	}else if(page == "index"){
		listNotices();
		setTimeout(mlat, 100);
	}else if(page == "inst") {
		setTimeout(mlat, 100);
	}else if(arrcad[tam-1] == "calengig.php"){
		setTimeout(mlat, 100);
	}else if(page == "psicologia") {
		psicMult(1);
		setTimeout(mlat, 100);
	}else if(page == "multimedia") {
		listVideos();
		setTimeout(mlat, 100);
	}
	if (paginact == 1) {
		//clickear();
		clickear2();
	}else{
		//clickear();
	}
	if (endpage == 1) {
		setTimeout(mlat, 100);
		setTimeout(goBack, 5000);
	}
}

function llamada_home() {
	setTimeout(dameDir, 8000);
}

function llamada_home2() {
	setTimeout(dameDir2, 8000);
}

function dameDir2() {
	window.open("franquicias.php", "_self");
}

function dameDir() {
	window.open("index.php", "_self");
}

function goBack() {
	history.back();
}

window.onscroll=function(){
 	var scrollY=window.pageYOffset || document.documentElement.scrollTop;
	eScrollY = scrollY;
}

//Bloque de prototype window
/**/
//ventana para el calendario

function ventana_pop2(dir, ancho, alto) {
	var ancho_pantalla=screen.width;
	var vAncho = parseInt(ancho);
	var vAlto = parseInt(alto);
	var wAncho = vAncho + 6;
	var wAlto = vAlto + 5;
	var espArriba = eScrollY+330;
	if (navego == "Microsoft Internet Explorer") {//y decian que naveg no era util xD
		var opac = 1;
	}else{
		var opac = 0.95;
	}
	//creacion de la ventana, usamos en left esa formula para calcular la mitad de la pantalla menos la mitad del ancho de la capa "container" + 10 pixeles, ya que si usamos un valor entero en las pantallas widescreen el valor de left estara en base a esa medida y se vera mal.
	win = new Window({className: "mac_os_x", title: "Calendario", width:wAncho, height:wAlto, top:espArriba, left:(ancho_pantalla/100)*65/*-(vAncho/2)*/, showEffect: Effect.BlindDown, hideEffect: Effect.BlindUp, draggable:false, wiredDrag:false, rezisable:false, minimizable:false, maximizable:false, opacity:opac})
	//contenido, destruye en cierre y muestra la ventana, si deseas algo mas, ponle ps xD
	win.getContent().innerHTML = '<iframe src='+dir+' width="'+vAncho+'" height="'+vAlto+'" marginheight="no" marginwidth="no" scrolling="no"></iframe>'; 
	win.setDestroyOnClose();
	win.show();
	return win;
}

//bloque contactanos

function meter_tablas(){
	var tabla = document.getElementById("formul2");
	var myselect = document.getElementById("numHijos");
	if(tabla.rows.length > 8){
	var holder = tabla.rows.length;
		for (m=4; m<holder-4; m++){
			tabla.deleteRow(tabla.rows.length-5);
		}
	}

	for (var i=0; i<myselect.options.length; i++){
		if (myselect.options[i].selected == true){
			valor = i+1;
			break;
		}
	}
	var rowCount = 0;
	for (j=4; j<4+valor; j++){
		var nvoRow = tabla.insertRow(4+rowCount);
		rowCount++;
		var nvoCell_0 = nvoRow.insertCell(0);
		var nvoCell_1 = nvoRow.insertCell(1);
		nvoCell_0.innerHTML = "Hijo "+rowCount;
		nvoCell_1.innerHTML = "<table width='312' border='0'>"+
  "<tr>"+
    "<th bgcolor='#DDDDDD' width='139' align='center' valign='middle' class='Estilo1'>Nombre y Apellidos</th>"+
    "<th bgcolor='#DDDDDD' width='61' align='center'valign='middle' class='Estilo1'>Grado y Sección</th>"+
    "<th bgcolor='#DDDDDD' width='90' align='center' valign='middle' class='Estilo1'>Local</th>"+
  "</tr>"+
  "<tr>"+
    "<td align='center' valign='middle'><input name='nombres0"+rowCount+"' type='text' id='nombres0"+rowCount+"' size='22' class='texto1' /></td>"+
    "<td align='center' valign='middle'><input name='grado0"+rowCount+"' type='text' id='grado0"+rowCount+"' size='7' class='texto1' /></td>"+
    "<td align='center' valign='middle'><input name='local0"+rowCount+"' type='text' id='local0"+rowCount+"' size='15' class='texto1' /></td>"+
  "</tr>"+
"</table>";
	}
}
function val_formul() {
	var capcha = igualar2();
	tabla = document.getElementById("formul2");
	//nombre
	var valor4 = document.getElementById("nombres").value;
	if( valor4 == null || valor4.length == 0 || /^\s+$/.test(valor4) ) {
		alert("por favor ingrese los datos correspondientes al campo referido");
		tabla.rows[0].cells[0].bgColor = "#FF9797";
		tabla.rows[0].cells[1].bgColor = "#FF9797";
		document.getElementById("nombres").focus();
		return false;
	}else{
		tabla.rows[0].cells[0].bgColor = null;
		tabla.rows[0].cells[1].bgColor = null;
	}
	//email
	var valor3 = document.getElementById("email").value;
	if( !(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(valor3)) ) {
		alert("formato de email incorrecto");		
		tabla.rows[2].cells[0].bgColor = "#FF9797";
		tabla.rows[2].cells[1].bgColor = "#FF9797";
		document.getElementById("email").focus();
		return false;
	}else{
		tabla.rows[2].cells[0].bgColor = null;
		tabla.rows[2].cells[1].bgColor = null;
	}

	var valor5 = document.getElementById("asunto").value;
	if( valor5 == null || valor5.length == 0 || /^\s+$/.test(valor5) ) {
		alert("por favor ingrese los datos correspondientes al campo referido");
		tabla.rows[5].cells[0].bgColor = "#FF9797";
		tabla.rows[5].cells[1].bgColor = "#FF9797";
		document.getElementById("asunto").focus();
		return false;
	}else{
		tabla.rows[5].cells[0].bgColor = null;
		tabla.rows[5].cells[1].bgColor = null;
	}

	var valor6 = document.getElementById("cuerpo2").value;
	if( valor6 == null || valor6.length == 0 || /^\s+$/.test(valor6) ) {
		alert("por favor ingrese los datos correspondientes al campo referido");
		tabla.rows[6].cells[0].bgColor = "#FF9797";
		tabla.rows[6].cells[1].bgColor = "#FF9797";
		document.getElementById("cuerpo").focus();
		return false;
	}else{
		tabla.rows[6].cells[0].bgColor = null;
		tabla.rows[6].cells[1].bgColor = null;
	}
	if (capcha == 1) {
		document.form2.submit();
	}else if (capcha == 0){
		alert("el código ingresado no es correcto, por favor verifique bien el código e intente de nuevo");
	}
}

function val_formul_franq() {
	var capcha = igualar2();
	tabla = document.getElementById("formul2");
	//nombre
	var valor4 = document.getElementById("txt_nombre").value;
	if( valor4 == null || valor4.length == 0 || /^\s+$/.test(valor4) ) {
		alert("por favor ingrese los datos correspondientes al campo referido");
		tabla.rows[0].cells[0].bgColor = "#FF9797";
		tabla.rows[0].cells[1].bgColor = "#FF9797";
		document.getElementById("nombres").focus();
		return false;
	}else{
		tabla.rows[0].cells[0].bgColor = null;
		tabla.rows[0].cells[1].bgColor = null;
	}
	//tipodni
	var opcion = document.getElementById("opt_di");
	var indexSel = opcion.selectedIndex;
	var optSel = opcion.options[indexSel];
	var txtSel = optSel.text;
	var varSel = optSel.value;
	if( varSel == 0 ) {
		alert("por favor seleccione el tipo de documento");
		tabla.rows[1].cells[0].bgColor = "#FF9797";
		tabla.rows[1].cells[1].bgColor = "#FF9797";
		document.getElementById("opt_di").focus();
		return false;
	}else{
		tabla.rows[1].cells[0].bgColor = null;
		tabla.rows[1].cells[1].bgColor = null;
	}
	//nrodni
	var valordi = document.getElementById("txt_numero_di").value;
	if( valordi == null || valordi.length == 0 || /^\s+$/.test(valordi) ) {
		alert("por favor ingrese los datos correspondientes al campo referido");
		tabla.rows[2].cells[0].bgColor = "#FF9797";
		tabla.rows[2].cells[1].bgColor = "#FF9797";
		document.getElementById("txt_numero_di").focus();
		return false;
	}else{
		tabla.rows[2].cells[0].bgColor = null;
		tabla.rows[2].cells[1].bgColor = null;
	}
	//email
	var valor3 = document.getElementById("txt_email").value;
	if( !(/\w{1,}[@][\w\-]{1,}([.]([\w\-]{1,})){1,3}$/.test(valor3)) ) {
		alert("formato de email incorrecto");		
		tabla.rows[4].cells[0].bgColor = "#FF9797";
		tabla.rows[4].cells[1].bgColor = "#FF9797";
		document.getElementById("txt_email").focus();
		return false;
	}else{
		tabla.rows[4].cells[0].bgColor = null;
		tabla.rows[4].cells[1].bgColor = null;
	}

	var valor5 = document.getElementById("txt_asunto").value;
	if( valor5 == null || valor5.length == 0 || /^\s+$/.test(valor5) ) {
		alert("por favor ingrese los datos correspondientes al campo referido");
		tabla.rows[5].cells[0].bgColor = "#FF9797";
		tabla.rows[5].cells[1].bgColor = "#FF9797";
		document.getElementById("txt_asunto").focus();
		return false;
	}else{
		tabla.rows[5].cells[0].bgColor = null;
		tabla.rows[5].cells[1].bgColor = null;
	}

	var valor6 = document.getElementById("txt_body").value;
	if( valor6 == null || valor6.length == 0 || /^\s+$/.test(valor6) ) {
		alert("por favor ingrese los datos correspondientes al campo referido");
		tabla.rows[6].cells[0].bgColor = "#FF9797";
		tabla.rows[6].cells[1].bgColor = "#FF9797";
		document.getElementById("txt_body").focus();
		return false;
	}else{
		tabla.rows[6].cells[0].bgColor = null;
		tabla.rows[6].cells[1].bgColor = null;
	}
	if (capcha == 1) {
		document.form2.submit();
	}else if (capcha == 0){
		alert("el código ingresado no es correcto, por favor verifique bien el código e intente de nuevo");
	}
}

function ventimpr(valor1, valor2) {
	window.open('formatoprt.php?id='+valor1+'&num='+valor2, '', 'width=600, height=500, scrollbars=YES');
}

function aux1() {
	window.open('formatoprt.html', '', 'width=600, height=500, scrollbars=YES');
}

function aux2() {
	window.open('formatoprt1.html', '', 'width=600, height=500, scrollbars=YES');
}

function aux3() {
	window.open('formatoprt2.html', '', 'width=600, height=500, scrollbars=YES');
}

function aux4() {
	window.open('formatoprt3.html', '', 'width=600, height=500, scrollbars=YES');
}

function aux5() {
	window.open('formatoprt5.html', '', 'width=600, height=500, scrollbars=YES');
}

function aux6() {
	window.open('formatoprt6.html', '', 'width=600, height=500, scrollbars=YES');
}
function aux7() {
	window.open('formatoprt7.html', '', 'width=600, height=500, scrollbars=YES');
}
function aux8() {
	window.open('formatoprt8.html', '', 'width=600, height=500, scrollbars=YES');
}
function aux9() {
	window.open('formatoprt9.html', '', 'width=600, height=500, scrollbars=YES');
}
function aux10() {
	window.open('formatoprt10.html', '', 'width=600, height=500, scrollbars=YES');
}
function aux11() {
	window.open('formatoprt11.html', '', 'width=600, height=500, scrollbars=YES');
}
function aux12() {
	window.open('formatoprt12.html', '', 'width=600, height=500, scrollbars=YES');
}
function aux13() {
	window.open('formatoprt13.html', '', 'width=600, height=500, scrollbars=YES');
}
function ventana_exist() {
	if (!ventana_c) {
		abreVentana();
	}else{
		ventana_c.close();
		setTimeout("abreVentana()", 1200);
	}
}

function abreVentana() {
	ventana_c = ventana_pop2('../../evento.html', 200, 300);
	ventana_c.setZIndex(50);
}

// captcha
function clickear(){
	var numeros=new Array("1","2","3","4","5","6","7","8","9");
	var letras=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z");
	var n1= Math.floor(Math.random()*9);
	var c1=numeros[n1];
	var n2= Math.floor(Math.random()*25);
	var c2=letras[n2];
	var n3= Math.floor(Math.random()*25);
	var c3=letras[n3];
	var n4= Math.floor(Math.random()*9);
	var c4=numeros[n4];
	var n5= Math.floor(Math.random()*25);
	var c5=letras[n5];
	var cadena=c1+c2+c3+c4+c5;
	//document.images('imagen').src='antispamex01.php?cadena='+cadena;
	document.getElementById('imagen').src='';
	document.getElementById('imagen').src='scripts/antispam/antispamex01.php?cadena='+cadena;
	document.form1.oculto.value=cadena;
}
function igualar(){
	document.form1.txtcaptcha.value=document.form1.txtcaptcha.value.toUpperCase();
	valor1=document.form1.txtcaptcha.value;
	valor2=document.form1.oculto.value;
	if(valor1==valor2){
		alert("Los valores son iguales");
	} else {
		alert("Los valores son diferentes");
	}
}

function clickear2(){
	var numeros=new Array("1","2","3","4","5","6","7","8","9");
	var letras=new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z");
	var n1= Math.floor(Math.random()*9);
	var c1=numeros[n1];
	var n2= Math.floor(Math.random()*25);
	var c2=letras[n2];
	var n3= Math.floor(Math.random()*25);
	var c3=letras[n3];
	var n4= Math.floor(Math.random()*9);
	var c4=numeros[n4];
	var n5= Math.floor(Math.random()*25);
	var c5=letras[n5];
	var cadena=c1+c2+c3+c4+c5;
	//document.images('imagen').src='antispamex01.php?cadena='+cadena;
	document.getElementById('imagen2').src='';
	document.getElementById('imagen2').src='scripts/antispam/antispamex01.php?cadena='+cadena;
	document.form2.oculto2.value=cadena;
}
function igualar2(){
	document.form2.txtcaptcha2.value=document.form2.txtcaptcha2.value.toUpperCase();
	valor1=document.form2.txtcaptcha2.value;
	valor2=document.form2.oculto2.value;
	if(valor1==valor2){
		return 1;
		} else {
		return 0;
	}
}

function goingTime() {
	var mydate=new Date();
	var year=mydate.getYear();
	if (year < 1000) {
		year+=1900;
	}
	var day=mydate.getDay();
	var month=mydate.getMonth();
	var daym=mydate.getDate();
	if (daym<10) {
		daym="0"+daym;
	}
	var dayarray=new Array("Domingo","Lunes","Martes","Mi&eacute;rcoles","Jueves","Viernes","S&aacute;bado");
	var montharray=new Array("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto","Septiembre","Octubre","Noviembre","Diciembre");
	var hours = mydate.getHours();
	if (hours<12) {
		meridiano = "am";
	}else{
		meridiano = "pm";
	}
	var tmin = mydate.getMinutes();
	if(tmin<10) {
		minutes = "0"+tmin;
	}else{
		minutes = tmin;
	}
	
	document.getElementById("horap").innerHTML = dayarray[day]+" "+daym+" de "+montharray[month]+" del "+year+", "+hours+":"+minutes+" "+meridiano;
	setTimeout("goingTime()", 60000);
}

//con la libreria protoype window cargamos las paginas de colegio y/o academia segun sea el caso
function div_loader_ca() {
	var scrwidth=screen.width;
	var win = new Window({className: "default", title: "",top:420, left:(scrwidth/2)-480, width:937, height:600, destroyOnClose: true, recenterAuto:false, draggable:false, rezisable:false, minimizable:false, maximizable:false, url: weblocaljs});
win.show(); 
}
