

/*************************************************************************************************************************/
/* Inheritance Function
/*************************************************************************************************************************/
Function.prototype.inheritsFrom=function(parent){
	if(parent.constructor == Function){
		this.prototype = new parent;		
		this.prototype.constructor = this;
		this.prototype.parent = parent.prototype;
	}else{
		this.prototype = parent;
		this.prototype.constructor = this;
		this.prototype.parent = parent;
	}
	return this;
}

/*************************************************************************************************************************/
/* ajaxEngine
/*************************************************************************************************************************/
function ajaxEngine(){
	this.name='ajaxEngine';
	this.processRequest=function(req,fnc){
		with(req){ if(readyState == 4){ if(status == 200){ if(fnc){ fnc(responseText); } } } }
	}
}
ajaxEngine.prototype.makeRequest=function(mth,url,dat,fnc){
	var req=false;
	var self=this;

	if(window.XMLHttpRequest){
		req = new XMLHttpRequest();
		if(req.overrideMimeType)
			req.overrideMimeType('text/xml');
	}else if(window.ActiveXObject){
		try{
			req = new ActiveXObject('Msxml2.XMLHTTP');
		}catch (e) {
			try{
				req = new ActiveXObject('Microsoft.XMLHTTP');
			}catch (e) {}
		}
	}

	if(!req){
		alert('Cannot create an XMLHTTP Instance');
		return false;
	}

	with(req){
		onreadystatechange=function(){ self.processRequest(req,fnc); };
		open(mth,url,true);
		setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		send(dat);
	}
}

