
// Popup Window No.1
function newWindow(type, id, defs, newedit)
{

	var item = '&id=';
	if 	(newedit == null || newedit == "")
	{
		var w = 1015;
		var h = 700;
		newedit = "/main.php?t="+type;
	}
	else
	{
		var w = screen.width-100;
		if (w > 1400) w = 1400;
		var h = screen.height-100;
		newedit = "/main.php?popupwin=1&t="+newedit;
		if (type == "people") item = '&peopleID=';
	}

	var winl = (screen.width-w)/4;
	var wint = (screen.height-h)/4;
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;

	defs = (defs == null)? "" : "&"+defs;

	var url = newedit  + item + id + defs;

	window.open(url, "_blank", "height="+h+",width="+w+",top="+ wint +",left="+ winl +",location=no," + "dependent=no, scrollbars=yes, menubars=no, toolbars=no, alwaysRaised=yes, resizable=yes, status=yes"); 
	
	return false;
	
} // koniec  popWindow



// Popup Window No.2 with sizes + locked
function newWindow2(url, width, height, name) 	// locked popup window
{
	var left = (screen.width-width)/4;
	var top = (screen.height-height)/4;
	if (left < 0) left = 0;
	if (top < 0) top = 0;

	if (url != "")
	{
		matchPos = url.search("&");
		if (matchPos != -1) url = url + "&"; else url = url + "?";
		url = url + "popupwin=1";
		
	}
	
	if (name == null) name = "_blank";
	
	window.open(url, name, "toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0, width="+width+", height="+height+", left="+left+", top="+top); 
	
	return false;
}






function getXMLHTTPResponse(url, post)
{
	if (document.all) {
    	var xmlhttp = new ActiveXObject("MSXML2.XMLHttp");
    } else {
    	var xmlhttp = new XMLHttpRequest();
    }

	if (post) 
	{
		xmlhttp.open('POST', url, false);
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=iso-8859-1');
		xmlhttp.send(post);
	} else {
		xmlhttp.open("GET", url, false);
		xmlhttp.send(null);
		if(!xmlhttp.getResponseHeader("Date")) {
		  var cached = xmlhttp;
		  xmlhttp =  new XMLHttpRequest();
		  var ifModifiedSince = cached.getResponseHeader("Last-Modified");
		  ifModifiedSince = (ifModifiedSince) ?
		      ifModifiedSince : new Date(0); // January 1, 1970
		  xmlhttp.open("GET", url, false);
		  xmlhttp.setRequestHeader("If-Modified-Since", ifModifiedSince);
		  xmlhttp.send("");
		  if(xmlhttp.status == 304) {
		    xmlhttp = cached;
		  }
		}
		
	}
	
	if(xmlhttp.status == 200)
	{
		return xmlhttp.responseText;
	} else {
		return "Error: "+xmlhttp.status;
	}
}

function assignXMLHTTPResponse(url, elname, post)
{
	response = getXMLHTTPResponse(url, post);
	el = document.getElementById(elname);
	el.innerHTML = response;
}

