var disBg='#DBDBDB';

var NUM = "0123456789";
var DNUM = NUM+".";
var SALPHA = "abcdefghijklmnopqrstuvwxyz";
var ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"+SALPHA;
var EMAIL = "!#$%&*+-./=?@^_`{|}"+NUM+ALPHA;
var PASSWORD = "!@.#,$%^*&_-"+ALPHA+NUM;

var oldNum=new Array();
oldNum['qna']='';
oldNum['rev']='';

function CheckType(s,spc) {
	var i;
	for(i=0; i<s.length; i++) {
		if (spc.indexOf( s.substring(i, i+1)) < 0) {
			return false;
		}
	}

	return true;
}

function CheckSpaceAll(str){
	var index;
	var len;

	while(true){
		index=str.value.indexOf(" ");
		if(index==-1) break;
		len=str.value.length;
		str.value=str.value.substring(0,index) + str.value.substring((index+1), len);
	}
return str.value;
}

function CheckSpace(str){
	var len;

	while(true){
		if (str.value.charAt(0) != " ") break;
		len=str.value.length;
		str.value=str.value.substring(1,len);
	}

	while(true){
		len=str.value.length;
		if (str.value.charAt(len-1) != " ") break;
		str.value=str.value.substring(0,len-1);
	}

return str.value;
}

function nextTab(obj,nxt,len){
	if (obj.value.length>=len) nxt.focus();
}

function setConfig(name,value){
	setCookie( name, value, 365 );
	alert('설정이 저장되었습니다');
}

function setCookie( name, value, expiredays ){
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function getCookie( name ){
	var nameOfCookie = name + "=";
	var x = 0;
	while ( x <= document.cookie.length ) {
		var y = (x+nameOfCookie.length);
		if ( document.cookie.substring( x, y ) == nameOfCookie ) {
		if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 )
			endOfCookie = document.cookie.length;
			return unescape( document.cookie.substring( y, endOfCookie ) );
		}
		x = document.cookie.indexOf( " ", x ) + 1;
		if ( x == 0 )
			break;
	}
	return "";
}

function layTgl(obj) {
	if(!obj) return;
	if (obj.style.display=='none') obj.style.display = 'block';
	else obj.style.display = 'none';
}

function layTgl2(obj_name) {
	obj=document.getElementById(obj_name);
	layTgl(obj);
}

function textDisable(o,d){
	if (d)
	{
		o.style.backgroundColor='#EFEFEF';
		o.disabled=true;
	}
	else
	{
		o.style.backgroundColor='';
		o.disabled=false;
	}
}

function checkBlank(o,m){
	if (typeof o=='undefined')
	{
		return true;
	}
	if (!o.value)
	{
		alert(m+' 입력하세요');
		o.focus();
		return false;
	}
	return true;
}

function checkSel(o,m){
	if (o.selectedIndex==0)
	{
		alert(m+' 선택하세요');
		o.focus();
		return false;
	}
	return true;
}

function checkCB(obj,msg){
	icbk=0;
	if (obj.length)
	{
		//fobj=obj[0];
		for (dh=0; dh<obj.length; dh++)
		{
			if (obj[dh].checked==true)
			{
				icbk++;
				break;
			}
		}
	}
	else if (obj && obj.checked==true)
	{
		//fobj=obj;
		icbk++;
	}

	if (icbk<1)
	{
		alert(msg+' 선택하세요');
		//if (fobj) fobj.focus();
		return false;
	}
	return true;
}

function checkAll(obj,ck){
	if (obj.length)
	{
		for (i=0; i<obj.length; i++)
		{
			obj[i].checked=ck;
		}
	}
	else if (obj)
	{
		obj.checked=ck;
	}
}

function checkOne(obj,i,ck){
	if (obj.length)
	{
		obj[i].checked=ck;
	}
	else if (obj)
	{
		obj.checked=ck;
	}
}

