var pedaso = top.location.href.split('?')
var ide = pedaso[1];
var sel_error = function(valor){
    if (valor > 0) {
        document.getElementById("btn__reporte_error").disabled = false
    }
}

var guardar_error = function(){
    var valor = document.getElementById("lista_errores").value;
    document.getElementById("btn__reporte_error").disabled = true
    var callback = {
        success: function(o){
            //listaDatos = YAHOO.lang.JSON.parse(o.responseText);
        },
        failure: function(){
        }
    };
    var sUrl = "WebServices/guardar_error.php";
    var params = ide + "&op=" + valor;
    var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, params);
    alert("Gracias.")
}
var mandar_sms = function(tipo){
    if (tipo == 1) {
        titulo = "SMS";
        total = "160";
    }
    else {
        titulo = "EMAIL";
        total = "260";
    }
    var handleSubmit = function(){
        var nombre = document.getElementById("txtSmsNombre").value;
        var correo = document.getElementById("txtSmsCorreo").value;
        var telefono = document.getElementById("txtSmsTelefono").value;
        var mensaje = document.getElementById('txtSmsTexto').value
        var op = 0;
        var opciones;
        var errores = "";
        if (!nombre) {
            errores = errores + " Nombre ";
        }
        if (!correo) {
            errores = errores + " Correo ";
        }
        if (!telefono) {
            errores = errores + " Telefono ";
        }
        if (!mensaje) {
            errores = errores + " Mensaje ";
        }
        if (errores) {
            document.getElementById("smsErrores").innerHTML = "<div align='center' style='font-size:8px;'>" + errores + "</div>";
        }
        else {
            document.getElementById("smsErrores").innerHTML = "<div>..ENVIANDO..</div>"
            var callback = {
                success: function(o){
                    var respuesta_sms = YAHOO.lang.JSON.parse(o.responseText);
                    alert("Mensaje enviado, gracias.")
                    /*if (enviarMensaje.repetido == "SI") {
                        alert("Solamente se le puede enviar un SMS")
                    }
                    else {
                        if (enviarMensaje.status == "exito") {
                            alert("Mensaje enviado con exito!");
                        }
                        else {
                            alert("ERROR al enviar el mensaje, favor de intentar mas tarde, gracias");
                        }
                    }*/
                },
                failure: function(){

                }
            };
            var sUrl = "WebServices/anuncio_contacto.php";
			var params = ide + "&nombre=" + nombre + "&correo=" + correo + "&telefono=" + telefono + "&mensaje=" + mensaje + "&tipo=" + tipo;
			var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, params);
            panel_sms.hide();
            panel_sms.destroy();
        }
    };
    var handleCancel = function(){
        panel_sms.hide();
        panel_sms.destroy();
    };
    panel_sms = new YAHOO.widget.Dialog("panel_sms ", {
        width: "250px",
        visible: true,
        constraintoviewport: true,
        fixedcenter: true,
        modal: true,
        buttons: [{
            text: "Enviar",
            handler: handleSubmit,
            isDefault: true
        }, {
            text: "Cancel",
            handler: handleCancel
        }]
    });
    panel_sms.setHeader('Enviar ' + titulo + ' ... EN MANTENIMIENTO');
    panel_sms.setBody("<div>&nbsp;</div><div>Tu Nombre:</div><div><input type='text' id='txtSmsNombre' onchange='contar()' onkeyup='contar()' onkeypress='contar()'/></div><div>Tu Correo:</div><div><input type='text' id='txtSmsCorreo' onchange='contar()' onkeyup='contar()' onkeypress='contar()'/></div><div>Tu Telefono:</div><div><input type='text' id='txtSmsTelefono' onchange='contar()' onkeyup='contar()' onkeypress='contar()'/></div><div>Tu Mensaje:</div><div><textarea name='msn' id='txtSmsTexto' cols='25' rows='4' onchange='contar()' onkeyup='contar()' onkeypress='contar()'></textarea></div><div>Caracteres restantes:<input type='text' size='3' id='carac' disabled='disabled' value='" + total + "'/></div><div id='smsErrores' style='color:red;'></div><div>&nbsp;</div><input type='hidden' value='" + total + "' id='totalMaximo'/>");
    panel_sms.setFooter('Gracias...');
    panel_sms.render(document.body);
}
var contar = function(){
    Nom = document.getElementById('txtSmsNombre').value
    Correo = document.getElementById('txtSmsCorreo').value
    Telefono = document.getElementById('txtSmsTelefono').value
    Obs = document.getElementById('txtSmsTexto').value
    total = document.getElementById("totalMaximo").value
    queda = total - Nom.length - Correo.length - Telefono.length - Obs.length
    document.getElementById('carac').value = queda
}
var guardar_favoritos = function(ide){
	var callback = {
            success: function(o){
                var respuesta = YAHOO.lang.JSON.parse(o.responseText);
                if (respuesta.status=="NO"){
                    alert('Error...');
                }else{
                    alert('Añadido a Favoritos Satisfactoriamente');
                }
            },
            failure: function(){
            }
        };
        var sUrl = "WebServices/guardar_favorito.php";
        var params = 'ide='+ide;
        var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, params);

        /*if (listaSesion[0].sesion == "SI") {
		//alert("con sesion")
		guardarFavoritos = CallBack.ajaxCallBack("WebServices/guardar_favorito.php?ide="+ide["ide"]);
		if(guardarFavoritos.status=="NO"){
			alert("Vehiculo previamente agregado a favoritos...")
		}
	}else{
		verLogin();
		//alert("sin sesion")
	}*/
}
var  ver_imprmir = function(ide){
    window.open("imprimir.php?ide="+ide , "ventana1" , "width=610,height=700,scrollbars=NO")
}
