// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function validateFrmLogin() {
	var userid = document.login_frm.userid;
	var password = document.login_frm.password;

	if (userid.value == "" || password.value=="") {

		if(userid.value==""){
	        userid.style.backgroundColor='FFFF66';
	        userid.focus();
	        result=false;
    	} else userid.style.backgroundColor='FFFFFF';

    	if(password.value==""){
	        password.style.backgroundColor='FFFF66';
	        if(result==true) password.focus();
	        result=false;
    	} else password.style.backgroundColor='FFFFFF';

    	alert("Please input username and password");
	}
	else {
		result= true;
	}
	return result;
}




function validateFrmAddUser(){
   	var username=frm_add_user.username;
    var password=frm_add_user.password;
    var re_password=frm_add_user.re_password;
    var start_date=frm_add_user.start_date;
    var user_level_s=frm_add_user.user_level_s;
    var user_role_s=frm_add_user.user_role_s;
    var fname=frm_add_user.fname;
    var lname=frm_add_user.lname;
    var title=frm_add_user.title;
    var contact_phone=frm_add_user.contact_phone;
    var email=frm_add_user.email;
    var package=frm_add_user.package;
    var server=frm_add_user.server;
    var drive=frm_add_user.drive;
    var port=frm_add_user.port;
    var remark=frm_add_user.remark;
    var status=frm_add_user.status;
    var payment_status=frm_add_user.payment_status;

    var result=true;

    if(username.value==""){
        username.style.backgroundColor='FFFF66';
        username.focus();
        result=false;
    } else username.style.backgroundColor='FFFFFF';

    if(password.value==""){
        password.style.backgroundColor='FFFF66';
        if(result==true) password.focus();
        result=false;
    } else password.style.backgroundColor='FFFFFF';

    if(re_password.value==""){
        re_password.style.backgroundColor='FFFF66';
        if(result==true) re_password.focus();
        result=false;
    } else re_password.style.backgroundColor='FFFFFF';
    if(start_date.value==""){
        start_date.style.backgroundColor='FFFF66';
        if(result==true) start_date.focus();
        result=false;
    } else start_date.style.backgroundColor='FFFFFF';
    if(user_role_s.value==""){
        user_role_s.style.backgroundColor='FFFF66';
        if(result==true) user_role_s.focus();
        result=false;
    } else user_role_s.style.backgroundColor='FFFFFF';

    if(user_level_s.value==""){
        user_level_s.style.backgroundColor='FFFF66';
        if(result==true) user_level_s.focus();
        result=false;
    } else user_level_s.style.backgroundColor='FFFFFF';



     if(title.value==""){
        title.style.backgroundColor='FFFF66';
        if(result==true) title.focus();
        result=false;
    } else title.style.backgroundColor='FFFFFF';
    if(fname.value==""){
        fname.style.backgroundColor='FFFF66';
        if(result==true) fname.focus();
        result=false;
    } else fname.style.backgroundColor='FFFFFF';

    if(lname.value==""){
        lname.style.backgroundColor='FFFF66';
        if(result==true) lname.focus();
        result=false;
    } else lname.style.backgroundColor='FFFFFF';

    if(contact_phone.value==""){
        contact_phone.style.backgroundColor='FFFF66';
        if(result==true) contact_phone.focus();
        result=false;
    } else contact_phone.style.backgroundColor='FFFFFF';
    if(email.value==""){
        email.style.backgroundColor='FFFF66';
        if(result==true) email.focus();
        result=false;
    } else email.style.backgroundColor='FFFFFF';
    if(package.value==""){
        package.style.backgroundColor='FFFF66';
        if(result==true) package.focus();
        result=false;
    } else package.style.backgroundColor='FFFFFF';
    if(server.value==""){
        server.style.backgroundColor='FFFF66';
        if(result==true) server.focus();
        result=false;
    } else server.style.backgroundColor='FFFFFF';
    if(drive.value==""){
        drive.style.backgroundColor='FFFF66';
        if(result==true) drive.focus();
        result=false;
    } else drive.style.backgroundColor='FFFFFF';
    if(port.value==""){
        port.style.backgroundColor='FFFF66';
        if(result==true) port.focus();
        result=false;
    } else port.style.backgroundColor='FFFFFF';
    if(remark.value==""){
        remark.style.backgroundColor='FFFF66';
        if(result==true) remark.focus();
        result=false;
    } else remark.style.backgroundColor='FFFFFF';
    if(status.value==""){
        status.style.backgroundColor='FFFF66';
        if(result==true) remark.focus();
        result=false;
    } else status.style.backgroundColor='FFFFFF';
    if(payment_status.value==""){
        payment_status.style.backgroundColor='FFFF66';
        if(result==true) payment_status.focus();
        result=false;
    } else payment_status.style.backgroundColor='FFFFFF';



    if(result==false){
    	alert("Please correct the incomplete fileds !");
    }

    if(result==true){
    	if((password.value!=re_password.value)){
         password.style.backgroundColor='FFFF66';
         re_password.style.backgroundColor='FFFF66';
            password.focus();
            alert("Please correct the incomplete fileds !");
         result=false;
     }
     else if(password.value==re_password.value) {
         password.style.backgroundColor='FFFFFF'
         re_password.style.backgroundColor='FFFFFF'
     }
    }
    return result;
}

