// Some Constants
var DOMAIN_NAME = "www.muztek.co.kr";
var ROOT_DIR = "/";
var INC_DIR = ROOT_DIR + "include/";
var CSS_DIR = ROOT_DIR + "stylesheets/";
var JS_DIR = ROOT_DIR + "javascripts/";
var IMG_DIR = ROOT_DIR + "images/";
var SCRIPTS_DIR = ROOT_DIR + "scripts/";

var NUMBER = '0123456789';
var LOWER = 'abcdefghijklmnopqrstuvwxyz';
var UPPER = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var ALLOWED_IMAGES = new Array("gif", "jpeg", "jpg", "png");
var ALLOWED_CELL_AREA = new Array("010", "011", "016", "017", "018", "019");
var ALLOWED_PHONE_AREA = new Array("02", "031", "032", "033", "041", "042", "043", "051", "052", "053", "054", "055", "061", "062", "063", "064", "070");


function swf(src,width,height,tr){
    object = '';
    object += '<object type="application/x-shockwave-flash" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" id="param" width="'+width+'" height="'+height+'">';
    object += '<param name="movie" value="'+src+'">';
    if(tr=='1'){
         object += '<param name="wmode" Value="Transparent">';
    }
    object += '<embed src="'+src+'" quality="high" ';    
    if(tr=='1'){
        object += ' wmode="transparent" ';
    }
    object += ' bgcolor="#ffffff" menu="false" width="'+width+'" height="'+height+'" swliveconnect="true" id="param" name="param" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
    object += '</object>';
    document.write(object);
}


function isNumber(str) {
  var found = false;

  for (i = 0; !found && (i < str.length); i++) {
    if ( (str.charAt(i) < '0') || (str.charAt(i) > '9') ) {
      found = true;
    }
  }
  
  if (found) {
    return false;
  } else {
    return true;
  } 
}


function trimWhiteSpaces(str)
{
  var index = 0;
  var found = false;

  // find an index of the first non-space char
  // '\t' and '\n' are not included. ('\t' changes focus, '\n' submits a form)
  for (i = 0; !found && i < str.length; i += 1) {
    if ( str.charAt(i) != ' ' ) {
      index = i;
      found = true;
    }
  }

  if ( found ) {
    str = str.substring(index);

    // find an index of the last non-space char
    i = str.length - 1;
    for (found = false; !found && i > -1 ; i -= 1) {
      if ( str.charAt(i) != ' ' ) {
				index = i;
        found = true;
      }
    }
    str = str.substring(0, (index + 1));
  } else {
    str = "";
  }

  return str;
}


function getAllowedFileString(opt)
{
	var fString;
	var allowedFiles;
	
	if ( opt == "image" ) {
		allowedFiles = ALLOWED_IMAGES;
	} else if ( opt == "movie" ) {
		allowedFiles = ALLOWED_MOVIES;
	} else {
		allowedFiles = ALLOWED_SOUNDS;
	}
	
	fString = allowedFiles[0];
	for ( i = 1; i < allowedFiles.length; i += 1 ) {
		fString += ", " + allowedFiles[i];
	}
	
	return fString;
}


function refreshProducts(sel, cID)
{
	if ( parseInt(sel.options[sel.selectedIndex].value) ) {	
		var uri = SCRIPTS_DIR + "product/product_02.php?";

		uri += "catID=" + cID + "&order=";
		uri += sel.options[sel.selectedIndex].value;
		top.document.location.href = uri;
	}

}


function searchSupport(fname)
{	
	fname.searchKey.value = trimWhiteSpaces(fname.searchKey.value);
  if ( fname.searchKey.value.length == 0 ) {
    alert("검색어를 입력하세요!");
    fname.searchKey.focus();
    return false;
  } else {
  	fname.action += "?act=&order=&orderDir=&search=true&searchKey=" + encodeURI(fname.searchKey.value);
  	fname.action += "&pageNum=";
    fname.submit();
  }
}


function refreshSupport(ord, ordDir, sch, schKey, pgNum)
{
	var uri = SCRIPTS_DIR + "support/support_01.php?order=";
	
	if ( ord != null ) {
		uri += ord;
	}
	
	uri += "&orderDir=";
	if ( ordDir != null ) {
		uri += ordDir;
	}
	
	uri += "&search=";
	if ( sch != null ) {
		uri += sch + "&searchKey=" + encodeURI(schKey);
	} else {
		uri += "&searchKey=";
	}
	
	uri += "&pageNum=";
	if ( pgNum != null ) {
		uri += pgNum;
	}
	
	top.document.location.href = uri;
}


function searchData(fname)
{
	fname.searchKey.value = trimWhiteSpaces(fname.searchKey.value);
  if ( fname.searchKey.value.length == 0 ) {
    alert("검색어를 입력하세요!");
    fname.searchKey.focus();
    return false;
  } else {
  	fname.action += "?act=&order=&orderDir=&search=true&searchKey=" + encodeURI(fname.searchKey.value);
  	fname.action += "&pageNum=";
    fname.submit();
  }
}


