var menu={
	curitem:0,
	nextmenu:false,
	timer:'',
	
	cancelTimer:function(){
		clearTimeout(this.timer);
	},
	clearmenu:function(){
		this.nextmenu=false;
		
		document.getElementById('menu').style.display='none';
		document.getElementById('menuBG').style.display='none';
		
		if(document.getElementById(this.curitem))
			document.getElementById(this.curitem).style.background='transparent';
		
		this.curitem=0;
	},
	gonext:function(itemID){
		if(this.nextmenu){
			menu.show(itemID);
		}
	},
	show:function(itemID){
		//alert(itemID);
		if(document.getElementById('menu')==null){
			var menu=document.createElement('div');
			menu.setAttribute("id","menu");
			menu.setAttribute("onmouseover","menu.cancelTimer();");
			menu.setAttribute("onmouseout","menu.startTimer();");
			menu.setAttribute("style","background:rgb(255,255,255);position:absolute;z-index:99;");
			document.body.appendChild(menu);
			
			var menuBG=document.createElement('div');
			menuBG.setAttribute("id","menuBG");
			menuBG.setAttribute("style","background:rgb(0,0,0);filter:alpha(opacity=30);opacity:0.3;-moz-opacity:0.3;position:absolute;z-index:98;");
			document.body.appendChild(menuBG);
		}
		if(this.curitem==itemID){
			this.nextmenu=false;
			
			document.getElementById('menu').style.display='none';
			document.getElementById('menuBG').style.display='none';
			
			document.getElementById(this.curitem).style.background='transparent';
			
			this.curitem=0;
		}else{
			this.nextmenu=true;
			if(this.curitem!=0){
				document.getElementById('menu').style.display='none';
				document.getElementById('menuBG').style.display='none';
				
				document.getElementById(this.curitem).style.background='transparent';
			}
			
			this.curitem=itemID;
			
			document.getElementById(itemID).style.background='rgb(255,255,255)';
			
			curX=0;
			curY=0;
			var theElement=document.getElementById(itemID);
			while(theElement!=null){
				curX+=theElement.offsetLeft;
				curY+=theElement.offsetTop;
				theElement=theElement.offsetParent;
			}
			
			document.getElementById('menu').style.left=curX+"px";
			document.getElementById('menu').style.top=(curY+25)+"px";
			
			document.getElementById('menuBG').style.left=(curX+3)+"px";
			document.getElementById('menuBG').style.top=(curY+28)+"px";
			
			if(itemID=='file'){
				if(!recentactions) recentactions = '<tr class="menurow"><td class="menumargin"></td><td class="menuitem">&laquo; Recent Actions &raquo;</td></tr>';
				document.getElementById('menu').innerHTML='<table cellspacing="0" onclick="menu.clearmenu();" class="leftmenu"><tr><td>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="newValuation()"><td class="menumargin"><img src="/images/icons/page_white.png" /></td><td class="menuitem">New</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="openDialogue();"><td class="menumargin"><img src="/images/icons/folder_page.png" /></td><td class="menuitem">Open</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="closeValuation()"><td class="menumargin"></td><td class="menuitem">Close</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr><td class="menumargin"></td><td class="menuitem"><hr size="1" width="95%" /></td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="saveForm()"><td class="menumargin"><img src="/images/icons/disk.png" /></td><td class="menuitem">Save</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="find();"><td class="menumargin"><img src="/images/icons/find.png" /></td><td class="menuitem">File Search</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr><td class="menumargin"></td><td class="menuitem"><hr size="1" width="95%" /></td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="printPreview();"><td class="menumargin"><img src="/images/icons/page_white_magnify.png" /></td><td class="menuitem">Print Preview</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="printPage();"><td class="menumargin"><img src="/images/icons/printer.png" /></td><td class="menuitem">Print</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr><td class="menumargin"></td><td class="menuitem"><hr size="1" width="95%" /></td></tr></table>'+
					'<table cellspacing="0" style="width:100%;">'+recentactions+'</table>'+
					'<table cellspacing="0" style="width:100%;"><tr><td class="menumargin"></td><td class="menuitem"><hr size="1" width="95%" /></td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="menu.exit()"><td class="menumargin"></td><td class="menuitem">Exit</td></tr></table>'+
					'</td></tr></table>';
			}
			if(itemID=='edit'){
				document.getElementById('menu').innerHTML='<table cellspacing="0" onclick="menu.clearmenu();" class="leftmenu"><tr><td>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="find(1)"><td class="menumargin"><img src="/images/icons/find.png" /></td><td class="menuitem">Find</td></tr></table>'+
					'</td></tr></table>';
			}
			if(itemID=='view'){
				document.getElementById('menu').innerHTML='<table onclick="menu.clearmenu();" class="leftmenu"><tr><td>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="zoomIn();"><td class="menumargin"></td><td class="menuitem">Zoom In</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="zoomOut();"><td class="menumargin"></td><td class="menuitem">Zoom Out</td></tr></table>'+
					'</td></tr></table>';
			}
			if(itemID=='tools'){
				document.getElementById('menu').innerHTML='<table onclick="menu.clearmenu();" class="leftmenu"><tr><td>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow"><td class="menumargin"><img src="/images/icons/spellcheck.png" /></td><td class="menuitem">Spelling</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow"><td class="menumargin"></td><td class="menuitem">Research</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr><td class="menumargin"></td><td class="menuitem"><hr size="1" width="95%" /></td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow"><td class="menumargin"></td><td class="menuitem">Options...</td></tr></table>'+
					'</td></tr></table>';
			}
			if(itemID=='data'){
				document.getElementById('menu').innerHTML='<table onclick="menu.clearmenu();" class="leftmenu"><tr><td>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow"><td class="menumargin"></td><td class="menuitem">Sort</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow"><td class="menumargin"></td><td class="menuitem">Filter</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow"><td class="menumargin"></td><td class="menuitem">Validation</td></tr></table>'+
					'</td></tr></table>';
			}
			if(itemID=='help'){
				document.getElementById('menu').innerHTML='<table cellspacing="0" onclick="menu.clearmenu();" class="leftmenu"><tr><td>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow"><td class="menumargin"><img src="/images/icons/help.gif" /></td><td class="menuitem">Help Index</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr><td class="menumargin"></td><td class="menuitem"><hr size="1" width="95%" /></td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="contact()"><td class="menumargin"></td><td class="menuitem">Contact Us</td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr><td class="menumargin"></td><td class="menuitem"><hr size="1" width="95%" /></td></tr></table>'+
					'<table cellspacing="0" style="width:100%;"><tr class="menurow" onclick="help();"><td class="menumargin"></td><td class="menuitem">About</td></tr></table>'+
					'</td></tr></table>';
			}
			
			document.getElementById('menuBG').innerHTML=document.getElementById('menu').innerHTML;
				
			document.getElementById('menu').style.display='block';
			document.getElementById('menuBG').style.display='block';
			
			document.getElementById('menu').style.zIndex=99;
			document.getElementById('menuBG').style.zIndex=98;
		}
		if(navigator.appVersion.indexOf("MSIE")!=-1){
			correctPNG();
		}
	},
	startTimer:function(){
		this.timer=setTimeout("menu.clearmenu();","500");
	},
	exit:function() {
		var reply = confirm("You are about to log out of Medici Express.\n\nContinue?");
		if(reply) {
			var http=createRequestObject();
			http.open('get','/logout.php');
			http.onreadystatechange=function(){
				if(http.readyState==4){
					window.location='/';
				}
			}
			http.send(null);			
		}
	},
	redirect:function(){
		var site=document.getElementById('webSelect').value;
		if(site==1){
			
		}else if(site==2){
			window.open('http://www.medici.com.au');
		}else if(site==3){
			window.open('http://experts.medici.com.au');
		}else if(site==4){
			window.open('http://www.practice4sale.com.au');
		}else if(site==5){
			window.open('http://www.jobs4careers.com.au');
		}
	}
}

