function createRequestObject() {
	var request_o;
	var browser=navigator.appName;
	if(browser=="Microsoft Internet Explorer"){
		request_o=new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		request_o=new XMLHttpRequest();
	}
	return request_o;
}

function printPreview(){
	var printinfo=document.getElementById('pagecontent').innerHTML;
	var printwin=window.open('/printview.php','Print','height=500,width=700,menubar=yes,resizable=yes,scrollbars=yes');
	var tmp=printwin.document;
	tmp.write('<!DOCTYPE HTML PUBLIC "-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN" "http:\/\/www.w3.org\/TR\/html4\/loose.dtd"><head><title>Medici Express<\/title>');
	tmp.write('<link href="\/css\/main.css" rel="stylesheet" type="text\/css" \/><link href="\/css\/print.css" rel="stylesheet" type="text\/css" \/> <link href="\/css\/report.css" rel="stylesheet" type="text\/css" \/>');
	tmp.write('<\/head><body>'+printinfo+'<\/body><\/html>');
	tmp.close();
	if(window.focus){printwin.focus()}
}

function printPage(){
	var targetdata=document.getElementById('pagecontent');
	if(document.getElementById('rightmargin'))targetdata=document.getElementById('rightmargin');
	var printinfo=targetdata.innerHTML;
	
	this.window.focus();
	var printwin=window.open('/printview.php','Print','height=1,width=1,menubar=no');
	var tmp=printwin.document;
	tmp.write('<!DOCTYPE HTML PUBLIC "-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN" "http:\/\/www.w3.org\/TR\/html4\/loose.dtd"><head><title><\/title>');
	tmp.write('<link href="\/css\/main.css" rel="stylesheet" type="text\/css" \/><link href="\/css\/print.css" rel="stylesheet" type="text\/css" \/>');
	tmp.write('<\/head><body>'+printinfo+'<\/body><\/html>');
	tmp.close();
	printwin.print();
	printwin.close();
}

