// global.js

function goURL(url){
	location.href=url; 	
}

function openWindow(url,target,stat){
	window.open(url,target,stat);
}

function resizeWin(x,y){
	window.resizeTo(x,y);
}

function retTrue(){
	return true;
}

function retFalse(){
	return false;
}

function onContextMenu(){
		document.oncontextmenu = retFalse;
}


function rTrim(word) {
	var wordLeng = word.length;
	var i;
	var pos, first, last;

	for(i = wordLeng-1; i >= 0; i--) {
		if(word.charAt(i) != " ") break;
	}
	pos = i;
	first = 0;
	last = pos + 1;
	word = word.substring(first,last);
	return word;
}

function lTrim(word) {
	var wordLeng = word.length;
	var i;
	var pos, first, last;

	for(i = 0; i < wordLeng; i++) {
		if(word.charAt(i) != " ") break;
	}
	pos = i;
	first = pos;
	last = wordLeng;
	word = word.substring(first,last);
	return word;
}

function trim(word) {
	word = lTrim(word);
	word = rTrim(word);
	return word;
}

function trimAll(word) {
	var wordLeng = word.length;
	var i;

	for(i=0; i<wordLeng; i++) {
		word = word.replace(' ','');
	}
	return word;
}

function getCookies(nameVal) {
	var numCookie = document.cookie.length;
	var oven = document.cookie.split("; ");
	for(var i=0; i<oven.length; i++) {
		if(oven[i].indexOf("=") != -1) {
			cookieName = oven[i].substring(0,oven[i].indexOf("="))
		} else {
			cookieName = oven[i];
		}
		if(cookieName == nameVal) {
			if(oven[i].indexOf("=") != -1) {
				cookieVal = oven[i].substr(oven[i].indexOf("=")+1);
			} else {
				cookieVal = "";
			}
			return cookieVal;
		}
	}
	return "";
}


//	共通サービス関数

function CheckNumber(fl) 
{
	t = fl.value ;
	for(i=0;i<t.length;i++) 
	if (t.charAt(i)<'0' || t.charAt(i)>'9') 
	{
		alert("숫자만 입력하세요.(数字だけ入力してください)") ;
		fl.value="";
		fl.focus() ;
		return false ;
	}
}

function chkstr(value, msg)
{
	var ret = true;
	if(value.split(" ").join("") == ""){
		alert (msg);
		ret = false;
	}
	return ret;
}

function chkstrFocus(obj, msg)
{
	var ret = true;
	if(obj.value.split(" ").join("") == ""){
		alert (msg);
		obj.focus();
		ret = false;
	}
	return ret;
}

function resizeImg(obj,w)
{
	var imgObj = obj;
	if (imgObj.width > w)
	{
		imgObj.width = w;
	}
}


function setIdPosition(id,x,y){
	document.getElementById(id).style.top = x;
	if(y!=null)	document.getElementById(id).style.left = y;
}





//共通関数 - パブアップチァングズングアングベチ

function popCenter() 
{
	if (document.layers) 
	{
		var sinist = screen.Width / 2 - outerWidth / 2;
		var Toppo = screen.Height / 2 - outerHeight / 2;
	} 
	else 
	{	var sinist = screen.Width / 2 - document.body.offsetWidth / 2;
		var Toppo = -25 + screen.Height / 2 - document.body.offsetHeight / 2;
	}
	self.moveTo(sinist, Toppo);
}


//パブアップチァングリサであって及び XPチェキング

function getCheckXPSP2() {
		var win_version	= window.navigator.appVersion;
		var win_version_split = win_version.split('; ');

		if(4 <= win_version_split.length)	{
			var os_version = win_version_split[2].split(' ');

			if(3 <= os_version.length && "Windows" == os_version[0])	{
				var os_version_num = new Number(os_version[2]);
				if(5.1 <= os_version_num  && 35 <= win_version.indexOf("SV1"))
						return true;
			}
		}
		return false;
}

function auto_fit_size() {
	window.resizeTo(100,100);
	var cw = document.body.scrollWidth;
	var ch = document.body.scrollHeight;
	var mw = (document.body.offsetWidth > cw) ? cw : document.body.offsetWidth;
	var mh = (document.body.offsetHeight > ch) ? ch : document.body.offsetHeight;

	if (getCheckXPSP2()) { 
		var ww = cw + 10;
	} else {
		var ww = cw + 10;
	}

	var wh = ch + (104 - mh);
	if(wh > 650)	wh = 650;

	if(wh < 650) {
		document.body.scroll = "no";
		window.resizeTo(ww,wh);
	} else {
		document.body.scroll = "yes";
		window.resizeTo(ww+17,wh);
	}
}

//サービス関数

function loginPopOpen()
{
	openWindow("http://www.damoim.net/pages/login/needloginPop.asp","","scrollbars=0,status=0,toolbar=0,resizable=0,location=0,menu=0,Width=345,Height=305")
}


function needLogin(f){
	var ncid = 	getCookies("key");
	if(ncid.length < 200){
		GoLogin(f);
		return false;
	}
	return true;
}