/*************************************************************************************************************************/
/* Base Class - controlPanel
/*************************************************************************************************************************/
var controlPanel = function(){
	this.aje=new ajaxEngine();
	this.name='controlPanel';
	this.contentID;
	this.tableID;
	this.countyID;
	this.authorized='';
	this.userDocs='';
	this.host='www.simpsontax.com';
	var me=this;

	this.open=function(cnt,tbl,cty){
		me.contentID=cnt;
		me.tableID=tbl;
		me.countyID=cty;
		if(typeof(tinyMCE) != 'undefined'){
			tinyMCE.pageID=me.contentID;
			tinyMCE.countyID=me.countyID;
			tinyMCE.ajaxEngine=me.aje;
		}
		if(me.authorized == ''){ me.promptLogin(); }
		else{ me.showContent(); }
	};

	this.hide=function(){
		document.getElementById('controlPanel').innerHTML='';
		document.getElementById('controlPanel').style.visibility='hidden';
	};

	this.promptLogin=function(){
		me.aje.makeRequest('GET','http://'+me.host+'/shared/src/login.asp?county='+me.countyID,null,me.displayLogin);
	};

	this.displayLogin=function(htm){
		var cp=document.getElementById('controlPanel');
		var wth=305;
		var hgt=120;

		cp.style.border='2px solid black';
		cp.style.width=wth+'px';
		cp.style.height=hgt+'px';
		cp.style.visibility='visible';
		cp.style.position='absolute';
		cp.style.top='50%';
		cp.style.left='50%';
		cp.style.marginLeft='-'+(wth / 2)+'px';
		cp.style.marginTop='-'+(hgt / 2)+'px';

		cp.innerHTML=htm;
		document.getElementById('frmLogin').onkeypress=me.checkSubmit;
	};

	this.checkSubmit=function(e){
		if(!e){ e = window.event; }
		if(e.which){ if(e.which == 13){ me.submitLogin(); } }
		else{ if(e.keyCode == 13){ me.submitLogin(); } }
	};

	this.submitLogin=function(){
		var un=document.getElementById('uname').value;
		var pw=document.getElementById('pword').value;
		if(un == '' || pw == ''){ alert('Username and Password are required.'); }
		else{ me.aje.makeRequest('GET','http://'+me.host+'/shared/src/auth.asp?uname='+un+'&pword='+pw,null,me.validateLogin); }
	};

	this.validateLogin=function(msg){
		if(msg == 'OK'){
			me.authorized='OK';
			me.showContent();
		}else{
			me.authorized='';
			document.getElementById('msg').innerHTML=msg;
		}
	};
}
controlPanel.prototype.showContent=function(){
	;
}
/*************************************************************************************************************************/
/* downloadAdmin Class - Derived from controlPanel
/*************************************************************************************************************************/
function downloadAdmin(){
	this.name='downloadAdmin';
	
	this.parent.showContent=function(){
		document.location.href='downloadpage.asp';
	}
}
downloadAdmin.inheritsFrom(controlPanel);
/*************************************************************************************************************************/
/* newsEditor Class - Derived from controlPanel
/*************************************************************************************************************************/
function newsEditor(){
	this.name='newsEditor';
	this.currentNewsItem;
	var me=this;

	if(typeof(tinyMCE) != 'undefined'){
		tinyMCE.init({
			mode : "textareas",
			editor_selector : "mceEditor",
			plugins : "ajaxSave,preview,upload,table,paste,new",
			save_enablewhendirty : false,
			plugin_preview_width : "800",
			plugin_preview_height : "600",
			content_css : 'http://'+me.host+'/shared/tiny_mce/style.css',
			external_image_list_url : 'http://'+me.host+'/shared/tiny_mce/imagelist.js',
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_buttons1 : "new,ajaxSave,preview,separator,bold,italic,underline,strikethrough,sub,sup,charmap,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,outdent,indent,separator,fontselect,fontsizeselect,separator,forecolor,backcolor,separator,link,unlink,image,upload,separator,hr,removeformat,separator,undo,redo,separator,help",
			theme_advanced_buttons2 : "table,delete_table,separator,row_props,cell_props,separator,row_before,row_after,delete_row,separator,col_before,col_after,delete_col,separator,split_cells,merge_cells,separator",
			theme_advanced_buttons3 : "",
			width : "100%",
			height : '300px',
			ajaxSave_request_url : 'http://'+me.host+'/shared/src/savedata.php',
			ajaxSave_callback : 'editor.getNews',
			ajaxSave_title : 'ntitle',
			force_br_newlines : true,
			cleanup_on_strtup : true,
			preformatted : true
		});
	}


	this.parent.showContent=function(){
		var cp=document.getElementById('controlPanel');
		var wth=980;
		var hgt=575;

		cp.style.border='1px solid black';
		cp.style.width=wth+'px';
		cp.style.height=hgt+'px';
		cp.style.visibility='visible';
		cp.style.position='absolute';
		cp.style.top='50%';
		cp.style.left='50%';
		cp.style.marginLeft='-'+(wth / 2)+'px';
		cp.style.marginTop='-'+(hgt / 2)+'px';
		cp.style.backgroundColor='white';
		me.aje.makeRequest('GET','http://'+me.host+'/shared/src/editnews.asp?county='+me.countyID,null,me.displayPage);
	};

	this.displayPage=function(htm){
		document.getElementById('controlPanel').innerHTML=htm;
		if(typeof(tinyMCE) != 'undefined'){
			tinyMCE.execCommand('mceAddControl',false,'news');
			me.getNews();
		}
	};

	this.getNews=function(){
		me.aje.makeRequest('GET','http://'+me.host+'/shared/src/getnews.php?county='+me.countyID,null,me.showNews);
	};

	this.showNews=function(htm){
		document.getElementById('news_items').innerHTML=htm;
		me.aje.makeRequest('GET','http://'+me.host+'/shared/inc/news_data.asp?county='+me.countyID,null,me.showNewsData);
	};

	this.showNewsData=function(htm){
		document.getElementById('newsvw').innerHTML=htm;
	};

	this.getNewsItem=function(id){
		me.aje.makeRequest('GET','http://'+me.host+'/shared/src/getnewsitem.php?county='+me.countyID+'&newsid='+id,null,me.showNewsItem)
	};

	this.showNewsItem=function(htm){
		var dat = htm.split('|-|');
		tinyMCE.currentNewsItem=dat[0];
		document.getElementById('ntitle').value=dat[1];
		tinyMCE.selectedInstance.getBody().innerHTML=dat[2];
	};

	this.deleteNewsItems=function(){
		var id,stg='';
		var chk = document.getElementsByName('news_item');
		for(i=0;i<chk.length;i++){
			if(chk[i].checked){
				id=chk[i].id.replace('news_item','');	
				stg+=id+',';
			}
		}
		me.aje.makeRequest('POST','http://'+me.host+'/shared/src/deletenews.php','county='+me.countyID+'&keys='+stg.substr(0,stg.length-1),me.getNews);
	};
}
newsEditor.inheritsFrom(controlPanel);

