<!--
/**
 *	check browser and set browser type and objects
 *	I really hate the compatibility about the Javascript!
 */
function sf_Browser()
{
	d = document;
	this.agt = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.dom = (d.getElementById)?1:0;
	this.ns = (d.layers);
	this.ns4up = (this.ns && this.major >=4);
	this.ns6 = (this.dom&&navigator.appName=="Netscape");
	this.op = (window.opera? 1:0);
	this.ie = (d.all);
	this.ie4 = (d.all&&!this.dom)?1:0;
	this.ie4up = (this.ie && this.major >= 4);
	this.ie5 = (d.all&&this.dom);
	this.win = ((this.agt.indexOf("win")!=-1) || (this.agt.indexOf("16bit")!=-1));
	this.mac = (this.agt.indexOf("mac")!=-1);
}
var sf_obj = new sf_Browser();
function sf_getPageX(o)
{ 
	var x=0; 
	if(sf_obj.ns) x=o.pageX; 
	else { 
		while(eval(o)) { 
			x+=o.offsetLeft; 
			o=o.offsetParent; 
		} 
	} 
	return x; 
}
function sf_getPageY(o)
{ 
	var y=0; 
	if(sf_obj.ns) y=o.pageY; 
	else { 
		while(eval(o)) { 
			y+=o.offsetTop; 
			o=o.offsetParent;
		} 
	} 
	return y; 
}

/**
 *	for menu, button function
 *	modified from Yahoo mail scripts
 *	it is used on some components, sman...
 */

/* Button */
function sf_BtnClick(p_oEvent)
{
	var oEvent = p_oEvent ? p_oEvent : window.event;
	var oSender = p_oEvent ? oEvent.target : oEvent.srcElement;

	if(p_oEvent) oEvent.stopPropagation();
	else oEvent.cancelBubble = true;

	this.Event = oEvent;
	this.Sender = oSender;

	sf_HideMenu();
	this.Menu.Button = this;
	global_oMenu = this.Menu;

	if(typeof this.ClickHandler != 'undefined') this.ClickHandler();
	else global_oMenu.Show();
	
	document.onclick = sf_DocClick;

	return false;
}

function sf_DropDownMenu(p_sMenuId)
{
	var oMenu = document.getElementById(p_sMenuId);

	if(oMenu)
	{
		oMenu.Show = function () { 

			if(document.all) this.style.width = this.offsetWidth+'px';

			var nTop = sf_getPageY(this.Button) + this.Button.offsetHeight;
			var nLeft = sf_getPageX(this.Button);
			
			if(sf_obj.ie && sf_obj.mac){
				nTop -= 4;
				nLeft -= 6;	
			}

			this.style.top = nTop+'px';
			this.style.left = nLeft+'px';
			this.style.visibility = 'visible'; 
		}
		return oMenu;
	}
	else return false;
}

function sf_RightMenu(p_sMenuId)
{
	var oMenu = document.getElementById(p_sMenuId);

	if(oMenu)
	{
		oMenu.Show = function () { 

			if(document.all) this.style.width = this.offsetWidth+'px';

			var nTop = sf_getPageY(this.Button);
			var nLeft = sf_getPageX(this.Button) + this.Button.offsetWidth;
			
			if(sf_obj.ie && sf_obj.mac){
				nTop -= 4;
				nLeft -= 6;	
			}

			this.style.top = nTop+'px';
			this.style.left = nLeft+'px';
			this.style.visibility = 'visible'; 
		}
		return oMenu;
	}
	else return false;
}

function Button(p_sButtonId)
{
	var oButton = document.getElementById(p_sButtonId);
	
	if(oButton){
		oButton.onclick = sf_BtnClick;
		return oButton;
	}
	else return false;
}

function overButton(p_sButtonId)
{
	var oButton = document.getElementById(p_sButtonId);
	
	if(oButton){
		oButton.onmouseover = sf_BtnClick;
		return oButton;
	}
	else return false;
}

