﻿// JScript 파일

	function goLoginPage()
	{
		var loginURL
			= "/Member/LoginForm.aspx?loginSuccessURL=" + encodeURIComponent(location.href);
		top.location.href = loginURL;
	}
	
	function goLogOut()
	{
		top.location.href = "/Member/LoginPS.aspx?isLogOut=1";
	}
	
	function goLoginPageAfterConfirm(message, isCloseWindowIfFalse)
	{
		if (isCloseWindowIfFalse == null) isCloseWindowIfFalse = false;
		
		if (confirm(message))
		{
			goLoginPage();
		}
		else
		{
			if (isCloseWindowIfFalse)
			{
				window.close();
			}
		}
	}
	
	function secedeMember()
	{
		if (confirm("포토야 회원탈퇴를 요청하셨습니다.\n탈퇴작업을 계속 진행하시겠습니까?"))
		{
			var url = "/Member/AJAX/SecedeMember.aspx";

			var pars = "";

			var newAjax = new Ajax.Request(
				url,
				{
					method: "post",
					parameters: pars,
					onComplete : secedeMemberFinish
				});

			startFloatLabel("회원 탈퇴 중입니다.");
		}
	}
	
	function secedeMemberFinish(ajaxRequest)
	{
		stopFloatLabel();

		if (ajaxRequest.responseText == "true")
		{
			alert("회원 탈퇴가 완료되었습니다.");
		}
		else if (ajaxRequest.responseText == "false")
		{
			alert("회원 탈퇴 작업 중 오류가 발생했습니다.");
		}
		else
		{
			alert(ajaxRequest.responseText);
		}
	}
	
	
	function setCookie(name, value, expireDuration, domain)
	{
		var exDate = new Date();
		
		var cookieString
			= name + "=" + encodeURIComponent(value) + "; "
			+ "path=/; " 

		if (expireDuration != null && expireDuration > 0)
		{
			exDate.setDate(exDate.getDate() + expireDuration);

			cookieString
				+= "expires=" + exDate.toGMTString() + ";";
		}
		
		if (domain != null)
		{
			cookieString
				+= "domain=" + domain + "; "
		}

		document.cookie = cookieString;
	}
	
	function getCookie(name)
	{
		var pattern = name + "=([^;]+)[;]+";
		var re = new RegExp(pattern,"ig");
		re.exec(document.cookie + ";");
		
		return decodeURIComponent(RegExp.$1);
	}
	
	function openMsgWindow(receiverID, isReload, rootMsgID)
	{
		url = "/Common/WriteMessageForm.aspx?receiverID=" + receiverID;
		if (rootMsgID != null && rootMsgID > 0) url += "&rootMsgID=" + rootMsgID;
		if (isReload != null) url += "&isReload=" + isReload;
		
		openWindowCenter(url, 364, 380, "msgform");
	}
	

	function openWindowCenter(openURL, w, h, windowName)
	{
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = "height="+h+",width="+w+",top="+wint+",left="+winl

		win = window.open(openURL, windowName, winprops);
	}
	
	function openWindowCenterScroll(openURL, w, h, windowName)
	{
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = "scrollbars=1,height="+h+",width="+w+",top="+wint+",left="+winl

		win = window.open(openURL, windowName, winprops);
	}
	
	
	function resizePopupWindow(maxWidth, maxHeight)
	{
		if (maxWidth == null) maxWidth = 1000;
		if (maxHeight == null) maxHeight = 700;
		
		var width = document.body.scrollWidth + (document.body.offsetWidth - document.body.clientWidth) + 11;
		var height = document.body.scrollHeight + (document.body.offsetHeight - document.body.clientHeight) + 27;

		if (width > 1000)
		{
			width = maxWidth;
		}
		if (height > 700)
		{
			height = maxHeight;
		}
		window.resizeTo(width, height);
	}

    function resizeImageWidth(imgElement, maxWidth)
    {
        if (imgElement != null && imgElement.width != 0)
        {
            if (imgElement.width > maxWidth)
            {
                
                var newWidth = maxWidth;
                var newHeight = (imgElement.height * newWidth) / imgElement.width;
                
                imgElement.style.width = newWidth;
                imgElement.style.height = newHeight;
            }
        }
        else
        {
            var tmpImg = new Image();
            tmpImg.src = imgElement.src;
            
            imgElement.width = tmpImg.width;
            imgElement.height = tmpImg.height;
        }
    }
  
	function resizeImage(imgElement, maxWidth, maxHeight, resizeCount)
	{
		if (imgElement != null)
		{
			var tempImg = new Image();
					
			tempImg.src = imgElement.src;
			
			if (tempImg.width > maxWidth || tempImg.height > maxHeight)
			{
				var maxRatio = maxWidth / maxHeight;
				var imgRatio = tempImg.width / tempImg.height;
				
				//if (tempImg.width > tempImg.height)
				if (maxRatio < imgRatio)
				{	
					var newWidth = maxWidth;
					var newHeight = (tempImg.height * newWidth) / tempImg.width;
					
					imgElement.width = newWidth;
					imgElement.height = newHeight;
				}
				else
				{
					var newHeight = maxHeight;
					var newWidth = (tempImg.width * newHeight) / tempImg.height;
					
					imgElement.width = newWidth;
					imgElement.height = newHeight;
				}
			}
			else if (tempImg.width == 0 || tempImg.height == 0)
			{
				imgElement.width = maxWidth;
				imgElement.height = maxHeight;
			}
			else
			{
				imgElement.width = tempImg.width;
				imgElement.height = tempImg.height;
			}
			
			imgElement.align = "absmiddle";
		}
	}
	
	
	function checkEmail(email)
	{
		var bReturn = false;
		
		bReturn = email.search(/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/gi) != -1;
		
		return bReturn;
	}
	
	
	function checkAll(chkObj, checked)
	{
		if (chkObj.length == null)
		{
			chkObj.checked = checked;
		}
		else
		{
			for (i = 0; i < chkObj.length; i++)
			{
				chkObj[i].checked = checked;
			}
		}
	}
	
	function getCheckedValueList(chkObj)
	{
		var idList = "";
		
		if (chkObj.length == null)
		{
			if (chkObj.checked)
			{
				idList = chkObj.value;
			}
		}
		else
		{
			for (i = 0; i < chkObj.length; i++)
			{
				if (chkObj[i].checked)
				{
					idList = 
						idList 
						+ "," + chkObj[i].value;
				}
			}
			
			if (idList.length > 0)
			{
				idList = idList.substring(1);
			}
		}

		return idList;
	}
	
	
	function isChecked(chkObj)
	{
		var returnValue = false;
		
		if (chkObj.length == null)
		{
			returnValue = chkObj.checked;
		}
		else
		{
			for (var i = 0; i < chkObj.length; i++)
			{
				if (chkObj[i].checked)
				{
					returnValue = true;
					break;
				}
			}
		}
		
		return returnValue;
	}
	
	
	function airloaderAddText(frmElement)
	{
		if (frmElement != null)
		{
			document.all.airLoader.AddText(frmElement.name, frmElement.value);
		}
	}
	
	function airloaderSelectBox(frmElement)
	{
		if (frmElement != null)
		{
			document.all.airLoader.AddText(frmElement.name, frmElement.value);
		}
	}
	
	function airloaderAddRadioBox(frmElement)
	{
		var checkValue = "false";
		
		if (frmElement != null)
		{
			if (frmElement[0].checked) { checkValue = "true"; }
		
			document.all.airLoader.AddText(frmElement[0].name, checkValue);
		}
	}
	
	function airloaderAddCheckBox(frmElement)
	{
		var checkValue = "false";
		
		if (frmElement != null)
		{
			if (frmElement.checked) { checkValue = "true"; }
			
			document.all.airLoader.AddText(frmElement.name, checkValue);
		}
	}


    function getStringLength(value)
    {
        var length = 0;
        
        for (ixx=0; ixx < value.length; ixx++)
        {
            var codeNum = value.charCodeAt(ixx);
            
            if (codeNum < 128) { length++; }
            else { length = length + 2; }
        }
        
        return length;
    }
	
	
	function moveNextElement(checkElement, nextElement , size)
	{
		if (checkElement.value.length == size)
		{
			nextElement.focus();
		}
	}
	
	function checkChildRadioBox(parentObj)
	{
		var radioObj = parentObj.getElementsByTagName("input");
		
		if (radioObj != null)
		{
			for (var i = 0; i < radioObj.length; i++)
			{
				if (radioObj[0].type == "radio")
				{
					radioObj[0].checked = true;
					break;
				}
			}
		}
	}
	
	
	// isClear는 isView==false일 때만 작동
	function showLayer(layerID, isView, isClear)
	{
		if (isClear == null) isClear = false;
		
		var layerObj = null;
		if (typeof(layerID) == "object") layerObj = layerID;
		else layerObj = document.getElementById(layerID);
		
		if (layerObj != null)
		{
//			if (isView) layerObj.style.display = "inline";
//			else layerObj.style.display = "none";
			if (isView) 
			{
				layerObj.style.height = "";
				layerObj.style.width = "";
				layerObj.style.overflow = "";
			}
			else 
			{
				layerObj.style.height = "0px";
				layerObj.style.width = "0px";
				layerObj.style.overflow = "hidden";
				
				if (isClear)
				{
					layerObj.innerHTML = "";
				}
			}
		}
	}
	
	function displayLayer(dispID, ajaxID)
	{
		var isChanged = false;
		
		try
		{
			if (ajaxID == null)
			{
				var tmpID = dispID;
				dispID = "layerDISP" + tmpID;
				ajaxID = "layerAJAX" + tmpID;
			}

			var ajaxObj = document.getElementById(ajaxID);
			var dispObj = document.getElementById(dispID);

			if (ajaxObj != null && dispObj != null)
			{
				if (ajaxObj.innerHTML.replace(/ /g, "").length < 1
					&& dispObj.dontChangeIfEmptyAJAXLyaer == "true")
				{
				}
				else
				{
					dispObj.innerHTML = ajaxObj.innerHTML;

					if (dispObj.autoHide == "true")
					{
						if (ajaxObj.innerHTML.replace(/ /g, "").length < 1)
						{
							dispObj.style.display = "none";
						}
						else
						{
							if (dispObj.style.display == "none")
							{
								dispObj.style.display = "inline";
							}
						}
					}

					isChanged = true;
				}
			}
			else if (ajaxObj != null)
			{
				if (dispObj.autoHide == "true")
				{
					dispObj.style.display = "none";
				}
			}
		} catch (err) {}
		
		return isChanged;
	}
	
	function swapLayer(dispID, ajaxID)
	{
		var isChanged = false;
		
		try
		{
			if (ajaxID == null)
			{
				var tmpID = dispID;
				dispID = "layerDISP" + tmpID;
				ajaxID = "layerAJAX" + tmpID;
			}

			var ajaxObj = document.getElementById(ajaxID);
			var dispObj = document.getElementById(dispID);

			if (ajaxObj != null && dispObj != null)
			{
				dispObj.firstChild.swapNode(ajaxObj.firstChild);
//					ajaxObj.innerHTML = "<div></div>";
				isChanged = true;
			}
		} catch (err) {}
		
		return isChanged;
	}
	
	
	function isEmptyLayer(layerID)
	{
		var isEmpty = false;
		
		var layerObj = document.getElementById(layerID);
		
		if (layerObj == null)
		{
			isEmpty = true;
		}
		else
		{
			isEmpty = layerObj.innerHTML.replace(/ /g, "").length < 1;
		}
		
		return isEmpty;
	}
	
	
	function changeButtonStyle(btnName, btnIndex, btnCount, onClassName, offClassName)
	{
		if (btnCount == null || btnCount < 1) btnCount = 100;
		
		for (var i = 0; i < btnCount; i++)
		{
			var btnObj = document.getElementById("btn" + btnName + i);
			if (btnObj != null)
			{
				btnObj.className = offClassName;
			}
		}
		
		
		var selBtnObj = document.getElementById("btn" + btnName + btnIndex);
		if (selBtnObj != null)
		{
			selBtnObj.className = onClassName;
		}
	}
	
	function changeButtonStyleLayerDisplay(btnName, btnIndex, btnCount, onClassName, offClassName)
	{
		if (btnCount == null || btnCount < 1) btnCount = 100;
		
		for (var i = 0; i < btnCount; i++)
		{
			var btnObj = document.getElementById("btn" + btnName + i);
			if (btnObj != null)
			{
				btnObj.className = offClassName;
			}
			
			var layerObj = document.getElementById("layer" + btnName + i);
			if (layerObj != null)
			{
				layerObj.style.display = "none";
			}
		}
		
		
		var selBtnObj = document.getElementById("btn" + btnName + btnIndex);
		if (selBtnObj != null)
		{
			selBtnObj.className = onClassName;
		}
		
		var selLayerObj = document.getElementById("layer" + btnName + btnIndex);
		if (selLayerObj != null)
		{
			selLayerObj.style.display = "";
		}
	}
	
	
	

	
	// 동적 Js 호출(파일명, 로드 완료 후 콜백함수)
	function include_js(file, callBackFunction)
	{
		var html_doc = document.getElementsByTagName('head')[0];

		js = document.createElement('script');
		js.setAttribute('type', 'text/javascript');
		js.setAttribute('src', file);

		html_doc.appendChild(js);

	 

		// This will load the javascript for Safari, but it won't
		// let us know when it's been loaded.  The following will.

		if(/WebKit|Khtml/i.test(navigator.userAgent))
		{
			var iframe = document.createElement('iframe');
			iframe.style.display = 'none';
			iframe.setAttribute('src',file);

			document.getElementsByTagName('body').item(0).appendChild(iframe);

	 

			// Fires in Saf
			iframe.onload = function() {

				 callbackFunction();
				 alert('JS iframe fired');
			}
		}

		// Fires in IE, also modified the test to cover both states
		js.onreadystatechange = function () {
			if (/complete|loaded/.test(js.readyState)) {

				callBackFunction();
	          
				//alert('JS onreadystate fired');
			}
		}

		// Fires in FF
		js.onload = function () {        

			callBackFunction();

			//alert('JS onload fired');
		}

		//return false;
	}
	
	function scrollIntoView(elementID)
	{
		var elementObj = document.getElementById(elementID);
		if (elementObj != null)
		{
			elementObj.scrollIntoView();
		}
	}




	function adBoxSearchKeyword(searchValue)
	{
		searchTwoBox(searchValue, 0);
	}
	

		
		
	function searchTwoBox(searchValue, searchType)
	{
		if (searchValue.blank())
		{
			alert("검색어를 입력해 주세요");
			
			var searchBox = document.getElementById("searchValue");
			if (searchBox != null)
			{
				searchBox.focus();
			}
		}
		else
		{
			var urlPage = "";
			switch (searchType)
			{
				case 0 :
					urlPage = "/TwoBox/PageSearchWeb.aspx";
					if (location.pathname.toLowerCase() == urlPage.toLowerCase())
					{
						urlPage = null;
					}
					break;
				case 1 :
					urlPage = "/TwoBox/PageSearchNews.aspx";
					if (location.pathname.toLowerCase() == urlPage.toLowerCase())
					{
						urlPage = null;
					}
					break;
				case 2 :
					urlPage = "/TwoBox/PageSearchPhoto.aspx";
					if (location.pathname.toLowerCase() == urlPage.toLowerCase())
					{
						urlPage = null;
					}
					break;
			}
			
			if (urlPage == null)
			{
				var searchValueBox = document.getElementById("searchValue");
				if (searchValueBox != null)
				{
					searchValueBox.value = searchValue;
					searchKeyword(searchValue);
				}
			}
			else
			{
				var url 
					= urlPage
					+ "?"
					+ Object.toQueryString(
						{
							searchValue : searchValue
						}
					);
				
				top.location.href = url;
			}
		}
	}
	
	
	function piSearchPhoto(searchValue)
	{
		if (location.pathname.substring(0, 8).toLowerCase() == "/twobox/")
		{
			searchTwoBox(searchValue, 2)
		}
		else 
		{
			CommonSearchPhotoShare(searchValue);
		}
	}
	
	
	
	function showSiteClause()
	{
		openWindowCenterScroll("/Member/SiteClause.html", 800, 550, "siteclause")
	}
	
	
	function getInnerText(element)
	{
		var text = "";
		
		if (element.innerText) text = element.innerText;
		else text = element.textContent;
		
		return text;
	}
	
