// Realizar el salto entre Seguro y No Seguro según el entorno (servidor) en el que nos encontremos
var IP_SEG_CIDAT= "https://212.8.109.95";
var IP_NOSEG_CIDAT= "http://212.8.109.18";
var IP_NOSEG_CIDAT2= "http://alambix_ii";
var IP_SEG_KUTXA_DES= "http://net.kutxa.pru";
var IP_NOSEG_KUTXA_DES= "http://www.kutxa.pru";
var IP_SEG_KUTXA_DESARROLLO= "http://desanet.kutxa.pru";
var IP_NOSEG_KUTXA_DESARROLLO= "http://desawww.kutxa.pru";
var IP_SEG_KUTXA_PRO= "https://net.kutxa.net";
var IP_NOSEG_KUTXA_PRO= "http://www.kutxa.net";
// en entorno CECA
var IP_SEG_CECA_PRO_CAS= "https://www.kutxa.es/2101";
var IP_SEG_CECA_PRO_EUS= "https://www.kutxa.es/2101/03default.htm";
var IP_SEG_CECA_DES_CAS= "http://www.cep.ceca.es/2101";
var IP_SEG_CECA_DES_EUS= "http://www.cep.ceca.es/2101/03default.htm";

function enlaceKutxa(noSeguro, seguro, html){
	var strUrl;
	
	if (document.location.host.indexOf("www")!=-1){
		strUrl = noSeguro;
	}	else{
		strUrl = seguro;
	}
	if (html){
	 document.write(strUrl);
	}	else{
	 window.location=strUrl;
	}	
}

/**
 * Función que pone un enlace para la parte segura y otra para la parte
 * no segura en caso de que no sea -1
 * Esta función se podría refinar para que no tuvieran que pasar parámetros
 */
function enlaceKutxaConTexto(noSeguro, textoNoSeguro, seguro, textoSeguro, html) {
	var strUrl = "";
	
	if (document.location.host.indexOf("www")!=-1) {
		if (noSeguro != -1)
		  strUrl = "<br /><a href=\"" + noSeguro + "\" target=\"_parent\">" + textoNoSeguro + "</a><br />";
	}	else {
		if (seguro != -1) 
		  strUrl = "<br /><a href=\"" + seguro + "\" target=\"_parent\">" + textoSeguro + "</a><br />";
	}
	if (html) {
	 document.write(strUrl);
	}	else {
	 window.location=strUrl;
	}	
}

function enlaceUrl(enlaceNoSeguro, enlaceSeguro){
	var strUrl;
	if (document.location.host.indexOf("www")!=-1){
		strUrl = enlaceNoSeguro;
	}	else{
		strUrl = enlaceSeguro;
	}
	 window.location=strUrl;	
}

function enlaceTextoUrl(textoEnlaceNoSeguro, enlaceNoSeguro, textoEnlaceSeguro, EnlaceSeguro){
	var strHtml;
	if (document.location.host.indexOf("www")!=-1){
	  strHtml = '<td colspan="2" valign="top"><a href="' + enlaceNoSeguro + '" target="_top" class="txtbs"> ' + textoEnlaceNoSeguro + '</a><br><span class="txt">(provisional en desarrollo) ¡no quitar!</span></td>';
	}else{
	  strHtml = '<td colspan="2" valign="top"><a href="' + enlaceSeguro + '" target="_top" class="txtbs"> ' + textoEnlaceSeguro + '</a><br><span class="txt">(provisional en desarrollo) ¡no quitar!</span></td>';
	}
 document.write(strHtml);
}

function ObtenerDominioKutxanet() {
	var queURL;
	
	if (document.location.host.indexOf("kutxa.pru")!=-1 || document.location.host.indexOf("kutxaempresas.pru")!=-1) 
		if (document.location.host.indexOf("desa")!=-1)
		  queURL=IP_SEG_KUTXA_DESARROLLO;
		else
			queURL=IP_SEG_KUTXA_DES;
	else if (document.location.host.indexOf(".kutxaempresas.")!=-1 || document.location.host.indexOf(".kutxa.")!=-1) 
		queURL=IP_SEG_KUTXA_PRO;
	else queURL=IP_SEG_KUTXA_PRO;
		
	return queURL;
}

