//<input name="nombre" value="" onchange="parent.document.getElementById('forma').obtenido.value=this.value" />
//<input name="nombre" value="" onkeyup="parent.document.getElementById('forma').obtenido.value=this.value" />
var IE = document.all ? true : false;

var posicX = 0
var posicY = 0
var moverPO = false;
var divMoverPO = "";//divPO_1
var zIndexPO=0;
var num_div=new Array();
var offsetPO=0;
var e_ext;
var shiftKey=false;
var scrollTop;
var scrollLeft;
var he_temp="0px";
var valLoadPage = true;
var NoSoportaPpp= false;

function select_f(e)
	{ 
	if(IE)
		{ 
		if (event.shiftKey)
			shiftKey=true;
		else
			shiftKey=false;
		}
	else
		{
		if (e.shiftKey)
			shiftKey=true;
		else
			shiftKey=false;
		}
	if(moverPO) 
		return false;	
	}
	
	
function geElId(div1){
		var divMoverPO = div1;
		//var tool;
		//alert (divMoverPO);

		if (divMoverPO  == null ||  divMoverPO == '' ){
			//alert ("5");
			return false;
			//return true;
		}
		else{
			//alert ("4");
			//tool = Val;
			return true;
		}
}
	
	
	
function movDivPO(e)
	{
	
	e_ext=e;
	
	mover_new=true;
	if( document.body && document.body.scrollTop )
		scrollTop = document.body.scrollTop
	else if( document.documentElement && document.documentElement.scrollTop )
		scrollTop = document.documentElement.scrollTop;
	else
		scrollTop = 0;

	if( document.body && document.body.scrollLeft )
		scrollLeft= document.body.scrollLeft;
	else if( document.documentElement && document.documentElement.scrollLeft )
		scrollLeft= document.documentElement.scrollLeft;
	else
		scrollLeft= 0;

	//scrollTop = Math.max(document.body.scrollTop, document.documentElement.scrollTop);
	//scrollLeft= Math.max(document.body.scrollLeft, document.documentElement.scrollLeft);
	if(IE)							//	IE
		{ 	
		posicX = event.clientX + scrollLeft; 
		posicY = event.clientY + scrollTop; 
		if (event.button==0)
			mover_new=false;
		}
	else							//	FF, NS y los demas
		{
		// al parecer mozilla no requiere el scrollTop
		posicX = e_ext.pageX; 
		posicY = e_ext.pageY; 
		}
	if (posicX < 0) {posicX = 0};
	if (posicY < 0) {posicY = 0};
	
	if (geElId(divMoverPO)){
		var tool = document.getElementById(divMoverPO);
		}
	
	//alert (tool);
	
//	var tool = document.getElementById(divMoverPO);
	//alert (typeof (tool));
	//alert ("valor tool:"+divMoverPO);
	/*if (tool == null){
		return false;
	}
	*/
	//var tool = document.getElementById(divMoverPO)
	//alert ("valor tool:"+divMoverPO);
	if (tool && typeof (tool == "undefined") && tool.style.visibility !='hidden' && mover_new)
	{
		//alert("1");
		var_izq = posicX-(parseInt(tool.style.width)/2)-offsetPO;
		var_top = posicY;
		var_top = var_top-10;
		//tomando el cuenta el scroll
	//	var_top+=scrollTop;
		//var_izq+=scrollLeft;
		
		if (moverPO && divMoverPO!="")
		{
			tool= document.getElementById(divMoverPO);
			if( tool )
			{
				tool.style.top=var_top+"px";
				tool.style.left=var_izq+"px";
			}
		}
	}
	else
		moverPO=false;
	return true
	}
function focoPO()
	{
	zIndexPO++;
	if( !document.getElementById(divMoverPO) )
		return;
	document.getElementById(divMoverPO).style.visibility='visible';
	document.getElementById(divMoverPO).style.display='';
	document.getElementById(divMoverPO).style.zIndex=zIndexPO;
	}

function moverIniPO(div)
	{
	if(IE) {						//	IE
		posicX = event.clientX +scrollLeft; posicY = event.clientY +scrollTop;
	}
	else { posicX = e_ext.pageX; posicY = e_ext.pageY; }			//	FF, NS y los demas
	if (posicX < 0) {posicX = 0};
	if (posicY < 0) {posicY = 0};
	divMoverPO=div;	
	moverPO=true;
	if( !document.getElementById(divMoverPO) )
		return;

	offsetPO=posicX-(parseInt(document.getElementById(divMoverPO).style.left))-(parseInt(document.getElementById(divMoverPO).style.width)/2);
	//he_temp = document.getElementById(divMoverPO).style.height;
//	document.getElementById("frame_"+divMoverPO.split("_")[1]).style.display="none";
	//document.getElementById(divMoverPO).style.height="20px";
	focoPO();
		
	}