function saveForm() {
	var div = document.getElementById('pagecontent');
	var forms = div.getElementsByTagName('form');
	if(forms.length == 0) {
		return;
	} else {
		for(var i=0; i<forms.length; i++) {
			if(forms[i].action != '') {
				if(forms[i].onsubmit) {
					if(forms[i].onsubmit()) {
						forms[i].submit();
					}
				} else {
					forms[i].submit();
				}
			}									
		}	
	}	
}

function GetParameters() {	
	var list = new Array();
	
	var url = top.location.search.substring(1);
	if(url == '') {
		return false;
	}
	
	url = url.split(/\&/);
	for(var i=0; i<url.length; i++) {
		var params = url[i].split(/\=/);
		list[params[0]] = params[1];
	}
	
	return list;
}

function newValuation() {
	var list = GetParameters();
	if(list) {
		var url = '';
		for(key in list) {
			if(url != '') url += '&';
			if(key == 'professionID' || key == 'valtypeID') {
				url += key + '=' + list[key];	
			}
		}
		window.location = '/secure/valuation/info.php?action=valedit&'+url;
	} else {
		newValuationWizard(1);
	}
}

function newValuationWizard(step) {
	var param = '';
	var select = '';
	
	switch(step) {
		case 1:
			param = 'professionselect';	
		case 2:
			if(param == '' && document.getElementById('professionType')) {
				if(document.getElementById('professionType').nodeName.toUpperCase() == 'SELECT') {
					var profession = document.getElementById('professionType').options[document.getElementById('professionType').selectedIndex].value;
				} else {
					var profession = document.getElementById('professionType').value;
				}
				if(profession == 0) {
					alert('Please select a profession type');
					newValuationWizard(step-1);
					return;
				}
				param = 'valtypeselect&profession='+profession;
			}
			
			var http=createRequestObject();
			http.open('get','/secure/filelisting.php?action=get'+param);
			http.onreadystatechange=function(){
				if(http.readyState==4){
					select = http.responseText;
					showForm();
				}
			}
			http.send(null);
			break;
		default:
			showForm();
	}
	
	function showForm() {
		var button='';
		var opentxt='<table class="content">'+
			'<tr class="titlebar"><td>New Valuation Wizard</td>'+
				'<td class="closebutton"><a href="javascript:void(closePopup());">X</a></td>'+
			'</tr>'+
			'<tr>'+
				'<td colspan="2" class="body">'+
				'<b>Step '+step+'</b><br /><br />';
				
		switch(step) {
			case 1:	
				opentxt += 'Please select a profession:<br /><br />'+
						'<select name="professionType" id="professionType">'+
						'<option value="0">Please select...</option>'+select+
						'</select>';
				break;
			case 2:	
				if(document.getElementById('professionType').nodeName.toUpperCase() == 'SELECT') {
					var profession = document.getElementById('professionType').options[document.getElementById('professionType').selectedIndex].value;
				} else {
					var profession = document.getElementById('professionType').value;
				}
				opentxt += 'Please select a valuation type:<br /><br />'+
						'<select name="valuationType" id="valuationType">'+
						'<option value="0">Please select...</option>'+select+
						'</select>'+
						'<input type="hidden" id="professionType" name="professionType" value="'+profession+'" />';
				button = '<input type="button" value="&laquo; Prev" onClick="newValuationWizard('+(step-1)+')" /> ';
				break;
			case 3:
				var profession = document.getElementById('professionType').value;
				var valtypeID = document.getElementById('valuationType').options[document.getElementById('valuationType').selectedIndex].value;
				
				if(valtypeID == 0) {
					alert('Please select a valuation type');
					newValuationWizard(step-1);
					return;
				}
				
				opentxt += 'Loading...<br /><br />';
				window.location='/secure/valuation/info.php?professionID='+profession+'&valtypeID='+valtypeID;
				break;
		}
			
		opentxt +='<br />'+
				'<br />'+
				button+'<input type="button" value="Next &raquo;" onClick="newValuationWizard('+(step+1)+')" />'+
				'</td>'+
			'</tr>'+
			'</table>';
			
		popup(opentxt);
	}
}

