var workHrDur;

////////// ------- prototype selector --------------
////////// ------- prototype selector --------------
var dashes = '---------------------------';

function sel_setID(ix){
this.id = ix;	
}

function sel_getID(){
return this.id;	
}

function sel_setWidth(xSz){
// this.selWidth=xSz;
 document.forms[this.formNo][this.id].style.width=xSz;
	
}


function sel_setFontSize(xFz){
 document.forms[this.formNo][this.id].style.fontSize=xFz;
}

function sel_getValue(){
var mDoc =document.forms[this.formNo][this.id];
return mDoc.value;
// var ss = document.forms[fNo][xID].options[i].value;
	
	
}

function sel_getOption(){
var mDoc =document.forms[this.formNo][this.id];
var i = mDoc.selectedIndex;
return mDoc.options[i].text;
// var ss = document.forms[fNo][xID].options[i].value;
	
	
}


function sel_setFormNo(xx){
	this.formNo=xx;	
}


function sel_popDialog(xVal){
var sx;
var i;
var s1;
var s2;
var isSelected = false;

var lSize = this.selWidth;
var rSize;

if (this.hasFind){
	s1 = this.selWidth.split("%");
	i  = parseInt(s1);

	lSize = parseInt(i * this.lftX).toString() + "%";
	rSize = parseInt(i * this.rgtX).toString() + "%";
 
}


ss  = '<select id="' + this.id + '" style="width:' + lSize + ';font-weight:bold;border:solid 1px gray;" size="' + this.selRows + '"';
ss += ' onChange="sel_updateFnd(\'' + this.formNo + '\',\'' + this.id + '\',' + this.findFloat + ');" >\n';

for (i=0;i<this.options.length;i++){
	ss += '<option value="' + this.values[i] + '"';
	if (xVal==this.values[i] && isSelected==false){ss += ' selected ';isSelected=true;};
	ss += '>' + this.options[i] + '</option>\n';
	
}
ss += '</select>\n';

if (this.hasFind){
	ss += '<input type="text" id ="' + this.id + 'fnd" ';
	if (this.findFloat){ss += ' value="' + xVal + '" ';};
	if (winType==0){ss += ' onkeyup="matchSel(\'' + this.formNo + '\',\'' + this.id + '\',' + this.findFloat + ');" '};

	ss += ' style="width:' + rSize + ';border:solid 1px gray;" >\n';
	
	
	
	if (winType!=0){window.setTimeout('sel_keepChecking("' + this.formNo + '","' + this.id + '",' + this.findFloat + ');',3000)};
//	window.setTimeout('sel_keepChecking("' + this.formNo + '","' + this.id + '");',3000);
	
}


return ss;

}


function sel_updateFnd(xFno,xId,xFlt){
var s2 = xId + "fnd";
var sDoc = document.forms[xFno].elements[xId];
var s1 = sDoc.value;

if (xFlt){
	if (s1.indexOf(".")==-1){s1 = s1 + ".0"};
	document.forms[xFno].elements[s2].value = s1;	
}
else {	
	if (this.hasFind){
		document.forms[xFno].elements[s2].value = "";
		afterChange(xId,xFno);
	}

};	

sel_followUp(xFno,xId,xFlt,s1);
	
}

function sel_followUp(xFno,xId,xFlt,xVal){
	
}


var xxMatch = new Array();

function matchSel(xFno,xId,xFlt){
	
var s3 = xId + "fnd";

var s1 = document.forms[xFno].elements[s3].value.toUpperCase();
//document.forms[xFno].zap.value = s3 + ">" + xxMatch[s3] + "<>" +s1;

if (xxMatch[s3]==s1){return};


var i;
var j=0;
var s2="";
var fx1;
var fx2;
var mDoc = document.forms[xFno].elements[xId];

if (s1!=""){
	for (i=0;i<mDoc.length;i++){
		if (!xFlt){
			s2 = mDoc.options[i].text.toUpperCase();
			if (s2.indexOf(s1)>-1){j=i;break};
		}
		else{
			fx1 = parseFloat(s1);
			fx2 = parseFloat(mDoc.options[i].value);
	//		document.forms[xFno].zap.value = fx1.toString() + " == " + fx2.toString();
			if (fx1==fx2){j=i;break};
			
		}
	}
	
	
	mDoc.selectedIndex = j;
if (xxMatch[s3]!=s1){xxMatch[s3]=s1;};

}



// document.forms[xFno].zap.value = s1 + '<<>>' + s2 + "==" + j.toString();
		
	
}

