function Join()
{
	location.href = "join_form0.php";
	// alert("Temporary unavailable.\nIt will be available soon.");
}

function Join_agree()
{
	location.href = "join_form.php";
}
function Join_disagree()
{
	alert("You have to agree this terms & conditions to join this site!");
}

function join_Submit1()
{
	if( ValidateUserid())
		if( join_ValidateFields1())
			frmMain.submit();
}

function join_ValidateFields1()
{
	bRetVal = false;

	if( ValidateLength('userid','User id',3) )
		if( ValidateLength('passwd','Password',3) )
			if( ValidateLength('confirm','Confirm password',3) )
				if( ValidateLength('fname','First Name',2) )
					if( ValidateLength('lname','Last Name',2) )
						if( ValidateLength('phone3','Area code', 2) )
							if( ValidateLength('phone','Telephone', 8) )
								if( ValidateLength('address','Address',5) )
									if( ValidateLength('suburb','Suburb',3) )
										if( ValidateLength('post','Post code',3) )
											bRetVal = true;
										else
											frmMain.post.focus();
									else
										frmMain.suburb.focus();
								else
									frmMain.address.focus();
							else
								frmMain.phone.focus();
						else
							frmMain.phone3.focus();
					else
						frmMain.lname.focus();
				else
					frmMain.fname.focus();
			else
				frmMain.confirm.focus();
		else
			frmMain.passwd.focus();
	else
		frmMain.userid.focus();

	if( bRetVal ) {
		pw = frmMain.passwd.value;
		pw2 = frmMain.confirm.value;

		if( pw != pw2 ) {
			bRetVal = false;
			alert("Password and confirm password does not match!");
			frmMain.passwd.value = "";
			frmMain.confirm.value = "";
			frmMain.passwd.focus();
		}
	}
	return bRetVal;
}

function Login()
{
	id = frmLogin.userid.value;
	pw = frmLogin.passwd.value;
	if( id.length > 2 ) {
		if( pw.length >2 ) {
			frmLogin.action = "code_login.php";
			frmLogin.submit();
		} else {
			alert("Password must be longer than 3 characters!");
			frmLogin.passwd.focus();
		}
	}else {
		alert("User id must be longer than 3 characters!");
		frmLogin.userid.focus();
	}    
}

function big_picture()
{
	var pic2_display = document.getElementById("pic2").style.display;
	if( pic2_display == "none" ) document.getElementById("pic2").style.display = "inline";
	else document.getElementById("pic2").style.display = "none";
}

function InitPass()
{
	pw = frmLogin.passwd.value;
	pw_cn = frmLogin.confirm.value;
	if( pw.length > 3 ) {
		if( pw_cn.length >3 ) {
			if( pw == pw_cn ) {
				if( pw != "1111" ) {
					frmLogin.action = "code_initpass.php";
					frmLogin.submit();
				}
				else {
					alert("New password must not be same as old one!");
					frmLogin.passwd.value = "";
					frmLogin.confirm.value = "";
					frmLogin.passwd.focus();
				}
			}else {
				alert("New password and confirm password must be same!");
				frmLogin.confirm.value = "";
				frmLogin.confirm.focus();
			}
		} else {
			alert("Confirm password must be longer than 3 characters!");
			frmLogin.confirm.focus();
		}
	}else {
		alert("Password must be longer than 3 characters!");
		frmLogin.passwd.focus();
	}    
}

function Logout()
{
	location.href="logout.php";
}

function addCart()
{
	alert("Customer order is not available at the moment.\nSorry for inconvenience.");
	/*
	result = confirm("Are you sure to add this item to your cart?");
	if( result )
		frmMain.submit();
	*/
}

function addCart_shop()
{
	alert("Customer order is not available at the moment.\nSorry for inconvenience.");
	/*
	result = confirm("Are you sure to add this item to your cart?");
	if( result )
		frmMain.submit();
	*/
}

function checkoutCart()
{
	result = confirm("Are you sure to check out?");
	if( result )
		frmMain.submit();
}

function backtoCart()
{
	location.href = "cart_view.php";
}

function backtoPromoCart()
{
	location.href = "promo_cart_view.php";
}

function confirmCart()
{
	result = confirm("Are you sure?");
	if( result )
		frmMain.submit();
}

function updateCart( form )
{
	form.action = "cart_update.php";
	form.submit();
}

function deleteCart( form )
{
	result = confirm("Are you sure to delete this item from cart?");
	if( result ) {
		form.action = "cart_delete.php";
		form.submit();
	}
}