function MM_jumpMenu(targ,selObj,restore){ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function swapWidth(el) {
  if (!el.oldWidth) {
	   el.oldWidth=250;
	} 
	var tmp = (el.parentNode.width=="") ? 15 : el.parentNode.width; 
	el.parentNode.width = el.oldWidth;  
	el.oldWidth = tmp;
}

function chWidth(el,ch) {
	   if (el.parentNode.width>-(ch)) { // large enough
   		 el.parentNode.width = (el.parentNode.width/1) + ch;
		 }	 
}



function toggleHeight(divel, stdHeight)
{
	if (divel.style.height == stdHeight)
	{
		divel.style.height = '100%';
	} else {
		divel.style.height = stdHeight;
	}
}	



function toggleShow(idd, res)
{
	var obj = document.layers ? document.layers[idd] :
		document.getElementById ?  document.getElementById(idd) : document.all[idd];
	obj.className = (obj.className=='hidden') ? '' : 'hidden';
	
	if (idd=='salescall' & obj.className=='')
	{
		document.getElementById('salescall_text').focus();
	}
	
    if (res=='true') return true; else return false;
}


function toggleShow2(idd, iState, res) // iState=1 visible, 0 hidden
{
	var obj = document.layers ? document.layers[idd] :
		document.getElementById ?  document.getElementById(idd) : document.all[idd];
	
	if (obj != null) obj.className = iState ? '' : 'hidden'; 
	
    if (res=='true') return true; else return false;
}



function toggleShow3(idd, iState, res) // iState=1 visible, 0 hidden
{
    
	var obj = document.getElementsByName(idd);

	for(var i=0;i<obj.length;i++)
	{
		if (iState != "") obj[i].className = (iState=="0") ? 'hidden' : '';
		else obj[i].className = (obj[i].className=='hidden') ? '' : 'hidden';
	}

    if (res=='true') return true; else return false;
}



function refreshAllMultibox ()
{
	toggleShow3('filter', 1);
	return false;
}



var popWindow;

function updateWindow(wnd, name, id)
{
}

var wnd;

function newUser(name,id)
{
	wnd = newWindow('users',0);
	alert(wnd.document.readyState);
	wnd.write('erterter');	
	
	//wnd.document.forms["Edycjadanych"].name.value = name;	
	//wnd.document.getElementById('peopleID').value = id;
	//wnd.document.getElementById('peopleIDdescr').value = name;
}








function listPopup(type, field, value) {
var GoToURL = 'selectorg.php?t='+type+'&f='+field+'&k='+value;

	poplistWindow = window.open(GoToURL,'_blank',
	'dependent=no, scrollbars=yes, alwaysRaised=yes, resizable=yes, left=150, top=150, width=750, height=550');

}

function recordListPopup(type, val) {
var GoToURL = 'recordlist.php?t='+type;

	if(val == 'goto')
	{
		poplistWindow = window.open(GoToURL,'_blank',
		'dependent=no, scrollbars=yes, alwaysRaised=yes, resizable=yes, left=450, top=150, width=450, height=450');
	} else {
		document.forms['Danedoedycji'].submit(); 
	}

}


function updateDim(dwlsrc,seldwlsrc,dwlsize,dwldir) {
	var wartosc = seldwlsrc.options[seldwlsrc.selectedIndex].value;
	if (wartosc=='') { 
		dwlsrc.value = ''; 
		dwlsize.value = '';
	} else { 
		dwlsrc.value = dwldir+wartosc; 
		dwlsize.value = 'Auto';
	}

} // koniec updateDim

function ZapiszDane() {

	if (confirm("Do you want to save your changes first?")) { 
		document.forms['Edycjadanych'].submit();
		return 1;
	} else return 0;

}



function UpdateLP(kogo,co) {

	if (kogo.value!='') {
		document.forms['Edycjadanych'].modified.value=1;

		if (confirm("Do you want to save the change now, in order to refresh the list?")) {
			document.forms['Edycjadanych'].submit();
			return true;
		}
	} else {
		alert('First enter '+co+'!');
		return false;
	}
}




function PrzejdzDo(el) {
	if (typeof(document.forms['Edycjadanych'])=='undefined' || document.forms['Edycjadanych'].modified.value==0 || confirm('Are you sure you do not want to save your changes?')) {
			document.forms['Danedoedycji'].submit(); 
	}
}



var uplWindow;

function uploadWindow(godir, filetype, typ, field, id, other, del){

	if (document.forms['Edycjadanych'].modified != null && document.forms['Edycjadanych'].modified.value==1 && confirm('Adding a new file requires refreshing the screen. Do you want to save your changes first?')) {
			document.forms['Edycjadanych'].submit();	
	}

	var GoToURL = 'upload.php?godir='+godir+'&filetype='+ filetype +'&typ='+typ +'&fl='+field +'&id=' +id +'&other=' +other +'&del=' +del;

	if (!uplWindow ||uplWindow.closed){
		uplWindow =window.open(GoToURL,'uplWindow', "dependent=yes, scrollbars=auto, alwaysRaised=yes, resizable=no, left=500, top=350, width=332, height=310");
	} else {
		uplWindow.location=GoToURL;
		uplWindow.focus();
	}

} 



function getMatchingRecords(key, type, needle, def, width, height, oldval)
{
	var el = document.getElementById(key+'_div');
	
	if (width == null)   var width = 350;
	if (height == null)  var height = 10;
	oldval = (oldval == null)? "&oldval=_vals" : "";
	
	if (document.all) {
    	var xmlhttp = new ActiveXObject("MSXML2.XMLHttp");
    } else {
    	var xmlhttp = new XMLHttpRequest();
    }

	xmlhttp.open("GET", "rpc_recordlist.php?t="+type+"&key="+key+"&s="+needle+"&def="+def+"&width="+width+"&height="+height+oldval, false);
	xmlhttp.send(null);
	
	if(xmlhttp.status == 200)
	{
		el.innerHTML = xmlhttp.responseText;
		//alert(xmlhttp.responseText);
	} else {
		alert("Error: "+xmlhttp.status);
	}

}



function onEnter(e, ths, clck) 
{
	if (window.event)
	{
		keyOK = window.event.keyCode == 13;
	} else {
		keyOK = e.keyCode == 13;
	}
	
	if (keyOK) 
	{
		var el = document.getElementById( ths+"_btn" );
		if ( clck==2 )
		{
			el.doubleclick();
		} else {
			el.click();
		}
		return false;
	}
	
	return true;
}


function onEnterDblClick(e, ths) 
{
	if (window.event)
	{
		keyOK = window.event.keyCode == 13;
	} else {
		keyOK = e.keyCode == 13;
	}
	
	if (keyOK) 
	{
		ths.ondblclick ();
		return false;
	}
	
	return true;
}

function el(id)
{
	return document.getElementById(id);
}


var selectedCol = 0;


function showTab(col_no, col_str, col_title)
{
	selectedCol = col_no;
	
	for (i=0; i<colCount; i++)
	{
		document.getElementById('tab_'+i).bgColor = ( selectedCol==i ) ? colorh : colorb;
	}

	if (col_str != null && col_str != "")
	{
		var table = el('datatable');
		var col_arr = col_str.split(",");
		for (i in col_arr)
		{
			if (col_arr[i] == 1)
			{
				toggleColumn(table, i, true);
			} else {
				toggleColumn(table, i, false);
			}
		}
		
	}
	
	if (document.getElementById('tab') != null)   { document.getElementById('tab').value = col_no; }
	if (document.getElementById('excelall') != null) {	document.getElementById('excelall').innerHTML = "Download all pages to Excel - '" + col_title + "' tab"; }
	
	var menus = [ "pagenum", "excellink", "tableheader",  "excelbtn" ];
	for (var menu in menus) 
	{
		if (document.getElementById(menus[menu]) != null)
		{
			var atags = document.getElementById(menus[menu]).getElementsByTagName('a')
			for(i=0;i<atags.length;i++)
			{
				str = atags[i].getAttribute('href');
				str = str.replace("&tab=0", "");
				str = str.replace("&tab=1", "");
				str = str.replace("&tab=2", "");
				str = str.replace("&tab=3", "");
				str = str.replace("&tab=4", "");
				str = str.replace("&tab=", "&tb=") + "&tab=" + col_no;
				atags[i].setAttribute('href', str); 
			}
		}
	}
	
	if (window.BrowserDetect !== undefined && BrowserDetect.browser == "Firefox") table.redraw();

	return false;
}


function toggleColumn(table, colIndex, isShow) 
{

	var p = "";
	if (window.BrowserDetect !== undefined && BrowserDetect.browser == "Firefox") p = "table-cell";
	
	for (var r = 0; r < table.rows.length; r++)
	{
    	if (table.rows[r].cells[colIndex] != null)
    	{
    		table.rows[r].cells[colIndex].style.display = (isShow) ? p : "none";
    	}
    }
}

function editField(table, key, id, mode)
{
	var url = "ajax_field.php?t="+table+"&k="+key+"&id="+id+"&mode="+mode;
	if (mode=="save")
	{
		el = document.getElementById(key);
		assignXMLHTTPResponse(url, key+'_fld', key+"="+el.value );
	} else {
		assignXMLHTTPResponse(url, key+'_fld' );
	}
}


function resetPassword(idx, password)
{
	if (confirm('Reset this user\'s password to the default value?'))
	{
		var msg = getXMLHTTPResponse('ajax_resetpassword.php', "typ=reset&id="+idx+"&pwd="+password);
		alert( msg );
	}
	return false;
}


function toggleCheckBoxes(formEl, type, checked) 
{
	type = type + '[]';
	for(var i=0; i<formEl.length; i++)
	{
		if(formEl[i].type == 'checkbox' && formEl[i].name.indexOf(type)==0)
		{
			if (!formEl[i].disabled) formEl[i].checked = checked;
		}
	}
	return false;
}


function toggleCheckBoxesId(formEl, type, checked) 
{
	for(var i=0; i<formEl.length; i++)
	{
		if(formEl[i].type == 'checkbox' && formEl[i].id.indexOf(type)==0)
		{
			if (!formEl[i].disabled) formEl[i].checked = checked;
		}
	}
	return false;
}



function toggleCheckBoxesAll(formEl, checked) 
{
	for(var i=0; i<formEl.length; i++)
	{
		if(formEl[i].type == 'checkbox')
		{
			if (!formEl[i].disabled) formEl[i].checked = checked;
		}
	}
	return false;
}


function toggleCheckBoxesDisable(formEl, checked) 
{
	for(var i=0; i<formEl.length; i++)
	{
		if(formEl[i].type == 'checkbox')
		{
			formEl[i].disabled = checked;
		}
	}
	

	if (formEl.name == "wbPreferencesForm")
	{
		formEl.fullstories[0].disabled = checked; 
		formEl.fullstories[1].disabled = checked;
		formEl.newsgroup[0].disabled = checked;
		formEl.newsgroup[1].disabled = checked;
		
	}
	
}




  


function changeColour(ID) 
{
	aWindow=window.open("lib/yuicolorpicker/colour.php?a="+ID,"NEF","toolbar=no,width=360,height=250,left=100,top=150,status=no,scrollbars=no,resize=no,menubars=no");
}


function nefflash(swf)
{
	document.write("<script type='text/javascript'>");
	document.write("AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','610','height','92','src','/pics/nef_"+swf+"','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','/pics/nef_"+swf+"' );\n");
	document.write("</script><noscript><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='610' height='92'>\n");
	document.write("<param name='movie' value='/pics/nef_"+swf+".swf' />\n");
	document.write("<param name='quality' value='high' />\n");
	document.write("<param name='wmode' value='transparent' />\n");
	document.write("<embed src='/pics/nef_"+swf+".swf' quality='high' wmode='transparent' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='610' height='92'></embed>\n");
	document.write("</object></noscript>\n");
}



// field1 - master field, 'onchange' script place
// field2 - linked list field
// arr - current array of values 
// field_nme - field name which use for option name
// field_id - field name which use for option id
// field_filter should = current field value in master field
function checkvalue(field1, field2, arr, field_nme, field_id, field_filter) 
{
	var field3=document.getElementById(field1);
	if (field3.type == "checkbox" || field3.type == "radio") var field3=document.getElementsByName(field1);
	var field2 = document.getElementById(field2);
	var curr = field2.options[field2.options.selectedIndex].value;
	var sel = false;
	
	if (field3 != null && field2 != null)
	{
		field2.length = 0;
		
		field_nme = field_nme.replace(' ', '');
		field_nme = field_nme.replace('_', '');
		field_nme = field_nme.replace('-', '');
		field_nme = field_nme.toLowerCase();
		
		field_id = field_id.replace(' ', '');
		field_id = field_id.replace('_', '');
		field_id = field_id.replace('-', '');
		field_id = field_id.toLowerCase();
		
		filter = getFieldValue(field3);		
		filter = filter.replace("'", "\'");
		filter = filter.toLowerCase();

		field2.options[field2.options.length] = new Option('[Select from list...]','');

		for (var i in arr)
		{
			if (arr[i][field_id] == curr) sel = true; else sel = false;
			if (arr[i][field_filter].toLowerCase() == filter) field2.options[field2.options.length] = new Option(arr[i][field_nme], arr[i][field_id], sel, sel);
		}
	}	
}



//  the same as above except: filter - current field value in master field for filter, should equal 1
function checkvalue2(field1, field2, arr, field_nme, field_id) 
{
	var field3=document.getElementById(field1);
	if (field3.type == "checkbox" || field3.type == "radio") var field3=document.getElementsByName(field1);
	var field2=document.getElementById(field2);
	var curr = field2.options[field2.options.selectedIndex].value;
	var sel = false;

	if (field3 != null && field2 != null)
	{
		field2.length = 0;
		
		field_nme = field_nme.replace(' ', '');
		field_nme = field_nme.replace('_', '');
		field_nme = field_nme.replace('-', '');
		field_nme = field_nme.toLowerCase();
		
		field_id = field_id.replace(' ', '');
		field_id = field_id.replace('_', '');
		field_id = field_id.replace('-', '');
		field_id = field_id.toLowerCase();
		
		filter = getFieldValue(field3);		
		filter = filter.replace(' ', '');
		filter = filter.replace('_', '');
		filter = filter.replace('-', '');
		filter = filter.toLowerCase();

		field2.options[field2.options.length] = new Option('[Select from list...]','');
		
		for (var i in arr)
		{
			if (arr[i][field_id] == curr) sel = true; else sel = false;

			if (arr[i][filter] == '1' || (field_id == 'opgradeid' && (((filter == 2 || filter == 8) && arr[i][field_id] >= 20) || (filter != 0 && filter !=2 && filter !=8 && arr[i][field_id] < 20))))							
						field2.options[field2.options.length] = new Option(arr[i][field_nme], arr[i][field_id], sel, sel);
		}
	}	
}


function currentTime(field1) 
{
	var field1=document.getElementById(field1);
	
	if (field1 != null)
	{
		var d = new Date();
		var curdate = d.getUTCFullYear()+"-0"+(d.getUTCMonth()+1)+"-"+d.getUTCDate() +" "+d.getUTCHours()+":"+d.getUTCMinutes();
		field1.value = curdate;
	}
}

function updateCurrency() 
{

	if (document.getElementById('opportunities_amountC'))
	{	
		var curr = document.getElementById('opportunities_amountC').value;  
		if (curr== null) curr = document.getElementById('opportunities_amountC').innerHTML; 
		if (document.getElementById('opportunities_amount_symbol')) document.getElementById('opportunities_amount_symbol').innerHTML = curr;
		if (document.getElementById('opportunities_revenue_symbol') && document.getElementById('opportunities_revenue').value != '') document.getElementById('opportunities_revenue_symbol').innerHTML = curr; 
		if (document.getElementById('opportunities_listprice_symbol')) document.getElementById('opportunities_listprice_symbol').innerHTML = curr;
		if (document.getElementById('opportunities_negotiatedprice_symbol')) document.getElementById('opportunities_negotiatedprice_symbol').innerHTML = curr; 
		if (document.getElementById('opportunities_slcPotential_symbol')) document.getElementById('opportunities_slcPotential_symbol').innerHTML = curr; 
		if (document.getElementById('opportunities_invoice1amount_symbol')) document.getElementById('opportunities_invoice1amount_symbol').innerHTML = curr; 
		if (document.getElementById('opportunities_invoice2amount_symbol')) document.getElementById('opportunities_invoice2amount_symbol').innerHTML = curr; 
		if (document.getElementById('opportunities_invoice3amount_symbol')) document.getElementById('opportunities_invoice3amount_symbol').innerHTML = curr; 
		if (document.getElementById('opportunities_invoice4amount_symbol')) document.getElementById('opportunities_invoice4amount_symbol').innerHTML = curr; 
	}
	
	if (document.getElementById('solarcontracts_currID'))
	{	
		var curr = document.getElementById('solarcontracts_currID').value;  
		if (curr == null) curr = document.getElementById('solarcontracts_currID').innerHTML; 
		if (document.getElementById('solarcontracts_contractLocal_symbol')) document.getElementById('solarcontracts_contractLocal_symbol').innerHTML = "m " + curr;
	}
	
	if (document.getElementById('CCS_projects_currID'))
	{	
		var curr = document.getElementById('CCS_projects_currID').value;  
		if (curr == null) curr = document.getElementById('CCS_projects_currID').innerHTML; 
		if (document.getElementById('CCS_projects_totalLocal_symbol')) document.getElementById('CCS_projects_totalLocal_symbol').innerHTML = "m " + curr;
	}

	if (document.getElementById('CCS_capturetechnology_currID'))
	{	
		var curr = document.getElementById('CCS_capturetechnology_currID').value;  
		if (curr == null) curr = document.getElementById('CCS_capturetechnology_currID').innerHTML; 
		if (document.getElementById('CCS_capturetechnology_costLocal_symbol')) document.getElementById('CCS_capturetechnology_costLocal_symbol').innerHTML = "m " + curr;
	}

	if (document.getElementById('NUC_powerstations_currID'))
	{	
		var curr = document.getElementById('NUC_powerstations_currID').value;  
		if (curr == null) curr = document.getElementById('NUC_powerstations_currID').innerHTML; 
		if (document.getElementById('NUC_powerstations_costLocal_symbol')) document.getElementById('NUC_powerstations_costLocal_symbol').innerHTML = "m " + curr;
	}
	
	if (document.getElementById('NUC_reactortechnology_currID'))
	{	
		var curr = document.getElementById('NUC_reactortechnology_currID').value;  
		if (curr == null) curr = document.getElementById('NUC_reactortechnology_currID').innerHTML; 
		if (document.getElementById('NUC_reactortechnology_costLocal_symbol')) document.getElementById('NUC_reactortechnology_costLocal_symbol').innerHTML = "m " + curr;
	}

	if (document.getElementById('NUC_reactors_currID'))
	{	
		var curr = document.getElementById('NUC_reactors_currID').value;  
		if (curr == null) curr = document.getElementById('NUC_reactors_currID').innerHTML; 
		if (document.getElementById('NUC_reactors_totalLocal_symbol')) document.getElementById('NUC_reactors_totalLocal_symbol').innerHTML = "m " + curr;
	}

	if (document.getElementById('NUC_reactorcapacity_currID'))
	{	
		var curr = document.getElementById('NUC_reactorcapacity_currID').value;  
		if (curr == null) curr = document.getElementById('NUC_reactorcapacity_currID').innerHTML; 
		if (document.getElementById('NUC_reactorcapacity_totalLocal_symbol')) document.getElementById('NUC_reactorcapacity_totalLocal_symbol').innerHTML = "m " + curr;
	}
	
	return true;
}


function updateUnit() 
{

	if (document.getElementById('solarcontracts_volumeUnit'))
	{	
		var unit = document.getElementById('solarcontracts_volumeUnit').value;  
		if (unit == null) unit = document.getElementById('solarcontracts_volumeUnit').innerHTML; 
		if (document.getElementById('solarcontracts_volume_symbol')) document.getElementById('solarcontracts_volume_symbol').innerHTML = unit;
	}
	return true;
}



function changeSubscriptionStatus(field, val) 
{
	var field = document.getElementById(field);
	
	if (!confirm('The subscription status will change all users associated with this opportunity. \nYou have the ability to change individual user status.\nDo you want to change the current status?'))
	{
		field.value = val;
	}
	
	return true;
}


function dhtmlwin(title, body) 
{
		var w = document.body.clientWidth  * 0.8;
		var h = getWindowHeight() * 0.6;
		var winl = (document.body.clientWidth  - w) / 2;
		var wint = 40 + (getWindowHeight() - h) / 2;
		
		
		var inlinewin = dhtmlwindow.open("broadcastbox", "inline", "<table cellspacing='10'><tr><td id='text11'>"+body+"</td></tr></table>", title, "width="+w+"x,height="+h+"px,left="+winl+"px,top="+wint+"px,resize=1,scrolling=1", "recal");
		inlinewin.onclose=function(){ return window.confirm("Close Window?"); }
}


// Window Height
function getWindowHeight() {
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        return window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
        //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        return document.body.clientHeight;
    }
}

