// rutinas.js - Funciones de JavaScript para www.plantdesign - Copyright (c) 2007 by kvbc.

function mail(texto){ 

    var mailres = true;             
    var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-"; 
     
    var arroba = texto.indexOf("@",0); 
    if ((texto.lastIndexOf("@")) != arroba) arroba = -1; 
     
    var punto = texto.lastIndexOf("."); 
                 
     for (var contador = 0 ; contador < texto.length ; contador++){ 
        if (cadena.indexOf(texto.substr(contador, 1),0) == -1){ 
            mailres = false; 
            break; 
     } 
    } 

    if ((arroba > 1) && (arroba + 1 < punto) && (punto + 2 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1)) 
      mailres = true; 
    else  {
      mailres = false; 
		}
                 
    return mailres; 
} 

function IsEmpty(aTextField) {
   if ((aTextField.value.length==0) ||
   (aTextField.value==null)) {
      return true;
   }
   else { 
	   return false; 
	 }
}

function ValidaDatos() {   //valida qie se hayan capturado todos los datos de la pagina contactos.html
	var DatosValidos = true;
	var CamposFaltantes="Debe de introducir los siguientes campos: ";
	if (IsEmpty(frmDatos.Nombre)) {
	  CamposFaltantes = CamposFaltantes + "nombre";
	  DatosValidos=false;
	}
	if (IsEmpty(frmDatos.Empresa)) {
	  CamposFaltantes = CamposFaltantes + " Empresa";
	  DatosValidos=false;
	}
	if (mail(frmDatos.email.value)==false) {
	  CamposFaltantes = CamposFaltantes + " Correo";
	  DatosValidos=false;
	}
	if (IsEmpty(frmDatos.Direccion)) {
	  CamposFaltantes = CamposFaltantes + " Direccion";
	  DatosValidos=false;
	}
	if (IsEmpty(frmDatos.Telefono)) {
	  CamposFaltantes = CamposFaltantes + " Telefono";
	  DatosValidos=false;
	}
	if (DatosValidos==false) {
      alert (CamposFaltantes)
	}
	else {
	  frmDatos.submit();
	}
	return DatosValidos;
}

function Resize() {window.location.reload()}
window.onresize=Resize;

function Pagina(pag) { 
// Todos los navegadores, menos el I.Explorer
if (self.innerHeight) {ancho= self.innerWidth; alto= self.innerHeight}
//  I.Explorer 6 en Strict Mode
else if (document.documentElement && document.documentElement.clientHeight) {ancho= document.documentElement.clientWidth; alto= document.documentElement.clientHeight}
// Otras versiones de I.Explorer
else if (document.body) {ancho=document.body.clientWidth; alto= document.body.clientHeight}
document.getElementById("Derecha").style.height=1+"px";

AncDis=parseInt(ancho);

if (AncDis >1075) {AncCue=900; AncDer=175} else {AncCue=775; AncDer=140};
document.getElementById("Derecha").style.width=AncDer+"px";
document.getElementById("Cuerpo").style.width=AncCue+"px";

AncIzq=24;
PosMen="";
PagCuerpo(pag) }

function PagCuerpo(pag) {
if (AncDis < (AncIzq + AncCue + AncDer) ) {AncIzq=0; AncDer=0};
SepDis=AncDis -AncIzq -AncCue -AncDer;
if (SepDis < 0) {SepLat=0; SepInt=0} else {SepInt=parseInt(SepDis*20/100); SepLat=parseInt(SepDis*30/100) }; 

PosMen=leerCookie('Ubicacion_Menu_Vertical');
if ( PosMen !=null) {PosMen=PosMen} else {PosMen="Derecha"};

if (PosMen=="Derecha") {
document.getElementById("Cuerpo").style.left=SepLat + AncIzq + SepInt +"px"; 
if (pag==4) {document.getElementById("Bandera").style.left=SepLat + AncIzq + SepInt +"px"};
document.getElementById("Derecha").style.left=SepLat + AncIzq + SepInt + AncCue + SepInt +"px" }

if (PosMen=="Izquierda") {
document.getElementById("Derecha").style.left=SepLat + AncIzq + SepInt +"px"; 
if (pag==4) {document.getElementById("Bandera").style.left=SepLat + AncIzq + SepInt + AncDer + SepInt -4 +"px"};
document.getElementById("Cuerpo").style.left=SepLat + AncIzq + SepInt + AncDer + SepInt -4 +"px" }

if (AncIzq > 0) {
  document.getElementById("Izquierda").style.left=SepLat +"px"; 
  document.getElementById("Izquierda").style.top=alto-350 +"px";
  document.getElementById("Izquierda").style.visibility="visible";}
  else {document.getElementById("Izquierda").style.display="none"} 
    
document.getElementById("Derecha").style.width=AncDer+"px";
if (AncDer > 0) {Menu()} else {document.getElementById("Derecha").style.display="none"; Ampliar(800)} }

function CamMenu(pag) {
if (PosMen=="Derecha") { 
    crearCookie('Ubicacion_Menu_Vertical', 'Izquierda'); 
    if (pag==4) {document.getElementById("Bandera").style.left=SepLat + AncIzq + SepInt + AncDer + SepInt -4 +"px"};
    PosMen="Izquierda"}
else {
    crearCookie('Ubicacion_Menu_Vertical', 'Derecha'); 
    if (pag==4) {document.getElementById("Bandera").style.left=SepLat + AncIzq + SepInt +"px"};
    PosMen="Derecha"} 
PagCuerpo(pag); }

function crearCookie(nombre, valor) {
var caducidad = new Date();
caducidad.setTime(caducidad.getTime() + ( 60 * 24 * 60 * 60 * 1000) ) ;
document.cookie = nombre + "=" + escape(valor) + "; expires=" + caducidad.toGMTString(); }

function leerCookie(name) {
 var cname = name + "=";
 var dc = document.cookie;
 if (dc.length > 0) { begin = dc.indexOf(name);
    if (begin != -1) { begin += cname.length; end = dc.indexOf(";", begin);
    if (end == -1) end = dc.length; return unescape(dc.substring(begin, end) ) ; } }
return null; }

AltVis=0;
function Menu() {
if (AltVis < 100 ) {
document.getElementById("Derecha").style.height=AltVis+"%"; 
document.getElementById("Derecha").style.visibility="visible";
AltVis=AltVis+2; setTimeout("Menu()",10) } else return }

// MOSTRAR TEXTOS OCULTOS
function Ampliar(num) {
document.getElementById("ampliar"+num).style.height="auto";
document.getElementById("ampliar"+num).style.display="block";
document.getElementById("ampliar"+num).style.visibility="visible";}

function AnularAmpliar(num) {
document.getElementById("ampliar"+num).style.height=1+"px";
document.getElementById("ampliar"+num).style.display="none";
document.getElementById("ampliar"+num).style.visibility="hidden"}

// ADAPTAR DIRECCION DE CORREO
arroba="@";
function CorreoAmigo(asunto) {location= "mailto:" + "?subject=" + asunto + "&amp;body=En cuanto puedas, visita: " + document.location + " "; }
function Casa(asunto) {destino="correo" + '@casaenventa.info'; location= "mailto:" + destino + "?subject=" + asunto; };

function CC() {return "consultor" + arroba + "begues.net" }
function CorreoConsultor(asunto) {document.write("<a href='mailto:" + CC() + "?subject=" + asunto + " '>" + CC() + "</a>") }

function CV() {return "correo" + arroba + "casaenventa.info" }
function CorreoCasa(asunto) {document.write("<a href='mailto:" + CV() + "?subject=" + asunto + " '>" + CV() + "</a>") }
