/*
*******************************************************************************
	PROCURADURÍA GENERAL DE LA REPÚBLICA
	COORDINACIÓN DE PLANEACIÓN, DESARROLLO E INNOVACIÓN INSTITUCIONAL
	DIRECCIÓN DE DESARROLLO DE INTERNET
	 
	DESARROLLADOR: LIC. GONZALO RODRÍGUEZ LARA
*******************************************************************************
*/


//función para enviar a un documento y destino deseado
function go2URL(address,target)
{
	window.open(address,target);
}


//función para abrir una nueva ventana
function newWindow(address)
{
	var maxW = screen.width;
	var maxH = screen.height;
	var w = 800;
	var h = 600;
	var _top = Math.floor((maxH - h) / 2);
	var _left = Math.floor((maxW - w) / 2);
	
	var win = window.open(address,'doiW',"toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width="+w+",height="+h);
	win.moveTo(_left,_top);
	win.focus();
}


//función para abrir una nueva ventana con las características deseadas
function xy_openNewWindow(URLtoOpen, windowName, windowFeatures, win_width, win_height, pos_x, pos_y){
	if (windowName == null || windowName == '' ) windowName='newwindow';
	if (win_width == null || win_width == '' ) win_width=600;
	if (win_height== null || win_height == '' ) win_height=400;		
	if (windowFeatures==null || windowFeatures == '' ) windowFeatures='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no';
	if ( pos_x==null || pos_x == '') {
	scr_width=screen.availWidth;
	pos_x=parseInt(scr_width-win_width-10);
	}
	if (pos_y==null || pos_y=='') {
	scr_height=screen.availHeight;
	pos_y=parseInt((scr_height-win_height)/2);
	}
	options=windowFeatures+",width="+win_width+",height="+win_height+",left="+pos_x+",top="+pos_y;
	newWindow=window.open(URLtoOpen, windowName, options);
	newWindow.focus();
}

//función para abrir una nueva ventana activando 
function yz_openNewWindow(URLtoOpen, windowName, windowFeatures, win_width, win_height, pos_x, pos_y){
	if (windowName == null || windowName == '' ) windowName='newwindow';
	if (win_width == null || win_width == '' ) win_width=600;
	if (win_height== null || win_height == '' ) win_height=400;		
	if (windowFeatures==null || windowFeatures == '' ) windowFeatures='toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no';
	if ( pos_x==null || pos_x == '') {
	scr_width=screen.availWidth;
	pos_x=parseInt(scr_width-win_width-10);
	}
	if (pos_y==null || pos_y=='') {
	scr_height=screen.availHeight;
	pos_y=parseInt((scr_height-win_height)/2);
	}
	options=windowFeatures+",width="+win_width+",height="+win_height+",left="+pos_x+",top="+pos_y;
	newWindow=window.open(URLtoOpen, windowName, options);
	newWindow.focus();
}

//función para abrir una nueva ventana con las características deseadas en Temas Relevantes
function xy_openNewWindowTR(URLtoOpen, windowName, windowFeatures, win_width, win_height, pos_x, pos_y){
	if (windowName == null || windowName == '' ) windowName='newwindow';
	if (win_width == null || win_width == '' ) win_width=760;
	if (win_height== null || win_height == '' ) win_height=500;		
	if (windowFeatures==null || windowFeatures == '' ) windowFeatures='toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no';
	if ( pos_x==null || pos_x == '') {
	scr_width=screen.availWidth;
	pos_x=parseInt(scr_width-win_width-10);
	}
	if (pos_y==null || pos_y=='') {
	scr_height=screen.availHeight;
	pos_y=parseInt((scr_height-win_height)/2);
	}
	options=windowFeatures+",width="+win_width+",height="+win_height+",left="+pos_x+",top="+pos_y;
	newWindow=window.open(URLtoOpen, windowName, options);
	newWindow.focus();
}


