// 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;
	}
}

function sf_checkOnOff(theForm, chkBox, elmBox) {
	var checkBox = chkBox;
	var elements = theForm.elements[elmBox];
	var elements_count = elements.length;


	if(elements_count){
		if (checkBox.checked == true) {
			for(var i=0; i<elements_count; i++){
				elements[i].checked = true;
			}
		} else {
			for(var i=0; i<elements_count; i++){
				elements[i].checked = false;
			}
		}
	}
}

function sf_showPageMoveForm(mark){
	$('pageMoveForm').show();
	$('pageMoveForm').style.left = mark.offsetLeft + 'px';
	//$('pageMoveForm').style.top  = mark.offsetTop + 'px';
}

function sf_toggleEditor(type, obj, epath, eheight) {

	if (type==3) {
		if (document.getElementById('div_'+obj).firstChild.nodeName == 'TEXTAREA') {

			if (eheight<300) {
				eheight = 300;
			}

			$(function(){
				$.fck.path = epath;
				$('#'+obj).fck({toolbar: 'Basic', height: eheight });
			});

/*
			var sBasePath = path;
			if (height<300) {
				height = 300;
			}
			var oFCKeditor = new FCKeditor( obj ) ;
			oFCKeditor.BasePath	= sBasePath ;
			oFCKeditor.Height	= height ;
			oFCKeditor.ToolbarSet	= 'Basic';
			//oFCKeditor.DefaultLanguage	= "ko";
			oFCKeditor.ReplaceTextarea() ;
*/
		}
	} else {
		if (document.getElementById('div_'+obj).firstChild.nodeName != 'TEXTAREA') {
			var oEditor = FCKeditorAPI.GetInstance(obj) ;
			var cont = oEditor.GetHTML();

			if (type<2 && cont){
				cont = strip_tags(cont);
			}

			$('#div_'+obj).html("<textarea name='"+obj+"' id='"+obj+"' style='height: "+eheight+"px; width: 100%;'>"+cont+"</textarea>");
		}
	}

}

function sf_sendmemo() {
	alert('Wait!');
}

function sf_sendmail(mail) {
	var url = '?iKey=sendmail';
	if (mail) {
		url += "&mail="+mail;
	}
	window.open(url, 'SendMail',
		'toolbar=no, location=(20,20), directories=no, status=no, menubar=no, scrollbars=auto, resizable=yes, width=700, height=600'
	);
}

function sf_profile(uid) {
	if (typeof memberDB =='undefined') {
		var url = '?iKey=profile&no_header=1&mid=' + uid;
	} else {
		var url = '?db='+ memberDB +'&actKey=profile&no_header=1&mid=' + uid;
	}

	window.open(url, 'Profile',
		'toolbar=no, location=(20,20), directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=400, height=500'
	);
}

function sf_view_stationery(sty, url_core) {
	var url = url_core + 'library/sendmail.stationery/' + sty;
	window.open(url, 'ViewStationary',
		'toolbar=no, location=(20,20), directories=no, status=no, menubar=no, scrollbars=auto, resizable=yes, width=400, height=160'
	);
}

function sf_check_id(idField, idValue) {
	var url = '?iKey=checkid&idField='+idField+'&idValue='+idValue;
	window.open(url, 'CheckIdWindow',
		'toolbar=no, location=(20,20), directories=no, status=no, menubar=no, scrollbars=auto, resizable=yes, width=200, height=240'
	);
}