function GoLogin(f){

	f.location.href = "http://www.damoim.net/pages/login/needlogin.asp";

}


// object view
// 누구삼.. -_-;; 함수 이름 바꾸지 마삼~
// TFT 황해성
function activateObject(id){
	document.getElementById(id).innerHTML = document.getElementById(id).innerHTML;

}
function writeSrc(strs){
	document.write(strs);
}

function activateHTML(objid, html)
{
	var obj = document.getElementById(objid);
	if ( typeof(obj)=="object"){
		obj.insertAdjacentHTML("afterBegin",html);	
		obj.style.display="";		
	}	
	else{
		return;
	}
}

function runObj(string)
{
	if(string != undefined) {
		document.write(string);
	}
}

function runObj_tframe(string, tframe)
{
	if(tframe == null)
	{
		if(string != undefined) {
			document.write(string);
		}
	}
	else
	{
		if(string != undefined) {
			tframe.document.write(string);
		}
	}
}

function runObj_innerHTML(string, tobj)
{
	if(string != undefined) {
		tobj.innerHTML = string;
	}
}



/* ----- 2007-03-06_pch 추가 시작 ----- */
function getId(gId, gWhere)
{
	// document.getElementById

	if (gWhere == null || gWhere == "") return document.getElementById(gId);
	else return eval(gWhere+".document.getElementById('"+gId+"')");
}

function getName(gName, gWhere)
{
	// document.getElementsByName Array

	if (gWhere == null || gWhere == "") return document.getElementsByName(gName);
	else return eval(gWhere+".document.getElementsByName('"+gName+"')");
}

function getTagName(gTagName, gWhere)
{
	// document.getElementsByTagName Array

	if (gWhere == null || gWhere == "") return document.getElementsByTagName(gTagName);
	else return eval(gWhere+".document.getElementsByTagName('"+gTagName+"')");
}

function getRadioValue(arg)
{
	// radio checked값 반환, null이면 선택된 값이 없음
	// arg: radio Name명
	var x = getName(arg);
	var y = x.length;

	if (y == 1 && x[0].checked) return x[0].value;
	else if (y > 1)
	{
		for (i = 0; i < x.length; i++)
		{
			if (x[i].checked) return x[i].value;
		}
	}
	else return null;
}

function chkAlphaNum(arg1, arg2)
{
	// 알파벳, 숫자 선택적 체크 // false : 문자열 유효하지 않음
	// arg1 : 체크할 문자열, arg2 : 1(영문), 2(숫자), 3(영문숫자)
	if (arg2 == 1) x="a-z|A-Z";
	else if (arg2 == 2) x="0-9";
	else if (arg2 == 3) x="0-9|a-z|A-Z";
	
	if (eval("arg1.search(/[^"+x+"]/)") != -1) return false;
}
/* ----- 2007-03-06_pch 추가 끝 ----- */
function auto_resizeto(arg)
{
	// 팝업사이즈 자동 리사이즈 // arg : 1(화면가운데 정열), 0(마음대로 정열)
	// !DOCTYPE 선언된 팝업창엥서도 작동됨
	var saw		= screen.availWidth;
	var sah		= screen.availHeight;
	var sw		= document.body.scrollWidth;
	var sh		= document.body.scrollHeight;
	var maxw	= parseInt(saw*0.95);		//최대width
	var maxh	= parseInt(sah*0.95);		//최대height
	var setw		= sw;							//설정width
	var seth		= sh;							//설정height
	
	var IEver = trim(navigator.appVersion.split(';')[1])
	if (IEver=='MSIE 7.0') {setw = setw +10; seth = seth + 71}			//IE7.0 : +71
	else if (IEver=='MSIE 6.0') {setw = setw +10; seth = seth + 49}	//IE6.0 : +49

	// 스크롤바 추가시 16px 추가 // x, y 하나의 스크롤바만 생성됩니다
	if (setw > maxw) 
	{
		setw = maxw;
		seth = seth+16;
		document.body.scroll = "auto";
	}

	if (seth > maxh) 
	{
		setw = setw+16;
		seth = maxh;
		document.body.scroll = "auto";
	}

	window.resizeTo(setw, seth);

	// 화면가운데 정열
	if (arg==1)
	{
		var setpw	= (saw/2)-(setw/2);
		var setph	= (sah/2)-(seth/2);
		window.moveTo(setpw,setph);
	}	
}