function closeValuation() {
	var url = '';
	var list = GetParameters();
	if(list) {
		var idFound = false;
		for(key in list) {
			if(key == 'id') {
				idFound = true;
				break;	
			}
		}
		
		if(idFound) {
			for(key in list) {
				if(key == 'id') {
					idFound = true;
					break;	
				}
				
				if(url != '') url += '&';
				if(key == 'professionID' || key == 'valtypeID') {
					url += key + '=' + list[key];	
				}
			}
			url = '?' + url;
		}
	}
	
	url = '/secure/valuation/' + url;	
	window.location = url;
}

function help(){
	var opentxt='<table class="content">'+
		'<tr class="titlebar"><td>About Medici Express</td>'+
			'<td class="closebutton"><a href="javascript:void(closePopup());">X</a></td>'+
		'</tr>'+
		'<tr>'+
			'<td colspan="2" class="body">'+
			'<br />'+
			'Medici Express<br />'+
			'<br />'+
			'&copy; 2007 Contributors.  All Rights Reserved.<br />'+
			'<br />'+
			'Medici Express BETA VERSION<br />'+
			'<br />'+
			'<br />'+
			'</td>'+
		'</tr>'+
		'</table>';
		
	popup(opentxt);
}

function contact(){
	var opentxt='<table class="content">'+
		'<tr class="titlebar"><td>Contact Us</td>'+
			'<td class="closebutton"><a href="javascript:void(closePopup());">X</a></td>'+
		'</tr>'+
		'<tr>'+
			'<td colspan="2" class="body">'+
			'<table>'+
			'<tr><td><b>Street Address:</b></td><td><b>Postal Address:</b></td></tr>'+
			'<tr><td style="padding-right:20px">17 - 27 Cotham Rd<br />KEW VIC 3101</td><td>PO Box 80<br />KEW VIC 3101</td></tr>'+
			'</table>'+
			'<br />'+
			'<b>Phone:</b> +61 3 9853 7933<br />'+
			'<br />'+
			'<b>Fax:</b> +61 3 9853 7990<br />'+
			'<br />'+
			'General Enquiries: info@medici.com.au<br />'+
			'<br />'+
			'Valuation Enquiries: valuations@medici.com.au<br />'+
			'<br />'+
			'<br />'+
			'</td>'+
		'</tr>'+
		'</table>';
		
	popup(opentxt);
}