function refreshData(ord, ordDir, sch, schKey, pgNum)
{
	var uri = SCRIPTS_DIR + "download/download_01.php?order=";
	
	if ( ord != null ) {
		uri += ord;
	}
	
	uri += "&orderDir=";
	if ( ordDir != null ) {
		uri += ordDir;
	}
	
	uri += "&search=";
	if ( sch != null ) {
		uri += sch + "&searchKey=" + encodeURI(schKey);
	} else {
		uri += "&searchKey=";
	}
	
	uri += "&pageNum=";
	if ( pgNum != null ) {
		uri += pgNum;
	}
	
	top.document.location.href = uri;
}


function searchNews(fname)
{
	fname.searchKey.value = trimWhiteSpaces(fname.searchKey.value);
  if ( fname.searchKey.value.length == 0 ) {
    alert("검색어를 입력하세요!");
    fname.searchKey.focus();
    return false;
  } else {
  	fname.action += "?act=&order=&orderDir=&search=true&searchKey=" + encodeURI(fname.searchKey.value);
  	fname.action += "&pageNum=";
    fname.submit();
  }
}


function refreshNews(ord, ordDir, sch, schKey, pgNum)
{
	var uri = SCRIPTS_DIR + "news/news_01.php?order=";
	
	if ( ord != null ) {
		uri += ord;
	}
	
	uri += "&orderDir=";
	if ( ordDir != null ) {
		uri += ordDir;
	}
	
	uri += "&search=";
	if ( sch != null ) {
		uri += sch + "&searchKey=" + encodeURI(schKey);
	} else {
		uri += "&searchKey=";
	}
	
	uri += "&pageNum=";
	if ( pgNum != null ) {
		uri += pgNum;
	}
	
	top.document.location.href = uri;
}


function verifyContact(fname)
{
	msg = false;
	
	fname.subject.value = trimWhiteSpaces(fname.subject.value);
	if ( !fname.subject.value.length ) {
		alert("제목을 입력하세요!\nPlease enter the subject!");
		return false;
	}
	
	fname.fromName.value = trimWhiteSpaces(fname.fromName.value);
	if ( !fname.fromName.value.length ) {
		alert("보내는 사람의 이름을 입력하세요!\nPlease enter the sender\'s name!");
		return false;
	}
	
	// check email account
	fname.emailAcct.value = trimWhiteSpaces(fname.emailAcct.value);
	if ( !fname.emailAcct.value.length ) {
		alert("이메일 계정을 입력하세요!\nPlease enter the email account!");
		return false;
	}

	// check email account
	fname.emailDomain.value = trimWhiteSpaces(fname.emailDomain.value);
	if ( !fname.emailDomain.value.length ) {
		alert("이메일 도메인 이름을 입력하세요!\nPlease enter the email domain name!");
		return false;
	}

	// check email address
	msg = checkEmailAddress(fname.emailAcct.value, fname.emailDomain.value)
	if ( msg ) {
		alert(msg);
		return false;
	}
	
	// check content
	fname.content.value = trimWhiteSpaces(fname.content.value);
	if ( !fname.content.value.length ) {
		alert("보내실 내용을 입력하세요!\nPlease enter the message!");
		return false;
	}

	// check security string
	fname.secStr.value = trimWhiteSpaces(fname.secStr.value);
	if ( !fname.secStr.value.length ) {
		alert("그림에 보이는 보안문자열을 입력하세요!\nPlease enter the characters you see in the picture!", "contact_01.php");
		return false;
	}

	fname.submit();
}


function verifyLogin(fname)
{
	msg = false;
	
	fname.uid.value = trimWhiteSpaces(fname.uid.value);
	if ( !fname.uid.value.length ) {
		alert("아이디를 입력하세요!");
		return false;
	}
	
	fname.pw.value = trimWhiteSpaces(fname.pw.value);
	if ( !fname.pw.value.length ) {
		alert("비밀번호를 입력하세요!");
		return false;
	}
	
	fname.submit();
}


//function checkSearchKey(f, opt)
//{
//	f.searchKey.value = trimWhiteSpaces(f.searchKey.value);
//	if ( !f.searchKey.value.length ) {
//    alert("검색어를 입력하세요!");
//		return false;
//	} else {
//  	f.action += "?opt=" + opt + "&sKey=" + encodeURI(f.searchKey.value);
//  	f.action += "&pageNum=";
//		top.document.location.href = f.action;
//  	//f.submit();
//	}
//}

	
function checkSearchKey(opt)
{
	var sKey = document.getElementById("searchKey");
	var url = SCRIPTS_DIR + "search/search_01.php";
	
	sKey.value = trimWhiteSpaces(sKey.value);
	if ( !sKey.value.length ) {
    alert("검색어를 입력하세요!");
		return false;
	} else {
  	url += "?opt=" + opt + "&sKey=" + encodeURI(sKey.value);
  	url += "&pageNum=";
		top.document.location.href = url;
	}
}

	
function refreshSearch(opt, sKey)
{
	var uri = SCRIPTS_DIR + "search/search_01.php?opt=" + opt + "&sKey=" + encodeURI(sKey);
	top.document.location.href = uri;
}

	
function showBigPic(pID)
{
	var tType;
  //var w = 575;
 	//var h = 754;	
  var w = 633;
 	//var h = 812;	
 	var h = 815;	
 	var wleft = (screen.width - w) / 2;
 	var wtop = (screen.height - h) / 2;
 	var newWin = null;
 
 	if ( wleft < 0 ) {
 	  w = screen.width;
 	  wleft = 0;
 	}
 	if ( wtop < 0 ) {
 	  h = screen.height;
 	  wtop = 0;
 	}
	newWin = window.open(SCRIPTS_DIR + "view/view_01.php?pID=" + pID,
 											 	"view_big_pic" + pID,
 											 	"resizable=no,toolbar=no,status=no,location=no,scrollbars=yes,width=" + w + ",height=" + h + ",top=" + wtop + ",left=" + wleft);
 	newWin.focus();

  return false;	
}


