var currentobj;
function toggleId(id) {
	if (!document.getElementById(id)) return(true);
	obj = document.getElementById(id);
	currentobj = obj;

	var init = '';
	var destroy = '';

	// id, init, destroy
	if (arguments.length > 1) init = arguments[1].toString();
	if (arguments.legth > 2) destroy = arguments[2].toString();

	if (obj.style.display == 'none') {
		if (init != '') {
			eval(init);
		} else if (obj.getAttribute('onshow')) {

			eval(obj.getAttribute('onshow'));
		}
		
		if (obj.tagName == 'TR' && !document.all) {
			obj.style.display = "table-row";
		} else if ((navigator.userAgent.indexOf("Opera")!=-1 || navigator.userAgent.indexOf("Opera/")!=-1) && obj.tagName == 'TR') {
                        obj.style.display = "table-row";
                } else {
                        obj.style.display = 'block';
                }
        } else {
		if (destroy != '') eval(destroy);
		else if (obj.getAttribute('onhide')) eval(obj.getAttribute('onhide'));
		obj.style.display = 'none';
        }
        return(false);
}

function visibleId(id) {
	if (!document.getElementById(id)) return(true);
	obj = document.getElementById(id);

	var init = '';
	var destroy = '';

	// id, init, destroy
	if (arguments.length > 1) init = arguments[1].toString();
	if (arguments.length > 2) destroy = arguments[2].toString();

	if (obj.style.display == 'none') {
		if (init != '') eval(init);
		else if (obj.getAttribute('onshow')) eval(obj.getAttribute('onshow'));
		
		if (obj.tagName == 'TR' && !document.all) {
			obj.style.display = "table-row";
		} else if ((navigator.userAgent.indexOf("Opera")!=-1 || navigator.userAgent.indexOf("Opera/")!=-1) && obj.tagName == 'TR') {
                        obj.style.display = "table-row";
                } else {
                        obj.style.display = 'block';
                }
        }
        return(false);
}

function toggle(id) {
	if (!document.getElementById(id)) return(false);
	obj = document.getElementById(id);
	if (!obj.className.match(/hide/)) {
		obj.className += ' hide';
	}else {
		obj.className = obj.className.replace(/\s*hide/,'');
	}
	return(false);
}

var testtime = 0;
var timediv = '';
var onunload_action = 1;
var onsubmit_confirm = 1;

function CountDown() {
	testtime--;
	var s = testtime;

	if (testtime <= 0) {
		return(FormNoActionsSubmit());
	}

	var h = m = 0;
	if (s > 3600) {
		h = parseInt(s / 3600);
		s -= 3600*h;
	}
	if (s > 60) {
		m = parseInt(s / 60);
		s -= 60*m;
	}
	if (s<10) s = '0'+s;
	if (m<10) m = '0'+m;
	if (h<10) h = '0'+h;
	var str = h + ':' + m + ':' + s;
	obj = document.getElementById(timediv);
	if (h == 0 && m == 0 && s <= 10 && !obj.className.match(/textRed/) )
		obj.className += ' textRed';
	obj.innerHTML = str;
	window.setTimeout(CountDown,1000);
}

function StartTime(time,id) {
	testtime = time;
	timediv = id;
	window.setTimeout(CountDown,1000);
}
function aken(url, name, w, h)
{
        var new_win;
	if (h == '100%') {
		if (screen.availHeight)
			h = 2*screen.availHeight-screen.height;
		else
			h = screen.height;
	}
	if (w == '100%') {
		w = screen.width;
	}
        var features = 'width='+w+',height='+h+',toolbar=0,status=0,menubar=0,directories=0,location=0,scrollbars=yes,copyhistory=0,resizable=yes';

        new_win = open(url, name, features);
        new_win.focus();
	new_win.moveTo(0,0);
	return(false);
}

function swapImage(imgName,newImg)
{
        if ((navigator.appName == 'Netscape' && parseFloat(navigator.appVersion) >= 3) || (parseFloat(navigator.appVersion) >= 4))
	{
                eval('document.' + imgName + '.src = "' + newImg + '"')
        }
}