function restaura_tam()
	{
//	document.getElementById("frame_"+divMoverPO.split("_")[1]).style.display="block";
/*	if(!IE)
		{
		document.getElementById(divMoverPO).style.height = he_temp;
		//i_frame.style.height=( parseInt(i_frame.style.height)-30 ) +"px";
		document.getElementById("div_cab_"+divMoverPO.split("_")[1]).style.zIndex = ++zIndexPO;
		}
	else
		document.getElementById(divMoverPO).style.height = he_temp;*/
	}
function calcula_pantalla() 
	{	
	medidas=new Array();
	medidas["width"]=0;
	medidas["height"]=0;
    if (window.innerWidth) 
		{
		medidas["width"] = window.innerWidth - 20;
		medidas["height"] = window.innerHeight;
		}
	else if (document.documentElement && document.documentElement.clientWidth) 
		{
		medidas["width"] = document.documentElement.clientWidth;
		medidas["height"] = document.documentElement.clientHeight;
		}
	else if (document.body && document.body.clientWidth) 
		{
		medidas["width"] = document.body.clientWidth;
		medidas["height"] = document.body.clientHeight;
		}
	medidas["height"]=medidas["height"]-5;
	medidas["width"]=medidas["width"]-5;
	return medidas;
	}

	//inicio cambios realizados por carlos
	
function ValidaCarga(){
	valLoadPage = false;
}	
	