function checkNum(o,m){
	if (!CheckType(o.value, NUM)) {
		alert(m+' 숫자만 입력하셔야 합니다');
		o.focus();
		return false;
	}
	return true;
}


function wisaOpen(url,name,scroll,w,h){
	//window.open(url,name,'top=10,left=10,height=100,width=100,status=no,scrollbars=no,toolbar=no,menubar=no');
	if (!scroll) scroll='no';
	if (!w) w='100';
	if (!h) h='100';
	window.open(url,name,'top=10,left=10,height='+h+',width='+w+',status=yes,resizable=yes,scrollbars='+scroll+',toolbar=no,menubar=no');
}


function selfResize(){
	self.resizeTo(document.body.scrollWidth , document.body.scrollHeight);
}

function selfResize2(a,b){
	if (!a) a=0;
	if (!b) b=0;
	self.resizeTo(document.body.scrollWidth+b , document.body.scrollHeight+a);
}

function Resize(w, h) {
	sh=screen.Height-150;
	if (h>sh)
	{
		h=sh;
	}

	if(Math.abs(document.body.offsetWidth - document.body.clientWidth) > 5) {
		window.resizeTo(w + 26, h + 55);
	}
	else {
		window.resizeTo(w + 10, h + 59);
	}


}

function zipSearch(form_nm,zip_nm,addr1_nm,addr2_nm){
	srurl=root_url+'/common/zip_search.php?form_nm='+form_nm+'&zip_nm='+zip_nm+'&addr1_nm='+addr1_nm+'&addr2_nm='+addr2_nm;
	window.open(srurl,'zip', ('scrollbars=yes,resizable=no,width=374, height=170'));
}

function CheckMail(email){
	aindex=email.indexOf("@");
	dotindex=email.indexOf(".");
//	if (aindex==-1 || dotindex==-1 || aindex >= (dotindex-1)) return false;
	if (aindex==-1 || dotindex==-1) return false;
	return true;
}

function isEmpty(data){
	for (ii=0; ii<data.length; ii++) {
		if(data.substring(ii, ii+1) != " ") return false;
	}
	return true;
}

function checkPhone(o,m){
	r=9;
	for (i=0; i<3; i++)
	{
		if (isEmpty(o[i].value) || !CheckType(o[i].value, NUM))
		{
			r=i;
			break;
			//alert(m+' 공백없이 숫자로 입력하세요');
			//o[i].select();
			//return false;
		}
	}
	return r;

}

function chgEmail(txt,sel,current){
	if (typeof sel=='undefined')
	{
		return;
	}
	if (current)
	{
		for (i=0; i<sel.length; i++)
		{
			if (sel[i].value==current)
			{
				sel.selectedIndex=i;
				break;
			}
		}

		if (sel.selectedIndex==0) sel.selectedIndex=sel.length-1;
	}
	else txt.value=sel.value;


	if (sel.selectedIndex<sel.length-1)
	{
		txt.readOnly=true;
		txt.style.backgroundColor=disBg;
	}
	else
	{
		txt.readOnly=false;
		txt.style.backgroundColor='';
	}
}

function zipInput(o){
	if (o.value=='한글 입력 상태')
	{
		o.value='';
	}
}

function checkLoginFrm(f){
	if (f.member_type)
	{
		if (!checkCB(f.member_type,"개인/기업회원을")) return false;
	}
	if (!checkBlank(f.member_id,"아이디를")) return false;
	if (!checkBlank(f.pwd,"비밀번호를")) return false;

	if (f.setHttps) { // 2008-05-19 보안서버 적용 by zardsama
		f.action = (f.setHttps.checked == true) ? f.action.replace ("http:","https:") : f.action.replace ("https:","http:");
	}
}

function checkGuestOrderFrm(f){
	if (!checkBlank(f.ono,"주문번호를")) return false;
	if (!checkBlank(f.phone,"전화번호를")) return false;
}

