/***********************************************
Developed By : อลงกรณ์ คงดีได้ (Accords)
Date : 19/12/2550
***********************************************/

// ฟังก์ชั่น ตรวจสอบข้อมูล ฟอร์ม  password
function checkPasswords()
{
	with (document.login) {
	var alertMsg1 = "Insert";

	if(passwd_old.value.length <= 0){alertMsg1 += " รหัสผ่าน  pls.";passwd_old.focus();}
	else if(frm_bug.value.length <= 0){alertMsg1 += " รหัสผ่านใหม่ pls.";frm_bug.focus();}
	else if(frm_bug_re.value.length <= 0){alertMsg1 += " รหัสใหม่ อีกครั้ง pls.";frm_bug_re.focus();}
	else if(frm_bug_re.value!=frm_bug.value){alertMsg1 += " รหัส ให้ตรงกัน pls.";frm_bug_re.value="";frm_bug_re.focus();}

	if (alertMsg1 != "Insert") {alert(alertMsg1);return false;}
	else{return true;} 
	}
}

function checkLogin()
{
	with (document.login) {
	var alertMsg1 = "Insert";

	if(user.value.length <= 3){alertMsg1 += " username";user.focus();}
	else if(passwd.value.length <= 3){alertMsg1 += " password ";passwd.focus();}

	if (alertMsg1 != "Insert") {alert(alertMsg1);return false;}
	else{return true;} 
	}
}

function checkBulletin()
{
	with (document.bul_post) {
	var alertMsg1 = "Insert";

	if(title.value.length <= 5){alertMsg1 += " Bulletin Title";title.focus();}

	if (alertMsg1 != "Insert") {alert(alertMsg1);return false;}
	else{return true;} 
	}
}

function checkDist()
{
	Email = /^[a-z0-9_.-]+([_\\.-][a-z0-9]+)*@([a-z0-9_\.-]+([\.][a-z]{2,4}))+$/i;

	with (document.frm) {
	var alertMsg1 = "Insert";

	if(username.value.length <= 4){alertMsg1 += " Username";username.focus();}
	else if(passwords.value.length <= 4){alertMsg1 += " Password";passwords.focus();}

	else if(firstname.value.length <= 1){alertMsg1 += " Firstname";firstname.focus();}
	else if(lastname.value.length <= 1){alertMsg1 += " Lastname";lastname.focus();}
	else if(address.value.length <= 1){alertMsg1 += " Address";address.focus();}
	else if(phone1.value.length <= 3){alertMsg1 += " Telephone";phone1.focus();}
	else if (email.value.search( Email ) == -1){alertMsg1 += " Email";email.value = "";email.focus();}

	if (alertMsg1 != "Insert") {alert(alertMsg1);return false;}
	else{return true;} 
	}
}

function checkDist2()
{
	Email = /^[a-z0-9_.-]+([_\\.-][a-z0-9]+)*@([a-z0-9_\.-]+([\.][a-z]{2,4}))+$/i;

	with (document.frm2) {
	var alertMsg1 = "Insert";

	if(passwords.value.length <= 3){alertMsg1 += " Password";passwords.focus();}

	else if(firstname.value.length <= 1){alertMsg1 += " Firstname";firstname.focus();}
	else if(lastname.value.length <= 1){alertMsg1 += " Lastname";lastname.focus();}
	else if(address.value.length <= 1){alertMsg1 += " Address";address.focus();}
	else if(phone1.value.length <= 3){alertMsg1 += " Telephone";phone1.focus();}
	else if (email.value.search( Email ) == -1){alertMsg1 += " Email";email.value = ""; email.focus();}

	if (alertMsg1 != "Insert") {alert(alertMsg1);return false;}
	else{return true;} 
	}
}

function checkSearch()
{
	with (document.frm) {
	var alertMsg1 = "Insert";

	if(shtext.value.length <= 0){alertMsg1 += " Text for Search";shtext.focus();}

	if (alertMsg1 != "Insert") {alert(alertMsg1);return false;}
	else{return true;} 
	}
}