function validateFrmModifyUser(){
   	var username=frm_add_user.username;
    var password=frm_add_user.password;
    var re_password=frm_add_user.re_password;
    var start_date=frm_add_user.start_date;
    var user_level_s=frm_add_user.user_level_s;
    var user_role_s=frm_add_user.user_role_s;
    var fname=frm_add_user.fname;
    var lname=frm_add_user.lname;
    var title=frm_add_user.title;
    var contact_phone=frm_add_user.contact_phone;
    var email=frm_add_user.email;
    var package=frm_add_user.package;
    var server=frm_add_user.server;
    var drive=frm_add_user.drive;
    var port=frm_add_user.port;
    var remark=frm_add_user.remark;
    var status=frm_add_user.status;
    var payment_status=frm_add_user.payment_status;

    var result=true;

    if(username.value==""){
        username.style.backgroundColor='FFFF66';
        username.focus();
        result=false;
    } else username.style.backgroundColor='FFFFFF';
    /*
    if(password.value==""){
        password.style.backgroundColor='FFFF66';
        if(result==true) password.focus();
        result=false;
    } else password.style.backgroundColor='FFFFFF';

    if(re_password.value==""){
        re_password.style.backgroundColor='FFFF66';
        if(result==true) re_password.focus();
        result=false;
    } else re_password.style.backgroundColor='FFFFFF';
    */
    if(start_date.value==""){
        start_date.style.backgroundColor='FFFF66';
        if(result==true) start_date.focus();
        result=false;
    } else start_date.style.backgroundColor='FFFFFF';
    if(user_role_s.value==""){
        user_role_s.style.backgroundColor='FFFF66';
        if(result==true) user_role_s.focus();
        result=false;
    } else user_role_s.style.backgroundColor='FFFFFF';

    if(user_level_s.value==""){
        user_level_s.style.backgroundColor='FFFF66';
        if(result==true) user_level_s.focus();
        result=false;
    } else user_level_s.style.backgroundColor='FFFFFF';



     if(title.value==""){
        title.style.backgroundColor='FFFF66';
        if(result==true) title.focus();
        result=false;
    } else title.style.backgroundColor='FFFFFF';
    if(fname.value==""){
        fname.style.backgroundColor='FFFF66';
        if(result==true) fname.focus();
        result=false;
    } else fname.style.backgroundColor='FFFFFF';

    if(lname.value==""){
        lname.style.backgroundColor='FFFF66';
        if(result==true) lname.focus();
        result=false;
    } else lname.style.backgroundColor='FFFFFF';

    if(contact_phone.value==""){
        contact_phone.style.backgroundColor='FFFF66';
        if(result==true) contact_phone.focus();
        result=false;
    } else contact_phone.style.backgroundColor='FFFFFF';
    if(email.value==""){
        email.style.backgroundColor='FFFF66';
        if(result==true) email.focus();
        result=false;
    } else email.style.backgroundColor='FFFFFF';
    if(package.value==""){
        package.style.backgroundColor='FFFF66';
        if(result==true) package.focus();
        result=false;
    } else package.style.backgroundColor='FFFFFF';
    if(server.value==""){
        server.style.backgroundColor='FFFF66';
        if(result==true) server.focus();
        result=false;
    } else server.style.backgroundColor='FFFFFF';
    if(drive.value==""){
        drive.style.backgroundColor='FFFF66';
        if(result==true) drive.focus();
        result=false;
    } else drive.style.backgroundColor='FFFFFF';
    if(port.value==""){
        port.style.backgroundColor='FFFF66';
        if(result==true) port.focus();
        result=false;
    } else port.style.backgroundColor='FFFFFF';
    /*if(remark.value==""){
        remark.style.backgroundColor='FFFF66';
        if(result==true) remark.focus();
        result=false;
    } else remark.style.backgroundColor='FFFFFF';
    */
	if(status.value==""){
        status.style.backgroundColor='FFFF66';
        if(result==true) status.focus();
        result=false;
    } else status.style.backgroundColor='FFFFFF';
    if(payment_status.value==""){
        payment_status.style.backgroundColor='FFFF66';
        if(result==true) payment_status.focus();
        result=false;
    } else payment_status.style.backgroundColor='FFFFFF';



    if(result==false){
    	alert("Please correct the incomplete fileds !");
    }

    if(result==true){
    	if((password.value!="" || re_password.value!="") && (password.value!=re_password.value)){
         password.style.backgroundColor='FFFF66';
         re_password.style.backgroundColor='FFFF66';
            password.focus();
            alert("Please correct the incomplete fileds !");
         result=false;
     }
     else if(password.value==re_password.value) {
         password.style.backgroundColor='FFFFFF'
         re_password.style.backgroundColor='FFFFFF'
     }
    }
    return result;
}

