//<script language="javascript">
	//document.onmousedown=noRightClick;
    //Función de fechas para futuras
    function fnAbrirFechaFuturo(url, strFecha){
		var Fecha = document.getElementById(strFecha);
		intTop = Fecha.offsetTop  + Fecha.offsetHeight;
		FechaSeleccionada = Fecha.value;
		strParametros="dialogWidth:185px;dialogHeight:230px;status:0;scroll:0;dialogTop:"+ intTop + ";dialogLeft:500"
		var cSearchValue=showModalDialog(url,FechaSeleccionada,strParametros);
		if (cSearchValue == -1 || cSearchValue == null){}
		else{
    		 var dtmFechaAhora = new Date();
    		 var dtmFechaAhora1 = new Date( dtmFechaAhora.getFullYear(), dtmFechaAhora.getMonth(), dtmFechaAhora.getDate() );
    		 var dtmFechaSel = new Date(cSearchValue);
             if( dtmFechaSel < dtmFechaAhora1 ){
	   		    alert("Debe Seleccionar un fecha futura");
                return;
	    	 }
	        Fecha.value=cSearchValue;
		}
	}
	
	//Función para maximizar la pantalla actual
	function fnMaximizar(){
	    window.moveTo(0,0);
        window.resizeTo(screen.availWidth,screen.availHeight);
        window.focus();
	}
	
	//Función que sirve para hayar el historial de las llamadas por el cliente
	function fnHistorialLlamadas(Op){
		document.all.frm_Historia.src="CONT_Historial.aspx?idCliente="+document.getElementById("txtIdCliente").value+"&idInmueble="+document.getElementById("txtidInmueble").value+"&Opcion="+Op+"&Dummy="+Date();
	}
	
	//Función que calcula la cantidad de caracteres faltantes por ingresar en un textarea
	function fnCantidadCaracteres(Objeto, MaxCaracteres, Label){
		var strPalabra;
		MaxCaracteres = parseInt(MaxCaracteres);		
		strPalabra = Objeto.value;
		if (strPalabra.length > MaxCaracteres){
		    alert('Ha sobrepasado el limite de caracteres permitidos, por favor verifique la informacion');
			strPalabra = strPalabra.substring(0,MaxCaracteres);
			Objeto.value = strPalabra;
		}
		var intCantidad = parseInt(strPalabra.length);
		intCantidad = MaxCaracteres - intCantidad;
		//document.all.item(Label).innerText = intCantidad;
		document.getElementById(Label).innerText = intCantidad + " / " + MaxCaracteres; 
	}

    //Funcion para abrir ventanas si se pasa para pantalla completa pasar alto = 0 y ancho = 0
    function fnAbreVentana(URL, alto, ancho){
        if (alto == 0){
            alto = screen.availHeight * .92;
        }
        if (ancho == 0){
            ancho = screen.availWidth * .98;
        }
        var top = (screen.availHeight * .92 - alto) / 2;
        var left = (screen.availWidth - ancho) / 2;
        window.open(URL,"","height=" + alto + ",width=" + ancho + ",status=yes,toolbar=no,resizable=yes,scrollbars=yes,menubar=no,location=no, top=" + top + ", left=" + left)
    }

    //Funcion para abrir ventanas si se pasa para pantalla completa pasar alto = 0 y ancho = 0
    function fnAbreVentanaNombre(URL, alto, ancho, Nombre){
        if (alto == 0){
            alto = screen.availHeight * .92;
        }
        if (ancho == 0){
            ancho = screen.availWidth * .98;
        }
        var top = (screen.availHeight * .92 - alto) / 2;
        var left = (screen.availWidth - ancho) / 2;
        window.open(URL,Nombre,"height=" + alto + ",width=" + ancho + ",status=yes,toolbar=no,resizable=yes,scrollbars=yes,menubar=no,location=no, top=" + top + ", left=" + left)
    }

    
    function fnAbreVentanaModal(URL, alto, ancho){
        var RTA;
        var strParametros;
        if (alto == 0){
            alto = screen.availHeight * .92;
        }
        if (ancho == 0){
            ancho = screen.availWidth * .98;
        }
        strParametros = "dialogHeight:" + alto + " px;dialogWidth:" + ancho + " px;status:Yes;resizable:Yes;center:Yes";
        //alert(strParametros);
        RTA = showModalDialog(URL,"",strParametros);
        return RTA;
    }

	String.prototype.trim = function() {
	 // skip leading and trailing whitespace
	 // and return everything in between
	  return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
	}
	function fnTeleclienteXMLHTTP(strURL){
		//alert(strURL);
		var oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
		oXMLHTTP.open("POST", strURL, false);
		oXMLHTTP.send();
		//alert(oXMLHTTP.responseText);
		//alert(oXMLHTTP.responseBody);
		//return 1;
		return oXMLHTTP.responseText;
		//return oXMLHTTP.responseBody; 
	}
	function fnXMLHTTP(strUrl) {
	    var peticion_http;	
        //Obtener la instancia del objeto XMLHttpRequest
        if(window.XMLHttpRequest) {
		    peticion_http = new XMLHttpRequest();
	    }else if(window.ActiveXObject) {
	        peticion_http = new ActiveXObject("Microsoft.XMLHTTP");
	    }	
	    //Preparar la funcion de respuesta
	    peticion_http.onreadystatechange = fnRTA;
	    //Realizar peticion HTTP
	    peticion_http.open("GET", strUrl, true);
	    peticion_http.send(null);
	    //Función de RTA XMLHTTP (AJAX)
	    function fnRTA() {
            if(peticion_http.readyState == 4) {
                if(peticion_http.status == 200) {
                  return peticion_http.responseText;
                }
            }
        }
    }
	function fnAbrirFecha(url, strFecha){
		//alert(strFecha);
		var Fecha = document.all.item(strFecha);

		FechaSeleccionada = Fecha.value;
		strParametros="dialogWidth:185px;dialogHeight:265px;status:0;scroll:0";
		var cSearchValue=showModalDialog(url,FechaSeleccionada,strParametros);
			
		if (cSearchValue == -1 || cSearchValue == null)
		      {
		   //alert('Canceló o cerró la ventana');	
		}
		else if (cSearchValue=="")
		      {
		   alert('No ingreso ninguna fecha');
		}
		else
		{
		   //alert('Fecha: ' + cSearchValue);
		         Fecha.value=cSearchValue;
		}
	}
	//Función para validar si hacen clic con el botón derecho del mouse
	function noRightClick(){
		if (event.button==2){
			alert('Boton derecho deshabilitado.')
		}
	}
	//Función para verificar si presionaron la tecla enter
	function disableEnterKey(){ 
     	if (window.event.keyCode == 13) window.event.keyCode = 0; 
	}
	
	//Funciones Cliente (Milton)
	
	//Función para permitir entrar solo valores numéricos en un cuadro
	//de texto
	//Forma de utilizarlo:
	//	onkeypress=javascript:fnVldarNmros(); onblur=javascript:this.value=this.value.toUpperCase();
	function fnVldarNmros(){
		if (event.keyCode > 45 && event.keyCode < 58){
			event.returnValue = true;
		} 
		else{
			event.returnValue = false;
		}
	}
	//TRIM
	String.prototype.trim = function(){
		return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
	}
	//REPLACE
	function replace(strOrig, strFrom, strTo) {
		var strNew;
		var i;
		var iFromLen;
		strNew = "";
		iFromLen = strFrom.length;
		i = strOrig.indexOf(strFrom)
		j = 0;
		while (i>=0) {
			strNew = strNew + strOrig.substring(j, i) + strTo;
			j = i + iFromLen
			i = strOrig.indexOf(strFrom, j)
		}
		i = strOrig.length;
		strNew = strNew + strOrig.substring(j, i);
		return strNew;
	}
	//Función para validar que un correo electrónico este bien escrito
	function fnValidarEmail(strCorreo){
		/*if(strCorreo.trim() == ""){
			alert("La cuenta de correo no puede estar en blanco.");
			return false;
		}*/
		//Validar la cuenta de correo usando una expresión regular (RegExp)
		if(strCorreo.search(/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/ig)){
			return false;
		}
		return true;
	}
	//Función que permite seleccionar el valor de un combo
	function fnSeleccionaValorCombo(objCombo,strValor){
	    var intI;
	    for (intI=0; intI <= parseInt(objCombo.length) -1; intI++){
	        if (objCombo.options[intI].value == strValor){
	            objCombo.selectedIndex = intI;
	        }
	    }
	}
	
	//FUNCIONES DE ORDENAMIENTO DE VECTORES
	Array.prototype.swap=function(a, b){
	    var tmp=this[a];
	    this[a]=this[b];
	    this[b]=tmp;
    }

    function partition(array, begin, end, pivot){
	    var piv=array[pivot];
	    array.swap(pivot, end-1);
	    var store=begin;
	    var ix;
	    for(ix=begin; ix<end-1; ++ix) {
		    if(array[ix]<=piv) {
			    array.swap(store, ix);
			    ++store;
		    }
	    }
	    array.swap(end-1, store);
	    return store;
    }

    function qsort(array, begin, end){
	    if(end-1>begin) {
		    var pivot=begin+Math.floor(Math.random()*(end-begin));
		    pivot=partition(array, begin, end, pivot);
		    qsort(array, begin, pivot);
		    qsort(array, pivot+1, end);
	    }
    }

    function quick_sort(array){
	    qsort(array, 0, array.length);
    }

    function dosort(form){
	    var array=form.unsorted.value.split(/ +/);
	    quick_sort(array);
	    form.sorted.value=array.join(' ');
    }

