<!--
//////////////////////////////////////////////////////////////////////////////////////////////////
// Add by Austin /////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
function chkStrField(theField, theFieldName){

	if (theField.value.length == 0 ){
		showAlert("\n" + theFieldName + " is missing");
		theField.focus();
		return true;
	} else { return false; }
}

function checkCalendar(theForm) {
	
	with(theForm) {
		if ( chkStrField(txtSubject, 'Calendar Subject') ) return false;
	}
	
	openInfoDialog();
	return disableForm(theForm);
}

function checkTitle(theForm) {
	
	with(theForm) {
		if ( chkStrField(txtTitle, 'Title') ) return false;
	}
	
	openInfoDialog();
	return disableForm(theForm);
}

function checkNewsletter(theForm) {
	
	with(theForm) {
		if ( chkStrField(txtSubject, 'Newsletter subject') ) return false;
	}
	
	openInfoDialog();
	return disableForm(theForm);
}

function checkChatroom(theForm) {
	
	with(theForm) {
		
		if ( chkStrField(txtName, 'Chatroom name') ) return false;
		
		if ((begin_date.value.length > 0 && end_date.value.length > 0) && (begin_date.value == end_date.value)) {
			alert("The 'Begining Date' and 'Ending Date' is same.\nPlease remove the 'Ending Date'.");
			end_date.focus();
			return false;				
		}
		
		if (begin_date.value.length == 0 && end_date.value.length > 0) {
			alert("Can NOT Enter 'Ending Date' without the 'Begining Date'.");
			begin_date.focus();
			return false;			
		}
		
		if (begin_hr.value.length > 0 && begin_min.value.length > 0 && end_hr.value.length > 0 && end_min.value.length > 0) { 
			if (begin_hr.value == end_hr.value && begin_min.value == end_min.value) {
				alert("The 'Begining Time' and 'Ending Time' is same.\nPlease check time setting.");
				end_hr.focus();
				return false;	
			} else if (begin_hr.value > end_hr.value && begin_min.value == end_min.value) {
				alert("The 'Ending Time' can NOT be less than 'Begining Time'.\nPlease check time setting.");
				begin_hr.focus();
				return false;	
			} else if (begin_hr.value == end_hr.value && begin_min.value > end_min.value) {
				alert("The 'Ending Time' can NOT be less than 'Begining Time'.\nPlease check time setting.");
				begin_hr.focus();
				return false;	
			}
		}	
		
		if (time_type[0].checked == false && time_type[1].checked == false) {
			alert("You must select a type of time between (1) or (2)");
			time_type[0].focus();
			return false;
		}
	}
		
	openInfoDialog();
	return disableForm(theForm);
}

function checkInvitaion(theForm) {

	openInfoDialog();
	return disableForm(theForm);
}

function sendExport() {

	openInfoDialog();
	return true;
}

function chkWriteEdit(theForm) {
	
	with(theForm) {		
		
		if ( chkStrField(txtName, 'Name') ) return false;
		if ( chkStrField(txtEmail, 'Email') ) return false;
		if ( chkStrField(txtPass, 'Password') ) return false;
		
		if (!byadmin.value && md5_pass.value.length != 0 && msg_id.value.length != 0) {
			if ( hex_md5(txtPass.value) != md5_pass.value) {
				showAlert("Password Does Not Match");
				txtPass.focus();
				return false;
			}
		}
		if ( chkStrField(txtSubject, 'Subject') ) return false;
		if ( chkStrField(txtMessage, 'Message') ) return false;
		if ( chkStrField(security_code, 'Security Code') ) return false;
	}
	
	openInfoDialog();
	return disableForm(theForm);
}

function chkAddComment(theForm) {
	
	with(theForm) {
		if ( chkStrField(txtName, 'Name') ) return false;		
		if ( chkStrField(txtPass, 'Password') ) return false;		
		if ( chkStrField(txtComment, 'Comment') ) return false;
	}
	
	openInfoDialog();
	return true;
}