function expandTable(field, height) 
{
	var button = field + "Btn";
	var obj = document.getElementById(field);
	if (obj.style.display == 'none') 
	{
		hideTable(field);
	}
	
	if (obj.style.height == "")
	{	
		obj.style.height = height;
		document.getElementById(button+"maximimize").className = "";
		document.getElementById(button+"restore").className = "hidden";
	}
	else
	{
		obj.style.height = "";
		document.getElementById(button+"maximimize").className = "hidden";
		document.getElementById(button+"restore").className = "";
	}
	return true;
}

function hideTable(field) 
{

	var obj = document.getElementById(field);
	obj.style.display = (obj.style.display=='none') ? '' : 'none';

	//var button = document.getElementById(field + "Title");
	//button.className = (button.className=='hidden') ? 'tableTitle' : 'hidden';

	if (document.getElementById(field + "Btnmain") != null)
	{
		var button = document.getElementById(field + "Btnmain");
		button.className = (button.className=='hidden') ? '' : 'hidden';
	}
	
	var button = document.getElementById(field + "Btnshow");
	button.className = (button.className=='hidden') ? '' : 'hidden';

	var button = document.getElementById(field + "Btnhide");
	button.className = (button.className=='hidden') ? '' : 'hidden';

	return true;
}

function showLiaisonreportUsers (org, users, yearmonth, company)
{
	var counter = 1;
	var myArray = users.split('');
	
	for (i=0;i<myArray.length;i++)
		if (myArray[i] == '~') counter++;


	 if (company == 'NCF') $line = 70; else $line = 40;
	$height = 410 + $line * counter;
		
	
	newWindow2("liaisonreport.php?org="+org+"&users="+users+"&yearmonth="+yearmonth+"&company="+company, screen.width*0.9, $height, "");
	
	return false;
}

