
var is_ie = navigator.appName == 'Microsoft Internet Explorer';
var is_op = navigator.appName == 'Opera' ? true : false;
//var is_ns = !is_ie && !is_op ? true : false;

String.prototype.trim = function() {
	return this.replace(/^\s*(\b.*\b|)\s*$/, "$1"); // 문장의 앞과 뒤의 공백 제거
}

function show_waiting() {
	var x = document.body.clientWidth/2 + document.body.scrollLeft - 150 ;
	var y = document.body.clientHeight/2 + document.body.scrollTop - 50 ;
	document.all.waiting.style.left = x ;
	document.all.waiting.style.top  = y ;
	document.all.waiting.style.visibility='visible';
}

/*-- 한글체크 ; 0 - 9 , a - z 사이의 값이 아닌 경우는 -1을 반환 --*/
function check_Hangeul(obj) {

	var intErr
	var strValue = obj.value
	var retCode = 0

	for (i=0; i<strValue.length; i++) {

		var retCode = strValue.charCodeAt(i)
		var retChar = strValue.substr(i,1).toUpperCase()

		retCode = parseInt(retCode)

		if ((retChar<"0" || retChar>"9") && (retChar<"A" || retChar>"Z") && ((retCode>255) || (retCode<0))) {
			intErr = -1;
			break;
		}
	}
	return (intErr);
}

/*-- 숫자 체크 ; 숫자가 아니면 -1을 반환한다. --*/
function check_Number(obj) {

	var intErr
	var newValue = obj.value
	var newLength = newValue.length;

	for(var i=0; i!=newLength; i++) {
		aChar = newValue.substring(i, i+1)
		if (aChar<"0" || aChar>"9") {
			intErr = -1;
			break;
		}
	}
	return (intErr);
}

function only_number(obj) {
	var intErr
	var newValue = obj.value
	var newLength = newValue.length;

	for (var i=0; i!=newLength; i++) {
		aChar = newValue.substring(i, i+1)
		if (aChar<"0" || aChar>"9") { 
			obj.value = '' ; 
		}
	}
}

/*-- 숫자 체크 --*/
function onlyNumber() {
	if((event.keyCode<48)||(event.keyCode>57))
    event.returnValue=false;
}

function isNum(str){ 
	if (isEmpty(str)) return false;
	for (var idx=0; idx<str.length; idx++) {
		if (str.charAt(idx)<'0' || str.charAt(idx)>'9') {
			return false;
		}
	}
	return true;
}

// 지정된 문자만...
// 가격 스타일 
function isValidPrice(e) { 
	var keynum;
	var keychar;

	if(window.event) { // IE
		keynum = e.keyCode;
	} else if(e.which) { // Netscape/Firefox/Opera
		keynum = e.which;
	}
	keychar = String.fromCharCode(keynum);

	var pattern = new RegExp('[^.0-9_]');
	//var pattern = /\d/; // 숫자만 입력안되게 할 때. 
	return !pattern.test(keychar);
	//event.returnValue=false; 
} 

// 빈값인지 리턴한다.
function isEmpty(pValue){
	if ((pValue=="") || (pValue==null)) {
		return true;
	}
	return false;
}

function isValidFormat(input, format) {
	if (input.value.search(format)!=-1) {
		return true; //올바른 포맷 형식
	}
	return false;
}
 
function isValidEmail(input) {
	var format = /^((\w|[\-\.])+)@((\w|[\-\.])+)\.([A-Za-z]+)$/;
	return isValidFormat(input, format);
}

function isValidPhone(input) {
	var format = /^(\d+)-(\d+)-(\d+)$/;
	return isValidFormat(input,format);
}

// 콤마 없애기 
function removeComma(input) {
	return input.value.replace(/,/gi,"");
}

function removeComma_2(value) {
	return value.replace(/,/gi,"");
}

// 숫자 3자리마다 콤마넣기 소스 
function commaSplit(obj) {
	objectValue = obj.value ; 
	objectValue = objectValue.replace(/,/gi,"");

	var txtNumber = '' + objectValue;
	var rxSplit = new RegExp('([0-9])([0-9][0-9][0-9][,.])');
	var arrNumber = txtNumber.split('.');
	arrNumber[0] += '.';
	
	do {
		arrNumber[0] = arrNumber[0].replace(rxSplit, '$1,$2');
	} while (rxSplit.test(arrNumber[0]));
	
	if (arrNumber.length>1) {
		val = arrNumber.join('');
	} else {
		val = arrNumber[0].split('.')[0];
	}

	obj.value = val ; 
}