function find(step) {
	/*var opentxt='<table class="content" width="250">'+
				'<tr class="titlebar"><td>Find...</td>'+
					'<td class="closebutton"><a href="javascript:void(closePopup());">X</a></td>'+
				'</tr>'+
				'<tr>'+
					'<td colspan="2" class="body">Loading Search Form</td>'+
				'</tr>'+
				'</table>';
				
	var http = createRequestObject();
	http.open('get','/secure/filelisting.php?action=&code='+coupon_code+'&professionID='+professionID+'&valtypeID='+valtypeID);
	http.onreadystatechange=function() {
		if(http.readyState == 4){
			
		}
	}
	http.send(null);			*/
					
	var opentxt='<table class="content" width="250">'+
				'<tr class="titlebar"><td>Find...</td>'+
					'<td class="closebutton"><a href="javascript:void(closePopup());">X</a></td>'+
				'</tr>'+
				'<tr>'+
					'<td class="body" colspan="2">'+
						'<table width="100%">'+
						'<tr>'+
							'<td><fieldset><legend>Search In:</legend>Valuations</fieldset></td>'+
						'</tr>'+
						'<tr>'+
						'<td valign="top"><fieldset><legend>Match Against:</legend>'+
						'<input type="text" id="matchstring" name="matchstring" class="txt" style="width:200px" /></fieldset></td>'+
						'</tr>'+
						'<tr>'+
						'<td valign="top" align="right"><input type="button" onclick="find(2)" value="Search" /></td>'+
						'</tr>'+
						'<tr>'+
						'<td><div id="searchresults" style="height:200px;overflow:auto;padding-top:10px"></div></td>'+
						'</tr>'+
						'</table>';
					'</td>'+
				'</tr>'+
				'</table>';
					
	if(step == 2) {		
		var matchstring = document.getElementById('matchstring').value;
		var searchfor = 'valuations'
		var http=createRequestObject();
		http.open('get','/secure/filelisting.php?action=search&type='+searchfor+'&match='+matchstring);
		http.onreadystatechange=function(){
			if(http.readyState==4){
				document.getElementById('searchresults').innerHTML = http.responseText;
			}
		}
		http.send(null);
	} else {				
		popup(opentxt);
	}
}

