// JavaScript Document
var i=0,j=0,k=0,tiempo,tiempo2;
var img_menu, antemenu="Opc";
var dms = 1;
var wwwroot = "http://www.uv.mx/";
var img_menu = wwwroot + "images/interiorUV/";
// Variable que contendrá toda la estructura del menu, y estará conformado por Object, para asignarle atributos.
var MP;
// Variable que sirve como contador del menu, para insertar a través de la funcion AgregaMenu()
var cm= new Object(3);
	cm.m = 0;
	cm.s2 = 0;

var submenuactual = "";

/*$(document).ready(function() {
	$('a[class="tblank"]').click( function() { this.target = "_blank"; });
});*/


function AgregaMenu(tipo,nombre,texto,liga,destino,px) {
var url = new String( document.location );
	if (tipo=="menu") {
		if (cm.m==0)
			MP = new Array();
		MP[cm.m] = new Object(7);
		MP[cm.m].submenu = new Array();	
		MP[cm.m].nombre = nombre;
		MP[cm.m].texto = texto;
		if (liga.substring(0,7)=="http://")
			MP[cm.m].liga = liga;
		else if(liga=="#")
			MP[cm.m].liga = url + "#";
		else
			MP[cm.m].liga = wwwroot + liga;
		MP[cm.m].destino = destino;
		if (px>0)
			MP[cm.m].px = px;
		cm.m++;
		cm.s2=0;
	}
	
	if (tipo=="sub2") {		
		if (cm.s2==0) {
			MP[cm.m-1].submenu = new Array();
			MP[cm.m-1].tsubm = 1;
		}
		MP[cm.m-1].submenu[cm.s2] = new Object(7);		
		MP[cm.m-1].submenu[cm.s2].nombre = nombre;
		MP[cm.m-1].submenu[cm.s2].texto = texto;
		if (liga.substring(0,7)=="http://")
			MP[cm.m-1].submenu[cm.s2].liga = liga;
		else if(liga=="#")
			MP[cm.m-1].submenu[cm.s2].liga = url + "#";
		else
			MP[cm.m-1].submenu[cm.s2].liga = wwwroot + liga;
		MP[cm.m-1].submenu[cm.s2].destino = destino;
		if (px>0)
			MP[cm.m-1].submenu[cm.s2].px = px;
		cm.s2++;
	}
	
}

//AgregaMenu("tipo menu","nombre","imagen","liga","destino",ubicacion_submenu);

AgregaMenu("menu","menuuniversidad","Universidad","universidad/info/menuindex.html","",0);
	AgregaMenu("sub2","subuvacerca","Acerca de la UV","universidad/info/menuindex.html","");
	AgregaMenu("sub2","subuvdependencias","Entidades y dependencias","universidad/dependencias/","");
	AgregaMenu("sub2","subuvautoridades","&Oacute;rganos colegiados","universidad/autoridades/menuindex.html","",230);
	AgregaMenu("sub2","subuvmensaje","Mensaje del Rector","universidad/mensaje/index.html","");
	AgregaMenu("sub2","subuvdocumentos","Documentos","universidad/doctosofi/menuindex.html","",245);
	AgregaMenu("sub2","subuvdirectorio","Directorio","universidad/directorio/","");
	//AgregaMenu("sub2","subuvdepartamentalizacion","Departamentalizaci&oacute;n","departamentalizacion/","");
	//AgregaMenu("sub2","subuvorganigrama","Estructura Org&aacute;nica","orgmet/nuv/organigrama/index.html","");

AgregaMenu("menu","menuoferta","Docencia","entidades/menuindex.html","",4);
	AgregaMenu("sub2","subofacultades","Entidades acad&eacute;micas","entidades/menuindex.html","");
	AgregaMenu("sub2","suboprogramas","Oferta educativa","oferta/programas/licenciaturas/menuindex.htm","");
	AgregaMenu("sub2","suboposgrado","Posgrado","posgrado/index.html","");
	AgregaMenu("sub2","subocalendario","Calendario","escolar/calendarios/oferta_escolarizado.php","");
	
AgregaMenu("menu","menuinvestigacion","Investigaci&oacute;n","invest/index.html","",154);
	AgregaMenu("sub2","subinuevopapel","Papel de la investigaci&oacute;n","invest/","");
	AgregaMenu("sub2","subiinstitutos","Institutos y centros","invest/institutos.html","");
	AgregaMenu("sub2","subiboletin","Bolet&iacute;n","invest/boletin/","");	