function sf_showHideDiv(clsname, objname, curid, bhv) {

	$(document).ready(function() {
		var divs = $(clsname);
		idArray = new Array();
		var s = 0;

		for (x=0; x<divs.length; x++) {
			if (!empty(divs[x].id)) {
				idArray[s] = divs[x].id;
				s++;
			}
		}

/*
		if (!curid) {
			var hideall = true;
			for (var i=0; i<idArray.length; i++) {
				if ($("#"+idArray[i]).is(":hidden")) var hideall = false;
			}

			if (hideall) {
				for (var i=0; i<idArray.length; i++) {
					if (bhv=='noeffect') $("#"+idArray[i]).hide();
					else $("#"+idArray[i]).slideUp("100");
				}
			} else {
				for (var i=0; i<idArray.length; i++) {
					if (bhv=='noeffect') $("#"+idArray[i]).show();
					else $("#"+idArray[i]).slideDown("100");
				}
			}

		} else
*/
		if (curid=="showall") {
			for (var i=0; i<idArray.length; i++) {
				if (bhv=='noeffect') $("#"+idArray[i]).show();
				else $("#"+idArray[i]).slideDown("100");
			}
		} else if (curid=="hideall") {
			for (var i=0; i<idArray.length; i++) {
				if (bhv=='noeffect') $("#"+idArray[i]).hide();
				else $("#"+idArray[i]).slideUp("100");
			}
		} else if ($("#"+objname+curid).is(":hidden")) {
			for (var i=0; i<idArray.length; i++) {
				if (idArray[i]==objname+curid) {
					if (bhv=='noeffect') $("#"+idArray[i]).show();
					else $("#"+idArray[i]).slideDown("100");
				} else {
					if (bhv=='noeffect') $("#"+idArray[i]).hide();
					else $("#"+idArray[i]).slideUp("100");
				}
			}

		} else {
			if (bhv=='noeffect') $("#"+objname+curid).hide();
			else $("#"+objname+curid).slideUp("100");
		}

	});
}

function sf_editChoiceForm(var_uid, varDB, targetDiv, v_key, v_name, v_curval, func) {
	var url = '?db='+varDB+'&actKey=edit&var_uid='+var_uid+'&hide_header=1&targetDiv='+targetDiv+'&v_key='+v_key+'&v_name='+v_name+'&v_curval='+v_curval+'&func='+func;
	window.open(url, 'varEditWindow',
		'toolbar=no, location=(20,20), directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width=600, height=500'
	);
}


function sf_open_window(url, width, height) {
	if (!width) {
		width = 600;
	}
	if (!height) {
		height = 400
	}
	window.open(url, 'openWindow',
		'toolbar=no, location=(20,20), directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, width='+ width +', height='+ height +''
	);
}

function sf_mm_extmenu(rand) {
	var mm = $('#'+rand);

	if (mm.is(":hidden")) {
		mm.fadeIn('fast');

		mm.bind("mouseleave",function(){
			mm.fadeOut('fast');
		});

		setTimeout('sf_mm_extmenuHide('+rand+')', 2000);

	} else {
		mm.fadeOut('fast');
	}

}

function sf_mm_extmenuHide(rand) {
	var mm = $('#'+rand);
	mm.fadeOut('fast');
}

function sf_toggleObj(objid) {
	var obj = document.getElementById(objid);

	if (obj.style.display=='none') {
		obj.style.display = 'block';
	} else {
		obj.style.display = 'none';
	}
}

// calculate typing start time
function sf_start_type(editorobj) {
	var eurl = '?iKey=set.starttime&obj='+editorobj;
	$.ajax({
		type: 'get',
		url: eurl,
		success: function(result) {
		}
	});
}

function sf_ajax_action(key, target, action) {
	var k = key.split(":");
	var eurl = "?" + k[0];
	eurl += "=" + k[1];
	eurl += "&";
	eurl += "hash";
	eurl += "=";
	eurl += HASH;

	if (action) {
		var a = action.split(":");
		eurl += "&";
		eurl += a[0];
		eurl += "=";
		eurl += a[1];
		if (a[2]) {
			eurl += "&";
			eurl += "op";
			eurl += "=";
			eurl += a[2];
		}
	}

	eurl += "&";
	eurl += "no_header";
	eurl += "=";
	eurl += "1";

	$.ajax({
		type: 'get',
		url: eurl,
		success: function(result) {
			$('#'+target).html(result);
		}
	});
}