function findPosX(varobj){
  var obj = document.getElementById(varobj);
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
		
	return curleft;
	
  }

  function findPosY(varobj){
  var obj = document.getElementById(varobj);
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  
function mostrarCapaAdv(varid,varVal,varPos){
	var idcapa = document.getElementById(varid);
	
	idcapa.style.top=212;
	idcapa.style.left=450;
	
	
	idcapa.style.visibility=varVal;
	idcapa.style.position=varPos;
}

function mostrarCapaAdv2(varid,varVal,varPos,varX,varY){
	var idcapa = document.getElementById(varid);
	
	idcapa.style.top=varY;
	idcapa.style.left=varX;
	
	
	idcapa.style.visibility=varVal;
	idcapa.style.position=varPos;
}

function openWindow(url,name,w,h,sc){
	var ancho_interface=10;
	var alto_interface=29;
	var tamx=screen.width;
	var tamy=screen.height;
	var posx=(tamx-(parseInt(w)+ancho_interface))/2;
	var posy=(tamy -(parseInt(h)+alto_interface))/2;
		
	var parameters = 'width='+w+',height='+h+',top='+posy+',left='+posx+',scrollbars='+sc;
	window.open(url,name,parameters);
}

function EsDigito(val) {
    return ((val >= "0") && (val <= "9"));
}

function EsDigitos(val) {
    for(i=0;i<val.length;i++){
        if(!EsDigito(val.charAt(i))) return false;
    }
    return true;
}    
    
function EsRango(val,min,max) {
    if (!EsNumerico(val)) return false;
    if (val<min || max<val) return false;
    return true;
}

function MinCaracteres(val,num) {
    return !(val.length<num);
}

function EsTelefono(val) {
    if (!MinCaracteres(val,9)) return false;
    if (!EsDigitos(val)) return false;
    if (val.charAt(0)!="9") return false;
    return true;
}

function EsMovil(val) {
    if (!MinCaracteres(val,9)) return false;
    if (!EsDigitos(val)) return false;
    if (val.charAt(0)!="6") return false;
    return true;
}

function EsVacio(val) {
    return ((val == null) || (val.length == 0));
}

function EsNumerico(val) {
    num = parseFloat(val);
    if (val!=''+num) return false;
    return true;
}

function EsFecha(val) {
    var dia = parseInt(val.substr(0,2),10);
    var mes = parseInt(val.substr(3,2),10);
    var anyo = parseInt(val.substr(6,4),10);
  
    if(val.length!=10) return false;
    d = new Date(val)
    if (isNaN( d.valueOf() )) return false;
    sArray = val.split("/")
    if (sArray.length > 3) return false;
    if( (sArray[0].length!=2) || (sArray[1].length!=2) || (sArray[2].length!=4) ) return false;
    if( (anyo<0) || (anyo>9999) ) return false;
    if((mes>12) || (mes<1)) return false;
    if((mes==4)||(mes==6)||(mes==9)||(mes==11)) {
        if((dia>30) || (dia<1)) return false;
    }
    if((mes==1)||(mes==3)||(mes==5)||(mes==7)||(mes==8)||(mes==10)||(mes==12)) {
            if((dia>31) || (dia<1)) return false;
    }
    if((mes==2) && (!EsBisiesto(anyo))) {
            if((dia>28) || (dia<1)) return false;
    } else if((mes==2) && (EsBisiesto(anyo))) {
            if((dia>29) || (dia<1)) return false;
    }
    return true;
}

function EsBisiesto(val) {
    return ((val % 4 == 0) && ((!(val % 100 == 0)) || (val % 400 == 0)));
}

function EsEmail(val) {
    arroba = val.lastIndexOf('@');

    if ( arroba < 1 )
        return false;
    else {
    punto = val.indexOf('.', arroba);
      if ( punto < arroba + 2 ||
         punto > val.length - 2 ) {
         return false;
      }
   }
   return true;
}

function ValidarTexto(texto){
    
    if ( texto.indexOf('@',0) != -1 || texto.indexOf(';',0) != -1
     || texto.indexOf(' ',0) != -1 || texto.indexOf('/',0) != -1
     || texto.indexOf(';',0) != -1 || texto.indexOf('<',0) != -1
     || texto.indexOf('>',0) != -1 || texto.indexOf('*',0) != -1
     || texto.indexOf('|',0) != -1 || texto.indexOf('`',0) != -1
     || texto.indexOf('&',0) != -1 || texto.indexOf('$',0) != -1
     || texto.indexOf('!',0) != -1 || texto.indexOf('"',0) != -1
     || texto.indexOf(':',0) != -1 || texto.indexOf("'",0) != -1
     || texto.indexOf(',',0) != -1)
       { return false; }
    
    return true;
}

function openCalendar(varX,varY,varCampo,varFecha){
	args = openCalendar.arguments;
	
	window.open('../calendario/calendario.asp?Campo='+varCampo+'&Fecha='+varFecha+'&nolimit='+args[4],'calendar','left='+varX+',top='+varY+',height=140,width=145');
}
function openCalendar2(varX,varY,varCampo,varFecha){
	args = openCalendar2.arguments;
	
	window.open('calendario/calendario.asp?Campo='+varCampo+'&Fecha='+varFecha+'&nolimit='+args[4],'calendar','left='+varX+',top='+varY+',height=140,width=145');
}

function openCalendarSMS(varX,varY,varCampo,varFecha){
	window.open('calendario.asp?Campo='+varCampo+'&Fecha='+varFecha+'&nolimit=','calendar','left='+varX+',top='+varY+',height=140,width=145');
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe contener una dirección de e-mail.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' debe ser un número.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' debe ser un número entre '+min+' y '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es obligatorio.\n'; }
  } if (errors) alert('se han producido los siguientes errores:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

function sobre(src,Color) {
   
   // if (!src.contains(event.fromElement)) {
	  src.style.cursor = 'pointer';
	  src.style.backgroundColor = Color;
	  //src.style.color = '#ffffff';
	//}
}

function fuera(src,Color) {
	//if (!src.contains(event.toElement)) {
	  src.style.cursor = 'default';
	  src.style.backgroundColor = Color;
	//}
}

function EsIP(val) {
  	var tblIPSNulas = new Array('127.0.0.1','255.255.255.0','255.255.255.255','0.0.0.0');
	if(EsVacio(val)) return false;
	
	sArray = val.split(".");
	if (sArray.length != 4) return false;
	if( (!EsNumerico(sArray[0])) || (!EsNumerico(sArray[1])) 
	|| (!EsNumerico(sArray[2])) || (!EsNumerico(sArray[3])) ) return false;
	if( (parseFloat(sArray[0])>255) || (parseFloat(sArray[1])>255) 
	|| (parseFloat(sArray[2])>255) || (parseFloat(sArray[3])>255) ) return false;
	if( (parseFloat(sArray[0])<0) || (parseFloat(sArray[1])<0) 
	|| (parseFloat(sArray[2])<0) || (parseFloat(sArray[3])<0) ) return false;
	
	for (var i=0;i<tblIPSNulas.length;i++){
		if (val==tblIPSNulas[i]){return false;}
	}
	
	return true;
}

function EsDominio(val) {
	if(EsVacio(val)) return false;
	
	sArray = val.split(".");
	if (sArray.length != 2) return false;
	if (!ValidarTexto(sArray[0])) return false;
	if (!ValidarTexto(sArray[1])) return false;
	if ( (sArray[0].length<=0) || (sArray[1].length<=1) ) return false;
		
	return true;
}

function selecionaTodosLista(objLista){
	for (i=0;i<=(objLista.length-1);i++){
		objLista.options[i].selected = true;
	}
}

function cambiaImagen(id, src){
	var img = document.getElementById(id);
	
	img.src = src;
}

function cambiaImagenADV(obj, src){
	obj.src = src;
}

function validarBuscador(frm){
	if (EsVacio(frm.txtbuscar.value)){alert('Debe introducir un texto para buscar.');return false;}
	
	return true;
}


//obtiene los parametros de la querystring
//var strQueryString = "";
//var strLocation = document.location+'';
//if (strLocation.indexOf('?')!=-1){
//	strQueryString = strLocation.substring(strLocation.indexOf('?')+1,strLocation.length);
//	strQueryString = strQueryString.replace('%2E','.');
//	strQueryString = strQueryString.replace('accesibilidad=estilo.css&','');
//	strQueryString = strQueryString.replace('accesibilidad=estilo_grande.css&','');
//	strQueryString = strQueryString.replace('accesibilidad=estilo.css','');
//	strQueryString = strQueryString.replace('accesibilidad=estilo_grande.css','');
//	strQueryString = '&' + strQueryString;
//}
//
//****************************************






var linkset=new Array()
//SPECIFY MENU SETS AND THEIR LINKS. FOLLOW SYNTAX LAID OUT

linkset[0]='<div class="menuitems"><a href="tipo_gestion.asp?page=selec_dormitorios.asp$I$page=listado_de_casas.asp" class="txtnegro"><b>·</b>&nbsp;Casas</a>&nbsp;</div>'
linkset[0]+='<div class="menuitems"><a href="tipo_gestion.asp?page=selec_dormitorios.asp$I$page=listado_de_chalets.asp" class="txtnegro"><b>·</b>&nbsp;Chalets</a>&nbsp;</div>'
linkset[0]+='<div class="menuitems"><a href="tipo_gestion.asp?page=listado_de_fincasrusticas.asp$I$page=" class="txtnegro"><b>·</b>&nbsp;Fincas Rústicas</a>&nbsp;</div>'
linkset[0]+='<div class="menuitems"><a href="tipo_gestion.asp?page=listado_de_garajes.asp$I$page=" class="txtnegro"><b>·</b>&nbsp;Garajes</a>&nbsp;</div>'
linkset[0]+='<div class="menuitems"><a href="tipo_gestion.asp?page=listado_de_locales.asp$I$page=" class="txtnegro"><b>·</b>&nbsp;Locales</a>&nbsp;</div>'
linkset[0]+='<div class="menuitems"><a href="tipo_gestion.asp?page=listado_de_naves.asp$I$page=" class="txtnegro"><b>·</b>&nbsp;Naves</a>&nbsp;</div>'
linkset[0]+='<div class="menuitems"><a href="tipo_gestion.asp?page=listado_de_oficinas.asp$I$page=" class="txtnegro"><b>·</b>&nbsp;Oficinas</a>&nbsp;</div>'
linkset[0]+='<div class="menuitems"><a href="tipo_gestion.asp?page=listado_de_parcelasurbanizables.asp$I$page=" class="txtnegro"><b>·</b>&nbsp;Parcelas urbanizables</a>&nbsp;</div>'
linkset[0]+='<div class="menuitems"><a href="tipo_gestion.asp?page=selec_dormitorios.asp$I$page=listado_de_pisos.asp" class="txtnegro"><b>·</b>&nbsp;Pisos</a>&nbsp;</div>'
linkset[0]+='<div class="menuitems"><a href="tipo_gestion.asp?page=listado_de_solares.asp$I$page=" class="txtnegro"><b>·</b>&nbsp;Solares</a>&nbsp;</div>'
linkset[0]+='<div class="menuitems"><a href="tipo_gestion.asp?page=listado_de_varios.asp$I$page=" class="txtnegro"><b>·</b>&nbsp;Varios</a>&nbsp;</div>'

linkset[1]='<div class="menuitems"><a href="calc_hipotecas.asp" class="txtnegro"><b>·</b>&nbsp;Calculadora de hipotecas</a>&nbsp;</div>'
linkset[1]+='<div class="menuitems"><a href="ahorrofiscal.asp" class="txtnegro"><b>·</b>&nbsp;Ahorro fiscal</a>&nbsp;</div>'
linkset[1]+='<div class="menuitems"><a href="gastoscompraventa.asp" class="txtnegro"><b>·</b>&nbsp;Gastos de Compra-Venta</a>&nbsp;</div>'
linkset[1]+='<div class="menuitems"><a href="calc_creditospersonales.asp" class="txtnegro"><b>·</b>&nbsp;Calcule su crédito personal</a>&nbsp;</div>'

linkset[2]='<div class="menuitems"><a href="index2.asp?accesibilidad=estilo_grande.css" class="txtnegro"><b>·</b>&nbsp;Texto grande</a>&nbsp;</div>'
linkset[2]+='<div class="menuitems"><a href="index2.asp?accesibilidad=estilo.css" class="txtnegro"><b>·</b>&nbsp;Texto pequeño</a>&nbsp;</div>'

////No need to edit beyond here

var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers

function showmenu(e,which){

if (!document.all&&!document.getElementById&&!document.layers)
return

clearhidemenu()

menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj

if (ie4||ns6)
menuobj.innerHTML=which
else{
menuobj.document.write('<layer name=gui bgColor=#E6E6E6 width=165 onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>')
menuobj.document.close()
}

menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
eventX=ie4? event.clientX : ns6? e.clientX : e.x
eventY=ie4? event.clientY : ns6? e.clientY : e.y

//Find out how close the mouse is to the corner of the window
var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.contentwidth)
//move the horizontal position of the menu to the left by it's width
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.thestyle.left=ie4? document.body.scrollLeft+eventX : ns6? window.pageXOffset+eventX : eventX

//same concept with the vertical position
if (bottomedge<menuobj.contentheight)
menuobj.thestyle.top=ie4? document.body.scrollTop+eventY-menuobj.contentheight : ns6? window.pageYOffset+eventY-menuobj.contentheight : eventY-menuobj.contentheight
else
menuobj.thestyle.top=ie4? document.body.scrollTop+event.clientY : ns6? window.pageYOffset+eventY : eventY
menuobj.thestyle.visibility="visible"
return false
}

