//////////////////////////////////index////////////////////////////////////////////////
function EditStore(store_id)
{

	document.location = "/store/edit.php?store_id="+store_id;
}

function ShowDetail()
{
	var obj = document.getElementById("div_detail");
	var button = document.getElementById("button_detail");
	if (obj.style.display == "none")
	{
		obj.style.display = "";
		button.src = "http://img.nowprofile.com/v1/btn/btn_close_sh_pro.gif";
	}
	else
	{
		obj.style.display = "none";
		button.src = "http://img.nowprofile.com/v1/btn/btn_spread_sh_pro.gif";
	}
}
var main_image_big_src = "";
var main_image_user_id = "";
var main_image_user_name = "";
var main_image_date = "";
var main_image_origin = "";
function DisplayThumbnailToMain(image_url_thumb, image_url_big, user_id, user_name, image_date, image_origin)
{   
	if(image_url_thumb == "" || image_url_big == "") return;
	var el_image_main = document.getElementById("store_image_main");
	el_image_main.src = image_url_thumb;
	el_image_main.style.alt = "닫기";
	main_image_big_src = image_url_big;
	main_image_user_id = user_id;
	main_image_user_name = user_name;
	main_image_date = image_date;
	main_image_origin = image_origin;
}
function ShowMainImage()
{
	var div_main_image = document.getElementById("iframe_main_image");
	
	if(main_image_big_src == "")
	return;
	div_main_image.src = "/store/index.image.php?img_main_image="+main_image_big_src+"&a_main_image_user="+"/user/index.php?user_id=" + main_image_user_id+"&a_main_image_user_name="+encodeURIComponent(main_image_user_name)+"&span_main_image_date="+main_image_date+"&main_image_origin="+encodeURIComponent(main_image_origin);
	

}
function ShowMainMap(store_id)
{
	var div_main_map = document.getElementById("iframe_main_map");
	if(store_id == "")
	return;
	div_main_map.src = "/store/index.map.php?store_id=" + store_id;
	div_main_map.style.display = "block";
}

function PageStoreImage(store_id, page,user_id,user_name)
{
	CallAjax("/store/store.image.ajax.php?store_id=" + store_id + "&page=" + page + "&user_id=" + user_id + "&user_name=" + encodeURIComponent(user_name), "DisplayStoreImage(responseText)");
}

function DisplayStoreImage(text)
{
	var target = document.getElementById("div_store_images");
	target.innerHTML = text;
	try{
		var div_main_image_script = document.getElementById("div_main_image_script");
		eval(div_main_image_script.innerHTML);
	}catch(e) {}
}

function SetMainImageSize(width, height) {
	var div_main_image = document.getElementById("iframe_main_image");
	div_main_image.style.width = width +24;
	div_main_image.style.height = height + 105;
	div_main_image.style.display = "block";

	var xMax = document.body.clientWidth;
	var yMax = document.body.clientHeight;
	var sTop = document.body.scrollTop;
	var sLeft = document.body.scrollLeft;

	var xOffset = (xMax-width-24)/2+sLeft;
	var yOffset = (yMax-height-105)/2+sTop;

	if(xOffset < 0) xOffset = 0;
	if(yOffset < 0) yOffset = 0;

	div_main_image.style.top = yOffset;
	div_main_image.style.left = xOffset;
}

