var ee;

/*#########################################################################
# Return   :
# Comment  : 즐겨찾기에 추가하기
###########################################################################*/
function bookmark(title,url)
{
	if (window.sidebar){ // firefox
		window.sidebar.addPanel(title, url, "");
	}
	else if(window.opera && window.print){// opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all){// ie
		window.external.AddFavorite(url, title);
	}
}



function moreSearch(obj, type){
	window.clearTimeout(ee);
	if(type) obj.style.display = "block";
	else obj.style.display = "none";
}
function displaySearch(type) {
	var obj = document.getElementById("searchpop");

	if(obj.style.display == "none") obj.style.display = "block";
	else	ee = window.setTimeout(function(){obj.style.display = "none";},300);
}
function setSearchPopColor(obj, type) {
	if(type == "1"){
		obj.style.backgroundColor='#EFEFEF';
	}else{
		obj.style.backgroundColor='#FFFFFF'
	}
	moreSearch(document.getElementById("searchpop"),true);
}
function _search_value(type, type_name){
	var frm = document.search;
	var obj = document.getElementById("type_name");
	var ttext = document.getElementById(type_name).innerHTML;
	obj.innerHTML = ttext;
	frm.type.value = type;
	moreSearch(document.getElementById("searchpop"),false);
}

function goNSearch3(target) {
	var form = eval('document.search');

	if(form.qu.value == '') {
		alert('검색어를 입력해 주세요.');
		form.qu.focus();
		return false;
	}

	var filter = /([\<.]script[\>.])+(\w*)([\(]?)([\"|\']?)(\w*)([\"|\']*)([\)]?)([;]?)([\<.][\/.]script[\>.])+/;

	if(filter.test(form.qu.value)) {
		form.qu.value = '';
		return;
	}

	form.target = '_top';


	var url = "/search/";

	var type = form.type.value;
	var qu = encodeURIComponent(form.qu.value);
	//var qu = form.qu.value;

	location.href = url + "?" + "type=" + type + "&qu=" + qu;
}
/*#########################################################################
# Args :
	str => 문자열

# Return :  string ( 공백을 제거한 문자열을 리턴)

# comment : 문자열을 받아서 공백을 제거
###########################################################################*/

function trim(str){
	try{
			if(str == '') return '';
    var len = str.length;
    for(i = (len - 1); (str.charAt(i) == ' ')||(str.charAt(i) == '\n'); i--);
    str = str.substring(0, i + 1);

    var len2 = str.length;
    for(j = 0; str.charAt(j) == ' '; j++);
    str = str.substring(j, len2);
	} catch (e) {
		str = '';
	}
    return str;
}

function removeListBox() {
	var autokeyword_div = document.getElementById("autokeyword_div");
	autokeyword_div.style.display = "none";
}

function XMLHTTP() {
	try	{
		xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
	}
	catch(e) {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}

function navigateView(){
	setTimeout("removeListBox()", 150);
}


function toKorean(str) {
    return str.replace(reg_exp,replace);
}

function replace(str,h,b,f) {
    return String.fromCharCode(en_h.indexOf(h)*21*28 + en_b[b]*28 + en_f[f] + 44032);
}

function snbpop_show(){
	_show = arguments[0] ? arguments[0] : "";
	var plusImg = "/images/main2009/btn_more.gif";
	var minusImg = "/images/main2009/btn_more01.gif";

	if($('#snbpop').is(':hidden')){
		document.getElementById('more_button').src=minusImg;
		$('#snbpop').show();
	}else{
		if(_show == '1'){
			document.getElementById('more_button').src=plusImg;
			$('#snbpop').hide();
		}
	}
}
function snbpop_show2(){
	var plusImg = "/images/main2009/btn_more.gif";
	var minusImg = "/images/main2009/btn_more01.gif";

	if($('#snbpop').is(':hidden')){
		document.getElementById('more_button').src=minusImg;
		$('#snbpop').show();
	}else{
		document.getElementById('more_button').src=plusImg;
		$('#snbpop').hide();
	}
}

function site_map_show(){
	var plusImg = "/images/common/bullet/2009_bul_arrow08.gif";
	var minusImg = "/images/common/bullet/2009_bul_arrow07.gif";

	if($('#site_map_tab').is(':hidden')){
		document.getElementById('site_map_button').src=minusImg;
		$('#site_map_tab').show();
		$('#site_map_theme_list').show();
		site_map_tab('theme');
	}else{
		document.getElementById('site_map_button').src=plusImg;
		$('#site_map_tab').hide();
		$('#site_map_theme_list').hide();
		$('#site_map_kndata_list').hide();
	}
}

function site_map_tab(target){
	$('#site_map_tab li:first-child').removeClass();		
	$('#site_map_tab li:last-child').removeClass();		

	if (target == "theme") {	
		$('#site_map_tab li:first-child').addClass('selected');		
		$('#site_map_tab li:last-child').addClass('off');		
		$('#site_map_theme_list').show();
		$('#site_map_kndata_list').hide();
	} else {
		$('#site_map_tab li:last-child').addClass('selected');		
		$('#site_map_tab li:first-child').addClass('off');		
		$('#site_map_kndata_list').show();
		$('#site_map_theme_list').hide();
	}

}

function family_move(val)
{
	if( val == "" ) return false;
	else window.open(val, "FamilySite");
}

// 하단 공통 영역 : 이메일 무단 수집거부
function email_collection_refuse(thisValue){
	var url = '/inc/email_collection_refuse.html';

	var divx = getAbsX(thisValue) - 100;
	var divy = getAbsY(thisValue) - 100;
	setX(document.getElementById('email_gather'), divx);
	setY(document.getElementById('email_gather'), divy);

	sendRequest(
		load_email_coll_refuse,
		'',
		'POST',	url,
		true, true
	)
}

function load_email_coll_refuse(oj){
	var res  =  oj.responseText;
	document.getElementById("email_gather").innerHTML = res;
	viewLayer('email_gather');
}

function select_section(){
	_no = arguments[0] ? arguments[0] : "";
	for(i=0; i < 5; i++){
		$('#tab_'+i).removeClass();
		$('#text_'+i).removeClass();
		$('#contens_data_'+i).hide();
		if(i != _no){
			if(i == 0){
				$('#tab_'+i).addClass('data_tab_off');
			}else if(i == 1){
				$('#tab_'+i).addClass('data_tab_off01');
			}else{
				$('#tab_'+i).addClass('data_tab_off02');
			}
			$('#text_'+i).addClass('tab_text_off');
		}
	}
	if(_no==0){
		$('#tab_'+_no).addClass('data_tab_on');
	}else if(_no==1){
		$('#tab_'+_no).addClass('data_tab_on01');
	}else{
		$('#tab_'+_no).addClass('data_tab_on02');
	}
	$('#text_'+_no).addClass('tab_text_on');
	$('#contens_data_'+_no).show();
}

function select_request(){
	_no = arguments[0] ? arguments[0] : "";
	for(i=0; i < 2; i++){
		$('#request_tab_'+i).removeClass();
		$('#request_text_'+i).removeClass();
		$('#request_'+i).hide();
		if(i != _no){
			if(i == 0){
				$('#request_tab_'+i).addClass('data_tab_off');
			}else{
				$('#request_tab_'+i).addClass('data_tab_off');
			}
			$('#request_text_'+i).addClass('tab_text_off');
		}
	}
	if(_no!=0){
		$('#request_tab_'+_no).addClass('data_tab_on');
	}else{
		$('#request_tab_'+_no).addClass('data_tab_on');
	}
	$('#request_text_'+_no).addClass('tab_text_on');
	$('#request_'+_no).show();
}

function login_check(){
	if($('#id_check').val() == '0'){
		$('#id').val('');
		$('#id_check').val('1');
	}
	if(!$('#snbpop').is(':hidden')){
		$('#snbpop').hide();
	}
}
var ii = 0;
var wrap = 0;
var timeout_a = "";
var type = "";
function select_brand_div_call_a(){
	_no = arguments[0] ? arguments[0] : "";
	wrap = ii = _no;
	for(i=0; i < 14; i++){
		document.getElementById("brand_"+i).style.display = "none";
	}

	document.getElementById("brand_"+_no).style.display = "block";
}
function stop_brand_div_call(type) {
	if(type == "a"){
		window.clearTimeout(timeout_a);
	}else if(type == "b"){
		window.clearTimeout(timeout_b);
	}else{
		window.clearTimeout(timeout_c);
	}
}
function restart_brand_div_call(type) {
	if(type == "a"){
		timeout_a = window.setTimeout("show_brand_div_call()", 5000);
	}else if(type == "b"){
		timeout_b = window.setTimeout("show_brand_div_call_b()", 5000);
	}else{
		timeout_c = window.setTimeout("show_brand_div_call_c()", 5000);
	}
}
function go_prv() {
	wrap = ii;
	document.getElementById("brand_"+wrap).style.display = "none";
	ii--;
	if(ii == -1) {
		ii = 13;
	}
	document.getElementById("brand_"+ii).style.display = "block";
}
function go_next(type) {
	if(type == "a"){
		show_brand_div_call();
		window.clearTimeout(timeout_a);
	}else if(type == "b"){
		show_brand_div_call_b();
		window.clearTimeout(timeout_b);
	}else{
		show_brand_div_call_c();
		window.clearTimeout(timeout_c);
	}
}
//show_brand_div_call_b();


function show_brand_div_call(){
	wrap = ii;
	document.getElementById("brand_"+wrap).style.display = "none";
	ii++;
	if(ii == 14) {
		ii = 0;
	}
	document.getElementById("brand_"+ii).style.display = "block";
	timeout_a = window.setTimeout("show_brand_div_call()", 5000);
}



var ii_c = 0;
var wrap_c = 0;
var timeout_c = "";
function show_brand_div_call_c(){

	wrap_c = ii_c;
	document.getElementById("brand_c_"+wrap_c).style.display = "none";
	ii_c++;
	if(ii_c == 6) {
		ii_c = 0;
	}
	document.getElementById("brand_c_"+ii_c).style.display = "block";
	timeout_c = window.setTimeout("show_brand_div_call_c()", 5000);
}

function select_brand_div_call_c(){
	_no = arguments[0] ? arguments[0] : "";
	wrap_c = ii_c = _no;
	for(i=0; i < 6; i++){
		document.getElementById("brand_c_"+i).style.display = "none";
	}
	document.getElementById("brand_c_"+_no).style.display = "block";
}

function go_prv_c() {
	wrap_c = ii_c;
	document.getElementById("brand_c_"+wrap_c).style.display = "none";
	ii_c--;
	if(ii_c == -1) {
		ii_c = 5;
	}
	document.getElementById("brand_c_"+ii_c).style.display = "block";
}




function rq_write_go() {
	var f = document.rq_write;
	if(f.title.value=="") {
		alert("요청글의 제목을 입력해주세요.");
		f.title.focus();
		return false;
	}
	f.submit();
}

// popup div 위치 결정함수
var ll = document.layers;

function getAbsX(el)
{
	if (el.x) return el.x;

	pos = 0;

	while (el != null) {
		pos += el["offsetLeft"];
		el = el.offsetParent;
	}

	if(document) {
		if(document.body.scrollWidth > document.body.offsetWidth)
			sw = document.body.scrollWidth;
		else
			sw = document.body.offsetWidth;

		if(pos+200 > sw)
			pos = sw-350;
	} else {
		if( pos > 670 )
			pos = 670;
	}

	return pos;
}

function getAbsY(el)
{
	if (el.y) return el.y;
	pos = 0;

	while (el != null) {
		pos += el["offsetTop"];
		el = el.offsetParent;
	}
	return pos;
}

function setX(el, x)
{
	ll?el.left=x:el.style.left=x;
}

function setY(el, y)
{
	ll?el.top=y:el.style.top=y;
}

function viewLayer(layerName) {

	var layer = document.getElementById(layerName);
	layer.style.display="block";
}


/**
*
* @(#) getCookie(cookieName)
*
* @comment  쿠키값 가져오기
* @date     2007.04.30
* @author   Minji.Jung
* @type     script
* @param
*		cookieName		:	쿠키명
* @return   void
*
**/
function getCookie( cookieName )
{
	var cookie = document.cookie;
    var _prefix = cookieName + "=";
	var _begin = cookie.indexOf(_prefix);
	if( _begin > -1 ) {
		var _end = cookie.indexOf(';', _begin);
		if( _end == -1 )
			_end = cookie.length;
		return unescape( cookie.substring( _begin+_prefix.length, _end ) );
	} else {
		return false;
	}
}

/**
*
* @(#) setCookie(cookieName, cookieValue, expireday)
*
* @comment  쿠키세팅
* @date     2007.04.30
* @author   Minji.Jung
* @type     script
* @param
*		cookieName		:	쿠키명
*		cookieValue		:	쿠키값
*		expireday		:	쿠키만료일(1:1일 / 2:2일.... )
* @return   void
*
**/
function setCookie( cookieName, cookieValue, expireday )
{
    var todayDate = new Date();
    todayDate.setDate( todayDate.getDate() + expireday );
    document.cookie = cookieName + '=' + escape( cookieValue ) + '; path=/; domain=.happycampus.com; expires=' + todayDate.toGMTString() + ';';
}
function saveId()
{
	var _expireday = -1;
	if( document.getElementById('saveIdChk').checked == true ){
		_expireday = 30;
		var _id = document.getElementById('id').value;
		setCookie('happySaveID', _id , _expireday);
	}else{
		setCookie('happySaveID', _id , -1);
	}
}

function saveIdCheck()
{
	if( $('#id') ) {
		var _saveId = getCookie('happySaveID');
		if( _saveId ) {
			document.getElementById('saveIdChk').checked = true;
			$('#id').val(_saveId);
			$('#id').css({'color':'#333333'});
			$('#id_check').val('1');
		}
	}
}

