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;}
//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){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);}}
//
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';}}