function showMovie(pID)
{
	var tType;
  var w = 575;
 	var h = 459;	
 	var wleft = (screen.width - w) / 2;
 	var wtop = (screen.height - h) / 2;
 	var newWin = null;
 
 	if ( wleft < 0 ) {
 	  w = screen.width;
 	  wleft = 0;
 	}
 	if ( wtop < 0 ) {
 	  h = screen.height;
 	  wtop = 0;
 	}
	newWin = window.open(SCRIPTS_DIR + "view/view_02.php?pID=" + pID,
 											 	"view_movie" + pID,
 											 	"resizable=no,toolbar=no,status=no,location=no,scrollbars=no,width=" + w + ",height=" + h + ",top=" + wtop + ",left=" + wleft);
 	newWin.focus();

  return false;	
}


function listenSound(pID)
{
	var tType;
  var w = 575;
 	var h = 459;	
 	var wleft = (screen.width - w) / 2;
 	var wtop = (screen.height - h) / 2;
 	var newWin = null;
 
 	if ( wleft < 0 ) {
 	  w = screen.width;
 	  wleft = 0;
 	}
 	if ( wtop < 0 ) {
 	  h = screen.height;
 	  wtop = 0;
 	}
	newWin = window.open(SCRIPTS_DIR + "view/view_03.php?pID=" + pID,
 											 	"listen_sound" + pID,
 											 	"resizable=no,toolbar=no,status=no,location=no,scrollbars=no,width=" + w + ",height=" + h + ",top=" + wtop + ",left=" + wleft);
 	newWin.focus();

  return false;	
}


/////////////////////////////////////////
// Utility Functions
/////////////////////////////////////////
function trimWhiteSpaces(str)
{
  var index = 0;
  var found = false;

  // find an index of the first non-space char
  // '\t' and '\n' are not included. ('\t' changes focus, '\n' submits a form)
  for (i = 0; !found && i < str.length; i += 1) {
    if ( str.charAt(i) != ' ' ) {
      index = i;
      found = true;
    }
  }

  if ( found ) {
    str = str.substring(index);

    // find an index of the last non-space char
    i = str.length - 1;
    for (found = false; !found && i > -1 ; i -= 1) {
      if ( str.charAt(i) != ' ' ) {
				index = i;
        found = true;
      }
    }
    str = str.substring(0, (index + 1));
  } else {
    str = "";
  }

  return str;
}


function checkEmailAddress(acct, domainName)
{
	var incorrect = false;
	var msg = false;
	var emailAddr = acct + "@" + domainName;
  var emailRegExp = new RegExp("^[^@ ]+@[^@ ]+\.[^@ \.]+$"); 

	//domain should contain at least one dot
	dotIndex = domainName.indexOf(".");
	
	if ( dotIndex == -1 ) {
		incorrect = true;
	} else if ( (dotIndex < 2) || ((domainName.length - dotIndex) < 3) ) { // at least 2 chars before/after the first dot
		incorrect = true;
	} else if ( !emailAddr.match(emailRegExp) ) {
		incorrect = true;
 	}
 	
 	if ( incorrect ) {
    msg = "이메일 주소의 형식이 올바르지 않습니다!\nPlease check the email address!";
	}

 	return msg;
}


function moveToSelected(sel)
{
	document.location.href = "#" + sel.value;
}


/**********************/
/* register_01.php related */
/**********************/
//function refreshDealer(act, ord, ordDir, sch, schKey, pgNum, dType, uID)
//{
//	var uri = SCRIPTS_DIR + "dealer.php?act=";
//	
//	if ( act != null ) {
//		uri += act;
//	}
//	
//	uri += "&order=";
//	if ( ord != null ) {
//		uri += ord;
//	}
//	
//	uri += "&orderDir=";
//	if ( ordDir != null ) {
//		uri += ordDir;
//	}
//	
//	uri += "&search=";
//	if ( sch != null ) {
//		uri += sch + "&searchKey=" + encodeURI(schKey);
//	} else {
//		uri += "&searchKey=";
//	}
//	
//	uri += "&pageNum=";
//	if ( pgNum != null ) {
//		uri += pgNum;
//	}
//	
//	uri += "&dealerType=";
//	if ( dType != null ) {
//		uri += dType;
//	}
//
//	uri += "&userID=";
//	if ( uID != null ) {
//		uri += uID;
//	}
//
//	top.document.frames['main'].location.href = uri;
//}


//function searchDealer(fname, dType)
//{
//	fname.searchKey.value = trimWhiteSpaces(fname.searchKey.value);
//  if ( fname.searchKey.value.length == 0 ) {
//    alert("찾고자 하는 딜러의 이름을 입력하세요!");
//    fname.searchKey.focus();
//    return false;
//  } else {
//  	fname.action += "?act=&order=&orderDir=&search=true&searchKey=" + encodeURI(fname.searchKey.value);
//  	fname.action += "&pageNum=&dealerType=" + dType + "&userID=";
//    return true;
//  }
//}