/*************************************************************************************************************************/
/* pageEditor Class - Derived from controlPanel
/*************************************************************************************************************************/
function pageEditor(){
	this.name='pageEditor';
	var me=this;

	if(typeof(tinyMCE) != 'undefined'){
		tinyMCE.init({
			mode : "textareas",
			editor_selector : "mceEditor",
			plugins : "ajaxSave,preview,upload,table",
			save_enablewhendirty : true,
			plugin_preview_width : "800",
			plugin_preview_height : "600",
			content_css : 'http://'+me.host+'/shared/tiny_mce/style.css',
			external_image_list_url : 'http://'+me.host+'/shared/tiny_mce/imagelist.js',
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_buttons1 : "ajaxSave,preview,separator,bold,italic,underline,strikethrough,sub,sup,charmap,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,outdent,indent,separator,fontselect,fontsizeselect,separator,forecolor,backcolor,separator,link,unlink,image,upload,separator,hr,removeformat,separator,help",
			theme_advanced_buttons2 : "table,delete_table,separator,row_props,cell_props,separator,row_before,row_after,delete_row,separator,col_before,col_after,delete_col,separator,split_cells,merge_cells,separator",
			theme_advanced_buttons3 : "",
			width : "100%",
			height : '550px',
			ajaxSave_request_url : 'http://'+me.host+'/shared/src/savepage.php',
			ajaxSave_callback : 'editor.getPageContent',
			ajaxSave_title : ''
		});
	}

	this.parent.showContent=function(){
		var cp=document.getElementById('controlPanel');
		var wth=975;
		var hgt=600;

		cp.style.border='1px solid black';
		cp.style.width=wth+'px';
		cp.style.height=hgt+'px';
		cp.style.visibility='visible';
		cp.style.position='absolute';
		cp.style.top='50%';
		cp.style.left='50%';
		cp.style.marginLeft='-'+(wth / 2)+'px';
		cp.style.marginTop='-'+(hgt / 2)+'px';
		cp.style.backgroundColor='white';
		me.aje.makeRequest('GET','http://'+me.host+'/shared/src/editpage.asp?page='+me.contentID+'&county='+me.countyID,null,me.displayPage);
	};

	this.displayPage=function(htm){		
		document.getElementById('controlPanel').innerHTML=htm;
		if(typeof(tinyMCE) != 'undefined'){
			tinyMCE.execCommand('mceAddControl',false,'content');
			me.getPageContent();
		}
	};

	this.getPageContent=function(){
		me.aje.makeRequest('GET','http://'+me.host+'/shared/src/getpage.php?county='+me.countyID+'&page='+me.contentID,null,me.showPageContent);
	}
	this.showPageContent=function(htm){
		if(tinyMCE){
			var dat=htm.split('|-|');
			tinyMCE.selectedInstance.getBody().innerHTML=dat[2];
		}
		document.getElementById('pgvw').innerHTML=dat[2];
	}
}
pageEditor.inheritsFrom(controlPanel);