AgregaMenu("menu","menudifusion","Difusi&oacute;n y Extensi&oacute;n","difyext/grupos/","",154);
	AgregaMenu("sub2","subddivulgacion","Vinculaci&oacute;n","vincula/","");
	AgregaMenu("sub2","subdeditorial","Difusi&oacute;n cultural","difyext/cultural.html","");
	AgregaMenu("sub2","subddaduv","Actividades deportivas","daduv/","_blank");
	AgregaMenu("sub2","subdscom","Servicios a la comunidad","servicios/comunidad.html","_blank");
	AgregaMenu("sub2","subdsuni","Servicios universitarios","servicios/universitarios.html","_blank");

AgregaMenu("menu","menutransparencia","Transparencia","transparencia/index.html","",260);

AgregaMenu("menu","menudefensoria","Defensor&iacute;a","defensoria/index.html","",260);

AgregaMenu("menu","menueventos","Eventos","eventos/?","",550);
	AgregaMenu("sub2","subaveventos","Convocatorias y Eventos","eventos/?","");	
	AgregaMenu("sub2","subavlicitaciones","Licitaciones","transparencia/infpublica/licitaciones/","");


var consubmenu=0;
var Menu_Activo = MP[0].nombre;
var SubMenu3_Activo;
	var SubMenu_Activo;
	var mvalido=0,svalido=0; //Variable para validar si el menú o submenú enviado como parámetro en una página es válido, esto para
						//indicar qué menú se va a "encender" o marcar como activo.

function menu_principal(color) {
	var Nombre_Submenu;
	var m_img_actual;
	var m_img_nueva;
	var destino_liga;
	
	Menu_Activo = document.getElementById('ImgMenuPrincipal').title;
	SubMenu_Activo = document.getElementById('ImgSubmenuPrincipal').title;
	SubMenu3_Activo = document.getElementById('ImgSubmenu3Nivel').title;
	Menu_Activo = Menu_Activo.toLowerCase();
	SubMenu_Activo = SubMenu_Activo.toLowerCase();
	SubMenu3_Activo = SubMenu3_Activo.toLowerCase();

	document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0' id='tabla_menu_principal' style='position:relative; top:1px; left:-1px'><tr><td>");
	
	//////// Generar pestañas superiores - menu principal ////////////////////////
	document.write("<ul id=MenuSuperiorPrincipal>");
	document.write("<li><a style='color:#0066FF' href='" + wwwroot + "'>Inicio</a></li>");
   	document.write("<li><div class='mmhide_SeparadorMenuPrincipal'></div></li>");
	for (i=0;i<MP.length;i++) {
			if (MP[i].tsubm==1) {
				document.write("<li><a href='" + MP[i].liga + "' id='" + MP[i].nombre  + "' onMouseOver=\"this.className='mmhide_MenuSuperiorPrincipal_Activo'; muestra_submenu('" + antemenu + MP[i].nombre + "')\" onMouseOut=\"this.className=''; oculta_submenu('" + MP[i].nombre + "')\">" + MP[i].texto + "</a></li>");
			}
			else {
		    	document.write("<li><a href='" + MP[i].liga + "' id='" + MP[i].nombre  + "' onMouseOver=\"this.className='mmhide_MenuSuperiorPrincipal_Activo'; oculta_todos_subm()\" onMouseOut=\"this.className=''; Muestra_Menu_Activo()\">" + MP[i].texto + "</a></li>");
			}
			if (i < (MP.length-1))
		    	document.write("<li><div class='mmhide_SeparadorMenuPrincipal'></div></li>");
	}
	document.write("</ul>");
	

	document.write("</td></tr>");

	document.write("<tr height=22><td valign=top>");
	///////// Generar Submenús - 2° Nivel ////////////
    document.write("<div id='SubMenuPrincipal' style='position:relative; left:0px; top:0px; width:700; height:20px; z-index:200;'>");	
		for (i=0;i<MP.length;i++) {
			if (MP[i].tsubm == 1) {
    			document.write("<div id='" + antemenu + MP[i].nombre + "' style='position:absolute; left:" + MP[i].px + "px; top:" + dms + "; width:100px; height:10px; z-index:201; visibility: hidden;' onMouseOver=\"en_el_submenu('" + MP[i].nombre + "')\" onMouseOut=\"oculta_submenu('" + MP[i].nombre + "')\">");
    			document.write("<table height='20' border='0' cellpadding='0' cellspacing='0'><tr>");
				for (j=0;j<MP[i].submenu.length;j++) {
						if (MP[i].submenu[j].destino!="")
								destino_liga = "target='" + MP[i].submenu[j].destino + "'";						
						else
							destino_liga = "";
						document.write("<td id='" + MP[i].submenu[j].nombre  + "'  nowrap  class='mmhide_SubMenuSuperiorPrincipal' onMouseOver=\"this.className='mmhide_SubMenuSuperiorPrincipal_Activo'\" onMouseOut=\"this.className='mmhide_SubMenuSuperiorPrincipal'\"><a href='" + MP[i].submenu[j].liga + "' " + destino_liga + ">" + MP[i].submenu[j].texto + "</a></td>");
/*						if (i<(MP.length-2)*/
							document.write("<td><div class='mmhide_SeparadorSubMenuPrincipal'></div></td>");							
				}
				document.write("</tr></table>");
				document.write("</div>");
			}
		}	
	document.write("</div>");	
	
	document.write("</td></tr></table>")
	
		for (i=0;i<MP.length;i++)
			if (MP[i].nombre==Menu_Activo) {
				mvalido=1;
				if (MP[i].tsubm==1)
					consubmenu=1;
			}
		
	for (i=0;i<MP.length;i++)
		for (j=0;j<MP[i].submenu.length;j++)
				if (MP[i].submenu[j].nombre==SubMenu_Activo)
					svalido=1;


	if (mvalido==1) {
		document.getElementById(Menu_Activo).className="mmhide_MenuSuperiorPrincipal_Activo";
		if (Menu_Activo != "menutransparencia")
			document.getElementById(antemenu + Menu_Activo).style.visibility="visible";
	}
	
	if (svalido==1) {
		document.getElementById(SubMenu_Activo).className="mmhide_SubMenuSuperiorPrincipal_Activo";
	}

}

