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 pop_volunteer(){
	var link_url = '/include/pop_volunteer.html';
	window.open(link_url,'volunteer','width=484,height=337,toolbar=no,status=no,menubar=no,scrollbars=no,left=300px,top=300px,resizable=no'); 
}

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;
	}
}

var click_chk = '';
function proc_click(flag , idx){
	var tmp_img = new Image(0,0);

	var click_idx = click_chk.split(',');
	var click_cnt = 0;

	if(click_idx.length){
		for(i = 0;i < click_idx.length;i++){
			if(click_idx[i] == flag + idx) click_cnt++;
		}
	}

	if(click_cnt == 0){
		tmp_img.src = '/data/proc_click.asp?flag=' + flag + '&idx=' + idx;
		click_chk = click_chk + ',' + flag + idx;
	}
}

function proc_join(idx , url , flag){
	proc_click('join' , idx);
	move_url(flag , url);
}

function proc_scrap(idx , scrap_txt){
	proc_click('scrap' , idx);
	if(scrap_txt) copy_clipboard(scrap_txt,'주소가 복사되었습니다, Ctrl + V로 붙여넣기 하세요^^');
}

function proc_postscript(idx , param , loginYN){
	if(loginYN == 'True'){
		proc_click('postscript' , idx);
		vt_ps_write_page('' , '<%= ps_param %>&page=<%= page %>' , '#ps_area');
	}
	else{
		alert('로그인 해주세요');
	}
}

function enter(func){
	if(event.keyCode == 13){
		eval(func);
	}
}