function memberOnly(u,c,t){
	if (mlv==10)
	{
		if (c==1 && !confirm('\n 로그인이 필요한 서비스입니다          \n\n 로그인하시겠습니까? \n'))
		{
			if(t==1) return false;
			else return;
			u='';
		}
		u=root_url+'/member/login.php?rURL='+escape(u);
	}
	if (u && t!=3) location.href=u;
	else if (t==1 || t==3) return true;
}

function checkSearchFrm(f){
	if (!checkBlank(f.search_str,"검색어를")) return false;
}

function layTglList(old,lay_name,lay_no){
	if (oldNum[old]!=lay_no)
	{
		if (oldNum[old])
		{
			if(document.getElementById(lay_name+oldNum[old])) document.getElementById(lay_name+oldNum[old]).style.display="none";
		}
		if(document.getElementById(lay_name+lay_no)) document.getElementById(lay_name+lay_no).style.display="block";
		oldNum[old]=lay_no;
	}
	else
	{
		if(document.getElementById(lay_name+lay_no)) document.getElementById(lay_name+lay_no).style.display="none";
		oldNum[old]="";
	}
}

function setComma(str,xx)
{
	var retValue = "";

	if (str && !CheckType(str, NUM+',') && !xx)
	{
		alert('숫자만 입력하셔야 합니다 - '.str);
		return 0;
	}
	/*
	if (str) str=removeComma(str);
	else return 0;
	*/
	str = ""+str+"";

	for(i=0; i<str.length; i++)
	{
		if(i > 0 && (i%3)==0) {
			retValue = str.charAt(str.length - i -1) + "," + retValue;
		} else {
			retValue = str.charAt(str.length - i -1) + retValue;
		}
	}
	return retValue
}

function removeComma(str)
{
	if (str!="")
	{
		str=str.replace(/,/g, "");
		str=str.replace(/\./g, "");
		str=eval(str);
	}
	return str
}

function kcpCardReceipt(tno){
	url='http://admin.kcp.co.kr/Modules/Sale/Card/ADSA_CARD_BILL_Receipt.jsp?c_trade_no='+tno
	window.open(url,name,'top=10,left=10,height=700,width=440,status=no,scrollbars=yes,toolbar=no,menubar=no');
}

function inicisCardReceipt(tid) {	// 이니시스 영수증 출력
	var receiptUrl = "https://iniweb.inicis.com/DefaultWebApp/mall/cr/cm/mCmReceipt_head.jsp?noTid=" + tid + "&noMethod=1";
	window.open(receiptUrl,"receipt","width=430,height=700");
}

function closePopup(popup){
	setCookie(popup,'Y',1);
	window.close();
}

function closePopup2(popup,n){
	setCookie(popup,'Y',1);
	layTgl2('wm_popup_'+n);
}

function closePopup7(popup,n){
	setCookie(popup,'Y',7);
	layTgl2('wm_popup_'+n);
}

function closePopup3(url){
	if (url)
	{
		parent.document.location.href=url;
	}
	window.close();
}


function setCookie( name, value, expiredays ) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}

function newSMSpwd(){
	url=root_url+'/member/sms_find.php';
	location.href = url;
	//window.open(url,name,'top=10,left=10,height=200,width=450,status=no,scrollbars=no,toolbar=no,menubar=no');
}

function click_prd_scroll(t){
	if (click_prd.length<1)
	{
		return;
	}
	if (t=="+")
	{
		tmp=click_prd_finish+1;
		if (tmp>click_prd.length)
		{
			alert('최근 본 상품의 마지막 상품입니다');
			return;
		}
		click_prd_start++;
		click_prd_finish++;
	}
	else
	{
		tmp=click_prd_finish-1;
		//if (tmp<0)
		if (tmp==click_prd_limit)
		{
			alert('최근 본 상품의 첫번째 상품입니다');
			return;
		}
		click_prd_start--;
		click_prd_finish--;
	}

	for (i=click_prd_start; i<click_prd_finish; i++)
	{
		tmp=i-click_prd_start;
		document.getElementById('click_prd_title'+tmp).innerHTML=click_prd[i];
	}
}

