/**************
<LINK name="author" HREF="http://www.holderness.eu"> 
<LINK name="license" TYPE="free to nonprofit organisations; others make an offer - see:" HREF="http://www.poptel.org.uk/nuj/mike/js.htm">
<META name="warning" content="I am actively looking for test cases to prosecute!">

This special to linkup.html: probably only need to pass clientLst in to generalise it.
**************/ 

owner_code="_NONE";
this_client="_NONE";
OwnerWidth=220;
InputSize=32;

// function clientLst() {for (var argx in arguments) {this.cl[argx]=arguments[argx]}};

function fillDIV(what,content) {
	if (version=="ECMA") {
		document.getElementById(what).innerHTML=content
	}
	else if (version=="IE5") {
		document.all[what].innerHTML=content
	}
}

function initOwner() {
	if (version=="IE5") { /* Bizarro effect with "shadow" of #nav */
		if (Wwidth<640) {
			InputSize=23
		} else {
			InputSize=27
		} 
	}
	client_list = new Array('client_1','client_2','client_3','client_4','client_5','client_6','client_7','client_8','client_9','client_a','client_b','client_c');
	owner_code="_other";
	for (var fld in client_list) { /* show buttons */
		fillDIV("X"+client_list[fld],"<INPUT type=text name="+client_list[fld]+" size="+InputSize+" maxlength=60><BUTTON type='button' onclick=getOwner('"+client_list[fld]+"')>owner...</BUTTON>")
	}
	fillDIV("WarningBox","")
}

function getOwner(clientN) {
	this_client=clientN;
	for (var fld in client_list) {unMarkField(client_list[fld])};
	setBG(this_client,"rgb(255,153,153)");
	client_name=getValue(clientN);
	client_pos=client_name.indexOf("_");
	if (client_pos>-1) {client_name=trimStr(client_name.substr(0,client_pos))}
	showDiv("_STET","OwnerBox"); /* in forms2.js */
	placeOwners();
	document.ownerForm.z_Ownercode.focus();
}

function putOwner() { /* called from ownerForm onSubmit */
	what=document.ownerForm.z_Ownercode.value;
	if (what=="_other") {what+="="+trimStr(document.ownerForm.z_OtherOwner.value)};
	putValue(this_client,client_name+' '+what,true);
	closeDiv("OwnerBox"); 
	document.thisForm.elements[this_client].focus();
	return false;
}

function closeOwner() {
	closeDiv('OwnerBox');
	unMarkField(this_client);
	return false;
}

function shuntOwners() {
	for (var fld in client_list) {unMarkField(client_list[fld])};
	for (var fld1=0; fld1<client_list.length; fld1++) {
		if (getValue(client_list[fld1])=="_NONE") {
			for (var fld2=fld1+1; fld2<client_list.length; fld2++) {
				temp=getValue(client_list[fld2]);
				if (temp!="_NONE") {
					putValue(client_list[fld1],temp);
					putValue(client_list[fld2],"");
					fld1++
				}
			}
		}
	}
}		

function placeOwners() {
	if (version=="ECMA") {
		with (document.getElementById("OwnerBox").style) {
			left 	= Wwidth - OwnerWidth - 2*mMargin - 10;
			top 	= mMargin + pageYOffset;
			width	= OwnerWidth;
		}
	}
	else if (version=="Nav4") {
		with (document.OwnerBox) {
			left	= Wwidth - OwnerWidth - mMargin;
			top	= mMargin + pageYOffset;
			width	= OwnerWidth;
		}
	}
	else if (version=="IE5") {
		if (!isMac) {
			with (document.all.OwnerBox.style) {
				left	= Wwidth - OwnerWidth - mMargin;
				top	= document.all.nav.style.top;
				width	= OwnerWidth;
			}
		} 
	}
};