function openDialogue() {
	var opentxt='<table class="content">'+
				'<tr class="titlebar"><td>Open...</td>'+
					'<td class="closebutton"><a href="javascript:void(closePopup());">X</a></td>'+
				'</tr>'+
				'<tr>'+
					'<td colspan="2" class="body">'+
						'<table>'+
						'<tr>'+
						'<td style="padding:5px;">'+
							'Directory:<br />'+
							'<div id="dirlisting" style="height:150px;overflow:hidden;width:200px;">'+
								'<table cellpadding="0" cellspacing="0">'+
									'<tr><td><img src="/images/nav/minus.gif" /></td>'+
									'<td><img src="/images/icons/folder.png" /></td>'+
									'<td style="padding-left:2px;">Medici Express Directory</td></tr></table>'+
								'<table cellpadding="0" cellspacing="0">'+
									'<tr><td width="19"> &nbsp; </td><td><img src="/images/nav/tplus.gif" id="valuationsicon" /></td><td><img src="/images/icons/folder.png" /></td><td style="padding-left:2px;"><a href="javascript:void(listfiles(\'valuations\'));">Valuations</a></td></tr>'+
									//'<tr><td width="19"> &nbsp; </td><td><img src="/images/nav/i.gif" /></td><td><img src="/images/nav/l.gif" /></td><td style="padding-left:2px;"><a href="javascript:void(listfiles(\'valuations\'));">Indicative</a></td></tr>'+
									'<tr><td width="19"> &nbsp; </td><td><img src="/images/nav/l.gif" /></td><td><img src="/images/icons/folder.png" /></td><td style="padding-left:2px;"><a href="javascript:void(listfiles(\'finance\'));">Finance</a></td></tr>'+
								'</table>'+
							'</div>'+
						'</td>'+
						'<td style="padding:5px;">'+
							'Files:<br />'+
							'<div id="filelisting"></div>'+
						'</td>'+
						'</tr>'+
						'<tr>'+
						'<td colspan="2" style="padding:5px;">'+
							'<table>'+
							'<tr>'+
								'<td>File:</td>'+
								'<td><input size="60" type="text" value="" id="openfile_filename" class="txt" /></td>'+
							'</tr>'+
							'<tr>'+
								'<td>File Type:</td>'+
								'<td><input size="60" type="text" value="" id="openfile_type" class="txt" /></td>'+
							'</tr>'+
							'</table>'+
						'</td>'+
						'</tr>'+
						'<tr>'+
							'<td align="right" colspan="2" style="padding:5px;">'+
							'<input type="button" value="Open" id="openfile_openbtn" />'+
							'<input onclick="closePopup();" type="button" value="Cancel" />'+
							'</td>'+
						'</tr>'+
						'</table>'+
					'</td></tr>'+
					'</table>';
		
	popup(opentxt);
}
			
function popup(opentxt) {
	if(document.getElementById('popup')) closePopup();
	
	opentxt = '<!--[if lte IE 6.5]><iframe></iframe><![endif]-->'+opentxt;
			
	var popup=document.createElement('div');
	popup.id = 'popup';
	popup.className = 'select-free';
	popup.innerHTML=opentxt;
	
	var popupBG=document.createElement('div');
	popupBG.id = 'popupBG';
	popupBG.className = 'select-free';
	popupBG.innerHTML=opentxt;
	popupBG.style.display='none';
	
	var pageblock=document.createElement('div');
	pageblock.setAttribute("style","background:rgb(150,150,150);height:100%;left:0;filter:alpha(opacity=30);opacity:0.3;-moz-opacity:0.3;position:absolute;top:0;width:100%;z-index:97;");
	pageblock.setAttribute("id","pageblock");
	pageblock.innerHTML='&nbsp;';
	
	document.body.appendChild(popup);
	//document.body.appendChild(popupBG);
	//document.body.appendChild(pageblock);
	
	// determine window width and height
	var divH = document.getElementById('popup').offsetHeight;
	var divW = document.getElementById('popup').offsetWidth;
	var winW=0, winH=0;
	if(typeof window.innerWidth  == 'number'){
		// Non-IE
		winW = window.innerWidth;
		winH = window.innerHeight;
	} else if(document.documentElement && (document.documentElement.clientWidth  || document.documentElement.clientHeight)){
		// IE 6+
		winW = document.documentElement.clientWidth;
		winH = document.documentElement.clientHeight;
	} else if(document.body && (document.body.clientWidth  || document.body.clientHeight)){
		// IE 4
		winW = document.body.clientWidth;
		winH = document.body.clientHeight;
	}
			
	// determine scrolling position
	var position = [0,0];
	if(typeof window.pageYOffset != 'undefined')
	{
		// Non-IE
		position = [
			parseInt(winW / 2) - parseInt(divW / 2) + window.pageXOffset,
			parseInt(winH / 2)- parseInt(divH / 2) + window.pageYOffset
		];
	}
	else if(document.documentElement) 
	{ 
		var tmptop=0;
		if(document.documentElement.scrollTop) {
			tmptop=parseInt(document.documentElement.scrollTop);
		}
		var tmpleft=0;
		if(document.documentElement.scrollLeft) {
			tmpleft=document.documentElement.scrollLeft;
		}
		position = [
			parseInt(winW / 2) - parseInt(divW / 2) + tmpleft,
			parseInt(winH / 2) - parseInt(divH / 2) + tmptop
		];
	}
	else if(document.body)
	{
		var tmptop=0;
		if(document.body.scrollTop) {
			tmptop=parseInt(document.body.scrollTop);
		}
		var tmpleft=0;
		if(document.body.scrollLeft) {
			tmpleft=document.body.scrollLeft;
		}
		position = [
			parseInt(winW / 2) - parseInt(divW / 2) + tmpleft,
			parseInt(winH / 2) - parseInt(divH / 2) + tmptop
		];
	}
	else
	{
		return;	
	}
	
	var lpos=position[0];
	var tpos=position[1];
	
	popup.style.left = lpos+'px';
	popup.style.top = tpos+'px';
	popupBG.style.left = (lpos + 4) + 'px';
	popupBG.style.top = (tpos + 4) + 'px';
}

