/*==========================================================
	ÆÄÀÏ¸í		:common.js
	ÆÄÀÏ¼³¸í		:ajax¿¡¼­ »ç¿ëµÇ´Â °øÅëÇÔ¼öµé
	Á¦  ÀÛ		:
==========================================================*/

var ns = (document.layers)? true:false;
var ie = (document.all)? true:false;
var doc = (ie)? document.all : document;

function getObject(objectId) {
    // checkW3C DOM, then MSIE 4, then NN 4. 
    // 
    if(document.getElementById && document.getElementById(objectId)) {
        return document.getElementById(objectId);
    }   
    else if (document.all && document.all(objectId)) {
        return document.all(objectId);
    }
    else if (document.layers && document.layers[objectId]) {
        return document.layers[objectId];
    }
    else{
        return false; 
    }
} 
    
/**     
  * ÀÔ·Â °ªÀÌ Object ÀÎÁö¸¦ ¹ÝÈ¯.
  * returns true if a is an object, and array, or a function.
  * It returns false if a is a string, a number, a boolean, or null, or undefined.
  */ 
function isObject(input) { 
        return (input && typeof input == 'object') || isFunction(input);
} 
 
/**     
  * ÀÔ·Â °ªÀÌ Function ÀÎÁö¸¦ ¹ÝÈ¯.
  */ 
function isFunction(input) {
        return typeof input == 'function';
}


/***********************************************************
	ÇÔ¼ö¸í		:func_paging(ÃÑ°Ô½Ã¹°¼ö)
	Ã³¸®³»¿ë		:ÆäÀÌÂ¡¿ë ÇÔ¼ö
***********************************************************/
function func_paging(totalcnt ,keywordMode , sidebarMode , searchDivMode){
	var totpages = Math.ceil(totalcnt/LISTUNIT); //ÃÑÆäÀÌÁö¼ö
	var thisblock = Math.ceil(THISPAGE/PAGEUNIT); //ÇöÀç ÆäÀÌÂ¡ºí·°
	var startpage, endpage;
	var ret_HTML = "";
	
	// ÇöÀç ÆäÀÌÁöºí·°ÀÇ ½ÃÀÛÆäÀÌÁö¹øÈ£
	if(thisblock > 1){
		startpage = (thisblock-1)*PAGEUNIT+1;
	}else{
		startpage = 1;
	}
	
	// ÇöÀç ÆäÀÌÁöºí·°ÀÇ ³¡ÆäÀÌÁö¹øÈ£
	if( (thisblock*PAGEUNIT) >= totpages ){
		endpage = totpages;
	}else{
		endpage = thisblock*PAGEUNIT;
	}
	
	//alert("[keywordMode]:"+keywordMode+"/[sidebarMode]:"+sidebarMode+"[searchDivMode]:"+searchDivMode);
	//ript:act_pongdang_list(1,'keyword','sidebar','search_Div');">
	
	ret_HTML = "<table border=0 cellpadding=0 cellspacing=0 width=350 >";	
	ret_HTML += "<TR>";
	ret_HTML += "  <TD align='center'  >";
	if(THISPAGE > 1){
		ret_HTML += "  [<A onclick=act_pongdang_list(1,'"+keywordMode+"','"+sidebarMode+"','"+searchDivMode+"'); style='cursor:hand;'><B>&lt;&lt;</B></A>]"; // ¸ÇÃ³À½À¸·Î °¡±â
		ret_HTML += "  [<A onclick=act_pongdang_list("+(THISPAGE-1)+",'"+keywordMode+"','"+sidebarMode+"','"+searchDivMode+"'); style='cursor:hand;'><B>&lt;</B></A>]"; // ÇöÀçºí·°ÀÇ ÀüÆäÀÌÁö
	}
	for(i=startpage; i<=endpage; i++){
		if(i!=THISPAGE){
			ret_HTML += " <A onclick=act_pongdang_list("+i+",'"+keywordMode+"','"+sidebarMode+"','"+searchDivMode+"'); style='cursor:hand;'>"+i+"</A>";
			
			//ret_HTML += " <A onclick=javascript:alert('" + sidebarMode + "');>"+i+"</A>";
			
		}else{
			ret_HTML += " <B>"+i+"</B>";
		}
	}
	
	if(THISPAGE != totpages){
		ret_HTML += "  [<A onclick=act_pongdang_list("+(THISPAGE+1)+",'"+keywordMode+"','"+sidebarMode+"','"+searchDivMode+"'); style='cursor:hand;'><B>&gt;</B></A>]"; // ÇöÀçºí·°ÀÇ ´ÙÀ½ÆäÀÌÁö
		ret_HTML += "  [<A onclick=act_pongdang_list("+totpages+",'"+keywordMode+"','"+sidebarMode+"','"+searchDivMode+"'); style='cursor:hand;'><B>&gt;&gt;</B></A>]"; // ¸Ç ¸¶Áö¸·ÆäÀÌÁö
	}
	ret_HTML += "  </TD>";
	ret_HTML += "</TR>";
	ret_HTML += "</TABLE>";
	
	return ret_HTML;
}