function validateFrmDeleteUser(s_username){
	if(window.confirm('Are you sure to delete the user: ' + s_username)){
    	var ban_remark = window.prompt('Please enter Ban reason for this user, ' + s_username + ':');
        window.location='user_add_user.php?mode=delete&tran_no=' + s_username + '&ban_remark=' + ban_remark;
	}
}

//user_manage_user.php for Search#####################################
function doSearchUserProfileReport(){
	document.getElementById("submit_option").value='Search';
	document.getElementById("offset").value='';
	document.getElementById("limit").value='';
    document.forms[0].submit();

}
function doClearUserProfileReport(){
    document.getElementById("username").value='';
    //document.getElementById("name").value='';
    document.getElementById("phone").value='';
    document.getElementById("email").value='';
    document.getElementById("status").value='';
    document.getElementById("server").value='';
    document.getElementById("package").value='';
}

function doClearUserProfileReportPayment(){
    document.getElementById("username").value='';
    document.getElementById("name").value='';
    document.getElementById("email").value='';
    document.getElementById("status").value='';
    document.getElementById("server").value='';
    document.getElementById("package").value='';
}

//payment_report.php for Search#####################################
function doSearchPaymentReport(){
	document.getElementById("submit_option").value='Search';
	document.getElementById("offset").value='';
	document.getElementById("limit").value='';
    document.forms[0].submit();

}
function doClearPaymentReport(){
    document.getElementById("username").value='';
    document.getElementById("no_of_month").value='';
    document.getElementById("paid_date").value='';
    document.getElementById("status").value='';
    document.getElementById("bank").value='';
    document.getElementById("package").value='';
    document.getElementById("skip_admin_tran").checked = false;
}

//budget_report.php for Search#####################################
function doSearchBudgetReport(){
	document.getElementById("submit_option").value='Search';
	document.getElementById("offset").value='';
	document.getElementById("limit").value='';
    document.forms[0].submit();

}
function doClearBudgetReport(){
    document.getElementById("tran_type").value='';
    document.getElementById("budget_type").value='';
    document.getElementById("server").value='';
    document.getElementById("id_from").value='';
    document.getElementById("id_to").value='';
    document.getElementById("record_dt_from").value='';
    document.getElementById("record_dt_to").value='';
    document.getElementById("description").value='';
}

//reservation_report.php for Search#####################################
function doSearchReservationReport(){
	document.getElementById("submit_option").value='Search';
	document.getElementById("offset").value='';
	document.getElementById("limit").value='';
    document.forms[0].submit();

}
function doClearReservationReport(){
    document.getElementById("request_type").value='';
    document.getElementById("username").value='';
    document.getElementById("contact_no").value='';
    document.getElementById("email").value='';
    document.getElementById("status").value='';
    document.getElementById("ad_source").value='';
    document.getElementById("package").value='';
}



function inputCurrentDate(field_name){
	cd = new Date();
	var day = cd.getDate();
	var month = (cd.getMonth() + 1);
	var year = cd.getYear();
	if(day.toString().length == 1) day = '0' + day;
	if(month.toString().length == 1) month = '0' + month;
	if(document.getElementById(field_name + '_box').checked){
		document.getElementById(field_name).value=day + "/" + month + "/" + year;
    }
	else{
		document.getElementById(field_name).value='';
    }
}

//Transaction_Report.php#####################################
function doSearchTransactionReport(){
	frm_transaction_report.submit_option.value='Search';
	frm_transaction_report.offset.value='';
	frm_transaction_report.limit.value='';
    frm_transaction_report.submit();

}
function doClearTransactionReport(){
    var create_date = document.frm_transaction_report.create_date;
    var search_name = document.frm_transaction_report.search_name;
    var trn_no = document.frm_transaction_report.trn_no;
    var serial_id = document.frm_transaction_report.serial_id;
    var status = document.frm_transaction_report.status;
    var limit_select = document.frm_transaction_report.limit_select;
    create_date.value="";
    search_name.value="";
    trn_no.value="";
    serial_id.value="";
    status.value="";
    limit_select.value="";
}

