//------------------------------ Ä«µå ÆË¾÷Ã¢ ¶ç¿ì±â -----------------------
function OpenWindow(w, h, win) {
	if(w == '') w = '550';
	if(h == '') h = '450';
	var popWindow = window.open('',win,'width='+w+',height='+h+',toolbar=no,location=no,directories=no, status=yes,menubar=no, status=yes,menubar=no,scrollbars=no,resizable=yes');
	popWindow.resizeTo(w,h);
	return popWindow;
}

//---------------------------- Ä«µå ÆË¾÷Ã¢ ¶ç¿ì°í Æû ½ÇÇà ------------------
function submitOpenWindow(w,h,fm,win){
	var ow = OpenWindow(w,h,win);
	if(fm) fm.submit();
	if(ow != null && ow){
		return true;
	}else{
		webblasare = navigator.appVersion;
		if((webblasare.indexOf('Windows NT 5.1') != -1) && (webblasare.indexOf('SV1') != -1)){
			alert('°áÁ¦ ÆË¾÷Ã¢À» ¿ÀÇÂÇÒ ¼ö ¾ø½À´Ï´Ù. \nºê¶ó¿ìÀúÀÇ »ó´Ü ³ë¶õ»ö [¾Ë¸² Ç¥½ÃÁÙ]À» Å¬¸¯ÇÏ½Å ÈÄ \n[ÇöÀç »çÀÌÆ®ÀÇ ÆË¾÷À» Ç×»ó Çã¿ë]À¸·Î ¼³Á¤ÇÏ¿© ÁÖ¼¼¿ä.');
		}else{
			alert('°áÁ¦ ÆË¾÷Ã¢À» ¿ÀÇÂÇÒ ¼ö ¾ø½À´Ï´Ù.');
		}
		return false;
	}
}


//--------------------------------- »õÃ¢ ¶ç¿ì±â -----------------------------
function opWin(opn,opw,oph,scr){
    window.open(opn, "", "left=0, top=0, width="+opw+", height="+oph+", menubar=no, statusbar=no, scrollbars="+scr+", directories=no, toolbar=no, location=no, resizable=no");
}


//--------------------------------- ¾ÆÀÌµð Áßº¹Ã¼Å© ¹× ¿ìÆí¹øÈ£ °Ë»ö --------
function id_check(fn,baseurl,errorMsg){
	if(fn.id.value == ''){
		alert(errorMsg);
		fn.id.focus();
	}else{
		window.open(baseurl+'/lib/popup.php?function=H2_check_id&id='+fn.id.value,'','width=300,height=230,scrollbars=yes');
	}
}
function addr_check(fn,baseurl){
	window.open(baseurl+'/lib/popup.php?function=H2_zipsearch&fn='+fn,'','width=500,height=300,scrollbars=yes');
}


//--------------------------------- ¾ÆµÚ,ºñ¹ø ¿£ÅÍÅ° ÀÔ·Â½Ã -----------------
function chk_enter_id(fn){
	if(event.keyCode == 13) fn.pw.focus();
}
function chk_enter_pw(fn){
	if(event.keyCode == 13) fn.submit();
}


//--------------------------------- ÆË¾÷ -------------------------------------
function pop(pPage,Opt) {
	if(self.popUpWin && !popUpWin.closed) {
		popUpWin.close();
	}
	if(Opt == "") Opt = ",width=600,height=500";
	popUpWin = window.open(pPage,'','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no'+Opt);
	popUpWin.moveTo(0,0);
}


//--------------------------------- °ø¹é ¾ø¾Ø ÈÄ ¸®ÅÏ -------------------------

function strTrim(str) {
	for(; str.indexOf(" ") != -1; ){
		str = str.replace(" ","")
	}
	return str;
}


//--------------------------------- ( ¿µ¹®, ¼ýÀÚ, '-', '_' ) ¸¸ Çã¿ë -----------