function showAlert(msg) {
	Dialog.alert(msg, {windowParameters: {width:300, height:100}, okLabel: "close", 
			  	ok:function(win) {debug("validate alert panel"); return true;}});	
}

function login(theForm) {
	
	close_info();
	return disableForm(theForm);
}

function editPage(thisForm) {
	
	openInfoDialog();
	return disableForm(theForm);
}

function disableForm(thisform) {
	
	for (i = 0; i < thisform.length; i++) {
		var tempobj = thisform.elements[i];
			
		if (tempobj.type.toLowerCase() == "submit") {
			tempobj.value = "...PROCESSING";
			tempobj.disabled = true;
		}
			
		if  (tempobj.type.toLowerCase() == "button") {
			tempobj.disabled = true;
		}
	}	
	
	return true;
}

function deleteTitle(t_id) {
	
	var msg = "Disabling this title will disable ";
	msg += "any sub titles and calendars.\n";
	msg += "Do you really like to continue?\n\n";
	msg += "Click YES/OK to continue or click CANCEL/NO to return";
	
	if( confirm(msg) )
	 	open("../control_panel/delete_title.php?curr_page=calendar&d=2&t_id="+t_id, "_self");
	else
		return false;
}

function deleteMessageBoard(t_id) {
	
	var msg = "This will inactivate current message board.\n";
	msg += "Do you really like to continue?\n\n";
	msg += "Click YES/OK to continue or click CANCEL/NO to return";
	
	if( confirm(msg) )
	 	open("../control_panel/delete_title.php?curr_page=message_board&d=2&t_id="+t_id, "_self");
	else
		return false;
}

function deleteCalendar(c_id) {
	
	var msg = "Do you really like to disable this calendar?\n\n";
	msg += "Click YES/OK to continue or click CANCEL/NO to return";
	
	if( confirm(msg) )
	 	open("delete_calendar.php?curr_page=calendar&d=2&c_id="+c_id, "_self");
	else
		return false;
}

function deleteNewsletter(n_id) {
	
	var msg = "Do you really like to disable this newsletter?\n\n";
	msg += "Click YES/OK to continue or click CANCEL/NO to return";
	
	if( confirm(msg) )
	 	open("delete_newsletter.php?curr_page=Newsletter&d=2&n_id="+n_id, "_self");
	else
		return false;
}

function deleteArticle(n_id) {
	
	var msg = "Do you really like to disable this article?\n\n";
	msg += "Click YES/OK to continue or click CANCEL/NO to return";
	
	if( confirm(msg) )
	 	open("delete_article.php?curr_page=article&d=2&n_id="+n_id, "_self");
	else
		return false;
}

function deleteChatroom(chat_id) {
	
	var msg = "Do you really like to disable this chatroom?\n\n";
	msg += "Click YES/OK to continue or click CANCEL/NO to return";
	
	if( confirm(msg) )
	 	open("delete_chatroom.php?curr_page=online_chat&d=2&chat_id="+chat_id, "_self");
	else
		return false;
}

// Removes leading whitespaces
function LTrim( value ) {	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");	
}

// Removes ending whitespaces
function RTrim( value ) {	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");	
}

// Removes leading and ending whitespaces
function trim( value ) {	
	return LTrim(RTrim(value));	
}

var timeout;
function openInfoDialog() {
	Dialog.info("Processing...Please Wait!",
				{windowParameters: {className: "alert_lite",width:200, height:50}, showProgress: true});
	timeout=3;
	setTimeout("infoTimeout()", 1000)
}

function infoTimeout() {
  	timeout--;
 	if (timeout > 0) {
    	Dialog.setInfoMessage("Processing...Please Wait!")
		setTimeout("infoTimeout()", 1000)
	} else {
	    Dialog.closeInfo()
	}
}

function getLoginBox(deep) {
	Dialog.alert({url: deep+"login/login.html", options: {method: 'get'}}, 
				 {windowParameters: {className: "alphacube", width:540}, okLabel: "Close"});
}

