/*********************************************** 
* Bookmark site script- ⓒ Dynamic Drive DHTML code library (www.dynamicdrive.com) 
* This notice MUST stay intact for legal use 
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code 
***********************************************/

String.prototype.ltrim = function() {
	var re = /\s*((\S+\s*)*)/;
	return this.replace(re, "$1");
}
 
String.prototype.rtrim = function() {
	var re = /((\s*\S+)*)\s*/;
	return this.replace(re, "$1");
}
 
String.prototype.trim = function() {
	return this.ltrim().rtrim();
}


String.prototype.number_format=function(){
return this.replace(/(\d)(?=(?:\d{3})+(?!\d))/g,'$1,');
}
function number_format( number, decimals, dec_point, thousands_sep ) {
    var n = number, prec = decimals, dec = dec_point, sep = thousands_sep;
    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);
    sep = sep == undefined ? ',' : sep;

    var s = n.toFixed(prec),
        abs = Math.abs(n).toFixed(prec),
        _, i;

    if (abs > 1000) {
        _ = abs.split(/\D/);
        i = _[0].length % 3 || 3;

        _[0] = s.slice(0,i + (n < 0)) +
            _[0].slice(i).replace(/(\d{3})/g, sep+'$1');

        s = _.join(dec || '.');
    } else {
        s = abs.replace('.', dec_point);
    }

    return s;
}

function getByteLength(s){
   var len = 0;
   if ( s == null ) return 0;
   for(var i=0;i<s.length;i++){
      var c = escape(s.charAt(i));
      if ( c.length == 1 ) len ++;
      else if ( c.indexOf("%u") != -1 ) len += 2;
      else if ( c.indexOf("%") != -1 ) len += c.length/3;
   }
   return len;
}

function setCookie(cookieName, cookieValue, expires, path, domain, secure) {
    document.cookie =
        escape(cookieName) + '=' + escape(cookieValue)
        + (expires ? '; expires=' + expires.toGMTString() : '')
        + (path ? '; path=' + path : '')
        + (domain ? '; domain=' + domain : '')
        + (secure ? '; secure' : '');
};

function getCookie(cookieName) {
    var cookieValue = '';
    var posName = document.cookie.indexOf(escape(cookieName) + '=');
    if (posName != -1) {
        var posValue = posName + (escape(cookieName) + '=').length;
        var endPos = document.cookie.indexOf(';', posValue);
        if (endPos != -1) cookieValue = unescape(document.cookie.substring(posValue, endPos));
        else cookieValue = unescape(document.cookie.substring(posValue));
    }   
    return (cookieValue);
};      