function muestra_submenu(submenu_id) {
		clearTimeout(tiempo);
		oculta_todos_subm();
		document.getElementById(submenu_id).style.visibility="visible";
		submenuactual=submenu_id;
}

function en_el_submenu(submenu_id){
		clearTimeout(tiempo);
		if (mvalido==1)
			if (consubmenu==1)
				document.getElementById(antemenu + Menu_Activo).style.visibility="hidden";
		else
			document.getElementById(antemenu + MP[0].nombre).style.visibility="hidden";
		document.getElementById(antemenu + submenu_id).style.visibility="visible";
}

function oculta_submenu(submenu_id) {
		tiempo=setTimeout("o_submenu('" + submenu_id + "')",1000);
}

function o_submenu(submenu_id) {
		document.getElementById(antemenu + submenu_id).style.visibility="hidden";
		Muestra_Menu_Activo();
}

function oculta_todos_subm() {
		clearTimeout(tiempo);
		for (i=0;i<MP.length;i++) {
			if (MP[i].tsubm==1)
				document.getElementById(antemenu + MP[i].nombre).style.visibility="hidden"
		}
}

function Muestra_Menu_Activo() {
		oculta_todos_subm();
		if (Menu_Activo != "menutransparencia") {
			if (mvalido==1) {
				document.getElementById(antemenu + Menu_Activo).style.visibility="visible";
				document.getElementById(Menu_Activo).className="mmhide_MenuSuperiorPrincipal_Activo";
			}
			if (svalido==1)
				document.getElementById(SubMenu_Activo).className="mmhide_SubMenuSuperiorPrincipal_Activo";
		}
}

var dias=new Array("Domingo","Lunes","Martes","Mi&eacute;rcoles","Jueves ","Viernes","S&aacute;bado");
var meses=new Array("enero","febrero","marzo","abril","mayo","junio","julio","agosto","septiembre","octubre","noviembre","diciembre");

function getthedate() {
	var mifecha=new Date()
	var ano=mifecha.getYear()
	if (ano < 1000)
		ano+=1900
	var dia=mifecha.getDay()
	var mes=mifecha.getMonth()
	var diam=mifecha.getDate()
	var cfecha="&nbsp;&nbsp;"+dias[dia]+" "+diam+" de "+meses[mes]+" de "+ano+" "
    document.write(cfecha);
}

