/*
* Filename	: common.js
* Function	:
* Comment		:
* History		: 2003/05/09, jerry, setup
*						
* Version		:	1.0
* Author		:	Copyright (c) 2005 by JcomTech Corp. All Rights Reserved.
*/

var IE = document.all;
var NS4 = document.layers;
var NS6 = !IE && document.getElementById != null ? true : false;
var doc = (IE ? document.all : document);

/* open window */
function __openWindow(url, popupName, scrollFlag, resizeFlag, width, height, left, top) {
	popupName = popupName == null ? "popup" : popupName;
	scrollFlag = scrollFlag == null ? "no" : scrollFlag;
	resizeFlag = resizeFlag == null ? "no" : resizeFlag;
	width = width == null ? 300 : width;
	height = height == null ? 300 : height;
	left = left == null ? 50 : left;
	top = top == null ? 50 : top;
	
	window.open(url, popupName, "scrollbars=" + scrollFlag + ", resizable=" + resizeFlag + ", width=" + width + ", height=" + height + ", left=" + left + ", top=" + top);
}

function openWindow(url, width, height, popupName) {
	__openWindow(url, popupName, "no", "yes", width, height);
}

function openWindowFixed(url, width, height, popupName) {
	__openWindow(url, popupName, "no", "no", width, height);
}

function openWindowScroll(url, width, height, popupName) {
	__openWindow(url, popupName, "yes", "yes", width, height);
}

function openWindowPos(url, width, height, popupName, left, top) {
	__openWindow(url, popupName, "no", "yes", width, height, left, top);
}

function openWindowFixedPos(url, width, height, popupName, left, top) {
	__openWindow(url, popupName, "no", "no", width, height, left, top);
}

function openWindowScrollPos(url, width, height, popupName, left, top) {
	__openWindow(url, popupName, "yes", "yes", width, height, left, top);
}

/* get IE version */
function getIEVersion() {
	var IEVersion = 0;
//var browserName = navigator.appName;
	var idx = navigator.appVersion.indexOf("MSIE");

	if (idx > -1) {	IEVersion = parseFloat(navigator.appVersion.substr(idx + 4)); }

	return IEVersion;
}

/* get object */
function getObjectByName(objName) {
	var obj = null;
	if (IE) {obj = document.all[objName];}
	else {obj = document.getElementById(objName);}
	return obj;
}

/* make array SET(eliminate duplication) */
function makeSet(array){
	var arrayLength = array.length;
	var ary = new Array();
	var size = 0;
	ary[0] = array[0];
	var unique = true;
	for(i=0;i<arrayLength;i++){
		unique = true;
		size = ary.length;
		for(j=0;j<size;j++){
			if(array[i]==ary[j]){
				unique = false;
				break;
			}
		}
		if(unique){
			ary[size] = array[i];
		}
	}
	return ary;
}

/* Merge two Array (concatenate two array)*/
function mergeArray(iArray, jArray){
	var iSize = iArray.length;
	var jSize = jArray.length;
	var mArray = new Array();
	var mSize = 0;
	var unique = true;
	
	mArray[0] = iArray[0];
	for(i=0;i<iSize;i++){
		mSize = mArray.length;
		mArray[mSize] = iArray[i];
	}
	
	for(j=0;j<jSize;j++){
		mSize = mArray.length;
		mArray[mSize] = jArray[j];
	}
	var nArray = makeSet(mArray);
	
	return nArray;
}

/* Array to String with seperator */
function arrayToString(array, sep){
	var size = array.length;
	var str = "";
	for(i=0;i<size;i++){
		if(array[i].length > 0){
			str = str+array[i]+sep;
		}
	}
	return str;
}

/* We need sort Array */
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}

MM_reloadPage(true);

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

/** Object tag write **/
function writeFlash(flashSrc, wd, ht, paramStr) {
	var objStr = "";
	objStr += "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='" + wd + "' height='" + ht + "'>";
	if (paramStr != null && paramStr.length > 0) {
		objStr += paramStr;
	}
	objStr += "	 <param name='movie' value='" + flashSrc + "'>";
	objStr += "	 <param name='quality' value='high'>";
	objStr += "	 <embed src='" + flashSrc + "' quality='high' pluginspage='https://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + wd + "' height='" + ht + "' wmode='transparent'></embed>";
	objStr += "	</object>";

	document.write(objStr);
}