function selectPayType()
{
	var pay_type = getSelectedValue(frmMain.pay_type);
	if( pay_type == "ac" ) {
		card_detail.style.display = "none";
		acc_password.style.display = "inline";
	}
	if( pay_type == "cc" ) {
		acc_password.style.display = "none";
		card_detail.style.display = "inline";
	}
	if( pay_type == "" ) {
		acc_password.style.display = "none";
		card_detail.style.display = "none";
	}
}

function Available()
{
    w_name = "new_customer"
	result = ValidateUserid();
	if( result ) {
	    userid = frmMain.i_userid.value;
		url = "available_id.php?userid="+userid;
	    Width = 500;
		Height = 400;
	    window_string = "toolbar=no,menubar=no,resizable=no,scrollbars=no, width=" + Width + ",height=" + Height;
		if( ValidateLength('i_userid','User id',2) )
			window.open(url,w_name,window_string);
		else
			frmMain.i_userid.focus();
	}
}


function Search()
{
	alert("Under contruction!");
}

function focus_Login()
{
	frmLogin.userid.focus();
}

function MiniCalendar(field)
{
    w_name = "calendar"
    url = "/mini_cal.php?field=" + field;
    Width = 240;
    Height = 150;
    Top = 170;
    Left = 380;
    window_string = "toolbar=no,menubar=no,resizable=no,scrollbarow=no, width=" + Width + ",height=" + Height + ",top=" + Top + ",left=" + Left;
    window.open(url,w_name,window_string);
}

function uncheckField(field)
{
	frmMain.elements(field).checked = false;
}

function resetPasswd()
{
	result = confirm("Distributor's password is going to reset to '1111'.\rDo you want to proceed?");
	if( result ) {
		frmMain.action = "user_reset.php";
		frmMain.submit();
	}
}

function shop_search()
{
	post = frmShopSearch.postcode.value;
	if( post.length > 3 ) {
		w_name = "post_search";
		url = "shop_search.php?postcode="+post;
	    Width = 350;
		Height = 250;
	    window_string = "toolbar=no,menubar=no,resizable=no,scrollbars=yes, width=" + Width + ",height=" + Height;
		window.open(url,w_name,window_string);
		// frmShopSearch.submit();
	} else {
		alert("Please input available post code first!");
		frmShopSearch.postcode.focus();
	}
}

function OrderProcess()
{
	bRetVal = false;
	var recv_choise = getSelectedValue(frmMain.recv_choise);
	if( recv_choise.length > 0 ) {
		if( ValidateLength('order_name','Your Name',2) )
			if( ValidateLength('customer_order_no','Customer Order No.',3) )
				if( ValidateLength('recv_name','Receiver Name',2) )
					if( ValidateLength('recv_address','Address',10) )
						if( ValidateLength('recv_suburb','Suburb',3) )
							if( ValidateLength('recv_state','State',2) )
								if( ValidateLength('recv_post','Post code',4) )
									bRetVal = true;
								else
									frmMain.recv_post.focus();
							else
								frmMain.recv_state.focus();
						else
							frmMain.recv_suburb.focus();
					else
						frmMain.recv_address.focus();
				else
					frmMain.recv_name.focus();
			else
				frmMain.customer_order_no.focus();
		else
			frmMain.order_name.focus();
	} else {
		alert("Choose delivery address");
	}

	if( bRetVal ) {
		frmMain.submit();
	}		
}

function CustomerOrderProcess()
{
	bRetVal = false;
	
	if( payment_status ) {
		alert("Please wait");
	}else {
	
		if( ValidateLength('recv_name','Receiver Name',2) ) {
			if( ValidateLength('cc_holder','Card Holder name',5) )
				if( ValidateLength('ccnum','Credit Card No.',10) )
					if( ValidateLength('cc_exp1','Card Expire Month',2) )
						if( ValidateLength('cc_exp2','Card Expire Year',2) )
							bRetVal = true;
						else
							frmMain.cc_exp2.focus();
					else
						frmMain.cc_exp1.focus();
				else
					frmMain.ccnum.focus();
			else
				frmMain.cc_holder.focus();
		} else
			frmMain.recv_name.focus();
	
		if( bRetVal ) {
			payment_status = true;
			frmMain.submit();
		}
	}
}

