/****************************************************
* @version : 1.0
* @date : 2007.06.18
* @author : moong
* @organization : Daum Communications UI Dev.
****************************************************/
function doDuplicate() {
	var dest;
	var openid2 = document.getElementById("dForm").openid2.value;


	if (!checkID()) return false;

	document.getElementById("dForm").dupcheck.value = "true";
	document.getElementById("dForm").submit();
}

function doDuplicate2() {
	var dest;
	var blog2 = document.getElementById("dForm").blog2.value;

	if (!checkID()) return false;

	//alert("before setting");
	document.getElementById("dForm").dupcheck.value = "true";
	//alert("after setting");
	document.getElementById("dForm").submit();
}


function checkdup(){
	var thisForm = document.getElementById("dupconfirm");
	if(document.getElementById('Id_make').className == 'openid'){
		if(thisForm.value == ""){
			alert("아이디(ID)중복확인을 해주세요");
			document.getElementById("openid2").focus();
		}
	}
}
function FrmChk(){
	if(document.getElementById('openid2')) if (!checkID()) return false;
	if (!checkPassword()) return false;
	if (!checkAgree()) return false;
	
	document.getElementById("dForm").action = '/account';
	document.getElementById("dForm").submit();
}

function checkID() {
	if(document.getElementById('openid2'))
		var thisForm = document.getElementById("openid2");
	if(document.getElementById('blog2'))
		var thisForm = document.getElementById("blog2");
	var id = thisForm.value;
	if (id == "") {
		alert("아이디(ID)를 입력해주세요.");
		thisForm.focus();	
		return false;
	} else {
		var ch;
		for (var i = 0; i < id.length; i++) {
			ch = id.charAt(i);
			if ( !(ch >= 'a' && ch <= 'z') && !(ch >= '0' && ch <= '9') && (ch != '-') && (ch != '_') && (ch != '.') || (id.length < 3) ) {
				alert("아이디(ID)는 3~15자의 영문소문자, 숫자, '-', '_', '.'만 가능합니다.");
				thisForm.focus();	
				return false;
			}
		}
	}
	return true;
}
function checkPassword() {
	var thisForm = document.getElementById("passwd");
	if (thisForm.value == "") {
		alert("비밀번호를 입력해주세요.");
		thisForm.focus();
		return;
	}	
	
	return true;
}
function checkAgree(){
	var thisForm = document.getElementById("agree");
	if(!thisForm.checked){
		alert("약관에 동의해주세요");
		return;
	}
	
	return true;
}

function FrmChk2(){
	if (!checkID()) return false;
	if (!checkPassword()) return false;
	
	document.getElementById("dForm").action = '/login';
	document.getElementById("dForm").submit();
}

function BlogTo(blog){
	if(blog){
		document.getElementById('Id_make').className = 'blog';
		document.getElementById('Id_make').innerHTML = '<input type="hidden" name="blog2" id="blog2" value="'+blog+'" /><span class="point">'+ blog +'</span>';
		document.getElementById('Id_txt').innerHTML = '<a href="javascript:OpenTo(\''+blog+'\')">[오픈ID 주소로 만들기]</a>';
	}
}

function OpenTo(blog){
	document.getElementById('Id_make').className = 'openid';
	document.getElementById('Id_make').innerHTML = '<span class="point">openid.daum.net/</span> <input type="text" id="openid2" name="openid2" class="tbox" value="" maxlength="50"/> <img src="/image/openid/btn_idok.gif" alt="중복확인" class="bt" style="cursor:hand" onclick="return doDuplicate();" />\n<div class="msg"><span class="point"></span></div>';
	if(blog != '')
		document.getElementById('Id_txt').innerHTML = '<a href="javascript:BlogTo(\''+blog+'\')">[블로그 주소로 오픈ID 만들기]</a>';
	else
		document.getElementById('Id_txt').innerHTML = 'Daum 블로그 주소로 오픈ID를 사용할 수 있습니다.<br /> <a href="http://blog.daum.net/_blog/redirect.do?redirect=register" target="new">[블로그 만들기]</a> 하시고 <a href="/account?blogmake=true">[블로그 주소로 오픈ID 만들기]</a> 를 클릭하세요.';
}

function setValue(approval){
	var thisForm = document.getElementById('dForm');
	if ( approval == "always" ) {
		thisForm.approval.value = 1;
	}else if ( approval == "once" ) {
		thisForm.approval.value = 0;
	} else {
		thisForm.approval.value = 100;
	} 
	thisForm.submit();
}


function FrmChkBlog(){
//	if (!checkID()) return false;
	if (!checkPassword()) return false;
	if (!checkAgree()) return false;
	
	document.getElementById("dForm").action = '/account';
	document.getElementById("dForm").submit();
}

var blogLogin = '<span class="point">blog.daum.net/</span> <input type="text" name="blog2" id="blog2" class="tbox" tabindex="1" maxlength="50"/>\n <div class="Text"><a href="javascript:OpenLogin();">[오픈ID 주소로 로그인]</a></div>';
var openidLogin = '<span class="point">openid.daum.net/</span> <input type="text" name="openid2" id="openid2" class="tbox" tabindex="1" maxlength="50" />\n <div class="Text"><a href="javascript:BlogLogin();">[블로그 주소로 로그인]</a></div>';

function BlogLogin(){
	document.getElementById('LoginHowTo').innerHTML = blogLogin;
	openid_setCookie('type','blog');
}

function OpenLogin(){
	document.getElementById('LoginHowTo').innerHTML = openidLogin;
	openid_setCookie('type','openid');
}

function FrmChkBLog(){
	if (!checkPassword()) return false;

	if(document.getElementById("agr"))	if (!checkAgree()) return false;

	document.getElementById("dForm").action = '/server/login.do';
	document.getElementById("dForm").submit();
}

function FrmChkAgr(){
	if (!checkAgree()) return false;
	
	document.getElementById("dForm").action = '/login';
	document.getElementById("dForm").submit();
}

//Cookie
var expireDate = new Date();
expireDate.setMonth(expireDate.getMonth()+1);

function openid_setCookie(c,s){
	document.cookie = c+'='+s+';expires='+expireDate.toGMTString()+';path=/;domain='+window.location.hostname+';';
}

function openid_getCookie(sName){
	var aCookie = document.cookie.split("; ");
	for (var i=0; i < aCookie.length; i++){
		var aCrumb = aCookie[i].split("=");
		if (sName == aCrumb[0])
			return unescape(aCrumb[1]);
	}
	return null;
}