function afterChange(xId,xFno){
	
	
}


function sel_keepChecking(xFno,xId,xFlt){
	
	matchSel(xFno,xId,xFlt);
	window.setTimeout('sel_keepChecking("' + xFno + '","' + xId + '",' + xFlt +');',1000);
}


function sel_setArray(myArray){
var i;
var s1;

//s1 = myArray.join("\n");


for (i=0;i<myArray.length;i++){
	s1 = myArray[i].split(comSep1);
	this.options[i] = s1[1];
	this.values[i] = s1[0];
}

	
}

function apxSel_setBackgroundColor(bCol){
// alert(bCol);
document.forms[this.formNo][this.id].style.background=bCol;
//document.getElementById(this.id).style.background=bCol;

}

function apxSelector(){
this.formNo = 0;
this.id ="";


this.selWidth = "100%";
this.selRows = 1;
this.hasFind = false;
this.findFloat = false;
this.lftX = 0.72;
this.rgtX = 0.20;

this.options = new Array();
this.values = new Array();
	
this.setFormNo =  sel_setFormNo;	
this.setID =  sel_setID;	
this.setWidth =  sel_setWidth;	
this.setFontSize =  sel_setFontSize;	
this.getID = sel_getID;
this.getValue = sel_getValue;
this.getOption = sel_getOption;
this.setBackgroundColor = apxSel_setBackgroundColor;
this.setArray = sel_setArray;
this.popDialog = sel_popDialog;
	
}



//////////// Task Selector ////////////////////
function task_setArray(myArray){
var i;
var s1;
var s2;
var z = 0;
this.options = new Array();
this.values = new Array();
s1 = myArray.join("\n");


this.options[0] = dashes;
this.values[0]  = "";		//"-not_used-";
for (i=0;i<myArray.length;i++){
	s1 = myArray[i].split(comSep1);
	this.options[i+1] = s1[1];
	this.values[i+1] = s1[0];	
}


}


function apxTaskSelector(){
	this.setArray = task_setArray;
}

apxTaskSelector.prototype = new apxSelector();



//////// Stage List  //////////////////

function apxStageSelector(){
}

apxStageSelector.prototype = new apxTaskSelector();



///////// Event Selector //////////////////

function apxEventTypeSelector(){
	
}

apxEventTypeSelector.prototype = new apxTaskSelector();




//////// Time List ////////////////////////

function time_setArray(){
var i;
var j;
var s1;
var s2;
var z = 1;

this.options = new Array();
this.values = new Array();

this.options[0] = "00:00";
this.values[0]  = "00:00";

for (i=0;i<24;i++){
	for (j=0;j<4;j++){
		s1 = make2char(i) + ":" + make2char(j*15);
		this.options[z] = s1;
		this.values[z]  = s1;
		z++;
	}
}

}

function apxTimeSelector(){
	this.setArray = time_setArray;
}

apxTimeSelector.prototype = new apxSelector();




//////// Duration List ///////////////


function duration_getValue(){
var s1 = this.id + "fnd";
var s2 = document.forms[this.formNo].elements[s1].value;	
return s2;
}

function duration_setArray(xx){
var i;
var j;
var s1;
var sHr = " hr";
var sFullDay = "Full Day";

this.options = new Array();
this.values = new Array();

this.options[0] = dashes;
this.values[0]  = "";	

this.options[1] = "0";
this.values[1]  = "0";	

this.options[2] = "30 mins";
this.values[2]  = "0.5";	

this.options[3] = "45 mins";
this.values[3]  = "0.75";	

this.options[4] = "1.0 hr";
this.values[4]  = "1.0";	
	

for (i=1;i<90;i++){
	s1 = (1 + i*0.25).toString();
	j = s1.length;
	if (s1.indexOf(".")== -1 ){s1 += ".0"};
	// alert(s1 + "\n" + s1.indexOf("."));
	s2 = "";
	if (workHrDur == s1){s2 = sFullDay};

	if (s2==""){s2 = s1 + sHr};
	this.options[4+i] = s2;	
	this.values[4+i] = s1;		// (1+i*0.5).toString();
}

	
}




