﻿function getXMLHttpRequest() {
	if (window.ActiveXObject) {
		try {
			return new ActiveXObject('Msxml2.XMLHTTP');
		} catch(e) {
			try {
				return new ActiveXObject('Microsoft.XMLHTTP');
			} catch(e1) { return null; }
		}
	} else if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else {
		return null;
	}
}

function chk_byte(chr){
	var c = escape(chr);
	if(c.length == 1) return 1;
	else if(c.indexOf("%u") != -1) return 2;
	else if(c.indexOf("%") != -1) return c.length/3;
}

function cut_str_byte(str , limit_length){
	var byte_size = 0;
	for(var i=0; i<str.length; i++){
		byte_size += chk_byte(str.charAt(i));
		if(byte_size > limit_length) break;
	}
	return str.substr(0 , i);
}

function byte_length(str){
	var resultSize = 0;
	if (str == null) return 0;
	for(var i=0; i<str.length; i++) resultSize += chk_byte(str.charAt(i));
	return resultSize;
}

function chk_byte_length(obj , limit_length){	
	if(byte_length(obj.value) > limit_length){
		alert('글자수 제한을 초과하였습니다.');
		obj.value = cut_str_byte(obj.value , limit_length);
		return false;
	}
	return true;
}

function trim(str){
	str = str.replace(/(^\s*)|(\s*$)/g, "");
	return str;
}

function serialize(form){
	var return_value = '';
	for(i = 0;i < form.elements.length;i++){
		if(form.elements.item(i).type == 'checkbox' || form.elements.item(i).type == 'radio'){
			if(form.elements.item(i).checked){
				if(i > 0) return_value = return_value + '&';
				return_value = return_value + form.elements.item(i).name + '=' + encodeURIComponent(form.elements.item(i).value);
			}
		}
		else{
			if(i > 0) return_value = return_value + '&';
			return_value = return_value + form.elements.item(i).name + '=' + encodeURIComponent(form.elements.item(i).value);
		}
	}
	return return_value;
}

function copy_clipboard(text,msg){
	window.clipboardData.setData('Text',text);
	alert(msg);
}

function displayImage(picName, windowName, windowWidth, windowHeight){
	var winHandle = window.open("" ,windowName,"toolbar=no,scrollbars=yes,status=no, location = no,resizable=no,width=" + (parseInt(windowWidth)+20) + ",height=" + windowHeight + ",left=225,top=165");
	if(winHandle != null){
		var htmlString = "<html><head><title>DETAIL IMAGE</title></head>"; 
		htmlString += "<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>";
		htmlString += "<a href=javascript:window.close()><img src=" + picName + " border=0 alt=닫기></a>";
		htmlString += "</body></html>";
		winHandle.document.open();
		winHandle.document.write(htmlString);
		winHandle.document.close();
	} 
	if(winHandle != null) winHandle.focus();
	return winHandle;
}

function move_url(flag , url){
	if(flag == "1"){
		var o  = document.createElement("form"); 
		document.body.appendChild(o); 
		o.setAttribute('target','blank'); 
		o.setAttribute('action',url); 
		o.submit(); 
	}
	else if(flag == "2"){
		location.href = url;
	}
}

function enter(func){
	if(event.keyCode == 13){
		eval(func);
	}
}