

CMS = new Object();
CMS.use_local = (typeof(JSON) == 'object' && typeof(localStorage) == 'object')? 1: 0;
CMS.CSS = [];
CMS.pLD = [];
CMS.rowMapKey = null;
CMS.includes = [];
CMS.includes['js'] = [];
CMS.includes['css'] = [];
CMS.INLINE_SCRIPTS = '';

STACKS = [];
PLI=[];

function distro_error(val){
	if(IS_DISTRO){
		alert("distro says:"+val);
	}
}

function mapsChange(iID,rIND,LsID){
	var lat = document.getElementById('lat'+LsID).value;
	var lng = document.getElementById('lng'+LsID).value;
	var center = lat+","+lng;

	var obj = {};
	obj.options = [];
	obj.options[0] = {};
	obj.options[0].value = center;
	obj.selectedIndex = 0;
	
	mapChange(2,1,rIND,obj);
	mapChange(3,2,rIND,obj);
}

function mapChange(mode,iID,rIND,obj){
	var modes = ['zoom','heading','center','location'];
	var map = document.getElementById('map-'+rIND+'-'+iID);
	var split = map.src.split("&");
	var newSrc = split[0];
	var val = obj.options[obj.selectedIndex].value;
	var key = modes[mode];
	for(var x in split){
		if(x == 0){continue;}
		var parts = split[x].split('=');
		if(parts[0] == key){
			newSrc += '&'+parts[0] + '=' + val;
		}else{
			newSrc += '&'+split[x];
		}
	}
	map.src = newSrc;
}

function mapsSave(iID,rIND,LsID){
	var rec_id = document.getElementById('record_id').value;
	var lat = document.getElementById('lat'+LsID).value;
	var lng = document.getElementById('lng'+LsID).value;

	top.document.getElementById('child-address-0-'+rec_id+'-lat').value = lat;
	top.document.getElementById('child-address-0-'+rec_id+'-long').value = lng;
	top.document.getElementById('child-address-0-'+rec_id+'-heading').value = document.getElementById('compassHeading').value;

	if((lat+0) != 0 && (lng+0) != 0){
		top.document.getElementById('child-address-0-'+rec_id+'-map_mode').selectedIndex = 1;
	}

	top.closeWindow(" ");
}

function setMapMarker(x,y){
	if(sMarkers[x][y].getAnimation() != null){
		sMarkers[x][y].setAnimation(null);
	}else{
		var id = 'map_canvas-'+x;
		var map = document.getElementById(id); // AR2-42075
		var offSet = getOffset(map,'top');
		var m = mapMarkers[x][y];
		top.scrollTo(0,offSet);
		gMap[x].setCenter(new google.maps.LatLng(m[0],m[1]));
		if(parseInt(m[4])){gMap[x].setZoom(m[4]);}
		sInfos[x][y].open(gMap[x],sMarkers[x][y]);
		sMarkers[x][y].setAnimation(google.maps.Animation.BOUNCE);
		setTimeout("sMarkers["+x+"]["+y+"].setAnimation(null);",5000);
	}
}

function social_link(a,b,c){

	// alert("a("+a+") b("+b+") c("+c+")");

	window.open(STACKS["SOCIAL"][a][b][c][0]);
}

function clear_login(obj,val){
	if(obj.value == val){obj.value="";}
}

function getScrollY(){
	return window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;
}

function getViewportWidth(){
	return window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
}

function getViewportHeight(){
	return window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
}

function imgLoad(obj){
	obj.style.visibility = 'visible';
	obj.parentNode.style.backgroundImage = 'none';
}

var offsets = new Object();
offsets.x=-60;
offsets.y=20;
var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
var relative_to_object = 0;
var tipobjInd = 0;
var tipobjMode = 0;
var tipobj=[];

function initHelp(){
	if(ie||ns6){
		tipobj[0]=document.all?document.all["dhtmltooltip"]:document.getElementById?document.getElementById("dhtmltooltip"):"";
		tipobj[1]=document.all?document.all["helptip"]:document.getElementById?document.getElementById("helptip"):"";
	}
}

