
// Codigos de los tipos de Comportamiento
var COD_COMPORTAMIENTO_SIN_REDIRECCION 		 = "1";
var COD_COMPORTAMIENTO_ENLACE_INTERNO        = "2";
var COD_COMPORTAMIENTO_ENLACE_INTERNO_POP_UP = "3";
var COD_COMPORTAMIENTO_ENLACE_EXTERNO 		 = "4";

// elimina los espacio en blanco a izquierda y a derecha de una cadena
// así como los retornos de carro y saltos de linea.
function trim(s) 
{
	// limpiar en lado izquierdo
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
	{ s = s.substring(1,s.length); }
	
	// limpiar en lado derecho
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
	{ s = s.substring(0,s.length-1); }
	
	return s;
} 

function colocarCapas(num)
{
	//var posicion = ((document.body.clientWidth-769)/2)+23;
	var posicion = 190;
	eval ("document.getElementById('subMenu01').style.left = "+posicion);
	for (i=1;i<num;i++)
	{
		sm = i+1;
		eval("anchura = document.getElementById('tdmenu"+i+"').clientWidth + 2");
		posicion = posicion + anchura;
		document.getElementById("subMenu0"+sm+"").style.left = posicion;
	}
	
	var anchoPag = document.body.clientWidth;
	var altoPag = document.body.clientHeight;
	
	var widthCont = anchoPag - 244;
	var heightCont = altoPag - 193;
	var widthMenu = anchoPag - 205;

	document.getElementById("contenido").style.width = widthCont;
	document.getElementById("contenido").style.height = heightCont;
	document.getElementById("subtitulo").style.width = widthCont;
	document.getElementById("menuLinks").style.width = widthMenu;
}
function colocarFrame() {
	// ancho menu vertical izdo = 178 pixels
	// alto menu superior = 90 pixels
	
	var anchoPag = document.body.clientWidth;
	var altoPag = document.body.clientHeight;
	
	var widthFrame = anchoPag - 180;
	var heightFrame = altoPag - 105;
	
	document.getElementById("txtHome").style.width = widthFrame;
	document.getElementById("txtHome").style.height = heightFrame;
}

function colocarCapasHome()
{
	// ancho menu vertical izdo = 178 pixels
	// ancho imagen = 577 pixels
	// alto menu superior = 90 pixels
	// alto imagen = 297 pixels
	// alto de la parte superior de la imagen = 168 pixels

	var anchoPag = document.body.clientWidth;
	var altoPag = document.body.clientHeight;	
	
	var leftHomeBg = ((anchoPag - 180 - 577)/2) + 90;
	var topHomeBg = ((altoPag - 105 - 297)/2) + 45;
	var leftHomeTxt = ((anchoPag - 180 - 577)/2) + 95;
	var topHomeTxt = ((altoPag - 105 - 168)/2)+ 170;
	
	document.getElementById("fondoHome").style.left = leftHomeBg;
	document.getElementById("fondoHome").style.top = topHomeBg;
	document.getElementById("txtHome").style.left = leftHomeTxt;
	document.getElementById("txtHome").style.top = topHomeTxt;
}

function colocarCapasForm()
{
	var anchoPag = document.body.clientWidth;
	var altoPag = document.body.clientHeight;
	
	document.getElementById("padding").style.width = anchoPag;
	document.getElementById("padding").style.height = altoPag;
	document.getElementById("ruta").style.width = anchoPag -50;
//	document.getElementById("contenido").style.height = heightCont;
//	document.getElementById("subtitulo").style.width = widthCont;
}

function rollOverImg(imgId,imgSrc)
{
	imgSrc.src=imgId;
}

function desplegar(capa)
{
	if (document.getElementById(capa).style.display=="block")
	document.getElementById(capa).style.display = "none";
	else
	document.getElementById(capa).style.display = "block";
	
	return false;
}

function enviarHome()
{
	rollOverImg('docs/images/botonEnviarOff.gif',this);
	setTimeout ("document.location = 'zonaOperativa.do'",500);
}