/*************************************************************************************************************************/
/* tableEditor Class - Derived from controlPanel
/*************************************************************************************************************************/
function tableEditor(){

	this.name='tableEditor';
	var me=this;

	this.parent.showContent=function(){
		var cp=document.getElementById('controlPanel');
		var wth=980;
		var hgt=600;

		cp.style.border='1px solid black';
		cp.style.width=wth+'px';
		cp.style.height=hgt+'px';
		cp.style.visibility='visible';
		cp.style.position='absolute';
		cp.style.top='50%';
		cp.style.left='50%';
		cp.style.marginLeft='-'+(wth / 2)+'px';
		cp.style.marginTop='-'+(hgt / 2)+'px';
		cp.style.backgroundColor='white';
		me.aje.makeRequest('GET','http://'+me.host+'/shared/src/edittable.asp?table='+me.tableID+'&county='+me.countyID,null,me.displayPage);
	};

	this.displayPage=function(htm){		
		document.getElementById('controlPanel').innerHTML=htm;
	};

	this.checkForFile=function(){
		document.getElementById('status').innerHTML='Uploading File. Please Wait...';
		me.aje.makeRequest('GET','http://'+me.host+'/shared/inc/xlsup.php?userfile='+document.getElementById('userfile').value+'&wait=3',null,me.procXLS);
	};

	this.procXLS=function(rlt){
		if(rlt == 1){
			document.getElementById('status').innerHTML='Storing File. Please Wait...';
			me.aje.makeRequest('GET','http://'+me.host+'/shared/src/convertxls.php?table='+me.tableID+'&county='+me.countyID+'&userfile='+document.getElementById('userfile').value,null,me.xlsResults);
		}else{ document.getElementById('status').innerHTML='An Error Occured During the Upload.'; }
	};

	this.xlsResults=function(rlt){
		if(rlt == 1){ 
			document.getElementById('status').innerHTML='Retrieving Table. Please Wait...';
			me.displayTable(); 
		}else{ document.getElementById('status').innerHTML='An Error Occured During the Upload.'; }
	};

	this.displayTable=function(){
		me.aje.makeRequest('GET','http://'+me.host+'/shared/src/tablepreview.php?tableid='+me.tableID+'&county='+me.countyID,null,me.displayTablePreview);
	};

	this.displayTablePreview=function(htm){

		var dat = htm.split('|-|');				//Split returned string by '|-|'
		var css = document.styleSheets[1];
		var rules = css.cssRules ? css.cssRules : css.rules;	//Get the correct rules object
		var tmp,rls;

		//Remove all existing rules from the style sheet for the table

		if(css.deleteRule){ //For standards compliant browsers
			for(i=rules.length-1;i>=0;i--){
				css.deleteRule(i);
			}
		}else if(css.removeRule){ //For IE
			for(i=rules.length-1;i>=0;i--){
				css.removeRule(i);
			}
		}

		//Remove <style></style> and <!-- --> tags
		dat[0]=dat[0].replace('<style type="text/css" id="data_Styles">','');
		dat[0]=dat[0].replace('<!--','');
		dat[0]=dat[0].replace('-->','');
		dat[0]=dat[0].replace('</style>','');

		try{
			//Seperate the rules
			tmp = dat[0].split('}');
			for(x=0;x<tmp.length;x++){
				if(tmp[x] != ''){ //Split the selector and the rule(s)
					rls=tmp[x].split('{');
					if(rls[1]){
						if(css.addRule){css.addRule(rls[0],rls[1]); }
						else if(css.insertRule){ 
							css.insertRule(rls[0]+'{'+rls[1]+'}',rules.length); 
						}
					}
				}
			}
		}catch(e){ 
			alert(e.description + '\n' + e.lineNumber + '\n' + rules.length); 
		}
		//Display the table and finish the procedure
		document.getElementById('table_view').innerHTML=dat[1];
		document.getElementById('tblvw').innerHTML=dat[1];
		document.getElementById('status').innerHTML='Upload Complete.';
	};
	
	this.getTable=function(){
		location.href='http://'+me.host+'/shared/inc/gettable.asp?table='+me.tableID+'&county='+me.countyID;
	}
}
tableEditor.inheritsFrom(controlPanel);