function viewMember2(n,id){
	if (id==undefined) id='';
	nurl=root_url+'/_manage/?body=member@member_view.frm&ref_front=true&mno='+n+'&mid='+id;
	window.open(nurl,'view_member','top=10,left=10,width=950,status=no,toolbars=no,scrollbars=yes');
}

function flashMovie(fid,src,wid,hei,fvs,wmd) {
  this.fPrint = '';
  this.Id = document.getElementById(fid);
  this.Src = src;
  this.Width = wid;
  this.Height = hei;
  this.FlashVars = (fvs != undefined)? fvs :'';
  this.Wmod = (wmd != undefined)? wmd :'';
  if(isObject(Id)) {

	fPrint = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="'+Width+'" height="'+Height+'" id="wisa_'+fid+'">';
    fPrint += '<param name="movie" value="'+Src+'">';
	fPrint += '<param name="allowScriptAccess" value="always" />';
	fPrint += '<param name="allowFullScreen" value="false" />';
    fPrint += '<param name="quality" value="high">';
    fPrint += (FlashVars != null) ? '<param name="FlashVars" value="'+FlashVars+'">' : '';
    fPrint += (Wmod != null) ? '<param name="wmode" value="'+Wmod+'">' : '';
    fPrint += '<embed';
    fPrint += ' src="'+Src+'"';
    fPrint += (FlashVars != null) ? ' FlashVars="'+FlashVars+'"' : '';
    fPrint += (Wmod != null) ? ' wmode="'+Wmod+'"' : '';
    fPrint += ' quality="high"';
	fPrint += ' allowScriptAccess="always"';
	fPrint += ' allowFullScreen="false"';
    fPrint += ' pluginspage="http://www.macromedia.com/go/getflashplayer"';
    fPrint += ' type="application/x-shockwave-flash" ';
    fPrint += ' width="'+Width+'"';
    fPrint += ' height="'+Height+'"';
    fPrint += '></embed>';
    fPrint += '</object>';
    Id.innerHTML = fPrint;
  }
}

function isObject(a) {
    return (a && typeof a == 'object');
}

function flashMovie2(fid,src,wid,hei,fvs,wmd) {
  this.fPrint = '';
  this.Id = document.getElementById(fid);
  this.Src = src;
  this.Width = wid;
  this.Height = hei;
  this.FlashVars = (fvs != undefined)? fvs :'';
  this.Wmod = (wmd != undefined)? wmd :'';
  if(isObject(Id)) {
    fPrint = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"';
    fPrint += ' width="'+Width+'"';
    fPrint += ' height="'+Height+'">';
    fPrint += '<param name="movie" value="'+Src+'">';
    fPrint += '<param name="quality" value="high">';
    fPrint += (FlashVars != null) ? '<param name="FlashVars" value="'+FlashVars+'">' : '';
    fPrint += (Wmod != null) ? '<param name="wmode" value="'+Wmod+'">' : '';
    fPrint += '<embed';
    fPrint += fPrint + ' src="'+Src+'"';
    fPrint += (FlashVars != null) ? ' FlashVars="'+FlashVars+'"' : '';
    fPrint += (Wmod != null) ? ' wmode="'+Wmod+'"' : '';
    fPrint += ' quality="high"';
    fPrint += ' pluginspage="http://www.macromedia.com/go/getflashplayer"';
    fPrint += ' type="application/x-shockwave-flash"';
    fPrint += ' width="'+Width+'"';
    fPrint += ' height="'+Height+'"';
    fPrint += '></embed>';
    fPrint += '</object>';
    Id.innerHTML = fPrint;
  }
}

function viewWMMsg(n) {
	if (n) url=root_url+'/mypage/msg_view.php?no='+n;
	else url=root_url+'/mypage/msg_list.php?mode=1';
	wisaOpen(url,'wmMgsWin');
}