//función que despliega los objetos multimedia en la sección 'multimedios' dentro de un documento (mov,mp3,wma,jpg,gif,png)
function displayMultimedia(idSection, URLtoOpen, sType, sWidth, sHeight)
{
	if (sType == 'mov' || sType == 'wmv') {
		strHTML = "<embed src='"+URLtoOpen+"' width='"+sWidth+"' height='"+sHeight+"'></embed>"
	} else if (sType == 'flv'){
		strHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='"+sWidth+"' height='"+sHeight+"' id='flv' align='middle'>";
		strHTML = strHTML + "<param name='allowScriptAccess' value='sameDomain' />";
		strHTML = strHTML + "<param name='movie' value='"+URLtoOpen+"' />";
		strHTML = strHTML + "<param name='quality' value='high' />";
		strHTML = strHTML + "<param name='bgcolor' value='#ffffff' />";
		strHTML = strHTML + "<embed src='"+URLtoOpen+"' quality='high' bgcolor='#ffffff' width='"+sWidth+"' height='"+sHeight+"' name='flv' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
	} else if (sType == 'mp3'){
		strHTML = "<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' id='mediaController' width='"+sWidth+"' height='"+sHeight+"' align='middle'>";
		strHTML = strHTML + "<param name='allowScriptAccess' value='sameDomain' />";
		strHTML = strHTML + "<param name='movie' value='"+URLtoOpen+"' /><param name='quality' value='high' /><param name='salign' value='lt' /><param name='bgcolor' value='#ffffff' /><embed src='"+URLtoOpen+"' quality='high' salign='lt' bgcolor='#ffffff' width='"+sWidth+"' height='"+sHeight+"' swLiveConnect=true id='mediaController' name='mediaController' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' />";
		strHTML = strHTML + "</object>";
	} else if (sType == 'wma'){
		strHTML = "<embed src='"+URLtoOpen+"' width='"+sWidth+"' height='"+sHeight+"'></embed>"
	} else {
		strHTML = "<img src='"+URLtoOpen+"' width='"+sWidth+"' height='"+sHeight+"' />";
	}
	//alert(strHTML);
	
	document.getElementById(idSection).innerHTML = strHTML;
}


//función que despliega los objetos Fecha en la sección 'Fecha' 
function displayFecha(idSection, dia, mes, anio)
{
	
		strHTML = ""+dia+" de "+mes+" de "+anio+"";
	//alert(strHTML);
	
	document.getElementById(idSection).innerHTML = strHTML;
}

//fucnión que inicializa el valor de un cuadro de texto en un formulario
function textClear(nameObject)
{
	document.getElementById(nameObject).value = "";
}


//función que asigna un valor a un cuadro de texto en un formulario
function textRestore(nameObject, strValue)
{
	if (document.getElementById(nameObject).value == ""){
		document.getElementById(nameObject).value = strValue;
	}
}


//función que verifica que el cuadro de texto contenga un criterio de búsqueda
function checkFormbusca(){
	if ( document.formbusca.SearchString.value == "" || document.formbusca.SearchString.value == "Buscar"){
		alert("Por favor proporcione el criterio de búsqueda");
		document.formbusca.SearchString.focus();
		return false;
	}
	item_seleccionado= 1;
	// selección de tipo de búsqueda
	/*item_seleccionado=document.formbusca.SearchType.selectedIndex+1;
	if (item_seleccionado == 4){
	item_seleccionado = 0;
	}*/
	document.formbusca.action="Query.asp?SearchType="+item_seleccionado;
	document.formbusca.submit();
	return false;
}


//función que verifica que la direccción de correo este bien escrita
function emailCheck (emailStr, sendform) {
var checkTLD=1;
var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
var emailPat=/^(.+)@(.+)$/;
var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
var validChars="\[^\\s" + specialChars + "\]";
var quotedUser="(\"[^\"]*\")";
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
var atom=validChars + '+';
var word="(" + atom + "|" + quotedUser + ")";
var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
var matchArray=emailStr.match(emailPat);

if (matchArray==null) {
	alert("La dirección de Email es incorrecta (cheque su @ y .)");
	return false;
}

var user=matchArray[1];
var domain=matchArray[2];

for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
		alert("Este Nombre de usuario(username) contiene caracteres inválidos.");
		return false;
   }
}

