﻿/*
   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
  |                                                                           |
  |   Application      :  Andian - Gestión Interna (Content Manager System)   |
  |   Author           :  2d2art - Daniel Vázquez [web developer]             |
  |   Contact          :  info@2d2art.com - www.2d2art.com                    |
  |   Info             :  Web developers                                      |
  |                       Content Manager Systems                             |
  |                       Flash, html, xhtml,                                 |
  |                       css, javaScript, VBScript, ActionScript,            |
  |                       .net, ASP, Visual Basic, SQL, DDBB,                 |
  |                       interactive CDs, ...                                |
  |   Location         :  Barcelona                                           |
  |   Legal            :  All rigths reserved by the author                   |
  |_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|

*/
ventanaSecundaria=0;

function rollOverTr (obj) {
		obj.className=obj.className + " trOver";
		obj.onmouseout = function() {			
			obj.className=obj.className.slice(obj.className.indexOf(" trOver"),obj.className.lastIndexOf(" trOver"));
		}
};

function rollOverTd (obj) {		
		obj.className=obj.className + " tdOver";		
		obj.onmouseout = function() {
		obj.className=obj.className.replace(/ tdOver/g, "")		
		}		
};

function rollOverDiv (obj) {		
		obj.className=obj.className + " divOver";		
		obj.onmouseout = function() {		
				obj.className=obj.className.replace(/ divOver/g, "")		
		}
};

function irUrl (url) {
	window.location = url;
};

function borraValueLabel (obj, valueLabel) {
	if (obj.value == valueLabel) {
		obj.value = "";
	}	
	obj.onblur = function() {	
		if (obj.value == "") {	
			obj.value = valueLabel;
		}
	}
};

function initGrupoPlantas() {
	if (document.getElementById('plantaActiva')!=null) {
		if (document.getElementById('plantaActiva').value!=""){
			plantaActual(document.getElementById(document.getElementById('plantaActiva').value));						
		}	
	}
};

function plantaActual (obj) {	
	if (document.getElementById('plantaActiva')!=null) {
		document.getElementById('plantaActiva').value=obj.id;
	}	
	var planta = [];
	planta=obj.parentNode.parentNode.getElementsByTagName('td');	
	for (var i=0; i<planta.length; i++){		
		planta[i].className=planta[i].className.replace(/plantaActual/g, "");		
	}
	obj.className=obj.className + " plantaActual";
};


var ccaa = new Array();
function preLoadCCAA(nombre,on,idCCAA) {
	ccaa[nombre]=new Image();
	ccaa[nombre].src = on;
	ccaa[nombre].idCCAA = idCCAA;
};

function formatoDecimal(obj){
	var patronDec = /[0-9.,]/;
	if (patronDec.test(obj.value)) {
		var valorPrecio = new String();	
		var valorEntero = new String();
		var valorDecimal = new String();
		var digito = [];
		valorPrecio=obj.value.replace(/\./g,"");
		valorPrecio=valorPrecio.replace(/^0*/g,"");		
		valorPrecio=valorPrecio+",";
		valorEntero=valorPrecio.substring(0,valorPrecio.indexOf(","));
		if (valorEntero=="") {
			valorEntero="0";
		}				
		valorDecimal=valorPrecio.slice(valorPrecio.indexOf(",")+1,valorPrecio.length+1);
		valorDecimal=valorDecimal.replace(/,/g,"");
		valorPrecio=String((parseFloat(valorEntero)+Math.round(parseFloat("0."+valorDecimal)*100)/100).toFixed(2));
		valorEntero=valorPrecio.substring(0,valorPrecio.indexOf("."));
		valorDecimal=valorPrecio.slice(valorPrecio.indexOf(".")+1,valorPrecio.length+1);	
		digito=valorEntero.split("");
		valorEntero="";	
		var j = 0;
		for (var i = digito.length-1; i>-1; i--) {
			j++;
			valorEntero=digito[i]+valorEntero;
			if (j==3 && i!=0) {
				valorEntero="."+valorEntero;
				j=0;
			}			
		}					
		obj.value=valorEntero+","+valorDecimal;				
	}
};

function ctrlEsNumDec(e){
	var key = window.event ? e.keyCode : e.which;
	var keyChar = String.fromCharCode(key);
	var patronDec = /[0-9.,]/;
	return patronDec.test(keyChar);	
};

