//rotate_num=0;
var onPwd=false;
function init(){
	if (document.login) {
		if(ID.length > 0) document.login.USERID.value=ID;
		if(!onPwd) document.login.USERID.focus();
	}
	//rand_notice();
	//notice_p();
	//notice_shs();
	//notice_shutdown();
	//if (document.all['imageDiv'] && document.all['image2Div'])
	//{
	//	rotateImage();
	//	if (document.all['Righthtml_t599bB1BDiv'])
	//		document.all['Righthtml_t599bB1BDiv'].style.visibility = 'visible';
	//}
	//if (document.all['Righthtml_t599bB1BDiv'])
	//	document.all['Righthtml_t599bB1BDiv'].style.visibility = 'visible';
}
function rotateImage(){
	if (rotate_num == 1)
	{
		rotate_num=0;
		document.all.imageDiv.innerHTML="<img src='http://chart.nate.com/image/KOSPI.gif?"+Math.random()+"' border=0 title='nate.com Á¦°ø'>";
		//document.all.image2Div.innerHTML="<img src=http://chart.bigcharts.com/custom/schwab_frontpage/schwab-fp-djia.gifquote?" + Math.random() + " border=0>";
		document.all.image2Div.innerHTML="<img src='http://money.cnn.com/ssi/BC/markets-data/dow.gif?"+Math.random()+"' border=0>";
	}
	else
	{
		rotate_num=1;
		document.all.imageDiv.innerHTML="<img src='http://chart.nate.com/image/KOSDAQ.gif?"+Math.random()+"' border=0 title='nate.com Á¦°ø'>";
		//document.all.image2Div.innerHTML="<img src=http://chart.bigcharts.com/custom/schwab_frontpage/schwab-fp-nasdaq.gifquote?" + Math.random() + " border=0>";
		document.all.image2Div.innerHTML="<img src='http://money.cnn.com/ssi/BC/markets-data/nasdaq.gif?"+Math.random()+"' border=0>";
	}
	setTimeout('rotateImage()',10000);
}
function GetCookie (name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i <clen){
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)	return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0)		break;
	}
	return null;
}
function getCookieVal(offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function innerOpen(url,width,height,leftl,topl,rightl){
	if (IEVER>=5) {
		if (rightl) {
			var posLeft = parseInt((window.screen.availWidth-width)-rightl);
			leftl = posLeft;
		}
		return window.showModelessDialog(url,window,'dialogWidth:'+width+'px;dialogHeight:'+height+'px;dialogLeft:'+leftl+'px;dialogTop:'+topl+'px;status:no;resizable:yes');
	}
	else{
		var posLeft = 	parseInt((window.screen.availWidth-width)/2);
		var posTop = 	parseInt((window.screen.availHeight-height)/2);
		var oWindow =	window.open(url,'_blank',"left="+posLeft+",top="+posTop+",width="+width+",height="+height+",menubar=no,scrollbars=no,resizable=no,status=no,toolbar=no,titlebar=no");
		if (oWindow){
			oWindow.focus();
			return oWindow;
		}
		else	return null;
	}
}
function notice_shs() {
	var disable=GetCookie("DIS0303SS");
	if ( disable !='openNo') {
		innerOpen("/notice/shs_seocho/popup_off200303.html",510,415,0,150,220);
	}
}
function notice_p() {
	var disable=GetCookie("DIS0227P");
	if ( disable !='openNo') {
		innerOpen("/notice/popup/premium200302.html",445,540,200,20,50);
	}
}
function notice_s() {
	var disable=GetCookie("DIS1121S");
	if ( disable !='openNo') {
		innerOpen("/notice/popup/stocknet20021121.html",455,510,200,100,50);
	}
}
function rand_notice() {
	rand_no=parseInt(Math.random() * 100);
	if (rand_no < 60)	notice_p();
	else			notice_s();
}
function notice_shutdown(){
	innerOpen("/notice/notice_shutdown.html",308,185,400,300,0);
}
function guest_check() {

	nick=document.guest_form.GUESTID.value;
	han_flag=1;
	if (nick==null)	return false;
	if (nick=="") {
		alert("´ëÈ­¸íÀ» ÀÔ·ÂÇÏ¼¼¿ä.");
		return false;
	}
	tmpstr=escape(nick);
	if (tmpstr.indexOf("%20")>=0) {
		alert("ºóÄ­(°ø¹é)À» ÀÔ·ÂÇÏ¼Ì½À´Ï´Ù.");
		return false;
	}
	if (tmpstr.match(/%/)){
		han_flag=2;
	}
	nick=unescape(tmpstr);
	if (nick.charAt(0)>='0'&& nick.charAt(0)<="9"){
		alert("´ëÈ­¸íÀº ¼ýÀÚ·Î ½ÃÀÛµÉ ¼ö ¾ø½À´Ï´Ù.\nÃ¹±ÛÀÚ°¡ ÇÑ±Û ¶Ç´Â ¿µ¹®ÀÌ¾î¾ß ÇÕ´Ï´Ù.");
		return false;
	}
	if ((nick.charAt(0)>='!'&& nick.charAt(0)<="/") || (nick.charAt(0)>=':'&& nick.charAt(0)<="@") || (nick.charAt(0)>='['&& nick.charAt(0)<="`") || (nick.charAt(0)>='{'&& nick.charAt(0)<="~")){
		alert("´ëÈ­¸íÀº Æ¯¼ö¹®ÀÚ·Î ½ÃÀÛµÉ ¼ö ¾ø½À´Ï´Ù.\nÃ¹±ÛÀÚ°¡ ÇÑ±Û ¶Ç´Â ¿µ¹®ÀÌ¾î¾ß ÇÕ´Ï´Ù.");
		return false;
	}
	if(nick.length*han_flag> 8){
		alert("¼Õ´Ô ´ëÈ­¸íÀº ÇÑ±Û 4±ÛÀÚ, ¿µ¹® 5±ÛÀÚ¸¦ ÃÊ°úÇÒ¼ö ¾ø½À´Ï´Ù.");
		return false;
	}
	document.guest_form.submit();
	return true;
}
function memberLogin(){
	nick=document.login.USERID.value;
	SetCookie('REALNAME',nick,'','/','.echat.co.kr');
	if (nick.length<1){
		alert ("¾ÆÀÌµð¸¦ ÀÔ·ÂÇÏ¼¼¿ä.");
		document.login.USERID.focus();
		return false;
	}
	tmpstr=escape(nick);
	if (tmpstr.indexOf("%20")>=0) {
		alert("¾ÆÀÌµð¿¡ ºóÄ­(°ø¹é)À» ÀÔ·ÂÇÏ¼Ì½À´Ï´Ù.");
		return false;
	}
	if (document.login.USERPWD.value.length<1){
		alert ("ºñ¹Ð¹øÈ£¸¦ ÀÔ·ÂÇÏ¼¼¿ä ");
		document.login.USERPWD.focus();
		return false;
	}
	//document.login.submit();

	Saveid(document.login)

	return true;
}
function SetCookie (name,value,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

function setCookie (name, value, expires) {
	document.cookie = name + "=" + escape (value) + "; path=/; expires=" + expires.toGMTString();
}

function Saveid(form) {
	var expdate = new Date();
	// ±âº»ÀûÀ¸·Î 30ÀÏµ¿¾È ±â¾ïÇÏ°Ô ÇÔ. ÀÏ¼ö¸¦ Á¶ÀýÇÏ·Á¸é * 30¿¡¼­ ¼ýÀÚ¸¦ Á¶ÀýÇÏ¸é µÊ
	if (form.checksaveid.checked)
		expdate.setTime(expdate.getTime() + 1000 * 3600 * 24 * 30); // 30ÀÏ
	else
		expdate.setTime(expdate.getTime() - 1); // ÄíÅ° »èÁ¦Á¶°Ç
	setCookie("UserSaveid", form.USERID.value, expdate);
}

function Getid(form) {
	form.checksaveid.checked = ((form.USERID.value = getCookie("UserSaveid")) != "");
}


function setHome()
{
	if (IEVER>=5) {
		HOMEPAGE.setHomePage("http://www.echat.co.kr");
	}
	else {
		alert("ÀÌ ±â´ÉÀº ÀÍ½ºÇÃ·Î·¯ 5.0 ÀÌ»ó¸¸ °¡´ÉÇÕ´Ï´Ù.");
	}
}
function addbookmark() {
	if (document.all)
		window.external.AddFavorite("http://www.echat.co.kr","ÀÌÃª - ½Ç½Ã°£ Áõ±Ç Ä¿¹Â´ÏÆ¼")
}
function guest_input() {
	if (document.all.guest_enter.style.display=="none") {
		document.all.guest_enter.style.display='';
		document.guest_form.GUESTID.focus();
	}
	else {
		document.all.guest_enter.style.display='none';
	}
	return;
}
function enter_channel(channel,group){	
	login_gate();
}
function enter_free_channel(key){
	login_gate();
}
function enter_free_channel_s(key){
	login_gate();
}
function enter_free_channel_o(key){
	login_gate();
}
function enter_stock_channel(channel){
	login_gate();
}
function check_enter_channel(theForm){
	alert("·Î±×ÀÎ ÇÏ¼Å¾ß ÇÕ´Ï´Ù.");
	return false;
}
function set_pwd(val) {
	if (val == "open") {
		document.all.pwdDis.style.display="none";
		create_form.lockcode.value="";
		create_form.lockcode.disabled=true;
	}
	else if (val == "secret") {
		document.all.pwdDis.style.display="";
		create_form.lockcode.disabled=false;
	}
}
function check_code() {
	if (document.j_chat.code.value.length <1){
		alert ('Á¾¸ñ¸í È¤Àº ÄÚµå¸¦ ÀÔ·ÂÇÏ¼¼¿ä');
		return false;
	}
	return true;
}
function open_board (url){
	board = window.open(url, '_new', 'width=800,height=580,scrollbars=yes,toolbar=no,resizable=yes,left=0,top=0');
	board.focus();
}
function login_gate(){
	document.location='/php/login_gate.php3';
}
function goLogin(){
	var ret=memberLogin();
	if(ret==true){
		document.login.action='https://www.echat.co.kr/login/login_v2.php3';
		document.login.submit();
	}
	else return false;
}