/* Modified to support Opera */ 
function bookmarksite(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 tmpLineFocus(obj,val,cnt) {
	//var obj = form.use_same_time;
	for(var i=1;i<=cnt;i++) {
		var str = val+"_"+i; 
		if(obj[i-1].checked) {
			$(str).className = "text_bg_sky";               
		} else {
			$(str).className = "";
		}
	}
}

/* del select multi options */
function delMultiOptions(objBox) {
	var boxLength = objBox.length;
	
	arrSelected = new Array();
	var count = 0;
	for (i = 0; i < boxLength; i++) {
		if (objBox.options[i].selected) {
			arrSelected[count] = objBox.options[i].value;
		} 
		count++;
	}   
	var x;
	for (i = 0; i < boxLength; i++) {
		for (x = 0; x < arrSelected.length; x++) {
			if (objBox.options[i].value == arrSelected[x]) {
				objBox.options[i] = null;
			}
		}
		boxLength = objBox.length;
   }
}

/* ip zone control */
function addIP(form,ipstr,iparea,ipaddr) {
	
	var objBox = $(iparea);
	var boxLength = objBox.length;
		
	var ip1 = ipstr+"_1";
	var ip2 = ipstr+"_2";
	var ip3 = ipstr+"_3";
	var ip4 = ipstr+"_4";
	if (isEmpty($(ip1).value))
	{
		alert(commonjs_input_addip);
		$(ip1).focus();
		return;
	}  
	if (isEmpty($(ip2).value) && (!isEmpty($(ip3).value) || !isEmpty($(ip4).value)) )
	{
		alert(commonjs_invalid_ip_zone);
		$(ip1).focus();
		return;
	}
	if (!isEmpty($(ip2).value) && isEmpty($(ip3).value) && !isEmpty($(ip4).value) )
    {                       
        alert(commonjs_invalid_ip_zone);
		$(ip1).focus();
        return;
    }
		
	// eS :  check split ip
	for(var i=1;i<=4;i++) {
		var ipunit = ipstr+"_"+i;
		if(!isEmpty($(ipunit).value)) {
			if(ipCheck($(ipunit),i)) {
				if(i==1) $(ipaddr).value = parseInt($(ipunit).value);
				else $(ipaddr).value = $(ipaddr).value + "." + parseInt($(ipunit).value);
			} else {
				alertIP(i); $(ipunit).focus(); return false;
			}
		}
	}

	var optText = $(ipaddr).value;
	var optValue = $(ipaddr).value;

	var isNew = true;
	if (boxLength != 0) {
		for (var i = 0; i < boxLength; i++) {
			thisitem = objBox.options[i].text;
			if (thisitem == optText) {
				isNew = false;
				break;
			}
		}
	}
	if (isNew) {
		newoption = new Option(optText, optValue, false, false);
		objBox.options[boxLength] = newoption;
		objBox[boxLength].selected = true;
	}

	for(var i=1;i<=4;i++) {
		var ipunit = ipstr+"_"+i;
		$(ipunit).value = "";
	}
	$(ip1).focus();
}

function ipCheck(ip,loc) {
	if(loc==1) {
		if(!checkNumber(ip.value)) return false;
		if(ip.value < 1 || ip.value > 223) return false;
	} else {

		if(checkNumber(ip.value)) {
			if(ip.value < 0 || ip.value > 255) return false;
		} else {
			return false;
		}
	}
	return true;
}

function alertIP(type) {
	if(type==1) alert(commonjs_set_ip_1);
	else alert(commonjs_set_ip_2);
}

/* PageTile & Location  */
function locationBar(title,locStr) {

var sHTML;

sHTML  = "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr>";
sHTML += "<td width=\"200\" class=\"padding05\">"+title+"</td>";
sHTML += "<td align=\"right\" class=\"padding04\">";
sHTML += "<img src=\"../images/home_content_point01.gif\" width=\"9\" height=\"6\">"+locStr+"</td>";
sHTML += "<tr></table>";

$('locbar').innerHTML = sHTML;


}

function round(elm, bgcolor, border, mode) { 
  var top = document.createElement('div'); top.style.cssText = 'height:5px'; 
  var bottom = document.createElement('div');bottom.style.cssText = 'height:5px'; 
  var temp = document.createElement('div'); temp.setAttribute('id', 'template'); 
  var border2 = (border) ? ";border-left:2px solid "+border+";border-right:2px solid "+border : ""; 
  var border1 = (border) ? ";border-left:1px solid "+border+";border-right:1px solid "+border : ""; 
  var bgcolor2 = (bgcolor) ? ";background:"+bgcolor : ""; 
  var bgcolor1 = (border) ? ";background:" + border : (bgcolor) ? ";background:" + bgcolor : ""; 

  var top_r = new Array(), bottom_r =new Array; 
  var box = elm.cloneNode(true) 
  for (i=1; i < 5 ;i++ ) 
  { top_r[i] = document.createElement('div')} 

  top_r[1].style.cssText = 'margin:0px 5px;height:1px' + bgcolor1 ; 
  top_r[2].style.cssText = 'margin:0px 3px;height:1px' + border2 + bgcolor2; 
  top_r[3].style.cssText = 'margin:0px 2px;height:1px' + border1 + bgcolor2; 
  top_r[4].style.cssText = 'margin:0px 1px;height:2px' + border1 + bgcolor2; 

  
  for (i=1; i < 5 ;i++ ) { 
    if (mode!='bottom') { top.appendChild(top_r[i]);temp.appendChild(top); } 
    bottom_r[i] = top_r[i].cloneNode(true); 
  } 

  temp.appendChild(box); 
  box.style.cssText =  border1 + bgcolor2; 
  temp.appendChild(bottom); 

  if (mode!='top') { 
    for (i=4; i > 0 ;i-- ) { 
      bottom.appendChild(bottom_r[i]); 
    } 
  } 

  elm.parentNode.replaceChild(temp, elm); 

} 


function checkValid(String, SpaceCheck) {

   var retvalue = false;

   for (var i=0; i<String.length; i++) {

      if (SpaceCheck == true) {
         if (String.charAt(i) == ' ') {
            retvalue = true;
            break;
         }
      } else {
         if (String.charAt(i) != ' ') {
            retvalue = true;
            break;
         }
      }
   }

   return retvalue;
}

function isEmpty(String) {
   return !checkValid(String, false);
}

function setClock() {
	var now = new Date(); 
	var nYear = now.getYear();
	var nMonth = now.getMonth()+1;
	var nDate = now.getDate();
	var Hours= now.getHours(); 
	var Minutes= now.getMinutes(); 
	var Seconds= now.getSeconds();

	var Value = nYear;
	Value+= "-" + nMonth
	Value+= "-" + nDate
	Value+= (Hours >=12) ? " PM" : " AM" 
	Value+= " " + ((Hours>12)? Hours - 12 : Hours)
	Value+= ":" + Minutes
	Value+= ":" + Seconds;

	$('clocktext').innerText = Value; 
	setTimeout ("setClock()", 1000); 
} 

function chkId(str) {  // 영소문자, 숫자 , _@-.
    for(var i=0;i<str.length;i++) { 
        achar = str.charCodeAt(i); 
		// 48~57	: 0 ~ 9
		// 65~90	: A ~ Z
		// 97~122	: a ~ z
		// 특수문자	: 95 _  64 @   45 -  46 .
		if( !(achar >= 48 && achar <= 57) && !(achar >= 97 && achar <= 122) && achar!=95 && achar!=64 && achar!=45 && achar!=46) { 
			return false; 
		} 
	} 
    return true; 
} 

function checkNumber(str){
    var anum=/(^\d+$)|(^\d+\.\d+$)/
    if (anum.test(str))
        return true;
    else{
        return false;
    }
}

// since 25141
function checkPhone(str){
    for(var i=0;i<str.length;i++) { 
        achar = str.charCodeAt(i); 
		// 48~57	: 0 ~ 9
		// 특수문자	: 45 -  46 .
		if( !(achar >= 48 && achar <= 57) && achar!=45 ) { 
			return false; 
		} 
	} 
    return true; 
}



/* 원단위 사용예 onkeyup="check_value(this)" */
function check_value(me){
	var myStr=numOffMask(me.value);
	me.value=numOnMask(myStr);
}

function reverseDiv(dd) {
	if(dd.style.display=='none') {
    	dd.style.display='';
    } else {
    	dd.style.display='none';
    }
}

function displayDiv(obj, fg) {
	if(!fg) {
		obj.style.display='none';
	} else {
		obj.style.display='';
	}
}

/* not used 
function searchCheck(form) {
	if(form.keyword.value=="") {
		alert("검색어를 입력해 주십시요");
		form.keyword.focus();						
	} else {
		form.submit();
	}
}
*/


/* Popup Window */
function OpenWindow(url,target,width,height,scroll,toolbar,resiz,stat) {
  toolbar = toolbar?toolbar:"no";
  resiz = resiz?resiz:"no";
  stat = stat?stat:"no";
  scroll = scroll?scroll:"no";
    window.open(url,target,'width=' + width + ',height=' + height + ',toolbar=' + toolbar + ',resizable='+resiz+',scrollbars='+scroll+',status='+stat);
	// ex OpenWindow('http://naver.com',500,500,0,0,0,0)
}