//Transaction_Print.php#####################################
function doPrintTransactionPrint(){
	frm_transaction_print.submit_option.value='Print';
    frm_transaction_print.submit();

}
function doPreviewTransactionPrint(){
	frm_transaction_print.submit_option.value='Preview';
    frm_transaction_print.submit();

}
function doClearTransactionPrint(){
	var create_date = document.frm_transaction_print.create_date;
    var trn_no = document.frm_transaction_print.trn_no;
    var serial_id = document.frm_transaction_print.serial_id;
    var status = document.frm_transaction_print.status;
    var sort_by = document.frm_transaction_print.sort_by;
    var sort_direction = document.frm_transaction_print.sort_direction;
    var TRN_CREATE_DT = document.frm_transaction_print.TRN_CREATE_DT;
    var TRN_CUSTOMER_NAME = document.frm_transaction_print.TRN_CUSTOMER_NAME;
    var TRN_GENDER = document.frm_transaction_print.TRN_GENDER;
    var TRN_SIZE = document.frm_transaction_print.TRN_SIZE;
    var TRN_SYMBOL = document.frm_transaction_print.TRN_SYMBOL;
    var TRN_SERIAL_ID = document.frm_transaction_print.TRN_SERIAL_ID;
    var TRN_VIA_BANK = document.frm_transaction_print.TRN_VIA_BANK;
    var TRN_SOLD_PRICE = document.frm_transaction_print.TRN_SOLD_PRICE;
    var TRN_DEPOSIT_FLAG = document.frm_transaction_print.TRN_DEPOSIT_FLAG;
    var TRN_REMARK = document.frm_transaction_print.TRN_REMARK;
    var TRN_STATUS = document.frm_transaction_print.TRN_STATUS;
    var TRN_RESERVE_DT = document.frm_transaction_print.TRN_RESERVE_DT;
    var TRN_DUE_DT = document.frm_transaction_print.TRN_DUE_DT;
    var TRN_FINISH_DT = document.frm_transaction_print.TRN_FINISH_DT;
    var TRN_DELIVER_DT = document.frm_transaction_print.TRN_DELIVER_DT;

    create_date.value="";
    trn_no.value="";
    serial_id.value="";
    status.value="";
    sort_by.value="";
    sort_direction.value="";
    TRN_CREATE_DT.checked=true;
    TRN_CUSTOMER_NAME.checked=true;
    TRN_GENDER.checked=true;
    TRN_SIZE.checked=true;
	TRN_SYMBOL.checked=true;
    TRN_SERIAL_ID.checked=true;
    TRN_VIA_BANK.checked=false;
    TRN_SOLD_PRICE.checked=false;
    TRN_DEPOSIT_FLAG.checked=false;
    TRN_REMARK.checked=true;
    TRN_STATUS.checked=true;
    TRN_RESERVE_DT.checked=true;
    TRN_DUE_DT.checked=true;
    TRN_FINISH_DT.checked=false;
    TRN_DELIVER_DT.checked=false;
    frm_transaction_print.submit_option.value='Clear';
    frm_transaction_print.submit();
}

function doExportTransactionPrint(){
	var create_date = document.frm_transaction_print.create_date;

	frm_transaction_print.submit_option.value='Export';
    popup_window(200,200,"export_window.php?create_date=" + create_date.value ,"export_window");
    //frm_transaction_print.submit();

}

//payment_record.php#####################################
function doAddPayment(){
	var record_date = document.getElementById("record_date");
    var recorder = document.getElementById("recorder");
    var transaction_date = document.getElementById("transaction_date");
    var bank = document.getElementById("bank");
    var amount = document.getElementById("amount");
    var package = document.getElementById("package");
    var no_of_month = document.getElementById("no_of_month");
    var start_date = document.getElementById("start_date");
    var end_date = document.getElementById("end_date");
    var confirm_type = document.getElementById("confirm_type");


	var result = true;
    /*
    if(record_date.value == ""){
    	record_date.style.backgroundColor='FFFF66';
        if(result == true) record_date.focus();
        result = false;
    }else { record_date.style.backgroundColor='FFFFFF';}
    */
    /*if(recorder.value == ""){
    	recorder.style.backgroundColor='FFFF66';
        if(result == true) recorder.focus();
        result = false;
    }else { recorder.style.backgroundColor='FFFFFF';}
    */
    if(transaction_date.value == ""){
    	transaction_date.style.backgroundColor='FFFF66';
        if(result == true) transaction_date.focus();
        result = false;
    }else { transaction_date.style.backgroundColor='FFFFFF';}
    if(bank.value == ""){
    	bank.style.backgroundColor='FFFF66';
        if(result == true) bank.focus();
        result = false;
    }else { bank.style.backgroundColor='FFFFFF';}
    if(amount.value == "" || amount.value <= 0){
    	amount.style.backgroundColor='FFFF66';
        if(result == true) amount.focus();
        result = false;
    }else { amount.style.backgroundColor='FFFFFF';}
    if(package.value == ""){
    	package.style.backgroundColor='FFFF66';
        if(result == true) package.focus();
        result = false;
    }else { package.style.backgroundColor='FFFFFF';}
    if(confirm_type.value=="normal confirm"){
    	if(no_of_month.value == ""){
	        no_of_month.style.backgroundColor='FFFF66';
	        if(result == true) no_of_month.focus();
	        result = false;
	    }else { no_of_month.style.backgroundColor='FFFFFF';}
    }
    /*
    if(start_date.value == ""){
    	start_date.style.backgroundColor='FFFF66';
        if(result == true) start_date.focus();
        result = false;
    }else { start_date.style.backgroundColor='FFFFFF';}
    if(end_date.value == ""){
    	end_date.style.backgroundColor='FFFF66';
        if(result == true) end_date.focus();
        result = false;
    }else { end_date.style.backgroundColor='FFFFFF';}
     */

    if(result==false){
	        alert("Please correct the incomplete fileds !");

	    }
	else{
    	payment_record.submit_option.value='Add';
        payment_record.submit();
	}
}

