function objToString(o){s='';for(aProp in o){s += aProp + "\t";}return s;}
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;}

// these will expand to your script side validation routines...
// we need to expand this script to include a holder for indexes and lookups
// Table -> Index -> Value + Key
// Your going to need a frame controller...

var conM = "Do you really want to delete this Record?";

function switch_tab(obj,tab){
	var grp = document.getElementById(obj.id);
	var tab_set = document.getElementById(tab).childNodes;
	var y = grp.selectedIndex;
	var l = tab_set.length
	for(x=0;x < l;x++){
		if(x==y){
			tab_set[x].style.display = 'block';
		}else{
			tab_set[x].style.display = 'none';
		}
	}
}

function switch_rec_tab(rec_no,tab_no){
	x=1;
	for(var z = 0 ; z < 10; z ++){
		try{
			var tab_class = (tab_no == z)? 'aTabA': 'aTabB';
			document.getElementById('rec_tab_'+rec_no+'_'+z).className = tab_class;
			var tab_display = (tab_no == z)? 'block': 'none';
			document.getElementById('rec_pane_'+rec_no+'_'+z).style.display = tab_display;
		}catch(e){z=20;}
	}
	return false;
}


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,hook,i,s,rowMapIndex){

	var sort = false;
	if(typeof(obj) === 'object'){	
		var i = obj.options[obj.selectedIndex].value;
	}else if(i == 'n'){
		var i = 1+parseInt(ROWS.pn);
	}else if(i == 'p'){
		var i = parseInt(ROWS.pn)-1;
	}else if(i == 'c'){
		sort = true;
		var d = (ROWS.dir == 1)? 0: 1;
		var i = parseInt(ROWS.pn);
	}

	var loc = top.location.toString();
	var p = loc.indexOf('?');
	var p2 = loc.indexOf('#');
	if(p2 > 0){loc = loc.substr(0,p2);}
	var arr;
	var str = '';
	var h = top.location.hash.toString();
	p++;
	arr = loc.substr(p).split('&');
	var l = arr.length;

	for(x=0;x < l;x++){ // this should be a whitelist...
		if(arr[x] === 'undefined'){continue;}
		if(arr[x] == h){continue;}
		if(arr[x] == ''){continue;}
		if(arr[x].indexOf("#") > 0){continue;}
		if(arr[x].substr(0,3) == 'pn='){continue;}
		if(arr[x].substr(0,4) == 'srt='){continue;}
		if(arr[x].substr(0,4) == 'dir='){continue;}	
		//if(arr[x].substr(0,9) == 'rec_type='){continue;}			
		//if(arr[x].substr(0,9) == 'rec_edit='){continue;}
		//if(arr[x].substr(0,9) == 'rec_view='){continue;}
		if(arr[x].substr(0,8) == 'rec_new='){continue;}	
		if(arr[x].substr(0,3) == 'ps='){continue;}
		if(arr[x].substr(0,6) == 'prefs='){continue;}
		if(arr[x].substr(0,6) == 'print='){continue;}
		str += arr[x] + '&';
	}
	if(sort){
		str += 'srt=' + s + '&';
		str += 'dir=' + d + '&';
	}else{
		str += 'srt=' + ROWS.srt + '&';
		str += 'dir=' + ROWS.dir + '&';
	}
	str += 'pn=' + i;
	if(hook == 1){
		str += '&rmi='+rowMapIndex;
		//alert(str);
 		requestController(str,1,false);
	}else{
		top.location = top.location.pathname + '?' + str;		
	}
	return false;
}

AUTOS = [];

function keyup(obj){
	var ele,ind,spl,key,command,key_ind;
	key = obj.value.toUpperCase();
	key_ind = obj.parentNode.childNodes[0];

	if(key.length < 2){
		// check for an open select and close it...
		if(AUTOS.key && AUTOS.ind){
			//alert(AUTOS.key);
			AUTOS[AUTOS.ind].div.style.display = 'none';
			AUTOS.key = null;
			AUTOS.ind = null;
		}		
	}else if(key.length==2){
		ele = key_ind.name;
		spl = ele.split("|");		
		ind = spl[0];
		if(!AUTOS[ind]){AUTOS[ind]=[];}
		//if(!AUTOS[ind][key]){AUTOS[ind][key]=[];}		
		if(AUTOS[ind][key]){
			AUTOS.key = key;
			AUTOS.ind = ind;
			write_select();
			AUTOS[ind].div.style.display = 'block';
		}else{
			AUTOS[ind].obj = obj;
			// send a request for the element...
			// do not set this until we have it returned...
			command = 'dds|'+ind+"|"+key;
			requestController(command);
		}
	}else if(key.length > 2){
		// we cycle through the indexes until we find matches...
		key = key.toUpperCase();
		ele = key_ind.name;
		spl = ele.split("|");		
		ind = spl[0];	

		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][ikey];
		if(!AUTOS[ind][key]){
			AUTOS[ind][key]=[];
		}
		for(x in master){
			//alert(objToString(master[x]));
			if(master[x].substr(0,lc).toUpperCase() == key){
				AUTOS[ind][key][x] = master[x];
			}
		}

		AUTOS.key = key;
		write_select();

		//alert('new aray');
		//alert(AUTOS[ind][key]);
		
	}
}