function random_password()
{
	var alph = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
	var length = alph.length;
	var newpasswd = new String;
	var random = 0;
                
	for (i=0;i<8;i++)
	{
		random = parseInt(Math.random()*length);
		newpasswd = newpasswd + alph.charAt(random);
	}
	return(newpasswd);
}

// helper for radio button checking
function RadioCheck(id) {
	obj = document.getElementById(id);
	if (obj != null) {
		obj.checked = true;
		if (obj.form.elements[obj.name].length > 0)
		for (i=0;i<obj.form.elements[obj.name].length;i++) {
			tmpobj = obj.form.elements[obj.name][i];
			if (tmpobj.onchange != null) tmpobj.onchange();
			
		}
		if (obj.onchange != null) obj.onchange();
	}
}

function ChangeRadioBg(obj,id,on,off) {
	el = document.getElementById(id);
	if (el != null && obj != null) {
		if (obj.checked == true) el.style.background = on;
		else el.style.background = off;
	}
}

function OnUnLoadCheck() {
	if (onunload_action != 1)
		return(true);
	else if (document.testing != null) {
		onsubmit_confirm = 0;
		document.testing.submit();
	}
}

function OnSubmitCheck(txt) {
	if (onsubmit_confirm == 1) {
		ok = confirm(txt);
		if (ok) {
			onsubmit_confirm = 0;
			onunload_action = 0;
			return(true);
		}else {
			return(false);
		}
	}
}

function FormNoActionsSubmit() {
	onsubmit_confirm = 0;
	onunload_action = 0;
	if (document.testing != null)
		document.testing.submit();
	else
	{
		tmp = document.getElementById('testing');
		if (tmp != null) tmp.submit();
		else
		{
			if (document.forms[0] != null)
				document.forms[0].submit();
		}
	}
	return(false);
}

// This is a javascript handler for the player and is always needed.
function thisMovie(movieName) {
	if(navigator.appName.indexOf("Microsoft") != -1) {
		//return window[movieName];
		return document.all[movieName];
	} else {
		return document[movieName];
	}
}

function heightTo(id,min) {
	obj = document.getElementById(id);
	cur = getBrowserHeight();
	var tmp = parseInt(cur - min);

	if (obj != null) {
		obj.style.height = tmp + 'px';
	}
}

function getBrowserHeight() {
                h = 0;

                //Non-IE
                if( typeof( window.innerHeight ) == 'number' ) {
                        h = window.innerHeight;

                //IE 6+ in 'standards compliant mode'
                } else if ( document.documentElement && document.documentElement.clientHeight) {
        
                        h = document.documentElement.clientHeight;

                //IE 4 compatible
                } else if( document.body && document.body.clientHeight ) {

                        h = document.body.clientHeight;
                }

                return(h);
}

function countwords(obj,chars_id,words_id) {
	cobj = document.getElementById(chars_id);
	wobj = document.getElementById(words_id);

	var chars = 0;
	var words = 0;

	var cont = obj.value;
	if (cont != '') {
		chars = cont.length;
		var tmp = cont.split(" ");
		for (i=0;i<tmp.length;i++)
			if (tmp[i] != '' && tmp[i].length > 1) words++;
	}
		

	if (cobj != null) cobj.innerHTML = chars;
	if (wobj != null) wobj.innerHTML = words;
}

var auto_update_url = '';
function SetAutoUpdate(url) {
	auto_update_url = url;
	form = document.forms['testing'];
	if (form == null) return(false);
	for  (i=0;i<form.elements.length;i++)
	{
		if (form.elements[i].type != 'hidden')
			form.elements[i].onchange = AutoUpdate;
	}	
}

function AutoUpdate() {
	form = document.forms['testing'];

	var success = function (r) {};
	var failure = function (r) {};
	
	if (YAHOO.util.Connect != null) {
		YAHOO.util.Connect.asyncRequest( 'POST', auto_update_url, {success:success, failure:failure}, YAHOO.util.Connect.setForm(form));
	}
}

