// Global Variables

var ajax_controller = '/apps/messageboard/default_ajax.asp';
var guiForm;
var orderItemsForm;
var dictionaryForm;
var guiFormName = '';
var chooserFilter = '';
var queryCount = 1;

// ------------------------------------------------------------------------------

function showAddForm(vCategoryID,vReplyID,vQuote) { 
	v_callmethod = 'showaddform';
	strURL = ajax_controller + '?' + 'callmethod=' + v_callmethod
	strURL = strURL + '&categoryid=' + vCategoryID;
	strURL = strURL + '&replyid=' + vReplyID;
    strURL = strURL + '&showquote=' + vQuote;
    
    if (vQuote == '2') {
        document.frmReply.update.value = 'true';
    } else {
        document.frmReply.update.value = '';
    }
    
    //document.frmReply.replyid.value = vReplyID;
	//alert(strURL);
	PassAjaxResponseToFunction(strURL, 'showAddForm_return', 'null');
	return true;
}

function showAddForm_return(str_response) {
	//alert('Response: ' + str_response); 
	arr_response = str_response.split('||');
	if ( arr_response[0] == '1') { 
		document.getElementById('BBSAddFormBody').innerHTML = arr_response[1];
	} else {
		alert(arr_response[1]);
	}
	return true;
}

// ------------------------------------------------------------------------------

function submitAddForm() {
    v_callmethod = 'submitaddform';
    strURL = 'callmethod=' + v_callmethod
    strURL = strURL + '&title=' + escape(document.frmReply.title.value);
    strURL = strURL + '&body=' + escape(document.frmReply.body.value);
    if (document.frmReply.messagetarget) { strURL = strURL + '&messagetarget=' + escape(document.frmReply.messagetarget.value); }
    strURL = strURL + '&emailnotification=' + escape(document.frmReply.emailnotification.value);
    strURL = strURL + '&replyid=' + escape(document.frmReply.replyid.value);
    strURL = strURL + '&categoryid=' + escape(document.frmReply.categoryid.value);
    strURL = strURL + '&update=' + escape(document.frmReply.update.value);
    strURL = strURL + '&messageid=' + escape(document.frmReply.messageid.value);
    if (document.frmReply.fname) { strURL = strURL + '&fname=' + escape(document.frmReply.fname.value); }
    if (document.frmReply.lname) { strURL = strURL + '&lname=' + escape(document.frmReply.lname.value); }
    if (document.frmReply.email) { strURL = strURL + '&email=' + escape(document.frmReply.email.value); }
    if (document.frmReply.phone) { strURL = strURL + '&phone=' + escape(document.frmReply.phone.value); }
    if (document.frmReply.username) { strURL = strURL + '&username=' + escape(document.frmReply.username.value); }
    if (document.frmReply.password) { strURL = strURL + '&password=' + escape(document.frmReply.password.value); }
    //alert(strURL); 
    PassAjaxResponseToFunctionUsingPost(ajax_controller,strURL, 'submitAddForm_return', 'null');
    return false;
}

function submitAddForm_return(str_response) {
	//alert('Response: ' + str_response); 
	arr_response = str_response.split('||');
	if ( arr_response[0] == '1') {
		document.getElementById('BBSAddFormBody').innerHTML = arr_response[1];
		//window.location.hash = '';
	} else {
		alert(arr_response[1]);
	}
	return true;
}

// ------------------------------------------------------------------------------

function openSearch() {
    document.getElementById('BBSSearch').style.display = 'block';
    document.getElementById('BBSSearchText').focus();
}

// ------------------------------------------------------------------------------

function closeSearch() {
    document.getElementById('BBSSearch').style.display = 'none';
}

// ------------------------------------------------------------------------------

function deleteMessage(vCategoryID,vReplyID,vMessageID) { 
    if (confirm('Are you sure you want to delete this message?')) {
	    v_callmethod = 'deletemessage';
	    strURL = ajax_controller + '?' + 'callmethod=' + v_callmethod
	    strURL = strURL + '&categoryid=' + vCategoryID;
	    strURL = strURL + '&replyid=' + vReplyID;
        strURL = strURL + '&messageid=' + vMessageID;
	    //alert(strURL);
	    PassAjaxResponseToFunction(strURL, 'deleteMessage_return', 'null');
	}
	return true;
}

