// Global Variables

var ajax_controller_main_auth = '/lib/ajax/global_clientauth_ajax.asp';
var guiForm;
var dictionaryForm;
var guiFormName = '';
var chooserFilter = '';
var queryCount = 1;
var vLoader = '<img src="/images_main/loading.gif" border="0" width="130" height="60">';
var vClientID = '';
var vCart = [];
var vErrorAlert;
var vUsername = '';
var vPassword = '';
var vAction = '';
var vParams = '';

// ------------------------------------------------------------------------------

function renderClientBar() {
	v_callmethod = 'renderClientBar';
	strURL = ajax_controller_main_auth + '?' + 'callmethod=' + v_callmethod
	if (queryString('clientid') && queryString('clientid') != '') {
	    strURL = strURL + '&clientid='+escape(queryString('clientid'));
	} else if (queryString('ministryid') && queryString('ministryid') != '') {
	    strURL = strURL + '&clientid='+escape(queryString('ministryid'));
	} else {
	    strURL = strURL + '&clientid=';
	}
	//alert(strURL); 
	PassAjaxResponseToFunction(strURL, 'renderClientBar_return', 'null');
	return true;
}

function renderClientBar_return(str_response) {
	//alert('Response: ' + str_response); 
	arr_response = str_response.split('||');
	if ( arr_response[0] == '1') { 
	    document.getElementById('divTopBar').innerHTML = arr_response[1];
	    //if (document.frmSignIn) { document.frmSignIn.fldUsername.focus(); }
	} else {
		alert(arr_response[1]);
	}
	return true;
}

// ------------------------------------------------------------------------------

function processSignIn() { 
	v_callmethod = 'processSignIn';
	strURL = ajax_controller_main_auth + '?' + 'callmethod=' + v_callmethod
	strURL = strURL + "&username=" + escape(document.frmSignIn.fldUsername.value)
	strURL = strURL + "&password=" + escape(document.frmSignIn.fldPassword.value)
	//alert(strURL); 
	PassAjaxResponseToFunction(strURL, 'processSignIn_return', 'null');
	return true;
}

function processSignIn_return(str_response) {
	//alert('Response: ' + str_response); 
	arr_response = str_response.split('||');
	if ( arr_response[0] == '1') { 
	    //document.getElementById('divTopBar').innerHTML = arr_response[1];
	    //renderClientBar();
	    location.href = '/controlpanel';
	} else if (arr_response[0] == '2') {
	    //document.getElementById('divTopBar').innerHTML = arr_response[1];
	    //renderClientBar();
	    location.href = arr_response[1];
	} else if (arr_response[0] == 'x301') {
	    //document.getElementById('divTopBar').innerHTML = arr_response[1];
	    //renderClientBar();
	    location.href = 'http://www.netministry.com/splitredirection.asp?clientid=0&source=dashboardlogin';
	} else {
		alert(arr_response[1]);
	}
	return true;
}

// ------------------------------------------------------------------------------

function processSignOut() { 
	v_callmethod = 'processSignOut';
	strURL = ajax_controller_main_auth + '?' + 'callmethod=' + v_callmethod
	//alert(strURL); 
	PassAjaxResponseToFunction(strURL, 'processSignOut_return', 'null');
	return true;
}

function processSignOut_return(str_response) {
	//alert('Response: ' + str_response); 
	arr_response = str_response.split('||');
	if ( arr_response[0] == '1') { 
	    location.href = arr_response[1] + '/default.asp';
	} else {
		alert(arr_response[1]);
	}
	return true;
}

// ------------------------------------------------------------------------------

function queryString( key )
{
    var re = new RegExp( "[?&]" + key + "=([^&$]*)", "i" );
    var offset = location.search.search( re );
    if ( offset == -1 ) return null;
    return RegExp.$1;
}