function getDelMsgBox(boardID, messageID, currPage, pageSize, todo) {
	Dialog.alert({url: "delMessage.php?curr_page=message_board&d=2&c=4&board_id="+boardID+"&msg_id="+messageID+"&now_page="+currPage+"&page_size="+pageSize+"&whichone="+todo, options: {method: 'get'}}, {windowParameters: {className: "alphacube", width:540}, okLabel: "Close"});
}

function getCommentBox(boardID, messageID, currPage, pageSize) {
	Dialog.alert({url: "add_Comment.php?curr_page=message_board&d=2&c=4&board_id="+boardID+"&msg_id="+messageID+"&now_page="+currPage+"&page_size="+pageSize, options: {method: 'get'}}, {windowParameters: {className: "alphacube", width:540}, okLabel: "Close"});
}

function getDelComtBox(boardID, messageID, commentID, currPage, pageSize) {
	Dialog.alert({url: "delComment.php?curr_page=message_board&d=2&c=4&board_id="+boardID+"&msg_id="+messageID+"&comment_id="+commentID+"&now_page="+currPage+"&page_size="+pageSize, options: {method: 'get'}}, {windowParameters: {className: "alphacube", width:540}, okLabel: "Close"});
}

function close_info() {
	Dialog.closeInfo()
}

//////////////////////////////////////////////////////////////////////////////////////////////////

function sendit()
{
	var df = document.login;
	
	if (df.id.value.length == 0)
	{
		alert("Please Enter Your ID")
		df.id.focus();
		return false;
	}
	if (df.psswd.value.length == 0)
	{
		alert("Please Enter Passwords")
		df.psswd.focus();
		return false;
	}
	df.submit();
}

function startOver()
{
	location.href='../login/login.php';
}

function checkEmail(){
	var d = document.account;
	var str=d.email.value;
	if(str == ''){
		alert("Please enter email field");
		d.email.focus();
	}
	else{
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	
		if (!filter.test(str)){
			alert("Please input a valid email address!");
			d.email.focus();
		}
		else{
			url = "../register/checkEmail.php?email="+str;
			window.open(url,"","width=400,height=150");
		}
	}
}

function checkReq(){
	var d = document.account;
	var str=d.email.value;
	var state = '';
	var add = d.add.value;
	var country = '';

	if(str == ''){
		alert("Please type email field");
		d.email.focus();
		return false;
	}
	else{
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	
		if (!filter.test(str)){
			alert("Please type a valid email address!");
			d.email.focus();
			return false;
		}
	}

	for(i=0 ; i< d.state.length; i++){
		if(d.state[i].selected){
			state = d.state[i].value;	
		}
	}
	
	for(i=0 ; i< d.country.length; i++){
		if(d.country[i].selected){
			country = d.country[i].value;	
		}
	}

	if(add != 'yes'){
		if( d.firstName.value == '' || d.lastName.value == '' || 
			d.street.value == '' ||d.city.value == '' || state == '' || 
			(d.zip.value == '' && country == 'USA') || d.phone1.value == '' || country == ''){
			alert("Please type all * field");
			d.firstName.focus();
			return false;
		}
	}
	else{
		var level = '';
		for(i=0 ; i< d.level.length; i++){
			if(d.level[i].checked){
				level = d.level[i].value;	
			}
		}
		
		if( d.firstName.value == '' || d.lastName.value == '' || 
			d.street.value == '' ||d.city.value == '' || state == '' || 
			(d.zip.value == '' && country == 'USA') || d.phone1.value == '' || level == '' || country == ''){
			alert("Please type all * field");
			d.firstName.focus();
			return false;
		}
	}

	
	d.submit();
}