FRMES = [];

// we split this into the normal requests for pane sections and we cut it down for commands to input boxes...

function requestController(command,hook,is_post){

	try{
		document.getElementById('dashboard_message').innerHTML='';
		document.getElementById('error_message').innerHTML='';
	}catch(e){}

	var l,ind,fr;
	// find an available frame...
	fr = top.frames;
	l = fr.length;
	if(l > 10){
		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...
		if(FRMES[x]['busy']!=true){
			FRMES[x]['busy']=true;
			FRMES[x]['command']=command;
			FRMES[x]['hook']=hook;
			// eventually your going to want to store the command and resend in case of failure...
			try{document.getElementById('loader').style.display='inline';}catch(e){}
			if(is_post == 'POST'){
				return fr[x];
			}else{
				fr[x].location.replace('index.php?trans='+command);
			}
			//}else{// when you come back to this you can just flag it to this file... you will need to wrap it in permissions...
			//	fr[x].location.replace('php/trans.php?id='+x+'&c='+command);
			//}
			
			return;
		}
	}

	//alert('create new');
	var newframe;
	newframe = document.createElement("IFRAME");
	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);
}

// 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);
	}
 	return;
}


// this is trggerd by the select

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

// this fills the div with the select information

function write_select(){

	// you will probably get faster performance by first hiding the div and then redisplaying it...
	val = AUTOS[AUTOS.ind][AUTOS.key];
	sel = AUTOS[AUTOS.ind].div.childNodes[0];
	// 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],x);
		//opt = document.createElement("OPTION");
		//opt.value = val[1][x]; 
		//opt.text = val[0][x];
		//sel.options.add(opt,x);
	}
	AUTOS[AUTOS.ind].div.style.display = (c)? 'block':'none';
}

function checkautofillclose(){
	if(!this.isfocused){
		AUTOS[AUTOS.ind].div.style.display = 'none';
	}
}

function fill_auto(ind,key,val){
	if(AUTOS[ind].div && AUTOS[ind][key]){
		//alert('reusing key: this should never happen... but it does...');
		AUTOS.key = key;
		AUTOS.ind = ind;
		write_select();
	}else{
		var obj = AUTOS[ind].obj;
		Offx = getOffset(obj,'left') - 2;
		Offy = getOffset(obj,'top') + 18;
		obj.onblur = function(){this.isfocused = false;setTimeout("checkautofillclose()",500);}
		obj.onmousedown = function(){this.isfocused = true;}
		obj.key = key;
		obj.ind = ind;
		
		w = obj.offsetWidth;
		if(!AUTOS[ind].div){ // you can probably initialize this when the page is sent rather than with javascript...
			div = document.createElement("DIV");	
			//div.setAttribute('style','position:absolute;top:'+Offy+'px;left:'+Offx+'px;width:'+w+'px;');
			div.style.position = "absolute";
			div.style.top = Offy+'px';
			div.style.left = Offx+'px';
			document.body.appendChild(div);
			sel = document.createElement("SELECT");
			sel.setAttribute('class','AdminSelectMult');
			sel.setAttribute('size','8');
			sel.onclick = ddsClick;
			div.appendChild(sel);			
			div.ddsInput = AUTOS[ind].obj;
			AUTOS[ind].div = div;
		}
		AUTOS.key = key;
		AUTOS.ind = ind;
		AUTOS[ind][key] = val;
		write_select();
	}
	return;
	//	newselect.setAttribute('class','AdminSelectMult');
	//	newselect.setAttribute('size','8');
	//	newselect.setAttribute('id','grabass');
	//	newselect.setAttribute('multiple','multiple');	
	//	sel = document.body.appendChild(newselect);
	//	sel = document.getElementById('grabass');
	//	alert(AUTOS[ind][key]['values']);
	//	var t = AUTOS[ind][key]['values'];
	//	var l = t[0].length; 
	//	for(var x=0; x < l; x++){
	//		sel.options[y]=new Option(t[1][x],t[0][x]);
	//		opt = document.createElement("OPTION");
	//		opt.value = t[1][x]; 
	//		opt.text = t[0][x];
	//		alert("value:"+ t[0][x]+"   Text:"+t[1][x]);
	//		newselect.options.add(opt,x);
	//	}
	//	obj.innerHTML = AUTOS[ind][key]['values'];
	//	alert(AUTOS[ind][key]['values']);
}