function doModifyPayment(){
    var record_date = document.getElementById("record_date");
    var recorder = document.getElementById("recorder");
    var transaction_date = document.getElementById("transaction_date");
    var bank = document.getElementById("bank");
    var amount = document.getElementById("amount");
    var package = document.getElementById("package");
    var no_of_month = document.getElementById("no_of_month");
    var start_date = document.getElementById("start_date");
    var end_date = document.getElementById("end_date");
    var status = document.getElementById("status");
    var confirm_type = document.getElementById("confirm_type");


	var result = true;
    /*
    if(record_date.value == ""){
    	record_date.style.backgroundColor='FFFF66';
        if(result == true) record_date.focus();
        result = false;
    }else { record_date.style.backgroundColor='FFFFFF';}
    */
    /*if(recorder.value == ""){
    	recorder.style.backgroundColor='FFFF66';
        if(result == true) recorder.focus();
        result = false;
    }else { recorder.style.backgroundColor='FFFFFF';}
    */
    if(transaction_date.value == ""){
    	transaction_date.style.backgroundColor='FFFF66';
        if(result == true) transaction_date.focus();
        result = false;
    }else { transaction_date.style.backgroundColor='FFFFFF';}
    if(bank.value == ""){
    	bank.style.backgroundColor='FFFF66';
        if(result == true) bank.focus();
        result = false;
    }else { bank.style.backgroundColor='FFFFFF';}
    if(amount.value == "" || amount.value <= 0){
    	amount.style.backgroundColor='FFFF66';
        if(result == true) amount.focus();
        result = false;
    }else { amount.style.backgroundColor='FFFFFF';}
    if(package.value == ""){
    	package.style.backgroundColor='FFFF66';
        if(result == true) package.focus();
        result = false;
    }else { package.style.backgroundColor='FFFFFF';}
    if(confirm_type.value=="normal confirm"){
    	if(no_of_month.value == ""){
	        no_of_month.style.backgroundColor='FFFF66';
	        if(result == true) no_of_month.focus();
	        result = false;
	    }else { no_of_month.style.backgroundColor='FFFFFF';}
    }
    if(status.value == ""){
    	status.style.backgroundColor='FFFF66';
        if(result == true) status.focus();
        result = false;
    }else { status.style.backgroundColor='FFFFFF';}
    /*
    if(start_date.value == ""){
    	start_date.style.backgroundColor='FFFF66';
        if(result == true) start_date.focus();
        result = false;
    }else { start_date.style.backgroundColor='FFFFFF';}
    if(end_date.value == ""){
    	end_date.style.backgroundColor='FFFF66';
        if(result == true) end_date.focus();
        result = false;
    }else { end_date.style.backgroundColor='FFFFFF';}
     */

    if(result==false){
	        alert("Please correct the incomplete fileds !");

	    }
	else{
    	payment_record.submit_option.value='Modify';
        payment_record.submit();
	}
}

function triggerNumOfMonth(controlID){
    if(document.getElementById(controlID).className!="txt_disabled"){
    	if(document.getElementById(controlID).value=="normal confirm"){
	        document.getElementById("lbl_num_of_month").style.display="block";
	        document.getElementById("inp_num_of_month").style.display="block";
	    }
	    else{
	        document.getElementById("lbl_num_of_month").style.display="none";
	        document.getElementById("inp_num_of_month").style.display="none";
	        document.getElementById("no_of_month").value="";
	        document.getElementById("no_of_month").style.backgroundColor='FFFFFF';
	    }
    }
    else if(document.getElementById(controlID).className=="txt_disabled" && document.getElementById(controlID).value=="addition confirm"){
        	document.getElementById("lbl_num_of_month").style.display="none";
	        document.getElementById("inp_num_of_month").style.display="none";
    }
}

function doUpdateExpiryDate(){
    var no_of_month = document.getElementById("no_of_month");
    var start_date = document.getElementById("start_date");
    var end_date = document.getElementById("end_date");

    end_date.value=addMonth(start_date.value,no_of_month.value);
}

function addMonth(dateStart,no_of_month){
	myDate = new Date(dateStart.substring(6,10),dateStart.substring(3,4),dateStart.substring(0,1));
	month = myDate.getMonth();
	modifiedMonth =parseInt(dateStart.substring(3,5)) + parseInt(no_of_month);
	//modifiedDate = new Date(dateStart.substring(6,10), modifiedMonth, dateStart.substring(0,2));
    modifiedDate = new Date(2008, 3, 22);
    alert(modifiedDate);
    return modifiedDate.getDay() + "/" + modifiedDate.getMonth() + "/"  + modifiedDate.getFullYear();
}