//Escribe el menú inferior que aparece en todas las páginas interiores
function menu_inferior() {
	document.write("<div id='MenuInferiorPrincipal'>");
	document.write("<a href='" + wwwroot  + "universidad/info/menuindex.html'>Universidad</a>");
	document.write("<a href='" + wwwroot  + "entidades/menuindex.html'>Docencia</a>");
	document.write("<a href='" + wwwroot  + "invest/'>Investigaci&oacute;n</a>");
	document.write("<a href='" + wwwroot  + "difyext/cultural.html'>Difusi&oacute;n y Extensi&oacute;n</a>");	
    document.write("<a href='" + wwwroot  + "transparencia/'>Transparencia</a>");
	document.write("<a href='" + wwwroot  + "defensoria/'>Defensor&iacute;a</a>");
	document.write("<a href='" + wwwroot  + "eventos/?'>Eventos</a><br />");
	document.write("PORTALES: ");
	document.write("<a href='" + wwwroot  + "dgda/menuindex.html' target='_blank'>Acad&eacute;micos</a>");
	document.write("<a href='" + wwwroot  + "administrativos/index.html' target='_blank'>Administrativos</a>");
	document.write("<a href='" + wwwroot  + "aspirantes/index.html' target='_blank'>Aspirantes</a>");
	document.write("<a href='" + wwwroot  + "directivos/index.html' target='_blank'>Directivos</a>");
	document.write("<a href='" + wwwroot  + "egresados/index.html' target='_blank'>Egresados</a>");
	document.write("<a href='" + wwwroot  + "estudiantes/index.html' target='_blank'>Estudiantes</a>");
	document.write("</div>");
}


function copyright_pie() {
	document.write("<span id='Copyright'>&#169; 2010 Universidad Veracruzana. Todos los derechos reservados<br>www.uv.mx</span>");
}

function abre( url ){
	 window.open( url,'plan',"scrollbars=1,menubar=0,resizable=0,width=820,height=600");
}

function abre2( url ){
	 window.open( url,'personal',"scrollbars=1,menubar=0,resizable=0,width=820,height=600");
}

function LogueoAcademicos(){
//	document.write("<iframe id='iFrame' name='iFrame' scrolling='si' frameborder='0' height='122' style='width:168px' src='http://dsia.uv.mx/portalesuv/Academicos'/></iframe>");
	document.write("<iframe id='iFrame' name='iFrame' scrolling='no' frameborder='0' height='153' style='width:168px' src='https://dsia.uv.mx/siiuuv/academicos/'/></iframe>");
}

function LogueoEstudiantes(){
	document.write("<iframe id='iFrame' name='iFrame' scrolling='si' frameborder='0' height='162' style='width:168px' src='http://148.226.1.33/siiuilog/'/></iframe>");
//	document.write("<iframe id='iFrame' name='iFrame' scrolling='si' frameborder='0' height='162' style='width:168px' src='https://dsia.uv.mx/siiuilog/'/></iframe>");
//	document.write("<iframe id='iFrame' name='iFrame' scrolling='si' frameborder='0' height='162' style='width:168px' src='http://148.226.1.35/SIIUIL/'/></iframe>");
//	document.write("<iframe id='iFrame' name='iFrame' scrolling='no' frameborder='0' height='158' style='width:168px' src='http://148.226.1.37/siiuuv/estudiantes/'/></iframe>");
}

function LogueoAdministrativos(){
//	document.write("<iframe id='iFrame' name='iFrame' scrolling='si' frameborder='0' height='122' style='width:168px' src='http://dsia.uv.mx/portalesuv/Administrativos'/></iframe>");
	document.write("<iframe id='iFrame' name='iFrame' scrolling='no' frameborder='0' height='163' style='width:168px' src='https://dsia.uv.mx/siiuuv/administrativos/'/></iframe>");
}

function LogueoAspirantes(){
	document.write("<iframe id='iFrame' name='iFrame' scrolling='si' frameborder='0' height='125' style='width:168px' src='http://148.226.1.35/siiuilprueba/'/></iframe>");
}

function LogueoDirectivos(){
//	document.write("<iframe id='iFrame' name='iFrame' scrolling='si' frameborder='0' height='122' style='width:168px' src='http://dsia.uv.mx/portalesuv/Autoridades'/></iframe>");
	document.write("<iframe id='iFrame' name='iFrame' scrolling='no' frameborder='0' height='163' style='width:168px' src='https://dsia.uv.mx/SIIUUV/Autoridades/'/></iframe>");
}