function redProveedores()
{
	var sector = document.forms[0].elements["sector"].value;
	for (i=0;i<=4;i++)
	{
		eval ("document.getElementById('sector"+i+"').style.display='none'");
		eval ("document.forms[0].elements['tipo"+i+"'].value = '0'")
	}
	eval ("document.getElementById('sector"+sector+"').style.display='block'")
}

function enviarUnir()
{
	if (document.forms[0].elements["tipo1"].value == "amb")
	{
		setTimeout ("document.location = 'formAmbulancias.do'",500)
	}
	if (document.forms[0].elements["tipo2"].value == "gru")
	{
		setTimeout ("document.location = 'formGruas.do'",500)
	}
	if (document.forms[0].elements["tipo2"].value == "tax")
	{
		setTimeout ("document.location = 'formTaxis.do'",500)
	}
	if (document.forms[0].elements["tipo2"].value == "tal")
	{
		setTimeout ("document.location = 'formTalleres.do'",500)
	}
	if (document.forms[0].elements["tipo3"].value == "hog")
	{
		setTimeout ("document.location = 'formHogar.do'",500)
	}
	if (document.forms[0].elements["tipo4"].value == "com")
	{
		setTimeout ("document.location = 'home.do'",500)
	}
	if (document.forms[0].elements["tipo5"].value == "gen")
	{
		setTimeout ("document.location = 'formGeneral.do'",500)
	}
	if ( (document.forms[0].elements["tipo1"].value == "0") && (document.forms[0].elements["tipo2"].value == "0") && (document.forms[0].elements["tipo3"].value == "0") && (document.forms[0].elements["tipo4"].value == "0") && (document.forms[0].elements["tipo5"].value == "0") )
	{
		rollOverImg('docs/images/botonEnviarOff.gif',this)
		alert("Debe seleccionar un SECTOR y un TIPO DE SERVICIO")
	}
}

function volver()
{
	rollOverImg('docs/images/botonVolverOff.gif',this)
	setTimeout ("history.go(-1)",500)
}

function NCom()
{
	rollOverImg('docs/images/botonNComOff.gif',this)
	setTimeout ("document.location = 'aclaracionServiciosNC.do'",500)
}

function confirmacion()
{
	var longitud = document.forms[0].length
	var chequeado = 0;
	for (i=0;i<longitud;i++)
	{
		if(document.forms[0].elements[i].checked) chequeado++;
	}

	if (chequeado > 0)
	{
		rollOverImg('docs/images/botonContinuarOff.gif',this)
		setTimeout ("document.location = 'confirmacionServiciosInfo.do'",500)
	}
	else
	{
		alert("Debe seleccionar una fila de la tabla.")
	}
}

function facturas()
{
	var longitud = document.forms[0].length
	var chequeado = 0;
	for (i=0;i<longitud;i++)
	{
		if(document.forms[0].elements[i].checked) 
		{
			chequeado++;
			var pagina = document.forms[0].elements[i].value;
		}
	}

	if (chequeado > 0)
	{
		rollOverImg('docs/images/botonContinuarOff.gif',this)
		setTimeout ("document.location = 'app/zonaOperativa/generarFacturasVis.jsp'",500)
	}
	else
	{
		alert("Debe seleccionar una opción.")
	}
}

function detalle()
{
	for (i=1;i<=3;i++)
	{
		eval("document.getElementById('detalle"+i+"').style.display='block'");
	}
}

function verNuevosAcuerdos()
{
	rollOverImg('docs/images/botonNacuerdosOff.gif',this)
	setTimeout ("document.location = 'app/clubProveedores/nuevosAcuerdos.jsp'",500)
}

function especialidades(texto)
{
	document.getElementById("especialidad").style.visibility = "visible";
	document.getElementById("contEsp").innerHTML = texto;
}

function ocultarEsp()
{
	document.getElementById("especialidad").style.visibility = "hidden";
}
	