function doClearPayment(){
   	var record_date = document.getElementById("record_date");
    var recorder = document.getElementById("recorder");
    var transaction_date = document.getElementById("transaction_date");
    var bank = document.getElementById("bank");
    var amount = document.getElementById("amount");
    var package = document.getElementById("package");
    var no_of_month = document.getElementById("no_of_month");
    var start_date = document.getElementById("start_date");
    var end_date = document.getElementById("end_date");
	var confirm_type = document.getElementById("confirm_type");

    /*record_date.value="";
    record_date.style.backgroundColor='FFFFFF'; */
    /*recorder.value="";
    recorder.style.backgroundColor='FFFFFF';  */
    transaction_date.value="";
    transaction_date.style.backgroundColor='FFFFFF';
    bank.value="";
    bank.style.backgroundColor='FFFFFF';
    amount.value="";
    amount.style.backgroundColor='FFFFFF';
    package.value="";
    package.style.backgroundColor='FFFFFF';
    no_of_month.value="";
    no_of_month.style.backgroundColor='FFFFFF';
    /*start_date.value="";
    start_date.style.backgroundColor='FFFFFF';
    */
    /*
    end_date.value="";
    end_date.style.backgroundColor='FFFFFF';
    */
	confirm_type.value="normal confirm";
    confirm_type.style.backgroundColor='FFFFFF';
	triggerNumOfMonth("confirm_type");
}




//utorrent_webui.php#####################################
function onChange_WebUIPort(thisControl,frame_id){
    var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);
	var cdname=navigator.appCodeName;
	var tmp_user_webui=thisControl.value.split("|");

    if(browser != "Microsoft Internet Explorer"){ //FF Broswer
		window.document.getElementById(frame_id).src="HTTP://" +tmp_user_webui[0]+ ":" + tmp_user_webui[1] + "@" + tmp_user_webui[2] + ":" + tmp_user_webui[3] +"/gui/";
	}
    else{	//IE Broswer
    	window.document.getElementById(frame_id).src="HTTP://" + tmp_user_webui[2] + ":" + tmp_user_webui[3] +"/gui/";
    }
}

//reservation_form.php#####################################
function validateFrmAddReservation(){
	var request_type=document.getElementById("request_type");
   	var username=document.getElementById("username");
    var password=document.getElementById("password");
    var re_password=document.getElementById("re_password");
    var fname=document.getElementById("fname");
    var lname=document.getElementById("lname");
    var contact_phone=document.getElementById("contact_phone");
    var email=document.getElementById("email");
    var package=document.getElementById("package");
    var no_of_month=document.getElementById("no_of_month");
    var ad_source=document.getElementById("ad_source");
    var friend_ref=document.getElementById("friend_ref");
    var remark=document.getElementById("remark");

    var result=true;

    if(request_type.value==""){
        request_type.style.backgroundColor='FFFF66';
        if(result==true) request_type.focus();
        result=false;
    } else request_type.style.backgroundColor='FFFFFF';


    if(fname.value==""){
        fname.style.backgroundColor='FFFF66';

        if(result==true) fname.focus();
        result=false;
    } else fname.style.backgroundColor='FFFFFF';

    if(lname.value==""){
        lname.style.backgroundColor='FFFF66';
        if(result==true) lname.focus();
        result=false;
    } else lname.style.backgroundColor='FFFFFF';

    if(contact_phone.value==""){
        contact_phone.style.backgroundColor='FFFF66';
        if(result==true) contact_phone.focus();
        result=false;
    } else contact_phone.style.backgroundColor='FFFFFF';
    if(email.value==""){
        email.style.backgroundColor='FFFF66';
        if(result==true) email.focus();
        result=false;
    } else email.style.backgroundColor='FFFFFF';

     if(username.value==""){
        username.style.backgroundColor='FFFF66';
        if(result==true) username.focus();
        result=false;
    } else username.style.backgroundColor='FFFFFF';

    if(password.value==""){
        password.style.backgroundColor='FFFF66';
        if(result==true) password.focus();
        result=false;
    } else password.style.backgroundColor='FFFFFF';

    if(re_password.value==""){
        re_password.style.backgroundColor='FFFF66';
        if(result==true) re_password.focus();
        result=false;
    } else re_password.style.backgroundColor='FFFFFF';

    if(package.value==""){
        package.style.backgroundColor='FFFF66';
        if(result==true) package.focus();
        result=false;
    } else package.style.backgroundColor='FFFFFF';

    if(no_of_month.value==""){
        no_of_month.style.backgroundColor='FFFF66';
        if(result==true) no_of_month.focus();
        result=false;
    } else no_of_month.style.backgroundColor='FFFFFF';

    if(ad_source.value==""){
        ad_source.style.backgroundColor='FFFF66';
        if(result==true) ad_source.focus();
        result=false;
    } else ad_source.style.backgroundColor='FFFFFF';



    if(result==false){
    	alert("Please correct the incomplete fileds !");
    }

    if(result==true){
    	if((password.value!=re_password.value)){
         password.style.backgroundColor='FFFF66';
         re_password.style.backgroundColor='FFFF66';
            password.focus();
            alert("Please correct the incomplete fileds !");
         result=false;
     }
     else if(password.value==re_password.value) {
         password.style.backgroundColor='FFFFFF'
         re_password.style.backgroundColor='FFFFFF'
     }
    }
    return result;
}

