//==============================================================================
//  SYSTEM      :  ÀáÁ¤ÆÇ Å©·Î½º ºê¶ó¿ìÀú Ajax¿ë ¶óÀÌºê·¯¸®
//  PROGRAM     :  XMLHttpRequest¿¡ ÀÇÇÑ ¼Û¼ö½Å°ü·Ã ÇÔ¼ö, UNNÀÇ AjaxÃ³¸® °ü·Ã ÀÚÃ¼ »ç¿ëÀÚÁ¤ÀÇ ÇÔ¼ö
//  FILE NAME   :  UnnAjax.js
//  CALL FROM   :  Ajax Å¬¶óÀÌ¾ðÆ®
//  AUTHER      :  Toshirou Takahashi http://jsgt.org/mt/01/
//  SUPPORT URL :  http://jsgt.org/mt/archives/01/000409.html
//  CREATE      :  2005.6.26
//  Last Edit	  : 2007.5.21
//  ////msg-URL    :  Çì´õ http://jsgt.org/ajax/ref/lib/////msg_head.htm
//  ////msg-URL    :  ÀÎÁõ   http://jsgt.org/mt/archives/01/000428.html
//  ////msg-URL    :  ºñµ¿±â 
//        http://allabout.co.jp/career/javascript/closeup/CU20050615A/index.htm
//  ////msg-URL    :  SQL     http://jsgt.org/mt/archives/01/000392.html
//------------------------------------------------------------------------------
// ÃÖ½Å Á¤º¸   : http://jsgt.org/mt/archives/01/000409.html 
//¡Ø Prototype.js 1.5.1¹öÁ¯ ÃÖÁ¾±âÁØÇÏ¿© ÀÛ¾÷ÇÔ.
//

	////
	// µ¿ÀÛ°¡´ÉÇÑ ºê¶ó¿ìÀú ÆÇÁ¤
	//
	// @sample        if(chkAjaBrowser()){ location.href='nonajax.htm' }
	// @sample        oj = new chkAjaBrowser();if(oj.bw.safari){ /* Safari ÄÚµå */ }
	// @return        ¶óÀÌºê·¯¸®°¡ µ¿ÀÛ°¡´ÉÇÑ ºê¶ó¿ìÀú¸¸ true  true|false
	//
	//  Enable list (v038ÇöÀç)
	//   WinIE 5.5+ 
	//   Konqueror 3.3+
	//   AppleWebKit°è(Safari,OmniWeb,Shiira) 124+ 
	//   Mozilla°è(Firefox,Netscape,Galeon,Epiphany,K-Meleon,Sylera) 20011128+ 
	//   Opera 8+ 
	//

	function chkAjaBrowser()
	{
		var a,ua = navigator.userAgent;
		this.bw= { 
		  safari    : ((a=ua.split('AppleWebKit/')[1])?a.split('(')[0]:0)>=124 ,
		  konqueror : ((a=ua.split('Konqueror/')[1])?a.split(';')[0]:0)>=3.3 ,
		  mozes     : ((a=ua.split('Gecko/')[1])?a.split(" ")[0]:0) >= 20011128 ,
		  opera     : (!!window.opera) && ((typeof XMLHttpRequest)=='function') ,
		  msie      : (!!window.ActiveXObject)?(!!createHttpRequest()):false 
		}
		return (this.bw.safari||this.bw.konqueror||this.bw.mozes||this.bw.opera||this.bw.msie)
	}
	

	////
	// XMLHttpRequest ¿ÀºêÁ§Æ® »ý¼º
	//
	// @sample        oj = createHttpRequest()
	// @return        XMLHttpRequest ¿ÀºêÁ§Æ®(ÀÎ½ºÅÏ½º)
	//
	function createHttpRequest()
	{
		if(window.ActiveXObject){
			 //Win e4,e5,e6¿ë
			try {
				return new ActiveXObject("Msxml2.XMLHTTP") ;
			} catch (e) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP") ;
				} catch (e2) {
					return null ;
	 			}
	 		}
		} else if(window.XMLHttpRequest){
			 //Win Mac Linux m1,f1,o8 Mac s1 Linux k3¿ë
			return new XMLHttpRequest() ;
		} else {
			return null ;
		}
	}
	
	////
	// ¼Û¼ö½Å ÇÔ¼ö
	//
	// @sample         sendRequest(onloaded,'&prog=1','POST','./about2.php',true,true)
	// @param callback ¼Û¼ö½Å½Ã¿¡ ±âµ¿ÇÏ´Â ÇÔ¼ö ÀÌ¸§
	// @param data	   ¼Û½ÅÇÏ´Â µ¥ÀÌÅÍ (&ÀÌ¸§1=°ª1&ÀÌ¸§2=°ª2...)
	// @param method   "POST" ¶Ç´Â "GET"
	// @param url      ¿äÃ»ÇÏ´Â ÆÄÀÏÀÇ URL
	// @param async	   ºñµ¿±â¶ó¸é true µ¿±â¶ó¸é false
	// @param sload	   ¼öÆÛ ·Îµå true·Î °­Á¦¡¢»ý·«¶Ç´Â false´Â ±âº»
	// @param user	   ÀÎÁõ ÆäÀÌÁö¿ë »ç¿ëÀÚ ÀÌ¸§
	// @param password ÀÎÁõ ÆäÀÌÁö¿ë ¾ÏÈ£
	//
	function sendRequest(callback,data,method,url,async,sload,user,password)
	{
		//XMLHttpRequest ¿ÀºêÁ§Æ® »ý¼º
		var oj = createHttpRequest();
		if( oj == null ) return null;
		
		//°­Á¦ ·ÎµåÀÇ ¼³Á¤
		var sload = (!!sendRequest.arguments[5])?sload:false;
		if(sload || method.toUpperCase() == 'GET')url += "?";
		if(sload)url=url+"t="+(new Date()).getTime();
		
		//ºê¶ó¿ìÀú ÆÇÁ¤
		var bwoj = new chkAjaBrowser();
		var opera	  = bwoj.bw.opera;
		var safari	  = bwoj.bw.safari;
		var konqueror = bwoj.bw.konqueror;
		var mozes	  = bwoj.bw.mozes ;

		//¼Û½Å Ã³¸®
		//opera´Â onreadystatechange¿¡ Áßº¹ ÀÀ´äÀÌ ÀÖÀ» ¼ö ÀÖ¾î onload°¡ ¾ÈÀü
		//Moz,FireFox´Â oj.readyState==3¿¡¼­µµ ¼ö½ÅÇÏ¹Ç·Î º¸ÅëÀº onload°¡ ¾ÈÀü
		//Win ie¿¡¼­´Â onload°¡ µ¿ÀÛÇÏÁö ¾Ê´Â´Ù
		//KonquerorÀº onload°¡ ºÒ¾ÈÁ¤
		//Âü°í http://jsgt.org/ajax/ref/////msg/response/responsetext/try1.php
		if(opera || safari || mozes){
			oj.onload = function () { callback(oj); }
		} else {
		
			oj.onreadystatechange =function () 
			{
				if ( oj.readyState == 4 ){
					callback(oj);
				}
			}
		}

		//URL ÀÎÄÚµù
		//data = uriEncode(data)
		if(method.toUpperCase() == 'GET') {
			url += data
		}
		
		//open ¸Þ¼Òµå
		oj.open(method,url,async,user,password);

		//Çì´õ application/x-www-form-urlencoded ¼³Á¤
		setEncHeader(oj)

		//µð¹ö±×
//		if (method.toUpperCase() == 'POST')
//		//alert("////jslb_ajaxxx.js//// \n data:"+data.substr(1);+" \n method:"+method+" \n url:"+url+" \n async:"+async);
//		else
//		//alert("////jslb_ajaxxx.js//// \n data:"+data+" \n method:"+method+" \n url:"+url+" \n async:"+async);
		
		//send ¸Þ¼Òµå

		if(method.toUpperCase() == 'POST') 
		{
			data = data.substr(1);
			oj.send(data);
		}
        else //GET
		{
			oj.send("");
		}

		//URI ÀÎÄÚµù Çì´õ ¼³Á¤
		function setEncHeader(oj){
	
			//Çì´õ application/x-www-form-urlencoded ¼³Á¤
			// @see  http://www.asahi-net.or.jp/~sd5a-ucd/rec-html401j/interact/forms.html#h-17.13.3
			// @see  #h-17.3
			//   ( enctypeÀÇ ±âº»°ªÀº "application/x-www-form-urlencoded")
			//   h-17.3¿¡ ÀÇÇØ¡¢POST/GET »ó°ü¾øÀÌ ¼³Á¤
			//   POST¿¡¼­ "multipart/form-data"À» ¼³Á¤ÇÒ ÇÊ¿ä°¡ ÀÖ´Â °æ¿ì¿¡´Â Ä¿½ºÅÍ¸¶ÀÌÁî ÇØÁÖ¼¼¿ä.
			//
			//  ÀÌ ¸Þ¼Òµå°¡ Win Opera8.0¿¡¼­ ¿¡·¯°¡ ³ª¹Ç·Î ºÐ±â(8.01Àº OK)
			var contentTypeUrlenc = 'application/x-www-form-urlencoded; charset=UTF-8';
			if(!window.opera){
				oj.setRequestHeader('Content-Type',contentTypeUrlenc);
			} else {
				if((typeof oj.setRequestHeader) == 'function')
					oj.setRequestHeader('Content-Type',contentTypeUrlenc);
			}	
			return oj
		}

		//URL ÀÎÄÚµù
		function uriEncode(data){

			if(data!=""){
				//&¿Í=·Î ÀÏ´Ü ºÐÇØÇØ¼­ encode
				var encdata = '';
				var datas = data.split('&');
				for(i=1;i<datas.length;i++)
				{
					var dataq = datas[i].split('=');
					encdata += '&'+encodeURIComponent(dataq[0])+'='+encodeURIComponent(dataq[1]);
				}
			} else {
				encdata = "";
			}
			return encdata;
		}


		return oj
	}

  /*
' ------------------------------------------------------------------
   Visual Effects °ü·Ã...S
' ------------------------------------------------------------------
*/

	//
	// One-shot Effects
	//
	function highlight(o_id) {
		if ($(o_id))
//			Fat.fade_element(o_id, null, 800, '#2FFFFF');
					Fat.fade_element(o_id, null, 800, '#2FFFFF','#F7F7F7');
	}
	
	function fadeout(o_id) {
		if ($(o_id)) {
			opacity(o_id, 100, 0, 500);
		}
	}
	
	function displaynone(o_id) {
		var seq = o_id.substring(4);
		
		$("_cmt" + seq).style.display = 'none';
		if ($("_cmt_line" + seq)) {
			$("_cmt_line" + seq).style.display = 'none';
			$("_cmt_reply" + seq).style.display = 'none';
		}
	}

