var version4 = (navigator.appVersion.charAt(0) == "4"); 
var popupHandle;

function GXPClosePopup() {
if(popupHandle != null && !popupHandle.closed) popupHandle.close();
}

function GXPOpenPopup(position,url,wName,wWidth,wHeight,wOptions) {
evnt = (version4 ? event : null);

// position=1 POPUP: makes screen display up and/or left, down and/or right 
// depending on where cursor falls and size of window to open
// position=2 CENTER: makes screen fall in center

var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;
if(navigator.appName == "Microsoft Internet Explorer") {
//screenY = document.body.offsetHeight;
screenY = window.screen.availHeight;
screenX = window.screen.availWidth;
}
else {
screenY = window.outerHeight
screenX = window.outerWidth
}
if(wWidth == 0) {
 wWidth = screenX;
}
if(wHeight == 0) {
 wHeight = screenY;
}
var properties = "toolbar = 0, location = 0, scrollbars = 1 ,height = " + wHeight;
properties = properties + ", width=" + wWidth;
if(position == 1)	{ // if POPUP not CENTER
cursorX = evnt.screenX;
cursorY = evnt.screenY;
padAmtX = 10;
padAmtY = 10;
if((cursorY + wHeight + padAmtY) > screenY) {
// make sizes a negative number to move left/up
padAmtY = (-30) + (wHeight * -1);
// if up or to left, make 30 as padding amount
}
if((cursorX + wWidth + padAmtX) > screenX)	{
padAmtX = (-30) + (wWidth * -1);	
// if up or to left, make 30 as padding amount
}
if(navigator.appName == "Microsoft Internet Explorer") {
leftprop = cursorX + padAmtX;
topprop = cursorY + padAmtY;
}
else {
leftprop = (cursorX - pageXOffset + padAmtX);
topprop = (cursorY - pageYOffset + padAmtY);
   }
}
else{
leftvar = (screenX - wWidth) / 2;
rightvar = (screenY - wHeight) / 2;
if(navigator.appName == "Microsoft Internet Explorer") {
leftprop = leftvar;
topprop = rightvar;
}
else {
leftprop = (leftvar - pageXOffset);
topprop = (rightvar - pageYOffset);
   }
}
if(evnt != null) {
properties = properties + ", left = " + leftprop;
properties = properties + ", top = " + topprop;
}
if(position != 3) { 
GXPClosePopup();
}
if(wOptions != null) {
properties = properties + ", " + wOptions;
}
popupHandle = open(url,wName,properties);
}