function apxDurationSelector(){
	this.setArray = duration_setArray;
	this.hasFind=true;
	this.findFloat=true;
	this.getValue = duration_getValue;
}

apxDurationSelector.prototype = new apxSelector();



//////// Venue List  //////////////////


function updateVenueText(xId, xFn, eNo, xVen){
	
var i = document.forms[xFn].elements[xId].selectedIndex;
s1 = xId + "txt";
var xDoc = document.forms[xFn].elements[s1];

if (i==eNo){xDoc.value = xVen} else {xDoc.value=""};
	
}


function updateVenueSel(xId,xFn,eNo){
	
var s1 = xId + "txt";
var s2 = document.forms[xFn].elements[s1].value;
var j;
var i;
var s3;
var s4 = s2.toUpperCase();
var xLen = document.forms[xFn].elements[xId].options.length;

if (s2==""){j=0} else {
	j = eNo;
	
};

document.forms[xFn].elements[xId].selectedIndex=j;

	
}



function venue_popDialog(xVal){
var sx;
var i;
var s1;
var s2;
var isSelected = false;

var s1 = this.selWidth.split("%");
var isz = parseInt(s1);

var lSize = parseInt(isz * this.lftX).toString() + "%";
var rSize = parseInt(isz * this.rgtX).toString() + "%";

	



ss  = '<select id="' + this.id + '" onchange="updateVenueText(\'' + this.id + '\',' + this.formNo + ',' + this.extNo + ',\'' + this.extVenue + '\');" ';
ss += ' style="width:' + lSize + ';font-weight:bold;border:solid 1px gray;" size="' + this.selRows + '">\n';
for (i=0;i<this.options.length;i++){
	ss += '<option value="' + this.values[i] + '"';
	if (xVal==this.values[i] && isSelected==false){ss += ' selected ';isSelected=true;};
	if (this.extVenue!="" && isSelected==false && i==this.extNo){ss += ' selected ';isSelected=true;};

	ss += '>' + this.options[i] + '</option>\n';
}
ss += '</select>\n';

ss += '<input type="text" value="' + this.extVenue + '" id="' + this.id + 'txt" ';
if (winType==0){ss += ' onkeyup="updateVenueSel(\'' + this.id + '\',' + this.formNo + ',' + this.extNo + ');" '};

ss += ' style="width:' + rSize + ';font-weight:bold;border:solid 1px gray;" >\n';


 if (winType!=0){window.setTimeout('venue_keepChecking("' + this.formNo + '"' + ',"' + this.id + '",' + this.extNo + ');',3000)};
//window.setTimeout('venue_keepChecking("' + this.formNo + '"' + ',"' + this.id + '",' + this.extNo + ');',3000);


return ss;

}


function venue_checkKeyUp(){
	
venue_keepChecking(this.id, this.extNo);	
		
}


function venue_keepChecking(tFno,sId,exNo){
var s1 = sId + "txt";

var mDoc = document.forms[tFno];
var s2 = mDoc.elements[s1].value;
var mSel = document.forms[tFno][sId].selectedIndex;

//if (winType!=1){document.getElementById("tt").value=s2};

// document.forms[0].valx.value=s2+"<<"+ mSel;
if (mSel==exNo && s2==""){document.forms[tFno][sId].selectedIndex=0};
if (mSel!=exNo && s2!="") {document.forms[tFno][sId].selectedIndex=exNo};

window.setTimeout("venue_keepChecking(\'" + tFno + "\','" + sId + "'," + exNo + ");",500);	
	
}