function ShowCommentDiv(div_id)
{
	var div_el = document.getElementById(div_id);
	if(div_el.style.display == "none") {
		document.getElementById("img_line_comment_write").src = "http://img.runpipe.com/v1/btn/btn_close_word.gif";
		div_el.style.display = "block";
	} else {
		document.getElementById("img_line_comment_write").src = "http://img.runpipe.com/v1/btn/btn_write_word.gif";
		div_el.style.display = "none";
	}
}
function ScoreSymbol(index)
{
	ScoreSymbolOver(index);
	var score = document.getElementById("comment_score");
	score.innerHTML = (index + 1) * 2;
}
function ScoreSymbolOver(index)
{
	var i = 0;

	for(; i <= index; i++)
	{
		var img = document.getElementById("score_image" + i);
		if (img.src != "http://img.runpipe.com/v1/icon/ico_point_star6.gif")
		img.src = "http://img.runpipe.com/v1/icon/ico_point_star6.gif";
	}

	for(; i < 5; i++)
	{
		var img = document.getElementById("score_image" + i);
		if (img.src != "http://img.runpipe.com/v1/icon/ico_point_star5.gif")
		img.src = "http://img.runpipe.com/v1/icon/ico_point_star5.gif";
	}
	if(index == -1) {
		document.getElementById("score_text").src = "http://img.runpipe.com/v1/text/text_sh_rating0.gif";
	} else {
		document.getElementById("score_text").src = "http://img.runpipe.com/v1/text/text_sh_rating"+(index+1)+".gif";
	}
}
function ScoreSymbolOut(index)
{
	var score = document.getElementById("comment_score").innerHTML;
	var current_score_index = score/2 - 1;
	ScoreSymbolOver(current_score_index);
}
function WriteOneLineComment(town_id, store_id)
{
	try{
		var comment = document.getElementById("text_oneline_comment").value;
		var score = document.getElementById("comment_score").innerHTML;
        
		if (comment == "")
		{
			alert("내용을 입력해 주세요.");
			return;
		}
		if(score == "0") {
			alert("프로필을 평가해 주세요.");
			return;
		}
		
		//CallAjax("/store/score.comment.ajax.php?store_id=<?= $int_profile_id ?>&store_name=" + encodeURIComponent("<?= addslashes($str_profile_name) ?>") + "&comment=" + encodeURIComponent(comment) + "&score=" + score, "DisplayStoreComment(responseText)");
		CallAjax("/store/score.comment.ajax.php?store_id="+one_store_id+"&store_name=" + encodeURIComponent(one_store_name) + "&comment=" + encodeURIComponent(comment) + "&score=" + score+"&category_id="+one_category_id, "DisplayOneLineComment(responseText,"+town_id+","+one_store_id+")");
		
	} catch(e) {
		//alert(e);
	}
}
function DeleteLineComment(score_id, profile_id)
{
	if(!score_id || !profile_id)
	return;
	if (confirm("삭제하시겠습니까?"))
	CallAjax("/store/score.comment.ajax.php?store_id=" + profile_id + "&score_id=" + score_id, "DisplayStoreComment(responseText)");
}
function RecommendLineComment(score_id, profile_id)
{
	if(!score_id || !profile_id)
	return;
	CallAjax("/store/score.comment.ajax.php?store_id=" + profile_id + "&score_id=" + score_id + "&recommend=1", "DisplayStoreComment(responseText)");
}
function PageStoreComment(store_id, page, category_id, town_id)
{  
	CallAjax("/store/score.comment.ajax.php?store_id=" + store_id + "&page=" + page+"&category_id="+category_id+"&town_id="+town_id, "DisplayStoreComment(responseText)");
}

function DisplayStoreComment(text)
{
	var target = document.getElementById("div_oneline_comment");
	target.innerHTML = text;
	var nocomment = document.getElementById("span_no_comment");

	if(document.getElementById("span_store_score"))
	{
		document.getElementById("div_store_score_star").innerHTML = document.getElementById("span_store_score").innerHTML;
	}
}

function DisplayOneLineComment(text, town_id, store_id)
{	
	var target = document.getElementById("div_oneline_comment");
	target.innerHTML = text;
	var nocomment = document.getElementById("span_no_comment");
	//if(nocomment) ShowCommentDiv("div_oneline_comment_write");
	
//	/*
	if(document.getElementById("span_store_score"))
	{
		//document.getElementById("span_display_score").innerHTML = document.getElementById("span_store_score").innerHTML;
		document.getElementById("div_store_score_star").innerHTML = document.getElementById("span_store_score").innerHTML;
	}
//	*/
	
	if(document.getElementById("span_recommend_result") && document.getElementById("span_recommend_result").innerHTML == "0") {
		alert("이미 추천하셨습니다.");
	}else if(document.getElementById("span_recommend_result")){
		alert("참여해 주셔서 감사합니다.");
	}
	if(document.getElementById("span_commend_result") && document.getElementById("span_commend_result").innerHTML == "0") {
		alert("이미 평가하셨습니다.");
	}

	PageBookmarker(town_id,store_id, 1);
}

function DisplayStarImage(text)
{
	var target = document.getElementById("div_store_score_star");
	target.innerHTML = text;
}