function checkChr(tocheck){
	var isChr = qwqwtrue;
	if(tocheck == null || tocheck == ""){
		isChr = false;
	}else{		
		for(var j=0 ; j<tocheck.length; j++){
			if( (tocheck.charAt(j) < "A" || tocheck.charAt(j) > "Z" )
			 && (tocheck.charAt(j) < "a" || tocheck.charAt(j) > "z" )
			 && ( tocheck.charAt(j) < '0' || tocheck.charAt(j) > '9')
			 && ( tocheck.charAt(j) != '-' && tocheck.charAt(j) != '_') ){
				isChr = false;
			}
		}
	}
	return isChr;
}

//--------------------------------- ( ¼ýÀÚ ) ¸¸ Çã¿ë ---------------------------
function checkNum(tocheck){
	var isNum = true;
	if(tocheck != null || tocheck != ""){
		for(var j=0; j<tocheck.length; j++){
			if( ( tocheck.charAt(j) < '0' || tocheck.charAt(j) > '9') && tocheck.charAt(j) != '.'){
				isNum = false;
			}
		}
	}
	return isNum;
}

//--------------------------------- ÁÖ¹Îµî·Ï¹øÈ£ Ã¼Å© --------------------------
function isJumin(jumin1, jumin2){
	var juminStr1 = jumin1.value;
	var juminStr2 = jumin2.value;
	if(juminStr1.length != 6){
		jumin1.focus();
		return false;
	}else if(juminStr2.length != 7){
		jumin2.focus();
		return false;
	}else{
		var digit=0;
		for(var i = 0; i < juminStr1.length; i++){
			var str_dig = juminStr1.substring(i, i+1);
			if(str_dig < '0' || str_dig > '9'){
				digit = digit + 1;
			}
		}
		if((juminStr1 == '') || ( digit != 0 )){
			jumin1.focus();
			return false;
		}
		var digit1 = 0
		for(var i = 0; i < juminStr2.length; i++){
		var str_dig1 = juminStr2.substring(i, i+1);
			if(str_dig1 < '0' || str_dig1 > '9'){
				digit1 = digit1 + 1
			}
		}
		if((juminStr2 == '') || ( digit1 != 0 )){
			jumin2.focus();
			return false;
		}
		if(juminStr1.substring(2,3) > 1){
			jumin1.focus();
			return false;
		}
		if(juminStr1.substring(4,5) > 3){
			jumin1.focus();
			return false;
		}
		if(juminStr2.substring(0,1) > 4 || juminStr2.substring(0,1) == 0){
			jumin2.focus();
			return false;
		}
		var a1 = juminStr1.substring(0,1);
		var a2 = juminStr1.substring(1,2);
		var a3 = juminStr1.substring(2,3);
		var a4 = juminStr1.substring(3,4);
		var a5 = juminStr1.substring(4,5);
		var a6 = juminStr1.substring(5,6);
		var check_digit = a1*2 + a2*3 + a3*4 + a4*5 + a5*6 + a6*7;
		var b1 = juminStr2.substring(0,1);
		var b2 = juminStr2.substring(1,2);
		var b3 = juminStr2.substring(2,3);
		var b4 = juminStr2.substring(3,4);
		var b5 = juminStr2.substring(4,5);
		var b6 = juminStr2.substring(5,6);
		var b7 = juminStr2.substring(6,7);
		var check_digit = check_digit + b1*8 + b2*9 + b3*2 + b4*3 + b5*4 + b6*5;
		check_digit = check_digit % 11;
		check_digit = 11 - check_digit;
		check_digit = check_digit % 10;
		if(check_digit != b7){
			return false;
		}else{
			return true;
		}
	}
}

