//dp_selectrouteplans.js -- various funcs populate a select box with the user's current route plan list.
//Separate js include, as it's used by several programs in the skycom management area.
//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, June 2006.

//BuildDayPartingArray -- 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 BuildDayPartingArray(TheArray,alsoget,nextfunc,failfunc) {
	var apicall="listmydaypartings.php?getalso="+alsoget;	//also get the items attached to each plan. (ie numbers, etc)
	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, 'BDPA_loadedokay', TheArray, 'BDPA_loadfailed', TheArray);

}
function BDPA_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=1;count<tmp.length-1;count++) {
		var info=(tmp[count]+"%% %% %% %%").split("%%");	//add some blank %% to the end, so the array contains empty elements at the end rather than not having enough elements.
		var maindata=info[0].split("|");
		var itemdata=new Array();
		for(itemcount=1;itemcount<info.length-1;itemcount++) {itemdata[itemcount]=(info[itemcount]+"|||||").split("|");}
		TheArray[maindata[0]]={id:maindata[0],name:maindata[1],inuse:(maindata[3]>0?true:false),inuse_yn:(maindata[3]>0?"Yes":"No")};
	}
	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 BDPA_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.
}