//function checkAllCBs(fname)
//{ 
//  for( i = 0; i < fname.length; i++ ) {
//   e = fname.elements[i];
//    if ( e.type == 'checkbox' && !e.disabled ) {
//      e.checked = true;
//    }
//  }
//}


//function dealerActionConfirm(sForm, tForm, aType)
//{
//  var count = 0;
//  var IDs;
//
//  count = numChecked(sForm);
//	IDs = formulateIdList(sForm); 
//
//  if ( count > 0 ) {
//		msg = "선택하신 ";
//  	switch ( aType ) {
//  		case 'grant':
//  			msg += "딜러쉽 요청을 승인하시겠습니까?";
//  			break;
//  		case 'password':
//  			msg += "딜러(들)에게 임시비밀번호를 발급하시겠습니까?";
//  			break;
//  		case 'regrant':
//  			msg += "딜러(들)과의 거래를 재개하시겠습니까?";
//  			break;
//  		case 'suspend':
//  			msg += "딜러(들)과 거래를 중지하시겠습니까?"
//  			break;
//  		case 'delete':
//  			msg += "딜러쉽 요청을 영구히 삭제하시겠습니까?";
//  			break;
//  	}
//  	if ( confirm(msg) ) {
//  		tForm.ids.value = IDs;
//  		tForm.actType.value = aType;
//  		tForm.submit();
//  	}
//  } else {
//  	msg = "";
//  	switch ( aType ) {
//  		case 'grant':
//  			msg = "딜러쉽을 승인하고자 하는 딜러를 선택하세요!";
//  			break;
//  		case 'password':
//  			msg = "임시비밀번호를 발급하고자 하는 딜러를 선택하세요!";
//  			break;
//  		case 'regrant':
//  			msg = "거래를 재개하고자 하는 딜러를 선택하세요!";
//  			break;
//  		case 'suspend':
//  			msg = "거래를 중지하고자 하는 딜러를 선택하세요!"
//  			break;
//  		case 'delete':
//  			msg = "삭제하고자 하는 딜러승인요청을 선택하세요!";
//  			break;
//  	}
//    alert(msg);
//  }
//}


function setContact(f)
{
	if ( f.sameInfo.checked ) {
		f.conName.value = f.repName.value;
		f.conCell1.value = f.repCell1.value;
		f.conCell2.value = f.repCell2.value;
		f.conCell3.value = f.repCell3.value;
		f.conEmail1.value = f.repEmail1.value;
		f.conEmail2.value = f.repEmail2.value;
	}
}


function trimTextDealerInfo(e, show)
{
	var msg = false;
	e.value = trimWhiteSpaces(e.value);
	if ( !e.value.length ) {
		switch (e.name) {
			case 'uID'   				: msg = "아이디를"; break;
			case 'dealerName'   : msg = "대리점명을"; break;
			case 'passwd'   		: msg = "비밀번호를"; break;
			case 'confPasswd'   : msg = "확인비밀번호를"; break;
			case 'regBusName'   : msg = "상호를"; break;
			case 'regOwner'     : msg = "사업자 성명을"; break;
			case 'regZipCode'   : msg = "사업장 소재지 우편번호를"; break;
			case 'regAddr'      : 
			case 'regDetailAddr': msg = "사업장 소재지를"; break;
			case 'regType'      : msg = "업태를"; break;
			case 'regSubType'   : msg = "종목을"; break;
			case 'repZipCode'   : msg = "실제 사업장의 우편번호를"; break;
			case 'repAddr'      :
			case 'repDetailAddr': msg = "실제 사업장 주소를"; break;
			case 'repName'      : msg = "대표 연락처의 성명을"; break;
			case 'repEmail1'    : msg = "대표 이메일의 계정을"; break;
			case 'repEmail2'    : msg = "대표 이메일의 주소를"; break;
			case 'conName'      : msg = "담당자 이름을"; break;
			case 'conEmail1'    : msg = "담당자 이메일의 계정을"; break;
			case 'conEmail2'    : msg = "담당자 이메일의 주소를"; break;
			case 'homeURL' 		 	: msg = "홈페이지 주소를"; break;
		}
		msg += " 입력하세요!";
		if ( show ) {
			alert(msg);
		}
		//e.focus();
	}
	
	return msg;
}


function trimNumDealerInfo(e, show)
{
	var msg = "";

	e.value = trimWhiteSpaces(e.value);
	if ( !isNumber(e.value) ) {
		msg = getMessagePrefix(e);
		msg += " 숫자만 입력하세요!";
		if ( show ) {
			alert(msg);
		}
	} else {
		msg += getMessageMiddle(e);
		if ( msg.length ) {
			msg = getMessagePrefix(e) + msg;
			msg += " 숫자를 입력하세요!";
			if ( show ) {
				alert(msg);
			}
		}
	}

	//if ( msg ) {
	//	e.focus();
	//}

	return msg;
}