function validateFrmResponseReservation(){
	//var admin_remark=document.getElementById("admin_remark");
   	var status=document.getElementById("status");

    var result=true;

    /*if(admin_remark.value==""){
        admin_remark.style.backgroundColor='FFFF66';
        if(result==true) admin_remark.focus();
        result=false;
    } else admin_remark.style.backgroundColor='FFFFFF';
    */
    if(status.value==""){
        status.style.backgroundColor='FFFF66';
        if(result==true) status.focus();
        result=false;
    } else status.style.backgroundColor='FFFFFF';


    if(result==false){
    	alert("Please correct the incomplete fileds !");
    }

    return result;
}

function triggerFriendRefInput(controlID){
    if(document.getElementById(controlID).value=="Friend Suggestion" || document.getElementById(controlID).value=="Other Ad"){
        if(document.getElementById(controlID).value=="Friend Suggestion"){
        	document.getElementById("lbl_friend_ref").style.display='block';
            document.getElementById("lbl_friend_ref_other").style.display='none';
        }
        else{
            document.getElementById("lbl_friend_ref").style.display='none';
            document.getElementById("lbl_friend_ref_other").style.display='block';
        }
    	document.getElementById("inp_friend_ref").style.display='block';
    }
    else{
        document.getElementById("lbl_friend_ref").style.display='none';
        document.getElementById("lbl_friend_ref_other").style.display='none';
    	document.getElementById("inp_friend_ref").style.display='none';
    }
}



//budget_form.php#####################################
function validateFrmAddBudget(){
	var tran_type=document.getElementById("tran_type");
   	var transaction_date=document.getElementById("transaction_date");
    var server=document.getElementById("server");
    var budget_type=document.getElementById("budget_type");
    var description=document.getElementById("description");
    var amount=document.getElementById("amount");
    var remark=document.getElementById("remark");

    var result=true;

    if(tran_type.value==""){
        tran_type.style.backgroundColor='FFFF66';
        if(result==true) tran_type.focus();
        result=false;
    } else tran_type.style.backgroundColor='FFFFFF';

    if(transaction_date.value==""){
        transaction_date.style.backgroundColor='FFFF66';
        if(result==true) transaction_date.focus();
        result=false;
    } else transaction_date.style.backgroundColor='FFFFFF';

    if(server.value==""){
        server.style.backgroundColor='FFFF66';
        if(result==true) server.focus();
        result=false;
    } else server.style.backgroundColor='FFFFFF';

    if(budget_type.value==""){
        budget_type.style.backgroundColor='FFFF66';
        if(result==true) budget_type.focus();
        result=false;
    } else budget_type.style.backgroundColor='FFFFFF';
    if(description.value==""){
        description.style.backgroundColor='FFFF66';
        if(result==true) description.focus();
        result=false;
    } else description.style.backgroundColor='FFFFFF';

     if(amount.value==""){
        amount.style.backgroundColor='FFFF66';
        if(result==true) amount.focus();
        result=false;
    } else amount.style.backgroundColor='FFFFFF';
    /*
    if(remark.value==""){
        remark.style.backgroundColor='FFFF66';
        if(result==true) remark.focus();
        result=false;
    } else remark.style.backgroundColor='FFFFFF';
    */



    if(result==false){
    	alert("Please correct the incomplete fileds !");
    }

    return result;
}

function validateFrmModifyBudget(){
  var tran_type=document.getElementById("tran_type");
   	var transaction_date=document.getElementById("transaction_date");
    var server=document.getElementById("server");
    var budget_type=document.getElementById("budget_type");
    var description=document.getElementById("description");
    var amount=document.getElementById("amount");
    var remark=document.getElementById("remark");

    var result=true;

    if(tran_type.value==""){
        tran_type.style.backgroundColor='FFFF66';
        if(result==true) tran_type.focus();
        result=false;
    } else tran_type.style.backgroundColor='FFFFFF';

    if(transaction_date.value==""){
        transaction_date.style.backgroundColor='FFFF66';
        if(result==true) transaction_date.focus();
        result=false;
    } else transaction_date.style.backgroundColor='FFFFFF';

    if(server.value==""){
        server.style.backgroundColor='FFFF66';
        if(result==true) server.focus();
        result=false;
    } else server.style.backgroundColor='FFFFFF';

    if(budget_type.value==""){
        budget_type.style.backgroundColor='FFFF66';
        if(result==true) budget_type.focus();
        result=false;
    } else budget_type.style.backgroundColor='FFFFFF';
    if(description.value==""){
        description.style.backgroundColor='FFFF66';
        if(result==true) description.focus();
        result=false;
    } else description.style.backgroundColor='FFFFFF';

     if(amount.value==""){
        amount.style.backgroundColor='FFFF66';
        if(result==true) amount.focus();
        result=false;
    } else amount.style.backgroundColor='FFFFFF';
    /*
    if(remark.value==""){
        remark.style.backgroundColor='FFFF66';
        if(result==true) remark.focus();
        result=false;
    } else remark.style.backgroundColor='FFFFFF';
    */



    if(result==false){
    	alert("Please correct the incomplete fileds !");
    }

    return result;
}