function GXPConfOpenPopup(MsgConf,wURL,wName,wWidth,wHeight,wOptions){
if (confirm(MsgConf)) {GXPOpenPopup(2,wURL,wName,wWidth,wHeight,wOptions)}
}
//Compare two URLs and return true if the same server
function GXPSameServer(url1,url2){
var i=0;var j=0;var prt_url1;var srv_url1;var prt_url2;var srv_url2;
i=url1.indexOf('://');prt_url1=url1.substr(0,i);i+=3;
j=url1.indexOf('/',i);srv_url1=url1.substr(i,j-i);
i=url2.indexOf('://');prt_url2=url2.substr(0,i);i+=3;
if(prt_url1==prt_url2){
  j=url2.indexOf('/',i);
  srv_url2=url2.substr(i,j-i);
  if(srv_url1==srv_url2){return true}
}else{
  if(prt_url2==''){return true}
}
return false;
}
//Change color of the row when Mouse Over
function ClrMouseOvr(src,clrOver) {if (!src.contains(event.fromElement)) {src.bgColor = clrOver;}}
function ClrMouseOut(src,clrIn) {if (!src.contains(event.toElement)) {src.bgColor = clrIn;}}
//Change image of the row when Mouse Over
function ImgMouseOvr(src,clrOver) {if (!src.contains(event.fromElement)) {src.background = clrOver;}}
function ImgMouseOut(src,clrIn) {if (!src.contains(event.toElement)) {src.background = clrIn;}}
//Change image of the option when Mouse Over
function PutImage(nameimg,imagen){document.images[nameimg].src = imagen;}
//Display application in IFRAME selected
function GXPAppIntDsp(Container,url,wintitle) 
{GXPSetWinTitle(wintitle);document.getElementById(Container).src = url;}
//Get Application Operation Services
function GXPAppIntGetOpe(CntNro,OpeKey,SrvId){
//alert('Refrezcar Container:'+CntNro+'  OpeKey:'+OpeKey+'  Servicio:'+SrvId);
var CntNroInt = CntNro/1; if (CntNro.lenght == 1 || CntNroInt < 10) CntNro = '0'+ CntNroInt;
GXPAppIntSetOpeSrvSel(CntNro,SrvId);
if (OpeKey!="") {
var lastsfsectorTDNode;var parNode = document.getElementById("GXPAppIntCnt"+CntNro+"IF");var found=false;
do{
if (parNode){
parNode = parNode.parentNode;
if (parNode){
if (parNode.nodeName == 'TD'){lastsfsectorTDNode = parNode;}
if (parNode.nodeName == 'TABLE'){if (parNode.id.indexOf('SFSECTOR') != -1){found = true;}}}}}
while (parNode && !found)
if (lastsfsectorTDNode){
if (OpeKey == "none"){lastsfsectorTDNode.style.display = "none";}
else if (OpeKey == "refresh"){
lastsfsectorTDNode.style.display = "inline";
URL = document.getElementById("GXPAppIntCnt"+CntNro+"IF").src;
GXPAppIntDsp("GXPAppIntCnt"+CntNro+"IF",URL);
}
else{
lastsfsectorTDNode.style.display = "inline";
URL = document.getElementById("GXPAppIntCntURL"+CntNro).value+','+OpeKey+','+SrvId;
GXPAppIntDsp("GXPAppIntCnt"+CntNro+"IF",URL);}
}}}
//Set Application Operation Service Selected 
function GXPAppIntSetOpeSrvSel(CntNro,SrvId){
var CntNroInt = CntNro/1; if (CntNro.lenght == 1 || CntNroInt < 10) CntNro = '0'+ CntNroInt;
GXPAppIntCntOpeSrv = parent.document.getElementById("GXPAppIntCntOpeSrv"+CntNro);
if (GXPAppIntCntOpeSrv) {GXPAppIntCntOpeSrv.value = SrvId;}}
//Get Application Operation Service Selected 
function GXPAppIntGetOpeSrvSel(CntNro){
var CntNroInt = CntNro/1; if (CntNro.lenght == 1 || CntNroInt < 10) CntNro = '0'+ CntNroInt; var SrvId = 0;
GXPAppIntCntOpeSrv = parent.document.getElementById("GXPAppIntCntOpeSrv"+CntNro);
if (GXPAppIntCntOpeSrv) {SrvId = GXPAppIntCntOpeSrv.value;}
return SrvId;}
//Refresh IFRAME and Windows title
function GXPRedirToIF(url,wintitle) 
{GXPSetWinTitle(wintitle);document.getElementById('gxpiframe').src = url;}
//Redir from iFRAME
function GXPRedirFromIF(url){parent.location.href = url;}
//Redir from iFRAME
function GXPRedirTo(url,wintitle)
{if (wintitle!=''){parent.document.title = wintitle;}location.href = url;}
//Cahnge Windows title
function GXPSetWinTitle(wintitle){if (wintitle){document.title = wintitle;}}
//Open NewWindow
function GXPOpenWin(wURL,wName,wOptions)
{wOptions1='scrollbars=1,location=1,menubar=1,toolbar=1,directories=1,status=1,resizable=1,'+wOptions;window.open(wURL,wName,wOptions1);}

//Redir de Menú de combos
function GXPMnuCombo(selObj){
link=selObj.options[selObj.selectedIndex].value;
//Open PopUp?
if (link.substr(0,1)!='Y'){
 link = link.substr(1,500);
 if (link.substr(0,11)=='javascript:'){
  link=link.substr(11,500);eval(link);
 }else{
  if(link!='*'){
   eval("location='"+link+"'");}}
}else{link=link.substr(1,500);GXPOpenWin(link,'','');}
}

