function enviaLogin(){
	user = document.getElementById('user').value;
	pwd = document.getElementById('pwd').value;
	if((user=="")||(pwd =="")) $('#campos_obligatorios').fadeIn("slow");
	else document.getElementById('formlogin').submit();
	
}
function loading(capa){
	document.getElementById(capa).innerHTML = '<img class="loadimg" src="imgs/rotate.gif" alt="loading &hellip;" />';
}
function oculta_mensajes(){
	$('#msg').fadeOut('slow');
	$('#campos_obligatorios').fadeOut('slow');
	
}
function enviaBrandsite(){
		oculta_mensajes();
		nombre 		= document.getElementById("nombre").value;
		apellidos 		= document.getElementById("apellidos").value;
		empresa 		= document.getElementById("empresa").value;
		localidad 	= document.getElementById("localidad").value;
		direccion 	= document.getElementById("direccion").value;
		pais 			= document.getElementById("pais").value;		
		provincia 	= document.getElementById("provincia").value;
		cp 	= document.getElementById("cp").value;
		telefono 	= document.getElementById("telefono").value;
		fax 	= document.getElementById("fax").value;
		email 	= document.getElementById("email").value;
		comentario 	= document.getElementById("comentario").value;
		leido = document.getElementById("leido").checked;
		
		var nombre		=		nombre.htmlEntities();
		var apellidos	=		apellidos.htmlEntities();
		var empresa	=		empresa.htmlEntities();
		var localidad	=		localidad.htmlEntities();
		var direccion	=		direccion.htmlEntities();
		var pais	=		pais.htmlEntities();
		var provincia	=		provincia.htmlEntities();
		var cp			=		cp.htmlEntities();
		var telefono	=		telefono.htmlEntities();
		var fax	=		fax.htmlEntities();
		var email	=		email.htmlEntities();		
		var comentario	=		comentario.htmlEntities();
		mail_valido = isValidEmail(email);
		if((nombre!="")&&(apellidos!="")&&(localidad!="")&&(direccion!="")&&(pais!="")&&(provincia!="")&&(cp!="")&&(telefono!="")&&(email!="")&&(leido)&&(mail_valido)){
			
			loading('msg');
			$.ajax({
			   type: "POST",
			   url: "secciones/brandsite/inserta_usuarios.php",
			   data: "ajax=1&OP_1=submit"+
			   "&nombre="+nombre+
			   "&apellidos="+apellidos+
			   "&empresa="+empresa+
			   "&localidad="+localidad+
			   "&direccion="+direccion+
			   "&pais="+pais+
			   "&provincia="+provincia+
			   "&cp="+cp+
			   "&telefono="+telefono+
			   "&fax="+fax+
			   "&email="+email+
			   "&comentario="+comentario,
			   
			   success: function(msg){
					alert(msg); 
					tmp = msg.split("__");
					alert(tmp);
					alert(tmp);
					switch(tmp[0]){
						case "error1":
							document.getElementById("msg").innerHTML = tmp[1];
						break;
						default:
							document.getElementById("msg").innerHTML = tmp[0];
							document.getElementById("formbrandsite").reset();
						break;
					} 
					$('#msg').fadeIn("slow");
			   	//cargaDadesCapa(msg,'container_general');
			   }
			 });
		}else{
			$('#campos_obligatorios').fadeIn("slow");
		}
		
		

}

function isValidEmail(str) {
   return (str.indexOf(".") >= 1) && (str.indexOf("@") > 0);
}

//	prototipo htmlentity en javascript
String.prototype.htmlEntities = function () {
   return this.replace(/&/g,'_AMP_').replace('>','_GRAN_').replace('<','_PETIT_').replace(/[+]/g,'_PLUS_').replace(/#/g,'_ALMO_');
};