function venue_getValue(){
var s1 = this.id + "txt";
s1 = document.forms[this.formNo].elements[s1].value;
var mSel = document.forms[this.formNo].elements[this.id];
var s2 = mSel.value;

if (mSel.selectedIndex == this.extNo){s2 += '~' + s1};

return s2;	
	
}


function venue_setArray(rArray){

var i;
var s1;
var j;
var status;
var z = 1;
this.options[0] = dashes;
this.values[0] = "";
for (i=0;i<rArray.length;i++){
	s1 = rArray[i].split(comSep1);
	j = parseInt(s1[0]);
	if (s1[2]!="0"){
		this.options[z]=s1[1];
		this.values[z]=s1[0];
		if(s1[3]=="1"){this.extNo = z};
		z++;
	}
}	
	
}



function apxVenueSelector(){
this.extVenue = "";
this.extIndex;
this.lftX=0.47;
this.rgtX=0.46;

this.setArray = venue_setArray;
this.popDialog = venue_popDialog;
this.checkKeyUp = venue_checkKeyUp;
this.getValue = venue_getValue;
}

apxVenueSelector.prototype = new apxTaskSelector();








///////////////// x List /////////////////////

function prj_setArray(myArray){
var i;
var j;
var k;
var s1;
var s2;
var s3;
var xAr = new Array();
var z = 1;

if (!myArray[0]){
	
	for (i=1;i<myArray.length;i++){
		if (myArray[i]){
			myArray[i]=xStr(myArray[i]);
		}
	}	
	myArray[0]="ok";
}

this.options[0] = dashes;
this.values[0] ="";

if (mhl){
s1 = mhl.split(comSep2);
for (i=0;i<s1.length;i++){
	j = parseInt(s1[i]);
	if (myArray[j]){
		s2 = myArray[j].split(comSep1);
		
		this.options[z]= setPrjOpt(s2,this.pType);
		this.values[z] = j;
		z++;	
	};
}
}

this.options[z] = dashes;
this.values[z] ="";

j=0;
for (i=1;i<myArray.length;i++){
	if (myArray[i]){
		s1 = myArray[i].split(comSep1);
		this.shortName[i] = s1[0];
		s2 = setPrjOpt(s1,this.pType);
		s2 = s2.toUpperCase() + comSep1 + s2 + comSep1 + i.toString();
		xAr[j] = s2;
		j++;
	}
};


xAr.sort();

for (i=0;i<xAr.length;i++){
	s1 = xAr[i].split(comSep1);
	z++	
	this.options[z] = s1[1];
	this.values[z] = s1[2];
};


}

function setPrjOpt(ss,xTyp){
	


switch (xTyp){
	case 1: return ss[0];	
	case 2: return ss[1];	
	case 3: return ss[0] + ' - ' + ss[1];	
	case 4: return ss[1] + ' - ' + ss[0];		
}
		
}


function prj_setProjType(xx){
	this.pType=xx;	
}

function prj_setFontSize(xFz){
var s1 = this.id + "fnd";
 document.forms[this.formNo][this.id].style.fontSize=xFz;
 document.forms[this.formNo][s1].style.fontSize=xFz;

}

function prj_getShortName(xNo){
	return this.shortName[xNo];	
	
}


function apxProjectSelector(myArray){
	this.hasFind=true;
	this.shortName = new Array();
	this.pType=1; 			// 1=Short 2=Full  3=Short+Full 4=Full+short
	this.setArray = prj_setArray;
	this.setProjectType = prj_setProjType;
	this.getShortName = prj_getShortName;
	
}

apxProjectSelector.prototype = new apxSelector



////////// Resources Object ////////////////

function apxResources(){
this.displayMode=0;		//0:used resource 1:all resources
this.inUse =  "";	
this.options = new Array();
this.values = new Array();
this.pointer = new Array();
this.isLive = new Array();
this.marked = new Array();
this.id = "resources";
this.columns = 3;
this.fontSize=10;
this.formNo=0;
this.wordLength=new Array(0,80,40,20,10,5);

this.setFormNo =  sel_setFormNo;	
this.setArray = res_setArray;
this.setID = sel_setID;
this.getID = sel_setID;
this.setInUse = res_setInUse;
this.popDialog = res_popDialog;
this.markList = res_markList;
this.updateInUse = res_updateInUse;
	
}