//To change Anchor and TD class
function GXPChgClassOve(src,AnchId,ClassName) 
{if (!src.contains(event.fromElement)) 
  {src.style.cursor = 'hand';
   if (ClassName!=''){AnchId.className='A'+ClassName;src.className='TD'+ClassName;}
}}
function GXPChgClassOut(src,AnchId,ClassName) 
{if (!src.contains(event.toElement)) 
  {src.style.cursor = 'default';
   if (ClassName!=''){AnchId.className='A'+ClassName;src.className='TD'+ClassName;}
}}
//To collapse sectors
function gxptablestatus(tableName, flag, image, imgExpand, imgCollapse)
{table = document.getElementById(tableName);
 if( table.style.display == "none"){table.style.display = "inline";image.src = imgCollapse;flag.value = "0";}
 else {	table.style.display = "none";image.src = imgExpand;flag.value = "1";}}

//To Hide and show Tables
function gxptableHS(tableName)
{table = document.getElementById(tableName);
 if( table.style.display == "none"){table.style.display = "inline";}
 else {	table.style.display = "none";}}

//Close Windows
function GXPClose() {window.close();}
//
function GXPCloseAndRefresh() {
window.close();
if (window.opener) {parentdoc = window.opener.document;} 
else {parentdoc = window.dialogArguments.document;}
parentdoc.forms[0].submit();}
//
function GXPCloseAndReload(){
window.close();
if (window.opener) {parentdoc = window.opener.location.reload(true);} 
else {parentdoc = window.dialogArguments.document;}
parentdoc.location.reload(true);}
//
function GXPCloseAndRedir(vURL) {
if (opener != null) {self.close();window.opener.document.location.replace(vURL);}}
//To display Flash
function GXPShowSWF(fileSWF,widthSWF,heightSWF){
var quality="high";
var linehtml="";
if (fileSWF){
  linehtml ='<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"'
  if (!widthSWF){widthSWF=100};if (!heightSWF){heightSWF=100};
  linehtml+='WIDTH="'+widthSWF+'" HEIGHT="'+heightSWF+'" >\n'
  document.write(linehtml);
  linehtml ='<PARAM NAME=movie VALUE="'+fileSWF+'" />\n'
  document.write(linehtml);
  linehtml ='<PARAM NAME=quality VALUE='+quality+'>\n'
  document.write(linehtml);
  linehtml ='<PARAM NAME=wmode VALUE="transparent" /\n>'
  document.write(linehtml);
  linehtml ='<EMBED SRC="'+fileSWF+'" QUALITY="'+quality+'" WMODE="transparent" WIDTH="'+widthSWF+'" HEIGHT="'+heightSWF+'" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>'
  document.write(linehtml);
  linehtml ='</OBJECT>\n'
  document.write(linehtml);
}}
//
function InitScrollbar(SectorId, SizeDragBar, ScrollSchema, EnableHScroll, EnableVScroll, ShowTrack, ShowSector){
var wndo = new dw_scrollObj('WN' + SectorId, 'LYR' + SectorId, 'TS' + SectorId);
wndo.bSizeDragBar = SizeDragBar;
if (ScrollSchema != 'Y' & ShowTrack == 'Y'){
if (EnableVScroll == 'Y'){wndo.setUpScrollbar('DBV' + SectorId, 'TRV' + SectorId, 'v', 1, 1);}
if (EnableHScroll == 'Y'){wndo.setUpScrollbar('DBH' + SectorId, 'TRH' + SectorId, 'h', 1, 1);}}
if (ShowSector == 'N'){document.getElementById('SCR' + SectorId).style.display = 'none';}}
//
function GXPChgSecSize(sectorId, sectorHeight, sectorWidth)
{sectorTable = document.getElementById(sectorId);
if (sectorHeight != '' || sectorWidth != ''){
if (sectorTable){
var parNode = sectorTable;var found = false;var sfsectorNode;var sfsectorverNode;var lastsfsectorverTDNode;var lastsfsectorTDNode;
do{if (parNode){
parNode = parNode.parentNode;
if (parNode){
if (parNode.nodeName == 'TD' && !sfsectorNode){lastsfsectorTDNode = parNode;}
if (parNode.nodeName == 'TD' && !sfsectorverNode){lastsfsectorverTDNode = parNode;}
if (parNode.nodeName == 'TABLE'){
if (parNode.id.indexOf('SFSECTORVER') != -1){found = true;sfsectorverNode = parNode;}
else{
if (parNode.nodeName == 'TABLE' && parNode.id.indexOf('SFSECTOR') != -1){sfsectorNode = parNode;}}}}}}
while (parNode && !found)
if (sfsectorNode && sfsectorverNode && lastsfsectorverTDNode && lastsfsectorTDNode){
if (sectorHeight != ''){sfsectorNode.style.height = '100%';sfsectorverNode.style.height = '100%';lastsfsectorverTDNode.style.height = sectorHeight;}
if (sectorWidth != ''){lastsfsectorTDNode.style.width = sectorWidth;}}}}}