function ObtenerDominioKutxa() {
	var queURL;
	
	if (document.location.host.indexOf(".pru")!=-1) {
		if (document.location.host.indexOf("desa")!=-1)
		  queURL=IP_NOSEG_KUTXA_DESARROLLO;
		else
			queURL=IP_NOSEG_KUTXA_DES;
	} else if (document.location.host.indexOf(".net")!=-1) queURL=IP_NOSEG_KUTXA_PRO;
	else queURL=IP_NOSEG_CIDAT;

	return queURL;
}

// Esta función la utilizan todos los enlaces cuando van a Seguro que pueden cambiar si estamos 
// trabajando con CECA o solos, para hacer el cambio en un sitio solo.
// En la fase 2 esta función deberá hacer sólo la 1ª parte actualmente entre comentarios
function sLocSNS_c(idioma) {
	var fecha=new Date();
	var tipouser="";
	
	if (document.location.host.indexOf(".kutxaempresas.")!=-1) tipouser="empresas";
	else tipouser="particulares";
	return ObtenerDominioKutxanet()+"/main.htm?idioma="+idioma+"&idid="+fecha.getTime()+"&tipouser="+tipouser;
}
function sLocSNS_c(idioma, portal) {
	var fecha=new Date();
	var tipouser="";
	
	if (document.location.host.indexOf(".kutxaempresas.")!=-1 || portal == "empresas") 
	  tipouser="empresas";
	else 
		tipouser="particulares";
	return ObtenerDominioKutxanet()+"/main.htm?idioma="+idioma+"&idid="+fecha.getTime()+"&tipouser="+tipouser;
}

function SaltaSNS(sUrlTo, linkTo){
	if(typeof(linkTo)!='undefined' && linkTo!=null && linkTo!="") {
		linkTo.href = sLocSNS(sUrlTo);
	} else {
		alert("Error en SaltaSNS: Url destino erronea. \nLa Url debe ser relativa al docsroot y empezar por '/' :\n " + sUrlTo);
		return;
	}
}

function sLocSNS(sUrlTo){
	var tipouser="";
	
	if (document.location.host.indexOf(".kutxaempresas.")!=-1) tipouser="empresas";
	else tipouser="particulares";
	if (document.location.protocol.indexOf("https")!=-1) return ObtenerDominioKutxa()+sUrlTo+"&tipouser="+tipouser;
	else return ObtenerDominioKutxanet()+sUrlTo+"&tipouser="+tipouser;
}

function launchRemoteProducto(idioma,productoid) {
	var ancho = screen.width-10;
	var alto = screen.height-50;
	
	var queURL=sLocSNS_c(idioma);
	queURL+="&productoid="+productoid;
	if (window.opener) 
	    window.location=queURL;
	else {
		  myRemote=open(queURL,"Kutxanet","width="+ancho+",height="+alto+",toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,top=0,left=0,resizable=1");
		  myRemote.focus();
	}
}
function launchRemoteProductoNuevaVentana(idioma,productoid) {
	var ancho = screen.width-10;
	var alto = screen.height-50;
	
	var queURL=sLocSNS_c(idioma);
	queURL+="&productoid="+productoid;
	
		  myRemote=open(queURL,"Kutxanet","width="+ancho+",height="+alto+",toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,top=0,left=0,resizable=1");
		  myRemote.focus();
	
}
function launchRemoteProducto(idioma,productoid,portal) {
	var ancho = screen.width-10;
	var alto = screen.height-50;
	
	var queURL=sLocSNS_c(idioma,portal);
	queURL+="&productoid="+productoid;
	if (window.opener) 
	    window.location=queURL;
	else {
		  myRemote=open(queURL,"Kutxanet","width="+ancho+",height="+alto+",toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,top=0,left=0,resizable=1");
		  myRemote.focus();
	}
}

function launchRemote(idioma) {
	launchRemoteProducto(idioma,0)
}
function launchRemote(idioma, portal) {
	launchRemoteProducto(idioma,0,portal)
}

function launchRemotees(){
	launchRemote("es");
}
function launchRemoteen(){
	launchRemote("en");
}
function launchRemotefr(){
	launchRemote("fr");
}
function launchRemoteeu(){
	launchRemote("eu");
}

