﻿window.onload = function() { 
	
	var anchor = document.getElementById("calcularLink"); 
	if(anchor.getAttribute("href")!="" && anchor.getAttribute("rel") == "external"){
		anchor.target = "_blank"; 
	} 
} 

function setCookie(name, value, expires, path, domain, secure)
{
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie= name + "=" + escape(value) +
	((expires) ? "; expires=" + expires_date.toGMTString() : "") +
	((path) ? "; path=" + path : "") +
	((domain) ? "; domain=" + domain : "") +
	((secure) ? "; secure" : "");
}


function imprimir() {
	if ( window.print() ) {
	  window.print();
	}
}

function cambiarImagen(name,file) {
	var img = document.getElementById( name );
	if ( img ) {
	  img.src = file;
	}
}
  

var nuevaventana;
function validadPopup(win) {
	if (win==null || typeof(win)=="undefined"){
		alert("Se ha detectado que tienes activado el bloqueador de ventanas en tu navegador.\nNuestras ventanas emergentes no contienen publicidad sino información que te es necesaria.\nIndica a tu navegador que acepte las ventanas emergente provinientes de nuestro sitio.");
		return false;
	} else {
		if (parseInt(navigator.appVersion) >= 4) { win.focus(); }  
	}
	
}

function pantallacompleta(win) {
	if (win && document.all) {
		win.resizeTo(screen.availWidth,screen.availHeight);
	} else if (document.layers||document.getElementById) {
		if (win.outerHeight<screen.availHeight||win.outerWidth<screen.availWidth){
			win.outerHeight = screen.availHeight;
			win.outerWidth = screen.availWidth;
		}	
	}
}

function AbrirVentana(theURL,winName,w,h) { //v2.0
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',top=0,left=0,scrollbars=yes';
	var nuevaventana = window.open(theURL,winName,winprops);
	validadPopup(nuevaventana);
	pantallacompleta(nuevaventana);
}

function AbrirVentana_completa(theURL,winName,w,h) { //v2.0

            winprops = 'height='+h+',width='+w+',top=0,left=0,scrollbars=yes,fullscreen=no';

            var nuevaventana = window.open(theURL,winName,winprops);

            validadPopup(nuevaventana);

            pantallacompleta(nuevaventana);
}

function AbrirVentana_1(theURL,winName,w,h) { //v2.0
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=yes,scrollbars=yes,fullscreen=no';
	if (!Opera56) win = window.open(theURL,winName,winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }  
}

//MARQUESINA
var porc = 0;
var intervalo;
var empezar = 1;

function getHeight(divId){
	var divHeight = 0;
	document.getElementById(divId).style.height="auto";
	if(document.getElementById(divId).clientHeight) {
		divHeight = document.getElementById(divId).clientHeight;
	} else if(document.getElementById(divId).offsetHeight) {
		divHeight = document.getElementById(divId).offsetHeight;
	} else if(document.getElementById(divId).innerHeight) {
		divHeight = document.getElementById(divId).innerHeight;
	} else if(document.getElementById(divId).scrollHeight) {
		divHeight = document.getElementById(divId).scrollHeight;
	}
	if(divHeight>0) divHeight = divHeight - 65;
	if(divHeight<0) divHeight = 0;
	return divHeight;
}

function scrollNews(dir){
var divHeight = getHeight('noticiasDiv');
if(!dir){
	if(porc < 1){
	porc = porc + 0.01;
	}
}else{
	if(porc > 0){
	porc = porc - 0.01;
	}
}
document.getElementById('noticiasDiv').style.top = (-parseFloat(porc) * divHeight).toString() + "px";
}0,57142857142857142857142857142857

function start(dir){
	var divHeight = getHeight('noticiasDiv');	
	
	if(empezar){
		intervalo = setInterval("scrollNews("+dir+")",divHeight * 0.6);
	}
}
function stop(){
	empezar = 0;
	clearInterval(intervalo);
	empezar = 1;
}

//MARQUESINA

//OTROS JS

	
function abrirCotizacion() {
	var direccion = "https://www.balumba.es/balumba/SNetPeticion?idPeticion=INSERV0001&servicio=COTIZANET&producto=AU01&operacion=NUEVACOT";
	var direccion3 = "mapa.html";
	AbrirVentana(direccion,"presupuesto","800","700");
}	

function msgValidador(i) {
	var obj = document.forms[i];
	obj.numedocu.regexp="_cadena";
	obj.numedocu.message="NÚMERO DE DOCUMENTO: No puede estar en blanco. (Ej.: 22343966T)";
	obj.cotizsec.regexp="_numeroEnteroSinSigno";
	obj.cotizsec.message="NÚMERO DE PRESUPUESTO: Debe rellenarse con números y no puede contener espacios en blanco.";

}

function enviarForm(i) {
	msgValidador(i);
	if (!validarTodoEnLista()) {
		return false;
	} else {
	
		var direccion = "https://www.balumba.es/balumba/SNetPeticion?idPeticion=INSERV0001&servicio=COTIZANET&producto=AU01&operacion=MODIFICAR";
		direccion = direccion + "&numedocu=" +document.forms[i].numedocu.value + "&cotizsec=" + document.forms[i].cotizsec.value;
		top.location = direccion;
		//var laventana = window.open(direccion, "Presupuesto","width=800,height=700,top=0,left=0,scrollbars=yes");
		//pantallacompleta(laventana);
		return false;
	}
}

function getParams() 
{
	var idx = document.URL.indexOf('?');
	var params = new Array();
	if (idx != -1) {
		var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
		for (var i=0; i<pairs.length; i++) {
			nameVal = pairs[i].split('=');
			params[nameVal[0]] = nameVal[1];
		}
	}
	return params;
}

var urldestino = "";
var urldestino2 = "";
var params = getParams();  
var urlorigen = "";
var urlbanner = "";

var urlorigen = params["urlorigen"];
var urlbanner = params["urlbanner"];	

if(urlorigen=="00010020"){
	var mytduid = params["tduid"];
	setCookie('TRADEDOUBLER', mytduid, 365);
}