/**************************************************************
 Mid: Returns a String containing a specified number of 
      characters from a string

 Parameters:
      String = String expression from which characters are 
               returned. If string contains null, false is 
               returned.
      Start  = Number. Character position in string at which 
               the part to be taken begins. If Start is 
               greater than the number of characters in 
               string, Mid returns a zero-length string ("").
      Length = Number of characters to return. If omitted 
               false is returned. 

 Returns: String
***************************************************************/

function Mid(String, Start, Length){
    if (String == null)
	    return (false);

    if (Start > String.length)
	    return '';

    if (Length == null || Length.length == 0)
	    return (false);

    return String.substr((Start - 1), Length);
} 

/**************************************************************
 FormatNumber: Returns an expression formatted as a number.

 Parameters:
      Expression            = Expression to be formatted.
      NumDigitsAfterDecimal = Numeric value indicating how
                              many places to the right of the
                              decimal are displayed.

 Returns: String
***************************************************************/
function FormatNumber(Expression, NumDigitsAfterDecimal)
{
	var iNumDecimals = NumDigitsAfterDecimal;
	var dbInVal = Expression;
	var bNegative = false;
	var iInVal = 0;
	var strInVal
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals)
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (bNegative)
	{
		return "-" + strWhole + "." + strDec;
	}
	else
	{
		return strWhole + "." + strDec;
	}
}

function fnValidaNumeros(){
	if (event.keyCode > 47 && event.keyCode < 58){
		event.returnValue = true;
	} 
	else{
		event.returnValue = false;
	}
}

/**************************************************************
 MinutesDiff: Returns the number of minutes between two dates.

 Parameters:
    - Date1: First date
    - Date2: Second data

 Returns: Number
***************************************************************/
function MinutesDiff(Date1, Date2)
{
	date1 = new Date();
	date2 = new Date();
	diff  = new Date();

	date1temp = new Date(Date1);
	date1.setTime(date1temp.getTime());

	date2temp = new Date(Date2);
	date2.setTime(date2temp.getTime());

	diff.setTime(date1.getTime() - date2.getTime());
	timediff = diff.getTime();

	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

	days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
	timediff -= days * (1000 * 60 * 60 * 24);

	hours = Math.floor(timediff / (1000 * 60 * 60)); 
	timediff -= hours * (1000 * 60 * 60);

	mins = Math.floor(timediff / (1000 * 60)); 
	timediff -= mins * (1000 * 60);

	secs = Math.floor(timediff / 1000); 
	timediff -= secs * 1000;

	return (mins + (hours * 60) + (days * 24 * 60) + (weeks * 7 * 24 * 60))
}


//</script>
