//----------------------------------------------------------------------------------
// Default.aspxhttp://localhost:1089/ICPrefabricados/ProyectosRealizados.aspx?Id=52
//----------------------------------------------------------------------------------
function CargarSimulador(idProyecto, idApartamento) {
    MyVentana = window.open('SimuladorDeCredito.aspx?Id=' + idProyecto + '&Id2=' + idApartamento, 'Simulador', 
	    'left=20,top=20,width=500,height=300,toolbar=0,resizable=1,scrollbars=1');
    MyVentana.focus();
}

function VisualizarFoto(rootFoto) {
    if(rootFoto != undefined) {
	    MyVentana = window.open(rootFoto, 'Ventana', 
		    'left=20,top=20,width=720,height=480,toolbar=0,resizable=1,scrollbars=1');
	    MyVentana.focus();
	}
}       

function ListadoDePrecios(listadoDePrecioURL) {
    window.location = listadoDePrecioURL;
} 
    
function DescargarListaDePrecios(idProyecto) {
    switch(idProyecto) {
        case 78:
            window.location = "ListadoDePrecios/Conjunto_Habitacional_Sayab.xls";
            
            break;      
    }      
    
    sleep(4000);
    window.close();
}

function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}
        
function RegistrarCotizacion(
    idApartamento, 
    nombre,
    ciudad,
    direccion,
    telefono,
    monto,
    email,
    opcion1,
    TextoOpcion1,
    Monto1,
    opcion2,
    TextoOpcion2,
    Monto2,
    opcion3,
    TextoOpcion3,
    Monto3,            
    opcion4,
    TextoOpcion4,
    Monto4,            
    opcion5,
    TextoOpcion5,
    Monto5,            
    opcion6,
    TextoOpcion6,
    Monto6,
    opcion7,
    TextoOpcion7,
    Monto7,            
    opcion8,
    TextoOpcion8,
    Monto8            
) {
    try 
    {
        // Valida que el email sea la correcta...
        var re = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");
        var m = re.exec(email);
                        
        if (m == null) {
            alert("Debe especificar correctamente la dirección de correo");
            return;
        }
                    
        Service.RegistrarCotizacion(
            idApartamento, 
            nombre,
            ciudad,
            direccion,
            telefono,
            monto,
            email,
            opcion1,
            TextoOpcion1,
            Monto1,
            opcion2,
            TextoOpcion2,
            Monto2,
            opcion3,
            TextoOpcion3,
            Monto3,            
            opcion4,
            TextoOpcion4,
            Monto4,            
            opcion5,
            TextoOpcion5,
            Monto5,            
            opcion6,
            TextoOpcion6,
            Monto6,
            opcion7,
            TextoOpcion7,
            Monto7,            
            opcion8,
            TextoOpcion8,
            Monto8            
        );      
        
        alert("A sido enviada a nuestros asesores, se pondrán en contacto con usted pronto");
    }
    
    catch(err) 
    {
        alert(err);
    }
}

function Contactenos(idProyecto, nombre, telefono, email) {
    // Valida que el email sea la correcta...
    var re = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");
    var m = re.exec(email);
                    
    if (m == null) {
        alert("Debe especificar correctamente la dirección de correo");
        return;
    }
    
    try
    {
        Service.Contactenos(idProyecto, nombre, telefono, email);
        alert("Gracias, en breve nos comunicaremos con usted");
    }
    
    catch(err) 
    {
        alert(err);
    }    
}

function RegistrarContarleAUnAmigo(idProyecto, idApartamento, de, emailPara, mensaje) {
    try 
    {
        // Valida que el email sea la correcta...
        var re = new RegExp("^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$");
        var m = re.exec(emailPara);
                        
        if (m == null) {
            alert("Por favor revise la dirección de correo a quien le quiere contar");
            return;
        }
        
        // Manda el correo...
        Service.RegistrarContarleAUnAmigo(idProyecto, idApartamento, de, emailPara, mensaje);
        
        alert("Mensaje Enviado");
    }
    
    catch(err) 
    {
        alert(err);
    }
} 
//----------------------------------------------------------------------------------
// Default.aspx
//----------------------------------------------------------------------------------

//----------------------------------------------------------------------------------
// Common Methods
//----------------------------------------------------------------------------------
function Trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function SendByKey(keycode)
{
    if (keycode == 13) Buscar();
    event.returnValue = false;
}

function preloadimages(imagesarray){
    
    ob=imagesarray.split(",")// spliting the images argument to array of images names
    
    for (t = 0; t <= ob.length; t++){// start looping
        newimage = new Image()// creating image object

        newimage.src = ob[t]// loading the images
    }
} 
//----------------------------------------------------------------------------------
// Common Methods
//----------------------------------------------------------------------------------

//----------------------------------------------------------------------------------
// URL Navigation (Common to all pages)
//----------------------------------------------------------------------------------
function ChatIni() {
    ChatVentana = window.open("ChatV1/Default.aspx", 'ChatVentana', 
        'left=20,top=20,width=630,height=720,toolbar=0,resizable=0,scrollbars=yes;');        

	ChatVentana.focus();
}    

function BuscarTexto() {
    var TextoABuscar = Trim(document.getElementById('Buscar1').value);
    if(TextoABuscar.length > 0) {
        URL = "BuscarEnSite.aspx?criteria=" + TextoABuscar;
        window.location = URL;
    }
}

function Login() {
    alert("En construcción");
}

function NuestraEmpresa() {
    window.location = "NuestraEmpresa.aspx";
}

function DesdeElExtranjero() {
    window.location = "DesdeElExtranjero.aspx";
}

function Noticias() {
    window.location = "Noticias.aspx";
}

var Controls = new Array();
Controls[0] = "ProyectosRealizados";
Controls[1] = "ProyectosEnVenta";
    
function VisualizarContenidoDeProyecto(divName, visible) {
    var ControlToHide = false;
    for(index = 0; index < Controls.length; index++) {
        // Valida si se trata del control que se desea colapsar/ocultar..
        if(Controls[index] == divName) {
            var Obj = document.getElementById(divName);
            Obj.style.display = (Obj.style.display != "" ? "" : "none");
            
            // Deshabilita los controles restantes...
            for(index2 = 0; index2 < Controls.length; index2++) {
                if(index2 != index) {
                    document.getElementById(Controls[index2]).style.display = "none";
                }
            }
            
            break;
        }
    }
}

function ColapsarTodasLasPestanas() {
    for(index = 0; index < Controls.length; index++) {
        document.getElementById(divName).style.display = "none";
    }
}
//----------------------------------------------------------------------------------
// URL Navigation (Common to all pages)
//----------------------------------------------------------------------------------