//Change cursor image on MouseOver/MouseOut
function GXPSwapCursor(object){
var brw=new GXPChkBrw();
 if ((object.style.cursor=="default") || (object.style.cursor=="")) {
  if (brw.ie){object.style.cursor="hand";}else{object.style.cursor="pointer";}
 }else{object.style.cursor="default";}
}

//Check Browser
function GXPChkBrw(){
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.ns4=(!this.dom && document.layers)?1:0;
	this.op=window.opera 
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ie=this.agent.indexOf("msie")>-1 && !this.op
	if(this.op){
		this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
		this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
		this.op7=this.dom&&!this.op5&&!this.op6 
	}else if(this.moz) this.ns6 = 1
	else if(this.ie){
		this.ie4 = !this.dom && document.all
  	this.ie5 = (this.agent.indexOf("msie 5")>-1)
  	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
  	this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
	}
	this.mac=(this.agent.indexOf("mac")>-1)
	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
  this.usedom= this.ns6||this.op7
  this.reuse = this.ie||this.op7||this.usedom 
  this.px=this.dom&&!this.op5?"px":""
return this
}

//
function GXPDynCode(codeTxt, codeType)
{
	this.code = codeTxt;
	this.type = codeType;
	return this;
}

//
function GXPProcessDynCode(aDynCode, aDynCodeCounter){
	i = 0;
	while (i < aDynCodeCounter)
	{
		if ((aDynCode[i] != null) & (aDynCode[i].code != null))
		{
			if (aDynCode[i].type != null)
			{
				if (aDynCode[i].type == "JS"){
					eval(aDynCode[i].code);
				}
				else {
					if (aDynCode[i].type == "HTML") {
						document.write(aDynCode[i].code);
					}
				}
			}
		}
		i += 1;
	}
}

//
function GXPChangeLng(LngId, CallerId, InFrame)
{
	if (InFrame == 1)
		docLocation = parent.location;
	else
		docLocation = document.location;
	
	qMarkPos = docLocation.href.indexOf("?");
	if (qMarkPos > -1)
		locHref = docLocation.href.substring(0, qMarkPos);
	else
		locHref = docLocation.href + ((CallerId == 1) ? "" : "?");
		
	GXPParms = docLocation.search.split(",");
	queryString = "";
	if (CallerId == 1 || (CallerId == 3 && docLocation.href.indexOf("/hgxpp001") == -1))
	{
		if (CallerId == 1)
		{
			sitePos = 3;
			pgmName = "hgxpt001";
		}
		else
		{
			sitePos = 2;
			pgmName = "hgxpt002";
		}
		locHref = locHref.replace(pgmName, "hgxpp003");
		hgxpt00xPos = docLocation.href.lastIndexOf("/") + 1;
		hgxpt00x = docLocation.href.substr(hgxpt00xPos, docLocation.href.length - hgxpt00xPos + 1);
		queryString = "?" + ((GXPParms[sitePos]) ? GXPParms[sitePos] : "") + ",P," + LngId + "," + escape(hgxpt00x);
	}
	else
	{		
		for (i = 0; (i < 8); i++)
		{
			if (i == 4)
				queryString += LngId;
			else
			{
				if (i == 6 && InFrame == 1)
				{
					queryString += "0";
				}
				else
				{
					if (GXPParms[i])
						queryString += GXPParms[i];
				}
				
			}
			if (i < 7)
				queryString += ",";
		}
	}
	docLocation.href = locHref + queryString;
}