//--------------------------------- ÀÌ¸ÞÀÏ Ã¼Å© --------------------------------
function isEmail(emailStr) {
	var checkTLD = 1;
	var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat = /^(.+)@(.+)$/;
	var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars = "\[^\\s" + specialChars + "\]";
	var quotedUser = "(\"[^\"]*\")";
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom = validChars + '+';
	var word = "(" + atom + "|" + quotedUser + ")";
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray = emailStr.match(emailPat);
	if(matchArray == null) {
		return false;
	}
	var user = matchArray[1];
	var domain = matchArray[2];
	for(i = 0; i < user.length; i++){
		if(user.charCodeAt(i) > 127){
			return false;
		}
	}
	for(i = 0; i < domain.length; i++){
		if(domain.charCodeAt(i) > 127){
			return false;
		}
	}
	if(user.match(userPat) == null){
		return false;
	}
	var IPArray = domain.match(ipDomainPat);
	if(IPArray != null){
		for(var i = 1; i <= 4; i++){
			if(IPArray[i] > 255){
				return false;
			}
		}
		return true;
	}
	var atomPat = new RegExp("^" + atom + "$");
	var domArr = domain.split(".");
	var len = domArr.length;
	for(i = 0; i < len; i++){
		if(domArr[i].search(atomPat) == -1){
			return false;
		}
	}
	if(checkTLD && domArr[domArr.length-1].length != 2 && domArr[domArr.length-1].search(knownDomsPat) == -1){
		return false;
	}
	if(len < 2){
		return false;
	}
	return true;
}

//--------------------------------- ÀÌ¹ÌÁö ÆÄÀÏ Ã¼Å© ---------------------------
function imageFileCheck(formName,inputName,errorMsg1,errorMsg2,errorMsg3){
	var imgBox = eval(formName + '.' + inputName);
	if(imgBox.value != ""){
		// È®ÀåÀÚ ÃßÃâ
		var ext_name = "";
		ext_name = imgBox.value.substring(imgBox.value.lastIndexOf('.')+1, imgBox.value.length).toLowerCase();

		// ÆÄÀÏÀÌ¸§ ÃßÃâ
		var image_name = "";
		image_name = imgBox.value.substring(imgBox.value.lastIndexOf('\\')+1, imgBox.value.length).toLowerCase();

		if((ext_name != "swf") && (ext_name != "gif") && (ext_name != "jpg") && (ext_name != "bmp") && (ext_name != "jpeg")){
			alert(errorMsg1);//-------("ÀÌ¹ÌÁöÆÄÀÏ¸¸ ¾÷·Îµå °¡´ÉÇÕ´Ï´Ù!!!");---------
			imgBox.focus();
			return false;
		}
//		if(image_name.indexOf(" ") > -1){
//			alert(errorMsg2);//-------("ÀÌ¹ÌÁöÆÄÀÏ ÀÌ¸§¿¡ °ø¹éÀº Çã¿ëµÇÁö ¾Ê½À´Ï´Ù");-------
//			imgBox.focus();
//			return false;
//		}
//		for(i=0; i<image_name.length; i++){
//			var a = image_name.charCodeAt(i);
//			if(a > 128){
//				alert(errorMsg3);//--------("ÀÌ¹ÌÁö ÀÌ¸§¿¡ ÇÑ±ÛÀº Çã¿ëµÇÁö ¾Ê½À´Ï´Ù!!!");--------
//				imgBox.focus();
//				return false;
//			}
//		}
	}
	return true;
}

/**************************************************************************************
* onluNumber()´Â ÀÔ·ÂÅ°ÀÇ °ªÀÌ ¼ýÀÚ¿¡ ÇÑÇØ¼­¸¸ ¹Þ¾Æ µéÀÌ°í ³ª¸ÓÁö´Â ¹Þ°í ½ÍÁö ¾ÊÀ»°æ¿ì
* »ç¿ëÇÏ´Â ÇÔ¼öÀÌ¸ç ÀÌ¶§ style='ime-mode:disabled'¸¦ ÁÖ¾î¼­ ÇÑ±Û·Î º¯È¯ÀÌ ¾ÈµÇ°Ô²û
* ÇØÁà¾ß ÇÑ´Ù. ±×¸®°í ¹Ýµå½Ã onkeypress="onlyNumber();"¸¦ ³Ö¾î ÁÖ¾î Å°°¡ ÀÔ·ÂµÉ¶§ ¸¶´Ù
* °Ë»ç°¡ °¡´ÉÇÏ°Ô²û ÇØÁà¾ß ÇÑ´Ù.
**************************************************************************************/
function onlyNumber() {
	if ((event.keyCode<48)||(event.keyCode>57)){
                	event.returnValue=false;
        	}
}