for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
		alert("Este nombre de dominio(domain name) contiene caracteres inválidos.");
		return false;
   }
}

if (user.match(userPat)==null) {
	alert("El nombre de usuario parece no ser válido.");
	return false;
}

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

	for (var i=1;i<=4;i++) {
		if (IPArray[i]>255) {
			alert("La dirección IP destino es inválida!");
			return false;
	   }
	}
	if (sendform == true){
		document.formx.submit();
		return true;
	} 
	return true;
}
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
alert("El nombre de dominio parece no ser válido.");
return false;
   }
}

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
alert("La dirección debe terminar con un dominio conocido o dos letras " + "ciudad.");
return false;
}

if (len<2) {
alert("La dirección no tiene nombre de host");
return false;
}

if (sendform == true){
	document.formx.submit();
	return true;
}
return true;
}


//función para envío de recomendación desde liga de página
function recommends(url){
	xy_openNewWindow(url+'?url='+document.location, 'myWin', '', '130', '175', '0', '0')
}


function viewTable(ntabla){

	var maxW = screen.width;
	var maxH = screen.height;
	
	if (ntabla == 1){
		w = 600;
		h = 170;
	} else if (ntabla == 2){
		w = 660;
		h = 220;
	} else if (ntabla == 3){
		w = 630;
		h = 20;
	} else if (ntabla == 4){
		w = 660;
		h = 250;
	} 
	
	temp = document.getElementById(ntabla).innerHTML;

	var _top = Math.floor((maxH - h) / 2);
	var _left = Math.floor((maxW - w) / 2);
	
	preWindow= open('', 'previewWindow', 'width='+w+',height='+h+',status=no,scrollbars=no,resizable=no,toolbar=no,menubar=no,left='+_left+',top='+_top);
	
	preWindow.document.open();
	preWindow.document.write(temp);
	preWindow.moveTo(_left,_top);
	preWindow.focus();
	preWindow.document.close();
}


//función para desplegar los menús de años anteriores de la sección de comunicación social
function showHistorical(tRcd,st,sMonth,sYear)
{
if (tRcd == 1){
	_newLoc = "plantilla.asp?tRcd="+tRcd+"&sMonth="+sMonth+"&sYear="+sYear
} else if (tRcd == 2){
	_newLoc = "plantilla.asp?tRcd="+tRcd+"&st="+st+"&sYear="+sYear
} else if (tRcd == 3){
	_newLoc = "plantilla.asp?tRcd="+tRcd+"&sYear="+sYear
} else if (tRcd == 4){
	_newLoc = "plantilla.asp?tRcd="+tRcd+"&sMonth="+sMonth+"&sYear="+sYear
}

document.location=_newLoc; 
}


//función para deslpegar las sección de derechos de privacidad en la página
function displayPrivacy(nameObject, action)
{
	document.getElementById(nameObject).style.display = action;
}


//función para el organigrama (desplegar u ocultar secciones)
function displaySection(section)
{
	if (section == 1) {
		document.getElementById("curriculum").style.display = 'inline';
		document.getElementById("scurriculum").className = 'current';
		document.getElementById("funciones").style.display = 'none';
		document.getElementById("sfunciones").className = '';
		document.getElementById("areas").style.display = 'none';
		document.getElementById("sareas").className = '';
	} else if (section == 2){
		document.getElementById("curriculum").style.display = 'none';
		document.getElementById("scurriculum").className = '';
		document.getElementById("funciones").style.display = 'inline';
		document.getElementById("sfunciones").className = 'current';
		document.getElementById("areas").style.display = 'none';
		document.getElementById("sareas").className = '';
	} else {
		document.getElementById("curriculum").style.display = 'none';
		document.getElementById("scurriculum").className = '';
		document.getElementById("funciones").style.display = 'none';
		document.getElementById("sfunciones").className = '';
		document.getElementById("areas").style.display = 'inline';
		document.getElementById("sareas").className = 'current';
	}
	
}