function open_win(strURL,strName,strSpecs)
{
	// strURL:주소, strName:창이름, strSpecs:속성값 // 페이지 로드시 auto_resizeto() 호출할것
	if (typeof(strURL) == "undefined" || strURL == "") return;
	if (typeof(strSpecs) == "undefined" || strSpecs == "") strSpecs = 'width=120,height=90,scrollable=yes,resizable=no,menubar=no,scrollbars=auto,status=no';
	
	window.open(strURL,strName,strSpecs);
}
/* ----- 2007-06-04_pch 추가 끝 ----- */
function imgResize(srcID, stdw, stdh)
{
	// srcID: 소스ID // stdw: 기준 width // stdh: 기준 height
	
	var x = getId(srcID);
	x.removeAttribute('width');
	x.removeAttribute('height');
	xw = x.width;
	xh = x.height;

	if (xw>stdw || xh>stdh)
	{
		Ratew = xw/stdw;
		Rateh= xh/stdh;

		if (Ratew > Rateh)			// width 기준 비율로 사이즈 줄임
		{
			x.width = xw/Ratew;
			x.height = xh/Ratew;
		}
		else	// height 기준 비율로 사이즈 줄임(비율이 같은 경우 포함)
		{
			x.width = xw/Rateh;
			x.height = xh/Rateh;
		}
	}
}
/* ----- 2007-06-06_pch 추가 끝 ----- */

function registerUser(strEmail, strGUID){
	var f=window.open("http://boa.damoim.net/pages/login/homebuilder_login_global_register.asp?email="+strEmail+"&guid="+strGUID, "homebuilder_regWindows", "width=10, height=10, scrollbars=yes, resizable=yes" );
	f.focus();
}

function openIstyleWin(fpnum, fpid, menu, curl, refRet){

	//fpid = ''   기본 fpnum으로 찾아가기
	var fpnumValue;
	var query ;

	var fpid = (typeof(fpid)=="undefined")?"":escape(fpid);
	var menu = (typeof(menu)=="undefined")?"":menu;
	var curl = (typeof(curl)=="undefined")?"":escape(curl);
	if (isNaN(fpnum) && fpid !="")	fpnumValue = "pid";
	else	fpnumValue = fpnum	;
	
	var openUrl = "http://style.iple.com/pages/istyle.sm?fpnum="+fpnumValue+"&fpid="+fpid+"&menu="+menu+"&curl="+curl;

	var winName = "";
	var cook = getCookie();
	if(cook && cook["info2"] && cook["info2"][5] && parseInt(cook["info2"][5], 10) == fpnum)
		winName = "mystyle";
	else
		winName = "istyle";

	var ret = window.open(openUrl, winName, 'scrollbars=0,width=965,height=675,resizable=0');
	if(ret == null)	{
		alert("팝업창이 뜰수 있도록 설정해 주십시요");
	}
	else	{
		ret.focus();	//포커싱은 창이 형성된후애 해야_2007-06-27_cyh
//			document.location.href = "http://www.damoim.net";
	}
//	ret.focus();
	// refRet 가 있을 경우 윈도우 레퍼런스를 refRet에 저장.
	if(refRet)
	{
		refRet = ret;
	}
}

// Plain Text Cookie를 읽어온다.
function getCookie()
{
	var cook = unescape(document.cookie);
	var sa = cook.split("; ");	//";" -> "; " : 2007-06-30_cyh
	var cookieMap = new Array();
	for(var i=0; i<sa.length; i++)
	{
		var subsa = sa[i].split("=");
		var subMap = new Array();
		for(var j=0; j<subsa.length; j++)
		{
			if(j == 0)
			{
				cookieMap[subsa[j]] = subMap;
			}
			else
			{
				var subsubsa = subsa[j].split("\t");
				for(var k=0; k<subsubsa.length; k++)
				{
					subMap[k] = subsubsa[k];
				}
			}
		}
	}

	return cookieMap;
}


function auto_resizeto(arg)
{	
	// 팝업사이즈 자동 리사이즈 // arg : 1(화면가운데 정열), 0(마음대로 정열)
	// !DOCTYPE 선언된 팝업창엥서도 작동됨
	// window.resizeTo(250, 100);	// 사이즈 초기화 필요(번쩍 거려서 우선은 주석처리)
	var saw		= screen.availWidth;
	var sah		= screen.availHeight;
	var sw		= document.body.scrollWidth;
	var sh		= document.body.scrollHeight;
	var maxw	= parseInt(saw*0.9);		//최대width
	var maxh	= parseInt(sah*0.9);		//최대height
	var setw		= sw;								//설정width
	var seth		= sh;								//설정height
	
	var IEver = trim(navigator.appVersion.split(';')[1])
	if (IEver=='MSIE 7.0') 
	{
		setw = setw +10;
		seth = seth + 81;
		//alert(IEver);
	}			//IE7.0 : +71? 81?
	else if (IEver=='MSIE 6.0') 
	{
		setw = setw +10;
		seth = seth + 59;
		//alert(IEver);
	}		//IE6.0 : +49? + 52?

	// 스크롤바 추가시 17px 추가 // x, y 하나의 스크롤바만 생성됩니다
	if (setw > maxw) 
	{
		setw = maxw;
		seth = seth+17;
		document.body.scroll = "auto";
	}

	if (seth > maxh) 
	{
		setw = setw+17;
		seth = maxh;
		document.body.scroll = "auto";
	}

	// 화면가운데 정열
	if (arg==1)
	{
		var setpw	= (saw/2)-(setw/2);
		var setph	= (sah/2)-(seth/2);
		window.moveTo(setpw,setph);
	}

	window.resizeTo(setw, seth);
}

