//dp_selectmailboxes.js -- various funcs populate a select box with the user's current mailbox list.
//Based on previous routeplans functionality.
//Note: Requires api_lite, etc, but doesn't include them here as they should always be included from the main program.
//Author: Simon Champion, Skymarket Ltd, August 2008.

//BuildMailboxArray -- this is the function to be called by the main app.
//TheArray is the array you want to save the data into. (note, since it's an array, it can be passed by reference)
function BuildMailboxArray(TheArray,nextfunc,failfunc) {
	var apicall="listmymailboxes.php";
	while(TheArray.length) {TheArray.pop();}	//empty the array of any pre-existing records.
	TheArray[0]=nextfunc;	//shove nextfunc into TheArray so we can pass it through the API without needing any additional params.
	TheArray[1]=failfunc;
	apilite_call(apicall, 'BMBA_loadedokay', TheArray, 'BMBA_loadfailed', TheArray);
}

function BMBA_loadedokay(responsestring,TheArray) {
	var tmp=responsestring.split("\n");	//split the returned lines into an array.
	var nextfunc=TheArray[0];
	var failfunc=TheArray[1];
	while(TheArray.length) {TheArray.pop();}	//empty the array of any pre-existing records.

	for(var count=1;count<tmp.length-1;count++) {
		var maindata=tmp[count].split("~|~");
		TheArray[maindata[0]]={id:maindata[0], name:maindata[1], created:maindata[2], email:maindata[3], inuse:(maindata[4]>0?true:false), inuse_yn:(maindata[4]>0?"Yes":"No"), accessnum:maindata[5], accesscode:maindata[6], accesspin:maindata[7]};
	}
	nfc=nextfunc.split("(");
	if(nfc[1]) {nfc[1]=nfc[1].substr(0,nfc[1].length-1);} //found an open bracket, then strip off the trailing bracket.
	else {nfc[1]="";} //not found a param, then set up a blank one so the next line doesn't error.
	if(nextfunc) {window[nfc[0]](nfc[1]);}	//only supporting one param here, as that's all I need for now.
}
function BMBA_loadfailed(responsestring,TheArray) {
	var nextfunc=TheArray[0];
	var failfunc=TheArray[1];
	nfc=nextfunc.split("(");
	if(nfc[1]) {nfc[1]=nfc[1].substr(0,nfc[1].length-1);} //found an open bracket, then strip off the trailing bracket.
	while(TheArray.length) {TheArray.pop();}	//empty the array of any pre-existing records.
	if(nextfunc) {window[nfc[0]](nfc[1]);}	//only supporting one param here, as that's all I need for now.
}