/**************************************************************************************
* Æû¿¡¼­ ÀüÃ¼ÀÇ Ã¼Å©¹Ú½º¸¦ Ã£¾Æ¼­ Ã¼Å©¸¦ ÀüÈ¯ ½ÃÄÑ ÁØ´Ù.
* function reverse_check(FormName);
* ÀÌ¶§ ÀÎÀÚ·Î ÆûÀÇ ÀÌ¸§À» ³Ñ°ÜÁØ´Ù.
**************************************************************************************/
function reverse_check(FormName) {
	for(var i=0; i<FormName.elements.length; i++) {
		var ele = FormName.elements[i];
		if(ele.disabled != true) {
			if(ele.type == "checkbox") {
				if( ele.checked == 1 ) {
					ele.checked = 0;
				} else if( ele.checked == 0 ) {
					ele.checked = 1;
				}
			}
		}
	}
}

/**************************************************************************************
* »óÇ°ÀÇ ¼ö·®À» Ãâ·ÂÇÏ´Â ÀÚ¹Ù½ºÅ©¸³Æ® ÇÔ¼ö
* function prn_quantity(quantity)
* -------------------------------------------------------------------------------------
* ÀÚ¹Ù½ºÅ©¸³Æ®·Î ¼ö·®¶õ¿¡ ¼¿·ºÆ® ¹Ú½º¸¦ Ãâ·ÂÇÏ´Â ÇÔ¼ö
* ÀÌ¶§ ¼ö·®(quantity)À» argument·Î ¹Þ¾Æ¼­ ÇØ´çÇÏ´Â ¼ö·®¸¸Å­ ¼¿·ºÆ® ¹Ú½º¿¡ ¿É¼ÇÀ» Ãâ·ÂÇÏ°í
* ¸¸¾à quantityÀÇ °¹¼ö°¡ 0ÀÎ°æ¿ì Àç°í ¾øÀ½À» Ãâ·Â
**************************************************************************************/
function prn_quantity(quantity,select_quantity,class_name) {
	var Stock_ch = quantity;
	var SELECTED_PRN;
	var width;

	if(!select_quantity) select_quantity = 1;

	document.write('<td><input type=text name=\"prod_count\" style=\"font-size: 9pt; width: 43\" value=\"' + select_quantity + '\"');
	if(class_name != "") document.write(' class=\"' + class_name + '\"');
	document.write('></td>');
}


/**************************************************************************************
* ¼ýÀÚ¸¦ ¹Þ¾Æ¼­ number_format ÇüÅÂÀÇ °á°ú °ªÀ¸·Î º¯È¯ÇÏ´Â ÇÔ¼ö
* function formatCurrency(num)
**************************************************************************************/
function formatCurrency(num) {
	num = num.toString().replace(/$|\,/g,'');
	if(isNaN(num)) num = "0";
	cents = Math.floor((num*100+0.5)%100);
	num = Math.floor((num*100+0.5)/100).toString();
	if(cents < 10) cents = "0" + cents;
	for (var i=0; i<Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	if(cents > 0) num = num + '.' + cents;
	return num;
}

function formatNumber(price,decimal){
	var rtn_price = 0;
	var key_decimal = 1;
	for(var i=0; i<decimal; i++){
		key_decimal = key_decimal * 10;
	}
	rtn_price = parseInt(price*key_decimal)/key_decimal;
	return rtn_price;
}

var AvaliableWidth = screen.width;
var AvaliableHeight = screen.height;

function makeWinReSize(url,w,h) {
	LeftPoint = ((AvaliableWidth - w) / 2);
	TopPoint = ((AvaliableHeight - h) / 2) - 30;
	newWin=window.open(url,'HWindow',"left="+LeftPoint+",top="+TopPoint+",width="+w+",height="+h+",scrollbars=1,resizable=1");
	if (newWin !=null) newWin.opener=self;
}

function makeWin(url) {
	LeftPoint = ((AvaliableWidth - w) / 2);
	TopPoint = ((AvaliableHeight - h) / 2) - 30;
	newWin=window.open(url,'HWindow',"left="+LeftPoint+",top="+TopPoint+",width=300,height=300,scrollbars=1,resizable=0");
	if (newWin !=null) newWin.opener=self;
}

function makeWinSize(url,w,h) {
	LeftPoint = ((AvaliableWidth - w) / 2);
	TopPoint = ((AvaliableHeight - h) / 2) - 30;
	newWin=window.open(url,'HWindow',"left="+LeftPoint+",top="+TopPoint+",width="+w+",height="+h);
	if (newWin !=null) newWin.opener=self;
}

function makeWinSizeScroll(url,w,h) {
	LeftPoint = ((AvaliableWidth - w) / 2);
	TopPoint = ((AvaliableHeight - h) / 2) - 30;
	newWin=window.open(url,'HWindow',"left="+LeftPoint+",top="+TopPoint+",width="+w+",height="+h+",scrollbars=1");
	if (newWin !=null) newWin.opener=self;
}

function allblur() {
for (i = 0; i < document.links.length; i++)
document.links[i].onfocus = document.links[i].blur;
}

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 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 "";
}

