
//Check price form
function check_price_form()
{	
	if (document.price_form.password.value == "")
	{
		alert("Please fill in your password");
		document.price_form.password.focus();
		return false;
	}
	return true;
}

//Check the product search keyword
function check_product_search_form()
{
	if (document.product_search_form.keyword.value == "")
	{
		alert("Please fill in the keywords for searching");
		document.product_search_form.keyword.focus();
		return false;
	}
	return true;
}

//Check the Forget Password Form
function check_forget_pwd_form()
{
	if (document.forget_pwd_form.login_name.value == "")
	{
		alert("Please enter you login name");
		document.forget_pwd_form.login_name.focus();
		return false;
	}
	return true;
}

//Check signup for individual
function check_user_signup_form()
{	
	if (document.user_signup_form.surname.value == "")
	{
		alert("Please fill in your Firstname");
		document.user_signup_form.surname.focus();
		return false;
	}
	if (document.user_signup_form.givename.value == "")
	{
		alert("Please fill in your Lastname");
		document.user_signup_form.givename.focus();
		return false;
	}
	if (document.user_signup_form.address.value == "")
	{
		alert("Please fill in your address 1");
		document.user_signup_form.address.focus();
		return false;
	}
	if (document.user_signup_form.suburb.value == "")
	{
		alert("Please fill in your Suburb");
		document.user_signup_form.suburb.focus();
		return false;
	}
	if (document.user_signup_form.postcode.value == "")
	{
		alert("Please fill in your Postcode");
		document.user_signup_form.postcode.focus();
		return false;
	}
	if (document.user_signup_form.telareacode.value == "")
	{
		alert("Please fill in your Tel area code.");
		document.user_signup_form.telareacode.focus();
		return false;
	} else {
		usetela = "user_signup_form.telareacode"
		if (!validate_phone(usetela))
		{
			return false;
		}
	}
	if (document.user_signup_form.tel.value == "")
	{
		alert("Please fill in your tel no.");
		document.user_signup_form.tel.focus();
		return false;
	} else {
		user_name = "user_signup_form.tel"
		if (!validate_phone(user_name))
		{
			return false;
		}
	}
	if (document.user_signup_form.email.value == "")
	{
		alert("Please fill in your email");
		document.user_signup_form.email.focus();
		return false;
	} else {
		e_name = "user_signup_form.email"
		if (!validate_email(e_name))
		{
			return false;
		}
	}
	if (!isDate (document.user_signup_form.year.value, document.user_signup_form.month.value, document.user_signup_form.day.value))
	{
		alert("Please fill in a vaild Date");
		document.user_signup_form.day.focus();
		return false;
	}
	return true;
}

//Check signup for company
function check_company_signup_form()
{
	if (document.company_signup_form.company_name.value == "")
	{
		alert("Please fill in the company name");
		document.company_signup_form.company_name.focus();
		return false;
	}
	if (document.company_signup_form.company_abn.value == "")
	{
		alert("Please fill in the company ABN");
		document.company_signup_form.company_abn.focus();
		return false;
	}
	if (document.company_signup_form.company_acn.value == "")
	{
		alert("Please fill in the company ACN");
		document.company_signup_form.company_acn.focus();
		return false;
	}	
	if (document.company_signup_form.address.value == "")
	{
		alert("Please fill in the company address");
		document.company_signup_form.address.focus();
		return false;
	}
	if (document.company_signup_form.suburb.value == "")
	{
		alert("Please fill in the suburb");
		document.company_signup_form.address.focus();
		return false;
	}
	if (document.company_signup_form.postcode.value == "")
	{
		alert("Please fill in the postcode");
		document.company_signup_form.address.focus();
		return false;
	}
	if (document.company_signup_form.telareacode.value == "")
	{
		alert("Please fill in the company tel area code");
		document.company_signup_form.telareacode.focus();
		return false;
	} else {
		tela = "company_signup_form.telareacode"
		if (!validate_phone(tela))
		{
			return false;
		}
	}	
	if (document.company_signup_form.tel.value == "")
	{
		alert("Please fill in the company Tel");
		document.company_signup_form.tel.focus();
		return false;
	} else {
		tel_name = "company_signup_form.tel"
		if (!validate_phone(tel_name))
		{
			return false;
		}
	}
	if (document.company_signup_form.faxareacode.value == "")
	{
		alert("Please fill in the company Fax area code");
		document.company_signup_form.faxareacode.focus();
		return false;
	} else {
		ctela = "company_signup_form.faxareacode"
		if (!validate_phone(ctela))
		{
			return false;
		}
	}
	if (document.company_signup_form.fax.value == "")
	{
		alert("Please fill in the company fax");
		document.company_signup_form.fax.focus();
		return false;
	} else {
		ff_name = "company_signup_form.fax"
		if (!validate_phone(ff_name))
		{
			return false;
		}
	}
	if (document.company_signup_form.surname.value == "")
	{
		alert("Please fill in the contact person Firstname");
		document.company_signup_form.surname.focus();
		return false;
	}
	if (document.company_signup_form.givename.value == "")
	{
		alert("Please fill in the contact person Lastname");
		document.company_signup_form.givename.focus();
		return false;
	}
	if (document.company_signup_form.email.value == "")
	{
		alert("Please fill in the contact person email");
		document.company_signup_form.email.focus();
		return false;
	} else {
		ee_name = "company_signup_form.email"
		if (!validate_email(ee_name))
		{
			return false;
		}
	}	
}

// validate email
function validate_email(name)
{
	email = eval("document." + name);
	emailOK = "false";
	for (var j=0; j<email.value.length; j++) {
	var tChar = email.value.charAt(j);

	if(tChar == "@")
	{
		for (var count=j; count<email.value.length; count++)
		{
			var thenext = email.value.charAt(count);
			if (thenext == ".") 
				{emailOK = "true";}
		}
	}}
	if (emailOK == "false")
	{
		alert("Invalid email format");
		email.focus();
		return false;
	}
	return true;
}

// validate phone no
function validate_phone(phone_name)
{
	PhoneOK = "true";
	var digits = 0;
	var phone = eval("document." + phone_name);

	for (var i=0; i < phone.value.length; i++)
	{
		var theChar = phone.value.charAt(i);
		if ((theChar >="0") && (theChar <="9")){
			digits++;
			continue;
		}

		if(theChar == " ") continue;
		if(theChar == "_") continue;
		if(theChar == "(") continue;
		if(theChar == ")") continue;
		PhoneOK = "false";
	}
	if (PhoneOK == "false")
	{
		alert("Invalid phone format");
		phone.value = "";
		phone.focus();
		return false;
	}
	return true;
}

function check_mydetails_form()
{
	if (document.edit_member_form.password.value != "")
	{
		if (document.edit_member_form.confirm_password.value == "")
		{
			alert("Please confirm the password");
			document.edit_member_form.confirm_password.focus();
			return false;
		}
		if (document.edit_member_form.password.value != document.edit_member_form.confirm_password.value)
		{
			alert("Password and Confirmed Password not matched");
			document.edit_member_form.confirm_password.focus();
			return false;
		}
	}
	
	return true;	
}