function inputAddress()
{
	bRetVal = false;
	if( ValidateLength('recv_phone','Phone No.',8) )
		if( ValidateLength('recv_address','Address',10) )
			if( ValidateLength('recv_suburb','Suburb',3) )
				if( ValidateLength('recv_post','Post code',4) )
					frmMain.submit();
				else
					frmMain.recv_post.focus();
			else
				frmMain.recv_suburb.focus();
		else
			frmMain.recv_address.focus();
	else
		frmMain.recv_phone.focus();
}

function deleteDelivery( seqno )
{
	result = confirm("Do you want to delete this address?");
	if( result ) {
		frmMain.seqno.value = seqno;
		frmMain.action = "addr_delete.php";
		frmMain.submit();
	}
}

function updateDelivery()
{
	if( ValidateFields_delivery()) {
		frmMain.action = "addr_update.php";
		frmMain.submit();
	}
}

function updateDeliveryForm( seqno )
{
	frmMain.seqno.value = seqno;
	frmMain.action = "addr_update_form.php";
	frmMain.submit();
}

function updateDefaultDelivery()
{
	frmMain.action = "addr_update_default.php";
	frmMain.submit();
}

function receiveDelivery(form)
{
	result = confirm("Did you receive this order?");
	if( result )
		form.submit();
}

function minOrder()
{
	alert("Your order amount is under minimum order amount.\rPlease add more items.");
}

function updatePromoCart( form )
{
	form.action = "promo_cart_update.php";
	form.submit();
}

function deletePromoCart( form )
{
	result = confirm("Are you sure to delete this item from cart?");
	if( result ) {
		form.action = "promo_cart_delete.php";
		form.submit();
	}
}

function printForm(seqno)
{
	w_name = "_blank";
	url = "order_print.php?seqno="+seqno;
	Width = 780;
	Height = 800;
	window_string = "toolbar=no,menubar=no,resizable=no,scrollbars=yes, width=" + Width + ",height=" + Height;
	window.open(url,w_name,window_string);
}

function inputEnq()
{
	var enq_type = getSelectedValue(frmMain.enq_type);
	if( enq_type.length > 0 ) {
		if( ValidateLength('fullname','Full name',2) )
			if( ValidateLength('email','Email',5) )
				frmMain.submit();
			else
				frmMain.email.focus();
		else
			frmMain.fullname.focus();
	}else {
		alert("Please choose type of enquery");
	}
}

function inputReturn()
{
	var enq_type = getCheckedValue(frmMain.enq_type);
	var repl_parts = getCheckedValue(frmMain.repl_parts);
	if( enq_type.length > 0 ) {
		if( ValidateLength('fullname','Full name',2) )
			if( ValidateLength('email','Email',5) )
				if( ValidateLength('product_code','Product Code',5) )
					if( repl_parts.length > 0 )
						frmMain.submit();
					else
						alert("Please choose parts");
				else
					frmMain.product_code.focus();
			else
				frmMain.email.focus();
		else
			frmMain.fullname.focus();
	}else {
		alert("Please choose type of return");
	}
}

function loginFirst()
{
	alert("Please login first");
}

function writeForumForm()
{
	location.href="forum_write_form.php";
}

function writeForum()
{
	if( ValidateLength('subject','Subject',5) )
		if( ValidateLength('content','Detail',10) )
			frmMain.submit();
		else
			frmMain.content.focus();
	else
		frmMain.subject.focus();
}

function replyForum()
{
	if( ValidateLength('comment','Comment',5) ) {
		frmMain.action = "forum_reply.php";
		frmMain.submit();
	}else
		frmMain.comment.focus();
}

function delReply(ref_no)
{
	result = confirm("Are you sure to delete this reply?");
	if( result ) {
		frmMain.ref_no.value = ref_no;
		frmMain.action = "forum_reply_del.php";
		frmMain.submit();
	}
}
function delForum()
{
	result = confirm("Are you sure to delete this post?");
	if( result ) {
		frmMain.action = "forum_delete.php";
		frmMain.submit();
	}
}

function cart_address_change()
{
	frmSub.action = "cust_cart_addr_change.php";
	frmSub.submit();
}

function cart_address_update()
{
	location.href = "addr_list.php";
}

function searchProd()
{
	p_detail = frmProdSearch.p_detail.value;
	if( p_detail.length > 0 ) {
		frmProdSearch.action = "prod_search.php";
		frmProdSearch.submit();
	}else {
		alert("Please type in product detail!");
		frmProdSearch.p_detail.focus();
	}
}