//dp_selectsoldcusts.js -- various funcs populate a select box with the user's current resold customer 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, September 2007.

//BuildResoldCustArray -- 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 BuildResoldCustArray(TheArray,alsoget,nextfunc,failfunc) {
	var apicall="listmyresoldcusts.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, 'BRCA_loadedokay', TheArray, 'BRCA_loadfailed', TheArray);
}

function BRCA_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(count=0;count<tmp.length-1;count++) {
		var maindata=tmp[count].split("~|~");
		TheArray[maindata[0]]={id:maindata[0], name:maindata[1], login:maindata[2], pass:maindata[3], comment:maindata[4], mob:maindata[5], mob_t:(maindata[5]>0?'Y':'-'), rp:maindata[6], rp_t:(maindata[6]>0?'Y':'-'), dp:maindata[7], dp_t:(maindata[7]>0?'Y':'-'), fx:maindata[8], fx_t:(maindata[8]>0?'Y':'-'), mb:maindata[9], mb_t:(maindata[9]>0?'Y':'-'), qtynums:maindata[10]};
	}
	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 BRCA_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.
}