function sendMsg(n){
	if (mlv==10)
	{
		alert('로그인하십시오');
		return;
	}
	nurl=root_url+'/mypage/msg_send.php?mode=1&mno='+n;
	window.open(nurl,'sendMSGW','top=10,left=10,width=450,height=100,status=no,toolbars=no,scrollbars=yes');
}

function trim(str){
	str = str.replace(/^\s*/,'').replace(/\s*$/, '');
	return str;
}

function qmc_check(o){
	if (o.checked==true)
	{
		r='Y';
	}
	else r='N';

	setCookie('quick_menu_move_check',r,365);
}

function seImgSize(o,width){
	if (o.width>width)
	{
		o.style.width=width;
	}
}
function AdminMailSend(url,w,h){ // 2006-12-10 : 관리자에게메일 - Han
	if(!w) w=500; if(!h) h=500;
	Op=window.open(url, "AdminM", "width="+w+", height="+h+", status=no, scrollbars=yes");
	Op.focus();
}

function adminMSck(f){
	if(!checkBlank(f.from_name,"이름을")) return false;
	if(!checkBlank(f.from_email,"이메일을")) return false;
	if(!checkBlank(f.sub,"제목을")) return false;
	if(!checkBlank(f.content,"내용을")) return false;
}

function getHttpRequest(URL,method) { // Ajax 사용함수
	
	nochache = new Date();

	if ( URL.indexOf("?") < 0) URL += "?";

	URL = URL+"&ncache="+nochache;
	if ( method == null ) method = "GET";

	var xmlhttp = null;
	if(window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
	else 	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	xmlhttp.open(method, URL, false);
		
	xmlhttp.onreadystatechange = function() { 
		if(xmlhttp.readyState==4 && xmlhttp.status == 200 && xmlhttp.statusText=='OK') {
			responseText = xmlhttp.responseText; 
		} 
	}
	xmlhttp.send('');
		
	return responseText = xmlhttp.responseText;
}

function createBackDiv(target, bgC){
	w=830;
	h=500;
	bw=target.document.body.clientWidth;
	bh=target.document.body.scrollHeight;
	bh2=target.document.body.clientHeight;
	posX=(bw-w)/2;
	posY=(bh-h)/2;
	
	if(!target.document.getElementById('dmMainBgDiv')){
		obj=target.document.createElement('div');
		with(obj.style){
			position='absolute';
			left=0;
			top=0;
			width='100%';
			height=(bh < bh2) ? bh2 : bh;
			backgroundColor='#000000';
			filter='Alpha(Opacity=50)';
			opacity='0.5';
			zIndex='50';
		}
		obj.id='dmMainBgDiv';
		target.document.body.appendChild(obj);
		obj.innerHTML='<iframe style="width:100%; height:100%; filter=\'Alpha(Opacity=0);\'"></iframe>';

		obj=target.document.createElement('div');
		with(obj.style){
			position='absolute';
			left=posX;
			top=10;
			width=w;
			height=bh2-20;
			if(bgC) backgroundColor=bgC;
			zIndex='100';
		}
		obj.id='dmMainDiv';
		target.document.body.appendChild(obj);
	}
}

function finishedHosting(url, type){
	createBackDiv(this, '');
	bh=document.body.clientHeight;
	posY=(bh-417)/2;
	div=document.getElementById('dmMainDiv');
	if(type == 1){ // 사용자
		content='<img src="'+url+'/_manage/image/service/hosting_end2.gif" width="550" height="417">';
	}else{
		content='<img src="'+url+'/_manage/image/service/hosting_end1.gif" width="550" height="417" usemap="#goExtend">\n';
		content+='<map name="goExtend"><area shape="rect" href="./?body=service@service_main&stype=1" coords="212,180,339,220"></map>';
	}
	div.innerHTML='<div id="finishHDiv" align="center" style="padding-top:'+posY+'px;">'+content+'</div>';
}