var bdown = false;
var x, y;
var sElem;

function isIE() {
	if(navigator.appName == "Microsoft Internet Explorer")
		return true;
	else 
		return false;
}
function getPointX(e) {
	return e.screenX;
}
function getPointY(e) {
	return e.screenY;
}
function Mdown(el, e) {
	bdown = true;
	//sElem = document.getElementById("iframe_main_image");
	sElem = document.getElementById(el);
	x = getPointX(e);
	y = getPointY(e);

	if(isIE()) {
		document.attachEvent("onmousemove", Mmove);
		document.attachEvent("onmouseup", Mup);
	} else {
		document.addEventListener('mousemove',Mmove,false);
		document.addEventListener('mouseup',Mup,false);
	}
}
function Mup(e) {
	bdown = false;
}
function Mmove(e) {
	if(bdown) {
		nowX = getPointX(e);
		nowY = getPointY(e);
		sElem.style.left = (sElem.offsetLeft + nowX - x) + 'px';
		sElem.style.top = (sElem.offsetTop + nowY - y) + 'px';	
		x = nowX;
		y = nowY;
		
		return false;
	}
}

/*장소지도크게보기 끝*/

///////////////////////edit//////////////////////////////////////////////////////////////////////////////////////
function SubmitCheck_Edit()
{
	
		
		if(document.store_input.store_time_table.value.length > 100){
			alert("영업시간은 100자 이하여야 합니다.");
			return false;
		}
		if(document.store_input.store_menu.value.length > 100){
			alert("추천 메뉴는 100자 이하여야 합니다.");
			return false;
		}
		
		document.store_input.town_id.value = document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].value;
		document.store_input.town_name.value = document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].text;
}

function DeleteUserImage(image_id, user_id, store_id) 
{
	if(confirm("삭제하시겠습니까?")) {
		CallAjax("/store/image.delete.ajax.php?image_id="+image_id+"&user_id="+user_id+"&store_id="+store_id, "DisplayUserImage(responseText, 'user_image')");
	}
}
function DisplayUserImage(responseText, div_id)
{
	var target_div = document.getElementById(div_id);
	target_div.innerHTML = responseText;
}


function storeConfirm(store_id)
{
	if(confirm("장소 프로필을 삭제 하시겠습니까?"))
	{
         document.location="/store/store.delete.proc.php?store_id="+store_id+"&from=1";
	}
}

function ShowLocationByName()
{
	var width = 320;
	var height = 328;
	var x = 270;
	var y = 280;
	var html = "<p><iframe src=\"/map/search.google.php\" width=\"" + width + "\" height=\"" + height + "\" leftmargin=\"0\" marginheight=\"0\" marginwidth=\"0\" topmargin=\"0\"  scrolling=\"no\"  frameborder=\"0\"></iframe></p>";

	var div = document.getElementById("popup");
	
	div.style.left = x;
	div.style.top = y;	
	div.style.width = width;
	div.style.height = height;
	div.innerHTML = html;
	div.style.display = "block";	
	popup = true;		
}

function PageImage(user_id,store_id,page)
{
	CallAjax("/store/image.delete.ajax.php?user_id="+user_id+"&store_id="+store_id+"&page="+page, "DisplayUserImage(responseText, 'user_image')");
}

///////////////////////////////store.relate.search.php////////////////////////////////////////////
function SearchProfile(store_id)
{
	var el = document.getElementById("query");
	if(trim(el.value) != "") {
		location.href = "/store/store.related.search.php?store_id="+store_id+"&query=" + encodeURIComponent(el.value);
	}
}

function RelatedLink(store_id, related_store_id) {
	if(confirm("관련 프로필로 연결 하시겠습니까?"))
	CallAjax("/store/store.related.link.ajax.php?store_id=" + store_id + "&related_store_id=" + related_store_id, "DisplayRSSMsg(responseText," + store_id + ")");
}
function DisplayRSSMsg(responseText,store_id) {
	if(responseText != "성공"){
		alert(responseText);
	}else{
		PageStoreRelated(1,1);
		if(confirm("관련 프로필로 연결 되었습니다. 지금 확인하시겠습니까?"))
			location.href="/store/index.php?store_id=" + store_id;
	}
}


////////////////////////////////////////////////////////add.store//////////////////////////////////////////////////
var name_check=0;