function makeArray(n) {
	this.length = n ;
	for (var i = 1 ; i <= n ; i++) {
		this[i] = 0 }
		return this
}

var fadeNewLine = function(div_name)
{
	$(div_name).bgColor = colors[y] ;

	var colors = new makeArray(16);
	colors[0] = "#000000" ;
	colors[1] = "#111111" ;
	colors[2] = "#222222" ;
	colors[3] = "#333333" ;
	colors[4] = "#444444" ;
	colors[5] = "#555555" ;
	colors[6] = "#666666" ;
	colors[7] = "#777777" ;
	colors[8] = "#888888" ;
	colors[9] = "#999999" ;
	colors[10] = "#aaaaaa" ;
	colors[11] = "#bbbbbb" ;
	colors[12] = "#cccccc" ;
	colors[13] = "#dddddd" ;
	colors[14] = "#eeeeee" ;
	colors[15] = "#ffffff" ;

	var y = 0;
	if (y < 16) {
		y++ ;
		setTimeout("fadeNewLine("+div_name+","+y+")", 30) ; /* The 100 can be changed to set the speed (in ticks) */
	}

}

//
//	Yellow Fade Techniques, Fade in/out 
//	by likejazz
//

// @name      The Fade Anything Technique
// @namespace http://www.axentric.com/aside/fat/
// @version   1.0-RC1
// @author    Adam Michela