function conexionSegura()
{	
	top.location.href=ObtenerDominioKutxanet();
}

function cierraEnfoca(urlTo)
{
	if (top.opener != null) {
		top.close();
		top.opener.focus();
	} else {
		top.location.href = urlTo;
	}
}

function conexionNoSegura()
{
	var sAuxIP = location.protocol + "//" + location.hostname;
	
	if(sAuxIP==IP_SEG_CIDAT) cierraEnfoca(IP_NOSEG_CIDAT);
	if(sAuxIP==IP_SEG_KUTXA_DES) cierraEnfoca(IP_NOSEG_KUTXA_DES);
	if(sAuxIP==IP_SEG_KUTXA_PRO) cierraEnfoca(IP_NOSEG_KUTXA_PRO);
}

function volverEntrar(idioma) 
{
	window.location=sLocSNS_c(idioma);
}

function volverInicio() 
{
	var sAuxIP = location.protocol + "//" + location.hostname;
	if(sAuxIP==IP_SEG_CIDAT) cierraEnfoca(IP_NOSEG_CIDAT);
	if(sAuxIP==IP_SEG_KUTXA_PRO) cierraEnfoca(IP_NOSEG_KUTXA_PRO);
	if(sAuxIP==IP_SEG_KUTXA_DES) cierraEnfoca(IP_NOSEG_KUTXA_DES);
}

function solicita_kutxanet(idioma) {
	var ventana;
        var fecha=new Date();
	var url = ObtenerDominioKutxanet()+"/jkn_opkn/loginKutxanet?idioma="+idioma+"&tipoCliente=06&log=n&pag=251&ENTIDAD=2101&nuevoKN=1";
	var ancho = 640;
	var alto = 475;
	
	ventana=open(url,"","width="+ancho+",height="+alto+",top=10,left=10,location=no,menubar=no, status=no, toolbar=no, scrollbars=1, resizable=no");
	ventana.focus();
}

function solicita_kutxanet(idioma, cliente) {
	var ventana;
    var fecha = new Date();
    var url = "";
    if (cliente){
    	url = ObtenerDominioKutxanet()+"/jkn_opkn/loginKutxanet?idioma="+idioma+"&tipoCliente=06&log=n&pag=251&ENTIDAD=2101&nuevoKN=1&origen=11&pagina=cuentae6.jsp";
    }else{
    	url = ObtenerDominioKutxanet()+"/jkn_opkn/loginKutxanet?idioma="+idioma+"&tipoCliente=04&log=n&pag=251&ENTIDAD=2101&nuevoKN=1&origen=11&pagina=cuentae4.jsp&rec=1";
    }
	var ancho = screen.width-10;;
	var alto = screen.height-50;;
	
	ventana=open(url,"Kutxanet","width="+ancho+",height="+alto+",toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,top=0,left=0,resizable=1");
	ventana.focus();
}


function solicita_kontugazte(idioma) {
		var url = ObtenerDominioKutxanet() + "/jkn_opkn/loginKutxanet?idioma=" + idioma + "&tipoCliente=04&log=n&pag=251&ENTIDAD=2101&nuevoKN=1&origen=11&pagina=cuentae8.jsp&rec=1&_ce_tipoprod=60";

		var ancho = screen.width - 10;
		var alto = screen.height - 50;
		
		var ventana = open(url, "Kutxanet", "width=" + ancho + ",height=" + alto + ",toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,top=0,left=0,resizable=1");
		ventana.focus();
}


function visita_demo(idioma) {

	var ancho = screen.width-10;
	var alto = screen.height-150;
	
	var url = ObtenerDominioKutxanet()+"/jkn_opkn/loginBE?idioma="+idioma+"&USUARIO=2101990001&PIN=2222&ENTIDAD=2101&nuevoKN=1&opcionIr=0000";

	if (window.opener) window.location=url;
	else {
		myRemote=open(url,"Demo","width="+ancho+",height="+alto+",toolbar=1,location=0,directories=1,status=1,menubar=1,top=0,left=0,scrollbars=1,resizable=1");
		window.blur();
		myRemote.focus();
	}

}
