function clean(obj,t)
{
	if(obj.value == t)
	{
		obj.value = '';	
	}
}

function cleanAndSetPassType()
{
	var cont  = document.getElementById('clave_cont');
	var clave = document.getElementById('clave_log');

	if(clave.value == 'clave')
	{
		cont.innerHTML = '<input type="password" id="clave_log" name="clave_log" value="">';
		
		document.getElementById('clave_log').focus();	
	}	
}


function post(url, vars)
{
	var xml = null;
	try {
		xml = new ActiveXObject('Microsoft.XMLHTTP');
	}catch(exception){
		xml = new XMLHttpRequest();
	}
	xml.open('POST',url,false);
	xml.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xml.send (vars);
	if(xml.status == 404) alert('Url no valida');
	return xml.responseText;
}

function registrar()
{
	var dict             = new Array();
	dict['razon_social'] = 'Razon Social'; 
	dict['cp']           = 'Codigo Postal'; 
	dict['direccion']    = 'Direccion'; 
	dict['numero']       = 'Numeracion de la Direccion'; 
	dict['id_paises']    = 'Pais'; 
	
	var msg = Vivaldi('frm_registrar',dict);
	
	if(msg != '')
	{
		alert(msg);
	}
	else	
	{
		if(!emailExists('email'))
		{
			document.getElementById('frm_registrar').submit();
		}
		else		
		{
			alert("Ya existe un Distribuidor con ese E-Mail");
		}
	}
}

function recuperar_clave()
{
	var msg = Vivaldi('frm_recuperar');
	
	if(msg != '')
	{
		alert(msg);
	}
	else	
	{
		document.getElementById('frm_recuperar').submit();
	}
}

function cambiar_clave()
{
	var msg = Vivaldi('frm_recuperar');
	
	if(msg != '')
	{
		alert(msg);
	}
	else	
	{
		if(document.getElementById('clave').value != document.getElementById('clave2').value)
		{
			alert('Las Claves no son iguales.');
		}
		else
		{
			document.getElementById('frm_recuperar').submit();
		}
	}
}

function emailExists(id)
{
	var email = document.getElementById(id).value;
	
	var r = post("ajax.php","act=ee&e="+email);
	
	return r == 'si' ? true : false;	
}

function popup(URL,w,h,vars) 
{	
    var left = (screen.width - w) / 2;
    var top  = (screen.height - h) / 2
	
	window.open(URL,"","left="+left+",top=" + top + ",width="+w+",scrollbars=yes,height="+h+vars);
}

function getPoblacion(id)
{
	var r = post('ajax.php','act=get_zonas&idp='+id);
	
	document.getElementById('poblacion_sel_cont').innerHTML = '<select name="id_poblaciones" id="id_poblaciones"><option value="">- Seleccionar -</option>'+r+'</select>';
}

function getPoblacionesById(id)
{
	var r = post('ajax.php','act=get_zonas_&idp='+id);
	
	document.getElementById('poblacion_sel_cont').innerHTML = '<select name="id_poblaciones" id="id_poblaciones"><option value="">- Seleccionar -</option>'+r+'</select>';
}

function getProvinciasById(id)
{
	var r = post('ajax.php','act=get_zonas_&idp='+id);
	
	document.getElementById('provincia_sel_cont').innerHTML = '<select name="id_provincias" id="id_provincias" onchange="getPoblacionesById(this.value);"><option value="">- Seleccionar -</option>'+r+'</select>';
}

function cleanIf(obj,x)
{
	if(obj.value == x)
	{
		obj.value = '';
	}	
}

function FastContact(i,w)
{
	var email    = document.getElementById('dist_email').value;
	var nombre   = document.getElementById('dist_nombre').value;
	var apellido = document.getElementById('dist_apellido').value;
	var mensaje  = document.getElementById('dist_mensaje').value;
	var telefono = document.getElementById('dist_telefono').value;
	
	var r = post(w+"ajax.php","act=dist_contact&email="+email+"&nombre="+nombre+"&apellido="+apellido+"&telefono="+telefono+"&mensaje="+mensaje+"&i="+i);

	if(r == 'ok')
	{
		document.getElementById('inst_contact').innerHTML = 'Se ha enviado el contacto correctamente.';
	}
	else	
	{
		alert(r);	
	}
}
	