function deleteMessage_return(str_response) {
	//alert('Response: ' + str_response); 
	arr_response = str_response.split('||');
	if ( arr_response[0] == '1') { 
		alert('Your message has been deleted.');
		if (arr_response[2] == arr_response[3]) {
		    location.href = '/apps/messageboard/default.asp?categoryid=' + arr_response[1];
		} else {
		    location.href = '/apps/messageboard/default.asp?categoryid=' + arr_response[1] + '&replyid=' + arr_response[2];
		}
	} else {
		alert(arr_response[1]);
	}
	return true;
}

// ------------------------------------------------------------------------------

function showProfileForm() { 
	v_callmethod = 'showprofileform';
	strURL = ajax_controller + '?' + 'callmethod=' + v_callmethod
	//alert(strURL);
	PassAjaxResponseToFunction(strURL, 'showProfileForm_return', 'null');
	return true;
}

function showProfileForm_return(str_response) {
	//alert('Response: ' + str_response); 
	arr_response = str_response.split('||');
	if ( arr_response[0] == '1') { 
		document.getElementById('BBSProfileFormBody').innerHTML = arr_response[1];
		previewAvatar();
	} else {
		alert(arr_response[1]);
	}
	return true;
}

// ------------------------------------------------------------------------------

function submitProfileForm() {
    v_callmethod = 'submitprofileform';
    strURL = 'callmethod=' + v_callmethod
    if (document.frmProfile.action.value == 'login') {
        strURL = strURL + '&fname=' + escape(document.frmProfile.fname.value);
        strURL = strURL + '&lname=' + escape(document.frmProfile.lname.value);
        strURL = strURL + '&email=' + escape(document.frmProfile.email.value);
        strURL = strURL + '&phone=' + escape(document.frmProfile.phone.value);
        strURL = strURL + '&username=' + escape(document.frmProfile.username.value);
        strURL = strURL + '&password=' + escape(document.frmProfile.password.value);
        strURL = strURL + '&action=' + escape(document.frmProfile.action.value);
    } else {
        strURL = strURL + '&fname=' + escape(document.frmProfile.fname.value);
        strURL = strURL + '&lname=' + escape(document.frmProfile.lname.value);
        strURL = strURL + '&email=' + escape(document.frmProfile.email.value);
        strURL = strURL + '&city=' + escape(document.frmProfile.city.value);
        strURL = strURL + '&state=' + escape(document.frmProfile.state.value);
        strURL = strURL + '&country=' + escape(document.frmProfile.country.value);
        strURL = strURL + '&phone=' + escape(document.frmProfile.phone.value);
        strURL = strURL + '&username=' + escape(document.frmProfile.username.value);
        strURL = strURL + '&password=' + escape(document.frmProfile.password.value);
        strURL = strURL + '&signature=' + escape(document.frmProfile.signature.value);
        strURL = strURL + '&avatar=' + escape(document.frmProfile.avatar.value);
        strURL = strURL + '&website=' + escape(document.frmProfile.website.value);
        strURL = strURL + '&bbssorting=' + escape(document.frmProfile.bbssorting.value);
        strURL = strURL + '&privatemessaging=' + escape(document.frmProfile.privatemessaging.value);
        strURL = strURL + '&action=' + escape(document.frmProfile.action.value);
    }
    //alert(strURL); 
    PassAjaxResponseToFunctionUsingPost(ajax_controller,strURL, 'submitProfileForm_return', 'null');
    return false;
}

// ------------------------------------------------------------------------------

function submitProfileForm_return(str_response) {
	//alert('Response: ' + str_response); 
	arr_response = str_response.split('||');
	if ( arr_response[0] == '1') {
	    if (arr_response[2] == 'login') {
	        showProfileForm();
	    } else {
		    document.getElementById('BBSProfileFormBody').innerHTML = arr_response[1];
		}
		//window.location.hash = '';
	} else {
		alert(arr_response[1]);
	}
	return true;
}

// ------------------------------------------------------------------------------

function previewAvatar() {
    if (document.frmProfile.avatar) {
        if (document.frmProfile.avatar.value == '') {
            document.getElementById('BBSAvatarPreviewButton').style.display = 'none';
        } else {
            document.getElementById('BBSAvatarPreviewButton').style.display = 'block';
        }
    }
}