function writeFlash2(flashSrc, wd, ht, paramStr) {
	var objStr = "";
	objStr += "<object id='ordermade' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='https://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='" + wd + "' height='" + ht + "'>";
	if (paramStr != null && paramStr.length > 0) {
		objStr += paramStr;
	}
	objStr += "	 <param name='movie' value='" + flashSrc + "'>";
	objStr += "	 <param name='quality' value='high'>";
	objStr += "	 <embed src='" + flashSrc + "' quality='high' pluginspage='https://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + wd + "' height='" + ht + "' wmode='transparent'></embed>";
	objStr += "	</object>";

	document.write(objStr);
}

/* check Numeric number */
function isNumeric(checkStr) {return !(/[^0-9]/.test(checkStr));}

// ÀüÈ­¹øÈ£ ÇÏÀÌÇÂ ÀÚµ¿ ÀÔ·Â
function PhoneNumStr( str ){ 
	var RegNotNum  = /[^0-9]/g; 
	var RegPhonNum = ""; 
	var DataForm   = ""; 

	// return blank     
	if( str == "" || str == null ) return ""; 

	// delete not number
	str = str.replace(RegNotNum,''); 

	if( str.length < 4 ) return str; 

	if( str.length > 3 && str.length < 7 ) { 
    DataForm = "$1-$2"; 
		RegPhonNum = /([0-9]{3})([0-9]+)/; 
	} else if(str.length == 7 ) {
		DataForm = "$1-$2"; 
		RegPhonNum = /([0-9]{3})([0-9]{4})/; 
	} else if(str.length == 8 ) {
		DataForm = "$1-$2"; 
		RegPhonNum = /([0-9]{4})([0-9]{4})/; 
	} else if(str.length == 9 ) {
		DataForm = "$1-$2-$3"; 
		RegPhonNum = /([0-9]{2})([0-9]{3})([0-9]+)/; 
	} else if(str.length == 10){ 
		if(str.substring(0,2)=="02"){
			DataForm = "$1-$2-$3"; 
			RegPhonNum = /([0-9]{2})([0-9]{4})([0-9]+)/; 
		}else{
			DataForm = "$1-$2-$3"; 
			RegPhonNum = /([0-9]{3})([0-9]{3})([0-9]+)/;
		}
	} else if(str.length > 10){ 
		DataForm = "$1-$2-$3"; 
		RegPhonNum = /([0-9]{3})([0-9]{4})([0-9]+)/; 
	} 

	while( RegPhonNum.test(str) ) {  
		str = str.replace(RegPhonNum, DataForm);  
	} 
	return str; 
}

// »ç¾÷ÀÚ µî·Ï ¹øÈ£ ÇÏÀÌÇÂ ÀÚµ¿ ÀÔ·Â
function BizNumStr( str ){ 
	var RegNotNum  = /[^0-9]/g; 
	var RegBizNum = ""; 
	var DataForm   = ""; 

	// return blank     
	if( str == "" || str == null ) return ""; 

	// delete not number
	str = str.replace(RegNotNum,''); 

	if( str.length < 4 ) return str; 

	if( str.length > 3 && str.length < 5 ) { 
    DataForm = "$1-$2"; 
		RegBizNum = /([0-9]{3})([0-9]+)/; 
	} else if(str.length == 5){ 
		DataForm = "$1-$2"; 
		RegBizNum = /([0-9]{3})([0-9]{2})/; 
	} else if(str.length == 6){ 
		DataForm = "$1-$2-$3"; 
		RegBizNum = /([0-9]{3})([0-9]{2})([0-9]+)/; 
	} else if(str.length > 6){ 
		DataForm = "$1-$2-$3"; 
		RegBizNum = /([0-9]{3})([0-9]{2})([0-9]+)/; 
	} 

	while( RegBizNum.test(str) ) {  
		str = str.replace(RegBizNum, DataForm);  
	} 
	return str; 
}

// window.onloadÅëÇÕ¹öÀü. Áßº¹ÇØ¼­ ¾µ °æ¿ì ¸¶Áö¸·¸¸ ÀÎ½ÄÇÏ´Â Çö»ó¿¡ ´ëÀÀ.
// template.asp¿¡¼­ »ç¿ë Áß
function addLoadEvent(func) {
  var oldonload = window.onload;
  if(typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