function textLimit (fieldname, cntname, maxlimit)
{
	var field = document.getElementById(fieldname);
	var cnt = document.getElementById(cntname);
	
	if (field.value.length > maxlimit && maxlimit > 0) 
		field.value = field.value.substring(0, maxlimit);
	
	if (field.value.length > 0)
	{
		if ( maxlimit > 0)
			cnt.innerHTML = field.value.length + ' characters <i> &#160;(maximum ' + maxlimit + ' characters)</i>';
		else 
			cnt.innerHTML = field.value.length + ' characters';
	}	
}



function getFieldValue(field)
{
   switch(field.type)
   {
      case "text" :
      case "textarea" :
      case "password" :
      case "hidden" :
         return field.value;

      case "select-one" :
         var i = field.selectedIndex;
         if (i == -1)   return "";
         else   return (field.options[i].value == "") ? field.options[i].text : field.options[i].value;

      case "select-multiple" :
         var allChecked = new Array();
         for(i = 0; i < field.options.length; i++)
            if(field.options[i].selected)
               allChecked[allChecked.length] = (field.options[i].value == "") ? field.options[i].text : field.options[i].value;
         return allChecked;

      case "button" :
      case "reset" :
      case "submit" :
         return "";

      case "radio" :
      case "checkbox" :
         if (field.checked) { return field.value; } else { return ""; }
      default :
         if(field[0].type == "radio")
         {
            for (i = 0; i < field.length; i++)
               if (field[i].checked)
                  return field[i].value;

            return "";
         }
         else if(field[0].type == "checkbox")
         {
            var allChecked = new Array();
            for(i = 0; i < field.length; i++)
               if(field[i].checked)
                  allChecked[allChecked.length] = field[i].value;

            return allChecked;
         }
         else
            var str = "";
            for (x in field) { str += x + "\n"; }
            alert("I couldn't figure out what type this field is...\n\n" + field.name + ": ???\n\n\n" + str + "\n\nlength = " + field.length);
            return field1.value;			
         break;
   }
   
   return "";
}

