// JavaScript Document
var HTTP_WEB_ROOT = "http://www.cerrajeros-bcn.com/";


/* -------------------- FUNCIONES COMUNES ---------------------- */


function recorta_caracter( campo, cantidad ) {
	var limite = cantidad;
	if(document.getElementById(campo).value.length > limite) {
	  document.getElementById(campo).value = document.getElementById(campo).value.substring(0,limite);
	}
}

function limit_caracter( evt, campo, cantidad ) {
	var charCode = ( evt.which ) ? evt.which : event.keyCode;
	var limite = cantidad;
    if( document.getElementById(campo).value.length > limite && charCode > 8  ) {
	  return false;
	}
	else {
		return true;
	}
}


//Ejecuta una funcion al apretar la tecla enter
function ejecuta_enter( evt, funcion ) {
    var charCode = ( evt.which ) ? evt.which : evt.keyCode
    if ( charCode == 13 ) {
    	funcion();
	} 
}

//Envia el formulario cuando clickamos la tecla enter
function envia_form_enter( evt, formulario ) {
    var charCode = ( evt.which ) ? evt.which : evt.keyCode
    if ( charCode == 13 ) {
    	document.getElementById(formulario).submit();
	} 
}

function envia_form( formulario ) {
   	document.getElementById(formulario).submit();
}

function solo_precio( evt ) {
    var charCode = ( evt.which ) ? evt.which : event.keyCode
    if ( charCode > 31 && charCode != 46 && ( charCode < 48 || charCode > 57 )  ) {
    	return false;
	} 
	else {
    	return true;
	}
}

function solo_num( evt ) {
    var charCode = ( evt.which ) ? evt.which : event.keyCode
    if ( ( charCode < 48 || charCode > 57 ) && charCode != 8 ) {
    	return false;
	} 
	else {
    	return true;
	}
}


function prepara_envio( formulario ) {
	var cadena = "";
	var num_elementos = document.getElementById(formulario).length;
	for( var i=0; i<num_elementos; i++ ) {

		if( document.getElementById(formulario).elements[i].type != "checkbox" && document.getElementById(formulario).elements[i].type != "radio"  ) {
			cadena += i>0 ? "&" : "";
			cadena += document.getElementById(formulario).elements[i].name + "=" + document.getElementById(formulario).elements[i].value;
		}
		else {
			if ( document.getElementById(formulario).elements[i].checked == true ) {
				cadena += i>0 ? "&" : "";
				cadena += document.getElementById(formulario).elements[i].name + "=" + document.getElementById(formulario).elements[i].value;
			}
		}
	}
	return cadena;
}

/* ------------------- AVISO LEGAL ------------------------ */

function carga_div(nombre) {
	ddrivetip('<div id=\''+nombre+'\'></div>');
}

var con_aviso_legal = new XHConn();
var fin_aviso_legal = function (oXML) { document.getElementById('aviso_legal').innerHTML = oXML.responseText; };
function aviso_legal() {
	con_aviso_legal.connect(HTTP_WEB_ROOT + '_dinamic/aviso_legal.php', 'POST', '', fin_aviso_legal);
}