function popupPP(src, width, height, titulo)
	{
	val_ret=new Array();
	tam_pantalla=calcula_pantalla();	
	//tam_pantalla["width"]
	//tam_pantalla["height"]
	color_background_PO = "";
	
		
	if (NoSoportaPpp || shiftKey || valLoadPage)
	{
		popUpExtW(src, width, height);
		return;
	}
	
	if( tam_pantalla_disponible=calcula_pantalla_disponible() )
		{
		
		if (tam_pantalla["width"] < width || tam_pantalla["height"] < height)
			{
			popUpExtW(src, width, height)
			return;
			}
		}
	if (jQuery.browser.msie) 
	{ 
		if(parseInt(jQuery.browser.version)<= 6 )
		{
			popUpExtW(src, width, height);
			return;
		}	
	} 	
		
		////*****////
		
		nuevo=true;
		for (src_div in num_div)
		{
		 if (num_div[src_div]==src)
		 	{
			divMoverPO="divPO_"+src_div;			
			nuevo=false;
			break;
			}			
		}
		if(nuevo)
		{
			divMoverPO="divPO_"+num_div.length;		
			num_div[num_div.length]=src;
		}
		
		var obj_dl=
			{
				width : width,
				height : height,
				title : titulo,
				buttons : {},
				resizable : false,
				autoOpen: true
			}
		
		    dialog_qn(divMoverPO,obj_dl);
            var contenid_form_modal =  "<iframe id='frame_"+num_div.length+"' frameborder='0' src="+src+" style='width:"+(width-31)+"px; height:"+(height-60)+"px;'></iframe>";
            $('#'+divMoverPO).html(contenid_form_modal);
            var arr_parents = $('#'+divMoverPO).parents(".ui-dialog");
			var boton_recargar  = '<a onMouseover="$(this).toggleClass(\'ui-state-hover\')" onMouseout="$(this).toggleClass(\'ui-state-hover\')" class="ui-state ui-corner-all" href="#" unselectable="on" style="-moz-user-select: none; position: absolute; right: 55px;">';
				boton_recargar += '<span onClick="popupPP_recargar(\''+num_div.length+'\',\''+src+'\'); return false;" class="ui-icon ui-icon-refresh" unselectable="on" style="-moz-user-select: none;">reload</span>';
				boton_recargar += '</a>';
			var boton_afuera  = '<a  onMouseover="$(this).toggleClass(\'ui-state-hover\')" onMouseout="$(this).toggleClass(\'ui-state-hover\')" class="ui-state ui-corner-all" href="#" unselectable="on" style="-moz-user-select: none; position: absolute; right: 30px;">';
				boton_afuera += '<span onClick="popupPP_cambiar(\''+divMoverPO+'\',\''+width+'\',\''+height+'\'); return false;" class="ui-icon ui-icon-newwin" unselectable="on" style="-moz-user-select: none;">reload</span>';
				boton_afuera += '</a>';
			
			$(".ui-dialog-titlebar-close", arr_parents[0] ).before(boton_afuera);
			$(".ui-dialog-titlebar-close", arr_parents[0] ).before(boton_recargar);
          
        return false;
		////****/////
	if(IE)					//	IE
		{
		posicX = event.clientX + scrollLeft;
		posicY = event.clientY + scrollTop;
		}
	else					//	FF, NS y los demas
		{
		color_background_PO = "background-color:#FFFFFF;";
		posicX = e_ext.pageX;
		posicY = e_ext.pageY;
		}
	if (posicX < 0) {posicX = 0};
	if (posicY < 0) {posicY = 0};
	
	var nuevo=true;
	for (src_div in num_div)
		{
		 if (num_div[src_div]==src)
		 	{
			divMoverPO="divPO_"+src_div;
			focoPO();
			nuevo=false;
			break;
			}			
		}
	if (nuevo)
		{
		var top;		
		var left;
		top=Math.max(((tam_pantalla["height"]-height)/2)+scrollTop,5);
		left=Math.max((tam_pantalla["width"]-width)/2,5);
		var div = document.createElement('div');
		divMoverPO="divPO_"+num_div.length;		
		div.setAttribute("className",'iframe');	//	IE
		div.setAttribute("class",'iframe');		//	FF, NS y los demas		
		div.style.cssText="left:"+left+"px;top:"+top+"px;border:1px solid #000000;position:absolute;color:#FFFFFF;background-color:#0099CC;font-weight:bold;font-family:Arial, Helvetica, sans-serif;font-size:11px;height:"+height+"px; width:"+width+"px";		
		
		div.setAttribute("id", divMoverPO);
		var div_cab = document.createElement('div');
		div_cab.setAttribute("id",'div_cab_'+num_div.length);
		div_cab.style.cssText="background-color:#0099CC; float:left; cursor:default; padding:2px 2px 2px 10px; width:"+(width-90)+"px; height:20px;";
		//	se grego: height:20px; el 29-MAYO-2007
		//position:relative;
		div_cab.setAttribute("onmousedown", "moverIniPO('"+divMoverPO+"');");
		div_cab.setAttribute("onmouseup", "moverPO=false; he_temp='"+height+"px'; restaura_tam();");
		var titulo = document.createTextNode(titulo);
		div_cab.appendChild(titulo);
		div.appendChild(div_cab);
		var div_btn = document.createElement('div');
		div_btn.style.cssText="text-align:right; float:right; background-color:#0099CC; height:20px;";
		//otra_pantalla
		var btn = document.createElement('img');
		btn.src = "/pr/imagenes/boton_cambiar.gif";
		btn.alt = 'Pantalla exterior';
		btn.setAttribute("onClick","popupPP_cambiar('"+div.id+"'); ");
		btn.setAttribute("onmousedown","moverPO=false;");
		btn.style.cssText="margin:2px;";
		ref_btn = div_btn.appendChild(btn);

		//recargar
		var btn = document.createElement('img');
		btn.src = "/pr/imagenes/boton_recargar.gif";
		btn.alt = 'Recargar (Dirección inicial)';
		btn.setAttribute("onClick","popupPP_recargar("+num_div.length+", '"+src+"'); ");
		btn.setAttribute("onmousedown","moverPO=false;");
		btn.style.cssText="margin:2px;";
		ref_btn = div_btn.appendChild(btn);

		//cerrar
		var btn = document.createElement('img');
		btn.src = "/pr/imagenes/boton_cerrar.gif";
		btn.alt = 'Cerrar';
		btn.setAttribute("onClick","cierra_popupPP('"+div.id+"'); ");
		btn.setAttribute("onmousedown","moverPO=false;");
		btn.style.cssText="margin:2px;";
		ref_btn = div_btn.appendChild(btn);
		
		div.appendChild(div_btn);
		
		var i_frame = document.createElement('iframe');
		i_frame.name = "frame_"+num_div.length;
		i_frame.id = "frame_"+num_div.length;
		
		i_frame.frameborder=0;
		i_frame.setAttribute("onfocus", "divMoverPO='"+divMoverPO+"'; focoPO();");
		i_frame.style.cssText = color_background_PO;
		//	lo toma del stilo del contenedor.		
		//	CAMBIÓ EL 29-MAYO-2007 (correción para Quiminet); antes; i_frame.style.width = "100%";
		i_frame.style.width = (width-1)+"px";
		i_frame.style.height = (height-21)+"px";//"100%";
		
		div.appendChild(i_frame);
		div.style.left = left+"px";
		ref_div = document.body.appendChild(div);
		
		/*	TRUCO PARA QUE AGARRE BIEN ALGUNAS PROPIEDADES (onclick, onmousedown, etc.) DE LOS OBJETOS EN 'IE'	*/
		//ref_btn.outerHTML = ref_btn.outerHTML.replace(/>/, " name ="+ref_btn.name+">");
		if(IE){ ref_div.outerHTML = ref_div.outerHTML.replace(/>/, " id="+ref_div.id+">"); }
		document.getElementById("frame_"+num_div.length).src = ''+src;
		num_div[num_div.length]=src;
		focoPO();
		}	
	}	
	function calcula_pantalla_disponible() 
	{	
	medidas=new Array();
	medidas["width"]=0;
	medidas["height"]=0;
    if (screen.availWidth && screen.availHeight) 
		{
		medidas["width"] = screen.availWidth;
		medidas["height"] = screen.availHeight;
		return medidas;
		}
	else
		{
		return false;
		}	
	}
	
