/* String.js */
String.prototype.checkFormat={email :{reg :/^[_\da-z-]+(:?\.[_\da-z-]+)*@[\da-z-]+(:?\.[\da-z-]+)*$/,min : 4,max : 80},password :{reg :/(?:^[_0-9a-zA-Z-]+$)/,min : 4,max : 12},name :{reg :/(?:[^'"]+$)/,min : 2,max : 20},categoryName :{reg :/(?:[^'"]+$)/,min : 1,max : 6},domain :{reg :/(?:^[0-9a-zA-Z-]+$)/,min : 4,max : 20},cellNumber : { reg : /\d{3}[-]?\d{3,4}[-]?\d{4}/, min : 10, max : 13}};
String.prototype.check=function(type){var fm=this.checkFormat[type];if(fm.reg){var result=this.match(fm.reg); if(!result||result[0]!=this)return false;}if(typeof fm.max!="undefined"&&fm.max<this.length)return false;if(typeof fm.min!="undefined"&&this.length<fm.min)return false;return true;};String.prototype.getByte=function(){var i;var strLen;var strByte;strLen=this.length;for(i=0,strByte=0;i<strLen;i++){if(this.charAt(i)>=' '&&this.charAt(i)<='~')strByte++;else strByte+=2;}return strByte;};String.prototype.replaceUrl=function(){if(this.search('http://')==-1)return "http://".concat(this);else return this;}
String.prototype.ltrim = function(){	var trimRe = /^\s*(.*)\s*$/;	return this.replace(trimRe, "$1");};
String.prototype.rtrim = function() {	return this.replace(/\s+$/,"");}
String.prototype.trim = function(){ return this.replace(/(^\s*)|(\s*$)/gi, "");};
String.prototype.stripTags = function(allowableTags){	var regExp = (allowableTags && allowableTags.length != 0)?"<\\/?(?!("+allowableTags.join('|')+"))\\b[^>]*>":"<\/?[^>]*>";	return this.replace(new RegExp(regExp, "gi"), "");}
String.prototype.ellipsis = function(maxLength, mark){		var strByte = 0;		for(var i=0; i < this.length; i++)		{			if(this.charAt(i) >= ' ' && this.charAt(i) <= '~' )			strByte++;			else			strByte += 2;			if(strByte >= maxLength)			return this.substr(0, i) + (mark ? mark : "...");		}    return this;};
String.prototype.replaceLink = function (){	if(this.indexOf("<a") != -1)		return this;    return this.replace(/(?:(http\:\/\/)|(www\.))+?([^<\s]*)/ig, "<a href='http://$2$3' target='_blank' class='linkUrl'>$1$2$3</a>");};
String.prototype.toLink = function(){		if(this.indexOf("http://") != -1)				return this;		return encodeURIComponent(("http://" + this));}
String.prototype.encode=function(){return encodeURIComponent(this);};String.prototype.decode=function(){return decodeURIComponent(this);};String.prototype.encodeSP=function(){var str=encodeURIComponent(this);str=str.replace(/\'/gi,"%27");str=str.replace(/\"/gi,"%22");return str;};String.prototype.password=function(){var sha1_input=function(message_array){var len,i;len=message_array.length&0xfffffffc;for(i=0;i<len;i+=4){this.message_block.push(((message_array.charCodeAt(i)<<8|message_array.charCodeAt(i+1))<<8|message_array.charCodeAt(i+2))<<8|message_array.charCodeAt(i+3));if(this.message_block.length==16)this.sha1processmessageblock();}switch(message_array.length&0x00000003){case 0: this.message_block.push(0x00000080<<24);break;case 1: this.message_block.push((message_array.charCodeAt(i)<<8|0x00000080)<<16);break;case 2: this.message_block.push(((message_array.charCodeAt(i)<<8|message_array.charCodeAt(i+1))<<8|0x00000080)<<8);break;case 3: this.message_block.push(((message_array.charCodeAt(i)<<8|message_array.charCodeAt(i+1))<<8|message_array.charCodeAt(i+2))<<8|0x00000080);break;}if(this.message_block.length>14){for(i=this.message_block.length;i<16;i++)this.message_block.push(0);this.sha1processmessageblock();}for(i=this.message_block.length;i<14;i++)this.message_block.push(0);this.message_block.push(message_array.length>>>29);this.message_block.push(message_array.length<<3);this.sha1processmessageblock();};var sha1processmessageblock=function(){var t,temp,w,a,b,c,d,e;w=new Array(80);for(t=0;t<16;t++)w[t]=this.message_block[t];for(t=16;t<80;t++)w[t]=circularshift(w[t-3]^w[t-8]^w[t-14]^w[t-16],1);a=this.intermediate_hash[0];b=this.intermediate_hash[1];c=this.intermediate_hash[2];d=this.intermediate_hash[3];e=this.intermediate_hash[4];for(t=0;t<20;t++){temp=circularshift(a,5)+((b&c)|(~b&d))+e+w[t]+0x5A827999;e=d;d=c;c=circularshift(b,30);b=a;a=temp;}for(t=20;t<40;t++){temp=circularshift(a,5)+(b^c^d)+e+w[t]+0x6ED9EBA1;e=d;d=c;c=circularshift(b,30);b=a;a=temp;}for(t=40;t<60;t++){temp=circularshift(a,5)+((b&c)|(b&d)|(c&d))+e+w[t]+0x8F1BBCDC;e=d;d=c;c=circularshift(b,30);b=a;a=temp;}for(t=60;t<80;t++){temp=circularshift(a,5)+(b^c^d)+e+w[t]+0xCA62C1D6;e=d;d=c;c=circularshift(b,30);b=a;a=temp;}this.intermediate_hash[0]+=a;this.intermediate_hash[1]+=b;this.intermediate_hash[2]+=c;this.intermediate_hash[3]+=d;this.intermediate_hash[4]+=e;this.message_block=new Array();};var sha1_result=function(){var i,message_digest="";for(i=0;i<5;i++){message_digest+=String.fromCharCode(this.intermediate_hash[i]>>>24&0x000000ff);message_digest+=String.fromCharCode(this.intermediate_hash[i]>>>16&0x000000ff);message_digest+=String.fromCharCode(this.intermediate_hash[i]>>>8&0x000000ff);message_digest+=String.fromCharCode(this.intermediate_hash[i]&0x000000ff);}return message_digest;};var circularshift=function(word,bits){return(word<<bits)|(word>>>(32-bits));};var octet2hex=function(str){var i,alpha,beta,to="";for(i=0;i<str.length;i++){alpha=str.charCodeAt(i);beta=alpha>>>4;if(beta<10)to+=String.fromCharCode(48+beta);else to+=String.fromCharCode(55+beta);beta=alpha&0x0000000f;if(beta<10)to+=String.fromCharCode(48+beta);else to+=String.fromCharCode(55+beta);}return to;};var sha1_reset=function(){this.message_block=new Array();this.intermediate_hash=new Array(5);this.intermediate_hash[0]=0x67452301;this.intermediate_hash[1]=0xEFCDAB89;this.intermediate_hash[2]=0x98BADCFE;this.intermediate_hash[3]=0x10325476;this.intermediate_hash[4]=0xC3D2E1F0;this.sha1_input=sha1_input;this.sha1processmessageblock=sha1processmessageblock;this.sha1_result=sha1_result;};var sha1_context,hash_stage2,to;if(this.length==0)return "";sha1_context=new sha1_reset();sha1_context.sha1_input(this);to=sha1_context.sha1_result();sha1_context=new sha1_reset();sha1_context.sha1_input(to);hash_stage2=sha1_context.sha1_result();to=octet2hex(hash_stage2);to="*"+to;return to;};
String.prototype.toUpperFirst=function(){		if(this.length == 0)				return this;		if(this.length == 1)				return this.toUpperCase();		return this.charAt(0).toUpperCase()+this.substring(1);}
String.prototype.toCellnumber = function(){
  var str = this.replace(/-/g,"");
  if(str.length==11)
    return str.substring(0,3)+"-"+str.substring(3,7)+"-"+str.substring(7);
  else if(str.length==10)
    return str.substring(0,3)+"-"+str.substring(3,6)+"-"+str.substring(6);
  else
    return this;
}

String.prototype.toEmail = function(){
	return '<a href="mailto:'+this+'">'+this+'</a>';
}

/* Base64.js */
var keyStr="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function encode64(input){if(!input) return; var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;do{chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64;}else if(isNaN(chr3)){enc4=64;}output=output+keyStr.charAt(enc1)+keyStr.charAt(enc2)+keyStr.charAt(enc3)+keyStr.charAt(enc4);}while(i<input.length);return output;}function decode64(input){if(!input) return; var output="";var chr1,chr2,chr3;var enc1,enc2,enc3,enc4;var i=0;input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{enc1=keyStr.indexOf(input.charAt(i++));enc2=keyStr.indexOf(input.charAt(i++));enc3=keyStr.indexOf(input.charAt(i++));enc4=keyStr.indexOf(input.charAt(i++));chr1=(enc1<<2)|(enc2>>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64){output=output+String.fromCharCode(chr2);}if(enc4!=64){output=output+String.fromCharCode(chr3);}}while(i<input.length);return output;}function encode64Han(str){return encode64(escape(str))}function decode64Han(str){return unescape(decode64(str))}

/* SHA1.js */
function SHA1(msg){function rotate_left(n,s){var t4=(n<<s)|(n>>>(32-s));return t4;};function lsb_hex(val){var str="";var i;var vh;var vl;for(i=0;i<=6;i+=2){vh=(val>>>(i*4+4))&0x0f;vl=(val>>>(i*4))&0x0f;str+=vh.toString(16)+vl.toString(16);}return str;};function cvt_hex(val){var str="";var i;var v;for(i=7;i>=0;i--){v=(val>>>(i*4))&0x0f;str+=v.toString(16);}return str;};function Utf8Encode(string){string=string.replace(/\r\n/g,"\n");var utftext="";for(var n=0;n<string.length;n++){var c=string.charCodeAt(n);if(c<128){utftext+=String.fromCharCode(c);}else if((c>127)&&(c<2048)){utftext+=String.fromCharCode((c>>6)|192);utftext+=String.fromCharCode((c&63)|128);}else{utftext+=String.fromCharCode((c>>12)|224);utftext+=String.fromCharCode(((c>>6)&63)|128);utftext+=String.fromCharCode((c&63)|128);}}return utftext;};var blockstart;var i,j;var W=new Array(80);var H0=0x67452301;var H1=0xEFCDAB89;var H2=0x98BADCFE;var H3=0x10325476;var H4=0xC3D2E1F0;var A,B,C,D,E;var temp;msg=Utf8Encode(msg);var msg_len=msg.length;var word_array=new Array();for(i=0;i<msg_len-3;i+=4){j=msg.charCodeAt(i)<<24|msg.charCodeAt(i+1)<<16|msg.charCodeAt(i+2)<<8|msg.charCodeAt(i+3);word_array.push(j);}switch(msg_len%4){case 0: i=0x080000000;break;case 1: i=msg.charCodeAt(msg_len-1)<<24|0x0800000;break;case 2: i=msg.charCodeAt(msg_len-2)<<24|msg.charCodeAt(msg_len-1)<<16|0x08000;break;case 3: i=msg.charCodeAt(msg_len-3)<<24|msg.charCodeAt(msg_len-2)<<16|msg.charCodeAt(msg_len-1)<<8|0x80;break;}word_array.push(i);while((word_array.length%16)!=14)word_array.push(0);word_array.push(msg_len>>>29);word_array.push((msg_len<<3)&0x0ffffffff);for(blockstart=0;blockstart<word_array.length;blockstart+=16){for(i=0;i<16;i++)W[i]=word_array[blockstart+i];for(i=16;i<=79;i++)W[i]=rotate_left(W[i-3]^W[i-8]^W[i-14]^W[i-16],1);A=H0;B=H1;C=H2;D=H3;E=H4;for(i=0;i<=19;i++){temp=(rotate_left(A,5)+((B&C)|(~B&D))+E+W[i]+0x5A827999)&0x0ffffffff;E=D;D=C;C=rotate_left(B,30);B=A;A=temp;}for(i=20;i<=39;i++){temp=(rotate_left(A,5)+(B^C^D)+E+W[i]+0x6ED9EBA1)&0x0ffffffff;E=D;D=C;C=rotate_left(B,30);B=A;A=temp;}for(i=40;i<=59;i++){temp=(rotate_left(A,5)+((B&C)|(B&D)|(C&D))+E+W[i]+0x8F1BBCDC)&0x0ffffffff;E=D;D=C;C=rotate_left(B,30);B=A;A=temp;}for(i=60;i<=79;i++){temp=(rotate_left(A,5)+(B^C^D)+E+W[i]+0xCA62C1D6)&0x0ffffffff;E=D;D=C;C=rotate_left(B,30);B=A;A=temp;}H0=(H0+A)&0x0ffffffff;H1=(H1+B)&0x0ffffffff;H2=(H2+C)&0x0ffffffff;H3=(H3+D)&0x0ffffffff;H4=(H4+E)&0x0ffffffff;}var temp=cvt_hex(H0)+cvt_hex(H1)+cvt_hex(H2)+cvt_hex(H3)+cvt_hex(H4);return temp.toLowerCase();}

/* Mys.js */
Mys = {};
Mys.getSafeArray = function (root){	if(!root)		return [];	return root.length ? root : [root];};
Mys.createCookie = function(name,value,days,hours,minutes,secs,domain) {	if (days) {		var date = new Date();		var time = 0;		if(secs)			time += secs;		if(minutes)			time += minutes*60;		if(hours)			time += hours*60*60;		if(days)			time += days*24*60*60;		date.setTime(date.getTime()+(time*1000));		var expires = "; expires="+date.toGMTString();	}	else var expires = "";	document.cookie = name+"="+value+expires+"; path=/"+((domain)?"; domain="+domain:"");}
Mys.readCookie = function(name) {	var nameEQ = name + "=";	var ca = document.cookie.split(';');	for(var i=0;i < ca.length;i++) {		var c = ca[i];		while (c.charAt(0)==' ') c = c.substring(1,c.length);		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);	}	return null;}
Mys.eraseCookie = function(name) {	Mys.createCookie(name,"",-1);}

/* Date.js */

Date.kDayNames = ["일요일", "월요일","화요일","수요일","목요일","금요일","토요일"];
Date.getFormatCode = function(character) {
	switch (character) {
	case "d":
		return "String.leftPad(this.getDate(), 2, '0') + ";
	case "D":
		return "Date.dayNames[this.getDay()].substring(0, 3) + ";
	case "j":
		return "this.getDate() + ";
	case "l":
		return "Date.dayNames[this.getDay()] + ";
	case "S":
		return "this.getSuffix() + ";
	case "w":
		return "this.getDay() + ";
	case "z":
		return "this.getDayOfYear() + ";
	case "W":
		return "this.getWeekOfYear() + ";
	case "Q":
		return "this.getWeekOfMonth() + ";
	case "F":
		return "Date.monthNames[this.getMonth()] + ";
	case "m":
		return "String.leftPad(this.getMonth() + 1, 2, '0') + ";
	case "M":
		return "Date.monthNames[this.getMonth()].substring(0, 3) + ";
	case "n":
		return "(this.getMonth() + 1) + ";
	case "t":
		return "this.getDaysInMonth() + ";
	case "L":
		return "(this.isLeapYear() ? 1 : 0) + ";
	case "Y":
		return "this.getFullYear() + ";
	case "y":
		return "('' + this.getFullYear()).substring(2, 4) + ";
	case "a":
		return "(this.getHours() < 12 ? 'am' : 'pm') + ";
	case "A":
		return "(this.getHours() < 12 ? 'AM' : 'PM') + ";
	case "g":
		return "((this.getHours() %12) ? this.getHours() % 12 : 12) + ";
	case "G":
		return "this.getHours() + ";
	case "h":
		return "String.leftPad((this.getHours() %12) ? this.getHours() % 12 : 12, 2, '0') + ";
	case "H":
		return "String.leftPad(this.getHours(), 2, '0') + ";
	case "i":
		return "String.leftPad(this.getMinutes(), 2, '0') + ";
	case "s":
		return "String.leftPad(this.getSeconds(), 2, '0') + ";
	case "O":
		return "this.getGMTOffset() + ";
	case "T":
		return "this.getTimezone() + ";
	case "Z":
		return "(this.getTimezoneOffset() * -60) + ";
	case "K":
		return "(this.getHours() < 12 ? '오전' : '오후') + ";
	case "E":
		return "Date.kDayNames[this.getDay()].substring(0, 1) + ";
	case "e":
		return "Date.kDayNames[this.getDay()] + ";
	default:
		return "'" + String.escape(character) + "' + ";
	}
};

Date.createParser = function(format) {
	var funcName = "parse" + Date.parseFunctions.count++;
	var regexNum = Date.parseRegexes.length;
	var currentGroup = 1;
	Date.parseFunctions[format] = funcName;

	var code = "Date." + funcName + " = function(input){\n"
		+ "var y = -1, m = -1, d = -1, h = -1, i = -1, s = -1;\n"
		+ "var d = new Date();\n"
		+ "y = d.getFullYear();\n"
		+ "m = d.getMonth();\n"
		+ "d = d.getDate();\n"
		+ "var results = input.match(Date.parseRegexes[" + regexNum + "]);\n"
		+ "if (results && results.length > 0) {";
	var regex = "";

	var special = false;
	var ch = '';
	for(var i = 0; i < format.length; ++i)
	{
		ch = format.charAt(i);
		if(!special && ch == "\\")
			special = true;
		else if (special)
		{
			special = false;
			regex += String.escape(ch);
		}
		else
		{
			var obj = Date.formatCodeToRegex(ch, currentGroup);
			currentGroup += obj.g;
			regex += obj.s;

			if(obj.g && obj.c)
				code += obj.c;
		}
	}


	code += "if(h >= 0 && typeof post != 'undefined')\n"
		+ "{ if(post) h += 12;"
		+ "else if(h == 12) h = 0;}"
		+ "if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0 && s >= 0)\n"
		+ "{return new Date(y, m, d, h, i, s);}\n"
		+ "else if (y > 0 && m >= 0 && d > 0 && h >= 0 && i >= 0)\n"
		+ "{return new Date(y, m, d, h, i);}\n"
		+ "else if (y > 0 && m >= 0 && d > 0 && h >= 0)\n"
		+ "{return new Date(y, m, d, h);}\n"
		+ "else if (y > 0 && m >= 0 && d > 0)\n"
		+ "{return new Date(y, m, d);}\n"
		+ "else if (y > 0 && m >= 0)\n"
		+ "{return new Date(y, m);}\n"
		+ "else if (y > 0)\n"
		+ "{return new Date(y);}\n"
		+ "}return null;}";

	Date.parseRegexes[regexNum] = new RegExp(regex);
	eval(code);
};

Date.formatCodeToRegex = function(character, currentGroup) {
	switch (character)
	{
	case "D":
		return {g:0,
		c:null,
		s:"(?:Sun|Mon|Tue|Wed|Thu|Fri|Sat)"};
	case "j":
	case "d":
		return {g:1,
			c:"d = parseInt(results[" + currentGroup + "], 10);\n",
			s:"(\\d{1,2})"};
	case "l":
		return {g:0,
			c:null,
			s:"(?:" + Date.dayNames.join("|") + ")"};
	case "S":
		return {g:0,
			c:null,
			s:"(?:st|nd|rd|th)"};
	case "w":
		return {g:0,
			c:null,
			s:"\\d"};
	case "z":
		return {g:0,
			c:null,
			s:"(?:\\d{1,3})"};
	case "W":
		return {g:0,
			c:null,
			s:"(?:\\d{2})"};
	case "F":
		return {g:1,
			c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "].substring(0, 3)], 10);\n",
			s:"(" + Date.monthNames.join("|") + ")"};
	case "M":
		return {g:1,
			c:"m = parseInt(Date.monthNumbers[results[" + currentGroup + "]], 10);\n",
			s:"(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)"};
	case "n":
	case "m":
		return {g:1,
			c:"m = parseInt(results[" + currentGroup + "], 10) - 1;\n",
			s:"(\\d{1,2})"};
	case "t":
		return {g:0,
			c:null,
			s:"\\d{1,2}"};
	case "L":
		return {g:0,
			c:null,
			s:"(?:1|0)"};
	case "Y":
		return {g:1,
			c:"y = parseInt(results[" + currentGroup + "], 10);\n",
			s:"(\\d{4})"};
	case "y":
		return {g:1,
			c:"var ty = parseInt(results[" + currentGroup + "], 10);\n"
				+ "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n",
			s:"(\\d{1,2})"};
	case "a":
		return {g:1,
			c:"var post = results[" + currentGroup + "] == 'am' ? false : true;\n",
			s:"(am|pm)"};
	case "A":
		return {g:1,
			c:"var post = results[" + currentGroup + "] == 'AM' ? false : true;\n",
			s:"(AM|PM)"};
	case "g":
	case "G":
	case "h":
	case "H":
		return {g:1,
			c:"h = parseInt(results[" + currentGroup + "], 10);\n",
			s:"(\\d{1,2})"};
	case "i":
		return {g:1,
			c:"i = parseInt(results[" + currentGroup + "], 10);\n",
			s:"(\\d{1,2})"};
	case "s":
		return {g:1,
			c:"s = parseInt(results[" + currentGroup + "], 10);\n",
			s:"(\\d{2})"};
	case "O":
		return {g:0,
			c:null,
			s:"[+-]\\d{4}"};
	case "T":
		return {g:0,
			c:null,
			s:"[A-Z]{3}"};
	case "Z":
		return {g:0,
			c:null,
			s:"[+-]\\d{1,5}"};

	case "K":
		return {g :1,
			c:"var post = results[" + currentGroup + "] == '오전' ? false : true;\n",
			s:"(오전|오후)"};
	case "E":
		return {g:0,
		c:null,
		s:"(?:일|월|화|수|목|금|토)"};
	case "e":
		return {g:0,
			c:null,
			s:"(?:" + Date.kDayNames.join("|") + ")"};
	case "B":
		return {g:0,
			c:null,
			s:"\\s*"};
	default:
		return {g:0,
			c:null,
			s:String.escape(character)};
	}
};

Date.parseTimeStr = function(str)
{
	var time = Date.parseDate(str, "KBh:i") ||
						 Date.parseDate(str, "aBh:i") ||
						 Date.parseDate(str, "ABh:i") ||
						 Date.parseDate(str, "H:i") ||
						 Date.parseDate(str, "KBh시Bi분") ||
						 Date.parseDate(str, "H시Bi분");

	return time;
};

Date.parseTimeSecondStr = function(str)
{
	var time = Date.parseDate(str, "KBh:i:s") ||
						 Date.parseDate(str, "aBh:i:s") ||
						 Date.parseDate(str, "ABh:i:s") ||
						 Date.parseDate(str, "H:i:s") ||
						 Date.parseDate(str, "KBh시Bi분Bs초") ||
						 Date.parseDate(str, "H시Bi분Bs초");

	return time;
};

Date.parseDateStr = function(str)
{
	var date = Date.parseDate(str, "Y/m/d") ||
						 Date.parseDate(str, "Y-m-d") ||
						 Date.parseDate(str, "Y.m.d") ||
						 Date.parseDate(str, "Y년Bm월Bd일");

	return date;
};

Date.parseString = function(dateStr, timeStr, hasSecond)
{
	if(!timeStr)
		var timeStr = dateStr;

	var date = Date.parseDateStr(dateStr);
	if(hasSecond)
		var time = Date.parseTimeSecondStr(timeStr);
	else
		var time = Date.parseTimeStr(timeStr);

	if(date && time)
	{
		date.setHours(time.getHours());
		date.setMinutes(time.getMinutes());
		date.setSeconds(time.getSeconds());
		date.hasTime = true;
	}

	return date;
}
// 두 date 객체를 입력 받아서 날짜까지만 같은지 판단하여 true, false를 반환한다.
// (주의!) 시간은 비교하지 않음.
Date.compareDate = function(date1, date2)
{
	if(typeof date1 == "string")
		date1 = Date.parseDateStr(date1);
	if(typeof date2 == "string")
		date2 = Date.parseDateStr(date2);

	if(!date1 || !date2)
		return false;

	if (date1.getFullYear() == date2.getFullYear() &&
			date1.getMonth() == date2.getMonth() &&
			date1.getDate() == date2.getDate())
				return true;

	return false;
};

Date.prototype.clearTime = function(clone)
{
	if(clone)
		return this.clone().clearTime();

	this.setHours(0);
	this.setMinutes(0);
	this.setSeconds(0);
	this.setMilliseconds(0);
	this.hasTime = false;

	return this;
};

Date.prototype.getWeekOfMonth = function()
{
	var firstDate = this.getFirstDateOfMonth();

	return this.getWeekOfYear() - firstDate.getWeekOfYear() + 1;
};



/* mysAsyncHttpRequest.js */
//Mys.AsyncHttpRequest=function(){this.init();this.requestPool={};this.formRequestPool={};};Mys.AsyncHttpRequest.prototype={serverURL:'/api/index.htm',fileServerURL:'/api/index.htm?model=util&mode=parse_phone_number&view=json',el:null,um:null,requestPool : null,scope:null,skipError : true,formRequestPool : null,formTID : 0,init : function(){this.el=document.createElement("DIV");this.um=new Ext.UpdateManager(this.el);this.um.indicatorText='<div class="loading-indicator"></div>';this.um.showLoadIndicator=true;this.um.on("update",this.onLoad,this);this.um.on("failure",this.onLoadException,this);},notting : function(){},setStateElement : function(elState){this.um.el=Ext.get(elState);},loadHTML : function(url,callback,scope,passData){this.um.update(url,"",this.onHTMLCallback.createDelegate(this));this.requestPool[this.um.transaction.tId]={scope : scope,callback : callback,passData : passData};},loadScripts : function(scripts,callback,scope,passData){scripts.count=0;for(var i=0;i<scripts.length;i++){this.um.update(scripts[i],"",this.onScriptsCallback.createDelegate(this));this.requestPool[this.um.transaction.tId]={scope : scope,callback : callback,passData : passData,scripts : scripts,number : i};}},request : function(param,callback,scope,internalCallback,intScope,passData){this.um.update(this.serverURL,param,this.onCallback.createDelegate(this));this.requestPool[this.um.transaction.tId]={scope : scope,passData : passData,callback : callback,intScope : intScope,internalCallback : internalCallback}},formRequest : function(form,reset,callback,scope){this.um.formUpdate(form,this.serverURL,reset,this.onFormCallback.createDelegate(this));this.formRequestPool={scope : scope,callback : callback}},fileRequest : function(param,callback,scope,internalCallback,intScope,passData){this.um.update(this.fileServerURL,param,this.onCallback.createDelegate(this));this.requestPool[this.um.transaction.tId]={scope : scope,passData : passData,callback : callback,intScope : intScope,internalCallback : internalCallback}},fileFormRequest : function(form,reset,callback,scope){this.um.formUpdate(form,this.fileServerURL,reset,this.onFormCallback.createDelegate(this));this.formRequestPool={scope : scope,callback : callback}},onFormCallback : function(el,bSuccess,response){var tr=this.formRequestPool;this.ftr=tr;if(!bSuccess)return;var data;try{data=Ext.util.JSON.decode(response.responseText);if(!data||data.response.code!=100&&!this.skipError){if(data&&data.response)alert(data.response.message);}}catch(e){window.status = "내부오류93:서버로부터 받은 데이타를 해석할 수 없습니다.응답결과="+response.responseText;return;}if(tr.internalCallback){var result=tr.internalCallback.call(tr.intScope,data,tr.passData,tr.callback,tr.scope);if(tr.callback&&result!==true){tr.callback.call(tr.scope,data,tr.passData);}}else{if(tr.callback)tr.callback.call(tr.scope,data);}},onCallback : function(el,bSuccess,response){var tr=this.requestPool[response.tId];this.tr=tr;if(!bSuccess)return;var data;try{data=Ext.util.JSON.decode(response.responseText);if(!data||data.response.code!=100&&!this.skipError){if(data&&data.response)alert(data.response.message);}}catch(e){window.status = "내부오류: 서버로부터 받은 데이타를 해석할 수 없습니다.";return;}if(tr.internalCallback){var result=tr.internalCallback.call(tr.intScope,data,tr.passData,tr.callback,tr.scope);if(tr.callback&&result!==true){tr.callback.call(tr.scope,data,tr.passData);}}else{if(tr.callback)tr.callback.call(tr.scope,data,tr.passData);}},onHTMLCallback : function(el,bSuccess,response){var tr=this.requestPool[response.tId];this.tr=tr;if(!bSuccess)return;var data=response.responseText;if(tr.callback)tr.callback.call(tr.scope,data,tr.passData);},onScriptsCallback : function(el,bSuccess,response){var tr=this.requestPool[response.tId];this.tr=tr;if(!bSuccess)return;tr.scripts[tr.number]=response.responseText;if(++tr.scripts.count==tr.scripts.length&&tr.callback){window.eval(tr.scripts.join("\n"));window.tr=tr;tr.callback.call(tr.scope,data,tr.passData);}},callback : function(){if(this.tr.callback)this.tr.callback.apply(this.tr.scope,arguments);this.um.el.hide();},onLoad : function(){this.um.el.setHeight(53);this.um.el.setWidth(162);this.um.el.center();this.um.el.setHeight(0);this.um.el.setWidth(0);this.um.el.update("");},onLoadException : function(){window.status = "서버에 연결할 수 없습니다.";}}












Mys.AsyncHttpRequest = function()
{
	this.init();
	this.requestPool = {};
	this.formRequestPool = {};
};


Mys.AsyncHttpRequest.prototype =
{
	serverURL:'/api/index.htm'
	,fileServerURL:'/api/index.htm?model=util&mode=parse_phone_number&view=json'
	,el:null
	,um:null
	,requestPool : null
	,scope:null
	,skipError : true // Error Msg 는 해당 소스에서 처리하도록..
	,formRequestPool : null
	,formTID : 0

	,init : function()
	{
		this.el = document.createElement("DIV"); // 나중에 이거 만들기

		this.um = new Ext.UpdateManager(this.el);
		this.um.indicatorText = '<div  class="loading-indicator"></div>';
		this.um.showLoadIndicator = true;

		this.um.on("update", this.onLoad, this);
		this.um.on("failure", this.onLoadException, this);
//		this.um.setRenderer(new Mys.Renderer);
	}
	,notting : function ()
	{
	}
	,setStateElement : function (elState)
	{
	    this.um.el = Ext.get(elState);
    }
	,loadHTML : function(url, callback, scope, passData)
	{
		this.um.update(url, "", this.onHTMLCallback.createDelegate(this));

		this.requestPool[this.um.transaction.tId] =
		{
			scope : scope,
			callback : callback,
			passData : passData
		};
	}
	,loadScripts : function(scripts, callback, scope, passData)
	{
		scripts.count = 0;

		for(var i = 0; i < scripts.length; i++)
		{
			this.um.update(scripts[i], "", this.onScriptsCallback.createDelegate(this));

			this.requestPool[this.um.transaction.tId] =
			{
				scope : scope,
				callback : callback,
				passData : passData,
				scripts : scripts,
				number : i
			};
		}
	}
	,request : function(param, callback, scope, internalCallback, intScope, passData)
	{
	    // update.el 이 한번 실행되면 스타일 적용이 안되서 매번 넣어줌.
	    /*
     	Ext.fly(this.um.el).setStyle( "position", "absolute");
       	Ext.fly(this.um.el).setStyle( "z-index", "1000");
    	Ext.fly(this.um.el).setStyle( "top", "10px");
        */

		this.um.update(this.serverURL, param, this.onCallback.createDelegate(this));

		//
		this.requestPool[this.um.transaction.tId] =
		{
			scope : scope,
			passData : passData,
			callback : callback,
			intScope : intScope,
			internalCallback : internalCallback
		}
	}

	,formRequest : function(form, reset, callback, scope)
	{
		this.um.formUpdate(form, this.serverURL, reset, this.onFormCallback.createDelegate(this));
		this.formRequestPool = {
			scope : scope,
			callback : callback
		}
	}

	,fileRequest : function(param, callback, scope, internalCallback, intScope, passData)
	{
		this.um.update(this.fileServerURL, param, this.onCallback.createDelegate(this));

		//
		this.requestPool[this.um.transaction.tId] =
		{
			scope : scope,
			passData : passData,
			callback : callback,
			intScope : intScope,
			internalCallback : internalCallback
		}
	}

	,fileFormRequest : function(form, reset, callback, scope)
	{
		this.um.formUpdate(form, this.fileServerURL, reset, this.onFormCallback.createDelegate(this));
		this.formRequestPool = {
			scope : scope,
			callback : callback
		}
	}

	,onFormCallback : function(el, bSuccess, response)
	{
		var tr = this.formRequestPool;
		this.ftr = tr;

		if (!bSuccess)
			return;

		var data;
		try
		{
			data = Ext.util.JSON.decode(response.responseText);

			if(!data || data.response.code != 100 && !this.skipError)
			{
				if(data && data.response)
					window.status = data.response.message;

				//return;
			}
		}
		catch(e)
		{
			window.status = "내부오류93:서버로부터 받은 데이타를 해석 할 수 없습니다.응답결과 = " + response.responseText;
			return;
		}

		if (tr.internalCallback)
		{
			var result = tr.internalCallback.call(tr.intScope, data, tr.passData, tr.callback, tr.scope);
			if (tr.callback && result !== true)
			{
				tr.callback.call(tr.scope, data, tr.passData);
			}
		}
		else
		{
			if (tr.callback)
				tr.callback.call(tr.scope, data);
		}
	}
	,onCallback : function(el, bSuccess, response)
	{
		var tr = this.requestPool[response.tId];
		this.tr = tr;

		if (!bSuccess)
			return;

		var data;
		try
		{
			data = Ext.util.JSON.decode(response.responseText);

			if(!data || data.response.code != 100 && !this.skipError)
			{
/*				var str = "";
				data.errors.error = typeof data.errors.error.length == "number" ? data.errors.error : [data.errors.error];

				for(var i = 0; i < data.errors.error.length; i++)
				{
					if(data.errors.error[i].level == "user")
						str += data.errors.error[i].message + "\n";
				}

				if(str)*/
				if(data && data.response)
					window.status = data.response.message;

				//return;
			}
		}
		catch(e)
		{
			window.status = "내부오류 : 서버로부터 받은 데이타를 해석 할 수 없습니다.";
			return;
		}

		if (tr.internalCallback)
		{
			var result = tr.internalCallback.call(tr.intScope, data, tr.passData, tr.callback, tr.scope);
			if (tr.callback && result !== true)
			{
				tr.callback.call(tr.scope, data, tr.passData);
			}
		}
		else
		{
			if (tr.callback)
				tr.callback.call(tr.scope, data, tr.passData);
		}
	}

	,onHTMLCallback : function(el, bSuccess, response)
	{
		var tr = this.requestPool[response.tId];
		this.tr = tr;

		if (!bSuccess)
			return;

		var data = response.responseText;

		if (tr.callback)
			tr.callback.call(tr.scope, data, tr.passData);
	}

	,onScriptsCallback : function(el, bSuccess, response)
	{
		var tr = this.requestPool[response.tId];
		this.tr = tr;

		if (!bSuccess)
			return;

		tr.scripts[tr.number] = response.responseText;

		if(++tr.scripts.count == tr.scripts.length && tr.callback)
		{
			window.eval(tr.scripts.join("\n"));
			window.tr = tr;
			tr.callback.call(tr.scope, data, tr.passData);
		}
	}
	,callback : function ()
	{
		if (this.tr.callback)
			this.tr.callback.apply(this.tr.scope, arguments);
		this.um.el.hide();

	}

	,onLoad : function()
	{
		this.um.el.setHeight(53);
		this.um.el.setWidth(162);
		this.um.el.center();
		this.um.el.setHeight(0);
		this.um.el.setWidth(0);
	    this.um.el.update("");
	}

	,onLoadException : function()
	{
		window.status = "서버에 연결할 수 없습니다.";
	}
}

/* mysModel.js */
Mys.Model=function(){};Ext.extend(Mys.Model,Ext.util.Observable,{ajax : new Mys.AsyncHttpRequest,setStateElement : function(elState){this.ajax.setStateElement(elState);},formRequest : function(form,reset,callback,scope){if(form.dom)form=form.dom;this.ajax.formRequest(form,reset,callback,scope);}});

/* Mys.Model.Session */
Mys.Model.Session = function()
{
	Mys.Model.Session.superclass.constructor.call(this);
};

Ext.extend(Mys.Model.Session, Mys.Model,
{
	getSession : function(id, callback, scope)
	{
		var query = "model=session&view=json&mode=get_session_key&user_id=" + id.encode();

		this.ajax.request(query, callback, scope);
	}

	,login : function(id, password, session_key, auto_login_day, callback, scope)
	{
		var login_key = SHA1(id+session_key+password.password());

		var query = "model=session&view=json&mode=login&login_key=" + login_key.encode() + "&auto_login_day=" + auto_login_day;

		this.ajax.request(query, callback, scope);
	}

	,loginWithNoEncode : function(id, password, session_key, auto_login_day, callback, scope)
	{
		var login_key = SHA1(id+session_key+password);

		var query = "model=session&view=json&mode=login&login_key=" + login_key.encode() + "&auto_login_day=" + auto_login_day;

		this.ajax.request(query, callback, scope);
	}
	
	,login_check : function(id, password, session_key, callback, scope)
	{
		var login_key = SHA1(id+session_key+password.password());

		var query = "model=session&view=json&mode=login_check&login_key=" + login_key.encode();

		this.ajax.request(query, callback, scope);
	}

	,logout : function(callback, scope)
	{
		var query = "model=session&view=json&mode=logout";

		this.ajax.request(query, callback, scope);
	}

});




/* Profile Model */

Mys.Model.Profile = function()
{
	Mys.Model.Profile.superclass.constructor.call(this);
};

Ext.extend(Mys.Model.Profile, Mys.Model,
{

	modify : function(id, name, phone_mobile, callback, scope)
	{
		var query = "model=profile&view=json&mode=modify_user&user_id=" + id.encode();
		
		if(name !== null)
		query += "&name=" + name.encode(); 
		
		if(phone_mobile !== null)
			query += "&phone_mobile=" + phone_mobile;

		this.ajax.request(query, callback, scope);
	}

});




Mys.Model.Sms = function()
{
	Mys.Model.Sms.superclass.constructor.call(this);
};

Ext.extend(Mys.Model.Sms, Mys.Model,
{
	GetSystemInquiry : function(start, limit, callback, scope)
	{
		var query = "model=sms&view=json&mode=get_campaign_status";

    if(start !== null)
      query+= "&start="+start;
    if(limit !== null)
      query+= "&limit="+limit;

		this.ajax.request(query, callback, scope);
	}

	,GetSystemInquiryDetail : function(campaign_id, callback, scope)
	{
		var query = "model=sms&view=json&mode=get_campaign_detail&campaign_id="+campaign_id;

		this.ajax.request(query, callback, scope);
	}

	,send : function(name, senddate, message, phone, callbackNum, description, callback, scope)
	{
	  var query = "model=sms&view=json&mode=send&name="+name+"&senddate="+senddate+"&message="+message.encode()+"&callback="+callbackNum;

	  if(phone instanceof Array)
	  for(i=0;i<phone.length;i++)
	   query +="&phone["+i+"]="+phone[i];

    if(description)
      query += "&description="+description.encode();
		this.ajax.request(query, callback, scope);
	}

  ,addUserMsg : function(class1, subclass, category, title, message, filepath, filepath_real, bPublic, tag, type, callback, scope)
  {
	  var query = "model=sms&view=json&mode=add_user_message&type="+type+"&message="+message.encodeSP()
	  				+"&public="+bPublic+"&title="+title.encodeSP()+"&class="+class1
	  				+"&sub_class="+subclass +"&category="+category;
	  
	  if(tag && tag.length != 0)
	  {
	  		for(var i = 0; i < tag.length; i++)
	  				query += "&tag_name["+i+"]="+tag[i].encodeSP();
	  }
	  
    if(filepath)
      query += "&filepath[0]="+filepath+"&filepath_real[0]="+filepath_real;

		this.ajax.request(query, callback, scope);
  }

	//($user_id, $id, $class, $sub_class, $category, $type, $public, $title, $message, $filepath, $filepath_real)
	
	,modifyUserMsg : function(user_id, id, subclass, category, title, public, tag, callback, scope)
  	{
		var query = "model=sms&view=json&mode=modify_user_message&id="+id
					+"&public="+public
					+"&category="+category
					+"&title="+title.encodeSP()
					+"&sub_class=" + subclass
					+"&user_id=" + user_id;
		
		if(tag && tag.length != 0)
		{
			for(var i = 0; i < tag.length; i++)
			query += "&tag_name["+i+"]="+tag[i].encodeSP();
		}
		
		this.ajax.request(query, callback, scope);
	}
  
	,getUserMsg : function(user_id, iclass, sub_class, category, type, start, limit, callback, scope)
	{
		var query = "model=sms&view=json&mode=get_user_message_list&start="+start+"&limit="+limit+"&type="+type;
	
		if(iclass)
			query += "&class="+iclass;
		if(category)
			query += "&category="+category;
		if(user_id)
			query += "&user_id="+user_id;
		if(sub_class)
			query += "&sub_class="+sub_class;
	
		this.ajax.request(query, callback, scope);
	}
	
	,getUserMsgByTag : function(tagName, user_id, type, start, limit, callback, scope)
	{
		var query = "model=tag&view=json&mode=get_user_message&start="+start+"&limit="+limit+"&tag_name="+tagName;
		
		if (type)
			query += "&type="+type;
		if(user_id)
			query += "&user_id="+user_id;
	
		this.ajax.request(query, callback, scope);
	}

  ,removeUserMsg : function(id, callback, scope)
  {
	  var query = "model=sms&view=json&mode=remove_user_message&id="+id;
		this.ajax.request(query, callback, scope);
  }

  ,getRecentPhoneList : function(callback, scope)
  {
	  var query = "model=sms&view=json&mode=get_recent_phone_list";
		this.ajax.request(query, callback, scope);
  }

	,fileFormsubmit : function(form, reset, callback, scope)
	{
		this.ajax.fileFormRequest(form, reset, callback, scope);
	}

	,formsubmit : function(form, reset, callback, scope)
	{
		this.ajax.formRequest(form, reset, callback, scope);
	}
});


Mys.Model.Addressbook = function()
{
	Mys.Model.Sms.superclass.constructor.call(this);
};

Ext.extend(Mys.Model.Addressbook, Mys.Model,
{
  getGroup : function(is_count, callback, scope)
  {
	  var query = "model=addrgroup&view=json&mode=get&is_count="+is_count;
		this.ajax.request(query, callback, scope);
  }

  ,getMember : function(addr_group_id, start, limit, is_count, callback, scope)
  {
	  var query = "model=addrmember&view=json&mode=get&start="+start+"&limit="+limit+"&is_count="+is_count;
	  if(addr_group_id)
  	  query += "&addr_group_id="+addr_group_id;
		this.ajax.request(query, callback, scope);
  }

  ,getMembers : function(addr_group_id, start, limit, is_count, find, searchType, searchWord, callback, scope)
  {
	  var query = "model=addrmember&view=json&mode=get&start="+start+"&limit="+limit+"&select_flag=1";
	  if(addr_group_id)
  	  query += "&addr_group_id="+addr_group_id;
	  
	  if(find)
  	  query += "&find="+find;
  	
    if(is_count)
  	  query += "&is_count="+is_count;
  	
  	if(searchType && searchWord)
  		query += "&search_type="+searchType+"&search_word="+searchWord;
  	
		this.ajax.request(query, callback, scope);
  }

  ,removeMember : function(addr_member_id, callback, scope)
  {
	  var query = "model=addrmember&view=json&mode=del&addr_member_id="+addr_member_id;
		this.ajax.request(query, callback, scope);
  }

  ,selectGroup : function(addr_group_id, callback, scope)
  {
	  var query = "model=addrgroup&view=json&mode=select&addr_group_id="+addr_group_id;
		this.ajax.request(query, callback, scope);
  }

	,selectGroupOnly : function(addr_group_id, callback, scope)
	{
	  var query = "model=addrgroup&view=json&mode=select_only&addr_group_id="+addr_group_id;
		this.ajax.request(query, callback, scope);
			
	}
			
  ,fastInput : function(addr_group_id, name, email1, phone_mobile, tag, callback, scope)
  {
	  var query = "model=addrmember&view=json&mode=add&name="+name+"&addr_group_id="+addr_group_id+"&phone_mobile="+phone_mobile;
	  if(email1)
  	  query += "&email1="+email1;
	  if(tag)
  	  query += "&tag="+tag;

		this.ajax.request(query, callback, scope, null, null, addr_group_id);
  }

	,addMember : function(form, callback, scope)
	{
		this.ajax.formRequest(form, false, callback, scope);
	}

  ,addGroup : function(title, color, callback, scope)
  {
	  var query = "model=addrgroup&view=json&mode=add&title="+title;
	  if(color)
  	  query += "&color="+color;
		this.ajax.request(query, callback, scope);
  }

	,modifyGroup : function(title, color, select_flag, default_flag, addr_group_id, callback, scope, index)
	{
		var query = "model=addrgroup&view=json&mode=modify&addr_group_id="+addr_group_id;
		
		if(title !== null)
				query += "&title="+title;
		
		if(color !== null)
				query += "&color="+color;
		
		if(select_flag !== null)
				query += "&select_flag="+select_flag;
		
		if(default_flag !== null)
				query += "&default_flag="+default_flag;
		
		this.ajax.request(query, callback, scope, null, null, index);
	}
			
  ,removeGroup : function(addr_group_id, callback, scope, index)
  {
	  var query = "model=addrgroup&view=json&mode=del&addr_group_id="+addr_group_id;
		this.ajax.request(query, callback, scope, null, null, index);
  }

	,removeAll : function(callback, scope)
	{
 		var query = "model=addrmember&view=json&mode=del_all";
 		
		this.ajax.request(query, callback, scope);			
	}
  /*,addGroup : function(addr_group_id, title, color, callback, scope)
  {
	  var query = "model=addrgroup&view=json&mode=modify&addr_group_id="+addr_group_id;
	  if(color)
  	  query += "&color="+color;
	  if(title)
  	  query += "&title="+title;
		this.ajax.request(query, callback, scope);
  }*/
});

Mys.Model.AddrConfig = function()
{
		Mys.Model.AddrConfig.superclass.constructor.call(this);
}

Ext.extend(Mys.Model.AddrConfig, Mys.Model, {
		modify : function(list_count, callback, scope)
		{
				var query = "model=addrconfig&view=json&mode=modify";
				
				if(list_count != null)
						query += "&list_count="+list_count;
				
				this.ajax.request(query, callback, scope);
		}
});


Mys.Model.Extfile = function()
{
	Mys.Model.Extfile.superclass.constructor.call(this);
};

Ext.extend(Mys.Model.Extfile, Mys.Model,
{
//올린 외부파일의 주소 가져오는 함수 is_count : 총카운트 가져올것인가?
  get : function(start, limit, is_count, callback, scope)
  {
	  var query = "model=tmpfile&view=json&mode=get_simple_file&start="+start+"&limit="+limit+"&is_count="+is_count;
		this.ajax.request(query, callback, scope);
  }

//외부파일 주소록에 등록
//addr_group_name=그룹 이름 (그룹이 없으면 생성, 색은 자동 선택)
  ,saveToAddress : function(addr_group_name, callback, scope)
  {
	  var query = "model=addrmember&view=json&mode=add_tmp_file&addr_group_name="+addr_group_name.encode();
		this.ajax.request(query, callback, scope);
  }

});

/* User Model */
Mys.Model.User = function()
{
	Mys.Model.User.superclass.constructor.call(this);
};

Ext.extend(Mys.Model.User, Mys.Model,
{
	getInfo : function(id, callback, scope)
	{
		var query = "model=user&view=json&mode=get&user_id=" + id.encode();

		this.ajax.request(query, callback, scope);
	}

	,checkID : function(id, callback, scope)
	{
		var query = "model=user&view=json&mode=check_id&user_id=" + id.encode();

		this.ajax.request(query, callback, scope);
	}

	,checkDomain : function(domain, callback, scope)
	{
		var query = "model=user&view=json&mode=check_domain&domain=" + domain.encode();

		this.ajax.request(query, callback, scope);
	}

	,checkName : function(name, callback, scope)
	{
		var query = "model=user&view=json&mode=check_name&name=" + name.encode();

		this.ajax.request(query, callback, scope);
	}

	,register : function(id, name, password, cryptCode, callback, scope)
	{
		var query = "model=user&view=json&mode=register&user_id=" + id.encode() + "&name=" + name.encode() + "&password=" + password.password() + "&crypt_code=" + (cryptCode ? cryptCode.encode() : "");

		this.ajax.request(query, callback, scope);
	}

	,modifyPassword : function(user_id, oldPassword, newPassword, callback, scope)
	{
		var query = "model=user&view=json&mode=modify&user_id="+user_id.encode()+"&old_password=" + oldPassword.password() + "&new_password=" + newPassword.password();

		this.ajax.request(query, callback, scope);
	}

	,findId : function(name , callback, scope){
		var query = "model=user&view=json&mode=find_Id&name=" + name.encode();
		this.ajax.request(query, callback, scope);
	}

	,findPassword : function(user_id , callback, scope){
		var query = "model=user&view=json&mode=find_password&user_id=" + user_id.encode();
		this.ajax.request(query, callback, scope);
	}
	
	,withdraw : function(user_id, reason, callback, scope){
		var query = "model=user&view=json&mode=withdraw&user_id=" + user_id.encode()+"&reason="+reason.encodeSP();
		this.ajax.request(query, callback, scope);			
	}

	,findUserId : function(name, callback, scope)
	{
		var query = "model=user&view=json&mode=find_user_id&name="+name.encode();

		this.ajax.request(query, callback, scope);
  }

	,sendAuthMail : function(callback, scope)
	{
			var query = "model=user&view=json&mode=send_validation_mail";
			
			this.ajax.request(query, callback, scope);
	}
});



Mys.Model.Mobile = function()
{
	Mys.Model.Mobile.superclass.constructor.call(this);
};

Ext.extend(Mys.Model.Mobile, Mys.Model,
{
	getKey : function(PhoneNumber, callback, scope)
	{
		var query = "model=mobile&view=json&mode=send_auth&phone_number	=" + PhoneNumber;
		this.ajax.request(query, callback, scope);
	}

	,confirmKey : function(key, callback, scope)
	{
		var query = "model=mobile&view=json&mode=confirm_auth&auth_key=" +key;
		this.ajax.request(query, callback, scope);
	}

	,getFreePoint : function(callback, scope)
	{
		var query = "model=mobile&view=json&mode=get_freesms_point";
		this.ajax.request(query, callback, scope);
	}

});


Mys.Model.TmpFile = function()
{
		Mys.Model.TmpFile.superclass.constructor.call(this);
};

Ext.extend(Mys.Model.TmpFile, Mys.Model,
{
		upload : function(form, callback, scope)
		{
				this.ajax.formRequest(form, false, callback, scope);
		}
});

Mys.Model.ExtAddr = function()
{
		Mys.Model.ExtAddr.superclass.constructor.call(this);
}

Ext.extend(Mys.Model.ExtAddr, Mys.Model,
{
		getExtAddr : function(id, password, site, callback, scope)
		{
				var query = "model=extaddr&mode=get_ext_addr&view=json&id="+id+"&pwd="+password+"&site="+site;
				
				this.ajax.request(query, callback, scope);
		}
});

/* Mys.Session */
Mys.Session = function(data)
{
	if(data)
		this.setLoginData(data);
};

Mys.Session.prototype =
{
	loginUserID : null,
	loginUserName : null,
	grade : null,

	setLoginData : function(data)
	{
		this.data = data;

		this.loginUserID = data.user_id;
		this.loginUserName = data.name;
		this.myDomain = data.mydomain;
		if (data.mylogo)
			this.myLogo = data.mylogo;
		this.grade = data.grade;
	},

	isLog : function()
	{
		return (typeof this.loginUserID == "string" && this.loginUserID.length > 0) ? true : false;
	},

	getID : function()
	{
		return this.loginUserID ? this.loginUserID : "";
	},

	getName : function()
	{
		return this.loginUserName ? this.loginUserName : "";
	},

	getGrade : function()
	{
		var grade = parseInt(this.grade);

		return (typeof grade == "number" && !isNaN(grade)) ? grade : 0;
	},

	getDomain : function()
	{
		return this.myDomain ? this.myDomain : "";
	}
};




Mys.Find = function()
{
	this.init();
}

Mys.Find.prototype = {
	init : function()
	{
		var findEl = Ext.get("findIdPw");
		this.idBoxEl = Ext.get("findIdForm");
		this.pwBoxEl = Ext.get("findPwForm");
		
		this.currentNaviEl = findEl.child("ul a.id");
		this.idBoxEl.dom.reset();
		this.pwBoxEl.dom.reset();
		
		findEl.select("ul a").on("click", this.onClickNavi, this);
		this.idBoxEl.on("submit", this.findId, this);
		this.pwBoxEl.on("submit", this.findPw, this);
		
		if(!Global.modelUser) Global.modelUser = new Mys.Model.User;
	},
	
	findId : function(evt, t)
	{
		var id = this.idBoxEl.dom.id;
		
		if(id.value == "")
		{
			alert("이름 또는 별명을 입력해주세요");
			id.focus();
			return;
		}
		
		Global.modelUser.findId(id.value, this.cbFindId, this);
	},
	
	cbFindId : function(data)
	{
		if(data.response.code != 100)
		{
			alert("데이터 전송 도중 문제가 발생하였습니다. 다시 시도해주시기 바랍니다");
			return;
		}
		
		var html = "";
		var user = data.response.user;
		for(var i = 0; i < user.length; i++)
		{
		
			html += "<p>"+user[i].user_id+"</p>";
		}
		
		var resultEl = this.idBoxEl.child(".result");
		
		resultEl.insertHtml("beforeEnd", html);
		resultEl.setStyle("display", "block");
	},
	
	findPw : function(evt, t)
	{
		var email = this.pwBoxEl.dom.email;
		
		if(email.value == "")
		{
			alert("이메일을 입력해주세요");
			email.focus();
			return;
		}
		
			Global.modelUser.findPassword(email.value, this.cbFindPw, this);
	},
	
	cbFindPw : function(data)
	{
		if(data.response.code != 100)
		{
			alert("데이터 전송 도중 문제가 발생하였습니다. 다시 시도해주시기 바랍니다");
			return;
		}
		
		alert("메일이 전송되었습니다");
		this.pwBoxEl.dom.reset();
	},
	
	onClickNavi : function(evt, t)
	{
		if(t.tagName == "IMG")
			t = t.parentNode;
			
		var el = Ext.get(t);
		var elClass = el.dom.className.replace("select", "").trim();
		
		if(elClass == "id")
		{
			this.idBoxEl.setStyle("display", "block");
			this.pwBoxEl.setStyle("display", "none");
		}
		else
		{
			this.pwBoxEl.setStyle("display", "block");
			this.idBoxEl.setStyle("display", "none");
		}
		
		this.currentNaviEl.removeClass("select");
		el.addClass("select");
		
		
		this.currentNaviEl = el;
	}
};




LoginBox = function(formEl, userID, callback, scope)
{
	this.form = formEl || Ext.get("loginForm");

  if(!this.form) return;
	this.userIDForm = Ext.get(this.form.dom.userId);
	this.userPWForm = Ext.get(this.form.dom.userPw);

	if(this.form.dom.saveEmail)
		this.chkSaveEmailEl = Ext.get(this.form.dom.saveEmail);

	//자동 로그인
	this.autoLoginDayEl = Ext.get(this.form.dom.autoLoginDay);
	if(this.autoLoginDayEl)
		this.autoLoginDayEl.on("click", this.alertAutoLogin, this);

	this.form.on("submit", this.login, this);

	///// 아이디 박스 컨트롤.
	this.userIDForm.on("blur", this.blurId, this);
	this.userPWForm.on("blur", this.blurPasswd, this);

	this.userIDForm.on("focus", this.focusId, this);
	this.userPWForm.on("focus", this.focusPasswd, this);

	if(this.userIDForm.getValue() != ""){
		this.form.dom.reset();
	}

	/* 이메일 저장 */
	var save_user_id = Mys.readCookie(this.saveEmail_cookieName);
	this.save_user_id = save_user_id;

	if(save_user_id)
	{
		this.userIDForm.dom.style.background = "#ffffff";
		this.userIDForm.dom.value = save_user_id;
	}
	if(this.chkSaveEmailEl)
		this.chkSaveEmailEl.dom.checked = true;

	var guestLoginEl = this.form.child(".btn_guestLogin");
	
	if(guestLoginEl)
	{
			guestLoginEl.on("click", this.guestLogin, this);
	}
	
	this.callback = callback;
	this.scope = scope;
};

LoginBox.prototype =
{
	form : null,
	saveEmail_cookieName : 'mgage_save_id',
	guestId : "guest@mgage.co.kr",
	guestPw : "*C614F3AF03181A2F5394B23E4EA6BB8866EA2F46",
	userIDForm : null,
	userPWForm : null,
	loginBtn : null,
	userID : null,

	alertAutoLogin : function(evt, t){
		if(t.checked){
			alert("브라우저를 닫더라도 로그인이 계속 유지될 수 있습니다.\n\n로그인 유지 기능을 사용할 경우 다음 접속부터는 로그인을 하실 필요가 없습니다. \n\n단 게임방, 학교 등 공공장소에서 이용시 개인정보가 유출될 수 있으니 꼭 로그아웃을 해주시기 바랍니다.");
			this.autoLoginDayEl.un("click", this.alertAutoLogin, this);
		}
	},
	
	guestLogin : function(evt, t){
			EXT_SESSION.modelSession.getSession(this.guestId, this.cbGuestLogin, this);
	},
	
	cbGuestLogin : function(data){
			EXT_SESSION.modelSession.loginWithNoEncode(this.guestId, this.guestPw, data.response.session_key, null, this.handleLogin, this);
	},
			
	focusId : function(){
		if(!this.userIDForm.dom.value)
			this.userIDForm.setStyle("background", "#FFFFFF");
	},

	focusPasswd : function(){
		if (!this.userPWForm.dom.value)
			this.userPWForm.setStyle("background", "#FFFFFF");
	},

	blurId : function(){
		if(!this.userIDForm.dom.value)
			this.userIDForm.setStyle("background", "#FFFFFF url('./images/bg_id.gif') no-repeat");
		else
			this.userIDForm.setStyle("background", "#FFFFFF");
	},

	blurPasswd : function(){
		if (!this.userPWForm.dom.value)
			this.userPWForm.setStyle("background", "url('./images/bg_pw.gif') no-repeat");
		else
			this.userPWForm.setStyle("background", "#FFFFFF");
	},

	login : function()
	{
		var value = this.userIDForm.getValue();				
		
		if (value != "kma")
		{	
			if(!value.check("email"))
			{
				alert("아이디는 이메일형식으로 입력해주세요.");
				return;
			}
		}
		
		if (value == "")
		{
			alert("아이디가 입력되지 않았습니다.\n먼저 아이디를 입력 바랍니다.");
			return;
		}

		var valuePw = this.userPWForm.getValue();
		if (valuePw == "")
		{
			alert("비밀번호가 입력되지 않았습니다.\n먼저 비밀번호를 입력 바랍니다.");
			return;
		}
		this.getSessionKey();
	},

	getSessionKey : function (){
		EXT_SESSION.modelSession.getSession(this.userIDForm.getValue(), this.cbGetSessionKey, this);
	},

	cbGetSessionKey : function (data) {
		if(!data || data.response.code != 100)
		{
			alert("입력하신 아이디 혹은 비밀번호가 일치하지 않습니다.");
			return;
		}

		autoLoginDay = "";

		if(this.autoLoginDayEl)
			autoLoginDay = this.autoLoginDayEl.dom.checked ? this.autoLoginDayEl.getValue() : "";

		EXT_SESSION.modelSession.login(this.userIDForm.getValue(), this.userPWForm.getValue().trim(), data.response.session_key, autoLoginDay, this.handleLogin, this);

	},

	handleLogin : function(data)
	{

		if(!data || data.response.code != 100){
			this.userIDForm.dom.focus();
			alert(data.response.message);
			return false;
		}
		if(this.callback){
			if(this.chkSaveEmailEl)
			{
				if(this.chkSaveEmailEl.dom.checked)
					Mys.createCookie(this.saveEmail_cookieName,this.userIDForm.getValue(),100);
				else
					Mys.eraseCookie(this.saveEmail_cookieName);
			}
			//this.userIDForm.dom.focus();
			this.callback.call(this.scope, data);
		}else
		{
			if(this.chkSaveEmailEl)
			{
				if(this.chkSaveEmailEl.dom.checked)
					Mys.createCookie(this.saveEmail_cookieName,this.userIDForm.getValue(),100);
				else
					Mys.eraseCookie(this.saveEmail_cookieName);
			}

			window.location.reload();
		}
	}
	,setFocus : function(){
		this.userIDForm.dom.focus();
	}
};


function showFindPopup(){
		var popupEl = Ext.get("findIdPw");
		
		if(!popupEl)
				return;
		
		popupEl.setStyle('display', 'block');
		
		if(!Global.ctrlFind) Global.ctrlFind = new Mys.Find;
}

function setPng24(obj) {
	obj.width=obj.height=1;
	obj.className=obj.className.replace(/\bpng24\b/i,'');
	obj.style.filter =
	"progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+ obj.src +"',sizingMethod='image');"
	obj.src='about:blank;';
	return '';

}

function sendAuthMail()
{
		if(!Global.modelUser) Global.modelUser = new Mys.Model.User;
		
		Global.modelUser.sendAuthMail(function(data){if(data.response.code != 100){alert("메일 전송 도중 문제가 발생하였습니다. 다시 시도해주세요"); return;} alert("인증 메일이 발송되었습니다"); return;});
}
function autoIframe(frameId)
{
	try
	{
		frame = document.getElementById(frameId);
		innerDoc = (frame.contentDocument) ? frame.contentDocument : frame.contentWindow.document;
		objToResize = (frame.style) ? frame.style : frame;
		frame.height = innerDoc.body.scrollHeight + 50;
	}
	catch(err)
	{
		window.status = err.message;
	}
}



/*******************/
/*   initialize    */
/*******************/
var EXT_SESSION = new Mys.Session();
EXT_SESSION.modelSession = new Mys.Model.Session();
if (typeof(LOGIN_DATA) != "undefined" && LOGIN_DATA)
{
	EXT_SESSION.setLoginData(LOGIN_DATA);
}
if(!Global) var Global = {};
if(!Global.modelSms) Global.modelSms = new Mys.Model.Sms;

Ext.onReady(function(){

  if(!LOG_USER_ID)  window.login = new LoginBox();

});




