var reg = "/CA25766E0010A233/";
var maps = "/CA2570C30016EEF3/";
var aniImg="<IMG src='/CA256F800017E8D4/WebObj/CB3D63BA5B90A857CA25786F00104580/$File/ajax-loader.gif'>";


function resizeIframe( h ) {
	document.getElementById('if1').style.height=h+10+"px";
	resizeContent();
}

function autoFit ( id ) {
	var h= document.getElementById(id).contentWindow.document.body.scrollHeight;
	document.getElementById(id).style.height = h+10+"px";
	resizeContent();
}

function quickSearch() {
	var SearchView  = "/CA256F800017E8D4/WebSearch?Search&Query=(";
	if (document.forms[0].search.value.length<1) { 
		alert("Please type the word or words you wish to search for in the Search Box.");
		document.forms[0].search.focus();
		return; } 
	else { 
		window.location = SearchView + document.forms[0].search.value
 + ")&Start=1&Count=20&SearchOrder=1";
		return false; } 
}

function setBaseFontSize( s ) {

	var b = document.getElementsByTagName('body')[0];
	switch (s) {
	case "m":
		b.style.fontSize = '110%';
		resizeContent();
		break;
	case "l":
		b.style.fontSize = '115%';
		resizeContent();
		break;
	default:
		b.style.fontSize = '100%';
		resizeContent();
	}
}

function dialogWin (docURL, tWidth, tHeight) {
	var winopt = 'toolbar=no,location=no,titlebar=no,menubar=no,resizable=yes,scrollbars=yes,directories=no,status=no,width=' + tWidth + ',height=' + tHeight;
	window.open(docURL,'DWIN',winopt, true );
}

function QL_jumpMenu(targ,selObj,restore){
	if (selObj.selectedIndex != 0) {
		eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
		if (restore) selObj.selectedIndex=0;
	}
}

function resizeContent() {
	if ( document.getElementById("sub-menu") ) {
		m1 = document.getElementById("sub-menu").offsetHeight ;
		m2 = document.getElementById("pgContent").offsetHeight ;
		document.getElementById("dcontent").style.minHeight = (Math.max( m1, m2, 480 ) + 50) + "px";
		
		/**
		d1 = dojo.query("UL[class='style2']");
		d2 = dojo.query("#dcontent");

		console.log( "menu " + d1[0].offsetHeight );
		console.log( "box " + d2[0].offsetHeight );
		console.log( Math.max( d1[0].offsetHeight, d2[0].offsetHeight) );

		dojo.style(d2[0], "height", Math.max( d1[0].offsetHeight, d2[0].offsetHeight) + 50 + "px" );
		**/
		
	}
}

function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
}

function disableEnterKey(e) {
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
}

function getRegView( v , id ) {
	dojo.byId(id).innerHTML = aniImg;
		
	dojo.xhrGet({
	url : (reg+v),
	handleAs : "text",
	load : function(data) { dojo.byId(id).innerHTML = data; refreshSorttable() },
	error : function(error) {dojo.byId(id).innerHTML = error;}
	});
}

function getMapsView( v, id ) {
	dojo.byId(id).innerHTML = aniImg;
		
	dojo.xhrGet({
	url: (maps+v),
	handleAs : "text",
	load : function(data) { dojo.byId(id).innerHTML = data; refreshSorttable() },
	error : function(error) {dojo.byId(id).innerHTML = error;}
	});

}

function s1( c ) {
	var v = "wDeclaredOrgs?OpenView&RestrictToCategory=" + c + "&Count=1000&Start=1" ;
	var id = "view";
	getRegView( v , id );
	resizeContent();
}

function s2( c ) {
	var v = "wVOLS?OpenView&RestrictToCategory=" + c + "&Count=1000&Start=1" ;
	var id = "view";
	getRegView( v , id );
	resizeContent();
}

function showHearingDetermined( n, xo, u , t  ) {
	dlgApp = new dijit.Dialog( { title: "Information", errorMessage : "<center>Unable to locate these details at the present time.<br><br> Applicant/Venue/Authority may no longer exists under that name</center>" } );
	p = dojo.position( n, false );	//get coord for linked tag
	dlgApp.attr( 'href', u );
	if ( t != "") dlgApp.attr( 'title', t );
	//dlgApp._relativePosition= { x: p.x+xo, y: p.y+10}; 		 
	dlgApp.show();
}

function HearingDeterminedFilterBy( o ) {	
	switch ( o.name ) {
		case 'filter_all':
			i = 'All' ; 
			break;
		default:
			i = o.options[o.selectedIndex].text  ; 			
			if ( (o.options[o.selectedIndex].text).substring(0,7)  == '*Select' ) i ='All';						
	}
	var v = "wHearingsDetermined?OpenView&RestrictToCategory=" + i + "&Start=1&Count=1000";
	var id = "view";
	getRegView( v , id );
	resizeContent();
}

function refreshSorttable(){
	if ( typeof sorttable != 'undefined') {
		forEach(document.getElementsByTagName('table'), function(table) {
			if (table.className.search(/\bsortable\b/) != -1) {
			sorttable.makeSortable(table);}
		});
	}
}
window.onload = function() { document.onkeypress = stopRKey; resizeContent() }