//fin cambios realizados por carlos	
	
	
var pops_act=new Array();
function popupPP_close(ids)
	{
	$('#'+ids).dialog('close');
	return;
	if(document.getElementById(ids))
		{
	//	document.body.removeChild(document.getElementById(ids));  
		document.getElementById(ids).style.visibility='hidden';
		document.getElementById(ids).style.display='none';
		}
	
	}


function cierra_popupPP(ids)
{
	try
	{
		if(opener)//alert("es opener");
		{
			opener.focus();
			self.close();
		}
		else if(ids)//alert("es parent");
		{
			// esto hace que cuando se vuelva a abrir sea un popup PP nuevo
			parent.num_div[ parseInt(ids.split('_')[1]) ]= '';
			parent.popupPP_close( ids );
		}
	}
	catch(e)
	{
		window.close();
	}
}



function popupPP_cambiar(ids,width,height)
	{
	if (typeof(width) == "undefined")
	{
		width=parseInt(document.getElementById(ids).style.width);
	}
	if (typeof(height) == "undefined")
	{
		height=parseInt(document.getElementById(ids).style.height);
	}
	popupPP_close(ids);
	url="";
	for (id_int in num_div)
		{
		if ("divPO_"+id_int==ids)
			{
			url=num_div[id_int];
			break;
			}
		}
	//xShowModalDialog(url,this,'');
	if (url=="") 
		alert("Ocurrio un error al seleccionar su página.");
	else
		popUpExtW(url,width ,height )
	}
function popupPP_recargar(num_r, src_r)
	{
	var iframe_r = document.getElementById("frame_"+num_r);
	if(iframe_r)
		{
		iframe_r.src = ''+src_r;
		}
	}
	
function popUpExtW(page,PWidth,PHeight) {
	var left = (screen.width/2) - PWidth/2;
	var top = (screen.height/2) - PHeight/2;
	popUpExt=parseInt(Math.random( )*100);
	 eval("fineline"+popUpExt+"=window.open('"+page+"&smr=1','_blank','toolbar=0,scrollbars=1,location=0,status=0,menubars=0,resizable=1,width="+PWidth+",height="+PHeight+",left="+left+", top="+top+",screenX="+left+", screenY="+top+"')")
}


// Inicializaciones:

//Identificar versión firefox
	if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){
		var ffversion= new Number(RegExp.$1);
		//alert(ffversion);
		if (ffversion <= 2){
			NoSoportaPpp= true;
		}
	}
// Fin Identificar versión firefox

var onload_anterior_pppp;
if (!IE)
{
	try {
		document.captureEvents(Event.MOUSEMOVE);	//	FF, NS y los demas
	} catch(excPO) {
		alert("Error JS en PO");
	}
}
try
{
	if(document.onmousemove)
	{
		document.onmousemove = movDivPO;
		document.onmousedown = select_f;
		document.onselectstart = select_f;
	}
	else
		setTimeout("document.onmousemove=movDivPO;document.onmousedown=select_f;document.onselectstart=select_f;", 1000);

	onload_anterior_pppp= window.onload;
	window.onload= function() {
		if( onload_anterior_pppp )
			onload_anterior_pppp();
		ValidaCarga();//verifica si carga
	};
}
catch(excPO)
{
	alert("Error JS en PO");
}
//document.getElementById(divMoverPO).innerHTML = "";