//------------------------------------------------------------------------------------
// ÆË¾÷Ã¢¿¡¼­ ¸¸µé¾îÁø ÄíÅ° Notice ÀÇ °ªÀÌ done ÀÌ ¾Æ´Ï¸é(Áï, Ã¼Å©ÇÏÁö ¾ÊÀ¸¸é,)
// °øÁöÃ¢ (new.htm) À» ¶ç¿ó´Ï´Ù
//------------------------------------------------------------------------------------
function scroll(ID,chk) {
	var idValue = eval(ID);
	switch(chk) {
		case 1: idValue.stop(); break;
		case 2: idValue.start(); break;
	}
}

//-----------------------------------------
//---- [MULTI SELECT] SCRIPT START --------
//-----------------------------------------
function move_multi(formName,tbox,str1,str2,str3,str4) {
	var i = 0;
	var j = 0;

	formName.price.value = strTrim(formName.price.value);
	if(formName.price.value == '') formName.price.value = 0;

	if(formName.name.value == '') {
		alert(str1);
		return;
	}
	if(formName.name.value.toLowerCase().match(/(;|&)/)) {
		alert(str2);
		return;
	}
	if(!formName.price.value.toLowerCase().match(/([0-9])/)) {
		alert(str3);
		return;
	}
	var textValue = formName.name.value;
	if(formName.price.value != '')	textValue += '&' + formName.price.value;
	else				textValue += '&0';
	for(i=0; i<tbox.options.length; i++) {
		if (tbox.options[i].value == textValue ){
			alert(str4);
			return;
		}
	}
	var addtext = textValue;
	var addvalue = textValue;
	var no = new Option(addtext,addvalue);
	tbox.options[tbox.options.length] = no;
	formName.name.focus();
	formName.name.value = '';
	formName.price.value = '';
}
function remove_multi(box,box2) {
	var j=0,i=0;

	if(box.options.length == 1 && box.options[0].selected==true){
		box.options.length = 0;
		return;
	}
	for(i=0; i<box.options.length; i++) {
		if (box.options[i].selected!=true) {
			var addtext = box.options[i].value ;
			var addvalue = box.options[i].text ;
			var no = new Option(addtext,addvalue);
			box2.options[j] = no;
			box2.options[j].value = box.options[i].value ;
			box2.options[j].text = box.options[i].text ;
			j++;
   		}
	}
	box2.options.length = j;
	for(i=0; i<box2.options.length; i++) {
		box.options[i].value = box2.options[i].value ;
		box.options[i].text = box2.options[i].text ;
	}
	box.options.length = box2.options.length;
}
function move_order(tbox,index,to) {
	var total = tbox.options.length-1;
	if (index == -1) return false;
	if (to == +1 && index == total) return false;
	if (to == -1 && index == 0) return false;
	var items = new Array;
	var values = new Array;
	for (i=total; i>=0; i--) {
		items[i] = tbox.options[i].text;
		values[i] = tbox.options[i].value;
	}
	for (i=total; i>=0; i--) {
		if (index == i) {
			tbox.options[i + to] = new Option(items[i],values[i], 0, 1);
			tbox.options[i] = new Option(items[i + to], values[i + to]);
			i--;
		}else {
			tbox.options[i] = new Option(items[i], values[i]);
   		}
	}
	tbox.focus();
}
//------ [MULTI SELECT] SCRIPT END ---------