// This is an unmodified function taken from the drop down menu script
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;
}

var BLUR_CACHE = [];

function dofocus(obj){
	obj.className=obj.className+'B';
	if(obj.className == 'cknuminpCB'){
		BLUR_CACHE[obj.name] = obj.value;
		obj.value = '';
	}
}

function doblur(obj){
	c = obj.className;
	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);
	}
}

var slideController = new Object();
var enableSlide = 0;
//	if(obj.parentNode.childNodes[1].style.display=='none'){
//		obj.parentNode.childNodes[1].style.display='';
//		obj.parentNode.childNodes[2].value = 0;
//	}else{
//		obj.parentNode.childNodes[1].style.display='none';
//		obj.parentNode.childNodes[2].value = 1;
//	}	

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);
		}
	}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;
}

PANES = [];
LOADER = null;
cacheVal = false;
cacheKey = false;

function iNitAdmin(){
	PANES.var_sect = document.getElementById('var_sect').value; // sect and panes are one and the same...
	PANES.i = PANES.var_sect;
	PANES['containers'] = [];
	PANES['containers'][0] = document.getElementById('var_wrap');
	PANES[PANES.i] = PANES['containers'][0].childNodes[0];
}

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){
	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;
			hook = FRMES[x]['hook']; // there may be no need for this???
			//alert('load pane - match found - resetting controller to free');
		}
	}
	try{document.getElementById('loader').style.display='none';}catch(e){}
	return hook;
}

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

function loadPane(sect,html,err_arr,loc,shake){ // 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);
	var div = document.createElement("DIV");
	//alert(html);
	if(typeof(loc) == 'string'){
		//alert('Loc'+loc);
		top.location.replace(loc);
		return true;
	}else if(typeof(err_arr) == 'object'){
		try{displayError(err_arr['success'],err_arr['message'])}catch(e){}
		// we need to know the name... the status... and any new value...
		if(err_arr['success'] == 1){
			//alert('PASS NEED TO SHOW MESSAGE... OR LOAD A NEW PAGE...');
		}else{
			for(field in err_arr['fields']){
				//alert(objToString(err_arr['fields'][field]));
				if(err_arr['fields'][field][1]){
					document.getElementById(field).style.border="solid 2px #F00";
				}
			}
			document.getElementById('error_message').innerHTML=err_arr['message'];
		}
	}else{
		div.innerHTML = html;
	}
	PANES[sect] = div;
	//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 loadRows(sect,html,pane,pn,sort,sortDir,rowIndex){ 
	var hook = clearController(sect);
	if(typeof(ROWS[pane]) === 'undefined'){
		ROWS[pane] = [];
	}
	//alert(pane);
	//alert(html);
	eval(html);
	var keys = "s"+sort+"-d"+sortDir+"-n"+pn;
	if(typeof(ROWS[pane][rowIndex][keys]) === 'undefined'){
		alert('internal script error... bad index on row sort in admin.js... shut off fast rows in page preferences...');
		alert(keys);
		alert(objToString(ROWS[pane][rowIndex]));
	}else{
		var ind = ROWS[pane][rowIndex][keys];
	}

	var rowTable = document.getElementById('rowTable-'+rowIndex);
	var rows = rowTable.childNodes[0].childNodes;
	var L1 = rows.length;
	for(x=1;x<L1;x++){
		var cols = rows[x].childNodes;
		var L2 = cols.length;
		rows[x].style.background = (RCLASS[pane][rowIndex][keys][(x-1)] == 1)? '#ddd': '#ccc';
		for(y=0;y<L2;y++){
			try{
				if(typeof(ind[(x-1)]) !== 'undefined'){
					var val = ROWS[pane][rowIndex][ind[(x-1)]][y];
					val = val.replace(/&gt;/g, ">");
					val = val.replace(/&lt;/g, "<");
					val = val.replace(/&amp;/g, "&");
					val = val.replace(/&quot;/g, '"');
				}else{
					val = '&nbsp;';
				}
				cols[y].childNodes[0].innerHTML = val;
			}catch(e){}
		}
	}

	ROWS.pn = pn++;
	ROWS.srt = sort;
	ROWS.dir = sortDir;	

	// 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(ROWS.srt == col_id){
			cols[y].className = (ROWS.dir==1)? 'but_in_up':'but_in_down';
		}else{
			cols[y].className = 'but_out';
		}
	}

	var ps = document.getElementById('page_select');
	ps.options.selectedIndex = parseInt(ROWS.pn);
	var total_page_count = ps.options.length;
	try{
		var p_prev = document.getElementById('page_prev').childNodes[0];
		p_prev.style.display = (parseInt(ROWS.pn) == 0)? 'none': 'block';
	}catch(e){}
	try{
		var p_next = document.getElementById('page_next').childNodes[0];
		p_next.style.display = (parseInt(ROWS.pn) == (total_page_count-1))? 'none': 'block';	
	}catch(e){}

	try{
		var page_nums = document.getElementById('page_nums');
		var s_cap = 1;
		var e_cap = (parseInt(ROWS.pn) + 4);
		if(e_cap > total_page_count){e_cap = total_page_count;s_cap = e_cap - 6;}else{s_cap = parseInt(ROWS.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) == parseInt(ROWS.pn))? 'underline':'none';
			but.innerHTML = s_cap;
			but.setAttribute('rel',(s_cap-1));
			s_cap++;
		}
	}catch(e){}
}

