﻿/* javascript load */
loadScript = function (src, dummy) {
	var js = document.getElementsByTagName('head')[0].appendChild(document
			.createElement('script'));
	js.type = 'text/javascript';
	js.charset = 'utf-8';
	js.src = src + (dummy ? '?dummy=' + dummy : '');
}

function numberCheck(t) {
	var pattern = /^[0-9]+$/;
	var val = t.value;
	if (val.length > 0 && !pattern.test(val)) {
		alert("숫자만 입력해주세요");
		t.value = val.substring(0,val.length-1);
		return 0;
	}
}

function innerNullValue(node) {
	for ( var i = 0; i < node.length; i++)
		if (!node[i].checked) {
			node[i].checked = "checked";
			node[i].value = "0";
		}

}

function valueCheck(p) {
	return (p.value == "" || p.value.length == 0) ? true : false;
}

function radioValueCheck(p) {
	var check = true;
	var count = 0;
	for(var i=0; i<p.length; i++){
		if(p[i].checked){
			count++;
		}
	}
	if(count>0) check = false;
	return check;
}

function getCookie(name){
	var nameOfCookie = name + "=";
    var x = 0;
    while ( x <= document.cookie.length ){
        var y = (x+nameOfCookie.length);
        if ( document.cookie.substring( x, y ) == nameOfCookie ) {
            if ( (endOfCookie=document.cookie.indexOf( ";", y )) == -1 ) {
                endOfCookie = document.cookie.length;
            }
            return unescape( document.cookie.substring( y, endOfCookie ) );
        }
        x = document.cookie.indexOf( " ", x ) + 1;
        if ( x == 0 )
        break;
    }
    return "";
}	

//$(function(){
//	gnbMenuSelect();
//})

gnbMenuSelect = function(){
	var pathName = window.location.pathname;
	var pathNameArr = pathName.split("/");
	var gnbIndex = pathNameArr.length;
	if(gnbIndex<3){
		gnbIndex = -1;
	} else if(gnbIndex>3){
		var r_path_name = pathNameArr[2];
		if(r_path_name=="intro"){
			gnbIndex = 0;
		}else if(r_path_name=="business"){
			gnbIndex = 1;
		}else if(r_path_name=="request"){
			gnbIndex = 2;
		}else if(r_path_name=="data"){
			gnbIndex = 3;
		}else if(r_path_name=="board"){
			gnbIndex = 4;
		}else if(r_path_name=="site"){
			gnbIndex = 5;
		}else if(r_path_name=="intranet"){
			gnbIndex = 6;
		}else{
			gnbIndex = -1;
		}
	}
	//alert("pathName : "+pathName+" pathNameArr : "+pathNameArr[pathNameArr.length-1].indexOf());
	$("#gnb li.s:eq("+gnbIndex+") div").css("display","block");
	
	$("#gnb li.s").mouseenter(function(){
		$("#gnb li.s").css("background","url(/images/common/bar_gnb.gif) no-repeat 0 0");
		$("#gnb li.s").find("div").css("display","none");
		$(this).css("background","none").find("div").css("display","block");
	}).find("div").trigger("click");
	
	$("#gnb li.s div").mouseleave(function(){
	 	$("#gnb li.s").css("background","url(/images/common/bar_gnb.gif) no-repeat 0 0");
		$("#gnb li.s").find("div").css("display","none");
		$("#gnb li.s:eq("+gnbIndex+") div").css("display","block");
	});
}
/* right quick menu moving */
function initMoving(target, position, topLimit, btmLimit) {
	if (!target)
		return false;
	var obj = target;
	obj.initTop = position;
	obj.topLimit = topLimit;
	obj.bottomLimit = document.documentElement.scrollHeight - btmLimit;
	obj.style.position = "absolute";
	obj.top = obj.initTop;
	obj.left = obj.initLeft;
	if (typeof (window.pageYOffset) == "number") {
		obj.getTop = function() {
			return window.pageYOffset;
		}
	} else if (typeof (document.documentElement.scrollTop) == "number") {
		obj.getTop = function() {
			return document.documentElement.scrollTop;
		}
	} else {
		obj.getTop = function() {
			return 0;
		}
	}
	if (self.innerHeight) {
		obj.getHeight = function() {
			return self.innerHeight;
		}
	} else if (document.documentElement.clientHeight) {
		obj.getHeight = function() {
			return document.documentElement.clientHeight;
		}
	} else {
		obj.getHeight = function() {
			return 500;
		}
	}
	obj.move = setInterval(function() {
		if (obj.initTop > 0) {
			pos = obj.getTop() + obj.initTop;
		} else {
			pos = obj.getTop() + obj.getHeight() + obj.initTop;
			//pos = obj.getTop() + obj.getHeight() / 2 - 15;
		}
		if (pos > obj.bottomLimit)
			pos = obj.bottomLimit;
		if (pos < obj.topLimit)
			pos = obj.topLimit;
		interval = obj.top - pos;
		obj.top = obj.top - interval / 3;
		obj.style.top = obj.top + "px";
	}, 30)
}