function closePopup() {
	if(document.getElementById('popup')) {
		var popup=document.getElementById('popup');
		//var popupBG=document.getElementById('popupBG');
		//var pageblock=document.getElementById('pageblock');
		
		document.body.removeChild(popup);
		//document.body.removeChild(popupBG);
		//document.body.removeChild(pageblock);
	}		
}

function zoomIn() {
	ts('pagecontent',1);
}

function zoomOut() {
	ts('pagecontent',-1);
}

//Specify affected tags. Add or remove from list:
var tgs = new Array( 'div','td','tr');

//Specify spectrum of different font sizes:
//var szs = new Array( 'xx-small','x-small','small','medium','large','x-large','xx-large' );
var szs = new Array( '8pt','9pt','10pt','11pt','12pt','13pt','14pt' );
var startSz = 0;

function ts( trgt,inc ) {
	if (!document.getElementById) return;
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
		
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];

	cEl.style.fontSize = szs[ sz ];

	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		//for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
		for ( j = 0 ; j < cTags.length ; j++ ) {
			var parentNode = cTags[ j ];
			while(parentNode.nodeName.toLowerCase() != 'html') {
				if(parentNode.style.fontSize) {
					break;
				} else {
					parentNode = parentNode.parentNode;
				}
			}
			var font = parseInt(parentNode.style.fontSize.substring(0,parentNode.style.fontSize.indexOf('pt')));
			font = font+(1*inc) < 8 ? 8 : font+(1*inc);
			font = font+(1*inc) > 14 ? 14 : font+(1*inc);
		
			cTags[ j ].style.fontSize = font+'pt';
		}
	}
}

function listfiles(type) {
	var params='/secure/filelisting.php?action=openfile&type='+type;
	switch(type) {
		case('valuations'):
			
		
			break;		
	}	
	
	var http=createRequestObject();
	http.open('get',params);
	http.onreadystatechange=function(){
		if(http.readyState==4){
			document.getElementById('filelisting').innerHTML = http.responseText;
		}
	}
	http.send(null);
}

function filedetails(valID) {
	var params='/secure/filelisting.php?action=getfiledetails&valID='+valID;
	var http=createRequestObject();
	http.open('get',params);
	http.onreadystatechange=function(){
		if(http.readyState==4){
			eval(http.responseText);
			document.getElementById('openfile_filename').value = valuation['name'];
			document.getElementById('openfile_type').value = valuation['type'];
			document.getElementById('openfile_openbtn').onclick = 
										function() {
											window.location='/secure/valuation/?professionID='+
																valuation['professionID']+'&valtypeID='+valuation['valtypeID']+
																'&id='+valID;
										}
		}
	}
	http.send(null);
	
}