/* Esta función redirige de diferente manera al pulsar sobre un contenido en función del comportamiento
   definido para el mismo
*/	
function enlaceContenido(comportamiento,urlInterna, urlExterna)
{
	// Enlace interno sobre la misma ventana
	if(comportamiento == 2){
		// Si estamos en la zona de manú vertical cargamos sobre el frame la url
		if(document.getElementById('ifrHomeZonaLibre') != null){
			document.getElementById('ifrHomeZonaLibre').src = urlInterna;
		}
		// Si no, es que estamos en el propio frame
		else{
			document.location = urlInterna;
		}
	}
	// Enlace interno sobre pop up		
	else if(comportamiento == 3){
		window.open(urlInterna);
	}
	// Enlace externo sobre nueva ventana
	else if(comportamiento == 4){
		window.open("http://"+urlExterna); 
	}	
}  

// Función que establece el alto de la capa padding (y su contenedora, txtHome) en función
// del espacio disponible en el body - 95 pixels, que es el alto de la cabecera
function pintascroll()
{
	document.getElementById("padding").style.height = parent.document.getElementsByTagName("body")[0].offsetHeight-100+"px";	
		
	parent.document.getElementById("txtHome").style.height=document.getElementById("padding").style.height;
		
	return false;
}

/***********************************************************/
/* valida si el valor que entra como parametro es numerico */
/***********************************************************/
function isNumerico(valor)
{
	// Si no viene ningun valor pasaria la validacion!! 
	// Porque puede ser un valor no requerido
	if (valor==null || valor.length==0)
		return true;
				
  	// Se pasa a cadena
	cad = valor.toString();
	for (var i=0; i<cad.length; i++) 
  	{
    	var caracter = cad.charAt(i);
		if (caracter<"0" || caracter>"9")
			return false;
  	}
  	return true;
}
/***********************************************************/
/* valida si el valor que entra como parametro es un mail  */
/***********************************************************/
function isMail(valor)
{			
  	// Se pasa a cadena
	cad = valor.toString();
	if (cad.indexOf("@") == -1) {
		return false;
	}
	if (cad.indexOf(".") == -1) {
		return false;
	}
	return true;
}

/* Función que imprime */
function imprimir(){
	// Eliminamos el scroll de la capa padding y modificamos height
	// para que no salga sólo la primera página
	document.getElementById('padding').style.height='auto';
	document.getElementById('padding').style.overflowY='hidden';
	
	// Ocultamos el menú
	document.getElementById('submenuproductos').style.display='none';
	window.print();
	
	// Volvemos a añadir el scroll y el menú
	document.getElementById('padding').style.overflowY='scroll';
	pintascroll();
	document.getElementById('submenuproductos').style.display='block';	
	return false;
}

function registraOperacion(url) {
	if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
	    req.open("GET", url, true);
	    req.send(null);
	} else if (window.ActiveXObject) {
	    req = new ActiveXObject("Microsoft.XMLHTTP");
	    if (req) {
	        req.open("GET", url, true);
	        req.send();
	    }
	}
}

// Funcion que se ejecuta cuando se accede a un Banner, Logo o Premio.
function llamarRegistrar(nombre, url)
{
	var archivo = "";
	var separado = new Array();
	separado = nombre.split("/");
	for (i=0;i<separado.length;i++){
		archivo = separado[i];
	}
	var tituloCompleto = archivo + " " + url;
	registraOperacion("RegistrarOperaciones.do?codigo=accBanners&descripcion=mapasist.label.accBanners&titulo="+tituloCompleto+"");
}