function getMessagePrefix(e)
{
	var msg = "";

	switch (e.name) {
		case 'regNo1'  : msg = "사업자등록번호의 첫번째 칸에는"; break;
		case 'regNo2'  : msg = "사업자등록번호의 두번째 칸에는"; break;
		case 'regNo3'  : msg = "사업자등록번호의 세번째 칸에는"; break;
		case 'repTel1' : msg = "대표 전화의 지역번호란에는"; break;
		case 'repTel2' : msg = "대표 전화의 국번란에는"; break;
		case 'repTel3' : msg = "대표 전화의 번호란에는"; break;
		case 'repFax1' : msg = "대표 팩스의 지역번호란에는"; break;
		case 'repFax2' : msg = "대표 팩스의 국번란에는"; break;
		case 'repFax3' : msg = "대표 팩스의 번호란에는"; break;
		case 'repCell1': msg = "대표 핸드폰의 통신사 식별번호란에는"; break;
		case 'repCell2': msg = "대표 핸드폰의 국번란에는"; break;
		case 'repCell3': msg = "대표 핸드폰의 번호란에는"; break;
		case 'conCell1': msg = "담당자 핸드폰의 통신사 식별번호란에는"; break;
		case 'conCell2': msg = "담당자 핸드폰의 국번란에는"; break;
		case 'conCell3': msg = "담당자 핸드폰의 번호란에는"; break;
	}

	return msg;
}


function getMessageMiddle(e)
{
	var msg = "";
		
	switch (e.name) {
		case 'regNo1'  :
		case 'repCell1':
		case 'conCell1': if ( e.value.length < 3 ) { msg += " 3자리"; } break;
		case 'regNo2'  : if ( e.value.length < 2 ) { msg += " 2자리"; } break;
		case 'regNo3'  : if ( e.value.length < 5 ) { msg += " 5자리"; } break;
		case 'repTel1' :
		case 'repFax1' : if ( e.value.length < 2 ) { msg += " 2자리 이상의"; } break;
		case 'repTel2' :
		case 'repFax2' :
		case 'repCell2':
		case 'conCell2': if ( e.value.length < 3 ) { msg += " 3자리 이상의"; } break;
		case 'repTel3' :
		case 'repFax3' :
		case 'repCell3':
		case 'conCell3': if ( e.value.length < 4 ) { msg += " 4자리"; } break;
	}
	
	return msg;
}


//function enableDisableBanner(f, show)
//{
//	var msg = false;
//	
//	if ( f.changeBanner[0].checked ) { // if Yes is checked
//		if ( f.banner.value.length ) {
//			if ( !isImage(f.banner.value) ) {
//				msg = "현재 배너용 이미지로 선택되어 있는 파일이 허용되지 않거나 이미지 파일이 아닙니다!\n";
//				msg += "허용되는 이미지파일: " + getAllowedFileString("image");
//				if ( show ) {
//					alert(msg);
//				}	
//			}
//		}
//		f.banner.disabled = false;
//	} else {
//		f.banner.disabled = true;
//	}
//	
//	return msg;
//}


function verifyDealerInfo(f)
{
	var msg = false;
	
	// check user id;
	msg = trimTextDealerInfo(f.uID, 0)
	if ( msg ) {
		alert(msg);
		return false;
	}
	// check dealerName;
	msg = trimTextDealerInfo(f.dealerName, 0)
	if ( msg ) {
		alert(msg);
		return false;
	}
	// check password;
	msg = trimTextDealerInfo(f.passwd, 0)
	if ( msg ) {
		alert(msg);
		return false;
	}
	// check confirm password;
	msg = trimTextDealerInfo(f.confPasswd, 0)
	if ( msg ) {
		alert(msg);
		return false;
	}
	// check registration info	
	msg = checkRegInfo(f);
	if ( msg ) {
		alert(msg);
		return false;
	}
	// check representative info
	msg = checkRepInfo(f);
	if ( msg ) {
		alert(msg);
		return false;
	}
	// check contact info
	msg = checkContactInfo(f);
	if ( msg ) {
		alert(msg);
		return false;
	}
	// check home url and banner
	msg = checkHomeURL(f);
	if ( msg ) {
		alert(msg);
		return false;
	}

	msg = checkDealerBanner(f);
	if ( msg ) {
		alert(msg);
		return false;
	}
	
	if ( f.isVerified.value != "1" ) {
		alert("아이디 사용가능 여부를 체크해 주세요!");
		return false;
	}
	
	if ( f.passwd.value != f.confPasswd.value ) {
		alert("입력하신 비밀번호와 확인비밀번호가 일치하지 않습니다!");
		return false;
	}
	
	f.submit();
}

function checkRegInfo(f)
{
	var msg = false;
	
	// regBusName
	msg = trimTextDealerInfo(f.regBusName, 0)
	if ( msg ) {
		return msg;
	}

	// regOwner
	msg = trimTextDealerInfo(f.regOwner, 0);
	if ( msg ) {
		return msg;
	}

	// regNo1/regNo2/regNo3
	msg = trimNumDealerInfo(f.regNo1, 0);
	if ( msg ) {
		return msg;
	}
	msg = trimNumDealerInfo(f.regNo2, 0);
	if ( msg ) {
		return msg;
	}
	msg = trimNumDealerInfo(f.regNo3, 0);
	if ( msg ) {
		return msg;
	}

	// regZipCode/regAddr/regDetailAddr
	msg = trimTextDealerInfo(f.regZipCode, 0);
	if ( msg ) {
		return msg;
	}
	msg = trimTextDealerInfo(f.regAddr, 0);
	if ( msg ) {
		return msg;
	}
	msg = trimTextDealerInfo(f.regDetailAddr, 0);
	if ( msg ) {
		return msg;
	}

	// regType/regSubType
	msg = trimTextDealerInfo(f.regType, 0);
	if ( msg ) {
		return msg;
	}
	msg = trimTextDealerInfo(f.regSubType, 0);
	if ( msg ) {
		return msg;
	}

	return msg;
}