function res_setArray(rArray){

var i;
var s1;
var j;
var status;
	
for (i=0;i<rArray.length;i++){
	s1 = rArray[i].split(comSep1);
	j = parseInt(s1[0]);
	this.pointer[i]=j;
	this.options[j]=s1[1];
	this.values[j]=s1[0];
	if (s1[2]=="1"){status=true} else {status=false};
	this.isLive[j]=status;	
}	
	
s1 = this.options.join("\n");


	
}


function res_setInUse(myStr){
this.inUse = myStr;
var i;
var j;
var s1;
s1 = myStr.split(comSep2);
this.marked = new Array();

for (i=0;i<this.options.length;i++){
	this.marked[i]=false;
}
for (i=0;i<s1.length;i++){
	j = parseInt(s1[i]);
	this.marked[j]=true;	
	
}
	
	
	
}


function res_markList(resNo,checkValue){

this.marked[resNo] = checkValue;

var s1 = this.id + '-' + resNo;

var st1 = "";
var st2 = "";
var s2 = this.options[resNo].substring(0,this.wordLength[this.columns]);

if (checkValue){st1 ="<b>"; st2="</b>"};

document.getElementById(s1).innerHTML = st1 + s2 + st2;
	
	
}


function res_updateInUse(){
var s1 = "";
var i;
for (i=0;i<this.options.length;i++){
	if (this.marked[i]){
		if (s1==""){s1 = i} else {s1 += comSep2 + i};	
	}	
}	
	

this.inUse = s1;
	
}

function res_popDialog(){
var rLen;
var j;
var k;
var s1;
var s2;
var s3;
var s4;
var i;
var cLen = this.columns;
var maxNo;
var colWidth;
var myInUse = this.inUse.split(comSep2);
var xNo;
var resNo;
var resName;
var isMarked;

var myList = new Array();

if (this.displayMode==0){
	if (this.inUse!=""){
			myList = this.inUse.split(comSep2);
			maxNo = myList.length;
		}
	else {
			myList = "";
			maxNo = 0;
		
		}
	} 
else {
	myList=this.pointer;
	maxNo = myList.length;


}



rLen = Math.ceil(maxNo/cLen);

colWidth = 100/cLen;

//alert(maxNo + "\n" + rLen);

	
	
var ss = '<table width="100%" cellspacing="0" cellpadding="2" bgcolor="#FFFFFF" ';	
ss += ' class="txt' + this.fontSize + '" >\n';

for (i=0;i<rLen;i++){
	ss += '<tr valign="top">\n';
	for (j=0;j<cLen;j++){
		ss += '<td width="' + colWidth + '%" >\n';
		xNo = i*cLen + j;
		if (xNo<maxNo){
			resNo = parseInt(myList[xNo]);
			isMarked = this.marked[resNo];
			s4 = this.options[resNo].substring(0,this.wordLength[cLen]);
			if (isMarked){ s4 = '<b>' + s4 + '</b>'};
			s4 = '<span id="' + this.id + '-' + resNo + '">' + s4 + '</span>';
			s3 = this.id + '_' + resNo;
			s2  = '<input type="checkbox" id="' + s3 + '" ';
			s2 += ' onclick="checkResource(\'' + s3 + '\',' + resNo + ',' + this.formNo + ');" ';
			if (this.marked[resNo]){s2 += ' checked >\n' + s4 + '\n' }
			else {s2 += '>\n' + s4 + '\n'};
			
		}
		else {s2 = ""};
		
		ss += s2 + '\n';
		
		ss += '</td>\n';
	}
	ss += '</tr>\n';
	
}


ss += '</table>\n';

return ss;	
	
	
	
	
	
}


function checkResource(resID,resNo,formNo){
var myChecked = document.forms[formNo].elements[resID].checked;	

//alert(resID + "\n" + resNo + "\n" + formNo + "\n" + myChecked);
	
}