//popup_alert_payment.php#####################################
function triggerPrePaymentDate(controlID){
	if(controlID=="cont_status2"){
	        document.getElementById("payment_dt_lbl").style.display="none";
	        document.getElementById("payment_dt_value").style.display="none";
    }
    else{
            document.getElementById("payment_dt_lbl").style.display="block";
	        document.getElementById("payment_dt_value").style.display="block";
    }
}

function doConfirmUserPayment(){
	var username = document.getElementById("username");
    var cont_status1 = document.getElementById("cont_status1");
    var cont_status2 = document.getElementById("cont_status2");
    var pre_payment_dt = document.getElementById("pre_payment_dt");
    var remark = document.getElementById("remark");


	var result = true;

    if(username.value == ""){
    	username.style.backgroundColor='FFFF66';
        if(result == true) username.focus();
        result = false;
    }else { username.style.backgroundColor='FFFFFF';}

    if(!document.frm_popup_alert_payment.cont_status[0].checked && !document.frm_popup_alert_payment.cont_status[1].checked){
    	cont_status1.style.backgroundColor='FFFF66';
        cont_status2.style.backgroundColor='FFFF66';
        if(result == true) cont_status1.focus();
        result = false;
    }else { cont_status1.style.backgroundColor='FFFFFF'; cont_status2.style.backgroundColor='FFFFFF';}

    if(document.frm_popup_alert_payment.cont_status[0].checked){
    	if(pre_payment_dt.value == "" || pre_payment_dt.value <= 0){
	        pre_payment_dt.style.backgroundColor='FFFF66';
	        if(result == true) pre_payment_dt.focus();
	        result = false;
	    }else { pre_payment_dt.style.backgroundColor='FFFFFF';}
    }

    if(result==false){
	        alert("Please correct the incomplete fileds !");

	    }
	else{
    	frm_popup_alert_payment.submit_option.value='Add';
        frm_popup_alert_payment.submit();
	}
}

function doLaterConfirmUserPayment(){
	window.location='payment_1index.php';
}

function submitForm(formAction){
	document.getElementById('form_action').value=formAction;
	document.forms[0].submit();
}

function selectRowData(thisRow){
	thisRow.style.backgroundColor='CDF5F3'

}

function SortByField(sort_by){
	if(sort_by==window.document.getElementById('sort_by').value && window.document.getElementById('sort_direction').value=='ASC'){
		window.document.getElementById('limit').value='';
		window.document.getElementById('offset').value='';
		window.document.getElementById('sort_by').value=sort_by;
		window.document.getElementById('sort_direction').value='DESC';
		window.document.forms[0].submit();
	}
	else{
		window.document.getElementById('limit').value='';
		window.document.getElementById('offset').value='';
		window.document.getElementById('sort_by').value=sort_by;
		window.document.getElementById('sort_direction').value='ASC';
		window.document.forms[0].submit();
	}
}

/*
function trigger_user_action(suser_control){
		if(confirm('Are you sure to proceed the action for this user?')){
        	var user_obj = document.getElementById(suser_control);
            document.getElementById('iframe_action').src = user_obj.options[user_obj.selectedIndex].value;
        }
        return false;
}
*/



function GetXmlHttpObject(){
	if (window.XMLHttpRequest)
	  {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	  }
	if (window.ActiveXObject)
	  {
	  // code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	  }
	return null;
}

function change_user_status(urls){

	 xmlhttp=GetXmlHttpObject();
	  if (xmlhttp==null)
		{
		alert ("Browser does not support HTTP Request");
		return;
		}

	  xmlhttp.onreadystatechange= function() { 
		  if (xmlhttp.readyState==4)
			document.getElementById(var_id).innerHTML=xmlhttp.responseText;	
		  }

		xmlhttp.onreadystatechange=stateChanged;
		xmlhttp.open("GET",urls,true);
		xmlhttp.send(null);
}


function trigger_user_action(suser_control){

		if(confirm('Are you sure to proceed the action for this user?')){
        	var user_obj = document.getElementById(suser_control);
			var select_value = user_obj.options[user_obj.selectedIndex].value; 


	   
        	if(select_value.substr(0,12) =='disable_user' || select_value.substr(0,11)=='enable_user'){
        	var para_type;
        
              if(select_value.substr(0,12) =='disable_user') {para_type = 'disable_user'; var username = select_value.substr(12);}
              if(select_value.substr(0,11) =='enable_user') {para_type = 'enable_user'; var username = select_value.substr(11);}
                  url= "ajax_response.php?"+para_type+"=" + username;
                  change_user_status(url);

            }else{
                document.getElementById('iframe_action').src = user_obj.options[user_obj.selectedIndex].value;
           }
  
		}
        return false;
}