function LogueoEgresados(){
	document.write("<iframe id='iFrame' name='iFrame' scrolling='si' frameborder='0' height='145' style='width:168px' src='https://dsia.uv.mx/siiuuv/Egresados/'/></iframe>");
}


/* *********** Funciones para validar la forma (busqueda) de Google */
function trim(cadena) {
			for(i=0; i<cadena.length; )	{
				if(cadena.charAt(i)==" ")
				cadena=cadena.substring(i+1, cadena.length);
				else
					break;
			}
			for(i=cadena.length-1; i>=0; i=cadena.length-1)	{
				if(cadena.charAt(i)==" ")
					cadena=cadena.substring(0,i);
				else
					break;
			}
			document.forms[0].q.value = cadena;
			return cadena;
		}


function validar(form) {
				var forma = document.forms['FormaBusqueda'];
				if (document.forms['FormaBusqueda'].b[1].checked || document.forms['FormaBusqueda'].b[2].checked)
					document.forms['FormaBusqueda'].action = "/universidad/directorio/";
				if (document.forms['FormaBusqueda'].b[0].checked)
					document.forms['FormaBusqueda'].action = "/resultados.html";

				if (document.forms['FormaBusqueda'].q.value=="Búsqueda...")
					return false;
				if( trim(document.forms["FormaBusqueda"].q.value)=="" || document.forms["FormaBusqueda"].q.value==null || document.forms["FormaBusqueda"].q.value=="B&uacute;squeda..." )
					return false;	
				return true;
}

var cadena;
var pf = 0;

function getParams() {
	var url = new String( document.location );
	var idx = url.indexOf('?');
	var params = new Array();
	if (idx != -1) {
		
		var pairs = url.substring(idx+1, url.length).split('&');
		
		for (var i=0; i<pairs.length; i++) {
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = nameVal[1];
			if (nameVal[0] == 'q')
				pf = 1;
  		}
	}
	return params;
	
}

function OnLoadGoogle() {
// Create a search control      
			var searchControl = new GSearchControl();;       
 			
			// create a searcher options object
			// set up for open expansion mode
			// load a searcher with these options
			var options = new GsearcherOptions();
			options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
			
			//LARGE_RESULTSET means 8 results and SMALL_RESULTSET means 4result 
			//searchControl.setResultSetSize(GSearch.LARGE_RESULTSET)
			
			siteSearch = new GwebSearch();
    	    siteSearch.setUserDefinedLabel("Resultados de búsqueda"); // The label that appears on  your search 
			siteSearch.setUserDefinedClassSuffix("siteSearch");
			//siteSearch.setSiteRestriction("uv.mx"); 
			siteSearch.setSiteRestriction("018320151572338808723:15f9bvrzzus"); 
			searchControl.addSearcher(siteSearch, options);
	
			var options = new GdrawOptions();
			options.setSearchFormRoot(document.getElementById("searchForm"));
	
			// tell the searcher to draw itself and tell it where to attach    
		    searchControl.draw(document.getElementById("searchResults"), options);  
		
			params = getParams();
			
			if (pf == 1 ) {
				cadena = unescape(params["q"]);
				// execute an inital search  
				searchControl.execute(cadena);  
			}
			
			
  }

function GoogleLoad() {
  window.onload = OnLoadGoogle;
}

function links(){
	$('a[rel="external"]').click( function() {
			  this.target = "_blank";
	});
	
	$('a[class="tblank"]').click( function() {
			  this.target = "_blank";
	});
	$('a[class="oclima"]').click( function() {
			//window.open( $(this).attr('href') );
			window.open( $(this).attr('href'),'ventanauv', 'width=340,height=190');
			return false;
			//onclick="MM_openBrWindow('clima/clima_por_region.html','ventanauv','width=340,height=190')"
	});
}

function hoverlink (){
	$("#ColumnaCentral li").hover(function() {
			$(this).find('a').addClass("mmhide_Selected");
	} , function() {
			$(this).find('a').removeClass("mmhide_Selected");
	});
		$("#ColumnaCentralAbajo li").hover(function() {
			$(this).find('a').addClass("mmhide_Selected");
	} , function() {
			$(this).find('a').removeClass("mmhide_Selected");
	});
}

/*   *********** Fin funciones de Google  ************* */


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function GAnalytics() {
	var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
	document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	try {
		var pageTracker = _gat._getTracker("UA-4613180-2");
		pageTracker._trackPageview();
	}
	catch(err){}
}