function checkRepInfo(f)
{
	var msg = false;

	// check repName
	msg = trimTextDealerInfo(f.repName, 0);
	if ( msg ) {
		return msg;
	}
	// check tel
	if ( !f.isRepPhone.checked ) {
		msg = trimNumDealerInfo(f.repTel1, 0);
		if ( msg ) {
			return msg;
		}
	}
	if ( !f.isRepPhone.checked ) {
		msg = checkPhoneArea(f.repTel1.value, f.repTel1.name);
		if ( msg ) {
			return msg;
		}
	}
	if ( !f.isRepPhone.checked ) {
		msg = trimNumDealerInfo(f.repTel2, 0);
		if ( msg ) {
			return msg;
		}
	} else {
		msg = trimNumDealerInfo2(f.repTel2, 0);
		if ( msg ) {
			return msg;
		}
	}
//	msg = trimNumDealerInfo(f.repTel2, 0);
//	if ( msg ) {
//		return msg;
//	}
	if ( !f.isRepPhone.checked ) {
		msg = trimNumDealerInfo(f.repTel3, 0);
		if ( msg ) {
			return msg;
		}
	} else {
		msg = trimNumDealerInfo2(f.repTel3, 0);
		if ( msg ) {
			return msg;
		}
	}
	// check fax, not mendatory input
	if ( f.repFax1.value.length && f.repFax2.value.length && f.repFax3.value.length ) {
		msg = trimNumDealerInfo(f.repFax1, 0);
		if ( msg ) {
			return msg;
		}
		msg = checkPhoneArea(f.repFax1.value, f.repFax1.name);
		if ( msg ) {
			return msg;
		}
		msg = trimNumDealerInfo(f.repFax2, 0);
		if ( msg ) {
			return msg;
		}
		msg = trimNumDealerInfo(f.repFax3, 0);
		if ( msg ) {
			return msg;
		}		
	} else if ( f.repFax1.value.length || f.repFax2.value.length || f.repFax3.value.length ) {
		msg = "대표 팩스의 지역번호, 국번, 번호 모두를 입력해 주세요!\n(혹은 필수 입력사항이 아니므로 모두 생략해 주세요!)";
		return msg;
	}
					
	// check cell
	msg = trimNumDealerInfo(f.repCell1, 0);
	if ( msg ) {
		return msg;
	}
	msg = checkCellArea(f.repCell1.value, f.repCell1.name);
	if ( msg ) {
		return msg;
	}
	msg = trimNumDealerInfo(f.repCell2, 0);
	if ( msg ) {
		return msg;
	}
	msg = trimNumDealerInfo(f.repCell3, 0);
	if ( msg ) {
		return msg;
	}

	// email address
	msg = trimTextDealerInfo(f.repEmail1, 0);
	if ( msg ) {
		return msg;
	}
	msg = trimTextDealerInfo(f.repEmail2, 0);
	if ( msg ) {
		return msg;
	}
	msg = checkEmailAccount(f.repEmail1.value, f.repEmail2.value, f.repEmail1.name);
	if ( msg ) {
		return msg;
	}

	// repZipCode/repAddr/repDetailAddr
	msg = trimTextDealerInfo(f.repZipCode, 0);
	if ( msg ) {
		return msg;
	}
	msg = trimTextDealerInfo(f.repAddr, 0);
	if ( msg ) {
		return msg;
	}
	msg = trimTextDealerInfo(f.repDetailAddr, 0);
	if ( msg ) {
		return msg;
	}	
	
	return msg;
}


function checkContactInfo(f)
{
	var msg = false;

	// conName
	msg = trimTextDealerInfo(f.conName, 0)
	if ( msg ) {
		return msg;
	}

	// check cell
	msg = trimNumDealerInfo(f.conCell1, 0);
	if ( msg ) {
		return msg;
	}
	msg = checkCellArea(f.conCell1.value, f.conCell1.name);
	if ( msg ) {
		return msg;
	}
	msg = trimNumDealerInfo(f.conCell2, 0);
	if ( msg ) {
		return msg;
	}
	msg = trimNumDealerInfo(f.conCell3, 0);
	if ( msg ) {
		return msg;
	}

	// email address
	msg = trimTextDealerInfo(f.conEmail1, 0);
	if ( msg ) {
		return msg;
	}
	msg = trimTextDealerInfo(f.conEmail2, 0);
	if ( msg ) {
		return msg;
	}
	msg = checkEmailAccount(f.conEmail1.value, f.conEmail2.value, f.conEmail1.name);
	if ( msg ) {
		return msg;
	}

	return msg;
}


