﻿function OpenRelatedURL(strURL) {
    try {
       if (opener != null && (opener.location != null) && (window.location != null) && (opener.location.href != window.location.href) ) {
            opener.location.href = 'index.aspx?o=' + escape(strURL);
       } else {
            window.open(strURL);
       }
    } catch (err) {
        //popUp(strURL, 1024, 728);
        //alert('Error:' + err);
    }
    window.focus();
} // OpenRelatedURL

function OpenRelatedURLinPage(strURL, strPage) {
    try {
       if (opener != null && (opener.location != null) && (window.location != null) && (opener.location.href != window.location.href) ) {
            opener.location.href = strPage + '?o=' + escape(strURL);
       } else {
            window.open(strURL);
       }
    } catch (err) {
        //popUp(strURL, 1024, 728);
        //alert('Error:' + err);
    }
    window.focus();
} // OpenRelatedURL

function OpenDocument(strURL) {
    window.open(strURL);
} // OpenDocument

/**
* Abre una ventana pop up, se usa llamándola en el atributo href de un a usando la
* sintaxis href="javascript:openPopUp(argUrl, argWidth, argHeight, argTitle, argScroll)"
*
* String argUrl    	= url a abrir
* String argWidth   = ancho de la ventana
* String argHeight  = altura de la ventana
* String argTitle  	= Titulo de la ventana
* Integer argScroll = mostrar scrolls , 1 = sí, 0 = no 
*/
var is = new Object()
is.ie = (document.all) ? 1:0
is.ns4 = (document.layers) ? 1:0
is.w3c = (document.getElementById && !is.ie) ? 1:0
is.win = (navigator.userAgent.toLowerCase().indexOf("win") > 0) ? 1:0
is.mac = (navigator.userAgent.toLowerCase().indexOf("mac") > 0) ? 1:0

function openPopUp(argUrl, argWidth, argHeight, argTitle, argScroll ) {
	openPopUpWindow(argUrl, argWidth, argHeight, argTitle, argScroll );
}

function popUp(URL,popW,popH) {
    var w = 480, h = 340;
    var topPos = (h-popH)-(4*h/100), leftPos = (w-popW)-(1*w/100);
	var path = document.getElementsByName("returnURL");
    day = new Date();
    id = day.getTime();
    if (document.all || document.layers) {
        w = self.screen.availWidth;
        h = self.screen.availHeight;
    }
    eval("page" + id + " =window.open(URL, 'popup', 'resizable = no, toolbar = no, location = no, status = no, scrollbars = no, menubar = no, titlebar=no, width=' + popW + ', height=' + popH + ', left=' + leftPos + ', top =' + topPos + ', screenX =' + leftPos + ', screenY = ' + topPos);");
	if ((path != null) && (path.length == 1)) {
		path = path[0].value;
		path = path.substr(0, path.lastIndexOf('/')) + '/index.aspx';
	}
}

/**
* Función genérica para abrir pop-ups
*
* String argUrl     = URL a abrir
* String argWidth   = ancho de la ventana
* String argHeight  = altura de la ventana
* String argTitle   = Nombre de la ventana a abrir
* Integer argScroll = 1 = Mostrar el scroll, 0 = no 
*/
var is = new Object()
is.ie = (document.all) ? 1:0
is.ns4 = (document.layers) ? 1:0
is.w3c = (document.getElementById && !is.ie) ? 1:0
is.win = (navigator.userAgent.toLowerCase().indexOf("win") > 0) ? 1:0
is.mac = (navigator.userAgent.toLowerCase().indexOf("mac") > 0) ? 1:0
is.msie = (navigator.userAgent.toLowerCase().indexOf("msie") > 0) ? 1:0

function openPopUpWindow(argUrl, argWidth, argHeight, argTitle, argScroll ) {
	var windowOpened = false;
	var x = (screen.availWidth - argWidth ) / 2;
	var y = (screen.availHeight - argHeight ) / 2;
	if(argScroll=="1" && !is.mac){
		argWidth = parseInt(argWidth) + 26;
	}
	if(argScroll=="1" && is.mac){
		argWidth = parseInt(argWidth) + 10;
	}
	if (is.msie) {
	    argWidth = parseInt(argWidth) + 28;
	}
	var sFeatures = "width = " + argWidth + ", height = " + argHeight + 
	                ",toolbar = no, status = no, scrollbars = " + argScroll + 
	                ",resizable = yes, left=" + x + ", top = " + y;
	if (window.open) {
		newWindow = window.open(argUrl, argTitle, sFeatures, false);
		windowOpened = newWindow?true:false;
		if (windowOpened && newWindow.focus) {
			newWindow.focus();
		}
	}
	return !windowOpened;
}

/**
* Función que abre un pop up cuando se pulsa un enlace normal de HTML.
* Por ejemplo:
* 	<a href="http://www.reusecompany.com" target="_blank" onclick="return popUpHTMLLink(this,'Reuse Company')">Reuse Company</a>
* En caso de que la ventana no pueda ser abierta debido a la configuración del explorador, el enlace
* funcionará normalemnte redigiendonos a la página pero en la misma ventana que teníamos abierta
*/
function popUpHTMLLink(link,name) {
	return openPopUpWindow(link.href, 800, 600, name, 'yes');
}

function popUpHTMLLink(link, height, width) {
	return openPopUpWindow(link.href, height, width, '', 'yes');
}