// Pre-load tab images
if(document.images) {
	var restoreimg1 = new Image(12,82);
	restoreimg1.src = '/images/nav/restore_tab_right.gif';
	
	var restoreimg2 = new Image(12,82);
	restoreimg2.src = '/images/nav/restore.gif';
} 
			
		
function closefind(){
	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 printInvoice(){
	var printinfo=document.getElementById('invoice').innerHTML;
	var printwin=window.open('/printview.php','Print','height=1,width=1,menubar=no');
	var tmp=printwin.document;
	tmp.write('<!DOCTYPE HTML PUBLIC "-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN" "http:\/\/www.w3.org\/TR\/html4\/loose.dtd"><head><title>express.medici.com.au - my payment receipts<\/title>');
	tmp.write('<style type="text/css">a{color:blue;}body{margin:0;padding:0;font:8pt Arial;}td{font:8pt Arial;}table.mainnav td{font:8pt Arial;padding-left:10px;padding-right:10px;}table.mainnav td:hover{background:url(/images/navBGon.jpg);cursor:pointer;}td.nav2cell{padding-left:5px;padding-right:5px;}td.nav2cell:hover{background:url(/images/navBGon.jpg);cursor:pointer;}td.leftmenuitem{background:url(/images/sidenavBG.jpg);cursor:pointer;font:8pt Arial;height:30px;padding-left:5px;padding-right:5px;}tr.tablehead td{background:url(/images/navBG.jpg);font:8pt Arial;height:25px;padding-left:5px;padding-right:5px;}a img {border:0;}<\/style>');
	tmp.write('<\/head><body><div style="text-align:right">Medici Capital<br \/>17-27 Cotham Road<br \/>Kew VIC 3101<br \/><br \/><\/div>');
	tmp.write('<div>Medici Express Payment Receipts<br \/><br \/><\/div>'+printinfo+'<\/body><\/html>');
	tmp.close();
	//if(window.focus){printwin.focus()}
	printwin.print();
	printwin.close();				
}

function retrieveComputedStyle(element,styleProperty){
	var computedStyle=null;
	if(typeof element.currentStyle!="undefined"){
		computedStyle=element.currentStyle;
	}else{
		computedStyle=document.defaultView.getComputedStyle(element,null);
	}
	return computedStyle[styleProperty];
}

function searchField() {
	var srch = document.getElementById('search').value;
	if(srch=='') return;
	var http=createRequestObject();
	http.open('get','/secure/filelisting.php?action=search&amp;match='+srch, true);
	http.onreadystatechange=function(){
		if(http.readyState==4){
			var opentxt='<table class="content">'+
				'<tr class="titlebar"><td>File Search...<\/td>'+
					'<td class="closebutton"><a href="javascript:void(closePopup());">X<\/a><\/td>'+
				'<\/tr>'+
				'<tr>'+
					'<td colspan="2" class="body">'+
					http.responseText+
					'<\/td>'+
				'<\/tr>'+
				'<\/table>';
			
			popup(opentxt);
		}
	}
	http.send(null);				
}


var margin={
	maximise:function(marginID){
		
		var newDate = new Date();
		newDate.setTime(newDate.getTime()+(24*60*60*1000));
		
		if(marginID=='left'){
			document.getElementById('leftmarginoption').innerHTML='<a href="javascript:void(margin.minimize(\'left\'));"><img src="/images/nav/minimise2.gif" style="border:0;" alt="Minimise Left Panel" /><\/a>';
			document.getElementById('innerleftmargin').style.display='block';
			document.getElementById('innerleftmargin').style.width='225px';
			var margin=document.getElementById('leftmargin');
			var width=margin.offsetWidth;
			var newwidth=width;
			for(var i=0;i<225;i++){
				newwidth=225-i;
				margin.style.width=newwidth+"px";
			}
			document.cookie = 'minimisel=false; expires='+newDate.toGMTString()+'; path=/';
		}else if(marginID=='right'){
			document.getElementById('rightmarginoption').innerHTML='<a href="javascript:void(margin.minimize(\'right\'));"><img src="/images/nav/help_hide.gif" style="border:0;" alt="Minimise Right Panel" /><\/a>';
			document.getElementById('innerrightmargin').style.display='block';
			var margin=document.getElementById('rightmargin');
			var width=margin.offsetWidth;
			var newwidth=width;
			/* for(var i=width;i<200;i++){
				newwidth=200-i;
				margin.style.width=newwidth+"px";
			} */
			document.cookie = 'minimiser=false; expires='+newDate.toGMTString()+'; path=/';
		}		
	},
	minimize:function(marginID){
		
		var newDate = new Date();
		newDate.setTime(newDate.getTime()+(24*60*60*1000));
		
		if(marginID=='left'){
			document.getElementById('leftmarginoption').innerHTML='<a href="javascript:void(margin.maximise(\'left\'));"><img src="/images/nav/restore.gif" style="border:0;" alt="Restore Left Panel" /><\/a>';
			document.getElementById('innerleftmargin').style.display='none';
			var margin=document.getElementById('leftmargin');
			var width=margin.offsetWidth;
			var newwidth=width;
			for(var i=0;i<width;i++){
				newwidth=width-i;
				margin.style.width=newwidth+"px";
			}
			document.cookie = 'minimisel=true; expires='+newDate.toGMTString()+'; path=/';
		}else if(marginID=='right'){
			document.getElementById('rightmarginoption').innerHTML='<a href="javascript:void(margin.maximise(\'right\'));"><img src="/images/nav/help_show.gif" style="border:0;" alt="Restore Right Panel" /><\/a>';
			document.getElementById('innerrightmargin').style.display='none';
			var margin=document.getElementById('rightmargin');
			var width=margin.offsetWidth;
			var newwidth=width;
			/* for(var i=0;i<width;i++){
				newwidth=width-i;
				margin.style.width=newwidth+"px";
			} */
			document.cookie = 'minimiser=true; expires='+newDate.toGMTString()+'; path=/';
		}
	}
}

var rightmargin= {
	curItem:'aaehelp',
	toggle:function(item){
		document.getElementById(this.curItem).style.display = 'none';
		this.curItem = item;
		document.getElementById(this.curItem).style.display = 'block';
	}	
}
			
var nav = {
	open:function(section) {
		var tbl = document.getElementById('leftnav_tbl');
		for(var i=0; i<tbl.rows.length; i++) {
			if(tbl.rows[i].id.indexOf('subnav') != -1) {
				tbl.rows[i].style.display = 'none';	
			}						
		}
		
		var browser=navigator.appName;
		if(browser=="Microsoft Internet Explorer"){
			var tmpStyle='block';
		}else{
			var tmpStyle='table-row';
		}
		document.getElementById(section+'_subnav').style.display = tmpStyle;
	}	
}

function correctPNG(){
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			var strNewHTML = "<span " + imgID + imgClass + imgTitle
				+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				+ "(src=\'" + img.src + "\', sizingMethod='scale');\"><\/span>"
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
}


/*function smartContextHighlight()
{
	/*var re = new RegExp('<[^<>]*>', 'gi');
	var bodyhtml = document.getElementById('pagecontent').innerHTML;
	var htmlArray = bodyhtml.match(re);
	var strippedText = bodyhtml.replace(re, '$!$');
	alert(strippedText.indexOf('EBIT'));
	return;
	
	var bodyhtml = document.getElementById('pagecontent').innerHTML;
	var re = new RegExp('(<span class\=highlight>)([^<>]*)(<\/span>)', 'gi');
	var newBodyhtml = bodyhtml.replace(re, "$2");*/
	
	
	
	//document.getElementById('pagecontent').innerHTML = newBodyhtml;
	
	/*if (arguments.length > 0)
	{
		var txt = '';
		for (var i=0; i<arguments.length; i++)
		{
			txt += arguments[i];
			if (i < arguments.length - 1)
			{
			txt += '¦';
			}
			}
			
			var bodyhtml = document.getElementById('pagecontent').innerHTML;
			
			*//* strip html */
		/*	var re = new RegExp('<[^<>]*>', 'gi');
			var htmlArray = bodyhtml.match(re);
			var strippedText = bodyhtml.replace(re, '$!$');
			
			var re2Text = '(' + txt + ')';
			var re2 = new RegExp(re2Text, 'gi');
			var highlighted = strippedText.replace(re2, '<span class="highlight">$1</span>');
			
			for(j=0; highlighted.indexOf("$!$")>-1; j++)
			{
				highlighted = highlighted.replace("$!$", htmlArray[j]);
			}
			
			document.getElementById('pagecontent'.innerHTML = highlighted;
	}
	return;
} */

//window.onload = smartContextHighlight;