function checkReq1(){
	var d = document.account;
	var state = '';
	var admin = d.admin.value;
	var country = '';
	//alert(d.phone1.value);

	for(i=0 ; i< d.state.length; i++){
		if(d.state[i].selected){
			state = d.state[i].value;	
		}
	}
	
	for(i=0 ; i< d.country.length; i++){
		if(d.country[i].selected){
			country = d.country[i].value;	
		}
	}
	
	if(admin != 'yes'){
		if(d.passwd1.value == '' || d.passwd2.value == '' ||
			d.firstName.value == '' || d.lastName.value == '' || d.street.value == '' ||
			d.city.value == '' || state == '' || (d.zip.value == '' && country == 'USA') || d.phone1.value == '' || country == ''){
			alert("Please type all * field");
			d.passwd1.focus();
			return false;
		}
	} else {
		var mylevel = ''; 
		for(i=0 ; i< d.level.length; i++){
			if(d.level[i].checked){
				mylevel = d.level[i].value;	
			}
		}

		if(d.passwd1.value == '' || d.passwd2.value == '' ||
			d.firstName.value == '' || d.lastName.value == '' || d.street.value == '' ||
			d.city.value == '' || state == '' || (d.zip.value == '' && country == 'USA') || d.phone1.value == ''
			|| d.activity.value == '' || mylevel == '' || country == ''){
			alert("Please type all * field");
			d.passwd1.focus();
			return false;
		}
	}
	
	if(d.passwd1.value != d.passwd2.value){
		alert("Both password fields do not match.");
		d.passwd1.focus();
		return false;
	}
	d.submit();
}

function checkReq2(){
	var d = document.evt_mem;
	if(d.email.value == '' || d.evtID.value == ''){
		alert("Please type all * field");
		d.email.focus();
		return false;
	}
	d.submit();
}

function checkReq3(){
	var d = document.account;
	var input = '';
	var str=d.email.value;
	var year = '';
	var month = '';
	var state = '';
	
	if(str == ''){
		alert("Please type email field");
		d.email.focus();
		return false;
	}
	else{
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	
		if (!filter.test(str)){
			alert("Please type a valid email address!");
			d.email.focus();
			return false;
		}
	}
	
	for(i=0 ; i< d.card.length; i++){
		if(d.card[i].checked){
			input = d.card[i].value;	
		}
	}
	
	for(i=0 ; i< d.year.length; i++){
		if(d.year[i].selected){
			year = d.year[i].value;	
		}
	}
	
	for(i=0 ; i< d.month.length; i++){
		if(d.month[i].selected){
			month = d.month[i].value;	
		}
	}

	for(i=0 ; i< d.state.length; i++){
		if(d.state[i].selected){
			state = d.state[i].value;	
		}
	}
	
	if(d.firstName.value == '' || d.lastName.value == '' || 
		d.street.value == '' ||d.city.value == '' || state == '' || 
		d.zip.value == '' || d.phone1.value == '' || input == '' ||
		d.amount.value == '' || d.cardNum.value == '' || d.csc.value == '' ||
		year == '' || month == ''){
		alert("Please type all * field");
		d.firstName.focus();
		return false;
	}
	
	var m = d.curMonth.value;
	if(m > month){
		alert("Please select valid expire date.");
		return false;
	}

	d.submit();
}

function checkReq4(){
	var d = document.account;
	var input = '';
	var year = '';
	var month = '';

	for(i=0 ; i< d.card.length; i++){
		if(d.card[i].checked){
			input = d.card[i].value;	
		}
	}
	
	for(i=0 ; i< d.year.length; i++){
		if(d.year[i].selected){
			year = d.year[i].value;	
		}
	}
	
	for(i=0 ; i< d.month.length; i++){
		if(d.month[i].selected){
			month = d.month[i].value;	
		}
	}

	if(d.amount.value == '' || d.cardNum.value == '' || d.csc.value == '' ||
		year == '' || month == '' || input == ''){
		alert("Please type all * field");
		d.amount.focus();
		return false;
	}

	var m = d.curMonth.value;
	if(m > month){
		alert("Please select valid expire date.");
		return false;
	}

	d.submit();
}