function inicializaMapa() {
	preLoadCCAA("noCCAA","sistema/activos/noCCAA.gif","0");
	preLoadCCAA("andalucia","sistema/activos/andalucia.gif","01");
	preLoadCCAA("aragon","sistema/activos/aragon.gif","02");
	preLoadCCAA("asturies","sistema/activos/asturies.gif","03");
	preLoadCCAA("cantabria","sistema/activos/cantabria.gif","06");
	preLoadCCAA("castillaLaMancha","sistema/activos/castLaMancha.gif","07");
	preLoadCCAA("castillaYLeon","sistema/activos/castYLeon.gif","08");	
	preLoadCCAA("catalunya","sistema/activos/catalunya.gif","09");
	preLoadCCAA("euskadi","sistema/activos/euskadi.gif","15");
	preLoadCCAA("extremadura","sistema/activos/extremadura.gif","10");
	preLoadCCAA("galiza","sistema/activos/galiza.gif","11");
	preLoadCCAA("illesBalearsIbizaFormentera","sistema/activos/illesBalears.gif","04");
	preLoadCCAA("illesBalearsMallorca","sistema/activos/illesBalears.gif","04");
	preLoadCCAA("illesBalearsMenorca","sistema/activos/illesBalears.gif","04");	
	preLoadCCAA("laRioja","sistema/activos/laRioja.gif","16");
	preLoadCCAA("madrid","sistema/activos/madrid.gif","12");
	preLoadCCAA("murcia","sistema/activos/murcia.gif","13");
	preLoadCCAA("nafarroa","sistema/activos/nafarroa.gif","14");
	preLoadCCAA("valencia","sistema/activos/valencia.gif","17");	
	var ddlCcaa = document.getElementById('ddlCcaa')	
	for (var i in ccaa) {		
		if (ccaa[i].idCCAA == ddlCcaa[ddlCcaa.selectedIndex].value) {
			document.getElementById('mapaPIberica').style.backgroundImage = 'url('+ccaa[i].src+')';	
			break;
		}
	}
		
	for (var i = 0; i < ddlCcaa.options.length; i++){	
		if (ddlCcaa.options[i].value != "0") {
			document.getElementById('ccaaAct'+ddlCcaa.options[i].value).style.backgroundImage = 'url(sistema/activos/ccaaAct'+ddlCcaa.options[i].value+'.gif)';			
		}
	}
							
};

function abrirSecundaria(obj){
  if(ventanaSecundaria)  {
    if(!ventanaSecundaria.closed) {
		ventanaSecundaria.close();
	}
  }
  ventanaSecundaria=window.open(obj.href, 'ventanaSecundaria', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=yes,resizable=no,copyhistory=no,width=501,height=300');

};

function abrirSecundariaUrl(href) {
	window.open(href, 'Documento');
};


function rollOverCCAA (obj) {	
		var mapaPIberica = document.getElementById('mapaPIberica');
		mapaPIberica.src=ccaa[obj.id].src;		
		obj.onclick = function() {
			var ddlCcaa = document.getElementById('ddlCcaa')				
			if (ccaa[obj.id].idCCAA != ddlCcaa[ddlCcaa.selectedIndex].value){
				for (var i = 0; i < ddlCcaa.options.length; i++){
					if (ccaa[obj.id].idCCAA == ddlCcaa.options[i].value) {
						ddlCcaa.options[i].selected = true;
						mapaPIberica.style.backgroundImage = 'url('+ccaa[obj.id].src+')';
						__doPostBack('ddlCcaa','');
						break;
					}
				}
			}
		}		
		obj.onmouseout = function() {	
				document.getElementById('mapaPIberica').src=ccaa['noCCAA'].src;		
		}
};

function cambiaImgPpal(src){
	if (document.getElementById('imgPpalInmuebleHolder')) {
		document.getElementById('imgPpalInmuebleHolder').src=src;
	} else {
		imgPpalInmuebleHolder.src=src;
	}
};

function ctrlEmail() {	

	if (telfOk(document.getElementById('telefonoConsulta').value) || eMailOk(document.getElementById('email').value)) {
		submit();
	} else {		
		alert ("Por favor, introducza un teléfono o una dirección de correo electrónico válidos, para que podamos ponernos en contacto con usted. \n \nMuchas gracias.");
		
	}
		
};

function telfOk(telf) {
	var patronTelf = /^([0-9\s\+\-])+$/;
	if (!patronTelf.test(telf)) {
	    //alert ("Número de teléfono incorrecto");						 
		return false;
	 }
	 return true;
};

function eMailOk(email) {
	var patronEmail = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!patronEmail.test(email)) { 
	    //alert ("Dirección de correo electrónico incorrecta"); 
	    return false; 
	} 
	return true; 	
};

function invisible(obj){	
	obj.style.visibility="hidden";
};

function visible(obj){
	obj.style.visibility="inherit";
};

function oculta(id){	
	invisible(document.getElementById(id));
};

function muestra(id){
	visible(document.getElementById(id));
};


function buscaId(id) { 
	if(document.layers) {
		return document.layersid; 
	}

	if(document.all && !document.getElementById) {
		return document.allid; 
	}
	if(document.all && document.getElementById) {
		return document.getElementById(id); 
	}
	if(!document.all && document.getElementById) {
		return document.getElementById(id); 
	}
};

var imgHPx = 499;
var imgVpx = 340;
var imgContHPx = 163;
var imgContVPx = 340;

var tiempo = 40;
var avancePx = 20;
var actualPx = 0;
var mueveOn;


function iniciaMueveI(velocidad){
	mueveOn=setInterval('mueveI('+velocidad+')',tiempo);
};

function iniciaMueveD(velocidad){
	mueveOn=setInterval('mueveD('+velocidad+')',tiempo);
};

function paraMueve(){
	clearInterval(mueveOn);
};

function mueveI(velocidad){	
	if (actualPx == 0){
		paraMueve();
		iniciaMueveD(0.05);
	}else{
		var obj = buscaId("contImgPanoramica");
		actualPx += avancePx*velocidad;
		obj.style.backgroundPosition = actualPx+'px 0px';
	}	
};

function mueveD(velocidad){
	if (actualPx == (imgContHPx-imgHPx)){
		paraMueve();
		iniciaMueveI(0.05);
	}else{
		var obj = buscaId("contImgPanoramica");
		actualPx -= avancePx*velocidad;
		obj.style.backgroundPosition = actualPx+'px 0px';
	}
};


