function login_submit()
{
	if(document.login_form.username.value=="")
	{
		alert("Please, fill the Username field.");
		document.login_form.username.focus();
		return false;
	}
	if(document.login_form.password.value=="")
	{
		alert("Please, fill the Password field.");
		document.login_form.password.focus();
		return false;
	}
	document.login_form.submit();
}

function load_states(country_id)
{
	var req;
	if( window.XMLHttpRequest )
	{
		req = new window.XMLHttpRequest();
	} else if( window.ActiveXObject ) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if( country_id ) {
		req.open("GET", "get_states.php?country_id="+country_id, false);
		req.send(null);
		
		content = req.responseText;
		states = content.split("\n");
		cmbStates = document.getElementById("estado");
		fill_combo( cmbStates, states );
	}
}

function fill_combo( combo, array )
{
	while( combo.options.length > 0 ) {
		combo.removeChild(combo.options[0]);
	}
	
	opt = document.createElement("option");
	opt.value="";
	opt.innerHTML="Select a State";
	combo.appendChild(opt);
	for( i = 0; i < array.length; i++ ) {
		values = array[i].split("=");
		opt = document.createElement("option");
		opt.value=values[0];
		opt.innerHTML=values[1];
		combo.appendChild(opt);
	}
}

function p_submit()
{
	if(document.contact_form.email.value=="")
	{
		alert("Please, fill the E-mail field.");
		document.contact_form.email.focus();
		return;
	}
	var ls_email=document.contact_form.email.value;
	if(ls_email.search("@")<0)
	{
		alert("Error: Invalid E-mail!");
		document.contact_form.email.focus();
		return;
	}
	if(document.contact_form.comments.value=="")
	{
		alert("Please, fill the Comments field.");
		document.contact_form.comments.focus();
		return;
	}
	document.contact_form.submit();
}
function recovery_submit()
{
	if(document.recovery_form.email.value=="")
	{
		alert("Please, fill the Email field.");
		document.recovery_form.email.focus();
		return;
	}
	var ls_email=document.recovery_form.email.value;
	if(ls_email.search("@")<0)
	{
		alert("Error: Invalid E-mail!");
		document.recovery_form.email.focus();
		return;
	}
	document.recovery_form.submit();
}
function getRandomNum(lbound, ubound) {
	return (Math.floor(Math.random() * (ubound - lbound)) + lbound);
}
function getRandomChar() {
	var numberChars = '0123456789';
	var lowerChars = 'abcdefghijklmnopqrstuvwxyz';
	var charSet;
	charSet += numberChars;
	charSet += lowerChars;
	return charSet.charAt(getRandomNum(0, charSet.length));
}
function getPassword() {
	var rc = "";
	rc = rc + getRandomChar();
	for (var idx = 1; idx < 8; ++idx) {
		rc = rc + getRandomChar();
	}
	return rc;
}
function update_rating( ) {
	frmRating = document.getElementById('rating_form');
	frmRating.submit();
}