
function popwin( wURL, wNAME, wWIDTH, wHEIGHT, wRESIZE, wSCROLL )
{
	var x = null;
	
	wX = (screen.width!=null)? screen.width/2-wWIDTH/2:0;
	wY = (screen.height!=null)? screen.height/2-wHEIGHT/2:0;
	
	if( wSCROLL == undefined ) wSCROLL = "0";
	if( wRESIZE == undefined ) wRESIZE = "0";
	
	wPARAM  = "left=" + wX + ",top=" + wY;
	wPARAM += ",WIDTH=" + wWIDTH + ",HEIGHT=" + wHEIGHT;
	wPARAM += ",location=0,resizable="+wRESIZE+",titlebar=1,directories=0";
	wPARAM += ",toolbar=0,menubar=0,scrollbars="+wSCROLL+",status=no";

	x = window.open( wURL, wNAME, wPARAM );
	x.focus();
}

function setClassName(elm,classname)
{
	var e = document.getElementById(elm);
	if(e) e.className = classname;
}

function changeIMG( imgId, imgSrc )
{
	if ( document.images )
    {
		img = document.getElementById( imgId );
		img.src = imgSrc;
	}
}

function timestamp()
{
	var n = new Date();
	_y = n.getYear(); if( _y < 1000 ) _y += 1900;
	_y *= 31556926;
	_m = n.getMonth()*2629744;
	_d = n.getDate()*86400;
	_h = n.getHours();
	_n = n.getMinutes();
	_s = n.getSeconds();
	return ( _y + _m + _d + _h + _n + _s );
}

function set_field_value(_id,_value)
{
	var e = document.getElementById(_id);
	if(e) e.value = _value;
}

function hide_div(_id)
{
	var e = document.getElementById(_id);
	if(e) e.style.display = 'none';
}

function sh_div(_id)
{
	var e = document.getElementById(_id);
	e.style.display = e.style.display=='none' ? 'block' : 'none';
	var s = e.style.display;
	
	var e = document.getElementById(_id+'_title');
	if(e){ e.className = s=='block' ? 'collapse_title' : 'collapsed_title'; };
}

function show_wordcount(_HTMLInputElement,_maxwords,_div)
{
	var wc = wordcount(_HTMLInputElement.value);
	var ws = (wc==1) ? wc+' word' : wc+' words';
	var op = (wc>_maxwords) ? '<span style="color: #cc0000; font-weight: bold;">'+ws+'</span>' : ws;
	if (wc==0) op = '';
	var el = document.getElementById(_div);
	if(el)
	{
		el.innerHTML = op;
		el.className = op=='' ? '' : 'wordcounter';
	}
}

function show_charcount(_HTMLInputElement,_maxchars,_div)
{
	var wc = _HTMLInputElement.value.length;
	var ws = (wc==1) ? wc+' letter' : wc+' letters';
	var op = (wc>_maxchars) ? '<span style="color: #cc0000; font-weight: bold;">'+ws+'</span>' : ws;
	if (wc==0) op = '';
	var el = document.getElementById(_div);
	if(el)
	{
		el.innerHTML = op;
		el.className = op=='' ? '' : 'charcounter';
	}
}

function wordcount(txt)
{
	txt = txt.replace(/[\s]+/gi,' ');
	var w=txt.split(' ');
	return (txt == '') ? 0 : w.length;
}

function launch_gpcfiles(gpc)
{
	var win_w = 450;
	var win_h = 350;
	var win_x = (screen.width-win_w)/2;
	var win_y = (screen.height-win_w)/2;
	var wPARAM = '';
	wPARAM += 'left='+win_x+',top='+win_y+',width='+win_w+',height='+win_h;
	wPARAM += ',location=0,resizable=1,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1,status=no';
	
	var pw = window.open( 'index.php?page=mycase.files', 'ttwin', wPARAM );
}

function tooltipwin(wurl)
{
	var win_w = 300;
	var win_h = 250;
	var win_x = (screen.width-win_w)/2;
	var win_y = (screen.height-win_w)/2;
	var wPARAM = '';
	wPARAM += 'left='+win_x+',top='+win_y+',width='+win_w+',height='+win_h;
	wPARAM += ',location=0,resizable=1,titlebar=1,directories=0,toolbar=0,menubar=0,scrollbars=1,status=no';
	
	var pw = window.open( wurl, 'ttwin', wPARAM );
}

/*function openTvFull(p1, p2) {
	var wURL = "full_tv.php?p1=" + p1 + "&p2=" + p2;
	
	wPARAM  = "toolbar=no,width=" + screen.availWidth;
	wPARAM += ",height=" + screen.availHeight;
	wPARAM += ",status=no,resizable=no,fullscreen=yes,scrollbars=no";
	var x = window.open( wURL , "tv_full", wPARAM);
	x.focus();
}*/
function openTvFull(p1) {
	var wURL = "/full_tv.php?p1=" + p1;
	
	wPARAM  = "top=0,left=0,toolbar=no,width=" + screen.availWidth;
	wPARAM += ",height=" + screen.availHeight;
	wPARAM += ",status=no,resizable=no,scrollbars=no";
	var x = window.open( wURL , "tv_full", wPARAM);
	x.focus();
}


var fold_st = new Array();
function groupfold(elm,b)
{
	if(typeof fold_st[elm] != 'undefined' ) b = !fold_st[elm];
	var e = document.getElementById('div_'+elm);
	if(e)
	{
		e.style.display = b ? 'block' : 'none';
		
		var e = document.getElementById('a_'+elm);
		if(e)
		{
			e.className = b ? 'arrow_unfolded' : 'arrow_folded';
			fold_st[elm] = b;
		}
	}
}
function ungroupfold(elm,b)
{
	if(typeof fold_st[elm] != 'undefined' ) b = !fold_st[elm];
	var e = document.getElementById('div_'+elm);
	if(e)
	{
		e.style.display = b ? 'none' : 'block';
		
		var e = document.getElementById('com_'+elm);
		if(e)
		{
			e.className = b ? 'arrow_unfoldedcom' : 'arrow_foldedcom';
			fold_st[elm] = b;
		}
	}
}

function newgroupfold(elm,b)
{
	if(typeof fold_st[elm] != 'undefined' ) b = !fold_st[elm];
	var e = document.getElementById('div_'+elm);
	if(e)
	{
		e.style.display = b ? 'none' : 'block';
		
		var e = document.getElementById('com_'+elm);
		if(e)
		{
			e.className = b ? 'arrow_fold' : 'arrow_unfold';
			fold_st[elm] = b;
		}
	}
}

var foldi_st = new Array();
function groupfold_img(elm,b)
{
	if(typeof foldi_st[elm] != 'undefined' ) b = !foldi_st[elm];
	var e = document.getElementById('div_'+elm);
	if(e)
	{
		e.style.display = b ? 'block' : 'none';
		
		var e = document.getElementById('img_'+elm);
		if(e)
		{
			e.src = b ? 'img/arrow_unfolded.gif' : 'img/arrow_folded.gif';
			foldi_st[elm] = b;
		}
	}
}

function confirmURL(u,msg)
{
	var sure = confirm(msg);
	if(sure)
	{
		document.location = u;
	}
}