function updateLog(table, id, table2, id2, f, f2)
{
	if (document.getElementById("logType") != null)  val  = getFieldValue(document.getElementsByName("logType")); else val = 1;
	if (document.getElementById("logField") != null && f != null) val2 = getFieldValue(document.getElementById("logField")); else val2 = "";
	
	var url = "ajax_log.php?table="+ table + "&id="+ id + "&table2="+ table2 + "&id2="+ id2 + "&logType=" + val + "&logField=" + val2;
	
	assignXMLHTTPResponse(url, 'logArea');

	if 	(f2 == null)
	{
		$("#sorttable").tablesorter({widgets: ['zebra']});		
		$("#sorttable").collapsible("td.collapsible", {collapse: true});
		//$("#sorttable").trigger("update");	
	}
}



function averagesMatrixReset() 
{
	var dealID 		= getFieldValue(document.getElementById("averagesmatrix_dealID"));
	var typeID 		= document.getElementById("averagesmatrix_typeID");
	var transtypeID = document.getElementById("averagesmatrix_transtypeID");
	var bmID 		= document.getElementById("averagesmatrix_bmID");
	var rafType 	= document.getElementById("averagesmatrix_rafType");
	
	typeID.disabled = 1;
	transtypeID.disabled = 1;
	bmID.disabled = 1;
	rafType.disabled = 1;
	
	if (dealID == "fnd") typeID.disabled = 0;
	if (dealID == "ipo") transtypeID.disabled = 0;
	if (dealID == "acq") bmID.disabled = 0;
	if (dealID == "rf") rafType.disabled = 0;
	
	return false;
}