function checkHomeURL(f)
{
	var msg = false;
	
	if ( f.homeURL.value.length ) {
		msg = trimTextDealerInfo(f.homeURL, 0);
		if ( !msg ) {
      var loc = f.homeURL.value.indexOf("http://");
      if ( loc == 0 ) {
        f.homeURL.value = f.homeURL.value.substring(7);
				if ( f.homeURL.value.length == 0 ) {
	 				msg = "홈페이지 주소를 입력하세요!";
	 				return msg;
				}
      } else {
				var incorrect = false;
			  var urlRegExp = new RegExp("^[^@ ]+\.[^@ \.]+$"); 
			  
				//domain should contain at least one dot
				dotIndex = f.homeURL.value.indexOf(".");
				if ( dotIndex == -1 ) { 
					incorrect = true;
				} else if ( (dotIndex < 2) || ((f.homeURL.value.length - dotIndex) < 3) ) { // at least 2 chars before/after the first dot
					incorrect = true;
				} else if ( !f.homeURL.value.match(urlRegExp) ) {
					incorrect = true;
			 	}
				if ( incorrect ) {
					msg = "홈페이지 주소가 올바른 형식이 아닙니다!";
				}
			}
		}
	}
	
 	return msg;
}


function checkDealerBanner(f)
{
	var msg = false;

	if ( f.banner.value.length ) {
		if ( !isImage(f.banner.value) ) {
			msg = "현재 배너용 이미지로 선택되어 있는 파일이 허용되지 않거나 이미지 파일이 아닙니다!\n";
			msg += "허용되는 이미지파일: " + getAllowedFileString("image");
		}
	}
	
	return msg;
}


function checkPhoneArea(aCode, aType)
{
	var msg = false;
	var found = false;
	
	for (i = 0; !found && i < ALLOWED_PHONE_AREA.length; i += 1) {
		if ( aCode == ALLOWED_PHONE_AREA[i] ) {
			found = true;
		}
	}

	if ( !found ) {
		msg = "입력하신 ";
		if ( aType == "repTel1" ) {
			msg += "대표 전화의 ";
		} else {
			msg += "대표 팩스의 ";
		}
		msg += "지역번호가 서비스되고 있지 않습니다!";
	}

	return msg;	
}


function checkCellArea(aCode, aType)
{
	var msg = false;
	var found = false;
	
	for (i = 0; !found && i < ALLOWED_CELL_AREA.length; i += 1) {
		if ( aCode == ALLOWED_CELL_AREA[i] ) {
			found = true;
		}
	}

	if ( !found ) {
		msg = "입력하신 ";
		if ( aType == "repCell1" ) {
			msg += "대표 핸드폰의 ";
		} else if ( aType == "conCell1" ) {
			msg += "담당자 핸드폰의 ";
		} else if ( aType == "cell1-1" ) {
			msg += "1번 핸드폰의 ";
		} else if ( aType == "cell2-1" ) {
			msg += "2번 핸드폰의 ";
		} else if ( aType == "cell3-1" ) {
			msg += "3번 핸드폰의 ";
		} else if ( aType == "cell4-1" ) {
			msg += "4번 핸드폰의 ";
		} else if ( aType == "cell5-1" ) {
			msg += "5번 핸드폰의 ";
		}
		msg += "서비스 식별번호가 서비스되고 있지 않습니다!";
	}

	return msg;	
}


function checkEmailAccount(acct, domainName, eType)
{
	var incorrect = false;
	var msg = false;
	var emailAddr = acct + "@" + domainName;
  var emailRegExp = new RegExp("^[^@ ]+@[^@ ]+\.[^@ \.]+$");

	//domain should contain at least one dot
	dotIndex = domainName.indexOf(".");
	
	if ( dotIndex == -1 ) { 
		incorrect = true;
	} else if ( (dotIndex < 2) || ((domainName.length - dotIndex) < 3) ) { // at least 2 chars before/after the first dot
		incorrect = true;
	} else if ( !emailAddr.match(emailRegExp) ) {
		incorrect = true;
 	}
 	
 	if ( incorrect ) {
  	if ( eType == "repEmail1" ) {
  		msg = "대표 ";
  	} else {
  		msg = "담당자 ";
  	}
    msg += "이메일 주소의 형식이 올바르지 않습니다!";
	}

 	return msg;
}


function isImage(fName)
{
	var found = false;
	var ext = fName.substring(fName.lastIndexOf(".") + 1);

	for (i = 0; !found && i < ALLOWED_IMAGES.length; i += 1) {
		if ( ext.toLowerCase() == ALLOWED_IMAGES[i] ) {
			found = true;
		}
	}
	
	return found;	
}	


function redirectToHome()
{
	document.location.href = ROOT_DIR;
}


function checkDuplicateUID(uid)
{
	uid.value = trimWhiteSpaces(uid.value);
	if ( !uid.value.length ) {
		alert("아이디를 입력하세요");
		uid.focus();
	} else {
		if ( !checkUID(uid.value) ) {
			alert("아이디는 4~16자리의 알파벳 대소문자와 숫자로 이뤄져야 합니다.");
			uid.focus();
			uid.select();
		} else {
		  var w = 470;
		  var h = 220;
		  var wleft = (screen.width - w) / 2;
		  var wtop = (screen.height - h) / 2;
		  var newWin = null;
		    
		  if ( wleft < 0 ) {
		    w = screen.width;
		    wleft = 0;
		  }
		  if ( wtop < 0 ) {
		    h = screen.height;
		    wtop = 0;
		  }
			newWin = window.open(("./duplicate.php?uid=" + uid.value),
														"duplicate",
													 	"resizable=no,scrollbars=no,width=" + w + ",height=" + h + ",top=" + wtop + ",left=" + wleft);
		  newWin.focus();
		}
	}
}	