function Close(res)
{
	
	if(res== -1){
		ClosePopup();
	return name_check=1;
	
	}else{
		ClosePopup();
		return name_check=0;
	}
}
function defaultCheck()
{
	return name_check=0;

}
function SubmitCheck(form)
{
	if(name_check == 0){
		alert("중복 확인을 해 주세요.");
		
		return false;
	}
	if(!form.store_name.value ){
		alert("장소 이름을 입력해 주세요.");
		form.store_name.focus();
		return false;
	}
	if(!CheckProfileName(form.store_name.value)){
		alert("장소 이름은 1자리 이상 30자리 이하의 한글, 영문자, 숫자로 구성되어야 합니다.");
		form.store_name.focus();
		return false;
	}
	if(form.store_description.value.length > 10000){
		alert("장소 소개는 10000자 이하여야 합니다.");
		form.store_description.focus();
		return false;
	}

	document.store_input.town_id.value = document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].value;
	document.store_input.town_name.value = document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].text;

	CallAjax("/store/store.name.php?type=submitcheck&store_name=" + encodeURIComponent(form.store_name.value) , "Result_Submit(responseText)");
    return false;
	
}
function Result_Submit(responseText)
{
	if(responseText == 'Y') {
		document.store_input.submit();
		
		
	}else
	{
		alert('이미 등록된 장소 이름이 있습니다.');
	}
}

// Ajax
function Reg_continue()
{
	if(name_check == 0){
		alert("중복 확인을 해 주세요.");
		
		return false;
	}
	if(!document.store_input.store_name.value ){
		alert("장소 이름을 입력해 주세요.");
		document.store_input.store_name.focus();
		return false;
	}
	if(!CheckProfileName(document.store_input.store_name.value)){
		alert("장소 이름은 1자리 이상 30자리 이하의 한글, 영문자, 숫자로 구성되어야 합니다.");
		document.store_input.store_name.focus();
		return false;
	}
	if(document.store_input.store_description.value.length > 10000){
		alert("장소 소개는 10000자 이하여야 합니다.");
		document.store_input.store_description.focus();
		return false;
	}

	document.store_input.town_id.value = document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].value;
	document.store_input.town_name.value = document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].text;

	CallAjax("/store/store.name.php?type=submitcheck&store_name=" + encodeURIComponent(document.store_input.store_name.value) , "Result_Submit_ajax(responseText)");

	return false;
}

function Result_Submit_ajax(responseText)
{
	if(responseText == 'Y') {
		document.store_input.action = "http://up1.nowprofile.com/store/add.proc.php?type=continue";
		document.store_input.submit();
	}else
	{
		alert('이미 등록된 장소 이름이 있습니다.');
	}
}

function PageBookmarker(town_id, store_id, page)
{
	CallAjax("/store/bookmarker.store.ajax.php?town_id="+town_id+"&store_id=" + store_id + "&page=" + page, "DisplayBookmarker(responseText)");
}

function DisplayBookmarker(text)
{	
	var target = document.getElementById("div_bookmarker");
	target.innerHTML = text;
}

function SubmitCheck_StoreAdd(form)
{	
	if(!form.store_name.value ){
		alert("장소 이름을 입력해 주세요.");
		form.store_name.focus();
		return false;
	}
	if(!CheckProfileName(form.store_name.value)){
		alert("장소 이름은 1자리 이상 30자리 이하의 한글, 영문자, 숫자로 구성되어야 합니다.");
		form.store_name.focus();
		return false;
	}
	if(form.store_description.value.length > 10000){
		alert("장소 소개는 10000자 이하여야 합니다.");
		form.store_description.focus();
		return false;
	}

	if(document.store_input.sel_town){
		document.store_input.town_id.value = document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].value;
		document.store_input.town_name.value = document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].text;
	}

	CallAjax("/store/store.name.php?type=submitcheck&store_name=" + encodeURIComponent(document.store_input.store_name.value) , "Result_Submit(responseText)");

	return false;
}

function Result_Submit(responseText)
{	
	if(responseText == 'Y') {   
		document.store_input.submit();
	}else
	{
		alert('이미 등록된 장소 이름이 있습니다.');
	}
}