/*************************************************************************************************************************/
/* calcEditor Class - Derived from controlPanel
/*************************************************************************************************************************/
function calcEditor(){
	this.name='calcEditor';
	var me=this;
	var fncpth='http://'+me.host+'/shared/src/calcfunctions.asp';

	this.parent.showContent=function(){
		var cp=document.getElementById('controlPanel');
		var wth=600;
		var hgt=450;

		cp.style.border='1px solid black';
		cp.style.width=wth+'px';
		cp.style.height=hgt+'px';
		cp.style.visibility='visible';
		cp.style.position='absolute';
		cp.style.top='50%';
		cp.style.left='50%';
		cp.style.marginLeft='-'+(wth / 2)+'px';
		cp.style.marginTop='-'+(hgt / 2)+'px';
		cp.style.backgroundColor='white';
		me.aje.makeRequest('GET','http://'+me.host+'/shared/src/editcalc.asp?county='+me.countyID,null,me.displayPage);
	};

	this.displayPage=function(htm){
		var cp=document.getElementById('controlPanel');
		cp.innerHTML=htm
		me.displayDistricts();
	};

	this.displayDistricts=function(){
		me.aje.makeRequest('GET',fncpth+'?method=8&args=lstDistricts,onclick="editor.showTaxRate()",'+me.countyID,null,me.loadDistricts);
		me.aje.makeRequest('GET',fncpth+'?method=8&args=lstCurDistricts,onclick="editor.showDistrict()",'+me.countyID,null,me.loadCurrentDistricts);

		//Repeated for issue with IE
		me.aje.makeRequest('GET',fncpth+'?method=8&args=lstDistricts,onclick="editor.showTaxRate()",'+me.countyID,null,me.loadDistricts);
		me.aje.makeRequest('GET',fncpth+'?method=8&args=lstCurDistricts,onclick="editor.showDistrict()",'+me.countyID,null,me.loadCurrentDistricts);

		document.getElementById('trate').value='';
		document.getElementById('dname').value='';
	};

	this.loadDistricts=function(htm){
		document.getElementById('taxDist').innerHTML=htm;
	};

	this.loadCurrentDistricts=function(htm){
		document.getElementById('currentTaxDist').innerHTML=htm;
	};

	this.showTaxRate=function(){		
		me.aje.makeRequest('GET',fncpth+'?method=7&args='+document.getElementById('lstDistricts').value+','+me.countyID,null,me.displayTaxRate);
	};

	this.displayTaxRate=function(vlu){
		document.getElementById('trate').value=vlu;
	};

	this.showDistrict=function(){
		me.aje.makeRequest('GET',fncpth+'?method=5&args='+document.getElementById('lstCurDistricts').value+','+me.countyID,null,me.displayDistrict);
	};

	this.displayDistrict=function(vlu){
		document.getElementById('dname').value=vlu;
	};

	this.isNumeric=function(tval){
		
		var validChars = '0123456789.';
		var char;
		
		char = tval.charAt(0);
		
		if(validChars.indexOf(char) == -1)
			return false;
		else
			return true;
	};

	this.makeUpper=function(e){		
		if(!e){ e = window.event; }
		var knm,kcr;

		knm = e.keyCode || e.which;
		if(knm != 8 && knm != 13 && knm){
			kcr=String.fromCharCode(knm).toUpperCase().charCodeAt(0);

			if(window.event){ e.keyCode = kcr; }
			else if(e.which){
				var newEvent=document.createEvent('KeyEvents');
				newEvent.initKeyEvent('keypress',true,true,document.defaultview,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,0,kcr);
				e.preventDefault();
				e.target.dispatchEvent(newEvent);
			}
		}
	};

	this.limitInput=function(e){
		if(!e){ e = window.event; }
		var knm=e.keyCode || e.which;
		var kcr=String.fromCharCode(knm);		
		var ctr;
		if(e.target){ ctr = e.target; }
		else{ ctr = e.srcElement; }
		var tmp = ctr.value;

		if(kcr == '.'){
			if(tmp.indexOf(kcr) != -1){
				if(window.event){ event.keyCode = 0; }
				else if(e.which){
					var newEvent=document.createEvent('KeyEvents');
					newEvent.initKeyEvent('keypress',true,true,document.defaultview,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,0,'');
					e.preventDefault();
					ctr.dispatchEvent(newEvent);
				}
				return;
			}
		}
		if(!me.isNumeric(kcr)){
			if(window.event){ event.keyCode = 0; }
			else if(e.which){
				var newEvent=document.createEvent('KeyEvents');
				newEvent.initKeyEvent('keypress',true,true,document.defaultview,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,0,'');
				e.preventDefault();
				ctr.dispatchEvent(newEvent);
			}
			return;
		}
	};

	this.doAction=function(act){
		var ctl;
		switch(act){
			case 1:
				ctl=document.getElementById('lstCurDistricts');
				if(ctl.selectedIndex != -1){
					me.aje.makeRequest('POST',fncpth,'method=1&args='+ctl.value+','+me.countyID,null);
				}else{ alert('Select a District before performing this action.'); }
				me.displayDistricts();
				break;
			case 2:
				ctl=document.getElementById('lstCurDistricts');
				ctl.selectedIndex=-1;
				document.getElementById('dname').value='';
				break;
			case 3:
				ctl=document.getElementById('lstDistricts');
				if(ctl.selectedIndex != -1){
					me.aje.makeRequest('POST',fncpth,'method=4&args='+ctl.value+','+document.getElementById('trate').value+','+me.countyID,null);
				}else{ alert('Select a District before performing this action.'); }
				break;
			case 4:
				ctl=document.getElementById('lstCurDistricts');
				if(document.getElementById('dname').value != ''){
					me.aje.makeRequest('POST',fncpth,'method=2&args='+encodeURIComponent(document.getElementById('dname').value)+','+ctl.value+','+me.countyID,null);
				}else{ alert('Enter a District Name before performing this action.'); }
				me.displayDistricts();
				break;
		}
	};
}
calcEditor.inheritsFrom(controlPanel);