// Funcion que abre u PopUp y realiza una peticion al action VerDocumentoPDF, pasando como parametro la URL del Documento
function consultaDocumentosCorporativos(filial,idioma)
{	
	var tipo = document.forms['comboPDF'].opciones.value;		

	// Se compone la URL del documento o de la pagina Web
	var URLDocumento=tipo;
			
	if (tipo != null && tipo.indexOf("pdf") != -1) 
	{
		URLDocumento = "/MAPASIST_PROVEEDORES/docs/pdfs/"+filial+"/"+idioma+"/"+tipo;
	}
		
	// Si la URL no es vacia se realiza una peticion al action VerDocumentoPDF
	if (URLDocumento !=null && URLDocumento != "")
	{
		// Se construye la url con los parametros necesarios para ver el documento PDF
		var URLAction = "/MAPASIST_PROVEEDORES/ConsultaDocumentosCorporativos.do?URLDocumento="+URLDocumento;
			
		// Ancho y alto Pop Up
		popUpWidth  = 600;
		popUpHeight = 400;
			
		// Determinamos la posicion relativa del pou up en funcion de la resolucion de la pantalla
		popUpLeft = (window.screen.width-popUpWidth)/2;
		popUpTop  = (window.screen.height-popUpHeight)/2;
			
		window.open(URLAction,"_blank","toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=yes, scrollbars=yes, ,width="+popUpWidth+", height="+popUpHeight+",top="+popUpTop+",left="+popUpLeft+"");
	}
}

// Funcion que se ejecuta cuando se pulsa sobre un Banner, Logo o Premio.
function onClickBanners(codComportamiento, enlaceInterno, enlaceExterno)
{	
	// Comportamiento --> Enlace Interno PopUp
	if(codComportamiento==COD_COMPORTAMIENTO_ENLACE_INTERNO_POP_UP) 	
	{
		// Se construye la url con los parametros necesarios para consultar los banners
		var URLAction = "/MAPASIST_PROVEEDORES/ConsultaBanners.do?URL="+enlaceInterno;
					
		// Ancho y alto Pop Up
		popUpWidth  = 600;
		popUpHeight = 400;
			
		// Determinamos la posicion relativa del pou up en funcion de la resolucion de la pantalla
		popUpLeft = (window.screen.width-popUpWidth)/2;
		popUpTop  = (window.screen.height-popUpHeight)/2;
			
		window.open(URLAction,"_blank","toolbar=yes, directories=yes, location=yes, status=yes, menubar=yes, resizable=yes, scrollbars=yes, ,width="+popUpWidth+", height="+popUpHeight+",top="+popUpTop+",left="+popUpLeft+"");	
	}
	// Comportamiento --> Enlace Interno
	else if(codComportamiento==COD_COMPORTAMIENTO_ENLACE_INTERNO && location.pathname.indexOf("/Acceso/ConsultarListaProductos")==-1)
	{
		// Si estamos en la zona de manú vertical cargamos sobre el frame la url
		if(document.getElementById('ifrZonaOperativa') != null)
		{
		
			window.frames['ifrZonaOperativa'].location="/MAPASIST_PROVEEDORES/ConsultaBanners.do?URL="+enlaceInterno;
		}
		// Si no, es que estamos en el propio frame
		else
		{
			document.location = "/MAPASIST_PROVEEDORES/ConsultaBanners.do?URL="+enlaceInterno;
		}	
	}	
	// Comportamiento --> Enlace Externo
	else if(codComportamiento==COD_COMPORTAMIENTO_ENLACE_EXTERNO)
	{
		if(enlaceExterno.toUpperCase().indexOf("HTTP://")==-1 && 
		   enlaceExterno.toUpperCase().indexOf("HTTPS://")==-1 && 
		   enlaceExterno.toUpperCase().indexOf("MAILTO:")==-1 )
		{  
			enlaceExterno = "http://" + enlaceExterno;     
		}

		// Se construye la url con los parametros necesarios para consultar los banners
		var URLAction = "/MAPASIST_PROVEEDORES/ConsultaBanners.do?URL="+enlaceExterno;
						
		// Ancho y alto Pop Up
		popUpWidth  = 600;
		popUpHeight = 400;
			
		// Determinamos la posicion relativa del pou up en funcion de la resolucion de la pantalla
		popUpLeft = (window.screen.width-popUpWidth)/2;
		popUpTop  = (window.screen.height-popUpHeight)/2;
			
		window.open(URLAction,"_blank","toolbar=yes, directories=yes, location=yes, status=yes, menubar=yes, resizable=yes, scrollbars=yes, ,width="+popUpWidth+", height="+popUpHeight+",top="+popUpTop+",left="+popUpLeft+"");	
	}
}


