function validateContinue()
{
	trimFields();
	//Shipping Address Validation
	if(obj.s_first_name.value == "")
	{
		alert("Please enter your First Name in Shipping Information.");
		obj.s_first_name.focus();
		return;
	}
	if(obj.s_last_name.value == "")
	{
		alert("Please enter your Last Name in Shipping Information.");
		obj.s_last_name.focus();
		return;
	}
	if(obj.s_address.value == "")
	{
		alert("Please enter the Address in Shipping Information.");
		obj.s_address.focus();
		return;
	}
	if(obj.s_city.value == "")
	{
		alert("Please enter the City in Shipping Information.");
		obj.s_city.focus();
		return;
	}
	if(obj.s_state.selectedIndex == 0 || obj.s_state.selectedIndex == 52)
	{
		alert("Please select a US or Canada State in Shipping Information.");
		obj.s_state.focus();
		return;
	}
	if(obj.s_zip.value == "")
	{
		alert("Please enter the Zip in Shipping Information.");
		obj.s_zip.focus();
		return;
	}
	if(obj.s_phone.value == "")
	{
		alert("Please enter the Phone Number in Shipping Information.");
		obj.s_phone.focus();
		return;
	}
	if(obj.s_email.value == "")
	{
		alert("Please enter the Email in Shipping Information.");
		obj.s_email.focus();
		return;
	}
	if(!chkEmail(obj.s_email.value))
	{
		alert("Please enter a valid Email Address in Shipping Information.");
		obj.s_email.focus();
		obj.s_email.select();
		return;
	}

	//Billing Address Validation
	if(obj.b_first_name.value == "")
	{
		alert("Please enter your First Name in Billing Information.");
		obj.b_first_name.focus();
		return;
	}
	if(obj.b_last_name.value == "")
	{
		alert("Please enter your Last Name in Billing Information.");
		obj.b_last_name.focus();
		return;
	}
	if(obj.b_address.value == "")
	{
		alert("Please enter the Address in Billing Information.");
		obj.b_address.focus();
		return;
	}
	if(obj.b_city.value == "")
	{
		alert("Please enter the City in Billing Information.");
		obj.b_city.focus();
		return;
	}
	if(obj.b_state.selectedIndex == 0 || obj.b_state.selectedIndex == 52)
	{
		alert("Please select a US or Canada State in Billing Information.");
		obj.b_state.focus();
		return;
	}
	if(obj.b_zip.value == "")
	{
		alert("Please enter the Zip in Billing Information.");
		obj.b_zip.focus();
		return;
	}
	if(obj.b_phone.value == "")
	{
		alert("Please enter the Phone Number in Billing Information.");
		obj.b_phone.focus();
		return;
	}
	if(obj.b_email.value == "")
	{
		alert("Please enter the Email in Billing Information.");
		obj.b_email.focus();
		return;
	}
	if(!chkEmail(obj.b_email.value))
	{
		alert("Please enter a valid Email Address in Billing Information.");
		obj.b_email.focus();
		obj.b_email.select();
		return;
	}
	if(obj.email.value != "" && !chkEmail(obj.email.value))
	{
		alert("Please enter a valid Login Email.\nIt can be either your Shipping or Billing email or any other.");
		obj.email.focus();
		obj.email.select();
		return;
	}
	if(obj.email.value != "" && obj.password.value == "")
	{
		alert("Please enter your Login Password.");
		obj.password.focus();
		return;
	}
	if(obj.password.value != "" && obj.email.value == "")
	{
		alert("Please enter your Login Email.\nIt can be either your Shipping or Billing email or any other.");
		obj.email.focus();
		return;
	}
	if(obj.password.value != "" && obj.conf_password.value == "")
	{
		alert("Please re-type the password to confirm.");
		obj.conf_password.focus();
		return;
	}
	if(obj.password.value != "" && obj.conf_password.value != "" && obj.password.value != obj.conf_password.value)
	{
		alert("The Password and re-typed Password do not match!\nPlease enter them again and ensure both are same.");
		obj.conf_password.focus();
		obj.conf_password.select();
		return;
	}
	obj.action = 'checkout.php';
	obj.submit();
}

function fillBillTo(chk)
{
	if(chk.checked)
	{
		//============copy Shipping Address into Billing Address fields============
		obj.b_first_name.value = obj.s_first_name.value;
		obj.b_last_name.value = obj.s_last_name.value;
		obj.b_company_name.value = obj.s_company_name.value;
		obj.b_address.value = obj.s_address.value;
		obj.b_city.value = obj.s_city.value;
		obj.b_state.selectedIndex = obj.s_state.selectedIndex;
		obj.b_country.selectedIndex = obj.s_country.selectedIndex;
		obj.b_zip.value = obj.s_zip.value;
		obj.b_phone.value = obj.s_phone.value;
		obj.b_fax.value = obj.s_fax.value;
		obj.b_email.value = obj.s_email.value;
	}
	else
	{
		//============erase the fields============
		obj.b_first_name.value = '';
		obj.b_last_name.value = '';
		obj.b_company_name.value = '';
		obj.b_address.value = '';
		obj.b_city.value = '';
		obj.b_state.selectedIndex = 0;
		obj.b_country.selectedIndex = 0;
		obj.b_zip.value = '';
		obj.b_phone.value = '';
		obj.b_fax.value = '';
		obj.b_email.value = '';
	}
}

//Gets customer info - by AJAX call
function getInfo()
{
	if(obj.old_email.value == "")
	{
		alert("Please enter your Email Address.");
		obj.old_email.focus();
		return;
	}
	if(!chkEmail(obj.old_email.value))
	{
		alert("Please enter a valid Email Address.");
		obj.old_email.focus();
		obj.old_email.select();
		return;
	}
	if(obj.old_password.value == "")
	{
		alert("Please enter your Password.");
		obj.old_password.focus();
		return;
	}
	alert("Please wait while we fetch your information from our database.");
	$('#loader_blk')[0].innerHTML = '<img src="img/ajax-loader.gif" alt="Loader" style="vertical-align:middle"> Please wait...';
	var arrParam = new Array();
	arrParam['email'] = obj.old_email.value;
	arrParam['password'] = obj.old_password.value;

	$.ajax({
	   type: "GET",
	   data: "email="+obj.old_email.value+"&password="+obj.old_password.value+'&hash='+parseInt(Math.random() * 10000000000),
	   url: "get_customer_info.php",
	   success: function(retVal){

		    //Shows the effect
			if(retVal == 'FAILURE')
			{
				alert('Sorry we could not retrieve any records of this Email Address and Password.\nPlease check if you have entered the correct values and try again.');
				obj.old_email.focus();
				obj.old_email.select();
			}
			else if(retVal == 'BAD_PASSWORD')
			{
				alert("Invalid password! Please type the correct password.\nNote that the password is case-sensitive.");
				obj.old_password.focus();
				obj.old_password.select();
			}
			else
			{
				var arrTemp = retVal.split("~~");
				var arr_keys = arrTemp[0].split("|");
				var arr_values = arrTemp[1].split("|");
				for(var i = 0; i<arr_keys.length-1; i++)
					eval('obj.'+arr_keys[i]).value = arr_values[i];
				//Re-type password box
				obj.conf_password.value = obj.password.value;
			}
			$('#loader_blk')[0].innerHTML = '<a href="javascript:void(0)" onclick="javascript:getInfo()" value="Retrieve &raquo;" class="btnl">Retrieve &raquo;</a>';
	   }
    });
}
