/////// GLOBALES /////////////////////////////////////////////////////////////////
var lang = 'esp';
/////// Moneda ///////
var curId, curName, curSimb, curCot, cotDate = '';
/////// Funcion auxiliar ///////
function getElem( id ) {
return document.getElementById( id );
}
////////////////////////////////////////////////////////////////////////////////////////
$().ready( function() {
Calendar.setup( {
inputField : "idTxtFecha",
ifFormat : "%d/%m/%Y",
button : "idImgCalendario"
} );
Calendar.setup( {
inputField : "idTxtFechaPub",
ifFormat : "%d/%m/%Y",
button : "idImgCalendarioPub"
} );
jQuery.validator.addMethod( "precio", function(value) {
return /^[0-9]{1,9},?[0-9]{0,2}$/.test(value);
},"");//{'.$words['monto_precio'].'}'; ?>" );
jQuery.validator.addMethod( "foto", function(value) {
return /^.*\.(jpg|jpeg|gif)$/.test(value);
},"Imagen");
jQuery.validator.addMethod( "titulo", function(value) {
return /^[a-zA-Z0-9_\-\.\+\$,áéíóúÁÉÍÓÚñÑ¡!¿\?\s]*$/.test(value);
},"");
jQuery.validator.addMethod( "v_email", function(value) {
return /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(value);
},"");
jQuery.validator.addMethod( "video", function(value) {
return /^.*(youtube|metacafe|dailymotion)\..*$/.test(value);
},"");
jQuery.validator.addMethod( "fecha", function(value) {
var a = m = d = 1;
if ( value.substring(6,10) < 2010 ) return false;
else if ( value.substring(6,10) > 2010 ) return true;
else {
if ( value.substring(3,5) < 3 ) return false;
else if ( value.substring(3,5) > 3 ) return true;
else {
if ( value.substring(0,2) <= 11 ) return false;
else return true;
}
}
}, "");
jQuery.validator.addMethod( "fecha_final", function(value){
var a = m = d = 1;
var fecha_pub;
var txt_fecha_pub = getElem('idTxtFechaPub');
fecha_pub = txt_fecha_pub.value;
if ( value.substring(6,10) < fecha_pub.substring(6,10) ) return false;
else if ( value.substring(6,10) > fecha_pub.substring(6,10) ) return true;
else {
if ( value.substring(3,5) < fecha_pub.substring(3,5) ) return false;
else if ( value.substring(3,5) > fecha_pub.substring(3,5) ) return true;
else {
if ( value.substring(0,2) <= fecha_pub.substring(0,2) ) return false;
else return true;
}
}
}, "");
$("#idFormAnuncio").validate( {
rules: {
"data[Anuncio][titulo]": {
required: true,
minlength: 3,
maxlength: 300,
titulo: true
},
"data[Anuncio][descripcion]": {
required: true,
minlength: 50,
maxlength: 2000
},
"data[Anuncio][localidad]": {
minlength: 3,
maxlength: 30
},
"data[Anuncio][monto]": {
required: true,
precio: true
},
"data[Anuncio][forma_pago]": {
required: true
},
"foto1[]": {
required: true,
foto: true
},
"foto2[]": {
foto: true
},
"foto3[]": {
foto: true
},
"foto4[]": {
foto: true
},
"foto5[]": {
foto: true
},
"foto6[]": {
foto: true
},
"data[Anuncio][video]": {
video: true
},
"data[Anuncio][link]": {
required: true,
url: true,
minlength: 5
},
"data[Anuncio][email]": {
required: true,
v_email: true,
minlength: 5,
maxlength: 255
},
"data[Anuncio][telefono]": {
minlength: 5,
number: true
},
"data[Anuncio][txt_fecha]": {
required: true,
fecha_final: true
},
"data[Anuncio][txt_fecha_pub]": {
required: true,
fecha: true
},
"hncaptcha_private_key": {
required: true,
minlength: 5
}
},
messages: {
"data[Anuncio][titulo]": {
required: "",//",
minlength: "",//",
maxlength: "",//",
titulo: ""
},
"data[Anuncio][descripcion]": {
required: "
",//",
minlength: "
",//",
maxlength: "
"//"
},
"data[Anuncio][localidad]": {
minlength: "
",//",
maxlength: "
"//"
},
"data[Anuncio][monto]": {
required: ""//"
},
"data[Anuncio][forma_pago]": {
required: ""//"
},
"foto1[]": {
required: "",
foto: ""
},
"foto2[]": {
foto: ""
},
"foto3[]": {
foto: ""
},
"foto4[]": {
foto: ""
},
"foto5[]": {
foto: ""
},
"foto6[]": {
foto: ""
},
"data[Anuncio][video]": {
video: ""//"
},
"data[Anuncio][link]": {
required: "",//",
url: "",//",
minlength: ""//"
},
"data[Anuncio][email]": {
required: "",//",
v_email: "",//",
minlength: "",//",
maxlength: ""//"
},
"data[Anuncio][telefono]": {
number: "",
minlength: ""//"
},
"data[Anuncio][txt_fecha]": {
required: ""//"
},
"data[Anuncio][txt_fecha_pub]": {
required: ""//"
},
"hncaptcha_private_key": {
required: "
",
minlength: "
"
}
}
} );
} );
////////////////////////////////////////////////////////////////////////////////////////
function doMoreAfterAjax( doMore, response ) {
switch( doMore ) {
case 'getProvs' :
window.setTimeout("showPriceInDollars()", 20);
break;
case 'getCurrency' :
var currencyData = splitResponseData( response );
curId = currencyData[0];
curName = currencyData[1];
curSimb = currencyData[2];
curCot = currencyData[3];
cotDate = currencyData[4];
var elem = document.getElementById('idSpanCurSimb');
if ( elem ) elem.innerHTML = curSimb;
break;
}
}
////////////////////////////////////////////////////////////////////////////////////////
function enableCity( idProv ) {
if ( idProv != 0 ) {
getElem('idLabelLoc').style.display = '';
getElem('idTxtLoc').disabled = false;
getElem('idTxtLoc').focus();
} else {
getElem('idLabelLoc').style.display = 'none';
getElem('idTxtLoc').disabled = true;
}
}
////////////////////////////////////////////////////////////////////////////////////////
/*function payOptions( idRadio ) {
var div_precio = getElem('idDivPrecio');
var input_txt = getElem('idTxtMonto');
var input_formas = getElem('idTxtFormaDePago');
if ( idRadio == 0 ) {
if ( div_precio.style.display == 'none' ) {
div_precio.style.display = 'block';
input_txt.disabled = false;
input_formas.disabled = false;
input_txt.value=data['Anuncio']['precio_local'])?$this->data['Anuncio']['precio_local']:'';?>;
}
input_txt.focus();
} else {
if ( div_precio.style.display == 'block' ) {
input_txt.disabled = true;
input_formas.disabled = true;
div_precio.style.display = 'none';
}
}
}*/
////////////////////////////////////////////////////////////////////////////////////////
function showPriceInDollars() {
var inDol = '';
var numero = 0;
var t = getElem('idTxtMonto');
if ( curId != 1 ) { // curId = 1 -> dolar
var v = t.value;
if ( /^[0-9]{1,9},?[0-9]{0,2}$/.test( v ) ) {
var cadena = String( v );
var numero = Math.round( ( parseFloat( cadena.split(",").join(".") ) / curCot ) * 100 ) / 100;
cadena = String( numero );
numero = cadena.split(".").join(",");
inDol = 'U$S ' + numero + ' (aprox.)';//)';
}
}
getElem('idSpanInDollars').innerHTML = inDol;
getElem('idHiddenPrecioDolares').value = numero;
}
////////////////////////////////////////////////////////////////////////////////////////
function addImage() {
for ( var i = 1; i <= 6; i++ ) {
if ( i == 6 ) {
getElem('idAAddImg').style.display = 'none';
}
var etiq = getElem('idLabelImg'+i);
if ( etiq.style.display == 'none' ) {
etiq.style.display = 'block';
getElem('idImg'+i).disabled = false;
break;
}
}
}
////////////////////////////////////////////////////////////////////////////////////////
function showFotos( valor ) {
var div = getElem('idDivFotos');
if ( valor == 1 ) {
div.style.display = 'block';
} else {
div.style.display = 'none';
}
var cant_vis = 0;
for ( var i = 1; i <= 6; i++ ) {
var etiq = getElem('idLabelImg'+i);
var imag = getElem("idImg"+i);
if ( valor == 1 ) {
if ( etiq.style.display == 'block' ) {
imag.disabled = false;
cant_vis++;
}
} else {
imag.disabled = true;
}
}
if ( valor == 1 && cant_vis == 0 ) {
addImage();
}
}
////////////////////////////////////////////////////////////////////////////////////////
function deleteImage( v ) {
getElem('idImg'+v).disabled = true;
getElem('idLabelImg'+v).style.display = 'none';
getElem('idAAddImg').style.display = 'block';
var cant_vis = 0;
for ( var i = 1; i <= 6; i++ ) {
if ( getElem('idLabelImg'+i).style.display == 'block' ) {
cant_vis++;
}
}
if ( cant_vis == 0 ) {
getElem("radioFotosNo").checked = true;
showFotos( 0 );
}
}
////////////////////////////////////////////////////////////////////////////////////////
function showVideo( valor ) {
var dv = getElem("idDivVideos");
var lab = getElem("idLabelVideo");
var txt = getElem("idVideo");
if ( valor == 1 ) {
dv.style.display = 'block';
lab.style.display = 'block';
txt.disabled = false;
txt.style.display = 'block';
} else {
dv.style.display = 'none';
lab.style.display = 'none';
txt.disabled = true;
txt.style.display = 'none';
}
}
////////////////////////////////////////////////////////////////////////////////////////
function muestraLink( f, idDiv, idTxt ) {
var div = getElem(idDiv);
var txt = getElem(idTxt);
if ( f == 1 ) {
div.style.display = 'block';
txt.disabled = false;
if (idTxt == 'idTxtLink'){
txt.value='http://';
} else{
txt.value='';
txt.focus();
}
} else {
if (idTxt='idTxtFechaPub'){
txt.value='11/03/2010';
}
div.style.display = 'none';
txt.disabled = true;
}
}
////////////////////////////////////////////////////////////////////////////////////////
function muestraFecha( f ) {
var div = getElem('idDivFecha');
var txt = getElem('idTxtFecha');
if ( f == 1 ) {
div.style.display = 'block';
txt.disabled = false;
txt.focus();
} else {
txt.disabled = true;
div.style.display = 'none';
}
}
////////////////////////////////////////////////////////////////////////////////////////
MM_preloadImages("/img/default/alerta_email_btn_hover.gif","/img/default/ajax-loader.gif");