function hidePane(sect){
	return false;
	PANES[sect].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,'Please Choose a File');
			return false;
		}else if(record_type==''){
			displayError(0,'Please Choose a Record Type');
			return false;			
		}else if(file_type==''){
			displayError(0,'Please Choose a File Type');
			return false;			
		}		
	}
}

function displayError(success,message){
	var dash = document.getElementById('dashboard_message');
	dash.innerHTML = message;
	var message_color = (success)? "#00ff00": "#ff0000";
	dash.style.backgroundColor = message_color;
}

function savePane(sect,pane,mode){

	//alert('SavePane() --- PANES.i= ' + PANES.i + ' sect= ' + sect + ' pane= ' + pane);
	if(PANES.i.substr(0,2) == 'F-'){
		PANES[PANES.i].paneform = document.getElementById(PANES.i);		
	}else{
		PANES[PANES.i].paneform = document.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");
	var loc = top.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);	
	//Tform.setAttribute('action','?trans='+PANES.i);	
	//alert(thepath+'/index.php?trans='+PANES.i);

	var c = PANES[PANES.i].paneform.elements.length;
	var cacheVals=[];
	//alert('elements length='+c);

	for(x=0;x < c; x++){
		var ele = PANES[PANES.i].paneform.elements[x];
		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.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'){
				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'){
				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{
				alert('Unknown Input Type=' + ele.type);
			}
		}else{
			alert('Unknown Element Type=' + ele.nodeName);
		}
	}

	//getUserData
	if(typeof(cacheKey) == 'object' && cacheVal){
		ckey = cacheKey.value.replace(/^\s+|\s+$/g, '');
		cval = cacheVals[0].value.replace(/^\s+|\s+$/g, '');
		var temp = RCD.createElement("INPUT");
		temp.setAttribute('name',cacheKey.name);
		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);
	// 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 loadLogin(key,val){
	// This is used to test the integrity of the encryption...
	document.getElementById("uid").value=key;
	document.getElementById("pwd").value=val;	
}

// START DRAGGABLE WINDOW LAYER
// ------------------------------------------------ Don't forget about docking boxes script

isIE=document.all;
isNN=!document.all&&document.getElementById;
isN4=document.layers;
isHot=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 ddN4(whatDog){
  if (!isN4) return;
  N4=eval(whatDog);
  N4.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
  N4.onmousedown=function(e){
    N4.captureEvents(Event.MOUSEMOVE);
    N4x=e.x;
    N4y=e.y;
  }
  N4.onmousemove=function(e){
    if (isHot){
      N4.moveBy(e.x-N4x,e.y-N4y);
      return false;
    }
  }
  N4.onmouseup=function(){
    N4.releaseEvents(Event.MOUSEMOVE);
  }
}

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";
}

//document.onmousedown=ddInit;
//document.onmouseup=Function("ddEnabled=false");





/**************************************************
 * dom-drag.js
 * 09.25.2001
 * www.youngpup.net
 * Script featured on Dynamic Drive (http://www.dynamicdrive.com) 12.08.2005
 **************************************************
 * 10.28.2001 - fixed minor bug where events
 * sometimes fired off the handle, not the root.
 **************************************************/

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;
	}
};