function chkRegMem()
{
	Number = /^[0-9() \-\+]{4,}$/i;
    UserID = /[& @ () <>]/g;
	Email = /^[a-z0-9_.-]+([_\\.-][a-z0-9]+)*@([a-z0-9_\.-]+([\.][a-z]{2,4}))+$/i;

	with (document.frm_regis) {
	var alertMsg1 = "";

	var currentTime = new Date();
	var year = currentTime.getFullYear();

	if(firstname.value.length <= 1){alertMsg1 += "Please enter your first name";firstname.focus();}
	else if(lastname.value.length <= 1){alertMsg1 += "Please enter your last name";lastname.focus();}
	else if(street.value.length <= 1){alertMsg1 += "Please enter your Street address";street.focus();}
	else if(suburb.value.length <= 1){alertMsg1 += "Please enter your Suburb";suburb.focus();}
	else if(city.value.length <= 1){alertMsg1 += "Please enter your City";city.focus();}
	else if(state.value.length <= 1){alertMsg1 += "Please enter your State / Province";state.focus();}
	else if(zipcode.value.length <= 1){alertMsg1 += "Please enter your Postal / ZIP code";zipcode.focus();}
	else if(country.value == ""){alertMsg1 += "Please select your Country";country.focus();}

	else if(phone1.value.length < 1){alertMsg1 += "Please enter your entire telephone number. \n(Including country code and area code)";phone1.focus();}
	else if(phone2.value.length < 1){alertMsg1 += "Please enter your entire telephone number. \n(Including country code and area code)";phone2.focus();}
	else if(phone3.value.length < 1){alertMsg1 += "Please enter your entire telephone number. \n(Including country code and area code)";phone3.focus();}

	else if(currencydollar.value == "0"){alertMsg1 += "Please select your currency preference";currencydollar.focus();}

	else if(email.value.search( Email ) == -1){alertMsg1 += "Please enter your Email address";email.value = ""; email.focus();}
	else if(re_email.value.search( Email ) == -1){alertMsg1 += "Please confirm your Email address";re_email.value = ""; re_email.focus();}
	else if(email.value != re_email.value){alertMsg1 += "You confirm email address is invalid";re_email.value = ""; re_email.focus();}

	else if(username.value.length < 6){alertMsg1 += "Username should be at least six characters or numbers long."; username.focus();}
    else if(username.value.search( UserID ) >= 0){alertMsg1 += " but you can not use ( ) < > & @ in either Username."; username.value = ""; username.focus();}
    
	else if(password.value.length < 6){alertMsg1 += "Password should be at least six characters or numbers long."; password.focus();}
	else if(re_password.value.length < 6){alertMsg1 += "Confirm password should be at least six characters or numbers long."; re_password.focus();}
	else if(password.value != re_password.value){alertMsg1 += "Confirm password does not match.";re_password.value = ""; re_password.focus();}
	
	else if(question.value == "0"){alertMsg1 += "Please select a secret question."; question.focus();}
	else if(myanswer.value.length < 1){alertMsg1 += "Please give an answer for your secret question."; myanswer.focus();}

	else if(birthdate1.value == ""){alertMsg1 += "Please enter your date of birth."; birthdate1.focus();}
	else if(birthdate2.value == ""){alertMsg1 += "Please enter your date of birth."; birthdate2.focus();}
	else if(birthdate3.value == ""){alertMsg1 += "Please enter your date of birth."; birthdate3.focus();}
	else if((year-birthdate3.value) < 18){alertMsg1 += "You must be at least 18 years old to use AxeBay."; birthdate3.focus();}

	if (alertMsg1 != "") {alert(alertMsg1);return false;}
	else{return true;} 
	}
}

function chkRegGus()
{
	Number = /^[0-9() \-\+]{4,}$/i;
    UserID = /[& @ () <>]/g;
	Email = /^[a-z0-9_.-]+([_\\.-][a-z0-9]+)*@([a-z0-9_\.-]+([\.][a-z]{2,4}))+$/i;

	with (document.frm_regis) {
	var alertMsg1 = "";

	var currentTime = new Date();
	var year = currentTime.getFullYear();

	if(firstname.value.length <= 1){alertMsg1 += "Please enter your first name";firstname.focus();}
	else if(lastname.value.length <= 1){alertMsg1 += "Please enter your last name";lastname.focus();}
	else if(street.value.length <= 1){alertMsg1 += "Please enter your Street address";street.focus();}
	else if(suburb.value.length <= 1){alertMsg1 += "Please enter your Suburb";suburb.focus();}
	else if(city.value.length <= 1){alertMsg1 += "Please enter your City";city.focus();}
	else if(state.value.length <= 1){alertMsg1 += "Please enter your State / Province";state.focus();}
	else if(zipcode.value.length <= 1){alertMsg1 += "Please enter your Postal / ZIP code";zipcode.focus();}
	else if(country.value == ""){alertMsg1 += "Please select your Country";country.focus();}

	else if(phone1.value.length < 1){alertMsg1 += "Please enter your entire telephone number. \n(Including country code and area code)";phone1.focus();}
	else if(phone2.value.length < 1){alertMsg1 += "Please enter your entire telephone number. \n(Including country code and area code)";phone2.focus();}
	else if(phone3.value.length < 1){alertMsg1 += "Please enter your entire telephone number. \n(Including country code and area code)";phone3.focus();}

	else if(currencydollar.value == "0"){alertMsg1 += "Please select your currency preference";currencydollar.focus();}
	
	else if(question.value == "0"){alertMsg1 += "Please select a secret question."; question.focus();}
	else if(myanswer.value.length < 1){alertMsg1 += "Please give an answer for your secret question."; myanswer.focus();}

	else if(birthdate1.value == ""){alertMsg1 += "Please enter your date of birth."; birthdate1.focus();}
	else if(birthdate2.value == ""){alertMsg1 += "Please enter your date of birth."; birthdate2.focus();}
	else if(birthdate3.value == ""){alertMsg1 += "Please enter your date of birth."; birthdate3.focus();}
	else if((year-birthdate3.value) < 18){alertMsg1 += "You must be at least 18 years old to use AxeBay."; birthdate3.focus();}

	if (alertMsg1 != "") {alert(alertMsg1);return false;}
	else{return true;} 
	}
}