function getOffset2(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function imgSwap(obj,target,scale){
	var img = document.getElementById(target);
	var src = obj.src;
	var ind = src.indexOf("?");
	if(ind > 0){
		src = src.substr(0,ind);	
	}
	src += "?w=" + scale;
	img.src = src;
}

function ddrivetip(thisObj,t,c,w,x2,y2,i,obj){

	tipobjMode=i;
	if(x2){offsets.x=x2;}
	if(y2){offsets.y=y2;}
	if(typeof w!="undefined"&&w){tipobj[i].style.width=w+"px";}
	if(typeof c!="undefined"&&c!=""){tipobj[i].style.backgroundColor=c;}
	if(ARW != null && ARW[0]){
		var id = thisObj.id.split("-");
		tipobjInd = id[1];
		if(ARW[id[1]]){
			var content = ARW[id[1]].title;
		}else{
			var content = t;
		}
	}else{
		var content = t;
	}

	if(tipobjMode==0){
		tipobj[i].innerHTML=content;
	}else{
		tipobj[i].childNodes[3].innerHTML=content;
	}

	relative_to_object=obj;
	enabletip=true;
	document.onmousemove=positiontip;
	return false;
}

function positiontip(e){
	i = tipobjMode;

	if(!enabletip){return}
	var B=(document.compatMode&&document.compatMode!="BackCompat")?document.documentElement:document.body;
	var curX=(ns6)?e.pageX:event.x+B.scrollLeft;
	var curY=(ns6)?e.pageY:event.y+B.scrollTop;
	var re=ie&&!window.opera? B.clientWidth-event.clientX-offsets.x:window.innerWidth-e.clientX-offsets.x-20
	var be=ie&&!window.opera? B.clientHeight-event.clientY-offsets.y:window.innerHeight-e.clientY-offsets.y-20
	var le=(offsets.x<0)? offsets.x*(-1):-1000;
	if(re<tipobj[i].offsetWidth){
		tipobj[i].style.left=ie? B.scrollLeft+event.clientX-tipobj[i].offsetWidth+"px":window.pageXOffset+e.clientX-tipobj[i].offsetWidth+"px";
	}else if(curX<le){
		tipobj[i].style.left="5px";
	}else{
		tipobj[i].style.left=curX+offsets.x+"px";
	}

	if(typeof(relative_to_object) == 'object'){ // this was done to patch ishop at home calendar rollovers...
		var offTop = getOffset2(relative_to_object,"top");
		var offLeft = getOffset2(relative_to_object,"left");

		//document.getElementById('dashboard_message').innerHTML = offTop + " - " + offLeft;
		tipobj[i].style.position = 'absolute';
		tipobj[i].style.top=offTop+50+"px";				
		tipobj[i].style.left=(offLeft-50)+"px";		
		if(re<tipobj[i].offsetWidth){
			tipobj[i].style.left=ie? B.scrollLeft+event.clientX-tipobj[i].offsetWidth+"px":window.pageXOffset+e.clientX-tipobj[i].offsetWidth+"px";
		}else if(curX<le){
			tipobj[i].style.left="5px";
		}
	}else{
		tipobj[i].style.top=curY+offsets.y+"px"		
	}

	//	tipobj[i].style.top=curY+offsets.y+"px"
	tipobj[i].style.visibility="visible";
	//	alert(tipobj[i].style.top);
	//	alert(tipobj[i].style.left);
}

function hideddrivetip(i){
	if(ns6||ie){
		tipobjMode=i;
		enabletip=false;
		tipobj[i].style.visibility="hidden";
		tipobj[i].style.left="-1000px";
		tipobj[i].style.backgroundColor='';
		tipobj[i].style.width='';
	}
}

if(typeof(XMLHttpRequest) == "undefined"){
  XMLHttpRequest = function() {
    try{return new ActiveXObject("Msxml2.XMLHTTP.6.0");}catch(e){}
    try{return new ActiveXObject("Msxml2.XMLHTTP.3.0");}catch(e){}
    try{return new ActiveXObject("Msxml2.XMLHTTP");}catch(e){}
    try{return new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}
  };
}

CART = new Object();

function slideCart(dir){
	CART.ramp++;
	var unit = CART.ramp + CART.ramp;
	if((CART.cartSlideLeft - unit) < 1){
		unit = CART.cartSlideLeft;
	}
	CART.cartSlideLeft = (CART.cartSlideLeft - unit);
	var leftOff = parseInt(CART.cartInner.style.left);
	CART.cartInner.style.left = (dir == 'R') ?(leftOff + unit) + 'px': (leftOff - unit) + 'px';
	if(CART.cartSlideLeft < 1){
		window.clearInterval(CART.interval);
		var string = (dir == 'R')? ['S','H','O','W','&nbsp;','C','A','R','T']: ['H','I','D','E','&nbsp;','C','A','R','T'];
		for(x in CART.cartButton.childNodes){
			CART.cartButton.childNodes[x].innerHTML = string[x];
		}
		if(dir == 'R'){CART.cart.style.zIndex = 1;}
		try{
			var req = new XMLHttpRequest();
			var command = (dir == 'R')? 'hide': 'show';
			req.open("GET",'index.php?trans=crt|'+command);
			req.send("");
		}catch(e){}
	}
}

function hide_cart(obj,w,h){
	window.clearInterval(CART.interval);
	CART.cart = document.getElementById("cartCon");
	CART.cartInner = document.getElementById("cartInnerCon");
	CART.cartButton = document.getElementById("cartButH");
	CART.leftOff = getOffset2(CART.cart,'left');
	CART.leftOffInner = getOffset2(CART.cartInner,'left');
	CART.cartSlideLeft = w;
	CART.ramp = 3;
	var dir = (CART.leftOff == CART.leftOffInner)? 'R': 'L';
	if(dir == 'L'){CART.cart.style.zIndex = 40;}
	CART.interval = window.setInterval('slideCart("'+dir+'");',5);
}

function setCartStyle(){
	var bottomMarker = document.getElementById('cartStretchMarker');
	var offSetT = getOffset2(bottomMarker,'top');
	if(offSetT > (jH-250)){
		document.getElementById('searchCon').style.position = 'absolute';
		document.getElementById('cartCon').style.position = 'absolute';		
	}
	return false;
}


// COMPATIBILITY IS AN ISSUE... I AM NOT MOVING OVER THE FRAME CONTROLLER UNTIL IT'S BETTER TESTED...

function framePrint(id){
	var item = document.getElementById(id);

	top[id].focus();
	top[id].print();	

	//item.focus();
	//item.print();
}


TICKERS=[];

function initTicker(i){
	var id = 'mMCPID-'+i+'-47';
	var ticker = document.getElementById(id);
	if(ticker.id == id){
		TICKERS[i]=[];
		TICKERS[i][0]=1;
		TICKERS[i][1]=ticker;
		setTimeout("moveTicker("+i+");",50);
	}
}

function switchTicker(i,status){
	try{
		TICKERS[i][0] = status;
	}catch(e){}
}

function moveTicker(i){
	if(TICKERS[i][0] == 1){
		ticker = TICKERS[i][1];
		var right_to_left = false;
		ticker.scrollLeft += (right_to_left)? -1: 1;
		if(right_to_left && ticker.scrollLeft <= 0){
			ticker.scrollLeft = ticker.scrollWidth - ticker.offsetWidth;
		}else if(!right_to_left && (ticker.scrollLeft >= (ticker.scrollWidth - ticker.offsetWidth))){
			ticker.scrollLeft = 0;
		}
	}
	setTimeout("moveTicker("+i+");",50);
}

function getOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function initSearch(){

	try{var s = document.getElementById("search"); if(s.value.replace(/^\s+|\s+$/g,"")=="" && jW > 1000 && ((document.documentElement.scrollTop || window.pageYOffset || 0) < 50)){s.focus();}}catch(e){}

}




function tohex(x){var s='',x_=!isNaN(Number(x))?Number(x):0;while(Boolean(x_)){s='0123456789ABCDEF'.charAt(x_&0xf)+s;x_>>>=4;}while(s.length&0x7){s='0'+s;}return(s);}
function encrypt(a,z,k){var t=new Array();t[0]=1;t[1]=new Number(a);t[2]=new Number(z);var s=0,d=0x9E3779B9,n=32;while(n-->0){t[1]=(t[1]+((t[2]<<4^((t[2]>>5)&0x07ffffff))+t[2]^s+k[(s&3)]))&0xffffffff;s=(s+d)&0xffffffff;t[2]=(t[2]+((t[1]<<4^((t[1]>>5)&0x07ffffff))+t[1]^s+k[(((s>>11)&0x001fffff)&3)]))&0xffffffff;}return(t);}
function cT(w,p){var v=0,h=0,u=null,g='',t,i,e="!!!!!!!\x0d\x0d!!!!!!!";t=''+String.fromCharCode((w.length/16777216)&0xFF)+String.fromCharCode((w.length/65536)&0xFF)+String.fromCharCode((w.length/256)&0xFF)+String.fromCharCode(w.length&0xFF);w=t+w;while(w.length&0x7){w+='\0';}i=0;while(p.length%16){p+=p.charAt(i++);}t=p;p=new Array(p.length/4);i=0;j=0;while(i<t.length)p[j++]=(((t.charCodeAt(i++)&0xFF)<<24)|((t.charCodeAt(i++)&0xFF)<<16)|((t.charCodeAt(i++)&0xFF)<<8)|((t.charCodeAt(i++)&0xFF)))&0xFFFFFFFF;i=0;j=0;k=new Array(4);l=w.length;while(i<l){m=p.length;if(j+4<=m){k[0]=p[j];k[1]=p[j+1];k[2]=p[j+2];k[3]=p[j+3];}else{k[0]=p[j%m];k[1]=p[(j+1)%m];k[2]=p[(j+2)%m];k[3]=p[(j+3)%m];}j=(j+4)%m;v=w.charCodeAt(i++)<<24;v|=w.charCodeAt(i++)<<16;v|=w.charCodeAt(i++)<<8;v|=w.charCodeAt(i++);v&=0xFFFFFFFF;h=w.charCodeAt(i++)<<24;h|=w.charCodeAt(i++)<<16;h|=w.charCodeAt(i++)<<8;h|=w.charCodeAt(i++);h&=0xFFFFFFFF;u=encrypt(v,h,k);g+=(u[0]?''+tohex(u[1])+tohex(u[2]):e);v=0;h=0;u=null;}return g;}

function objToString(o){
	var s = '';
	for(aProp in o){
		s += aProp + ",";
		if(typeof(o[aProp]) == 'object' || typeof(o[aProp]) == 'array'){
			s += "{" + objToString(o[aProp]) + "}\n";
		}
	}
	return s;
}

function getKey(x,arr){
	for(var z in arr){
		if(!x){
			return z;
		}
		x--;
	}
	return 0;
}

function trim(str, chars){
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars){
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars){
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function pr(v){
	distro_error(v);
}

function sortNumber(a,b){
	return a - b;
}

function is_integer(value){
	return ((parseFloat(value) == parseInt(value)) && !isNaN(parseInt(value)))? 1: 0;
}

function countReal(a){
	var c = 0;
	for(var x in a){c++;}
	return c;
}

// CAL...

var cal_only = 0;
var is_nav = 0;
var Events = [];

ROWS=[]; // ----------------------- ??? ---- ??? ---- ??? ---- ???
RCLASS=[];
ROWSC=[];
ROWS.dir=0;
ROWS.srt=0;
ROWS.pn=1;
HELP_STACKS=[];
SEARCH_STACK=[];
PATH_TO_ROOT=[];

RECORDS=[];
LANGS=[];

//ROWS['inbox'] = [];
//ROWS['inbox'].srt = 5;
//page=mail&pane=inbox&page_only=1&srt=5&dir=0&pn=2&rmi=inbox

MOD_STACK=[]; // which mods loaded where...
TL = {};
TL.t = null;
TL.l = false
stateMaps=[];
CHARTS=[];
TEMPLATES=[];
RECORD_MAPS=[];
RECORD_HINGE=[]; // parent - child relationships...
CALS=[];
FRMES=[];
NEW_RECORD_COUNTERS=[];
DRAG_TODO=[];
DRAG_TODO[1]=[];
DRAG_TODO[2]=[];
DRAG_TODO.p=0;
DRAG_TODO.block=null;
FS_PANEL=[];
BLUR_CACHE=[];
PANES=[];
PAGES=[];
CATS=[];
STAGES=[];
LOADER=null;
PROD_SELECTION=[];
TABIND=[[],[]];
cacheVal=false;
cacheKey=false;

TRANS_OPT = 0;

FILES_C = 0;

SELCACHE=[]; // cache

if(typeof(AUTOS) == 'undefined'){
	AUTOS=[];
}

isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers; // ---- YOU SHOULD REALLY TAKE A FEW SECONDS AND REMOVE THIS CRAP... ANYTHING WHICH REFERENCES NS4
isHot=false;

var conM = "Do you really want to delete this Record?";
var AUTO_SAVE = new Object();
var slideController = new Object();
var enableSlide = 0;

function loadVars(arr){ // For now these objects sit outside the main CMS object... but not forever...
	for(x in arr){
		//alert(" x("+x+")=" + arr[x]);
		for(y in arr[x]){
			//alert(" x("+x+")=" + arr[x] + " y("+y+")="+arr[x][y]);
			if(y == 'is_nav'){
				is_nav = arr[x][y];	
			}else if(x == 'Events'){
				Events[y] = arr[x][y];
			}
		}
	}
}

function getRecordFromStack(ind,id,cat_id){

	var activeLang = LANGS['active'][0];

	var activeServ = LANGS['active'][1];

	// LANG KEY IN USE FOR LANGUAGE INTERFACE...

	var lang_serv_key = "lang-"+activeLang+"-"+activeServ;

	// pr("LOADING FROM STACK = x("+ind+") y("+id+") z("+activeLang+")");

	var request_template = 'JS';

	if(typeof(RECORDS[ind]) == 'undefined' || typeof(RECORDS[ind][id]) == 'undefined' || typeof(RECORDS[ind][id][activeLang]) == 'undefined'){

		var command = 'rec|'+ind+"|"+id+"|"+cat_id+"|"+request_template+"|"+RECORD_INDEX+"|"+RECORD_ID;

		requestController(command,0,false,false,false);

		return false;
	}

	var rec_type = 'order';

	loadRecord(false,rec_type,id,cat_id,null,null,null,'edit',null,2,ind,0,null,0);

	return false;
}

function chartCollapse(obj,state){
	var pane = obj.parentNode.parentNode.childNodes[1];
	pane.style.display = (pane.style.display == 'block')? 'none': 'block';
	obj.innerHTML = (pane.style.display == 'block')? 'collapse': 'expand';
}

function toggleDisplay(id,c,r,obj){
	try{
		var display = document.getElementById(id);
		var on = (display.style.display == 'block')? 1: 0;
		display.style.display = (on)? 'none': 'block';
		obj.className = (on)? c+'1': c+'2';
	}catch(e){
		pr("toggleDisplay("+id+")="+e);
		return true;
	}
	return (r)? true: false;
}

function loadRecords(arr){ // Combine with stackLoader

	// MAY NEED RECORD HINGES AT THIS POINT

	var str = '';
	var pIn = 0;
	var pId = 0;

	for(var x in arr){
		if(typeof(RECORDS[x]) == 'undefined'){RECORDS[x]=[];}
		for(var y in arr[x]){
			if(typeof(RECORDS[x][y]) == 'undefined'){RECORDS[x][y]=[];}
			for(var z in arr[x][y]){

				str += ' x('+x+') y('+y+') z('+z+') --- ';

				// pr("loadRecords x("+x+") y("+y+") z("+z+")");

				RECORDS[x][y][z]=arr[x][y][z];

				if(typeof(arr[x][y][z]['PARENT_ID']) != 'undefined'){
					var c = arr[x][y][z]['RECORD_INDEX'];
					var d = arr[x][y][z]['RECORD_ID'];
					var a = arr[x][y][z]['PARENT_INDEX'];
					var b = arr[x][y][z]['PARENT_ID'];
					if(typeof(RECORD_HINGE[a]) == 'undefined'){RECORD_HINGE[a]=[];}
					if(typeof(RECORD_HINGE[a][b]) == 'undefined'){RECORD_HINGE[a][b]=[];}
					if(typeof(RECORD_HINGE[a][b][c]) == 'undefined'){RECORD_HINGE[a][b][c]=[];}
					if(typeof(RECORD_HINGE[a][b][c][d]) == 'undefined'){RECORD_HINGE[a][b][c][d]=[];}
					//pr("parent index found:" + arr[x][y][z]);
				}
			}
		}
	}

	// pr("LOAD RECORDS = "+str);
}

function stack_loader(arr){ // Combine with loadRecords

	for(x in arr){
		var a = x.toString();
		if(typeof(STACKS[a]) == 'undefined'){
			STACKS[a]=[];
		}
		if(a == 'LBID' || a == 'LBPR' || a == 'AVAILP' || a == 'ECOM' || a == 'OPTS' || a == 'CIMGS' || a == 'PRODSEL'){
			STACKS[a]=arr[x];
		}else if(a == 'AUTODDS'){
			for(y in arr[x]){
				STACKS[a][y] = arr[x][y];
			}
		}else if(a == 'LBD'){
			for(y in arr[x]){
				var b = y.toString();
				STACKS[a][b]=arr[x][y];
			}
		}else if(a == 'SOCIAL'){
			for(y in arr[x]){
				var b = y.toString();
				if(typeof(STACKS[a][b]) == 'undefined'){
					STACKS[a][b]=[];
				}
				for(z in arr[x][y]){
					var c = z.toString();
					STACKS[a][b][c]=arr[x][y][z];
				}
			}
		}else{
			pr("UNKNOWN STACK LOADER KEY("+a+")");
		}
	}
}

function sendChart(id,key,mode,swit,is_reset){ // mode 1
	var obj = document.getElementById('chart-'+id);
	var OffL1 = getOffset(obj.childNodes[0],'left');
	var OffL2 = getOffset(obj.childNodes[1],'left');
	var width = OffL2 - OffL1;
	var height = parseInt(obj.style.height);
	var key = (typeof(key) != "undefined")? key: CHARTS[id][0][1];
	var mode = (typeof(mode) != "undefined")? mode: CHARTS[id][0][2];
	var swit = (typeof(swit) != "undefined")? swit: CHARTS[id][0][3];
	var sLBL = CHARTS[id][0][4];
	var sCHK = CHARTS[id][0][5];
	var chart = CHARTS[id][1][swit];
	var data = (typeof(CHARTS[id][key]) != "undefined" && typeof(CHARTS[id][key][mode]) != "undefined" && typeof(CHARTS[id][key][mode][swit]) != "undefined")? CHARTS[id][key][mode][swit]['data']: false;

	if(!width){return;}
	obj.childNodes[2].style.display = "block";
	obj.childNodes[2].style.height = height+"px";
	obj.childNodes[2].style.width = width+"px";

	// alert('php/graphics/pchart.php?c='+chart+'&w='+width+'&h='+height+data);

	if(data){

		var l = data.length;
		var data_str = '';
		var is_label = 0;

		for(var x = 0; x < l; x++){
			if(sLBL && (l-1) == x){
				is_label = 1;
				data_str += '&S=';		
			}else{
				data_str += (x==0)? '&L=': '&L'+x+'=';
			}
			if(x && sCHK && !is_label){
				var chkB = document.getElementById('chtC-'+(x-1)+'-CB');
				if(is_reset){
					chkB.checked = "checked"; 
				}else if(!Boolean(chkB.checked)){
					data_str += 'NULL';
					continue;
				}
			}
			data_str += data[x].join('|');
		}

		var xl = (data.length - 1);
		for(var x = 0; x < 13; x++){
			var d = (x < xl)? 'block': 'none';
			var dObj = document.getElementById('stat3Col'+x);
			if(dObj != null){
				dObj.style.display = d;
			}
		}

		var src = 'php/graphics/pchart.php?c='+chart+'&w='+width+'&h='+height+data_str;

		obj.childNodes[3].innerHTML = '<img onload="ChartLoaded(this);" src="'+src+'" style="width:100%;" border="0">';
		var avgs = CHARTS[id][key][mode][swit]['avgs'];

		try{
			for(x in avgs){
				document.getElementById(x).innerHTML = avgs[x];
			}
		}catch(e){alert(x+" = "+e);}

	}else{
		var command = "cht|"+id+"|"+key+"|"+mode+"|"+swit+"|"+RECORD_ID;
		//alert("command="+command);
		requestController(command,0,false,false,false);
	}
}

function loadChart(command,chart_id,date_key,mode,swit,arr){
	clearController(command);
	if(typeof(CHARTS[chart_id][date_key]) == 'undefined'){CHARTS[chart_id][date_key] = [];}
	if(typeof(CHARTS[chart_id][date_key][mode]) == 'undefined'){CHARTS[chart_id][date_key][mode] = [];}
	CHARTS[chart_id][date_key][mode][swit] = arr[chart_id][date_key][mode][swit];
	sendChart(chart_id,date_key,mode,swit);
}

function setChart(obj,id){
	var d = document.getElementById('stats_date[day]').value;
	var m = document.getElementById('stats_date[month]').value;
	var y = document.getElementById('stats_date[year]').value;
	var key = y+"/"+m+"/"+d;
	var mode = document.getElementById('stats_date_mode');
	mode = mode[mode.selectedIndex].value;
	var swit = document.getElementById('stats_switch_mode');
	swit = swit[swit.selectedIndex].value;
	var is_reset = (obj.nodeName=='SELECT')? 1: 0;
	sendChart(id,key,mode,swit,is_reset);
}

function ChartLoaded(obj){
	//obj.parentNode.style.height = null;
	obj.parentNode.parentNode.childNodes[2].style.display = "none";
}

function loadCharts(){
	if(typeof(CHARTS) != 'undefined'){
		for(x in CHARTS){
			sendChart(x);
		}
	}
}

function requestController(command,hook,is_post,no_busy,throbber,obj,throbberId){

	try{
		var dm = document.getElementById('dashboard_message');
		dm.innerHTML='';
		dm.style.background = "none";
	}catch(e){}

	try{
		PANES[PANES.i].ownerDocument.getElementById('error_message').innerHTML='';
	}catch(e){}

	if(no_busy && 1==1){
		var req = new XMLHttpRequest();
		req.open("GET",'index.php?trans='+command);
		req.send("");
		return false;
	}

	if(throbber){// reserveClass
		var a = document.getElementById(command).childNodes[1];
		a.classNameCached = a.className;
		a.innerHTMLCached = a.innerHTML;
		a.innerHTML = '&nbsp;';
		a.className = throbber;
		a.blur();
	}

	if(typeof(throbberId) != 'undefined'){
		try{
			document.getElementById(throbberId).style.display = 'block';
		}catch(e){}
	}

	var l,ind,fr;
	fr = top.frames;
	l = fr.length;
	//alert("L is="+l);
	if(l > 20){
		//alert("L is greater than 20 its="+l);
		for(x=0;x<l;x++){
			//alert("className="+fr[x].frameElement.className);
			//alert(objToString(fr[x]));
		}
		//top.location.replace(top.location.toString());
		return;
	}

	//	perhaps you should be setting a timeout on the frames... we need to clean these up as we go along... and we need to remove the limit...
	//	alert("length:"+l);

	for(var x=1; x < l; x++){ // skip the heartbeat...
		if(!FRMES[x]){FRMES[x]=[];} // move to an initializer...
		try{fr[x].test = x;}catch(e){continue;}
		if(FRMES[x]['busy']!=true && fr[x].frameElement.className == 'frameController'){
			FRMES[x]['busy']=true;
			FRMES[x]['command']=command;
			FRMES[x]['hook']=hook;
			FRMES[x]['throbberId']=throbberId;
			// eventually your going to want to store the command and resend in case of failure...
			try{
				PANES[PANES.i].ownerDocument.getElementById('loader').style.display='block';
			}catch(e){}
			top.frames[x].id = 'RC'+x;
			if(is_post == 'POST'){
				return fr[x];
			}else{
				if(typeof(obj) == 'object'){
					FRMES[x].innerSTORE = obj.innerHTML;
					FRMES[x].caller = obj;
					FRMES[x].oldClass = obj.className;
					//obj.innerHTML = ''; // THIS IS CAUSING ISSUES WHEN A SECOND CHILD RECORD IS CALLED IN INTERNET EXPLORER ONLY...
					obj.className = obj.className+"X";
					obj.blur();
				}
				fr[x].location.replace('index.php?trans='+command);
				return false;
				return x;
			}
		}
	}

	var newframe;

	newframe = document.createElement("IFRAME");
	newframe.setAttribute('class','frameController');
	newframe.className = 'frameController';

	if(IS_DISTRO){
		newframe.setAttribute('width','1000px');
		newframe.setAttribute('height','1000px');
	}else{
		newframe.setAttribute('style','position:absolute;left:-500px;top:0px;');
		newframe.setAttribute('width','0px');
		newframe.setAttribute('height','0px');
		newframe.setAttribute('border','0px');
	}

	document.body.appendChild(newframe);
	return requestController(command,hook,is_post,no_busy,0,obj,throbberId);
}

function switch_tab(obj,tab,pane,tabMap){

	// alert(typeof(tabMap));
	// This should be using ID numbers... NOT CADENCE...
	// CAN I REDIRECT FINAL PRINTS TO NEW WINDOWS BASED ON TABLE PRINT OUTS...
	// NEED TO SHOW AND HIDE OPTIONAL ROW STATUS COMPLETE SELECT...

	var grp = document.getElementById(obj.id);
	var tab_set = document.getElementById(tab).childNodes;
	var y = grp.options[grp.selectedIndex].value;
	var l = tab_set.length;

	if(typeof(tabMap) == 'object' && typeof(tabMap[y]) != 'undefined'){
		y = tabMap[y];
	}

	// alert('tab=' + tab + ' y=' + y);

	for(x in tab_set){
		if(typeof(tab_set[x].id) != 'undefined'){
			var block_id = tab_set[x].id.substr(1);
			tab_set[x].style.display = (y == block_id)? 'block': 'none';
		}
	}

	if(tab == 'tab_set'){
		document.getElementById('F-'+pane).target = ((y == 2))? "_blank": "";
	}
}

function switch_rec_tab(rec_no,tab_no,obj){

	for(x in REC_TAB){
		try{
			var tab_class = (tab_no == x)? 'aTabA': 'aTabB';
			document.getElementById('rec_tab_'+rec_no+'_'+x).className = tab_class;
			var tab_display = (tab_no == x)? 'block': 'none';
			document.getElementById('rec_pane_'+rec_no+'_'+x).style.display = tab_display;
		}catch(e){z=20;}
	}
	try{
		loadCharts();
		obj.blur();
	}catch(e){}

	return false;
}

function initAutoSave(){
	var id = document.getElementById('iAutoS').value;
	var freq = document.getElementById('iAutoSF').value;
	var mili = freq * 60000;
	AUTO_SAVE.setTimeout = setTimeout("runAutoSave()",5000);
}

function runAutoSave(lang){

	if(lang){
		//alert("CALL TO SAVE LANG");
		var activeLang = LANGS['active'][0];
		var activeServ = LANGS['active'][1];	
		var sect = 'lang';
		var pane = activeLang+"-"+activeServ;
		var id = document.getElementById('iLangS').value;
		var frame = document.getElementById(id+"___Frame");
		var content = frame.contentWindow;
		var html = content.FCK.GetXHTML();// FCKConfig.FormatSource 

		var rec_id = document.getElementById('rec_id').value;
		var rec_type = document.getElementById('rec_type').value;
		var lang_serv_key = "lang-"+activeLang+"-"+activeServ;
		//RECORDS[rec_type][rec_id][lang_serv_key] = [];
		//RECORDS[rec_type][rec_id][lang_serv_key][1] = arr[1][1];
		//RECORDS[rec_type][rec_id][lang_serv_key][2] = arr[1][2];
		RECORDS[rec_type][rec_id][lang_serv_key][3] = html;

		document.getElementById('in-3').value = html;
		element_whitelist=[];
		element_whitelist[0] = 'rec_id';
		element_whitelist[1] = 'rec_type';
		//element_whitelist[2] = 'iLangSV'; // replaced in favour of in-3
		element_whitelist[3] = 'rec_lang';
		var y = 4;
		for(x in RECORDS[rec_type][0]['cam']){
			element_whitelist[y++] = 'in-'+x;
		}
		savePane(sect,pane,'AUTO_SAVE',element_whitelist);
	}else{
		var sect = 'newsletter';
		var pane = 'newsletters';
		var id = document.getElementById('iAutoS').value;
		var frame = document.getElementById(id+"___Frame");
		var onOff = document.getElementById('iAutoST').value;
		if(onOff == 'off'){return;}
		var content = frame.contentWindow;
		var html = content.FCK.GetXHTML();// FCKConfig.FormatSource 
		if(html.replace(/^\s+|\s+$/g,"") == ""){
			var freq = document.getElementById('iAutoSF').value;
			var mili = freq * 60000;
			AUTO_SAVE.setTimeout = setTimeout("runAutoSave()",mili);	
			return;
		}
		document.getElementById('iAutoSV').value = html;
		element_whitelist=[];
		element_whitelist[0] = 'rec_id';
		element_whitelist[1] = 'rec_type';
		element_whitelist[2] = 'iAutoSV';
		savePane(sect,pane,'AUTO_SAVE',element_whitelist);
		var freq = document.getElementById('iAutoSF').value;
		var mili = freq * 60000;
		AUTO_SAVE.setTimeout = setTimeout("runAutoSave()",mili);
	}
}

function toggleAutoSave(obj){
	var onOff = document.getElementById('iAutoST');
	if(onOff.value == 'off'){
		onOff.value = 'on';
		obj.innerHTML = 'Enabled';
		var freq = document.getElementById('iAutoSF').value;
		var mili = freq * 60000;
		AUTO_SAVE.setTimeout = setTimeout("runAutoSave()",mili);
	}else{
		onOff.value = 'off';
		obj.innerHTML = 'Disabled';
		clearTimeout(AUTO_SAVE.setTimeout);
	}
}

function restoreAutoSave(){
	var sect = 'newsletter';
	var pane = 'newsletters';
	element_whitelist=[];
	element_whitelist[0] = 'rec_id';
	element_whitelist[1] = 'rec_type';
	savePane(sect,pane,'RESTORE_SAVE',element_whitelist);
}

function setLangLock(t){
	setTimeout("LANGS['lock'] = 0;",t);
}

function restoreLang(lang,ver,mode,anchor){

	if(LANGS['lock']){ // KLUDGE // Required because a fast double click causes the wrong record to overwrite from cache...
		return;
	}
	LANGS['lock'] = 1;
	setLangLock(1000);

	// mode 2 is a reque...
	// mode 0 is a switch, or load...

	// SHOULD THESE BE NAME VALUE PAIRS???
	// alert("RESTORE LANG="+lang + " " + ver + " " + mode);
	var sect = 'lang';
	var pane = lang+"-"+ver;
	var activeLang = (!mode)? lang:LANGS['active'][0];
	var activeServ = (!mode)? ver:LANGS['active'][1];
	var rec_id = document.getElementById("rec_id").value;
	var rec_type = document.getElementById("rec_type").value;
	var rec_lang = document.getElementById("rec_lang").value;
	var lang_serv_key = "lang-"+lang+"-"+ver;
	if(!mode){
		// I need to cache stored...
		// alert("active="+LANGS['active'][0]+" "+LANGS['active'][1]);

		var id = document.getElementById('iLangS').value;
		var frame = document.getElementById(id+"___Frame");
		var content = frame.contentWindow;
		var default_lang = LANGS[0];
		var var_sect = document.getElementById('var_sect').value;
		var form = document.getElementById(var_sect);

		// ALWAYS STORE CHANGES
		var lang_store_key = "lang-"+LANGS['active'][0]+"-"+LANGS['active'][1];

		if(LANGS['active'][0] == default_lang){
			lang_store_key = default_lang;
		}
		if(lang == default_lang){
			lang_serv_key = default_lang;
		}

		//pr("lang_store_key("+lang_store_key+") lang_serv_key("+lang_serv_key+")");

		var html = content.FCK.GetXHTML();
		for(x in RECORDS[rec_type][0]['cam']){
			var fieldID = 'in-'+RECORD_INDEX+'-'+x;
			var fieldINDEX = RECORDS[rec_type][0]['cam'][x];
			//alert("restoreLand fieldID("+fieldID+")");
			var store_value = (fieldINDEX == 3)? html: document.getElementById(fieldID).value;
			RECORDS[rec_type][rec_id][lang_store_key][x] = store_value;	
			var lang_input_key = lang_store_key+'-'+x;
			try{
				var input = document.getElementById(lang_input_key).value = store_value;
			}catch(e){
				var input = document.createElement('INPUT');
				input.setAttribute('id',lang_input_key);
				input.setAttribute('name',lang_input_key);
				input.setAttribute('type','hidden');
				input.value = store_value;
				form.appendChild(input);
			}
		}
		// I WANT TO CHECK THE LANG MAPS TO SEE IF ITS BEEN STORED OR NOT... and reload from stored.
		if(LANGS[2][lang_serv_key][2]){
			//pr("RESTORE("+lang_serv_key+")="+objToString(RECORDS[rec_type][rec_id][lang_serv_key]));
			for(x in RECORDS[rec_type][0]['cam']){
				var fieldID = 'in-'+RECORD_INDEX+'-'+x;
				var fieldINDEX = RECORDS[rec_type][0]['cam'][x];
				if(fieldINDEX == 3){
					content.FCK.SetData(RECORDS[rec_type][rec_id][lang_serv_key][x]);
				}else{
					document.getElementById(fieldID).value = RECORDS[rec_type][rec_id][lang_serv_key][x];
				}
			}
			LANGS['active'] = [lang,ver];
			toggle_lang_switches();
			return;
		}
		//alert("ITS NOT LOADED REQUEST FROM SERVER="+lang_serv_key);
	}

	var com = 'rl'+mode;
	var command = com+"|"+activeLang+"|"+activeServ+"|"+rec_type+"|"+rec_id;
	requestController(command,0,false,false,false);
}

function loadAutoSave(sect,data,mode,arr){ // called when a frame returns content...
	// WHAT HAPPENS WHEN YOU'VE BEEN LOGGED OUT DUE TO INACTIVITY? CLEAR COOKIES AND FIND OUT...
	var hook = clearController(sect);
	if(mode == 'AUTO_SAVE'){
		document.getElementById('auto_save_time').innerHTML = data;
	}else if(mode == 'RESTORE_SAVE'){
		var id = document.getElementById('iAutoS').value;
		var frame = document.getElementById(id+"___Frame");
		var onOff = document.getElementById('iAutoST').value;
		if(onOff == 'off'){return;}
		var content = frame.contentWindow;
		//alert(data);
		content.FCK.SetData(arr[1][3]);
	}else if(mode == 'LANG_SAVE'){
		var lang_key = "lang-"+arr[0][0];
		var lang_serv_key = "lang-"+arr[0][0]+"-"+arr[0][1];
		LANGS[3][lang_key][1] = arr[0][1];
		LANGS[2][lang_serv_key][1] = 1;
		LANGS[2][lang_serv_key][4] = 0;
		toggle_lang_switches();
	}else if(mode == 'RESTORE_LANG'){
		var rec_id = document.getElementById('rec_id').value;
		var rec_type = document.getElementById('rec_type').value;
		var lang_key = "lang-"+arr[0][0];
		var lang_serv_key = "lang-"+arr[0][0]+"-"+arr[0][1];
		var is_preferred = arr[2][1];

		if(arr[0][0] == LANGS[0]){
			lang_serv_key = LANGS[0];
		}

		// pr("loadAutoSave lang_serv_key("+lang_serv_key+")");

		RECORDS[rec_type][rec_id][lang_serv_key] = [];
		RECORDS[rec_type][rec_id][lang_serv_key][1] = arr[1][1];
		RECORDS[rec_type][rec_id][lang_serv_key][2] = arr[1][2];
		RECORDS[rec_type][rec_id][lang_serv_key][3] = arr[1][3];
		//alert("lang_serv_key="+objToString(RECORDS[rec_type][rec_id][lang_serv_key]));
		LANGS[2][lang_serv_key][2] = 1;
		var id = document.getElementById('iLangS').value;
		var frame = document.getElementById(id+"___Frame");
		var content = frame.contentWindow;
		for(x in RECORDS[rec_type][0]['cam']){
			var fieldID = 'in-'+RECORD_INDEX+'-'+x;
			var fieldINDEX = RECORDS[rec_type][0]['cam'][x];
			
			//pr("loadAutoSave fieldID("+fieldID+") fieldINDEX("+fieldINDEX+")");

			if(fieldINDEX == 3){
				content.FCK.SetData(arr[1][3]);
			}else{
				document.getElementById(fieldID).value = RECORDS[rec_type][rec_id][lang_serv_key][fieldINDEX];
			}
		}

		//alert("LOAD AUTO SAVE="+lang_serv_key);
		//alert(LANGS[2][lang_serv_key]);
		LANGS[2][lang_serv_key][1] = arr[2][1];
		LANGS[2][lang_serv_key][3] = arr[2][3];
		LANGS[2][lang_serv_key][4] = arr[2][4];
		if(is_preferred == 1){
			LANGS[3][lang_key][1] = arr[0][1];
		}		

		//alert(LANGS[2][lang_serv_key]);

		LANGS['active'] = [arr[0][0],arr[0][1]];
		toggle_lang_switches();
	}
}

// I NEED A LANG OBJECT FOR TOGGLING PURPOSES...

function toggle_lang_switches(){
	var lang_box = document.getElementById("lang_box");
	var arr = LANGS['active'];
	var this_lang = "lang-"+arr[0]+"-"+arr[1];
	var this_sect = "lang-"+arr[0];
	var styles = ['proofA','proofIA','proofAP','proofIAP','proofIN','proofIAN','proofAE','proofE','proofIAE','proofIE'];
	document.getElementById("rec_lang").value = arr[0]+"-"+arr[1];
	//alert(LANGS['active'][0] +" "+ LANGS['active'][1]);
	var lang_key,active,lang_button,lang_sect_key,ex,panel_set;
	//alert(this_lang);
	for(x in LANGS[2]){

		// pr("SPLITTING LANG[2] x("+x+")");

		ex = x.split("-");
		var lang_pref = LANGS[2][x];

		var lang_control_key = (ex[0] == LANGS[0])? 'lang-'+LANGS[0]: 'lang-'+ex[1];
		var lang_ele = (ex[0] == LANGS[0])? 'lang-'+LANGS[0]+'-0': x;

		// pr("LANG CONTROL KEY("+lang_control_key+")   0("+ex[0]+") 1("+ex[1]+")");

		var lang_control = LANGS[3][lang_control_key];
		var B1 = document.getElementById(lang_ele);

		if(lang_pref[4] > 0){
			B1.className = (x == this_lang)? styles[8]: styles[9];
			if(!lang_control[0] && ex[2] == lang_control[1] && lang_pref[3] == 1){
				B1.className = (x == this_lang)? styles[6]: styles[7];
			}else if(lang_control[1] && ex[2] == lang_control[1] && lang_pref[3] > 1){
				B1.className = (x == this_lang)? styles[6]: styles[7];
			}
		}else if(!lang_control[0] && ex[2] == lang_control[1] && lang_pref[3] == 1){ // its preferred...
			B1.className = (x == this_lang)? styles[2]: styles[3];
		}else if(lang_control[1] && ex[2] == lang_control[1] && lang_pref[3] > 1){ // strict Proofing Preferred
			B1.className = (x == this_lang)? styles[2]: styles[3];
		}else if(parseInt(lang_pref[3]) == 0){
			B1.className = (x == this_lang)? styles[5]: styles[4];
		}else{
			B1.className = (x == this_lang)? styles[0]: styles[1];
		}

		// pr("B1classname id("+x+") class("+B1.className+") B2("+B2+")");

		if(ex[2] > 0){
			if(ex[1] == arr[0]){
				if(panel_set == 1){continue;}
				panel_set = 1;
			}
			active = ((ex[0]+"-"+ex[1]) == this_sect)? 1: 0;
			//alert("FOUND ACTIVE="+"("+ex[0]+"+ +"+ex[1]+") == "+this_sect);
			lang_sect = document.getElementById("lang-"+ex[1]);
			var lC0 = lang_sect.childNodes[1].childNodes[0];
			var lC1 = lang_sect.childNodes[1].childNodes[1];
			lC0.className = (active)? "proofIA":"";
			lC0.style.display = (active)? "inline":"none";
			lC1.className = (active)? "proofIA":"";
			lC1.style.display = (active)? "inline":"none";
		}
	}
}

function switch_widget(obj,tab){
	//obj.parentNode.parentNode.(obj.options.selectedIndex);
	var inp = obj.parentNode.parentNode.childNodes[1].childNodes[0];
	if(obj.options.selectedIndex && obj.options[obj.options.selectedIndex].text.indexOf('Is') == -1){
		inp.disabled = 0;
		inp.focus();
	}else{
		inp.disabled = 1;
		inp.value = '';
	}
}

function goto_pn(obj,i,s,rowMapIndex,paneIndex){

	var sort = 0;
	var filters = false;
	var paneFind = false;
	var paneFindVal = '';

	if(obj.id.substring(0,11) === 'page_select'){	
		var i = obj.options[obj.selectedIndex].value;
	}else if(i == 'n'){
		var i = 1+parseInt(ROWSC[rowMapIndex].pn);
	}else if(i == 'p'){
		var i = parseInt(ROWSC[rowMapIndex].pn)-1;
	}else if(i == 'c'){
		sort = 1;
		var d = (ROWSC[rowMapIndex].dir == 1)? 0: 1;
		var i = parseInt(ROWSC[rowMapIndex].pn);
	}else if(i == 'f'){ // filter
		var i = parseInt(ROWSC[rowMapIndex].pn);
		var filters = true;
	}else if(i == 's'){ // search
		var i = parseInt(ROWSC[rowMapIndex].pn);
		var paneFindVal = obj.parentNode.childNodes[1].value;
		paneFind = true;
	}

	if(!sort){
		s = ROWSC[rowMapIndex].srt;
		d = ROWSC[rowMapIndex].dir;
	}

	//str += 'pn=' + i;
	var checkF = '';
	if(filters){
		var checkFilters = document.getElementById('check_filters');
		var cFC = checkFilters.childNodes[0].value;
		for(var x = 0; x < cFC; x++){
			var input = document.getElementById('check_filter-'+x);
			if(input.nodeName == 'INPUT'){
				checkF += (input.checked)? '1':'0';
			}else{
				checkF += (input.selected)? '1':'0';
			}
		}
	}

	var page_only = (top.location.href.indexOf('page_only=1') > 0)? 1: 0;
	var do_find = (paneFind)? 1: 0;
 	var command = 'row|'+sort+"|"+s+"|"+d+"|"+i+"|"+rowMapIndex+"|"+do_find+"|"+paneFindVal+"|"+paneIndex+"|"+checkF+"|"+page_only;

	requestController(command,1,false);
	obj.blur();
	return false;
}

function checkbox(obj){
	var pane = PANES.i.substr(2);

	// pr("checkbox() pane("+pane+")");

	obj.className = "checkC";
	element_whitelist=[];
	element_whitelist[0] = obj.childNodes[0].id;
	element_whitelist[1] = 'SAVE';
	element_whitelist[2] = 'record_id';
	savePane('erp',pane,'CHECKBOX',element_whitelist);
}

function checkboxReturn(objName,objValue){
	var obj = document.getElementById(objName);
	obj.parentNode.className = (objValue > 0)? "checkB": "checkA";
	obj.value = objValue;
}

function to_do_drag(obj,mode){

	// we need to cycle through all the to dos and understand thier co-ordinates...
	var toDoBlock = obj.parentNode.parentNode.parentNode;
	DRAG_TODO.block = toDoBlock;

	var l = (mode == 1)? toDoBlock.childNodes.length:toDoBlock.childNodes.length-2; // we skip the add to... and the hidden textarea...
	var bTop = getOffset(toDoBlock,'top');
	var oTop = getOffset(obj,'top');
	var z = 0;
	for(x = 0; x < l; x++){
		childNode = toDoBlock.childNodes[x];
		ttop = getOffset(childNode,'top') - oTop;
		DRAG_TODO[1][x] = ttop;
		DRAG_TODO[2][x] = childNode;
		DRAG_TODO.l = x;
		if(!ttop){DRAG_TODO.p = x;}
		childNode.style.zIndex = (!ttop)? "100": "10";
	}

	var minY = DRAG_TODO[1][0]; // this is position of the item in relation to the mainblock... in negative numbers...
	var maxY = DRAG_TODO[1][(l-1)];
	var toDo = obj.parentNode.parentNode;

	Drag.init(toDo,null,-5,5,minY,maxY);
	Drag.oHeight = DRAG_TODO[1][DRAG_TODO.p+1]; // find the height of the object...
	Drag.oHeight = 24;

	toDo.onDrag = function(x, y){
		for(z=0;z<l;z++){
			var oby = DRAG_TODO[1][z];
			if(!oby){continue;}
			if(y > 0){
				DRAG_TODO[2][z].style.top = (y >= oby && oby > 0)? Drag.oHeight * -1 + "px": "0px";
			}else if(y < 0){
				DRAG_TODO[2][z].style.top = (y <= oby && oby < 0)? Drag.oHeight + "px": "0px";
			}
		}
	}

	toDo.onDragEnd = function(x, y){
		var l = DRAG_TODO.l;
		var block = DRAG_TODO.block;
		var clones=[];
		var positions=[];
		var ups = 0;
		var downs = 0;
		for(x=0;x<=l;x++){
			obj = DRAG_TODO[2][x];
			var pos = parseInt(obj.style.top);
			if(pos < 0){
				i = x-1;if(x != DRAG_TODO.p){ups++;}
			}else if(pos > 0){
				i = x+1;if(x != DRAG_TODO.p){downs++;}
			}else{
				i = x;
			}
			positions[x] = i;
			obj.style.top = "0px";
			obj.style.left = "0px";
			clones[x] = obj.cloneNode(true);
			block.removeChild(obj);
		}
		positions[DRAG_TODO.p] = (ups)? DRAG_TODO.p+ups: DRAG_TODO.p-downs;
		cadence=[];
		for(x=0;x<=l;x++){
			cadence[positions[x]] = x;
		}
		//alert(positions);
		var c = 0;
		var str = "";
		for(x=0;x<=l;x++){
			block.insertBefore(clones[cadence[x]],block.childNodes[c]);
			var s = clones[cadence[x]].id.split("-");
			var p = (mode == 1)? s.length-1: s.length-2;
			str += s[p] + "-";
			c++;
		}

		var command = (mode == 1)? 'Otl|': 'Otd|';
		command += rtrim(str,"-");
		requestController(command,0,false,true);
	}
}

function over_to_do_item(obj){
	this.className = 'toDoRowO';
}

function out_to_do_item(obj){
	this.className = 'toDoRow';
}

function reorderLists(obj){
	var state = (obj.innerHTML == "Re-Order Lists")? 1: 0;
	var paneForm = document.getElementById("F-project_to_do_lists").childNodes[0];
	var l = paneForm.childNodes.length;
	for(x=0;x<l;x++){
		var toDoBlock = paneForm.childNodes[x];
		var cN = toDoBlock.childNodes;
		
		if(cN[2] && cN[0]){
			cN[2].style.display = (state)? "none":"block";		
			cN[0].childNodes[0].className = (state)? "toDoDragA": "toDoDrag";
		}
	}
	obj.innerHTML = (state)? "Click to Finish Re-Order": "Re-Order Lists";
	obj.className = (state)? "mMinpY":"mMinpI";
}

function requestRecord(obj,rec_type,rec_id,parent_id,parent_rec_index,searchRecId,throbberId,child_rec_index){

	if(!isInitDone){
		return false;
	}

	// CHECK TO SEE IF WE HAVE LOADED THE TEMPLATE...
	// TEMPLATES NEED TO FAIL GRACEFULLY OR ROUTE OTHERWISE ON FULL SCREEN RECORD LOAD...
	// IF IT'S A CALL TO A NEW RECORD WE CAN SKIP THE CALL TO SERVER...

	var state = (rec_id == 'N')? "new":"edit";

	var stateMap = (stateMaps[parent_rec_index] && stateMaps[parent_rec_index][child_rec_index] && stateMaps[parent_rec_index][child_rec_index][state])? stateMaps[parent_rec_index][child_rec_index][state]: null;

	var request_template = (!stateMap || typeof(TEMPLATES[parent_rec_index]) == 'undefined' || typeof(TEMPLATES[parent_rec_index][child_rec_index]) == 'undefined' || typeof(TEMPLATES[parent_rec_index][child_rec_index][stateMap.tmpl]) == 'undefined')? 1: 0;

	// pr("requestRecord state("+state+") stateMap("+stateMap+") rec_type("+rec_type+") parent_rec_index("+parent_rec_index+") child_rec_index("+child_rec_index+")");

	// check to see if an item is loaded into search

	// pr("stateMap("+stateMap.tmpl+") request_template("+request_template+")");

	if(searchRecId && trim(searchRecId) != ''){
		var searchRecId = document.getElementById(searchRecId).value;
		if(trim(searchRecId) != '' && searchRecId > 0){
			rec_id = searchRecId;
		}
	}

	if(!request_template && state == "new" && rec_id == 'N'){
		var arr=[];
		return loadRecord(false,rec_type,rec_id,parent_id,arr,null,null,state,[],0,parent_rec_index,0,{},child_rec_index);
	}

	var command = 'rec|'+rec_type+"|"+rec_id+"|"+parent_id+"|"+request_template+"|"+parent_rec_index;

	// pr("requestRecord command("+command+")");

	requestController(command,null,false,false,false,obj,throbberId);
}

function fill_record(type,rec_type,rM,record_index,rec_id,prev_rec_id,is_child,is_clear){

	var fields = rM['fields'];

	// check for a category field???

	// pr("record_index("+record_index+") rec_id("+rec_id+")");

	for(var x in fields){

		var key = fields[x][0];

		var widget_id = 'in-'+record_index+'-'+key;

		var widget_name = null;

		var swap_id = null;

		var swap_name = null;

		if(fields[x].CHARTS){
			//pr("CHART FOUND CONTINUE key("+key+")");
			continue;
		}

		if(!key){
			pr("NO KEY FOUND as in B[0] does not exist (COULD BE A CATEGORY ISSUE in ajax functions) fields[x]("+objToString(fields[x])+")");
			continue;
		}

		if(is_child){

			// pr("IS CHILD - key("+key+") index("+record_index+") "+objToString(fields[x]));

			// alert("child-"+x+"-0-"++"-");

			widget_id = "child-"+rec_type+"-0-"+prev_rec_id+"-"+key;

			if(prev_rec_id != rec_id){
				//alert("SWAP FOUND prev_rec_id("+prev_rec_id+") rec_id("+rec_id+")");
				swap_id = "child-"+rec_type+"-0-"+rec_id+"-"+key;
			}
		}

		if(!is_clear && (!prev_rec_id || typeof(RECORDS[record_index][rec_id]['en'][key]) == 'undefined')){
			// pr("KEY NOT FOUND key("+key+") widget_id("+widget_id+")");
			
			if(!is_child){
				pr("TOP VALUES NOT FOUND key("+key+") widget_id("+widget_id+") field[1]("+fields[1]+") fields[x]("+objToString(fields[x])+")");
			}
			continue;
		}

		var val = (is_clear)? null: RECORDS[record_index][rec_id]['en'][key];

		z = -1;

		for(var y in fields[x]){

			z++;

			if(!z){continue;}
			if(z > 1){break;}

			if(y == 'join' && fields[x].join[2] == 'undefined'){
				pr("JOIN SELECTOR rec_type("+rec_type+") y("+y+") obj("+objToString(fields[x])+") fields[x].join[0]("+fields[x].join[0]+")");
				continue;			
			}

			var widget = document.getElementById(widget_id);

			if(!widget){
				//pr("widget NOT FOUND key("+widget_id+") rec_type("+rec_type+")");

				if(!is_child){
					pr("IS TOP widget NOT FOUND key("+widget_id+") rec_type("+rec_type+") y("+y+")");
				}

				continue;
			}else{
				//pr("widget key("+'in-'+record_index+'-'+key+") x("+x+")");
			}
				
			if(y == 'static'){

				widget.innerHTML = (is_clear)? "": val;

			}else if(y == 'WYS'){

				// pr("WYS rec_type("+rec_type+") y("+y+") obj("+objToString(fields[x])+") val("+val+")");

				var id = document.getElementById('iLangS').value;
				var frame = document.getElementById(id+"___Frame");
				var content = frame.contentWindow;
				content.FCK.SetData(val);

			}else if(y == 'select' && !is_clear){ // some of these are static... so there are problems...
				
				//alert(objToString(fields[x]['select']));

if(!is_child){
	// pr("IS TOP - key("+key+") index("+record_index+") AUTOINDEX("+x+") valKey("+val+") selectIndex("+fields[x].select.select_index+") "+objToString(fields[x]));
}

				if(fields[x]['select'].autodds && typeof(fields[x]['select']['autodds'][0]) != 'undefined' && fields[x]['select']['autodds'][0] == 'AC'){
					widget.childNodes[0].value = val[0];
					widget.childNodes[1].value = val[1];
					// alert("AUTO DROP DOWN FOUND val("+val+") "+widget.innerHTML);						

					if(swap_id){
						widget.id = swap_id;
					}

					continue;
				}

//if(is_child){
//	pr("IS CHILD - key("+key+") index("+record_index+") AUTOINDEX("+x+") valKey("+val+") "+objToString(fields[x]));
//}

				var autoIn = (fields[x].select && fields[x].select.select_index)? fields[x].select.select_index: x;

				if(AUTOS[autoIn] && fields[x]['select']['static']){

					widget.innerHTML = AUTOS[x][val];

				}else if(SELCACHE[autoIn] && SELCACHE[autoIn][val]){

					widget.selectedIndex = SELCACHE[autoIn][val];

					// pr("SEL CACHE FOUND");

				}else if(AUTOS[autoIn]){

//if(!widget.options){
//	pr("NO WIDGET OPTIONS ON SELECT widget_id("+widget_id+")");
//	continue;
//}

					widget.options.length = 0;

					var selCount = 0;

					var selectedIndex = 0;

					var sel_cache = [];

					for(xx in AUTOS[autoIn]){
						if(xx == val){
							selectedIndex = selCount;
						}
						sel_cache[xx]=selCount;
						widget.options[selCount++] = new Option(AUTOS[autoIn][xx].toString(),xx);
					}
					widget.selectedIndex = selectedIndex;
					
					SELCACHE[autoIn]=sel_cache;
				}

				// widget.innerHTML = val;

				// fields[x]['select']['select_index']; Paid / Ok values...

			}else if(y == 'join' && fields[x].join[2] == 'CHKLST'){

				//	pr("CHKLST AUTO FOUND!!! x("+x+")");

				for(var xx in val){

					document.getElementById(widget_id+'-'+xx).checked = (val[xx])? 'checked': '';
				}

			}else if(y == 'join' && fields[x].join[2] == 'SELLST'){

				var autoIn = (fields[x].select && fields[x].select.select_index)? fields[x].select.select_index: x;

				pr("SELLST AUTO FOUND!!! x("+autoIn+")");

				if(AUTOS[autoIn]){

					widget.options.length = 0;
					var selCount = 0;
					var selectedIndex = 0;
					for(xx in AUTOS[autoIn]){
						if(xx == val){
							selectedIndex = selCount;
						}
						widget.options[selCount++] = new Option(AUTOS[autoIn][xx].toString(),xx);
					}
					widget.selectedIndex = selectedIndex;
				}

			}else if(y == 'image_selector'){

				setNewImage(val,prev_rec_id,is_child);

			}else if(y == 'date_selector'){

				// pr("DATE SELECTOR 1 rec_type("+rec_type+") y("+y+") widget_id("+widget_id+")");

				for(var z in val){
					var date_id = widget_id+"-"+z;
					widget = document.getElementById(date_id);
					widget.options.length = 0;
					var selCount = 0;
					var selectedIndex = 0;
					if(AUTOS[x] && AUTOS[x][z]){
						for(var xx in AUTOS[x][z]){
							if(parseInt(xx) == parseInt(val[z])){
								selectedIndex = selCount;
							}
							widget.options[selCount++] = new Option(AUTOS[x][z][xx].toString(),xx);
						}
						widget.selectedIndex = selectedIndex;
					}
				}

// 	<select class="" name="birthday|0[day]" id="birthday|0[day]">
//	<select class="" name="birthday|0[month]" id="birthday|0[month]">
//	<select class="" name="birthday|0[year]" id="birthday|0[year]">

			}else if(y == 'textarea'){

				widget.innerHTML = (is_clear)? "": val;

			}else if(y == 'boolean'){

				//	pr("BOOLEAN CHECKED ("+val+")");

				widget.checked = (!parseInt(val) || is_clear)? '':'checked';

			}else if(y == 'input'){

				//	alert("INPUT WIDGET widget_id("+widget_id+")");

				widget.value = (is_clear)? "": val;

			}else{

				pr("FOUND unknown widget("+y+") key("+key+") type("+y+") value("+val+") id("+'in-'+record_index+'-'+key+") y("+y+") obj("+objToString(fields[x])+")");

				if(y == 'join'){
					pr("DETAILS OF JOIN objToString("+objToString(fields[x].join)+")");
				}

			}

			if(swap_id){
				widget.id = swap_id;
			}
		}
	}

	if(is_child && prev_rec_id > 0 && type != 'SLIDE'){ // try and swap out the widgets...
		var d_id = 'child-'+rec_type+'-0-'+rec_id+'-ROW';
		var p_d_id = 'child-'+rec_type+'-0-'+prev_rec_id+'-ROW';

		try{
			document.getElementById(p_d_id).id = d_id;
		}catch(e){
			pr("FAILED CHILD SWAP d_id("+d_id+") p_d_id("+p_d_id+")");
		}

		var r_id = 'child-'+rec_type+'-0-'+rec_id+'-DELETE';
		var p_r_id = 'child-'+rec_type+'-0-'+prev_rec_id+'-DELETE';

		try{
			document.getElementById(p_r_id).id = r_id;		
		}catch(e){
			pr("FAILED CHILD SWAP r_id("+r_id+") p_r_id("+p_r_id+")");
		}
	}
}

// THIS NEEDS TO BE A CLEAN ALGO... I NEED TO BE ABLE TO THROW ANYTHING AT IT SERVER SIDE AND HAVE IT RETURN TO THE SERVER IN TACT...

function loadRecord(command,rec_type,rec_id,parent_id,arr,tmpl,record_map,state,autos,load_type,record_index,server_exec_time,mvcObj,child_index){

	var hook = 0;
	if(command){
		hook = clearController(command);
		try{
			FRMES[hook].caller.innerHTML = FRMES[hook].innerSTORE;
			FRMES[hook].caller.className = FRMES[hook].oldClass;
			FRMES[hook].caller.style.border = (rec_type == 'ERROR')? "1px solid #F00":"none";
			document.getElementById(FRMES[hook]['throbberId']).style.display = 'none';
		}catch(e){}
	}

	distro_bench(server_exec_time,1);

	if(rec_type == 'ERROR'){
		// WHEN THIS THROWS... THE ERROR FIELDS IF ANY SHOULD ALSO HIGHLIGHT...
		displayError(0,0,rec_id);
		return;
	}else{
		displayError(0,100,"");
	}

	// alert(tmpl);
	// alert(record_map);

	if(state == 'deleted'){
		var childTable = document.getElementById("child-"+rec_type+"-"+parent_id+"-"+rec_id+"-ROW");
		childTable.parentNode.removeChild(childTable);
		return;
	}

	if(typeof(autos) != 'undefined'){ // ---------------- THIS NEEDS A MERGE OR PUSH TO END OF STACK FUNCTION ---------------------------------------
		for(x in autos){
			if(typeof(AUTOS[x]) == 'undefined'){
				AUTOS[x] = [];
			}
			for(y in autos[x]){
				AUTOS[x][y.toString()] = autos[x][y];
			}
		}
	}

	//	alert("LOAD RECORD");
	//	alert(objToString(RECORD_MAPS));
	//	pr(record_map);
	//	pr("loadRecord() rec_type("+rec_type+") load_type("+load_type+") state("+state+") record_index("+record_index+") child_index("+child_index+") record_id("+rec_id+")");

	if(parseInt(rec_type) != rec_type){
		// pr("rec_type("+rec_type+") IS NOT NUMERIC!!! CANNOT PULL RECORD_MAP");
	}

	if(typeof(stateMaps[record_index]) == 'undefined' || typeof(stateMaps[record_index][child_index]) == 'undefined'){
		
		pr("NO STATE MAP recordIndex("+record_index+") child_index("+child_index+") state("+state+")");

		for(var x in stateMaps){
			pr("stateMap key("+x+")");
		}

		pr("END STATEMAP LOADER");

	}

	// pr("START LOADER record_index("+record_index+") child_index("+child_index+") state("+state+")");

	stateMap = stateMaps[record_index][child_index][state];

	//	IF A TEMPLATE HAS BEEN RETURNED... CACHE IT...
	//	I ALSO NEED A MAP... WHICH TRANSLATES THE DATA KEYS TO THE TEMPLATE WIDGETS...

	if(typeof(RECORD_MAPS[record_index]) == 'undefined'){
		RECORD_MAPS[record_index] = record_map;
	}

	if(	typeof(TEMPLATES[record_index]) == 'undefined' || 
		typeof(TEMPLATES[record_index][child_index]) == 'undefined' || 
		typeof(TEMPLATES[record_index][child_index][stateMap.tmpl]) == 'undefined'){
		if(typeof(TEMPLATES[record_index]) == 'undefined'){TEMPLATES[record_index]=[];}
		if(typeof(TEMPLATES[record_index][child_index]) == 'undefined'){TEMPLATES[record_index][child_index]=[];}

		if(tmpl == null){
			pr("TRIED TO LOAD NULL TEMPLATE");
		}

		TEMPLATES[record_index][child_index][stateMap.tmpl] = tmpl;

		// pr("caching template record_index("+record_index+") child_index("+child_index+") key("+stateMap.tmpl+")");

	}else{
		tmpl = TEMPLATES[record_index][child_index][stateMap.tmpl];

		// pr("loading template from cachce record_index("+record_index+") child_index("+child_index+") key("+stateMap.tmpl+")");
	}

	//	pr(stateMap.tmpl);
	//	pr(rec_id);
	//	pr(rec_type.substr(0,6));

	//	pr("rec_type=("+rec_type+")");

	if(rec_id == 'N' && rec_type != 'to_do'){
		if(typeof(NEW_RECORD_COUNTERS[rec_type]) == 'undefined'){
			try{
				NEW_RECORD_COUNTERS[rec_type] = CHILD_OBJS[rec_type]['N'];
			}catch(e){
				pr("no child_objs counters found");
				NEW_RECORD_COUNTERS[rec_type] = 0;				
			}
		}
		NEW_RECORD_COUNTERS[rec_type]++;
		rec_child_index = rec_id + NEW_RECORD_COUNTERS[rec_type];
		rec_child_name_index = rec_child_index;
	}else if(rec_type != 'to_do'){
		rec_child_index = rec_id;
		rec_child_name_index = rec_id; // ------------ THIS IS POTENTIALLY BACKWARDS
	}else{
		rec_child_index = rec_id;
		rec_child_name_index = 0; // ------------ THIS IS POTENTIALLY BACKWARDS	
	}

	// OUCH!!!!!!!

	if(load_type == 1){ // this is a call to fill the record interface...
		//alert("load_type="+load_type);
		// I want to know all the element ids... from there they all get plugged with new values...
		// alert(arr);

		var activeLang = LANGS['active'][0];
		var activeServ = LANGS['active'][1];
		var lang_serv_key = "lang-"+activeLang+"-"+activeServ;
		
		// alert(arr[lang_serv_key+'-1']);
		// alert("rec_type="+record_index+" rec_id="+rec_id);
		
		if(typeof(RECORDS[record_index][rec_id]) == 'undefined'){
			RECORDS[record_index][rec_id] = [];
			RECORDS[record_index][rec_id][lang_serv_key] = [];
		}

		var string = '';
		for(x in RECORDS[record_index][0].cam){ // THIS NEED TO EXPAND TO LOAD CRUMBS, AND WYSIWYG, AND PERMISSIONS, AND EVERYTHING...
			string = arr[lang_serv_key+'-'+x];
			document.getElementById('in-'+x).value = string;
			RECORDS[record_index][rec_id][lang_serv_key][x] = string;
		}
		return;
	}else if(load_type == 2){

		// LOADING A RECORD JS SIDE

		var prId = RECORD_ID;
		var prIn = RECORD_INDEX;
		var rId = rec_id;
		var rIn = RECORD_MAPS[record_index]['RECORD_INDEX'];

		var stage_id = 'INC-'+RECORD_INDEX+'-'+RECORD_ID;
		var content_id = 'P-'+RECORD_INDEX+'-'+RECORD_ID;

		document.getElementById(stage_id).id = 'INC-'+record_index+'-'+rec_id;
		document.getElementById(content_id).id = 'P-'+record_index+'-'+rec_id;

		RECORD_INDEX = record_index;
		RECORD_ID = rec_id;

		// THE CACHE IS NOT TRANSLATED TO BOOLEAN AND SUCH...

		// pr("call to full record load...");

		if(arr){

			loadRecords(arr); // this is caught in a cycle where it is reloading the records each time... oh well for now... but fix for later to avoid cycles...

			// pr("RECORD_INDEX("+RECORD_INDEX+") RECORD_ID("+RECORD_ID+")");

			RECORDS[RECORD_INDEX][RECORD_ID].mvcObj = mvcObj;

		}else{

			mvcObj = RECORDS[RECORD_INDEX][RECORD_ID].mvcObj;

		}

		// NOTICE THIS SWAPPING??? NOT GOOD PROBABLY

		distro_bench(server_exec_time,2);

		for(var x in RECORD_MAPS[record_index]['children']){

			var cIn = RECORD_MAPS[record_index]['children'][x]['RECORD_INDEX'];

			var showC = (RECORD_HINGE[prIn] && RECORD_HINGE[prIn][prId] && RECORD_HINGE[prIn][prId][cIn])? countReal(RECORD_HINGE[prIn][prId][cIn]): 0;

			var fillC = (RECORD_HINGE[rIn] && RECORD_HINGE[rIn][rId] && RECORD_HINGE[rIn][rId][cIn])? countReal(RECORD_HINGE[rIn][rId][cIn]): 0;

			// pr("STATE MAP x("+x+") rIn("+rIn+") cIn("+cIn+")");

			var type = stateMaps[rIn][cIn][state].type;

			var childFields = RECORD_MAPS[record_index]['children'][x];

			var prevChildChunk = (showC)? RECORD_HINGE[prIn][prId][cIn]: [];

			var currChildChunk = (fillC)? RECORD_HINGE[rIn][rId][cIn]: [];

			var totalC = countReal(currChildChunk);

			if(type == 'SLIDE'){
				document.getElementById('counter-current-'+x).innerHTML = 1;
				document.getElementById('counter-total-'+x).innerHTML = (fillC)? fillC: 1;
				fillC = 1;
				showC = (showC)? 1: 0;
			}else if(type == 'COLLAPSE'){
				document.getElementById('counter-total-'+x).innerHTML = (fillC)? ' ( '+fillC+' ) ':'';
			}

			var remC = (showC > fillC)? showC-fillC: 0;

			// alert("HINGE FOUND key("+x+") showC("+showC+") fillC("+fillC+") type("+type+") addC("+addC+") remC("+remC+")");
			
			var activeLang = LANGS['active'][0];

			for(var z = 0; z < fillC; z++){
				var cId = getKey(z,currChildChunk);
				var pcId = getKey(z,prevChildChunk);
				var clearC = (totalC > z)? 0: 1;
				var addC = (showC > z || type == 'SLIDE')? 0: 1;

				// alert("record_fill key("+x+") clearC("+clearC+") totalC("+totalC+") keyReal("+pcId+")");

				distro_bench(0,5,x+"(!"+addC+")");

				if(addC){
					var arr=RECORDS[cIn][cId][activeLang];
					loadRecord(false,'child-'+x,cId,0,arr,null,null,'new',[],0,RECORD_INDEX,0,{},cIn);
				}else{
					fill_record(type,x,childFields,cIn,cId,pcId,1,clearC);
				}
			}

			while(remC){

				var keyReal = getKey(z,prevChildChunk);

				//pr("remove_child rec_type("+x+") recC("+remC+") PLEASE NOTE THIS STILL NEEDS TO ACCOMODATE FOR MULTIPLE REMOVALS...");

				remove_child(x,0,keyReal);				
				
				remC--;
				z++;
			}
		}

		distro_bench(server_exec_time,3);

		fill_record('TOP',rec_type,RECORD_MAPS[record_index],rIn,rId,rId,0,0);

		distro_bench(server_exec_time,4);

		LOAD_ARROWS(mvcObj);

		LOAD_ELEMENTS(mvcObj);

		return;
	}

	// BOTTOM LINE - THIS ONLY FILLS CHILDREN...

	var child_key = (rec_type.substr(0,6) == 'child-')? rec_type.substr(6): rec_type;

	// pr("rec_type.substr(0,6)("+rec_type.substr(0,6)+") rec_type.substr(6)("+rec_type.substr(6)+")");

	// pr("FILLING CHILD child_index("+child_index+") record_index("+record_index+") rec_type("+rec_type+")");

	if(!parseInt(child_index)){

		// pr("no child fill template");

		rM = RECORD_MAPS[record_index]['fields'];

	}else{

		// pr("there is a child fill template");

		rM = RECORD_MAPS[record_index]['children'][child_key]['fields'];

	}

	// Still need form stamps...
	rM.recordType = {"0":"record_type","hidden":{"FN":true}};
	rM.record_id = {"0":"record_id","hidden":{"FN":true}};
	rM.parent_id = {"0":"parent_id","hidden":{"FN":true}};
	rM.form_stamp = {"0":"form_stamp","hidden":{}};
	rM.CANCL = {"0":"CANCEL","eh":{"tag":"A","event":"onclick","func":"close_record(this)","text":"Cancel"}};
	rM.SAVE = {"0":"SAVE","eh":{"tag":"A","event":"onclick","func":"save_record(this)","text":"Save"}};
	rM.DELETE = {"0":"DELETE","eh":{"tag":"A","event":"onclick","func":"delete_record(this)","text":"","className":"delRec","title":"delete"}};

	// THE PLAIN TEXT IS NOT REFRESHING AFTER AN EDIT/SAVE
	arr['record_type'] = rec_type;
	arr['parent_id'] = parent_id;
	arr['record_id'] = rec_id;
	arr['form_stamp'] = '';
	arr['CANCEL'] = rec_id;
	arr['SAVE'] = rec_id;

	// pr("load_type("+load_type+") record_id("+rec_id+") parent_id("+parent_id+")");

	// pr(tmpl);

	var str = tmpl;
	var objCache=[];

	// distro_bench(server_exec_time,5,child_key);

	c = 0;
	for(x in rM){

		var z = -1;
		for(y in rM[x]){

			z++;

			if(!z){continue;}
			if(z > 1){break;}

			var objD = document.createElement("DIV");
			var obj = null;
			var field = rM[x][y];
			var field_name = rM[x][0];
			var att_id = rec_type+"-"+parent_id+"-"+rec_id+"-"+field_name;
			var att_name = rec_type+"["+field_name+"|"+rec_child_name_index+"]";

			// please note this change... oct 4th 2011

			var val = (isset(arr,field_name) && typeof(arr[field_name]) != 'undefined')? arr[field_name]: null;

			// var val = (rec_id != 'N' && isset(arr,field_name))? arr[field_name]: null; // it might be better to set defaults for new records...


			var addLabel = false;
			var skipAppend = false;

			// pr("y("+y+") rM[x][y]("+rM[x][y]+") field_name("+field_name+") val("+val+")");

			if(y == 'input'){
				var att_id = rec_type+"-"+parent_id+"-"+rec_child_index+"-"+field_name;
				obj = fill_input(val,stateMap,att_id,att_name);
				addLabel = true;
			}else if(y == 'textarea'){
				obj = fill_textarea(val,stateMap,att_id,att_name);
				addLabel = true;
			}else if(y == 'select'){

				var att_id = rec_type+"-"+parent_id+"-"+rec_child_index+"-"+field_name;

				if(field.autodds && field.autodds[0] == 'AC'){
					att_id = field.select_index+"|"+rec_child_name_index+"|DDSinp";
				}

				att_name = rec_type+"[S|"+field_name+"|"+rec_child_name_index+"]";
				obj = fill_select(val,field,stateMap,false,att_id,att_name,rec_child_name_index,rec_type);
				addLabel = true;
			}else if(y == 'boolean'){
				obj = fill_boolean(val,stateMap,att_id,att_name);
				addLabel = true;
			}else if(y == 'static'){
				var att_id = rec_type+"-"+parent_id+"-"+rec_child_index+"-"+field_name;
				obj = fill_static(val,stateMap,att_id,att_name);
				addLabel = true;
			}else if(y == 'hidden'){
				if(field_name == 'parent_id'){
					att_name = rec_type+"["+field_name+"]";
				}
				obj = fill_hidden(val,att_id,att_name);
			}else if(y == 'eh'){
				var att_id = rec_type+"-"+parent_id+"-"+rec_child_index+"-"+field_name;
				var att_name = rec_type+"["+parent_id+"]["+field_name+"|"+rec_child_name_index+"]";
				obj = fill_eh(val,rM[x],att_id,att_name);
			}else if(y == 'image_selector'){
				str = str.replace(/{{{img_instance_id}}}/g,rec_child_name_index);
				continue;
			}else if(y == 'date_selector'){

				var label = document.createElement("SPAN");
				label.className = (y == 'boolean')? "ckchktxt":"cklabel";
				label.innerHTML = x;
				objD.appendChild(label);
				str = str.replace('{{{'+field_name+'}}}',objD.innerHTML);
			
				var objD = document.createElement("DIV");
				att_name = field_name+"|"+rec_child_name_index+"[day]";
				obj = fill_select(val,field,stateMap,"d",att_id,att_name,rec_child_name_index,rec_type);
				objD.appendChild(obj);
				str = str.replace('{{{'+field_name+'-d}}}',objD.innerHTML);

				var objD = document.createElement("DIV");
				att_name = field_name+"|"+rec_child_name_index+"[month]";
				obj = fill_select(val,field,stateMap,"m",att_id,att_name,rec_child_name_index,rec_type);
				objD.appendChild(obj);
				str = str.replace('{{{'+field_name+'-m}}}',objD.innerHTML);

				var objD = document.createElement("DIV");
				att_name = field_name+"|"+rec_child_name_index+"[year]";
				obj = fill_select(val,field,stateMap,"y",att_id,att_name,rec_child_name_index,rec_type);
				objD.appendChild(obj);
				str = str.replace('{{{'+field_name+'-y}}}',objD.innerHTML);
				skipAppend = true;
			}else{
				pr("UNKNOWN DATA TYPE:"+y+" = "+rM[x][y] +" - " +field_name);
				continue;
			}

			if(addLabel && stateMap.labels && y != 'boolean'){
				var label = document.createElement("SPAN");
				label.className = "cklabel";
				label.innerHTML = x;
				objD.appendChild(label);
			}
			
			if(!skipAppend){

				objCache[c] = obj.staticFill;
				objD.appendChild(obj);
				
				if(addLabel && stateMap.labels && y == 'boolean'){
					var label = document.createElement("SPAN");
					label.className = "ckchktxt";
					label.innerHTML = x;
					objD.appendChild(label);					
				}

				str = str.replace('{{{'+field_name+'}}}',objD.innerHTML);
			}

			var tabL = TABIND[0].length;
			TABIND[0][tabL] = att_id;
			TABIND[1][att_id] = tabL;

		}
		c++;
	}

	str = str.replace(/{{{id}}}/gi,rec_child_index);
	str = str.replace(/{{{parent_record_id}}}/gi,parent_id);

	str = str.replace(/{{{\w+}}}/gi,""); // KLUDGE

	// alert("rec_id="+rec_id);
	// alert("state="+state);
	// alert("rec_type="+rec_type);
	
	// edits are not updating...
	// new records are not closing...

	if(state == 'savedNew'){
		// alert("savedNew= "+rec_type+"-"+parent_id+"-"+rec_child_index+"-CANCEL");
		// to_do-0-107-CANCEL
		var addBlock = append_child_record(parent_id,rec_type,rec_id);
		var lastNewId = NEW_RECORD_COUNTERS[rec_type];// --------------------------------------- THIS WILL CAUSE PROBLEMS WHEN MULTIPLE ITEMS ARE OPEN...
		var to_do = document.getElementById(rec_type+"-"+parent_id+"-N-CANCEL");
		close_record(to_do);
	}else if(state == 'savedEdit'){
		//	alert("savedEdit= "+rec_type+"-"+parent_id+"-"+rec_child_index+"-CANCEL");
		var to_do = document.getElementById(rec_type+"-"+parent_id+"-"+rec_child_index+"-CANCEL");
		close_record(to_do);
		//	alert('child-'+rec_type+'-'+parent_id+'-'+rec_id+'-ROW');
		var addBlock = document.getElementById('child-'+rec_type+'-'+parent_id+'-'+rec_id+'-ROW');
		addBlock.childNodes[2].childNodes[0].childNodes[0].innerHTML = objCache[1];
		addBlock.childNodes[3].innerHTML = objCache[0];
		return;
	}else if(state == 'edit'){ // This the items are already preloaded with rec_ids and rec_types...
		//	alert(rec_type+'-'+rec_id+'-ADD');
		var addBlock = document.getElementById(rec_type+'-'+rec_id+'-ADD');
		if(rec_type == 'to_do' && rec_id != 'N'){
			block = addBlock.parentNode;
			block.childNodes[2].style.display = "none";
			block.childNodes[3].style.display = "none";
			block.childNodes[4].style.display = "none";
			block.childNodes[5].style.display = "none";
		}
	}else if(state == 'new'){
		//	alert(rec_type+'-Table-'+parent_id);
		var block = document.getElementById(rec_type+'-Table-'+parent_id);
		var l = block.childNodes.length;
		if(rec_type == 'to_do'){
			block.childNodes[(l-2)].style.display = 'none';
			var addBlock = block.childNodes[(l-1)];
		}else{
			var addBlock = document.createElement("DIV");
			addBlock.setAttribute("id",rec_type+"-"+parent_id+"-"+rec_child_index+"-ROW");
			block.appendChild(addBlock);
		}
	}else{
		alert("COULD NOT CATCH STATE");
	}

	//alert(state);
	addBlock.innerHTML = str;
	addBlock.style.display = 'block';
	if(rec_type == 'to_do'){
		addBlock.childNodes[1].focus();
	}
	//alert("FIN");
	// make a makeshift map...
}

function append_child_record(parent_id,rec_type,rec_id){ // this loads a placeholder for an editing template...
	var todoTable = document.getElementById(rec_type+'-Table-'+parent_id);
	var l = todoTable.childNodes.length;
	var addBlock = document.createElement("DIV");
	addBlock.className = "toDoRow";
	addBlock.id = "child-"+rec_type+"-"+parent_id+"-"+rec_id+"-ROW";
	addBlock.onmouseover = over_to_do_item;
	addBlock.onmouseout = out_to_do_item;
	var toDoBlock = todoTable.childNodes[(l-1)];
	toDoBlock.childNodes[1].value = "";
	toDoBlock.childNodes[(toDoBlock.childNodes.length-1)].className = "";
	todoTable.insertBefore(addBlock,todoTable.childNodes[(l-2)]);
	return addBlock;
}

function close_record(obj){ // THIS IS ATTACHED TO THE ANCHOR... NOT A GOOD IDEA...
	var split = obj.id.split("-");
	var rec_type = split[0];
	var parent_id = split[1];
	var rec_id = split[2];
	var block = obj.parentNode.parentNode.parentNode;
	var block = document.getElementById('child-'+rec_type+'-'+parent_id+'-'+rec_id+'-ROW');

	var l = block.childNodes.length;
	if(rec_id == 'N'){
		block.style.display = 'block';
		var addItemBlock = document.getElementById('to_do-'+parent_id+'-N-ADD');
		addItemBlock.style.display = 'none';
	}else{
		block.childNodes[(l-1)].childNodes[1].value = '';
		block.childNodes[(l-1)].style.display = 'none';
		block.childNodes[(l-2)].style.display = 'block';
		block.childNodes[(l-3)].style.display = 'block';
		block.childNodes[(l-4)].style.display = 'block';
		block.childNodes[(l-5)].style.display = 'block';
	}
	return false;
}

function remove_child(key,pid,rec_id){
	//	child-order_items-0-18718-ROW
	//	Delete Record:child,options,0,N1,DELETE
	//	alert("Delete Record - "+key+"-"+pid+"-"+rec_id+"-ROW");
	var id = "child-"+key+"-"+pid+"-"+rec_id+"-ROW";
	var childTable = document.getElementById(id);
	if(childTable){
		childTable.parentNode.removeChild(childTable);
	}else{
		pr("childTable was NULL element_id("+id+")");
	}
	//	alert("FIN");
	return;
}

function delete_record(obj){ // the delete is wrapped in a span // THIS IS MESSED UP BECAUSE THE "-" vs "|" divider is wrong. IT BACK TRACKS FROM RIGHT
	var split = obj.parentNode.id.split("-");
	var l = split.length;
	var split3 = split[l-2];
	var split2 = split[l-3];
	var split1 = split[l-4];
	var split0 = split[l-5];
	//alert("Delete Record:" + split[3] + " childKey"+split3);
	//alert("Delete Record (Parent Node):" + obj.parentNode.id);
	//alert(RECORD_INDEX);
	if(split3.substr(0,1) == "N" || split3.substr(0,1) == ""){
		return remove_child(split1,split2,split3);
	}
	var command = "Del|"+split3+"|"+split1+"|"+split2+"|D|"+RECORD_INDEX+"|"+RECORD_ID;
	var x = requestController(command,0,false,false);
	var obj = obj.parentNode;
	FRMES[x].innerSTORE = obj.innerHTML;
	FRMES[x].caller = obj;
	FRMES[x].oldClass = obj.className;
	obj.className = obj.className+"X";
	obj.blur();
}

function mapit_record(obj){
	var split = obj.parentNode.parentNode.parentNode.parentNode.parentNode.id.split("-");	
	var l = split.length;
	var split3 = split[l-2];
	var split2 = split[l-3];
	var split1 = split[l-4];
	var split0 = split[l-5];
	var command = "Map|"+split3+"|"+split1+"|"+split2+"|D|"+RECORD_INDEX+"|"+RECORD_ID;
	var fieldMap = RECORD_MAPS[RECORD_INDEX]['children'][split1]['fields'];

	var str = '';
	for(var x in fieldMap){
		var key = fieldMap[x][0];
		var id = "child-"+split1+"-0-"+split3+"-"+key;
		var field = document.getElementById(id);
		if(typeof(fieldMap[x]['input']) != 'undefined'){
			str += key+"> "+field.value.replace('>', ' ')+">>";
		}else if(typeof(fieldMap[x]['select']) != 'undefined'){
			str += key+"> "+field.options[field.selectedIndex].text.replace('>', ' ')+">>";
		}else if(typeof(fieldMap[x]['static']) != 'undefined'){
			str += key+"> "+field.innerHTML.replace('>', ' ')+">>";
		}
	}
	command += '|' + encodeURI(str);

	var x = requestController(command,0,false,false);
	obj.blur();
	return false;
}

function save_record(obj){ // THESE NEED TO CALL ITEMS BASED ON IDS... NOT BASED ON LOCATION...
	var block = obj.parentNode.parentNode;
	
	//alert(block.id);
	
	var sect = 'erp';
	var pane = 'to_do_lists-project_to_do_lists';
	var textarea = block.childNodes[1];
	var select = block.childNodes[3];
	var checkbox = block.childNodes[4];
	var record_id = block.childNodes[5];
	var record_type = block.childNodes[6];
	var parent_id = block.childNodes[7];

	//alert(parent_id.id);
	//alert(block.innerHTML);

	var l = block.childNodes.length;
	var linkBar = block.childNodes[(l-1)];
	if(textarea.value.length < 6){textarea.focus();return;}
	linkBar.className = "add_item_send_active";
	element_whitelist=[];
	element_whitelist[0] = textarea.id;
	element_whitelist[1] = select.id;
	element_whitelist[2] = checkbox.id;
	element_whitelist[3] = record_id.id;
	element_whitelist[4] = record_type.id;
	element_whitelist[5] = parent_id.id;
	savePane(sect,pane,'RECORD',element_whitelist);
	return false;
}

function fill_eh(val,map,att_id,att_name){

	var obj = document.createElement(map.eh.tag);
	var text = document.createTextNode(map.eh.text);
	if(map.eh.func && map.eh.event){
		obj.setAttribute(map.eh.event,map.eh.func);
	}
	obj.appendChild(text);

	if(map.eh.className){
		var wrapSpan = document.createElement("SPAN");
		wrapSpan.className = map.eh.className;
		wrapSpan.title = map.eh.title;
		wrapSpan.appendChild(obj);
		obj = wrapSpan;
	}

	obj.setAttribute("id",att_id);
	obj.setAttribute("name",att_name);

	return obj;
}

function fill_input(val,stateMap,att_id,att_name){

	if(stateMap.plainText){
		var ele = document.createElement("SPAN");
		var text = document.createTextNode(val);
		ele.appendChild(text);
	}else{
		var ele = document.createElement("INPUT");
		var value = (val !== null)?val:'';
		var className = "ckinp";
		ele.setAttribute("value",value);
		ele.setAttribute("class",className);
	}

	ele.setAttribute("id",att_id);
	ele.setAttribute("name",att_name);

	return ele;
}

function fill_textarea(val,state,att_id,att_name){

	var type = (stateMap.plainText)? "SPAN": "TEXTAREA";
	var ele = document.createElement(type);
	var text = document.createTextNode(val);

	ele.appendChild(text);
	ele.staticFill = val;
	ele.setAttribute("id",att_id);
	ele.setAttribute("name",att_name);

	return ele;
}

// THERE IS A WRITE SELECT AND A FILL SELECT OPTION... THEY NEED TO MERGE OVER TIME... SCRIPT_LISTS vs AUTOS!!!!

function fill_select(val,field,state,date_multi_key,att_id,att_name,rec_child_name_index,rec_type){

	//alert("select index="+field.select_index);
	//alert(field.auto);
	//alert(AUTOS);
	//alert(field.autodds);

	if(field.autodds && field.autodds[0] == 'AC'){

		//	alert("AUTO COMPLETE FOUND select_index = "+field.select_index+" rec_child_name_index="+ rec_child_name_index);

		var select = document.createElement("SPAN");
		var div1 = document.createElement("DIV");
		var className = (field.autodds.className)? field.autodds.className: "aCWidget";
		div1.setAttribute("class",className);

		var div2 = document.createElement("DIV");
		div2.setAttribute("id",field.select_index+"|"+rec_child_name_index+"|DDS");

		var inp1 = document.createElement("INPUT");
		inp1.setAttribute("type","hidden");
		inp1.setAttribute("id",field.select_index+"|"+rec_child_name_index+"|asval");
		inp1.setAttribute("name",att_name);

		var inp2 = document.createElement("INPUT");
		inp2.setAttribute("id",att_id);

		// what it needs to be - child-upcs[S|partner_name|00000000000000000065]
		// alert("new="+rec_type+"[S|"+field.auto_key+"|"+rec_child_name_index+"]");

		inp2.setAttribute("name",rec_type+"[S|"+field.auto_key+"|"+rec_child_name_index+"]");
		inp2.setAttribute("type","text");
		inp2.setAttribute("autocomplete","off");
		inp2.setAttribute("class","ckinp");

		inp2.setAttribute("onkeyup","keyup(this);");
		inp2.setAttribute("onkeydown","return keydown(event,1,this);");
		inp2.setAttribute("onfocus","dofocusDDSinp(this);");
		inp2.setAttribute("onblur","doblurDDSinp(this);");
		// for ie
		inp2.onkeyup = function(){keyup();}
		inp2.onkeydown = function(e){return keydown(e,1,this);}
		inp2.onfocus = function(){dofocusDDSinp();}
		inp2.onblur = function(){doblurDDSinp();}

		div1.appendChild(inp1);
		div1.appendChild(inp2);

		select.appendChild(div1);
		select.appendChild(div2);

		STACKS['AUTODDS'][att_id] = (typeof(field.autodds.FUNC) != 'undefined')? parseInt(field.autodds.FUNC): 0;

		return select;

	}else if(typeof(AUTOS[field.select_index]) != 'undefined'){
		var l = AUTOS[field.select_index].length;
		var select = document.createElement("SELECT");
		if(typeof(field.is_multi) != 'undefined' && field.is_multi > 1){
			select.setAttribute("multiple","multiple");
			select.setAttribute("size",field.is_multi);

			att_name += "[]";

		}
		var z=0;

		if(!date_multi_key){
			for(x in AUTOS[field.select_index]){
				var opt = document.createElement("OPTION");
				var selval = (x.substr(0,1) == 0)? parseInt(x,10): x;
				select.options[z++] = new Option(AUTOS[field.select_index][x].toString(),selval);
			}
		}else if(typeof(AUTOS[field.select_index][date_multi_key]) != 'undefined'){
			for(x in AUTOS[field.select_index][date_multi_key]){
				var opt = document.createElement("OPTION");
				var selval = (x.substr(0,1) == 0)? parseInt(x,10): x;
				select.options[z++] = new Option(AUTOS[field.select_index][date_multi_key][x].toString(),selval);
			}		
		}
		//AUTOS[field.select_index] = select.cloneNode(true);
	}else{
		pr("AUTOS UNDEFINED field.select_index("+field.select_index+")");
		//var select = AUTOS[field.select_index].cloneNode(true);
	}

	//alert("FIN val="+val);

	if(val){
		var l = select.options.length;
		for(var x=0;x<l;x++){
			if(select.options[x].value == val){
				select.selectedIndex = x;
				select.options[x].setAttribute("selected","selected");
				select.staticFill = select.options[x].text;
				break;
			}
		}
	}

	if(stateMap.plainText){
		var span = document.createElement("SPAN");
		var val = select.options[select.selectedIndex].text;
		var text = document.createTextNode(val);
		span.appendChild(text);
		span.staticFill = val;
		span.setAttribute("id",att_id);
		span.setAttribute("name",att_name);
		return span;
	}

	select.setAttribute("id",att_id);
	select.setAttribute("name",att_name);

	return select;
}

function fill_boolean(val,state,att_id,att_name){

	if(stateMap.plainText){
		var obj = document.createElement("SPAN");
		var text = document.createTextNode(val);
		obj.appendChild(text);
	}else{
		var obj = document.createElement("INPUT");
		obj.setAttribute("type","checkbox");
		if(val > 0){
			obj.setAttribute("checked","checked");
		}
	}

	obj.setAttribute("id",att_id);
	obj.setAttribute("name",att_name);

	return obj;
}

function fill_hidden(val,att_id,att_name){
	var obj = document.createElement("INPUT");
	obj.setAttribute("type","hidden");
	obj.value = val;
	obj.setAttribute("id",att_id);
	obj.setAttribute("name",att_name);
	return obj;
}

function fill_static(val,stateMap,att_id,att_name){

	var obj = document.createElement("DIV");

	obj.innerHTML = val;
	obj.setAttribute("id",att_id);
	obj.setAttribute("name",att_name);

	return obj;
}

function validate_widget(obj,type){
	if(type == 1){ // number
		var val = obj.value;
		var parse = parseFloat(val);
		obj.style.backgroundColor = (val.length && parse != val)? "#F00":null;
	}
}

function adjustTextarea(textarea, collapsed) {
	var lines = textarea.value.split("\n");
	var count = lines.length;
	var l = lines.length;
	for(x=1;x < l;x++){
		count += parseInt(lines[x].length / 70);
	}
	var rows = parseInt(collapsed / 20);
	if (count > rows) {textarea.style.height = (collapsed * 2) + 'px';}
	if (count <= rows) {textarea.style.height = collapsed + 'px';}
}

function fileStat(mode,count,filesize){
	if(mode == 'FIN'){
		alert('FILE FINISHED UPLOADING=' + mode);
	}else if(mode == 'FILESTAT'){
		//alert("THIS IS A REPORT FROM THE FILE CHECKER... filesize="+filesize);
		var listSize = document.getElementById('listSize'+count);
		listSize.innerHTML = filesize;
		var command = "FILECHECK="+count;
		clearController(command);
		//setTimeout("xhReq=new XMLHttpRequest();xhReq.open('GET','index.php?trans="+command+"',false);xhReq.send(null);alert(xhReq.responseText)",2000);
		setTimeout("requestController('"+command+"')",2000);
	}
	return false;
}

function onFileRemove(obj){
	var par = obj.parentNode;
	var keyArr = par.id.split("");
	var ind = keyArr[(keyArr.length-1)];
	var upInp = document.getElementById("uploader"+ind);
	upInp.parentNode.removeChild(upInp);
	par.parentNode.removeChild(par);
}

function onFileSelect(sect,pane,mode,selectorObj,fileList,fileInputs){

	var fileNo = FILES_C;
	var list = document.getElementById(fileList);
	var div = document.createElement("DIV");
	div.setAttribute('id','listFile'+fileNo);
	div.setAttribute('class','listFileRow');
	var arr = selectorObj.value.split(".");
	var ext = arr[arr.length-1];
	var mime = MIMES['default'];
	var l = MIMES['mimes'].length;
	for(x=0;x<l;x++){
		if(MIMES['mimes'][x] == ext){
			mime = MIMES['mimes'][x];
			x = l;
		}
	}
	div.setAttribute('style','background:url('+MIMES["path"]+'32/'+mime+'.png) no-repeat;');
	list.appendChild(div);
	var a = document.createElement("A");
	a.setAttribute('onclick',"onFileRemove(this);");
	var span = document.createElement("span");
	div.appendChild(span);
	div.appendChild(a);
	span.innerHTML = selectorObj.value;
	a.innerHTML = 'remove';

	var div = document.createElement("DIV");
	div.setAttribute('id','listSize'+fileNo);
	div.setAttribute('class','listSizeRow');
	list.appendChild(div);	
	
	selectorObj.setAttribute('style','position:absolute;left:-500px;top:0px;');

	FILES_C++;

	// create a new file uploader...
	var holder = document.getElementById(fileInputs);
	var inp = document.createElement("INPUT");	
	inp.setAttribute('name','uploader['+FILES_C+']');
	inp.setAttribute('type','file');
	inp.setAttribute('id','uploader'+FILES_C);
	inp.setAttribute('onchange',"onFileSelect('erp','dashboard-note','FILE',this,'fileList','fileInputs')");
	holder.appendChild(inp);	

	//	setTimeout("savePane('"+sect+"','"+pane+"','"+mode+"')",500);
	//	setTimeout("requestController('FILECHECK="+FILES_C+"')",2000);

	return false;
}

function setCaretTo(obj,pos){
	if(obj.createTextRange){
		var range = obj.createTextRange();
		range.move("character", pos);
		range.select();
	}else if(obj.selectionStart){
		obj.focus();
		obj.setSelectionRange(pos, pos);
	}
}

// you obviously had this figured out at one point... use it...

function requestReceiver(command,result){
	var hook = clearController(command);
	var c = command.split("|");
	if(c[0] == "dds"){
		fill_auto(c[1],c[2],result,c[3]);
	}
 	return;
}

// this fills the div with the select information

function isset(arr,key){
	return (arr[key] !== 'undefined')? 1: 0;
}

function dofocus(obj){
	var obj = (typeof(obj) != 'undefined')? obj: this;
	var cName = obj.className;
	var l = cName.length;
	obj.className = (cName.substr((l-1)) == 'B')? cName:cName+'B';
	if(obj.className == 'cknuminpCB'){
		BLUR_CACHE[obj.name] = obj.value;
		obj.value = '';
	}
}

function doblur(obj){
	var obj = (typeof(obj) != 'undefined')? obj: this;
	c = obj.className;
	if(obj.className == 'f_errB'){
		obj.className = c.substr(0,(c.length-1))+'C';
	}else{
		obj.className = c.substr(0,(c.length-1));
		if(obj.className == 'cknuminpC' && obj.value == ''){
			obj.value = BLUR_CACHE[obj.name];
		}
	}
}

function initAnchor(){
	var hrf = window.location.toString();
	var ind = hrf.indexOf("#");
	if(ind != -1){
		//location.hash = hrf.substring((ind+1));
	}
}

// you need to hide the help buttons and such for open and closed states

function slideCollapsablePane(dir){
	slideController.count += (dir)? -10:10;
	if(slideController.count < 0){slideController.count = 0;}
	slideController.pane.parentNode.childNodes[1].style.height= slideController.count+'px';
	if(dir && slideController.count <= slideController.MaxCount){
		slideController.pane.parentNode.childNodes[1].style.display='none';
		clearInterval(slideController.timer);
	}else if(!dir && slideController.count >= slideController.MaxCount){
		clearInterval(slideController.timer);
	}
}

function collapsePane(obj){

	if(obj.parentNode.childNodes[1].style.display=='none'){
		obj.parentNode.childNodes[1].style.display='';
		obj.parentNode.childNodes[2].value = 0;
		if(enableSlide){
			obj.parentNode.childNodes[1].style.height='0px';
			obj.parentNode.childNodes[1].style.overflow='hidden';
			slideController.count = 0;
			slideController.MaxCount = 100;
			slideController.pane = obj;
			slideController.timer = setInterval('slideCollapsablePane(0);',1);
		}

		// THIS IS NOT FORGOTTEN ABOUT BUT IT DOES NOT TAKE A PRIORITY...
		// CALLING MULTIPLE ROWS TO EASE THE LOADING THE PROCESS AND STRAIN ON THE INTIAL RECORD LOAD...
		// WILL MOST LIKELY REQUIRE PROPER CLIENT SIDE LOADER ARRAYS FOR STORAGE AND REQUESTING...
		// LOOK FOR 'COLLAPSE' SERVER SIDE...
		//alert(obj.id);
		//rec|child-options|N|0|1|1

		var rec_type = 'child-options';
		var rec_id = '1371808375';
		var parent_id = RECORD_ID;
		var parent_rec_index = RECORD_INDEX;

		// requestRecord(this,\'child-'.$record_type.'\',\'N\',0,'.$parent_recordIndex.')
		// requestRecord(obj,rec_type,rec_id,parent_id,parent_rec_index);
		// I need to reference a script side map containing info about the rows...
		// When I send the command I need to reference a limit, 1,10 - 11,20 ect...

	}else{
		obj.parentNode.childNodes[2].value = 1;
		if(enableSlide){
			obj.parentNode.childNodes[1].style.overflow='hidden';
			slideController.count = 100;
			slideController.MaxCount = 0;
			slideController.pane = obj;
			slideController.timer = setInterval('slideCollapsablePane(1);',5);
		}else{
			obj.parentNode.childNodes[1].style.display='none';
		}
	}	
}

// When the arrows are used to populate the calendar via javascript you need to have a redirect in place.
// otherwise you'll be using the same static get str that you had in place when the page loaded.

function redirectAdminCrumb(page,mode){
	var page_only_str = (undefined!==window.page_only)? '&page_only=1': '';
	if(page=='mycal'){
		if(mode=='month'){
			document.location.href = 'index.php?page=mycal'+page_only_str;
		}else if(mode=='day'){
			var year = document.getElementById('year').value;
			var month = document.getElementById('month').value;
			var day = document.getElementById('day').value;
			//alert('index.php?page=mycal&year='+year+'&month='+month +'&day='+day+page_only_str);
			document.location.href = 'index.php?page=mycal&year='+year+'&month='+month +'&day='+day+page_only_str;
		}		
	}
	return;
}

function iNitAdmin(){

	var var_sect = document.getElementById('var_sect'); // sect and panes are one and the same...

	if(!var_sect){
		return;
	}

	PANES.i = PANES.var_sect = var_sect.value;
	PANES['containers']=[];
	PANES['containers'][0] = document.getElementById('var_wrap');
	PANES[PANES.i] = PANES['containers'][0].childNodes[0];
}

function iNitFrame(val,doc){
	PANES.var_sect = val; // sect and panes are one and the same...
	PANES.i = PANES.var_sect;
	PANES['containers']=[];
	PANES['containers'][0] = doc;
	PANES[PANES.i] = PANES['containers'][0].childNodes[0];
}

function iNitCMS(){

	if("onhashchange" in window){
		if(IS_DISTRO){
			//alert("The browser supports the hashchange event!");
		}
		window.onhashchange = fireHashChange;
	}else{
		//if(IS_DISTRO){
		//	alert("No hashchange support Setting Event Listener");
		//}
		//window.addEventListener("hashchange", fireHashChange, false);
	}

	CMS.has_local = (typeof(localStorage) != 'undefined')? 1: 0;

	if(typeof(MOD_STACK[RECORD_INDEX]) == 'undefined'){
		MOD_STACK[RECORD_INDEX] = [];
	}

	if(typeof(MOD_STACK[RECORD_INDEX][RECORD_ID]) == 'undefined'){
		MOD_STACK[RECORD_INDEX][RECORD_ID] = [];
	}

	for(x in MODS_LOADED){
		if(parseInt(x) == x){
			MOD_STACK[RECORD_INDEX][RECORD_ID][x] = [];
			for(y in MODS_LOADED[x]){
				MOD_STACK[RECORD_INDEX][RECORD_ID][x][y] = 1;
			}
		}
	}
}

function fireHashChange(){
	var h = window.location.hash.toString();
	if(h.substring(1,2) == "|"){
		var s = h.split("|");
		var obj = new Object();
		obj.blur = new Function();
		var path = 0; // TO DO --------------------------------- PATH IS EMPTY!!!!! --------------- PATH IS EMPTY!!!!!
		var loc_key = 'RECORDS-'+RECORD_INDEX+'-'+RECORD_ID+'-'+SI+'-'+PN;
		var his_key = 'RECORDS-'+s[3]+'-'+s[4]+'-'+s[5]+'-'+s[6];
		if(loc_key != his_key){
			// alert(loc_key+" = "+his_key);
			callTransition(obj,0,s[2],s[3],s[4],s[6],path,s[5]);
		}
	}
}

function setOpacity(obj,level){
	if (obj.filters){
		obj.filters.alpha.opacity=level;
	}else if (obj.style.MozOpacity){
		obj.style.MozOpacity=level/101;
	}else{
		obj.style.opacity=level/100;	
	}
}

function fadeStage(stage_id,dir){
	var dir = parseInt(dir);
	var level = STAGES[stage_id].stageOpacity += (dir)? 10: -10;
	setOpacity(STAGES[stage_id],level);
	if((level > 0 && !dir) || (level < 100 && dir)){
		setTimeout("fadeStage('"+stage_id+"',"+dir+")",30);
	}
}

function callTransition(caller,transition,cat_id,rec_type,rec_id,pn,path,si,opt){

	if(TL.l){
		return false;
	}

	TL.l = true;
	TL.t = setTimeout('TL.l = false;',5000); // 5 sec

	CMS.startTime = new Date();

	TRANS_OPT = (parseInt(opt) == opt)? opt: 0;

	// pr("callTransition() = cat_id="+cat_id+" rec_id="+rec_id+" rec_type="+rec_type+" transition="+transition+" si=("+si+") pn="+pn);

	if(typeof(RECORDS) == 'undefined'){
		RECORDS=[];
	}

	if(typeof(RECORDS[rec_type]) == 'undefined'){
		RECORDS[rec_type]=[];
	}

	var is_search = (rec_id == 918 && rec_type == 54)? 1: 0;
	var is_mod = (rec_type == 47)? 1: 0;

	if(rec_type == RECORD_INDEX && rec_id == RECORD_ID && !is_search && !is_mod){
		//	alert(rec_type +" == "+ RECORD_INDEX +" && "+ rec_id +" == "+ RECORD_ID);
		caller.blur();
		return false;
	}

	var stage_id = 'INC-'+RECORD_INDEX+'-'+RECORD_ID;

	// pr("callTransition() stage_id="+stage_id);

	STAGES[stage_id] = document.getElementById(stage_id);
	STAGES[stage_id].transition = transition;

	if(transition == 2){ // fade
		STAGES[stage_id].stageOpacity = 100;
		STAGES[stage_id].style.display = 'block';
		fadeStage(stage_id,0);
	}

	var fs_panel_str = '';
	var flag = '';
	for(var x = 1;x < 13; x++){
		flag = (typeof(FS_PANEL[x]) != 'undefined')? '1': '0';
		fs_panel_str += flag;
		if(flag == '1' && typeof(CMS.pLD[x]) != 'undefined'){
			FS_PANEL[x] = '<div id="FSP-'+x+'">'+document.getElementById('FSP-'+x).innerHTML+'</div>';
		}
	}
	
	if(rec_type == 49){
		caller.parentNode.parentNode.parentNode.parentNode.style.backgroundColor = '';
		if(typeof(ROWSC[CMS.rowMapKey]) != 'undefined'){
			try{
				var rowObj = ROWSC[CMS.rowMapKey];
				var rRows = ROWS[rowObj.pane][rowObj.rowMapKey][rowObj.key]
				for(x in rRows){if(rRows[x] == rec_id){RCLASS[rowObj.pane][rowObj.rowMapKey][rowObj.key][x] = 1;break;}}
			}catch(e){alert('did not set RCLASS = '+e);}
		}
	}

	//	alert(objToString(FS_PANEL));

	//	There is no problem with this... these are not the droids you are looking for...

	var search_string = '';
	var is_sect = (rec_type == 54)? 1: 0;
	var is_search = (is_sect && rec_id == 918)? 1: 0;
	if(is_search){
		search_string = escape(document.getElementById('search').value);
		var sli = 1;
		var ssk = null;
		for(x in SEARCH_STACK){
			if(si == sli){
				ssk = x;
			}
			sli++;
		}
		if(ssk){
			document.getElementById('search').value = unescape(ssk);
		}else if(!pn){
			SEARCH_STACK[search_string] = si = sli;
		}else if(typeof(SEARCH_STACK[search_string]) != 'undefined'){
			si = SEARCH_STACK[search_string];
		}
	}else if(is_sect && cat_id){
		// pr("callTransition() IS_SECT stage_id("+stage_id+") cat_id("+cat_id+")");
		pn = cat_id;
	}

	var page_only = (top.location.href.indexOf('page_only=1') > 0)? 1: 0;
	var command = 'rec|'+rec_type+"|"+rec_id+"|"+cat_id+"|A|"+RECORD_INDEX+"|"+RECORD_ID+'|'+page_only+'|'+search_string+'|'+fs_panel_str+'|'+pn+'|'+path+"|"+si+"|"+opt;

	var loc_key = 'RECORDS-'+rec_type+'-'+rec_id+'-'+si+'-'+pn;
	var loadStore = 0;

	if(CMS.has_local){
		localStorage.clear();
	}

	//	alert("HOWDY rec_type=("+rec_type+") rec_id("+rec_id+") si("+si+") pn("+pn+")");

	if(typeof(RECORDS[rec_type][rec_id]) == 'undefined' || typeof(RECORDS[rec_type][rec_id][si]) == 'undefined' || typeof(RECORDS[rec_type][rec_id][si][pn]) == 'undefined'){
		if(typeof(RECORDS[rec_type][rec_id]) == 'undefined'){RECORDS[rec_type][rec_id]=[];}
		if(typeof(RECORDS[rec_type][rec_id][si]) == 'undefined'){RECORDS[rec_type][rec_id][si]=[];}
		if(typeof(RECORDS[rec_type][rec_id][si][pn]) == 'undefined'){RECORDS[rec_type][rec_id][si][pn]=[];}
	}else if(CMS.use_local && localStorage.getItem(loc_key) != null){
		var arr = JSON.parse(localStorage.getItem(loc_key));
		if(CMS.timestamp < arr[0][12]){
			loadStore = 1;
		}
	}else if(typeof(RECORDS[rec_type][rec_id][si][pn]) != 'undefined'){
		var arr = RECORDS[rec_type][rec_id][si][pn];
		loadStore = 1;
		//	alert("rec_type="+rec_type+" rec_id="+rec_id);
	}

	if(loadStore){
		arr[0][0] = RECORD_INDEX;
		arr[0][1] = RECORD_ID;
		arr[0][2] = rec_type;
		arr[0][3] = rec_id;
		arr[1][stage_id] = arr[1][arr[0][6]];
		if(stage_id != arr[0][6]){
			delete arr[1][arr[0][6]];
		}
		delete arr[3][arr[0][6]];
		arr[3][stage_id] = 'INC-' + rec_type + '-' + rec_id;
		arr[0][6] = stage_id;
		loadTransition(command,arr);
		var logC = 'log|'+RECORD_INDEX+'|'+RECORD_ID;
		var RC = requestController(logC,0,0,1,0,null);
		// var RC = requestController(logC,null,false,false,false,0);
	}else{
		var sendSaller = (1==2)? caller: 0;
		// alert("command="+command);
		var RC = requestController(command,null,false,false,false,sendSaller);

		resetPagePos(CMS.topPos,0,rec_type);

	}

	try{
		caller.blur(); // this causes the object class to disappear.
	}catch(e){}

	return false;
}

function setSidePanelHighlight(x,RECORD_ID,RECORD_INDEX){
	if(x==2){
		return;
	}
	var key = (x==8)? 'P'+x+'-'+RECORD_INDEX+'-'+RECORD_ID:'P'+x+'-'+RECORD_ID;
	//alert(key);
	var a = document.getElementById(key);
	if(CMS.panelHighlightKey){
		var b = document.getElementById(CMS.panelHighlightKey);
		if(b){
			b.className = "FSli1";
		}
	}
	if(a){
		a.className = "FSliA1";
		CMS.panelHighlightKey = key;
		a.parentNode.style.display = 'block';
	}
	// alert(a.className);
	// alert(key);
}

function in_array(arr,val){
	for(x in arr){
		if(arr[x] == val){
			return 1;
		}
	}
	return 0;
}

function setNavClasses(NavKeys,rID,rIN,p1,p2){

	var p = PATH_TO_ROOT[rIN][rID];

	for(x in p){
		for(y in NavKeys){
			try{
				var id1 = "T-"+y+"-"+rIN+"-"+p[x];
				var id2 = "linkCon-"+p[x];
				var tab = document.getElementById(id1);
				var tabC = NavKeys[y];
				for(z in tabC){
					if(tab.className == tabC[z][p1]){
						tab.className = tabC[z][p2];
						document.getElementById(id2).style.display = (p2)? "block":"none";
						break;
					}
				}
			}catch(e){}
		}
	}
}

function setNav(cat_id,tabID,new_path_to_root,recId,recIn){

	var split = TAB_INDEX.split("-");

	var tabIDc = split[2];

	if(typeof(PATH_TO_ROOT[3]) == 'undefined'){
		PATH_TO_ROOT[3] = [];
	}

	for(x in new_path_to_root[3]){
		PATH_TO_ROOT[3][x] = new_path_to_root[3][x];
	}

	var NavKeys = [];

	var z = 0;

	for(x in MODS_LOADED){
		if(x.substring(0,3) == "NAV"){
			NavKeys[x.substring(3,4)] = MODS_LOADED[x].tabClasses;
		}
	}

	setNavClasses(NavKeys,tabIDc,3,1,0);

	setNavClasses(NavKeys,tabID,3,0,1);

	try{
		document.getElementById('navC0').style.display = ((RECORD_INDEX == 54 && RECORD_ID == 918))? 'none': 'block';
	}catch(e){}
}

function distro_bench(server_exec_time,num,txt){

	try{
		if(!IS_DISTRO){return;}
	
		var now = new Date();
	
		var IDnum = (num > 1)? 2: 1;
	
		var dash = document.getElementById('clientLoadTime'+IDnum);
		var exec_time = (((Math.floor(now)) - (Math.floor(CMS.startTime))) / 1000);
	
		if(num > 1){
			if(num == 2){
				var t1 = " T"+num+": " + exec_time + "<br>";
			}else{
				var txt = (typeof(txt) != 'undefined')? txt: num;
				var t1 = dash.innerHTML + " T"+txt+": " + exec_time + "<br>";
			}
			dash.innerHTML = t1;
			return;
		}
	
		var t1 = "Client Load Time: " + exec_time;
		var t2 = "";
		if(server_exec_time){
			t2 = " Server Load Time: " + server_exec_time + " (" + Math.floor((server_exec_time/exec_time) * 100) + "%)";
		}
		dash.innerHTML = t1 +"<br>"+ t2;
		dash.style.backgroundColor = (server_exec_time && server_exec_time > 1)? "#ff0000":null;
	
		var dash = document.getElementById('dashboard_message');
		var exec_time = (((Math.floor(now)) - (Math.floor(CMS.startTime))) / 1000);
		var t1 = "Client Load Time: " + exec_time;
		var t2 = "";		
		if(server_exec_time){
			t2 = " Server Load Time: " + server_exec_time + " (" + Math.floor((server_exec_time/exec_time) * 100) + "%)";
		}
		dash.innerHTML = t1 + t2;
		dash.style.backgroundColor = (server_exec_time && server_exec_time > 1)? "#ff0000":null;
	}catch(e){}
}

// When the pane loads... I store the section in the container... and I associate the container keys with the pane loaded...
// When it's a second time... the check is made for the container piece...
// Requests for containers DO NOT have to be sent seperately with each page request...
// rec|54|905|0|A|54|904|1| 

function loadTransition(command,arr,server_exec_time,INLINE_SCRIPTS){

	clearTimeout(TL.t);

	distro_bench(server_exec_time,1);

	var page_only = (top.location.href.indexOf('page_only=1') > 0)? 1: 0;

	clearController(command);

	var caller_record_index = arr[0][0];
	var caller_record_id = arr[0][1];

	RECORD_INDEX = arr[0][2];
	RECORD_ID = arr[0][3];
	PN = arr[0][20];
	SI = arr[0][23];

	if(typeof(RECORDS[RECORD_INDEX]) == 'undefined'){ // sometimes there is a redirect server side... so... 
		RECORDS[RECORD_INDEX]=[];
		if(typeof(RECORDS[RECORD_INDEX][RECORD_ID]) == 'undefined'){
			RECORDS[RECORD_INDEX][RECORD_ID]=[];
			if(typeof(RECORDS[RECORD_INDEX][RECORD_ID][SI]) == 'undefined'){
				RECORDS[RECORD_INDEX][RECORD_ID][SI]=[];
				if(typeof(RECORDS[RECORD_INDEX][RECORD_ID][SI][PN]) == 'undefined'){
					RECORDS[RECORD_INDEX][RECORD_ID][SI][PN]=[];
				}
			}
		}
	}

	RECORDS[RECORD_INDEX][RECORD_ID][SI][PN] = arr;

	// ##################### TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO 
	// ##################### TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO 
	// ##################### TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO 
	// ##################### TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO 
	// ##################### TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO TO DO 
	
	// I ALSO NEED TO GET THE NAV STRUCTS IN HERE... THEY NEED TO COME IN THROUGH THE MODS???
	// SECT_ID = 0; 

	var ex = command.split("|");
	var cat_id = ex[3];
	var tabID = ex[2];
	setNav(cat_id,tabID,arr[0][19],RECORD_INDEX,RECORD_ID);

	try{
		top.document.title = arr[0][7];
	}catch(e){
		pr("FAILED TO LOAD DOCUMENT TITLE="+arr[0][7]+" ERROR="+e);
	}

	try{

		//	pr("GET TAB 1("+TAB_INDEX+")");

		if(TAB_INDEX != 'T-54-918'){
			var tab = document.getElementById(TAB_INDEX);
			if(tab){
				tab.className = arr[0][4][1];
			}
		}

//		pr(TAB_INDEX+"("+TAB_INDEX+") arr[0][4]("+arr[0][4]+") arr[0][5]("+arr[0][5]+")");

		TAB_INDEX = arr[0][5];

		//	pr("GET TAB 2("+TAB_INDEX+")");

		if(TAB_INDEX != 'T-54-918'){
			var tab = document.getElementById(TAB_INDEX);
			if(tab){
				tab.className = arr[0][4][0];
			}
		}

	}catch(e){
		pr("FAILED TO LOAD TAB_INDEX="+TAB_INDEX+" ERROR="+e);
	}

//	for(x in arr[2]){
//		try{
//			alert("Change id="+x+" to Class="+arr[2][x]);
//			document.getElementById(x).className = arr[2][x];
//		}catch(e){
//			pr("FAILED TO Change Class="+x+" ERROR="+e);
//		}
//	}

//	try{
//		document.getElementById(TAB_INDEX).className = arr[0][4];
//		PATH_TO_ROOT = arr[0][19];
//	}catch(e){
//		pr("FAILED TO LOAD PATH_TO_ROOT="+PATH_TO_ROOT+" ERROR="+e);
//	}

	try{
		if(typeof(arr[0][8]) != 'undefined'){
			document.getElementById(ICON_ID).id = arr[0][8];
			ICON_ID = arr[0][8];
		}
	}catch(e){
		pr("FAILED TO LOAD ICON_ID="+ICON_ID+" arr[0][8]="+arr[0][8]+" ERROR="+e);
	}

	// I may need to pull the panel before each new request...
	// At the very least... the first panel sent out needs to be stored in pLD...

	try{
		var fsPanelStr = '';
		var p1 = 0;
		var p2 = 0;
		var pLD = [];
		if(typeof(arr[0][9]) != 'undefined' && page_only){
			for(x in arr[0][9]){
				if(typeof(FS_PANEL[x]) == 'undefined'){
					FS_PANEL[x] = arr[0][9][x];
				}
				fsPanelStr += FS_PANEL[x];
				pLD[x] = 1;
			}
			CMS.pLD = pLD;
			document.getElementById('FS_PANEL').innerHTML = fsPanelStr;
			for(x in CMS.pLD){
				setSidePanelHighlight(x,RECORD_ID,RECORD_INDEX);
			}
		}
	}catch(e){
		pr("FAILED TO LOAD FS_PANEL ERROR (9)="+e);
	}

	try{
		if(typeof(arr[0][10]) != 'undefined'){
			for(x in arr[0][10]){
				if(typeof(CMS.CSS[x]) == 'undefined'){
					//alert("loadInclude("+arr[0][10][x]+") x = "+x);
					loadInclude(arr[0][10][x],x);
					CMS.CSS[x] = true;
				}
			}
		}
	}catch(e){
		pr("FAILED TO LOAD FS_PANEL ERROR (10) ="+e);
	}

	LOAD_ARROWS(arr);

	stage_id = 'INC-'+caller_record_index+'-'+caller_record_id;
	var stage = STAGES[stage_id];

	if(stage.transition == 2){
		if(stage.stageOpacity > 0){
			stage.arr = arr;
			setTimeout("loadTransition('"+command+"',STAGES['"+stage_id+"'].arr)",100);
			return;
		}else{
			fadeStage(stage_id,1);
		}
	}

	resetPagePos(CMS.topPos,1,RECORD_INDEX);

	try{
		var content = arr[1][arr[0][6]];
		for(x in arr[0][18]){
			// check to see if this item is already in cache...
			if(arr[0][18][x] !== null){
				HELP_STACKS[x] = arr[0][18][x]; // SO THIS IS OVERKILL AT THE MOMENT... BUT IT DOES SERVE THE PURPOSE OF KEEPING ITEMS OUT OF CACHE
			}
			content = content.replace("###"+x+"###",HELP_STACKS[x]);
			arr[0][18][x] = null;
		}
		if(RECORD_INDEX == 47){
			document.getElementById("mMCPID"+RECORD_ID).innerHTML = content;
		}else{
			document.getElementById(arr[0][6]).innerHTML = content;		
		}
	}catch(e){
		pr("FAILED TO CACHE HELP="+x+" ERROR="+x);
	}

	LOAD_ELEMENTS(arr);

	for(x in arr[3]){
		try{

			// alert("CHECKING ID("+x+") = "+arr[3][x]);

			document.getElementById(x).id = arr[3][x];

		}catch(e){

			pr("FAILED TO Change ID1("+x+")="+arr[3][x]+" ERROR="+e);

		}
	}

	try{

		var content_id = 'P-'+caller_record_index+'-'+caller_record_id;

		//	pr("CHECKING ID("+content_id+") = "+arr[5]);

		document.getElementById(content_id).id = arr[5];

	}catch(e){

		pr("FAILED TO Change ID2("+content_id+")="+arr[5]+" ERROR="+e);

	}

	if(CMS.use_local){
		var loc_key = 'RECORDS-'+RECORD_INDEX+'-'+RECORD_ID+'-'+SI+'-'+PN;
		localStorage.setItem(loc_key,JSON.stringify(arr));
	}

	// parent.loadTransition('rec|5|270|0|A|3|21',arr);
	// parent.loadTransition('rec|5|270|0|A|3|21',arr);

	// Take some time to do this right... 
	// elimiate the lengthy keys in the panes.php
	// make an initializer to store the interface elements inside the object itself...
	// maybe go so far as to fix the naming scheme on rowMapIndex vs rowMapKey...

	try{
		for(x in arr[0][14]){
			if(typeof(ROWSC[x]) == 'undefined'){
				pr("SKIPPING ROWSC x("+x+") ROWSC("+ROWSC[x]+")");
				continue;
			}
			setRowInterface(x);
		}
	}catch(e){
		pr("ROWSC x("+x+") e("+e+")");
	}

	try{
		for(x in arr[0][15]){
			if(typeof(arr[0][15][x]) == 'undefined'){continue;}
			sendChart(arr[0][15][x]);
		}
	}catch(e){
		pr("PLOT ERROR="+e);
	}

	try{
		if(typeof(arr[0][17]) != 'undefined' && arr[0][17] > 0){
			CMS.INLINE_SCRIPTS = INLINE_SCRIPTS;
			setTimeout("loadVars(CMS.INLINE_SCRIPTS);",1000);	// THIS ONE SECOND DELAY IS A TOTAL HACK... I NEED TO RE-ORGANIZE CALENDAR GLOBALS...
		}
	}catch(e){
		pr("INLINE SCRIPT ERROR (17)="+e);
	}

	try{
		if(typeof(arr[0][21]) != 'undefined'){
			for(x in arr[0][21]){
				for(y in arr[0][21][x]){
					var f=document.createElement("style");
					f.setAttribute("type", "text/css");		
					if(f.styleSheet){
						f.styleSheet.cssText = arr[0][21][x][y].toString();
					}else{
						f.appendChild(document.createTextNode(arr[0][21][x][y].toString()));
					}
					document.getElementsByTagName("head")[0].appendChild(f);
				}
			}
		}
	}catch(e){
		pr("INLINE SCRIPT ERROR (20)="+e);
	}

	try{
		if(typeof(arr[0][22]) != 'undefined'){
			stack_loader(arr[0][22]);
		}
	}catch(e){
		pr("INLINE SCRIPT ERROR (20)="+e);
	}

	try{
		if(typeof(arr[0][24]) != 'undefined'){
			var link = document.getElementsByTagName("link");
			var head = document.getElementsByTagName("head")[0];
			for(x in link){
				if(link[x].type == 'application/rss+xml'){
					if(typeof(arr[0][24][link[x].title]) != 'undefined'){
						delete arr[0][24][link[x].title];
					}
				}
			}
			for(x in arr[0][24]){
				var f = document.createElement("link");
				f.setAttribute("rel","alternate");
				f.setAttribute("type","application/rss+xml");
				f.setAttribute("title",x);
				f.setAttribute("href",arr[0][24][x]);
				head.appendChild(f);
			}
		}
	}catch(e){
		pr("HEAD ERROR (24)="+e);
	}

	if(typeof(arr[4]) != 'undefined'){
		// alert("MODULES FOUND");
		// cycle through the mods and snap them in...

		if(typeof(MOD_STACK[RECORD_INDEX]) == 'undefined'){
			MOD_STACK[RECORD_INDEX] = [];
		}
		if(typeof(MOD_STACK[RECORD_INDEX][RECORD_ID]) == 'undefined'){
			MOD_STACK[RECORD_INDEX][RECORD_ID] = [];
		}

		for(x in arr[4]){
			try{
				if(x == 'H'){
					for(y in arr[4][x]){
						for(z in arr[4][x][y]){
							if(typeof(MODS_LOADED['H'][y]) == 'undefined'){MODS_LOADED['H'][y]=[];}
							MODS_LOADED['H'][y][z] = arr[4][x][y][z];
						}
					}
					startit(true,caller_record_index,caller_record_id);
				}else{
					for(y in arr[4][x]){
						var modKey = ((x == 13))? "navC"+y: "mMCPID"+y;
						var modKeyObj = document.getElementById(modKey);
						if(modKeyObj){
							modKeyObj.innerHTML = arr[4][x][y];
							modKeyObj.style.display = 'block';
							// alert("MODID ("+"mMCPID"+y+") mod_type="+x+" mod_id="+y);
							// alert(arr[4][x][y]);
							if(parseInt(x) == x && x != 13){
								if(typeof(MOD_STACK[RECORD_INDEX][RECORD_ID][x]) == 'undefined'){
									MOD_STACK[RECORD_INDEX][RECORD_ID][x] = [];
								}
								MOD_STACK[RECORD_INDEX][RECORD_ID][x][y] = [];
							}
						}
					}
				}
			}catch(e){
				pr("error loading mod modKey=("+modKey+") x("+x+") error="+e);
			}
		}
	}

	try{

		// FOR NOW I AM ONLY LOOKING TO REMOVE THE PAGE DIRECTORY... THE STABLE TO ISHOP IS THE REAL TEST...

		for(x in MOD_STACK[caller_record_index][caller_record_id]){
			if(typeof(MOD_STACK[RECORD_INDEX][RECORD_ID][x]) == 'undefined'){
				if(parseInt(x) == 21){
					for(y in MOD_STACK[caller_record_index][caller_record_id][x]){
						var modKey = ((parseInt(x) == 13))? "navC"+y: "mMCPID"+y;
						document.getElementById(modKey).style.display = 'none';						
					}
				}
			}
		}

	}catch(e){
		pr("CLEAR MODE ERROR caller_record_index("+caller_record_index+") caller_record_id("+caller_record_id+") (0)="+e);	
	}

	try{
		for(x in arr[6]){
			if(x == 1){
				initProdOpt();
			}
		}
	}catch(e){
		pr("INIT ERROR="+e);
	}

	try{
		// s = sect / p = pane / r = rec_type / i = id 
		window.location.hash = "|0|0|"+RECORD_INDEX+"|"+RECORD_ID+"|"+SI+"|"+PN;
	}catch(e){
		pr("HASH ERROR="+e);
	}

	//PANES.var_sect = document.getElementById('var_sect').value; // sect and panes are one and the same...
	//PANES.i = PANES.var_sect;

	iNitAdmin();

	TL.l = false;
	clearTimeout(TL.t);
}

function LOAD_ELEMENTS(arr){
	for(var x in arr[1]){
		try{
			if(x == arr[0][6]){
				continue;
			}
			document.getElementById(x).innerHTML = arr[1][x];
		}catch(e){
			// pr("FAILED TO LOAD="+x+" ERROR="+e);
		}
	}
}

function LOAD_ARROWS(arr){
	try{
		if(typeof(arr[0][11]) != 'undefined'){
			loadArw(arr[0][11]);
		}
	}catch(e){
		pr("Arrow error"+e);
	}
}

function startPageRamp(){
	// so, I need a loop...

	// I need two vars... one for the increment rate, and the other for the actual distance, needs to cache, cannot pull from DOM.

	CMS.ramp[2] = (CMS.ramp[2] - 50);

	top.scrollTo(0,CMS.ramp[2]);

	if(CMS.ramp[2] > CMS.ramp[0]){		
		CMS.rampTO = setTimeout("startPageRamp();",10);
	}
}

function resetPagePos(id,mode,recIn){

	try{
		var t = CMS.transitions;
		var topOff = parseInt(CMS.topOff);
		var content_top = 100;
		var scrollY = getScrollY();

		if(id != ''){
			var Atop = document.getElementById(id);
			var content_top = getOffset(Atop,'top') + topOff;
			topOff = content_top;
		}


		if(!mode){
			if(typeof(t[recIn]) != 'undefined' && t[recIn] == 4){
				CMS.ramp=[content_top,topOff,scrollY];
				CMS.rampTO = setTimeout("startPageRamp();",10);
			}
			return;
		}

		// pr("scrollY("+scrollY+") > content_top("+content_top+") id("+id+")");

		if(scrollY > content_top){
			top.scrollTo(0,0);
		}

	}catch(e){
		pr("FAILED ON REPOSITIONING id("+id+") ERROR="+e);
	}
}

function getPane(sect,hook,c,p){ // this function has been linearized... it used to be... getPane(sect,pane,num,act)

	if(hook == 1){
		myLightbox.hideElements();
	}

	PANES.hook = hook;
	PANES.c = c;
	PANES.p = p;
	if(typeof(sect) == 'object'){// this is happening with links injected into the loaded page content...
		sect = sect.getAttribute('rev');
	}

	if(hook == 1){
		PANES['containers'][1] = document.getElementById('pageContainer');
		PANES['containers'][1].style.overflow = 'auto';
	}

	if(typeof(PANES[sect]) == 'undefined'){
		//alert('requesting controller');
		requestController(sect,hook);
	}else{
		//alert('ITS ALREADY LOADED... sect='+sect+ ' panes.i='+PANES.i);
		hidePane(PANES.i);
		showPane(sect);
	}
	return false;
}

function clearController(sect){
	try{
		var a = document.getElementById(sect).childNodes[1];
		if(typeof(a.classNameCached) != 'undefined'){
			a.className = a.classNameCached;
			a.innerHTML = a.innerHTMLCached;
		}
	}catch(e){}
	var len = FRMES.length;
	//alert('length='+ len);
	for(x = 1; x < len; x++){ // the first frame is always the statistics tracker
		//alert(sect +'  ==  '+ FRMES[x]['command']);
		
		if(sect == FRMES[x]['command']){
			//alert('SET TO FALSE');
			FRMES[x]['busy']=false;
			try{
				PANES[PANES.i].ownerDocument.getElementById('loader').style.display='none';
			}catch(e){}
			return x;
			//alert('load pane - match found - resetting controller to free');
		}
	}
}

function loadInclude(mode,filename,txt){
	// alert("loadInclude mode="+mode+" filename="+filename);

	if(typeof(CMS.includes[mode[0]][mode[1]]) != "undefined"){
		// alert("ALREADY LOADED("+mode[0]+"/"+mode[1]+")="+filename);
		if(mode[0] == 'js' && mode[2] != ''){
			setTimeout(mode[2],50);
		}
		return;
	}
	if(mode[0]=='js'){
		var f=document.createElement('script');
		f.setAttribute("type","text/javascript");
		f.setAttribute("src", filename);
		if(typeof(mode[2]) != 'undefined'){
			f.setAttribute("onload",mode[2]);
			f.onreadystatechange = function(){if(this.readyState == 'complete'){alert("HOWDY EXPLORER ON READY STATE CHANGE");}}
		}
	}else if(mode[0]=='css'){
		var f=document.createElement("link");
		f.setAttribute("rel", "stylesheet");
		f.setAttribute("type", "text/css");
		f.setAttribute("href", filename);
		f.setAttribute("onload", "onloadSS()");
	}
	if(typeof(f)!="undefined"){
		document.getElementsByTagName("head")[0].appendChild(f);
		CMS.includes[mode[0]][mode[1]] = true;
		//alert("LOADED("+mode[0]+"/"+mode[1]+")="+filename);
	}
}

function loadArw(arr){

	var oldArw = ARW;

	for(var x=0;x<2;x++){
		var Arw = document.getElementById('Arw-'+x);
		if(typeof(arr[x]) !== 'undefined'){
			Arw.style.display = 'block';
			ARW[x] = arr[x];
		}else{
			Arw.style.display = 'none';
		}
	}

	tipobj[0].innerHTML = (oldArw[tipobjInd])? oldArw[tipobjInd]['title']: '';

}

function doArw(caller,ind,cat_id){
	// load the variables from the array... with that info call the transition...

	CMS.startTime = new Date();

	if(RECORD_INDEX == 54 && RECORD_ID == 920){
		var m = (!ind)? -1: 1;
		return set_cal(0,m,0);
	}else if(RECORD_INDEX == 54 && RECORD_ID == 921){
		alert("DAY VIEW");
		return false;
	}

	// cat_id=908 rec_id=9232 rec_type=49 transition=1;
	// alert("RECORD ID="+RECORD_ID+" rec_id="+ARW[ind]['id']+" RECORD TYPE="+RECORD_INDEX+" rec_type="+rec_type);
	// alert("INDEX="+ind);
	// alert(objToString(CMS));
	// alert(arr);

	var arr = ARW[ind];
	var transition = 1;
	var cat_id = (RECORD_INDEX == 3)? cat_id: SECT_ID;
	var rec_type = RECORD_INDEX;
	var rec_id = arr['id'];

	return getRecordFromStack(rec_type,rec_id,cat_id);
	// return callTransition(caller,transition,cat_id,rec_type,rec_id,0);
}

function displayError(type,success,message,fields){

	try{
		if(type == 0){
			var dash = document.getElementById('dashboard_message');
			dash.innerHTML = message;
			var message_color = (success)? "#00ff00": "#ff0000";
			dash.style.backgroundColor = (success == 100)? null:message_color;
		}else if(type == 1){
			var errMessage = document.getElementById('errorMessage');
			errMessage.innerHTML = message;
			errMessage.style.display = "block";
			var ypos = getOffset(errMessage,'top');
			var xpos = getOffset(errMessage,'left');
			window.scrollTo(xpos,ypos);
			for(x in fields){
				if(fields[x][1].trim() != ''){
					try{
						var ele = document.getElementById(x);
						ele.style.border = INP_BORDER_ERROR;
						ele.style.background = INP_BACKGROUND_ERROR;
					}catch(e){}
				}
			}
		}
	}catch(e){}
}

function processPane(sect,pane,mode,element_whitelist){

	//	var sect = sect.toString();
	//	split = sect.split(".");
	//	var recId = split[0];
	//	var recIndex = split[1];

	var form = document.getElementById('content_form_'+sect);
	var l = form.elements.length;
	var pass = true;
	var err_fields = [];
	var ele,required,x,l2;
	var radios = [];

	for(x = 0; x < l; x++){
		ele = form.elements[x];
		required = ele.getAttribute("required");
		if(ele.type == 'radio'){
			if(typeof(radios[ele.name]) == 'undefined'){
				radios[ele.name]=[];
				radios[ele.name][1]=[];
			}
			l2 = radios[ele.name][1].length;
			radios[ele.name][1][l2] = ele;
			radios[ele.name][0] = (radios[ele.name][0] || ele.checked)? true: false;
		}else if(ele.type == "submit"){
			continue;
		}else if(required == 1 && trim(ele.value) == ''){
			ele.style.border = INP_BORDER_ERROR;
			ele.style.background = INP_BACKGROUND_ERROR;
			pass = false;
		}else{
			ele.style.border = INP_BORDER_NORMAL;
			ele.style.background = INP_BACKGROUND_NORMAL;
		}
	}

	for(x in radios){
		if(typeof(radios[x]) != 'object'){continue;}
		if(!radios[x][0]){
			for(y in radios[x][1]){
				radios[x][1][y].parentNode.style.border = INP_BORDER_ERROR;
				radios[x][1][y].parentNode.style.background = INP_BACKGROUND_ERROR;
			}
			pass = false;
		}else{
			for(y in radios[x][1]){
				radios[x][1][y].parentNode.style.border = "none";
				radios[x][1][y].parentNode.style.background = INP_BACKGROUND_NORMAL;
			}		
		}
	}

	if(!pass){
		displayError(1,0,'Some items highlighted red are required.',err_fields);
		return false;
	}

	return savePane(sect,pane,mode,element_whitelist);
}


// WE WILL SET THE TRANSPORT TO USE SSL...

function loadPane(type,sect,html,arr,loc,shake,insert_id,pairs){ // called when a frame returns content...
	// WHAT HAPPENS WHEN YOU'VE BEEN LOGGED OUT DUE TO INACTIVITY? CLEAR COOKIES AND FIND OUT...
	var hook = clearController(sect);
	hidePane(PANES.i);
	//alert(html);

	if(type == 1){
		if(arr['success'] == 0){
			displayError(1,0,arr['message'],arr['fields']);
		}else{
			if(typeof(arr['form_id']) == 'string'){
				try{
					document.getElementById('content_form_'+arr['form_id']).style.display = 'none';
					document.getElementById('commentBox_'+arr['form_id']).innerHTML = arr['message'];
					if(insert_id.length){
						document.getElementById(insert_id).innerHTML = html;
					}
				}catch(e){}
			}else{
				alert("OBJECT SUCCEED BUT THE TYPE OF RETURN STRING IS NO GOOD.");
			}
		}
	}else if(typeof(loc) == 'string'){
		//alert('Loc'+loc);
		top.location.replace(loc);
		return true;
	}else if(typeof(arr) == 'object'){
		try{displayError(0,arr['success'],arr['message'])}catch(e){}
		// we need to know the name... the status... and any new value...
		if(arr['success'] == 1){
			//alert('PASS NEED TO SHOW MESSAGE... OR LOAD A NEW PAGE...');
			if(typeof(arr['booleans']) == 'object'){
				for(field in arr['booleans']){
					checkboxReturn(field,arr['booleans'][field]);
				}
			}
		}else{
			for(field in arr['fields']){
				// -----
				//alert(objToString(arr['fields'][field]));
				if(arr['fields'][field][1]){
					if(!shake){
						document.getElementById(field).style.border="solid 2px #F00";
					}else if(shake == 1){ // highlight label...
						var label = document.getElementById('label-'+field);
						label.className="cklabel_error";
						var widget = document.getElementById(field);
						widget.labelObj = label;
						//label.onmouseover = ddrivetip;//("Invalid Range of characters. The forward slash operator is not permitted.","",0,10,20,0);
						//label.onmouseout = hideddrivetip;//(0);
						//
						//alert(arr['fields'][field][1]);
					}
				}
			}
			if(!shake){
				PANES[sect].ownerDocument.getElementById('error_message').innerHTML=arr['message'];
			}else if(shake == 1){
				PANES[sect].ownerDocument.getElementById('dashboard_message').innerHTML=arr['message'];
			}
		}
	}else if(insert_id){
		if(typeof(pairs) == 'object'){
			for(x in pairs){
				for(y in pairs[x]){
					if(y==1){
						document.getElementById(x).className = pairs[x][y];
					}else if(y==2){
						document.getElementById(x).innerHTML = pairs[x][y];
					}				
				}
			}
		}else{
			try{
				if(html.length){
					document.getElementById(insert_id).innerHTML = html;
				}
			}catch(e){}
		}
		return;
	}else{
		PANES[sect].innerHTML = html;
	}

	//alert('hook assignment='+hook);
	PANES[sect].hook = hook; // you may have incorrectly assigned the hook to the section because the section is not dependant on a hook...
	showPane(sect);
}

function stackRCLASS(pane,rowMapKey,rClas){

	// pr("stackRCLASS pane("+pane+") rowMapKey("+rowMapKey+") rClas("+rClas+")");

	if(typeof(RCLASS[pane]) === 'undefined'){RCLASS[pane]=[];}
	if(typeof(RCLASS[pane][rowMapKey]) === 'undefined'){RCLASS[pane][rowMapKey]=[];}
	for(x in rClas){
		// alert("STACKING RCLASS pane="+pane+" rowMapKey="+rowMapKey+" x="+x+" rClas="+rClas[x]);
		RCLASS[pane][rowMapKey][x] = rClas[x];
	}
}

function stackROWS(pane,rowMapKey,rRows){
	if(typeof(ROWS[pane]) === 'undefined'){ROWS[pane]=[];}
	if(typeof(ROWS[pane][rowMapKey]) === 'undefined'){ROWS[pane][rowMapKey]=[];}
	for(x in rRows){ROWS[pane][rowMapKey][x] = rRows[x];}
}

function stackROWSC(rowMapKey,rowObj){
	ROWSC[rowMapKey] = rowObj;
	CMS.rowMapKey = rowMapKey;
}

function loadRows(sect,rRows,rClas,rowObj){

	var split = sect.split('|');
	try{
		document.getElementById('rF4').style.display = (split[7].length)? '': 'none';
	}catch(e){}

	var hook = clearController(sect);

	var rowMapKey = split[5];
	var rowObj = rowObj[rowMapKey];
	var pane = rowObj.pane;
	var sortDir = rowObj.dir;
	var sort = rowObj.srt;
	var pn = rowObj.pn;
	var key = rowObj.key;

	stackROWS(pane,rowMapKey,rRows);
	stackRCLASS(pane,rowMapKey,rClas);

	var rowTable = document.getElementById('rowTable-'+rowMapKey);
	var rows = rowTable.childNodes[0].childNodes;
	var L1 = rows.length;
	var LS = rowObj.start_record_number;
	var LE = rowObj.end_record_number; 
	var LT = rowObj.total_records;
	var LP = (rowObj.total_pages);
	var LH = (rowObj.rowHeight+1);

	//alert("recNS="+recNS+" recNE="+recNE+" recNT="+recNT);

	if(pn >= LP){
		pn=0;
	}

	//var key = "s"+sort+"-d"+sortDir+"-n"+pn;
	if(typeof(ROWS[pane][rowMapKey][key]) === 'undefined'){
		alert('internal script error... bad index on row sort in admin.js... shut off fast rows in page preferences...');
		alert(key);
		alert(objToString(ROWS[pane][rowMapKey]));
	}else{
		var ind = ROWS[pane][rowMapKey][key];
	}

	var cols,L2,rowClassStat,filled,do_fill,ind,val;

	// This should at some point reference a template...

	for(x=1;x<LH;x++){
		cols = rows[x].childNodes;
		L2 = cols.length;
		rowClassStat = RCLASS[pane][rowMapKey][key][(x-1)];
		rows[x].style.background = (rowClassStat == 1 || rowClassStat == 3)? '#ddd': '#ccc';
		rows[x].className = (rowClassStat == 2 || rowClassStat == 3)? 'AdminTableRow highPriority': 'AdminTableRow';
		filled = 1;
		do_fill = (typeof(ind[(x-1)]) !== 'undefined')? 1: 0;
		indX = ind[(x-1)];
		for(y=0;y<L2;y++){
			try{
				if(do_fill){
					val = ROWS[pane][rowMapKey][indX][y];
					val = val.replace(/&gt;/g, ">");
					val = val.replace(/&lt;/g, "<");
					val = val.replace(/&amp;/g, "&");
					val = val.replace(/&quot;/g, '"');
				}else{
					val = '&nbsp;';
					filled = 0;
				}
				cols[y].childNodes[0].innerHTML = val;
			}catch(e){
				alert("L2="+L2+" LH="+LH+" indX="+indX+" ERROR FILLING ROW " + e);
			}
		}
		rows[x].style.display = (!filled && pn < 1)? 'none': '';
	}

	stackROWSC(rowMapKey,rowObj);

	setRowInterface(rowMapKey);
}

function setRowInterface(rowMapKey){

	var rowObj = ROWSC[rowMapKey];
	var supp = rowObj.suppress_interface;

	if(supp == 3){return;}

	var rowTable = document.getElementById('rowTable-'+rowMapKey);
	var rows = rowTable.childNodes[0].childNodes;
	var LS = rowObj.start_record_number;
	var LE = rowObj.end_record_number; 
	var LT = rowObj.total_records;
	var LP = rowObj.total_pages;
	var LH = (rowObj.rowHeight+1);
	var pane = rowObj.pane;
	var key = rowObj.key;

	// pr("setRowInterface pane("+pane+") rowMapKey("+rowMapKey+") key("+key+")");

	// for(var x in RCLASS){
	// 	pr("x("+x+") RCLASS("+RCLASS[x]+")");
	// }


	for(x=1;x<LH;x++){
		rowClassStat = RCLASS[pane][rowMapKey][key][(x-1)];
		rows[x].style.background = (rowClassStat == 1 || rowClassStat == 3)? '#ddd': '#ccc';
		rows[x].className = (rowClassStat == 2 || rowClassStat == 3)? 'AdminTableRow highPriority': 'AdminTableRow';	
	}

	try{
		document.getElementById('rowTable-'+rowMapKey+'-message').style.display = (LT == 0)? 'block':'none';
	}catch(e){}

	// reset the arrow icon...
	var cols = rows[0].childNodes;
	var L2 = cols.length;
	for(y=0;y < L2;y++){
		if(typeof(cols[y].childNodes[0]) === 'undefined'){continue;}
		var col_id = cols[y].id.substr(2);
		if(ROWSC[rowObj.rowMapKey].srt == col_id){
			cols[y].className = (ROWSC[rowObj.rowMapKey].dir==1)? 'but_in_up':'but_in_down';
		}else{
			cols[y].className = (cols[y].className == 'but_dis')? 'but_dis': 'but_out';
		}
	}

	// CAN I SEND A GENERIC ID => VALUE pair object to cycle through to insert values?

	try{
		document.getElementById('recNS').innerHTML = LS;
		document.getElementById('recNE').innerHTML = LE;
		document.getElementById('recNT').innerHTML = LT;
	}catch(e){}

	var pn = parseInt(ROWSC[rowObj.rowMapKey].pn);
	var ps = document.getElementById('page_select-'+rowMapKey);
	ps.options.selectedIndex = pn;
	var total_page_count = LP;

	try{
		var p_prev = document.getElementById('page_prev-'+rowMapKey).childNodes[0];
		p_prev.style.display = (pn == 0)? 'none': 'block';
	}catch(e){}

	try{
		var p_next = document.getElementById('page_next-'+rowMapKey).childNodes[0];
		p_next.style.display = ((pn+1) >= total_page_count)? 'none': 'block';
	}catch(e){}

	try{
		var page_nums = document.getElementById('page_nums-'+rowMapKey);
		var s_cap = 1;
		var e_cap = (pn + 4);
		if(e_cap > total_page_count){e_cap = total_page_count;s_cap = e_cap - 6;}else{s_cap = pn - 2;}
		if(s_cap < 1){s_cap = 1;e_cap = 7;}
		if(e_cap > total_page_count){e_cap = total_page_count;}
		for(y=0;y < 7;y++){
			if(typeof(page_nums.childNodes[y]) === 'undefined'){continue;}
			var but = page_nums.childNodes[y].childNodes[0];
			but.style.textDecoration = ((s_cap-1) == pn)? 'underline':'none';
			but.innerHTML = s_cap;
			but.setAttribute('rel',(s_cap-1));
			but.style.display = (y >= total_page_count)? "none": "";
			s_cap++;
		}
	}catch(e){}

	try{
		var l = ps.length;
		var x = (total_page_count > l)? total_page_count: l;
		var spread = (x > 10000)? 1000: 1;
		var opts = [];

		if(spread > 1){
			var num_of_spreads = Math.floor(total_page_count / spread);
			var spread_point = 1;
			opts[1] = spread_point;
			var z = 2;
			for(var y = 1; y <= num_of_spreads; y++){
				spread_point = (y * spread);
				opts[z++] = spread_point;
			}

			var spread_start = pn - 4;
			spread_start = (spread_start < 1)? 1: spread_start;
			var spread_end = pn + 6;
			spread_end = (spread_end > total_page_count)? 1: spread_end;
			for(var y = spread_start; y < spread_end; y++){
				opts[z++] = y;
			}
			opts.sort(sortNumber);
			ps.options.length = 0;
	
			var z = 0;
			for(y in opts){
				ps.options[z] = new Option(opts[y].toString(),opts[y]-1);	
				if(pn == ps.options[z].value){
					ps.options.selectedIndex = y;
				}
				z++;
			}
		}else{
			ps.options.selectedIndex = pn;
		}

		

	}catch(e){pr("pagination"+e);}
	
	//alert("ROW LOADER FINISHED");	
}

function hidePane(sect){
	return false;
	PANES[sect].style.display = 'none';
}

function closeWindow(sect){
	if(typeof(sect) == 'string'){
		var winCon = top.document.getElementById("winCon"); // DOES NOT SUPPORT MULTI WINDOWS AT THE MOMENT
		document.body.removeChild(winCon);			
	}else{
		document.body.removeChild(this.parentNode.parentNode);	
	}
}

function drag(){
	this.divCov = this.parentNode.childNodes[0];
	this.divCov.style.height = "1000px";
	Drag.init(this.parentNode,null,0,getViewportWidth(),0,10000);
	this.parentNode.onDragEnd = function(x, y){
		this.childNodes[0].style.height = "0px";
	}
}

POPUPS=[];

function launchPageFrame(sect,page,popup,is_inline){

	clearController(sect);

	// THESE VARS HAVE TO PASS UP WITH THE COMMAND... width,height,throbberclass

	var popup_isset = (typeof(popup) != 'undefined')? 1: 0;

	var width = (popup_isset && typeof(popup['w']) !== 'undefined')? popup['w']:550;
	var height = (popup_isset && typeof(popup['h']) !== 'undefined')? popup['h']:375;
	var scroll = (popup_isset && typeof(popup['s']) !== 'undefined')? popup['s']:0;

	if(!is_inline){
		var left = (screen.width/2)-(width/2);
		var top = (screen.height/2)-(height/2);
		var title = popup.title;
		if(typeof(POPUPS[title]) !== 'undefined' && !POPUPS[title].closed){
			POPUPS[title].focus();
			return;
		}

		var targetWin = window.open(page,title,'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+width+', height='+height+', top='+top+', left='+left);
		POPUPS[title] = targetWin;
		return;
	}

	var scrollY = getScrollY();
	var viewportHeight = getViewportHeight();
	var viewportWidth = getViewportWidth();
	var isIE6 = /msie|MSIE 6/.test(navigator.userAgent);

	//alert("window.pageYOffset="+window.pageYOffset +" document.body.scrollTop="+document.body.scrollTop+" document.documentElement.scrollTop="+document.documentElement.scrollTop);
	//alert("window.innerHeight="+window.innerHeight+" document.documentElement.clientHeight="+document.documentElement.clientHeight + " document.body.clientHeight="+document.body.clientHeight);
	//alert("window.innerWidth="+window.innerWidth+" document.documentElement.clientWidth="+document.documentElement.clientWidth + " document.body.clientWidth="+document.body.clientWidth);

	var centerX = parseInt(parseInt(viewportWidth) / 2);
	var centerY = (isIE6)? parseInt(parseInt(viewportHeight) / 2) + parseInt(scrollY): parseInt(parseInt(viewportHeight) / 2);
	var div = document.createElement("DIV");
	div.className = "winCon";
	div.setAttribute("id","winCon");
	div.style.top = (centerY-((height+20)/2)) +"px"; // THIS IS NOT RELATIVE TO THE CENTER OF SCREEN...
	div.style.left = (centerX-(width/2)) +"px";
	div.style.height = (height+20)+"px";
	div.style.width = width+"px";
	var div2 = document.createElement("DIV");
	div2.className = "winCov";
	div.appendChild(div2);
	var div3 = document.createElement("DIV");
	div3.className = "thrbL";
	div.appendChild(div3);
	var div4 = document.createElement("DIV");
	div4.className = "winBar";
	div4.onmousedown = drag;
	div.appendChild(div4);
	var div5 = document.createElement("DIV");
	div5.onclick = closeWindow;
	div5.onmousedown = drag;
	div5.className = "winBarClose";
	div5.id = "winBarClose";
	div4.appendChild(div5);
	var frame = document.createElement("IFRAME");
	frame.style.width = width+"px";
	frame.style.height = height+"px";
	frame.style.border = "none";
	var frameID = "pop-1";
	frame.setAttribute("id",frameID);
	var scroll = (scroll)? "yes": "no";
	frame.setAttribute("scrolling",scroll);
	frame.setAttribute("frameborder","0");
	frame.frameContainer = div;
	div.appendChild(frame);
	document.body.appendChild(div);
	frame.src = page+"&content_only=99";
	frame.throbber = div3;
//	frame.areaHeight = height; // this was removed as it caused issues with firefox.
	//frame.onload = clearFrameThrobber;
	startFrameThrobber(frame);
	if(isIE6){window.onscroll = fixedIE;}
}



function fixedIE(){
	try{
		var fixedElement = document.getElementById("winCon");
		fixedElement.style.top = (parseInt(getScrollY()) + "px");   
	}catch(e){}
} 

function startFrameThrobber(frm){
	frm.throbber.style.height = frm.areaHeight+"px";
	frm.throbber.style.display = 'block';
}

function clearFrameThrobber(id){
	document.getElementById(id).throbber.style.display = "none";
}

function showPane(sect){ // make the container creator in here???

	PANES.i = sect;
	if(PANES.hook == 1){
		myLightbox.showPage();
	}
}

function importPane(sect,pane,mode){ // this is obviously a big mistake...
	if(pane == 'batch_importer'){
		var myfile = document.getElementById('myfile').value;
		var record_type = document.getElementById('record_type').value;
		var file_type = document.getElementById('file_type').value;
		if(myfile==''){
			displayError(0,0,'Please Choose a File');
			return false;
		}else if(record_type==''){
			displayError(0,0,'Please Choose a Record Type');
			return false;			
		}else if(file_type==''){
			displayError(0,0,'Please Choose a File Type');
			return false;			
		}		
	}
}

CANCEL_AJAX=0;
function cvalChange(){
	var is_safari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;
	if(is_safari){CANCEL_AJAX=1;}
}

function savePane(sect,pane,mode,element_whitelist,caller){

	//	pr('SavePane() --- PANES.i('+PANES.i+') sect('+sect+') pane('+pane+')');
	//	return false;

	if(PANES.i.substr(0,2) == 'F-'){
		PANES[PANES.i].paneform = document.getElementById(PANES.i);		
	}else{
		PANES[PANES.i].paneform = PANES[PANES.i].ownerDocument.getElementById('content_form_'+sect);
	}

	var hook = 0;
	if(hook == 1){
		myLightbox.hideElements();
	}

	var RC = requestController(PANES.i,hook,'POST');
	RCD = RC.document;
	Tform = RCD.createElement("FORM");
	Tform.setAttribute("id","trans_form");
	Tform.setAttribute("method","post");
	if(mode == 'FILE'){
		Tform.setAttribute("enctype","multipart/form-data");
	}
	var loc = PANES[PANES.i].ownerDocument.location.toString();
	var thepath = loc.substr(0,loc.lastIndexOf('/'));

	//	I DONT KNOW WHY YOU HAD THIS AS ABSOLUTE BUT FIRFOX THROWS ERRORS WITH HTTPS ABSOLUTE PATHS...

	Tform.setAttribute('action',loc);

	if(sect == 'login' && CANCEL_AJAX){
		var checkbox = document.getElementById('remember_me').childNodes[0];
		if(checkbox.checked){return true;}
	}

	//	Tform.setAttribute('action','?trans='+PANES.i);
	//	alert(thepath+'/index.php?trans='+PANES.i);

	var form_stamp = false;
	try{
		form_stamp = document.getElementById('form_stamp').value;	
	}catch(e){}

	var c = PANES[PANES.i].paneform.elements.length;
	var cacheVals=[];
	var cacheVal = false;

	//	alert('elements length='+c);

	var check_whitelist = false;
	if(typeof(element_whitelist) == 'object'){
		check_whitelist = true;
	}

	for(x=0;x < c; x++){
		var ele = PANES[PANES.i].paneform.elements[x];
		if(mode == 'FILE' && ele.type != 'file' && ele.id != 'form_stamp'){
			continue;
		}

		if(check_whitelist && element_whitelist.length){
			var check = ele.id;
			var pass = false;
			for(z in element_whitelist){
				if(element_whitelist[z] === check){
					pass = true;
				}
			}
			if(!pass){continue;}
			//alert(check);
		}

		if(ele.nodeName == 'TEXTAREA'){
			//alert(ele.textContent);
			var temp = RCD.createElement("TEXTAREA");
			var n = ele.name;
			if((n.substr(0,4)=='new_' && mode == 'SAVE') || (n.substr(0,4)!='new_' && mode == 'ADD')){continue;}
			temp.setAttribute('name',n);
			temp.value = ele.value;
			//temp.setAttribute('value',ele.value);
			Tform.appendChild(temp);
		}else if(ele.nodeName == 'SELECT'){
			var temp = RCD.createElement("SELECT");
			var n = ele.name;
			temp.setAttribute('name',n);
			if(ele.options.length){
				var val = ele.options[ele.selectedIndex].value;
				var temp2 = RCD.createElement("OPTION");
				temp2.setAttribute('value',ele.value);
				temp2.setAttribute('selected','selected');
				temp.appendChild(temp2);
				Tform.appendChild(temp);
			}
		}else if(ele.nodeName == 'INPUT'){
			if(ele.alt == 'ckey'){
				cacheKey = ele;//alert('CACHE KEY');
			}else if(ele.alt == 'cval'){
				cacheVal = true;
				cacheVals[cacheVals.length] = ele;//alert('CACHE VAL');
			}else if(ele.type == 'checkbox' || ele.type == 'radio'){
				if(ele.checked){
					var temp = RCD.createElement("INPUT");
					var n = ele.name;
					if((n.substr(0,4)=='new_' && mode == 'SAVE') || (n.substr(0,4)!='new_' && mode == 'ADD')){continue;}
					temp.setAttribute('name',n);
					temp.setAttribute('value',ele.value);
					Tform.appendChild(temp);
				}
			}else if(ele.type == 'text' || ele.type == 'submit' || ele.type == 'hidden' || ele.type == 'password'){
				var temp = RCD.createElement("INPUT");
				var n = ele.name;
				var val = ele.value;
				if((n.substr(0,4)=='new_' && mode == 'SAVE') || (n.substr(0,4)!='new_' && mode == 'ADD')){continue;}
				temp.setAttribute('name',n);
				if(ele.type == 'password'){
					val = val.replace(/^\s+|\s+$/g, '');
					if(val.length > 0 && form_stamp){					
						val = cT(val,form_stamp);
					}
				}
				if(typeof(ele.labelObj) == 'object'){
					ele.labelObj.className = 'cklabel';
				}
				temp.setAttribute('value',val);
				Tform.appendChild(temp);				
			}else if(mode == 'FILE' && ele.type == 'file'){
				temp = ele.cloneNode(true);
				Tform.appendChild(temp);
			}else{
				pr('Unknown Input Type=' + ele.type);
			}
		}else{
			pr('Unknown Element Type=' + ele.nodeName);
		}
	}

	//getUserData
	if(typeof(cacheKey) == 'object' && cacheVal){
		ckey = cacheKey.value.replace(/^\s+|\s+$/g, '');
		if(ckey.length == 0){ckey="0";}
		if(cacheKey.name == 'uid'){
			var temp = RCD.createElement("INPUT");
			temp.setAttribute('name','hint');
			if(((ckey.indexOf("@") > 1) || parseInt(ckey) == ckey)){
				temp.setAttribute('value',ckey.substr(0,1)+""+ckey.substr(ckey.length-1));	
				Tform.appendChild(temp);
			}
		}

		cval = cacheVals[0].value.replace(/^\s+|\s+$/g, '');
		var temp = RCD.createElement("INPUT");
		temp.setAttribute('name',cacheKey.name);
		if(cval.length == 0){cval="0";}
		temp.setAttribute('value',cT(ckey,cval));
		Tform.appendChild(temp);
		var l = cacheVals.length;

		for(x=0;x < l;x++){
			cval = cacheVals[x].value.replace(/^\s+|\s+$/g, '');
			var temp = RCD.createElement("INPUT");
			temp.setAttribute('name',cacheVals[x].name);
			temp.setAttribute('value',cT(cval,ckey));	
			Tform.appendChild(temp);
		}
	}

	var temp = RCD.createElement("INPUT");
	temp.setAttribute('name','trans');
	temp.setAttribute('value','trans');	
	Tform.appendChild(temp);
	var temp = RCD.createElement("INPUT");
	temp.setAttribute('name','panesi');
	temp.setAttribute('value',PANES.i);	
	Tform.appendChild(temp);
	var temp = RCD.createElement("INPUT");
	temp.setAttribute('name','pane');
	temp.setAttribute('value',pane);
	Tform.appendChild(temp);
	var temp = RCD.createElement("INPUT");
	temp.setAttribute('name','sect');
	temp.setAttribute('value',sect);
	Tform.appendChild(temp);
	var temp = RCD.createElement("INPUT");
	temp.setAttribute('name','trans_action'); // This used to be action but it conflicted with the form action event...
	temp.setAttribute('value',mode);
	Tform.appendChild(temp);

	//	if(top != self){ // DOESN'T WORK
	//		var temp = RCD.createElement("INPUT");
	//		temp.setAttribute('name','trans_source'); // This used to be action but it conflicted with the form action event...
	//		temp.setAttribute('value','iframe');
	//		Tform.appendChild(temp);		
	//	}

	// IE
	if(!RC.document.body){
		var temp = RCD.createElement("BODY");
		RCD.appendChild(temp);
	}
	RC.document.body.appendChild(Tform);

	//alert(Tform.action);
	//Tform.submit();

	RC.document.getElementById('trans_form').submit();

	return false;
}

function ddInit(e){
  topDog=isIE ? "BODY" : "HTML";
  whichDog=isIE ? document.all.theLayer : document.getElementById("theLayer");  
  hotDog=isIE ? event.srcElement : e.target;  
  while (hotDog.id!="titleBar"&&hotDog.tagName!=topDog){
    hotDog=isIE ? hotDog.parentElement : hotDog.parentNode;
  }  
  if (hotDog.id=="titleBar"){
    offsetx=isIE ? event.clientX : e.clientX;
    offsety=isIE ? event.clientY : e.clientY;
    nowX=parseInt(whichDog.style.left);
    nowY=parseInt(whichDog.style.top);
    ddEnabled=true;
    document.onmousemove=dd;
  }
}

function dd(e){
  if (!ddEnabled) return;
  whichDog.style.left=isIE ? nowX+event.clientX-offsetx : nowX+e.clientX-offsetx; 
  whichDog.style.top=isIE ? nowY+event.clientY-offsety : nowY+e.clientY-offsety;
  return false;  
}

function hideMe(){
  if (isIE||isNN) whichDog.style.visibility="hidden";
  else if (isN4) document.theLayer.visibility="hide";
}

function showMe(){
  if (isIE||isNN) whichDog.style.visibility="visible";
  else if (isN4) document.theLayer.visibility="show";
}

var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};

// AUTODSS

function fill_auto(ind,key,val,iid){

	var obj = AUTOS[ind]['I'][iid].obj;
	Offx = getOffset(obj,'left') - 0;
	Offy = getOffset(obj,'top') + 22;

	//	I am losing focus the second I click outside the select
	obj.key = key;
	obj.ind = ind;
	obj.iid = iid;
	
	w = obj.offsetWidth;
	if(!AUTOS[ind]['I'][iid].div){ // you can probably initialize this when the page is sent rather than with javascript...

		div = document.createElement("DIV");
		div.setAttribute("class","aCWidgetDDS");
		div.style.position = "absolute";
		div.style.zIndex = 1000;
		div.style.top = Offy+'px';
		div.style.left = Offx+'px';
		document.body.appendChild(div);
		sel = document.createElement("SELECT");
		sel.setAttribute('class','AdminSelectMult'); // THIS AT SOME POINT SHOULD BE FULLY ABSTRACTED FROM A SELECT TO DDM
		sel.setAttribute('size','8');
		sel.setAttribute('id',ind+'|'+iid+'|DDSsel');
		sel.onclick = ddsClick;

		sel.onblur = function(){autoDDSBlur();}
		sel.onmousedown = autoDDSLock;
		sel.onkeydown = function(e){return keydown(e,2,this);}

		div.appendChild(sel);
		div.ddsInput = AUTOS[ind]['I'][iid].obj;
		AUTOS[ind]['I'][iid].div = div;
		AUTOS[ind]['I'][iid].sel = sel;
	}

	AUTOS.key = key;
	AUTOS.ind = ind;
	AUTOS.iid = iid;
	AUTOS[ind]['K'][key] = val;
	write_select(ind,key,iid);

	return;
}

function write_select(ind,key,iid){
	// you will probably get faster performance by first hiding the div and then redisplaying it...

	if(!isset(AUTOS,ind) || !isset(AUTOS[ind]['K'],key) || !isset(AUTOS[ind]['I'],iid)){
		pr("AUTOS.ind is not set = "+ val);
		return;
	}

	// alert("write_select("+ind+","+key+","+iid+")");

	if(typeof(AUTOS[ind]['I'][iid].div) == 'undefined'){
		pr("AUTOS.div is not set = ");
		return;
	}

	var val = AUTOS[ind]['K'][key];
	var sel = AUTOS[ind]['I'][iid].div.childNodes[0];
	var obj = AUTOS[ind]['I'][iid].obj;
	var div = AUTOS[ind]['I'][iid].div;

	Offx = getOffset(obj,'left') - 0;
	Offy = getOffset(obj,'top') + 22;

	div.style.top = Offy+'px';
	div.style.left = Offx+'px';

	AUTOS[ind]['I'][iid].div.style.display = 'none';

	// alert(objToString(sel));
	// AUTOS[AUTOS.ind].div.style.display = 'block';
	sel.options.length = 0;
	var c = 0;
	for(x in val){
		sel.options[c++]=new Option(val[x][0],x);
		//opt = document.createElement("OPTION");
		//opt.value = val[1][x];
		//opt.text = val[0][x];
		//sel.options.add(opt,x);
	}

	if(typeof(AUTOS[ind]['I'][iid].ininp) == 'undefined' || !AUTOS[ind]['I'][iid].ininp){
		return;
	}

	AUTOS[ind]['I'][iid].div.style.display = (c)? 'block':'none';
	AUTOS[ind]['I'][iid].isopen = (c)? 1: 0;

	if(c){
		clearTimeout(AUTOS[ind]['I'][iid].timeout);
	}
}

function dofocusDDSinp(obj){
	var obj = (typeof(obj) != 'undefined')? obj: this;
	var spl = obj.parentNode.childNodes[0].id.split("|");
	var ind = spl[0];
	var iid = spl[1];
	if(AUTOS[ind] && AUTOS[ind]['I'] && AUTOS[ind]['I'][iid]){
		AUTOS[ind]['I'][iid].indds = 0;
	}
	keyup(obj);
	dofocus(obj);
}

function timeoutDDS(ind,iid){
	if(!AUTOS[ind]['I'][iid].isopen && AUTOS[ind]['I'][iid].div){
		AUTOS[ind]['I'][iid].div.style.display = 'none';
	}
}

// I COULD KEEP TRYING TO TIME THIS RIGHT FOR A SOLID LOCK...
// I COULD CAPTURE MOUSE CO-ORDINATES... AND HACK IT...
// I COULD RELY ON MOUSEOUT EVENTS, BUT THEY WILL BE UNRELIABLE...
// I want a second hint which says whether or not we are inside the DDS

function doblurDDSinp(obj){ // Blur from the input...

	var obj = (typeof(obj) != 'undefined')? obj: this;
	var spl = obj.parentNode.childNodes[0].id.split("|");
	var ind = spl[0];
	var iid = spl[1];

	if(AUTOS[ind] && AUTOS[ind]['I'] && AUTOS[ind]['I'][iid]){
		if(!AUTOS[ind]['I'][iid].indds && AUTOS[ind]['I'][iid].div){
			AUTOS[ind]['I'][iid].div.style.display = 'none';
		}else{
			AUTOS[ind]['I'][iid].timeout = setTimeout("timeoutDDS('"+ind+"','"+iid+"')",500);
		}
		AUTOS[ind]['I'][iid].ininp = 0;
	}

	doblur(obj);
}

function autoDDSLock(){ // signal that we are inside the dds...

	var spl = this.id.split("|");
	var ind = spl[0];
	var iid = spl[1];

	if(AUTOS[ind] && AUTOS[ind]['I'][iid]){
		AUTOS[ind]['I'][iid].indds = 1;
	}
}

function autoDDSBlur(){ // maybe this timeout is just a bad idea...

	var ind = AUTOS.ind;
	var iid = AUTOS.iid;

	AUTOS[ind]['I'][iid].isopen = 0;
	AUTOS[ind]['I'][iid].div.style.display = 'none';

	return;
}

function keydown(e,n,obj){

	// I DO NOT WANT TO CACHE THE INDEXES IN HERE... BUT INSTEAD THEY MUST REFERENCE THE OBJECT THAT CALLED IT...

	if (!e) var e = window.event;
	var key = e.keyCode;

	if(n == 1){
		if(key == 40){ // down arrow

			var spl = obj.id.split("|");
			var ind = spl[0];
			var iid = spl[1];
			AUTOS[ind]['I'][iid].isopen = 1;
			AUTOS[ind]['I'][iid].indds = 1;
			AUTOS[ind]['I'][iid].div.childNodes[0].focus();

		}else if(key == 13){
			return false;
		}
	}else if(n == 2){

		var spl = obj.id.split("|");
		var ind = spl[0];
		var iid = spl[1];
		var auto = AUTOS[ind]['I'][iid];

		if(key == 38){ // up arrow
			var sel = auto.div.childNodes[0];
			var si = sel.selectedIndex;
			if(si == 0){
				AUTOS[ind]['I'][iid].isopen = 0;
				AUTOS[ind]['I'][iid].indds = 0;
				auto.obj.focus();
				var pos = auto.obj.value.length;
				setCaretTo(auto.obj,pos);
				return false;
			}
		}else if(key == 13){ // enter
			AUTOS[ind]['I'][iid].div.childNodes[0].onclick();
			return false;
		}
	}
}

// SO I BASICALLY HAVE TO ENSURE THIS CLEANS UP ON A BLUR...
// AND THE DDS ITSELF... THAT NEEDS AN ON BLUR EVENT HANDLER AS WELL...

function keyup(obj){

	var obj = (typeof(obj) != 'undefined')? obj: this;

	var spl,command,key_ind;
	var key = obj.value.toUpperCase();
	var key_ind = obj.parentNode.childNodes[0];

	var ele = key_ind.id;
	var spl = ele.split("|");
	var ind = spl[0];
	var iid = spl[1];

	if(!AUTOS[ind]){
		AUTOS[ind]=[];
	}
	if(!AUTOS[ind]['I']){
		AUTOS[ind]['I']=[];
		AUTOS[ind]['K']=[];
	}
	if(!AUTOS[ind]['I'][iid]){AUTOS[ind]['I'][iid]=[];}

	AUTOS[ind]['I'][iid].ininp = 1;

	if(key.length < 2){

		if(AUTOS[ind] && AUTOS[ind]['I'] && AUTOS[ind]['I'][iid] && AUTOS[ind]['I'][iid].div){
			AUTOS[ind]['I'][iid].div.style.display = 'none';
			AUTOS[ind]['I'][iid].isopen = 0;
		}		

		if(key.length < 1){
			key_ind.value = null; // This needs to expand of course to be much more discriminating...
		}

	}else if(key.length==2){

		if(AUTOS[ind]['K'][key]){ // AUTOS[ind]['I'][iid].div

			AUTOS.key = key;
			AUTOS.ind = ind;
			AUTOS.iid = iid;
			
			if(!AUTOS[ind]['K'][key].div){
				AUTOS[ind]['I'][iid].obj = obj;
				fill_auto(ind,key,AUTOS[ind]['K'][key],iid); // reload using pre-existing arrays
			}else{
				write_select(ind,key,iid);
				AUTOS[ind]['I'][iid].div.style.display = 'block';
				AUTOS[ind]['I'][iid].isopen = 1;
				clearTimeout(AUTOS[ind]['I'][iid].timeout);
			}
		}else{
			AUTOS[ind]['I'][iid].obj = obj;
			// send a request for the element...
			// do not set this until we have it returned...
			command = "dds|"+ind+"|"+key+"|"+iid;
			requestController(command);
		}
	}else if(key.length > 2){

		// we cycle through the indexes until we find matches...
		ikey = key.substring(0,2);
		lc = key.length;
		//alert(ikey); // you always referencing the master array which could lead to slow downs...
		
		master = AUTOS[ind]['K'][ikey];
		if(!AUTOS[ind]['K'][key]){
			AUTOS[ind]['K'][key]=[];
		}
		for(x in master){
			//alert(objToString(master[x]));
			if(master[x][0].substr(0,lc).toUpperCase() == key){
				AUTOS[ind]['K'][key][x] = master[x];
			}
		}

		AUTOS.key = key;



			AUTOS.key = key;
			AUTOS.ind = ind;
			AUTOS.iid = iid;
			
			if(!AUTOS[ind]['K'][key].div){
				AUTOS[ind]['I'][iid].obj = obj;
				fill_auto(ind,key,AUTOS[ind]['K'][key],iid); // reload using pre-existing arrays
			}else{
				write_select(ind,key,iid);
				AUTOS[ind]['I'][iid].div.style.display = 'block';
				AUTOS[ind]['I'][iid].isopen = 1;
				clearTimeout(AUTOS[ind]['I'][iid].timeout);
			}




		// Originally Write Select...
		//fill_auto(ind,key,AUTOS[ind]['K'][key],iid);
		//write_select(ind,key,iid);
	}
}


// this is trggerd by the select

function ddsClick(){

	var spl = this.id.split("|");
	var ind = spl[0];
	var iid = spl[1];
	var key = AUTOS.key;


	var obj = AUTOS[ind]['I'][iid].obj;
	var div = AUTOS[ind]['I'][iid].div;
	var sel = AUTOS[ind]['I'][iid].div.childNodes[0];
	var inp = AUTOS[ind]['I'][iid].div.ddsInput;

	inp.value = AUTOS[ind]['K'][key][sel.value][0];
	inp.parentNode.childNodes[0].value = sel.value;
	div.style.display = 'none';

	AUTOS[ind]['I'][iid].isopen = 0;

	// for usability... we search the tabindex for the next item. and focus it...

	if(typeof(TABIND[1][inp.id]) != 'undefined'){
		var p = TABIND[1][inp.id]+1;
		var l = TABIND[0].length;
		var i = (p > l)? 0: p;
		if(typeof(TABIND[0][i]) != 'undefined'){

			try{
				var obj = document.getElementById(TABIND[0][i]);
				if(!obj.value){
					document.getElementById(TABIND[0][i]).focus();
				}
			}catch(e){}
		}
	}

	var funcKey = ind+"|"+iid+"|DDSinp";

	var funcID = (typeof(STACKS['AUTODDS']) != 'undefined' && typeof(STACKS['AUTODDS'][funcKey]) != 'undefined')? STACKS['AUTODDS'][funcKey]: 0;

	if(funcID == 88){

		var price = AUTOS[ind]['K'][key][sel.value][1];

		document.getElementById('child-order_items-0-'+iid+'-cost').value = price;

		var qty = document.getElementById('child-order_items-0-'+iid+'-qty').value;

		qty = (qty == parseInt(qty) && qty > 0)? qty: 1;
		
		document.getElementById('child-order_items-0-'+iid+'-qty').value = qty;

		//alert(price);
	}else if(funcID == 17){

		var id = sel.value;
		var ind = 17;
	
		var obj = getRecordFromStack(ind,id,0); // TUCK THE INTERFACE LOADER INSIDE THIS FUNCTION???	
	}

	// grab the value...
	// transfer it to the hidden and visible input
	// var x = this.parentNode.ddsInput;
	// x.isfocused = false;
 	// x.value = AUTOS[AUTOS.ind]['K'][AUTOS.key][this.value];
	// x.parentNode.childNodes[0].value = this.value;
	// hide the object for later
	// this.parentNode.style.display = 'none';
	// x.focus();
}

// Just for now... not forever...

function imgSwapOpt(obj,target,scale,varCat,varInd,varID,varArr){

	imgSwap(obj,target,scale);

	try{
	
		if(typeof(varArr) != 'undefined' && varArr.length > 0){
			for(x in varArr){
				var vCat = varArr[x][0];
				var vInd = varArr[x][1];
				var vID = varArr[x][2];
				if(!vCat && vInd == 1 && vID > 0 && typeof(STACKS['AVAILP'][vID]) != 'undefined'){
					document.getElementById('prod_id').value = vID;
				}else if(vCat && vInd > 0 && vID > 0){
					document.getElementById("opt-1-"+vInd).value = vID;
				}
			}
		}

		set_prod_opt(0,0,null,0);
	}catch(e){
		pr(e);
	}

	// alert("vCat="+varCat+" vType="+varInd+" varId="+varID);

	updateProdTextuals();

}

function updateProdTextuals(rec_ind){

	var C = STACKS['ECOM'];
	var O = STACKS['ECOM']['O'];
	var A = STACKS['ECOM']['A'];
	var optVals = STACKS['ECOM']['optVals'];

	if(C[0]){

		document.getElementById('rec-'+rec_ind+'-T').innerHTML = A['t'];
		document.getElementById('rec-'+rec_ind+'-D').innerHTML = A['d'];
		document.getElementById('rec-'+rec_ind+'-P').innerHTML = A['p'];
	
		var varStr = '';
		for(z in O){
			if(typeof(O[z][optVals[z]]) == 'undefined'){continue;}
			varStr += O[z][optVals[z]] + " / ";
		}
	
		document.getElementById('rec-'+rec_ind+'-V').innerHTML = varStr.substring(0,(varStr.length - 3));

	}
}

function get_prod_opt_stock(A,optVals,varID,varInd){

	var obj = A[0];
	var ind = 0;
	var found = 0;
	var val = 0;

	for(var q in optVals){

		if(!parseInt(q)){continue;}

		val = parseInt(optVals[q]);
		val = (val > 0)? val: 0;

		ind = (q == varID)? varInd: val;
		ind = (ind > 0)? ind: 0;
		if(typeof(obj[ind]) != 'undefined'){
			obj = obj[ind];
			found = 1;
			continue;
		}
		found = 0;
	}

	// alert("VARID("+varID+") VARIND("+varInd+") VAL("+val+") OBJ("+obj['i']+")");

	return (found)? obj['i']: 0;
}

// I may want to consider an initializer... just to make it cleaner but it is not a requirement...

function set_prod_opt(varCat,varInd,obj,varID){

	var C = STACKS['ECOM'];
	var InvM = C[1];
	var InvS = C[3];

	// The cadence is messed up when switching to and from... wont fit more variety options in... could be an issue way way way down the line...
	// alert("varCat="+varCat+" varInd="+varInd+" varID="+varID);

	if(!varCat && varInd && varID){
		document.getElementById('prod_id').value = varID;
	}else if(C[0] && varCat && varInd && varID){
		document.getElementById("opt-"+varCat+"-"+varInd).value = varID;
	}

	var prodObj = document.getElementById('prod_id');
	var prod = (C[0])? prodObj.value: prodObj.options[prodObj.selectedIndex].value;
	var O = STACKS['OPTS'];
	var A = STACKS['AVAILP'][prod];
	var optVals = [];
	var optObjs = [];
	var optIcos = [];
	var optSIs = [];
	var in_stock = 0;
	var rec_ind = 2;

	var errBox = document.getElementById('addToCartMessage');

	if(errBox != null){
		errBox.innerHTML = ' ';
	}

	// pr("SETTING ECOM PROD("+prod+")");

	STACKS['ECOM']['O'] = O;
	STACKS['ECOM']['A'] = A;
	STACKS['ECOM']['optVals'] = optVals;
	STACKS['ECOM']['errBox'] = errBox;
	STACKS['ECOM']['prod'] = prod;

	if(typeof(A) == 'undefined'){

		// THEN THE PRODUCT DOESNT EXIST... OR IS UNAVAILBLE FOR ORDERING... SO WHAT TO DO??? SHOULD I RESET???
		// This is an issue because when clicking a catalog item which is unavailable for ordering it takes us to a page which defaults to the shirt.
		// How can I show the item not available for ordering???

		// I NEED TO SEND ARRAYS OF THE IMAGES OUT FROM THE SERVER... INCLUDING DEFAULTS...

		for(z in O){
			optVals[z] = 0;
		}

		// I NEED TO TRY AND CATCH A PRODUCT OPTION IMAGE...



		var x = 0;
		for(z in STACKS['AVAILP']){
			x = 1;
			prod = z;
			STACKS['ECOM']['A'] = A = STACKS['AVAILP'][prod];
			if(C[0]){
				prodObj.value = prod;
				STACKS['ECOM']['prod'] = prod;
			}else{
				pr("INCOMPLETE SELECT RESET");
			}
			break;
		}

		if(!x){
			pr("type A is undefined NEED TO SET TO BLANK IMAGE");
			return false;
		}
	}

	optVals[0] = prod;

	if(C[0]){
		for(var x in STACKS['AVAILP']){
			var itemId = 'optsON-0-1-'+x;
			var itemObj = document.getElementById(itemId);
			var className = (optVals[0] == x)? 'B': 'A';
			itemObj.className = 'optsON-0-1-'+className;
		}
	}

	for(z in O){
		optVals[z] = 0;
		try{
			optObjs[z] = document.getElementById("opt-1-"+z);
			optVals[z] = optObjs[z].value;

			if(typeof(A[z][optVals[z]]) == 'undefined'){
				for(x in A[z]){
					optVals[z] = x;
					break;
				}
			}
		}catch(e){
			pr("COULD NOT CATCH VALUE");
		}
		optIcos[z] = [];
		for(x in O[z]){
			optIcos[z][x] = document.getElementById("prodOpt"+z+"-"+x);
			if(optIcos[z][x] != null){
				optIcos[z][x].style.display = "none";
			}
		}
	}

	for(z in A){
		if(typeof(O[z]) == 'undefined'){
			continue;
		}

		optObjs[z].length=0;

		for(x in A[z]){

			in_stock = get_prod_opt_stock(A,optVals,z,x);

			if(!in_stock && InvM){
				continue;
			}

			if(optIcos[z][x] != null){
				optIcos[z][x].style.display = "block";
				if(InvS && InvS == z){
					optIcos[z][x].childNodes[0].childNodes[0].innerHTML = in_stock + " Left";
				}
			}

			if(!C[0]){
				var optL = optObjs[z].options.length;
				var optV = O[z][x];
				optV = (typeof(optV) != 'undefined')? optV: ' ';
				optObjs[z].options[optL]=new Option(optV,x);
				if(x == optVals[z]){
					optObjs[z].selectedIndex = optL;
				}
			}

			if(C[0]){
				var itemId = 'optsON-1-'+z+'-'+x;
				var itemObj = document.getElementById(itemId);
				var isSelected = (optVals[z] == x || (obj && obj.id == itemId))? 1: 0;
				if(itemObj != null){
					var className = (isSelected)? 'B': 'A';
					itemObj.className = 'optsON-1-'+z+'-'+className;
				}
				if(isSelected){
					optObjs[z].value = x;
				}
			}
		}
	}

	updateProdTextuals(rec_ind);

	updateProdImage();

	return false;
}

function add_to_cart(obj){ // routine to check availability with javascript...

	var C = STACKS['ECOM'];
	var InvP = C[4];
	var A = C['A'];
	var optVals = C['optVals'];
	var errBox = C['errBox'];

	obj.blur();

	if(!InvP){
		distro_erro("NO INV P (RETURNING TRUE)");
		return true;
	}

	if(optVals[1] == 0 && optVals[2] == 0){
		errBox.innerHTML = 'Please Make a Selection';
		return false;
	}

	var i = A[0][optVals[1]][optVals[2]]['i'];
	if(parseInt(i) == i && i > 0){
		return true;
	}

	errBox.innerHTML = 'Out of Stock. <br> Try a Different Selection.';
	return false;
}

function path_search_stack(path_arr,arr,depth){
	var l = path_arr.length;
	var y = path_arr;
	var z = arr;
	var f = 1;
	var key = 0;
	var zeroPath = 0;
	var depth = (!depth)? l: depth;

	for(var x = 0; x < l; x++){

		//pr("CYCLE x("+x+") y[x]("+y[x]+")");

		key = (!f || x >= depth)? 0: y[x];

		if(typeof(z[key]) == 'undefined'){
			f = 0;

			//pr("NOT FOUND ON CYCLE("+x+") DEPTH("+depth+") key("+key+") z("+arr+")");

			if(x < 3){
				key = 0;
				if(typeof(z[key]) == 'undefined'){
					//	pr("UNDEFINED DROP BACK A LEVEL("+x+") DEPTH("+depth+")");
					var p = path_search_stack(path_arr,arr,(x-1));
					return [0,p[1]];
				}
			}
			for(var a in z){
				key = a;
				break;
			}
		}
		//pr("STACK LEVEL ("+x+") WAS SET VAL("+z[y[x]]+")");
		z = z[key];
	}
	return [f,z];
}


function initProdOpt(){

	// when I come in from arrows. Not selection is found. If I can restore. Do it.

	// Try Restore if OPT STORE

	// IF NO OPT STORE AND AN OPT VAL... TRY TO MATCH ON OPT VAL...

	// I ALSO WANT TO UPDATE THE SELECTIONS WHEN I CLICK A PICTURE...

	// FOR NOW I LOOK FOR THE STACK SELECTION AND SET THE WIDGETS...

	var prodSel = STACKS['PRODSEL'];

	if(TRANS_OPT && typeof(prodSel[RECORD_INDEX]) != 'undefined' && typeof(prodSel[RECORD_INDEX][RECORD_ID]) != 'undefined' && typeof(prodSel[RECORD_INDEX][RECORD_ID][TRANS_OPT]) != 'undefined'){

		var prodSelSect = prodSel[RECORD_INDEX][RECORD_ID][TRANS_OPT];

		for(var x in prodSelSect){
			if(!parseInt(x)){
				document.getElementById('prod_id').value = prodSelSect[x][1];
				//pr("SETTING PROD=("+prodSelSect[x][1]+")");
				continue;
			}
			for(var y in prodSelSect[x]){
				var val = prodSelSect[x][y];
				var id = 'opt-'+x+'-'+y;
				//pr("id("+id+")");
				var obj = document.getElementById(id);
				obj.value = val;
			}
		}
		//pr("SELECTION FOR PAGE FOUND");
	}

	var store_found = 0;

//	if(typeof(PROD_SELECTION[RECORD_INDEX]) != 'undefined' && typeof(PROD_SELECTION[RECORD_INDEX][RECORD_ID]) != 'undefined'){
		//pr("SELECTION STORE FOUND");

//		store_found = 1;

//		if(TRANS_OPT){
			//pr("STORE MAY NOT MATCH REQUEST");
//		}
//	}

	var prodOpt = document.getElementById("prod_id");

	set_prod_opt(0,1,prodOpt);

	if(TRANS_OPT || !store_found){

		updateProdImage();

	}

//	if(typeof(PROD_SELECTION[RECORD_INDEX]) == 'undefined'){
//		PROD_SELECTION[RECORD_INDEX]=[];
//	}

//	PROD_SELECTION[RECORD_INDEX][RECORD_ID]=s;

}

function updateProdImage(){

	var c = STACKS['CIMGS'];
	var optVals = STACKS['ECOM']['optVals'];
	var s = [];
	s[0] = RECORD_INDEX;
	s[1] = RECORD_ID;
	s[2] = STACKS['ECOM']['prod'];
	s[3] = optVals[1];
	s[4] = optVals[2];
	s[5] = optVals[3];
	s[6] = optVals[4];
	s[7] = optVals[5];

	//	pr("STACKS['ECOM']['prod']"+STACKS['ECOM']['prod']);

	for(x in s){
		s[x] = (parseInt(s[x]) == s[x])? s[x]: 0;
	}

	//	pr("s("+s+")");

	var p = path_search_stack(s,c,0);
	var img = document.getElementById('tagged_image');

	if(p[0]){
		//pr("FULL STACK VALUE FOUND VAL("+p[1]+") s("+s+")");

		img.src = 'http://www.joytshirt.com/'+p[1][0];
		img.style.left = (p[1][1] < 0)? p[1][1]+'px':'0px';
		img.style.top = (p[1][2] < 0)? p[1][2]+'px':'0px';

	}else{
		//pr("PATH NOT FOUND VAL("+p[1]+") s("+s+")");

		img.src = 'http://www.joytshirt.com/'+p[1][0];
		img.style.left = (p[1][1] < 0)? p[1][1]+'px':'0px';
		img.style.top = (p[1][2] < 0)? p[1][2]+'px':'0px';
	}
}



function check_invoice_row(obj){
	alert("CALL TO CHECK");
}










var cssdropdown={aa:250,ab:false,ac:1,dmo:null,ie:document.all,ff:document.getElementById&&!document.all,st:undefined,bc:0,g:function(w,ot){var to=(ot=="left")?w.offsetLeft:w.offsetTop;
var p=w.offsetParent;return to=(ot=="left")? to+p.offsetLeft:to+p.offsetTop;},se:function(){if(this.bc<parseInt(this.dmo.offsetHeight)){this.bc+=10+(this.bc/10);
this.dmo.style.clip="rect(0 auto "+this.bc+"px 0)";}else{return;
}this.st=setTimeout("cssdropdown.se()",10);},sh:function(obj,e){if(this.ie||this.ff){this.dmo.style.left=this.dmo.style.top="-500px"}
if(e.type=="click"&&obj.visibility==hidden||e.type=="mouseover"){if(this.ac==1){if(typeof this.st!="undefined"){clearTimeout(this.st);}obj.clip="rect(0 auto 0 0)";
this.bc=0;this.se();}obj.visibility="visible";
}else if(e.type=="click"){obj.visibility="hidden";
}else if(e.type=="focus"){obj.visibility="visible";
}},iec:function(){return(document.cm&&document.cm!="BackCompat")?document.documentElement:document.body;
},ce:function(obj,w){var ed=0;
if(w=="rightedge"){var we=this.ie&&!window.opera?this.iec().scrollLeft+this.iec().clientWidth-15:window.pageXOffset+window.innerWidth-15;
this.dmo.cm=this.dmo.offsetWidth;
if (we-this.dmo.x < this.dmo.cm){ed=this.dmo.cm-obj.offsetWidth;
}}else{var te=this.ie && !window.opera? this.iec().scrollTop:window.pageYOffset;
var we=this.ie && !window.opera? this.iec().scrollTop+this.iec().clientHeight-15:window.pageYOffset+window.innerHeight-18;
this.dmo.cm=this.dmo.offsetHeight;
if (we-this.dmo.y < this.dmo.cm){ed=this.dmo.cm+obj.offsetHeight;
if((this.dmo.y-te)<this.dmo.cm);
ed=this.dmo.y+obj.offsetHeight-te;
}}return ed;
},di:function(obj,e,did){if(this.dmo!=null){this.dmo.style.visibility="hidden";
}this.ch();
if(this.ie||this.ff){obj.onmouseout=function(){cssdropdown.dhm()};

this.dmo=document.getElementById(did);
obj.onmousedown=function(){setTimeout("cssdropdown.dmo.style.visibility='hidden';",50);return !cssdropdown.ab;};

this.dmo.onmouseover=function(){cssdropdown.ch()};
this.dmo.onmouseout=function(e){cssdropdown.dh(e)};
this.dmo.onclick=function(){cssdropdown.dhm()};
this.sh(this.dmo.style, e);
this.dmo.x=this.g(obj.parentNode,"left");
this.dmo.y=(typeof DDMFIXEDOFFSETHEIGHT == "undefined")?this.g(obj,"top"):this.g(obj.parentNode.parentNode,"top");
this.dmo.style.left=this.dmo.x-this.ce(obj,"rightedge")+"px";
var chromemenuT = document.getElementById("chromemenu");
var bottomEdgeTest = this.ce(obj,"bottomedge");
var topPos = (typeof DDMFIXEDTOP == "undefined")? chromemenuT.offsetTop:DDMFIXEDTOP;
var offSetHeight = (typeof DDMFIXEDOFFSETHEIGHT == "undefined")? obj.offsetHeight: DDMFIXEDOFFSETHEIGHT;
this.dmo.style.top=topPos+obj.offsetTop+offSetHeight+1+"px";
/* PUT BOTTOM TEST <--- BACK FOR SNAP TO TOP if(bottomEdgeTest != 0){this.dmo.style.left = parseInt(this.dmo.style.left) + 150 + "px";}*/
}},cff:function(a,b){while(b.parentNode){if((b=b.parentNode)==a){return true;
}}return false;
},dh:function(e){var evtobj=window.event?window.event:e;
if(this.ie&&!this.dmo.contains(evtobj.toElement)){this.dhm();
}else if (this.ff&&e.currentTarget!= evtobj.relatedTarget&& !this.cff(evtobj.currentTarget,evtobj.relatedTarget)){this.dhm();
}},dhm:function(){this.delayhide=setTimeout("cssdropdown.dmo.style.visibility='hidden';",this.aa);
},ch:function(){if (this.delayhide!="undefined"){clearTimeout(this.delayhide);
}},startchrome:function(){for(var ids=0;
ids<arguments.length;
ids++){var mi=document.getElementById(arguments[ids]).getElementsByTagName("a");
for(var i=0;i<mi.length; i++){if(mi[i].getAttribute("rel")){
mi[i].onfocus=function(e){var event=typeof e!="undefined"?e:window.event;
cssdropdown.di(this,event,this.getAttribute("rel"));
}
mi[i].onmouseover=function(e){var event=typeof e!="undefined"?e:window.event;
cssdropdown.di(this,event,this.getAttribute("rel"));
}}}}}};


function ddmsClick(obj){
	var con = obj.parentNode.parentNode;
	var opts = con.childNodes[1];
	opts.style.display = (opts.style.display == 'block') ? 'none':'block';
}

function ddmsCC(obj){
	var con = obj.parentNode.parentNode;
	var opts = con.childNodes[1];
	var choice = con.childNodes[0].childNodes[0];
	var hidden = con.childNodes[0].childNodes[2];

	opts.style.display = 'none';

	choice.innerHTML = obj.innerHTML;
	choice.value = obj.value;
	hidden.value = obj.value;
}












var INP_BORDER_NORMAL = "solid 2px #CCC";var INP_BORDER_ERROR = "solid 2px #F00";var INP_BACKGROUND_NORMAL = "#fff";var INP_BACKGROUND_ERROR = "#BFD3E6";var IS_DISTRO = false;function inpblur(o){o.style.background=INP_BACKGROUND_NORMAL;}function inpfocus(o){o.style.background=INP_BACKGROUND_ERROR;}