function genGallery()
{
var myImages = new Array ('gallery_01.jpg','gallery_02.jpg','gallery_03.jpg','gallery_04.jpg','gallery_05.jpg','gallery_06.jpg','gallery_07.jpg','gallery_08.jpg','gallery_09.jpg','gallery_10.jpg');
var strlinks = "";
var j = 1;

//alert(myImages.length);

	for (var i=0; i < myImages.length; i++){
		strlinks = strlinks + "<a href=\"javascript:displayMultimedia('multimedios', '/prensa/2007/galeria/"+myImages[i]+"', 'img', '400', '267')\" class='fecha_portal'>"+j+"</a>";
		j += 1;
		if (i <= myImages.length-2){
			strlinks = strlinks + " | "
		}
	}

	strlinks += "<img src='/imgs/spacer_blue.gif' width='10' height='10''/>";
	
	document.getElementById("fecha").innerHTML = strlinks;
	displayMultimedia("multimedios", "/prensa/2007/galeria/"+myImages[0], "img", "400", "267");
}



function viewBol(){
	
var sumTab1 = 0;
var sumTab2 = 0;
var flag = false;

var sUrl = new Array();
sUrl[0] = "http://localhost/"
sUrl[1] = "http://www.pgr.gob.mx/"
sUrl[2] = "http://wwwnew.pgr.gob.mx/"
sUrl[3] = "http://10.3.194.11/"
sUrl[4] = "http://localhost/index.asp"
sUrl[5] = "http://www.pgr.gob.mx/index.asp"
sUrl[6] = "http://wwwnew.pgr.gob.mx/index.asp"
sUrl[7] = "http://10.3.194.11/index.asp"

dir = document.location;
dir = dir.toString();
dir = dir.toLowerCase();

strLink = "<div align='right'><a href='/prensa/prensa.asp' class='ver_todas'>ver todas +</a></div>";
	
	
for (var i = 0; i < sUrl.length; i++) {
	if (sUrl[i] == dir ) {
		flag = true;
		break;
	}
}	
	
if (flag){
	
	sumTab1 = document.getElementById("Licitation").clientHeight + document.getElementById("InfPub").clientHeight + 20;
	sumTab2 = document.getElementById("new1").clientHeight + document.getElementById("new2").clientHeight + document.getElementById("new3").clientHeight + 10;
	
	//alert("new1="+document.getElementById("new1").clientHeight+" new2="+document.getElementById("new2").clientHeight+" new3="+document.getElementById("new3").clientHeight)
	
	if (sumTab2 <= sumTab1){
		document.getElementById("new3").style.display = "inline";
		/*alert("Licit="+document.getElementById("Licitation").clientHeight+" Infpub="+document.getElementById("InfPub").clientHeight);
		alert("new1="+document.getElementById("new1").clientHeight+" new2="+document.getElementById("new2").clientHeight+" new3="+document.getElementById("new3").clientHeight)
		alert("sumTab1="+sumTab1+", sumTab2="+sumTab2);*/
		document.getElementById("vertodas2").innerHTML = strLink;
	} else {
		document.getElementById("new3").style.display = "none";
		//alert("sumTab1="+sumTab1+", sumTab2="+sumTab2);
		document.getElementById("vertodas1").innerHTML = strLink;
	}
}
}


//función para descargar cualquier tipo de archivo del sitio
function descargar(downfile){ 
 Url= "http://200.23.176.186/multimedia/downloadFile.asp?n2=" + downfile 
  go2URL(Url,'downloadFile')
} 


//función para desplegar u ocultar textos dentro de los formularios de los correos electrónicos
var active = false;

function displayRules()
{
	if (active == false) {
		document.getElementById("nota").style.display = 'inline';
		active = true;
	} else {
		document.getElementById("nota").style.display = 'none';
		active = false;
	}
	
}