/***********************************************************
	ÇÔ¼ö¸í		:func_getPaging(ÃÑ°Ô½Ã¹°¼ö)
	Ã³¸®³»¿ë		:ÆäÀÌÂ¡¿ë ÇÔ¼ö
***********************************************************/
function func_getPaging(totalcnt){
	var total_pages = Math.ceil(totalcnt/LISTUNIT); //ÃÑÆäÀÌÁö¼ö
	var this_block = Math.ceil(THISPAGE/PAGEUNIT); //ÇöÀç ÆäÀÌÂ¡ºí·°
	var start_page, end_page;
	var pg_HTML = "";
	
	// ÇöÀç ÆäÀÌÁöºí·°ÀÇ ½ÃÀÛÆäÀÌÁö¹øÈ£
	if(this_block > 1){
		start_page = (this_block-1)*PAGEUNIT+1;
	}else{
		start_page = 1;
	}
	
	// ÇöÀç ÆäÀÌÁöºí·°ÀÇ ³¡ÆäÀÌÁö¹øÈ£
	if( (this_block*PAGEUNIT) >= total_pages ){
		end_page = total_pages;
	}else{
		end_page = this_block*PAGEUNIT;
	}
	
	pg_HTML = "<table border=0 cellpadding=0 cellspacing=0 width=350 >";	
	pg_HTML += "<TR>";
	pg_HTML += "  <TD align='center'  >";
	//alert(THISPAGE);
	if(THISPAGE > 1){
		pg_HTML += "  [<A onclick='act_list(1);' style='cursor:hand;'><B>&lt;&lt;</B></A>]"; // ¸ÇÃ³À½À¸·Î °¡±â
		pg_HTML += "  [<A onclick='act_list("+(THISPAGE-1)+");' style='cursor:hand;'><B>&lt;</B></A>]"; // ÇöÀçºí·°ÀÇ ÀüÆäÀÌÁö
	}
	for(z=start_page; z<=end_page; z++){
		if(z!=THISPAGE){
			pg_HTML += " <A onclick='act_list("+z+");' style='cursor:hand;'>"+z+"</A>";
			
		}else{
			pg_HTML += " <B>"+z+"</B>";
		}
	}
	
	if(THISPAGE != total_pages){
		pg_HTML += "  [<A onclick='act_list("+(THISPAGE+1)+");' style='cursor:hand;'><B>&gt;</B></A>]"; // ÇöÀçºí·°ÀÇ ´ÙÀ½ÆäÀÌÁö
		pg_HTML += "  [<A onclick='act_list("+total_pages+");' style='cursor:hand;'><B>&gt;&gt;</B></A>]"; // ¸Ç ¸¶Áö¸·ÆäÀÌÁö
	}
	pg_HTML += "  </TD>";
	pg_HTML += "</TR>";
	pg_HTML += "</TABLE>";
	
	return pg_HTML;
}





/***********************************************************
	ÇÔ¼ö¸í		:newXMLHttpRequest()
	Ã³¸®³»¿ë		:¿äÃ»°´Ã¼¸¦ »ý¼ºÈÄ ¹ÝÈ¯
***********************************************************/
// function from http://www-128.ibm.com/developerworks/kr/library/j-ajax1/index.html
function newXMLHttpRequest() {
	var xmlreq = false;
	if (window.XMLHttpRequest) {
		// Create XMLHttpRequest object in non-Microsoft browsers
		xmlreq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		// Create XMLHttpRequest via MS ActiveX
		try {
			// Try to create XMLHttpRequest in later versions
			// of Internet Explorer
			xmlreq = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e1) {
			// Failed to create required ActiveXObject
			try {
				// Try version supported by older versions
				// of Internet Explorer
				xmlreq = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				// Unable to create an XMLHttpRequest with ActiveX
			}
		}
	}
	return xmlreq;
}

function divShow(layer){
	var dLayer=document.getElementById(layer);
	dLayer.style.display='';
}
function divHidden(layer){
	var dLayer=document.getElementById(layer);
	dLayer.style.display='none';
}

//ÆË¾÷À» À§ÇÑ ÄíÅ°Ã£±â
function setCookie( name, value, expiredays ) { 
	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate() + expiredays);
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
} 

function getCookie(name) { 
	var Found = false 
	var start, end 
	var i = 0 	 
	while(i <= document.cookie.length) { 
		start = i 
		end = start + name.length 
		
	if(document.cookie.substring(start, end) == name) { 
			Found = true 
			break
		} 	i++ 
	}  
	if(Found == true) { 
		start = end + 1 
		end = document.cookie.indexOf(";", start) 
		if(end < start) 
			end = document.cookie.length 
	
		return document.cookie.substring(start, end)
	}	
	return "" 
}

/** À½¼º È÷µç, ºä */
function showSound(){
	var soundView;

	if(document.getElementById("soundTR1").style.display == "none") {
		document.getElementById("soundTR1").style.display = "block";
		document.getElementById("soundTR2").style.display = "none";
		soundView = "Y";
	} else {
		document.getElementById("soundTR1").style.display = "none";
		document.getElementById("soundTR2").style.display = "block";
		soundView = "N";
	}

	/** À½¼º UI Èùµç ¿©ºÎ¸¦ ÄíÅ°¿¡ ÀúÀå. */
	setCookie("SOUND_VIEW_YN_C", soundView , 1);
}

/** »ç¿îÆ® Æû È÷µç ¿©ºÎ */
window.onload = function() {
	if(document.getElementById("soundTR1") != null) {
		if(getCookie("SOUND_VIEW_YN_C") == "Y") {
			document.getElementById("soundTR1").style.display = "block";
			document.getElementById("soundTR2").style.display = "none";
		} else {
			document.getElementById("soundTR1").style.display = "none";
			document.getElementById("soundTR2").style.display = "block";
		}
	}
}