function sf_BtnMenu(p_sButtonId, p_sMenuId, p_ev)
{
	if(!p_ev){
		var oButton = new Button(p_sButtonId);

		if(oButton){
			oButton.Menu = new sf_DropDownMenu(p_sMenuId);
			return oButton;
		}
		else return false;
	}else if(p_ev == 'over') {
		var oButton = new overButton(p_sButtonId);
		if(oButton){
			oButton.Menu = new sf_DropDownMenu(p_sMenuId);
			return oButton;
		}
		else return false;
	}else if(p_ev == 'rOver') {
		var oButton = new overButton(p_sButtonId);
		if(oButton){
			oButton.Menu = new sf_RightMenu(p_sMenuId);
			return oButton;
		}
		else return false;
	}
}

function sf_HideMenu()
{
	if(typeof global_oMenu != 'undefined' && global_oMenu)
	{
		if(global_oMenu.Hide) global_oMenu.Hide();
		else global_oMenu.style.visibility = 'hidden';
		
		global_oMenu = null;
		document.onclick = null;
		window.onresize = null;
	}
	else return;
}

function sf_DocClick()
{
	if(document.Selects)
	{
		var nSelects = document.Selects.length-1;
		for(var i=nSelects;i>=0;i--) document.Selects[i].style.visibility = 'visible';
	}

	sf_HideMenu();
}

/* Image */
function sf_Img(p_imgId)
{
	var oImg = document.getElementById(p_imgId);
	
	if(oImg){
		oImg.onclick = sf_BtnClick;
		return oImg;
	}
	else return false;
}

function sf_ImgMenu(imgId, p_sMenuId)
{
	var img = new sf_Img(imgId);
	if(img){
		img.Menu = new sf_DropDownMenu(p_sMenuId);
		return img;
	}else return false;
}

function sf_getObj(p_oId) {
	var oid = document.getElementById(p_oId);
	return oid;
}

/**
 *	common functions
 */
// input form onclick event function
function OnEnter(field)
{ 
	if(field.value == field.defaultValue ){ 
		field.value = ""; 
	} 
}
// input form onblur event function
function OnExit(field)
{ 
	if(field.value == ""){ 
		field.value = field.defaultValue; 
	} 
}
// site manager
function sman(key)
{
	var key = "index.php?key=" + key;
	window.open(key,
	'sMan',
	'toolbar=no,location=(20,20),directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=800,height=600'
	);
}

// check all
function sf_checkAll(theForm, act)
{
	var elements = theForm.elements['sf_chk[]'];
	var elements_count = elements.length;

	if(elements_count){
		for(var i=0; i<elements_count; i++){
			elements[i].checked = act;
		}
	}
}

// check all on/off
function sf_checkAllAuto(theForm)
{
	var elements = theForm.elements['sf_chk[]'];
	var elements_count = elements.length;
	var chkBtn = theForm.sf_chkAll;

	if(chkBtn.checked) var act = true;
	else var act = false;

	if(elements_count){
		for(var i=0; i<elements_count; i++){
			elements[i].checked = act;
		}
	}
}

// confirm and go
function sf_confirmNgo(url, msg)
{
	if(confirm(msg)){
		location.href = url;
	}else return false;
}

// confirm
function sf_confirm(theForm, msg)
{
	if(confirm(msg)){
		theForm.submit();
	} else {
		return false;
	}
}

// delete confirm
function sf_delete(msg)
{
	if(confirm(msg)) return true;
	else return false;
}

// add form element to submit
function sf_submit(theForm, formName, value)
{
	var elmt = theForm.elements[formName];
	elmt.value = value;
	theForm.submit();
}

function sf_selectWin(url)
{
	window.open(url, 'selectWin',
		'toolbar=no,location=(20,20),directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=500,height=480'
	);
}

function sf_newWin(url)
{
	window.open(url, 'newWin',
		'toolbar=no, location=(20,20), directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=640, height=480'
	);
}

function sf_mProfile(uid)
{
	var url = script_name + "?iKey=profile&mid=" + uid + "&hide_header=1";
	window.open(url, 'mProfile',
		'toolbar=no,location=(20,20),directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=400'
	);
}

function sf_mailer(receiver)
{
	var url = script_name + "?iKey=mailer&to=" + receiver + "&hide_header=1";
	window.open(url, 'mailer',
		'toolbar=no,location=(20,20),directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=400,height=400'
	);
}

function sf_help(id)
{
	var url = script_name + "?iKey=help&id="+id+"&no_header=1";
	window.open(url, 'help',
		'toolbar=no, location=(20,20), directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=640, height=480'
	);
}
-->