function checkReq5(){
	var d = document.account;
	
	if(d.psswd.value == '' || d.psswd1.value == '' || d.oldpsswd.value == ''){
		alert("Please type all * field");
		d.oldpsswd.focus();
		return false;
	}
	if(d.oldpsswd.value != d.old.value){
		alert("You typed the wrong current password.");
		d.oldpsswd.focus();
		return false;
	}
	if(d.psswd.value != d.psswd1.value){
		alert("You typed the different new password.");
		d.psswd.focus();
		return false;
	}
	d.submit();
}

function checkSearch(){
	var d = document.find_book;
	var search_by = '';
	
	for(i=0 ; i< d.search_by.length; i++){
		if(d.search_by[i].selected){
			search_by = d.search_by[i].value;	
		}
	}
	
	if(search_by == ''){
		alert("Please select a search category.");
		//d.search_by.focus();
		return false;
	}
	if(d.key.value == ''){
		alert("Please type a search keyword");
		//d.key.focus();
		return false;
	}
	d.submit();
}

function checkCat(){
	var d = document.browse;
	var cat = '';
	
	for(i=0 ; i< d.category.length; i++){
		if(d.category[i].selected){
			cat = d.category[i].value;	
		}
	}
	
	if(cat == ''){
		alert("Please select a category.");
		//d.categoty.focus();
		return false;
	}
}

function checkCat1(){
	var d = document.newCat;
	if(d.cat.value == ''){
		alert("Please type a category");
		d.cat.focus();
		return false;
	}
	else{
		return checkCon();	
	}
	d.submit();
}

function checkCon(){
	var agree = confirm("Are you sure to continue?");
	if(agree)
		return true;
	else
		return false;
		
	d.submit();
}

function checkBook(){
	var d = document.newBook;
	var cat = '';

	for(i=0 ; i< d.cat.length; i++){
		if(d.cat[i].selected){
			cat = d.cat[i].value;	
		}
	}
	
	if(cat == '' || d.title.value == '' || d.price.value == ''){
		alert("Please type all * field.");
		return false;
	}
	else{
		return checkCon();	
	}
		d.submit();

}

function checkBook1(){
	var d = document.newBook;
	
	if(d.title.value == '' || d.price.value == ''){
		alert("Please type all * field.");
		return false;
	}
	else{
		return checkCon();	
	}
		d.submit();

}

function checkCle(){
	var d = document.newCle;
	if(d.s_price.value == '' || d.copy.value == '' || d.title.value == '' || d.price.value == ''){
		alert("Please type all * field.");
		return false;
	}
	else{
		return checkCon();	
	}
		d.submit();

}

function checkLev(){
	var d = document.newLev;
	if(d.lev.value == '' || d.lev_desc.value == ''){
		alert("Please type all * field.");
		return false;
	}
	else{
		return checkCon();	
	}
		d.submit();

}

function checkMyEmail(){
	var d = document.myEmail;
	if(d.email.value == ''){
		alert("Please type your email address.");
		return false;
	}
		d.submit();

}

function checkSrch(){
	var d = document.search;
	if(d.key.value == ''){
		alert("Please type search keyword.");
		return false;
	}
	else{
		if(d.field.value == 'email'){
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
			var str=d.key.value;

			if (!filter.test(str)){
				alert("Please type a valid email address!");
				d.key.focus();
				return false;
			}
		}
		else if (d.field.value == 'status'){
			var tmp = d.key.value;
			var str = tmp.toLowerCase();
			
			if(str != 'member' && str != 'nonmember'){
				alert("Please type a valid status (member or nonmember)!");
				d.key.focus();
				return false;
			}
		}
		else if(d.field.value == 'date'){
			var filter=/^[1-9]\d{3}-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1]))$/;
			var str=d.key.value;

			if (!filter.test(str)){
				alert("Please type a valid date( yyyy-mm-dd )!");
				d.key.focus();
				return false;
			}
		}
	}
	d.submit();
}