function contains_ns6(a, b) {
//Determines if 1 element in contained in another- by Brainjar.com
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function hidemenu(){
if (window.menuobj)
menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
}

function dynamichide(e){
if (ie4&&!menuobj.contains(e.toElement))
hidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
hidemenu()
}

function delayhidemenu(){
if (ie4||ns6||ns4)
delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
if (window.delayhide)
clearTimeout(delayhide)
}

function highlightmenu(e,state){
if (document.all)
source_el=event.srcElement
else if (document.getElementById)
source_el=e.target
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
else{
while(source_el.id!="popmenu"){
source_el=document.getElementById? source_el.parentNode : source_el.parentElement
if (source_el.className=="menuitems"){
source_el.id=(state=="on")? "mouseoverstyle" : ""
}
}
}
}

if (ie4||ns6)
document.onclick=hidemenu

var ie=document.all
var ns6=document.getElementById&&!document.all

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat" && !window.opera)? document.documentElement : document.body
}

function enlarge(which, e, position, imgwidth, imgheight){
if (ie||ns6){
crossobj=document.getElementById? document.getElementById("showimage") : document.all.showimage
if (position=="center"){
pgyoffset=ns6? parseInt(pageYOffset) : parseInt(ietruebody().scrollTop)
horzpos=ns6? pageXOffset+window.innerWidth/2-imgwidth/2 : ietruebody().scrollLeft+ietruebody().clientWidth/2-imgwidth/2
vertpos=ns6? pgyoffset+window.innerHeight/2-imgheight/2 : pgyoffset+ietruebody().clientHeight/2-imgheight/2
if (window.opera && window.innerHeight) //compensate for Opera toolbar
vertpos=pgyoffset+window.innerHeight/2-imgheight/2
vertpos=Math.max(pgyoffset, vertpos)
}
else{
var horzpos=ns6? pageXOffset+e.clientX : ietruebody().scrollLeft+event.clientX
var vertpos=ns6? pageYOffset+e.clientY : ietruebody().scrollTop+event.clientY
}
crossobj.style.left=horzpos+"px"
crossobj.style.top=vertpos+"px"

crossobj.innerHTML='<div align="right" id="dragbar" onMouseOver=sobre(this,"#333333") onMouseOut=fuera(this,"")><span id="closetext" class="menu" onClick="closepreview()"><img src="pics/close_d.gif" width="11" height="11" align="absmiddle" alt="CERRAR" hspace="2"></span> </div><img src="'+which+'" vspace="2" hspace="2">'
crossobj.style.visibility="visible"
return false
}
else //if NOT IE 4+ or NS 6+, simply display image in full browser window
return true
}

function closepreview(){
crossobj.style.visibility="hidden"
}

function drag_drop(e){
if (ie&&dragapproved){
crossobj.style.left=tempx+event.clientX-offsetx+"px"
crossobj.style.top=tempy+event.clientY-offsety+"px"
}
else if (ns6&&dragapproved){
crossobj.style.left=tempx+e.clientX-offsetx+"px"
crossobj.style.top=tempy+e.clientY-offsety+"px"
}
return false
}

function initializedrag(e){
if (ie&&event.srcElement.id=="dragbar"||ns6&&e.target.id=="dragbar"){
offsetx=ie? event.clientX : e.clientX
offsety=ie? event.clientY : e.clientY

tempx=parseInt(crossobj.style.left)
tempy=parseInt(crossobj.style.top)

dragapproved=true
document.onmousemove=drag_drop
}
}

document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")

