// window.open
function openPop(src,target,width,height,scroll)
{
	var wid = (screen.availWidth - width) / 2;
	var hei = (screen.availHeight - height) / 2;
	var opt = 'width='+width+',height='+height+',top='+hei+',left='+wid+',resizable=no,scrollbars='+scroll;
	window.open(src,target,opt);
}

function open_geohome(userid)
{
	if(userid)
	{
		var width=940;
		var height=540;
		wid = ( screen.availWidth - width ) / 2;
		hei = ( screen.availHeight - height ) / 2;
		size = 'width=' + width + ',height=' + height + ',top=' + hei + ',left=' + wid;
		etc = size + ',resizable=no,scrollbars=no,status=no';
		reval = window.open('http://hompy.geopia.com/?masterid='+userid,'geoblog',etc);
		reval.focus();
	}
}

function open_payment(type)
{
	var msg;
	if (type == 'hompy')
	{
		msg = 'Á¤È¸¿ø ¶Ç´Â ¿©¼ºÈ¸¿ø¸¸ È¨ÇÇ¸¦ ¿­¶÷ÇÏ½Ç ¼ö ÀÖ½À´Ï´Ù.';
	}
	alert(msg);
	location.href='http://help.geopia.com/?view=payment';
}


// copyright popup
function copyrightPop(type)
{
	if(type == 'company')
	{
		openPop('http://www.geopia.com/company/home.ggi','company',750,600,'no');
	}
	else if(type == 'agree')
	{
		openPop('http://www.geopia.com/guide/agree.php','agree',600,770,'no');
	}
	else if(type =='privacy')
	{
		openPop('http://www.geopia.com/privacy/privacy.html','privacy',597,650,'yes');
	}
	else if(type =='junior')
	{
		openPop('http://www.geopia.com/privacy/junior.ggi','junior',597,650,'yes');
	}
	else if(type == 'noemail')
	{
		openPop('http://www.geopia.com/noemail.ggi','noemail',380,220,'no');
	}
	else if(type == 'ad')
	{
		openPop('http://www.geopia.com/popup/ad_mail.ggi','ad',400,535,'no');
	}
	else if(type == 'recruit')
	{
		openPop('http://www.geopia.com/company/company4_3.ggi?visitfrom=geo','recruit',771,604,'yes');
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function hompy(userid)
{
	window.open('http://hompy.geopia.com/?masterid='+userid,'','width=940,height=540');
}

function open_join()
{
	window.open('https://addusrs.geopia.com:448/?vfrom=g','','width=772,height=580');
}

function open_idpass()
{
	window.open('http://login.geopia.com/geopia/login_pass_01.ggi','','width=400,height=260')
}

function findIdPwd()
{
	//windowOpen('http://login.geopia.com/geopia/login_pass_01.ggi','findIdPwd',400,260,'yes');
	windowOpen('http://www.geopia.com/?view=findPasswd1','findIdPwd',420,495,'yes');
}

function saveid_func(userid, ip){
	var chk = document.login_form.saveid.checked;

	if(chk == true && userid && ip){
		document.hidden_save.action.value = 'saveId';
		document.hidden_save.mode.value = 'save';
		document.hidden_save.save_id.value = userid;
		document.hidden_save.save_ip.value = ip;
	}else{
		document.hidden_save.action.value = 'saveId';
		document.hidden_save.mode.value = 'del';
	}
	document.hidden_save.target = 'hidden_frame';
	document.hidden_save.submit();
}

String.prototype.ltrim = function()
{
	var re = /\s*((\S+\s*)*)/;
	return this.replace(re, "$1");
}

String.prototype.rtrim = function()
{
	var re = /((\s*\S+)*)\s*/;
	return this.replace(re, "$1");
}

String.prototype.trim = function()
{
	return this.ltrim().rtrim();
}



// Ä«Å×°í¸® ÀÚµ¿¿Ï¼º °ü·Ã

var mobileYN = 'N';

function categoryInput()
{
	var fn = document.forms.writeform;
	var patterns = /[^(°¡-ÆRa-zA-Z0-9)]/;
	if (!fn.ctKeyword.value)
	{
		alert('Ä«Å×°í¸®¸¦ ÀÔ·ÂÇÏ¼¼¿ä.');
		fn.ctKeyword.focus();
		return false;
	}
	else if (patterns.test(fn.ctKeyword.value))
	{
		alert('Ä«Å×°í¸®´Â ÇÑ±Û,¼ýÀÚ,¿µ¹® Á¶ÇÕ¸¸ °¡´ÉÇÕ´Ï´Ù.');
		return false;
	}
	else
	{
		//fn.categoryName.value = fn.ctKeyword.value;
		fn.categoryId.value = '0';
		//fn.ctKeyword.value = '';
		changeKeyword('','resultDiv');
	}
}

function categoryClick(id,name)
{
	var fn = document.forms.writeform;
	fn.categoryId.value = id;
	fn.ctKeyword.value = name;
	//fn.ctKeyword.value = '';
	changeKeyword('','resultDiv');
}

var orgKeyword = '';
function changeKeyword(value,divId)
{
	if (mobileYN == 'N')
	{
		AjaxAction('?view=action&action=ajax&actionType=categoryList&keyword='+value,divId);
		orgKeyword = value.trim();
	}
}

var beforeKeyword = null;
var selectedOptNum = -1;
var already = 'N';

function changeKeywordNew(value,divId,e)
{
	var fn = document.forms.writeform;
	if (mobileYN == 'N')
	{
		clickChk = true;
		keyword = document.getElementById('ctKeyword').value;
		if(e.keyCode == 13)
		{
			if (fn.ctKeyword.value)
			{
				//fn.categoryName.value = fn.ctKeyword.value;
				//fn.ctKeyword.value = '';
				document.getElementById(divId).innerHTML = '';
				if (selectedOptNum == -1)
				{
					fn.categoryId.value = 0;
				}

				selectedOptNum = -1;
			}
		}
		else if (e.keyCode == 8)
		{
			AjaxAction('?view=action&action=ajax&actionType=categoryList&keyword='+value,divId);
			selectedOptNum = -1;
			fn.categoryId.value = '0';
		}
		else
		{
			if(!keyword)
			{
				beforeKeyword = '';
				document.getElementById(divId).innerHTML = '';
			}
			else
			{
				AjaxAction('?view=action&action=ajax&actionType=categoryList&keyword='+value,divId);
				beforeKeyword = keyword;
				fn.categoryId.value = '0';
			}
		}
	}
	else
	{
		fn.categoryId.value = '0';
	}
}

// Å°ÄÚµå Á¦¾î
function keyClick(e,val)
{
	var keyCode;

	if (window.event)
	{
		keyCode = window.event.keyCode;
	}
	else if (e)
	{
		keyCode = e.which;
	}
	else
	{
		return true;
	}

	// ½¬ÇÁÆ® ¿£ÅÍ½Ã ´ÙÀ½ÁÙ
	if (e.shiftKey == true && keyCode == 13)
	{
	}
	else if (keyCode == 13 && document.forms.commentForm.enterCheck.checked == true)
	{
		$('#commentButton').click();
		//document.forms.writeform.content.blur();
	}
	else
	{
	}
	return false;
}


function shareSNS(type,url,msg)
{
	var width = 0;
	var height = 0;
	var scroll = 'no';

	if (type == 'twitter')
	{
		width = 690;
		height = 500;
		linkUrl = 'http://twitter.com/share?url='+url+'&text='+msg;
	}
	else if (type == 'facebook')
	{
		width = 690;
		height = 700;
		linkUrl = 'http://www.facebook.com/sharer.php?u='+url+'&t='+msg;
		scroll = 'yes';
	}
	else if(type == 'me2day')
	{
		width = 690;
		height = 700;
		linkUrl = 'http://me2day.net/posts/new?new_post[body]=&quot;'+msg+'&quot;:'+url;
		scroll = 'yes';
	}
	else if(type == 'cyworld')
	{
		width = 405;
		height = 405;
		linkUrl = 'http://csp.cyworld.com/bi/bi_recommend_pop.php?url='+url;
	}

	windowOpen(linkUrl,'twitter',width,height,scroll);
}

// window.open
function windowOpen(src,target,width,height,scroll)
{
	var wid = (screen.availWidth - width) / 2;
	var hei = (screen.availHeight - height) / 2;
	var opt = 'width='+width+',height='+height+',top='+hei+',left='+wid+',resizable=no,status=no,scrollbars='+scroll;
	window.open(src,target,opt);
}