// Ajax
function Reg_continue()
{
	if(!document.store_input.store_name.value ){
		alert("장소 이름을 입력해 주세요.");
		document.store_input.store_name.focus();
		return false;
	}
	if(!CheckProfileName(document.store_input.store_name.value)){
		alert("장소 이름은 2자리 이상 30자리 이하의 한글, 영문자, 숫자로 구성되어야 합니다.");
		document.store_input.store_name.focus();
		return false;
	}
	if(document.store_input.store_description.value.length > 10000){
		alert("장소 소개는 10000자 이하여야 합니다.");
		document.store_input.store_description.focus();
		return false;
	}

	document.store_input.town_id.value = document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].value;
	document.store_input.town_name.value = document.store_input.sel_town.options[document.store_input.sel_town.selectedIndex].text;

	CallAjax("/store/store.name.php?type=submitcheck&store_name=" + encodeURIComponent(document.store_input.store_name.value) , "Result_Submit_ajax(responseText)");

	return false;
}

function Result_Submit_ajax(responseText)
{
	if(responseText == 'Y') {
		document.store_input.action = "http://up1.runpipe.com/store/add.proc.php?type=continue";
		document.store_input.submit();
	}else
	{
		alert('이미 등록된 장소 이름이 있습니다.');
	}
}

	function SaveScore(store_id,  user_id, score)
	{ 
			CallAjax("/store/game.score.proc.ajax.php?store_id="+store_id+"&score="+score, "DisplaySaveScore(responseText, "+score+", "+store_id+","+user_id+")");
				
	}
	
	function DisplaySaveScore(text, score, store_id, user_id)
	{   
		  text = text.split("|");
		  var top_score = text[0];
		  var top_user_name = text[1];
		  var top_user_id = text[2];
          
		  if(confirm("점수를 이야기글로 남기시겠습니까?")){
					if(top_score < 1){
						document.posting.content.value= commify(score)+"점으로 1위가 되었습니다.";
					}else if(score > top_score && top_user_id != user_id){
						document.posting.content.value= commify(score)+"점으로 @"+top_user_name+" 님을 제치고 1위가 되었습니다.";
					}else{
						document.posting.content.value= commify(score)+ "점을 획득하였습니다.";
					}
					CallAjax("/store/game.score.proc.ajax.php?store_id="+store_id+"&score="+score+"&type=1", "");
					WritePost();
					PostStore(1, store_id, 0);
					PageBookmarkerReload(1003,store_id, 1);

			}
			ShowGameRanking(store_id ,1);
	}
	function PageBookmarkerReload(town_id, store_id, page)
	{
          PageBookmarker(town_id,store_id, page);
		  PostStore(1, store_id, 0);
	} 

		function EditPost(post_id)
	{
		document.getElementById("div_post_" + post_id).style.display = "none";
		document.getElementById("div_post_edit_" + post_id).style.display = "block";
	}

	function EditCancel(post_id)
	{
		document.getElementById("div_post_edit_" + post_id).style.display = "none";
		document.getElementById("div_post_" + post_id).style.display = "block";
		document.getElementById("post_edit_" + post_id).content.value = document.getElementById("post_content_" + post_id).innerHTML.replace(/<br>/gi, "\n");
	}

	function SendEdit(post_id)
	{
		if (trim(document.getElementById("post_edit_"  + post_id).content.value) == "")
		{
			alert("글을 입력해주세요.");
			return;
		}
		document.getElementById("post_edit_"  + post_id).submit();
	}

	function PostStore(book_page,store_id, post_id)
	{      
		  if(post_id > 0)
			CallAjax("/store/post.store.ajax.php?page=" + book_page+ "&store_id="+ store_id+ "&post_id="+ post_id+"#post_"+post_id, "DisplayPostStore(responseText)");
		  else
			CallAjax("/store/post.store.ajax.php?page=" + book_page+ "&store_id="+ store_id, "DisplayPostStore(responseText)");
	}
	function DisplayPostStore(text)
	{
		  var target = document.getElementById("post_list");
		  target.innerHTML = text;
	}

	function ShowNewStore(town_id)
	{      
			CallAjax("/inc/new.store.list.ajax.php?town_id="+ town_id, "DisplayShowNewStore(responseText)");
	}
	function DisplayShowNewStore(text)
	{
		  var target = document.getElementById("new_store_list");
		  target.innerHTML = text;
	}

