function validarEdad(limit) 
{
	var day = $F('Day');
	var month = $F('Month');
	var year =  $F('Year');
	var correct = false;
	var older = false;
	
	$('div_fecha_invalida').hide();
	
	if (day && month && year) {
		switch (month) {
			case "1": case "3":	case "5": case "7":	case "8": case "10": case "12": correct = true; break; 
			case "4": case "6": case "9": case "11": if (day <= 30) correct = true; break;
			case "2": 
				if ((year % 4 == 0) && (day == 29)) correct = true;
				if (day <= 28) correct = true; 
				break;
		}	
		var inputDate = new Date();
		inputDate.setSeconds(0);
		inputDate.setMinutes(0);
		inputDate.setHours(0);
		inputDate.setFullYear(year,(month-1),day);		
		limit += 3601; // js fix
		older = (Math.round(inputDate.getTime()/1000.0) <= Number(limit));
	}	
	if (correct) {
		if (!older) {
			$('div_form').hide();
			$('div_atencion').show();
		} else {
			window.location.href = PATH+"home-"+LANG;
		}
	} else {
		$('div_fecha_invalida').show();
	}	
}


var img_index = 0;
function imgAnterior()
{
	img_index = (img_index > 0) ? (img_index - 1) :  imagenes_producto.length - 1;
	cargaImgen();
}
function imgSiguiente()
{
	img_index = (img_index == imagenes_producto.length - 1) ? 0 : (img_index + 1);
	cargaImgen();
}

function cargaImgen()
{
	$('img_producto').title = imagenes_producto[img_index][1];
	$('img_producto').alt = imagenes_producto[img_index][1];
	
	var img_url = PATH+"img/large/"+imagenes_producto[img_index][0];
	var img_src = PATH+"_include/thumb.php?name="+img_url+"&w=243&h=297";
	
	if (!document.all) {
		new Effect.Fade('div_imagen', { // the id of the <DIV> containing the photos 
			duration: 1, 
			fps: 50, 
			afterFinish: function() { 
				$('img_producto').src = img_src;
				new Ajax.Updater('img_producto',img_src, { // URL for next <IMG> tag 
					asynchronous: true, 
					onSuccess: function() { 
						new Effect.Appear('div_imagen', {
							duration: 1,
							fps: 50,
							queue:'end'
						})
					} 
				}) 
			} 
		});
	} else {
		$('img_producto').src = img_src;
	}
}

function aover(img)
{
	var value = img.id.split("i_")[1];
	var folder = img.src.split("/").slice();
	folder = folder.slice(0,folder.length-1).join("/");
	img.src = folder+"/"+value+".jpg";
}
function aout(img)
{
	var value = img.id.split("i_")[1];
	var folder = img.src.split("/").slice();
	folder = folder.slice(0,folder.length-1).join("/");
	img.src = folder+"/"+value+"_off.jpg";
}

function lineaCompleta(id)
{
	scrollTo(0,0);
	$('div_lineacompleta').show();
	$('img_lineacompleta').src = PATH+"img/productos/"+id+".jpg";
	$('div_lineacompleta_inside').show();
}

function cerrarLineaCompleta()
{
	$('div_lineacompleta_inside').hide();
	$('div_lineacompleta').hide();
}


function formCheck() 
{
	if ($F('nombre') == "") {
		$('div_msg').update(MSG_nombre);
		$('nombre').focus();
	} else 
	if ($F('apellido') == "") {
		$('div_msg').update(MSG_apellido);
		$('apellido').focus();
	} else 
	if ($F('empresa') == "") {
		$('div_msg').update(MSG_empresa);
		$('empresa').focus();
	} else 
	if ($F('telefono') == "") {
		$('div_msg').update(MSG_telefono);
		$('telefono').focus();
	} else 
	if ($F('email') == "") {
		$('div_msg').update(MSG_email);
		$('email').focus();
	} else 
	if ($F('pais') == "") {
		$('div_msg').update(MSG_pais);
		$('pais').focus();
	} else {
		formSend();
	}
}



function formSend() 
{
	if (!document.sending) {
		var AJAX = new sack(PATH+"/_include/ajax/form_post.php");
		AJAX.setVar("nombre", urlencode($F('nombre')));
		AJAX.setVar("apellido", urlencode($F('apellido')));
		AJAX.setVar("empresa", urlencode($F('empresa')));
		AJAX.setVar("telefono", urlencode($F('telefono')));
		AJAX.setVar("email", urlencode($F('email')));
		AJAX.setVar("pais", urlencode($F('pais')));
		AJAX.setVar("mensaje", urlencode($F('mensaje')));
		AJAX.setVar("id_marca", $F('id_marca'));
		AJAX.setVar("contacto", $F('contacto'));
		AJAX.setVar("nombre_marca", urlencode($F('nombre_marca')));

		AJAX.onCompletion = function() {
			if (AJAX.response == 1) {
				$('div_msg').update(MSG_OK);
			} else {
				$('div_msg').update(MSG_ERROR);
				window.location.href = "mailto:info@montepaz.com.uy?subject=Contacto desde sitio web";
			}
			document.sending = false;
		}
		$('div_msg').update(MSG_SENDING);
		document.sending = true;
		AJAX.runAJAX();
	} else {
		$('div_msg').update(MSG_SENDING_WAIT);
	}
}

function urlencode(str) {
    var result = "";
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == " ") result += "+";
        else result += str.charAt(i);
    }
    return escape(result);
}


function urldecode(str) {    
    var result = str.replace(/\+/g, " ");
    return unescape(result);
}