var Fat = {
	make_hex : function (r,g,b) 
	{
		r = r.toString(16); if (r.length == 1) r = '0' + r;
		g = g.toString(16); if (g.length == 1) g = '0' + g;
		b = b.toString(16); if (b.length == 1) b = '0' + b;
		return "#" + r + g + b;
	},
	fade_all : function ()
	{
		var a = document.getElementsByTagName("*");
		for (var i = 0; i < a.length; i++) 
		{
			var o = a[i];
			var r = /fade-?(\w{3,6})?/.exec(o.className);
			if (r)
			{
				if (!r[1]) r[1] = "";
				if (o.id) Fat.fade_element(o.id,null,null,"#"+r[1]);
			}
		}
	},
	fade_element : function (id, fps, duration, from, to) 
	{
		if (!fps) fps = 30;
		if (!duration) duration = 3000;
		if (!from || from=="#") from = "#FFFF33";
		if (!to) to = this.get_bgcolor(id);
		
		var frames = Math.round(fps * (duration / 1000));
		var interval = duration / frames;
		var delay = interval;
		var frame = 0;
		
		if (from.length < 7) from += from.substr(1,3);
		if (to.length < 7) to += to.substr(1,3);
		
		var rf = parseInt(from.substr(1,2),16);
		var gf = parseInt(from.substr(3,2),16);
		var bf = parseInt(from.substr(5,2),16);
		var rt = parseInt(to.substr(1,2),16);
		var gt = parseInt(to.substr(3,2),16);
		var bt = parseInt(to.substr(5,2),16);
		
		var r,g,b,h;
		while (frame < frames)
		{
			r = Math.floor(rf * ((frames-frame)/frames) + rt * (frame/frames));
			g = Math.floor(gf * ((frames-frame)/frames) + gt * (frame/frames));
			b = Math.floor(bf * ((frames-frame)/frames) + bt * (frame/frames));
			h = this.make_hex(r,g,b);
		
			setTimeout("Fat.set_bgcolor('"+id+"','"+h+"')", delay);

			frame++;
			delay = interval * frame; 
		}
		setTimeout("Fat.set_bgcolor('"+id+"','"+to+"')", delay);
	},
	set_bgcolor : function (id, c)
	{
		var o = document.getElementById(id);
		o.style.backgroundColor = c;
	},
	get_bgcolor : function (id)
	{
		var o = document.getElementById(id);
		while(o)
		{
			var c;
			if (window.getComputedStyle) c = window.getComputedStyle(o,null).getPropertyValue("background-color");
			if (o.currentStyle) c = o.currentStyle.backgroundColor;
			if ((c != "" && c != "transparent") || o.tagName == "BODY") { break; }
			o = o.parentNode;
		}
		if (c == undefined || c == "" || c == "transparent") c = "#FFFFFF";
		var rgb = c.match(/rgb\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)/);
		if (rgb) c = this.make_hex(parseInt(rgb[1]),parseInt(rgb[2]),parseInt(rgb[3]));
		return c;
	}
}

//
// Cross-browser BlendTrans Filter Javascript, Fade in/out
//
function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";

	if (opacity == 0) displaynone(id);
}

// Callback function
function displaynone(id) {}
//
// Cross-browser BlendTrans Filter Javascript, Fade in/out
//
  /*
' ------------------------------------------------------------------
   Visual Effects °ü·Ã...E
' ------------------------------------------------------------------
*/