function stripNumber(val) {
	val = val.replace(/[^0123456789.]/g, "");
	val = Number(val);
	return val;
}

function formatNumber(val) {
	val = (val).toLocaleString();
	return val;
}

function NumberFormat(fn){
	var str = fn;
	var Re = /[^0-9]/g;
	var ReN = /(-?[0-9]+)([0-9]{3})/;
	str = str.replace(Re,'');              
	while (ReN.test(str)) { 
		str = str.replace(ReN, "$1,$2"); 
	}
	return str;
}

function setCookie(name,value,expires) { 
	document.cookie=name + "=" + escape(value) + ((expires == null)? "" : (" ; expires=" + expires.toGMTString())); 
} 

function getCookie(name) { 
	var arg = name + "="; 
	var alen = arg.length; 
	var clen = document.cookie.length; 
	var i = 0; 
	while (i<clen) { 
		var j = i + alen; 
		if (document.cookie.substring(i,j)==arg) { 
			var end = document.cookie.indexOf(";",j);
			if(end == -1) end = document.cookie.length; 
			return unescape(document.cookie.substring(j,end)); 
		} 
		i = document.cookie.indexOf(" ",i)+1;
		if (i==0) break; 
	} 
	return null; 
} 

function getFontCookie() { 
	var cookie = getCookie("news_font_size"); 
	if (cookie==null) return 12; 
	if (cookie.length) return cookie; else return 12; 
} 

function scaleFont(val) { 
	var content, lineHeight; 
	content = document.getElementById("main_content");
	if (val>0){ 
		if (fontSize<=18)	{ 
			fontSize = fontSize + val; 
			lineHeight = fontSize+Math.round(1.1*fontSize); 
			content.style.fontSize = fontSize + "px"; 
		}
	} else { 
		if (fontSize>12) { 
			fontSize = fontSize + val;
			lineHeight = fontSize+Math.round(1.1*fontSize); 
			content.style.fontSize = fontSize + "px"; 
		}
	} 
	var mydate = new Date; 
	mydate.setDate(mydate.getDate()+1000); 
	setCookie("news_font_size", fontSize, mydate); 
} 
var fontSize = parseInt(getFontCookie()); 

// 확장자 체크. 
function check_extension(ext, img_types) { 

	var img_types = new Array(img_types);
	var i = 0;
	var check_value = 0; 
	for (i; i<img_types.length; i++) { 
		if (ext==img_types[i]) check_value = 1;  
	}
	return check_value; 
}

/*
function validPW(str) {

	var chk_pattern = /^[a-z0-9]{6,16}$/;
	
	if( !chk_pattern.test(str) ) {
		alert("비밀번호는 6~16자의 영문 소문자와 숫자만 사용할 수 있습니다.");
		return 0;
	}
	return 1;
}
*/ 



// ajax type 1 start 
function uriEncode(data){
	if(data!=""){
		//&와=로 일단 분해해서 encode
		var encdata = '';
		var datas = data.split('&');
		for(i=0;i<datas.length;i++)
		{
			var dataq = datas[i].split('=');
			encdata += '&'+encodeURIComponent(dataq[0])+'='+encodeURIComponent(dataq[1]);
		}
	} else {
		encdata = "";
	}
	return encdata;
}