function checkUID(val)
{
	var i, found;
	
	if ( val.length < 4 || val.length > 16 ) {
		return false;
	} else {
		for ( i = 0, found = false; !found && i < val.length; i += 1 ) {
			if ( val.charCodeAt(i) < 48 || val.charCodeAt(i) > 122 ||
					(val.charCodeAt(i) > 57 && val.charCodeAt(i) < 65) ||
					(val.charCodeAt(i) > 90 && val.charCodeAt(i) < 97) ) {
				found = true;
			}
		}
		if ( found ) {
			return false;
		} else {
			return true;
		}
	}
}


function setUID(uid, available)
{
	if ( available ) {
		opener.top.document.register_01.isVerified.value = "1";
	} else {
		opener.top.document.register_01.isVerified.value = "0";
		opener.top.document.register_01.uID.focus();
		opener.top.document.register_01.uID.select();		
	}
	self.close();
}


function showZipcode(aType)
{
  var w = 470;
  var h = 245;
  var wleft = (screen.width - w) / 2;
  var wtop = (screen.height - h) / 2;
  var newWin = null;
    
  if ( wleft < 0 ) {
    w = screen.width;
    wleft = 0;
  }
  if ( wtop < 0 ) {
    h = screen.height;
    wtop = 0;
  }
	newWin = window.open(("./zipcode.php?act=" + "&aType=" + aType),
												"zipcode",
											 	"resizable=no,scrollbars=no,width=" + w + ",height=" + h + ",top=" + wtop + ",left=" + wleft);
  newWin.focus();
}	


function searchZipcode(aType)
{
  var dongName = document.getElementsByName("dong");

	if ( !dongName[0].value.length ) {
		alert("지역명을 입력하세요!");
		dongName[0].focus();
	} else {
	  var w = 470;
	  var h = 510; // 510 - expanded, 200 - initial
	  var wleft = (screen.width - w) / 2;
	  var wtop = (screen.height - h) / 2;
	  var newWin = null;
	
	  if ( wleft < 0 ) {
	    w = screen.width;
	    wleft = 0;
	  }
	  if ( wtop < 0 ) {
	    h = screen.height;
	    wtop = 0;
	  }
		newWin = window.open(("./zipcode.php?act=search&aType=" + aType + "&dong=" + encodeURI(dongName[0].value)),
													"zipcode",
												 	"resizable=no,scrollbars=no,width=" + w + ",height=" + h + ",top=" + wtop + ",left=" + wleft);
		newWin.moveBy(0, -175);
		newWin.resizeTo(470, 590);
	  newWin.focus();
	}
}


function setZip(sel, aType)
{	
	var selValue = new Array();	

	for (i = 0, found = false; !found && i < sel.length; i += 1) {
		if ( sel.options[i].selected ) {
			found = true;
			selValue = sel.options[i].value.split('|');
		}
	}

	if ( found ) {
		if ( aType == "reg" ) {
			opener.top.document.register_01.regZipID.value = selValue[0];
			opener.top.document.register_01.regZipCode.value = selValue[1];
			opener.top.document.register_01.regAddr.value = selValue[2];
		} else {
			opener.top.document.register_01.repZipID.value = selValue[0];
			opener.top.document.register_01.repZipCode.value = selValue[1];
			opener.top.document.register_01.repAddr.value = selValue[2];
		}
		self.close();
	}
}


function enableDisableRepTell1(fObj)
{
	if ( fObj.isRepPhone.checked ) {
		fObj.repTel1.value = "";
		fObj.repTel1.disabled = true;
	} else {
		fObj.repTel1.disabled = false;
	}
}


function trimNumDealerInfo2(e, show)
{
	var msg = "";

	e.value = trimWhiteSpaces(e.value);
	if ( !isNumber(e.value) ) {
		msg = getMessagePrefix2(e);
		msg += " 숫자만 입력하세요!";
		if ( show ) {
			alert(msg);
		}
	} else {
		msg += getMessageMiddle2(e);
		if ( msg.length ) {
			msg = getMessagePrefix2(e) + msg;
			msg += " 숫자를 입력하세요!";
			if ( show ) {
				alert(msg);
			}
		}
	}

	//if ( msg ) {
	//	e.focus();
	//}

	return msg;
}


function getMessagePrefix2(e)
{
	var msg = "";

	switch (e.name) {
		case 'repTel2' : msg = "대표 전화번호의 국번란에는"; break;
		case 'repTel3' : msg = "대표 전화번호의 번호란에는"; break;
	}

	return msg;
}


function getMessageMiddle2(e)
{
	var msg = "";
		
	switch (e.name) {
		case 'repTel2':
		case 'repTel3': if ( e.value.length < 4 ) { msg += " 4자리"; } break;
	}
	
	return msg;
}

