var fecha=new Date();
// Funcion que carga el js necesario dependiendo del protocolo
// y llama a una funcion para que registre la url.
carga_estadisticas_google();


// Funcion que abre el htm de contratacion o entra directamente a ejecutar la operacion

function direcciona(pg,cabMen,contMen,ejOp,p_param,p_param_htm){	

	if (location.protocol=="http:"){
		cont="parent.contenido.location.href='"+pg+"?param=carp="+ cabMen+ "&fald="+ contMen ;
		if (p_param_htm != null) cont = cont + p_param_htm;
		cont = cont + "'"; 
 		eval (cont);
		}
	else {	
		test_s(location.protocol,ejOp,cabMen,contMen,1,p_param);
	}		
}



// Funcion que abre la identificacion o ejecuta una operacion

function test_s(proto,pg,cabMen,contMen,tipoUs,p_param){
	switch(proto){
		case 'http:':{  
				top.PA_sgP_last=pg;		
				top.op_cabecera=cabMen;
				top.op_faldon=contMen;
				top.PA_sgP_ejOp=p_param;
				openID(tipoUs);
				break;
			}
		case 'https:':{			
				//MANOLO 27/4/2004
				//Hago que cuando estas identificado se cambie la carpeta por la que viene por parámetros
				//De esta forma no hace falta hacer cambiaCarpeta antes de llamar a test_s. 
				top.cabecera.cambiaCarpeta(cabMen,1,contMen);
				if (p_param != null) miEjecutarOp(p_param[0],p_param[1],p_param[2]);
				else top.contenido.location = pg;
				break;
			}
		}
}


//abre la ventana de identificación de cliente , llamada al servlet
function openID(tipoUs){

	if (top.PA_sgP_ejOp==''){
	  top.PA_sgP_last=parent.contenido.location;	  
	}
	
	var callServin;
		
	top.cabecera.document.cabec.p_bc.value="ec";
	top.cabecera.document.cabec.p_pt.value=parent.sOrigen;
	top.cabecera.document.cabec.p_id.value="esp";
	top.cabecera.document.cabec.p_pm.value="pc";
	top.cabecera.document.cabec.p_tc.value="pb";
	top.cabecera.document.cabec.s_ut.value=top.PA_sgP_last;
	top.cabecera.document.cabec.s_cab.value=top.op_cabecera;
	top.cabecera.document.cabec.s_cont.value=top.op_faldon;
	top.cabecera.document.cabec.s_ejOp.value=top.PA_sgP_ejOp;
			
	if (tipoUs=="1")
		top.cabecera.document.cabec.p_pf.value="c";
	else 
		top.cabecera.document.cabec.p_pf.value="p";
			
	top.cabecera.document.cabec.target.value="_top";
	
	top.cabecera.document.cabec.action= "https://" + location.host + "/AppECOM/servlet/servin?";

	top.cabecera.document.cabec.submit();
	return true;
}

function limpiaVble()
{
	top.V_Renting="No";
	top.V_Impresora="No";
	top.V_Modelo="";
	
	top.V_producto ="";
	top.V_modalidad ="";
	top.V_importe ="";
	top.V_descripcion="";
}

function findQParam(p_Params) 
{
var ret = null;
var l_query = location.search;
var fIndex = l_query.indexOf(p_Params+"=");
	if (fIndex != -1){
		fIndex += (p_Params.length+1);
		l_query = l_query.substring(fIndex);
	
		var endIndex = l_query.indexOf('&');
		if (endIndex == -1)
			ret = l_query;
		else 
	  	ret = l_query.substring(0,endIndex);
	}	
	return ret;
}

function findQArrayParam(p_Params) 
{
var ret = null;
var l_query = location.search;
var fIndex = l_query.indexOf(p_Params+"=");
	if (fIndex != -1){
		fIndex += (p_Params.length+1);
		l_query = l_query.substring(fIndex);
		ret = l_query;
	}
	return ret;
}


function miEjecutarOp(p_ihc,p_cod,p_par,p_pub)
{
		if (p_pub!=null) {
			top.contenido.location= '/Bpepublic?_ABT_FROM_PART=' +p_ihc+ '&codOperacion=' +p_cod+ p_par;
		}
		else {
			top.sendPioMenu(0,p_ihc,p_cod,p_par);
		}
}

function rTrim(p_valor){
var l_long=p_valor.length-1;
	while (p_valor.charAt(l_long)==" "){
		l_long--;
	}
	return( p_valor.substring(0,l_long+1));
}

function wrt_js(js_src) {
	
  var_js="<SCRIPT language='JavaScript' src='"+js_src+"'></SCRIPT>";
  return (var_js);
}

function path() {
	var l_location;
	if (location.protocol=="http:"){
		l_location = "http://" + location.host;
	}
	else {
		l_location = "https://" +location.host;
	}
	return (l_location);
}

function carga_estadisticas_google()
{
	aux = window.location.href;
	if (aux.indexOf("AppECOM/servlet/servin") != -1)
		return;
	if (aux.indexOf("bancopopular-e.com") == -1)
		return;
	/*
	var body = document.getElementsByTagName('html').item(0);
	sc = document.createElement('script');
	sc.src = '/esp/ecom/pc/pweb/src/estadisticas_google.js';
	sc.type = 'text/javascript';
	*/
	inetscape=(document.layers)? true:false
	iexplorer=(document.all)? true:false 
	if ((inetscape)||(!iexplorer))
	{
	       	var mybody = document.getElementsByTagName("head").item(0);
	       	var s = document.createElement("script")
	       	p = document.createTextNode("estadisticas_google2();");
	       	s.appendChild(p);
	       	mybody.appendChild(s);
	}
	else
        {        	
        	estadisticas_google2();        	
        }
}

function estadisticas_google2()
{
	var body = document.getElementsByTagName("head").item(0);
	scrip = document.createElement("script");
	scrip.type = "text/javascript";

	// Comprobamos si estamos en protocolo seguro o no para ver que libreria incluimos
	aux = window.location.href;
	aux = aux.substring(0,5);
	if (aux.toLowerCase() == "https")
		scrip.src = "https://ssl.google-analytics.com/ga.js";
	else
		scrip.src = "http://www.google-analytics.com/ga.js";

	body.appendChild(scrip);

	
	if ((inetscape)||(!iexplorer))
	{
	       	var mybody2 = document.getElementsByTagName("head").item(0);
	       	var s2 = document.createElement("script")
	       	s2.defer = "true";
	       	p2 = document.createTextNode('setTimeout(\'var pageTracker=_gat._getTracker("UA-662039-1");pageTracker._trackPageview();\',1000);');
	       	s2.appendChild(p2);
	       	mybody2.appendChild(s2);
	       	
	}
	else
        {
        	setTimeout('var pageTracker=_gat._getTracker("UA-662039-1");pageTracker._trackPageview();',1000);
        	
        }
        
}

//*** Función que despliega y contrae capas ***//
function desplegarDiv(dv)
{
	if (dv.style.display == "none")
		dv.style.display = "block";
	else
		dv.style.display = "none";
}

//*** Función que despliega y contrae capas (para FireFox) ***//
function toggle(id)
{
	if (document.getElementById(id).style.display == 'block') {
		document.getElementById(id).style.display = 'none';
	} else {
		document.getElementById(id).style.display = 'block';
	}
}

//*** Abre pop-up de Reuters ***//
function ReutersContent()
{
	var l_link = "/esp/ecom/pc/pweb/htm/05_013_out.htm";
	window.open(l_link , 'newWin','status=no,title=yes,width=550,height=202,top=120,left=100,scrollbars=no');
}