var xh = false;
function get_ajax_01() { 
	try {
		xh = new XMLHttpRequest();
	} catch (trymicrosoft) {
		try {
			xh = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (othermicrosoft) {
			try {
				xh = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (failed) {
				xh = false;
			}  
		}
	}
	return xh; 
} 

function request_ajax_01(method, url, params, async, rpfunc, target) {
	xh = get_ajax_01(); 
	//alert(xh); 
	if (!xh) { 
		alert("Error initializing XMLHttpRequest!");
	} else { 
		params = uriEncode(params); 
		if (method.toUpperCase()=='GET') {
			url += "?" + "t=" + (new Date()).getTime() + "&" + params ;
		}
		//alert(url); 
		xh.open(method, url, async); 
		xh.onreadystatechange = function () { rpfunc(target); }
		xh.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); // 요청헤더의 정의 
		xh.send(null);
	} 
}

function response_ajax_01(target) {
	//alert(target); 
	if (xh.readyState == 4) {
		//alert(xh.status); 
		if (xh.status == 200) {
			//var _ctype = xh.getResponseHeader("Content-type");
			//alert(_ctype);
			//alert(_ctype.indexOf("text/xml"));
			var xmlDoc = xh.responseXML;
			//alert(xh.responseXML.xml); 
			root = xmlDoc.documentElement; 
			//alert(root.nodeName); 
			str = root.firstChild.nodeValue;
			document.all[target].innerHTML = str;
			if (target=='contentsBox') { setLoadConfirm(); } 
		} else { 
			alert("status is " + xh.status);
		}
	}
	return false;
}
// ajax type 1 end 


function print_flash(uwidth,uheight,usrc) {

	var flash_tag = "";

	flash_tag = '<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';

	flash_tag +='codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ';

	flash_tag +='WIDTH="'+uwidth+'" HEIGHT="'+uheight+'" >';

	flash_tag +='<param name="movie" value="'+usrc+'">';

	flash_tag +='<param name="quality" value="high">';

	flash_tag +='<param name="wmode" value="transparent">';

	//flash_tag +='<param name="wmode" value="transparent">';

	flash_tag +='<embed src="'+usrc+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" ';

	flash_tag +='type="application/x-shockwave-flash" WIDTH="'+uwidth+'" HEIGHT="'+uheight+'"></embed></object>'

	document.write(flash_tag);

}
/* shopping mall ?*/ 
function visible_layer(id, flag) {
	if(flag==true) {
		document.getElementById(id).style.visibility = "visible" ;
	} else { 
		document.getElementById(id).style.visibility = "hidden" ;
	}
}

function display_layer(id, flag) {
	if(flag==true) {
		document.getElementById(id).style.display = "";
	} else { 
		document.getElementById(id).style.display = "none";
	}
}

former_id = ''; 
function toggle(id, group_id) {
	if (former_id==id) {
		document.getElementById(id).style.display = ""; 
		//document.getElementById(id).style.display = "none"; 
		//id = ''; 
	} else {
		document.getElementById(id).style.display = ""; 
		if (former_id) {
			document.getElementById(former_id).style.display = "none"; 
		}
	}
	former_id = id; /* 전역 변수 선언은 var 없이 */ 
} 

function rollover_bg(id, isOver) {
	var lmObj = document.getElementById(id);
	var lmHandle = lmObj.className.replace(/_over/i, "");
	if (isOver=='1') {
		lmHandle += "_over";
	}
	lmObj.className = lmHandle;
}

function rollover_bg2(obj, isOver) {
	var lmObj = obj;
	var lmHandle = lmObj.className.replace(/_over/i, "");
	if (isOver=='1') {
		lmHandle += "_over";
	}
	lmObj.className = lmHandle;
}

var view_file_window = null; 
function view_file(file_path, width, height, left, top, scroll, resize) { 
	var URL = file_path;
	if ( view_file_window == null || view_file_window.closed) {
		view_file_window = window.open(URL, 'fileView', 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar=no,menubar=no,statusbar=no,scrollbars='+scroll+',resizable='+resize)
		view_file_window.focus();
	} else {
		view_file_window.location = URL;
		view_file_window.focus();
	}
}

var view_image_window = null; 
function view_image(file_path) { 
	if (file_path=='[object]') { 
		var file_path = file_path.src;
	} 
	var URL = 'view_image.php?file_path=' + file_path;
	if (view_image_window==null || view_image_window.closed) {
		view_image_window = window.open(URL, 'imageView', 'left=20,top=20,width=1,height=1,toolbar=no,menubar=no,statusbar=no,scrollbars=no,resizable=yes')
		view_image_window.focus();
	} else {
		view_image_window.location = URL;
		view_image_window.focus();
	}
}

/* 2007.11.25 added */
function get_img_info(obj) {
	var arr = obj.src.split('/');
	var fname = arr[(arr.length-3)] + "/" + arr[(arr.length-2)] + "/" + arr[(arr.length-1)]; 
	obj.alt = fname + ' (' + obj.width + '*' + obj.height + ')'; 
}

/* 2008.01.17 added */
function ResizeThem() {  
	var maxheight = 300;  
	var maxwidth = 300; 
	var imgs = document.getElementsByTagName("img");  
	for ( var p = 0; p < imgs.length; p++ )  
	{   
		if ( imgs[p].getAttribute("alt") == "user posted image" )
		{
			var w = parseInt( imgs[p].width );   
			var h = parseInt( imgs[p].height );  
			if ( w > maxwidth ) { 
				imgs[p].style.cursor = "pointer";      
				imgs[p].onclick = function( ) {          
					var iw = window.open ( this.src, 'ImageViewer','resizable=1' );          
					iw.focus();       
				};      
				h = ( maxwidth / w ) * h;      
				w = maxwidth;        
				imgs[p].height = h;       
				imgs[p].width = w;     
			}      
			
			if ( h > maxheight ) { 
				imgs[p].style.cursor="pointer";        
				imgs[p].onclick = function( ) {
					var iw = window.open ( this.src, 'ImageViewer','resizable=1' );      
					iw.focus( );        
				};       
				imgs[p].width = ( maxheight / h ) * w;        
				imgs[p].height = maxheight;    
			}   
		}  
	}
}
/* <body onLoad="ResizeThem()"> */

/* 2008.04.06 added */ 
function isURLFormat(url) {
	var re = new RegExp("^http://|^mms://", "i");
	return re.test(url);
}

function getPath(url) {
	var qmark = url.indexOf("?");
	if (qmark == -1) return url;
	else return url.substring(0, qmark);
}

function isCompatibleURL(url, type) {
	if (type == 'multi_video') {
		var re = new RegExp("\\.(avi|mov|mpg|mpeg|asf|wmv|wma)$", "i");
	} else if (type == 'multi_flash') {
		var re = new RegExp("\\.(swf)$", "i");
	} else if (type == 'multi_audio') {
		var re = new RegExp("\\.(mp3|wma|mmf)$", "i");
	} else if (type == 'image') {
		var re = new RegExp("\\.(gif|jpg|jpeg|png|bmp)$", "i");
	} 

	return re.test(getPath(url));
}

function checkLinkUrl(url, type) {
	
	if (false == isURLFormat(url)) {
		return false;
	}

	if (false == isCompatibleURL(url, type)) {
		return false;	
	}
	
	return true;
}


function textCounter(obj, max, bgcolor) { 
	var form = document.input_form; 

	//------------------------------------------// 
	var maxLimit = max ; 

  var str = obj.value ;
	var strLength = str.length  ;

	if ( strLength > maxLimit) {  
		obj.blur() ; 
		obj.style.backgroundColor = bgcolor;  
		obj.value = obj.value.substring(0, maxLimit); 
	} else { 
		//form.text_counter.value = maxLimit - strLength ; 
	}
} 

function set_favorite(title, url){
	if (document.all)
	window.external.AddFavorite(url, title);
	else if (window.sidebar)
	window.sidebar.addPanel(title, url, "")
}
// <span onclick="set_favorite('welcome to home.com', 'http://home.com/')" >favorite</span>
// <a href="javascript:set_favorite('welcome to home.com', 'http://home.com/')" >favorite</a>

function set_homepage(obj, url) { 
	obj.style.behavior='url(#default#homepage)'; 
	obj.setHomePage(url); 
} 
// <span onclick="set_homepage(this, 'http://home.com')" >시작페이지</span> => 에러남 
// <a href="javascript:set_homepage(this, 'http://home.com')" >시작페이지</a> => 에러남. 
// <a href="JavaScript:" onclick="this.style.behavior='url(#default#homepage)'; this.setHomepage('http://home.com')"> => 오케이 


function set_ip(ip) { 
	var mydate = new Date; 
	mydate.setDate(mydate.getDate()+1000); 
	setCookie("trace_ip", ip, mydate); 
} 

function get_ip() { 
	var cookie = getCookie("trace_ip"); 
	if (cookie==null) {
		return ""; 
	} 
	if (cookie.length) {
		return cookie; 
	} else {
		return ""; 
	} 
} 