/*************************************************************************************************************************/
/* photoEditor Class - Derived from controlPanel
/*************************************************************************************************************************/
function photoEditor(){
	this.name='photoEditor';
	var me=this;
	var fncpth='http://'+me.host+'/shared/src/photofunctions.php';
	this.testID='';

	this.parent.showContent=function(){
		var cp=document.getElementById('controlPanel');
		var wth=665;
		var hgt=430;

		cp.style.border='1px solid black';
		cp.style.width=wth+'px';
		cp.style.height=hgt+'px';
		cp.style.visibility='visible';
		cp.style.position='absolute';
		cp.style.top='50%';
		cp.style.left='50%';
		cp.style.marginLeft='-'+(wth / 2)+'px';
		cp.style.marginTop='-'+(hgt / 2)+'px';
		cp.style.backgroundColor='white';
		//alert(me.imagePath);
		if(me.testID != ''){ me.countyID = me.testID; }
		me.aje.makeRequest('GET','http://'+me.host+'/shared/src/editphotos.asp?county='+me.countyID,null,me.displayPage);
	};

	this.getFileList=function(){	
		document.getElementById('txtUpCap').value = '';	
		var pth=location.href.substring(0,location.href.lastIndexOf('/')+1) + 'i/'
		me.aje.makeRequest('GET','http://'+me.host+'/shared/src/getphotolist.php?county='+me.countyID+'&path='+pth,null,me.displayFileList);
	};

	this.displayFileList=function(htm){
		var sel = document.getElementById('lstFiles');
		sel.options.length = 0;
		var arr = htm.split('^');
		var len = arr.length;
		var itm = null;
		if(htm != ''){
			for(var i=0;i<len;i++){
				itm = arr[i].split('|');
				sel.options[sel.length]=new Option(itm[0],itm[1]);
			}
		}
		document.getElementById('txtCap').value = '';
		var smp = document.getElementById('preview');
		smp.innerHTML='';
		//document.getElementById('uploadForm').reset();

	};

	this.displayPage=function(htm){
		var cp=document.getElementById('controlPanel');
		cp.innerHTML=htm;
		document.getElementById('county').value = me.countyID;
		me.getFileList();
	};

	this.showSelected=function(){
		var sel = document.getElementById('lstFiles');
		var cap = document.getElementById('txtCap');
		var smp = document.getElementById('preview');
		cap.value = sel.options[sel.selectedIndex].value;
		smp.innerHTML = '<img src="'+this.imagePath+sel.options[sel.selectedIndex].text+'?v=1" alt="Preview" height="235" />';
	}

	this.deletePhoto=function(){
		var sel = document.getElementById('lstFiles');
		if(sel.selectedIndex > -1){
			if(confirm('Delete the selected photo?')){
				me.aje.makeRequest('GET',fncpth+'?method=1&photo=' + sel.options[sel.selectedIndex].text + '&county=' + me.countyID,null,me.getFileList);
			}
			
		}else{
			alert('You must first select an existing Photo.');
		}
	}

	this.updatePhoto=function(){
		var sel = document.getElementById('lstFiles');
		var cap = document.getElementById('txtCap');
		if(sel.selectedIndex == -1){
			alert('You must first select an existing Photo.');
			return;
		}
		me.aje.makeRequest('GET',fncpth+'?method=2&photo=' + sel.options[sel.selectedIndex].text + '&caption=' + cap.value + '&county=' + me.countyID,null,me.getFileList);
	}

	this.uploadPhoto=function(){
		var img = document.getElementById('image');
		var cap = document.getElementById('txtUpCap');
		if(img.value == ''){
			alert('No image to upload.');
			return;
		}
		if(cap.value == ''){
			alert('A caption is required.');
			return;
		}
		var test = img.value.substring(img.value.indexOf('.')+1);
		if(test != "jpg" && test != "JPG" && test != "jpeg" && test != "JPEG" && test != "png" && test != "PNG" && test != "gif" && test != "GIF"){
			alert('Invalid Format\nAccepted formats are JPG (*.jpg,*.jpeg), PNG (*.png) and GIF (*.gif).');
			return;
		}
		document.getElementById('uploadForm').submit();

	}


	this.makeUpper=function(e){		
		if(!e){ e = window.event; }
		var knm,kcr;

		knm = e.keyCode || e.which;
		if(knm != 8 && knm != 13 && knm){
			kcr=String.fromCharCode(knm).toUpperCase().charCodeAt(0);

			if(window.event){ e.keyCode = kcr; }
			else if(e.which){
				var newEvent=document.createEvent('KeyEvents');
				newEvent.initKeyEvent('keypress',true,true,document.defaultview,e.ctrlKey,e.altKey,e.shiftKey,e.metaKey,0,kcr);
				e.preventDefault();
				e.target.dispatchEvent(newEvent);
			}
		}
	};

	this.closeEditor=function(){
		window.location.reload();
		//this.hide();
	};
}
photoEditor.inheritsFrom(controlPanel);