//client
/*alert box*/
var ALERT_TITLE = "Oops!";
var ALERT_BUTTON_TEXT = "Ok";
if(document.getElementById) {
	window.alert = function(txt) {
		createCustomAlert(txt);
	}
}



function createCustomAlert(txt) 
{
	d = document;
  if(d.getElementById("modalContainer")) return;
	mObj = d.getElementsByTagName("body")[0].appendChild(d.createElement("div"));
	mObj.id = "modalContainer";
	mObj.style.height = d.documentElement.scrollHeight + "px";

	
	alertObj = mObj.appendChild(d.createElement("div"));
	alertObj.id = "alertBox";
	if(d.all && !window.opera) alertObj.style.top = document.documentElement.scrollTop + "px";
	alertObj.style.left = (d.documentElement.scrollWidth - alertObj.offsetWidth)/2 + "px";
	alertObj.style.visiblity="visible";

	h1 = alertObj.appendChild(d.createElement("h1"));
	h1.appendChild(d.createTextNode(ALERT_TITLE));

	msg = alertObj.appendChild(d.createElement("p"));
	msg.appendChild(d.createTextNode(txt));

	btn = alertObj.appendChild(d.createElement("a"));
	btn.id = "closeBtn";
	btn.appendChild(d.createTextNode(ALERT_BUTTON_TEXT));
	btn.href = "#";
	btn.focus();
	btn.onclick = function() { removeCustomAlert();return false; }

	alertObj.style.display = "block";
}



function removeCustomAlert() {

	document.getElementsByTagName("body")[0].removeChild(document.getElementById("modalContainer"));

}

/*end of alert box*/





/*VALIDATES USER REGISTRATION AND USER SETTINGS*/

function validateRegistrationForm()

{

	var frm=document.frmRegistration;	
	
	/* the minumum age you want to allow in */
			var min_age = 21;

			/* change "age_form" to whatever your form has for a name="..." */
			var year = parseInt(document.forms["frmRegistration"]["bYear"].value);
			var month = parseInt(document.forms["frmRegistration"]["bMonth"].value) - 1;
			var day = parseInt(document.forms["frmRegistration"]["bDay"].value);

			var theirDate = new Date((year + min_age), month, day);
			var today = new Date;

			if ( (today.getTime() - theirDate.getTime()) < 0) {
				alert("You are too young to enter this site!");
				return false;
			}

	if(frm.txtFName.value=="")

	{

		alert("Please Enter Your First Name");

		frm.txtFName.focus();

		return false;

	}	
	if(frm.txtCity.value=="")

	{

		alert("Please Enter Your City");

		frm.txtCity.focus();

		return false;

	}	
	if(frm.txtZip.value=="")

	{

		alert("Please Enter Your Zip Code");

		frm.txtZip.focus();

		return false;

	}	
	
		if(frm.txtState.value=="")

	{

		alert("Please Select Your State");

		frm.txtState.focus();

		return false;

	}
	if(frm.txtLName.value=="")

	{

		alert("Please Enter Your Last Name");

		frm.txtLName.focus();

		return false;

	

	}

	if(frm.txtEmail.value=="")

	{

		alert("Please Enter Your Email Address");

		frm.txtEmail.focus();

		return false;

	}	

	if(!checkEmail(frm))

	{

		frm.txtEmail.focus();

		return false;

	}

	if(frm.txtAddress1.value=="")

	{

		alert("Please Enter Your Address");

		frm.txtAddress1.focus();

		return false;

	}

	if(frm.txtUserName.value=="")

	{

		alert("Please Confirm Your Email Address");

		frm.txtUserName.focus();

		return false;

	}	

	if(frm.txtEmail.value!=frm.txtUserName.value)

	{

		alert("Your Email Addresses Do Not Match");

		frm.txtUserName.focus();

		return false;

	}

	if(frm.bMonth.value==0)

	{

		alert("Please select Your Birth Month");

		return false;

	}

	if(frm.txtPassword.value=="")

	{

		alert("Password Cannot be Empty");

		frm.txtLName.focus();

		return false;

	}

	if(frm.txtPassword.value!=frm.txtConfirmPassword.value)

	{

		alert("Your Passwords Do not match");

		frm.txtLName.focus();

		return false;

	}

	if(count(frm.txtPassword.value)<5)

	{

		alert("Your Password Should Have A Minimum  of 5 Characters.");

		frm.txtPassword.focus();

		return false;

	}

	if(frm.bYear.value=="")

	{

		alert("Please Select Your Correct Birth Year");

		return false;

	}

	if(frm.bDay.value=="")

	{

		alert("Please Select Your Correct Day Of Birth");

		return false;

	}

	if(frm.bYear.value >d.getFullYear())

	{

		alert("Year Of Birth Is Invalid");

		return false;

	}

	if(frm.bDay.value >32)

	{

		alert("Date Of Birth Is Invalid");

		return false;

	}

		

	if(frm.bMonth.value==2 && frm.bYear.value %4!=0 && frm.bDay.value >28)

	{

		alert("Invalid Date");

	}

	if(frm.bMonth.value==2 && frm.bYear.value %4==0 && frm.bDay.value >29)

	{

		alert("Invalid Date");

		return false;

	}



	return true;	



}



//VALIDATES USER LOGIN

function validatelogin()

{

	frm=document.frmLogin;

	if(frm.txtusername.value=="")

	{

		alert("username cannot be null");

		frm.txtusername.focus();

		return false;

	}

	if(frm.txtpassword.value=="")

	{

		alert("Password cannot be null");

		frm.txtpassword.focus();

		return false;

	}

	return true;

}

//VALIDATES FORGOT PASSWORD SECTION

function validatepass()

{

	frm=document.frmLogin;

	if(frm.txtpassword.value=="")

	{

		alert("Password cannot be null");

		frm.txtpassword.focus();

		return false;

	}

	return true;

}



//VALIDATES EMAIL

function checkEmail(myForm)

{

	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.txtEmail.value))

	{

		return true;

	}

	else

	{

		alert("Invalid E-mail Address! Please re-enter.");

		return false;

	}

}



function AddLiquorBasket(bottle,liquorbrandid){

	if(isNaN(bottle.value)){

		alert("Please, enter numeric value.");

		return false;

	}else{

	document.location='customer.php?option=com_customer&task=preorder_liquor&action=addliquorbasket&bottle='+bottle.value+'&liquorbrandid='+liquorbrandid;

	}

}

