/*********************************************************************************
 함수명			:	checkString
 파라메터		:	str		-   문장이 공백인지의 여부를 검사하는 함수
 설명			:	입력된 문자열이 값이 없거나 ""으로만 되어있는지 검사하는 함수
 반환값			:	true/false
*********************************************************************************/
function checkString(str) {
	var strLen = 0;
	var maxLen = 0;
	for (var i=0;i<str.length;i++) {
		if (str.charAt(i) == " ")  strLen++;
	}
	if (strLen == str.length) return false;
	else                      return true;
}

/*********************************************************************************
 함수명			:	checkEmail
 파라메터		:	strEmail		-   올바른 이메일 패턴인지 검사할 문자열
 설명			:	입력된 문자열이 이메일 포맷인지여부를 검사하는 함수
 반환값			:	true/false
*********************************************************************************/
function checkEmail(strEmail) {	
	var arrMatch = strEmail.match(/^(\".*\"|[A-Za-z0-9_-]([A-Za-z0-9_-]|[\+\.])*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z0-9][A-Za-z0-9_-]*(\.[A-Za-z0-9][A-Za-z0-9_-]*)+)$/);
	if (arrMatch == null) return false;

	var arrIP = arrMatch[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (arrIP != null) {
		for (var i = 1; i <= 4; i++) {
			if (arrIP[i] > 255)  return false;
   		}
	}
	return true;
}

/*********************************************************************************
 함수명			:	checkIP
 파라메터		:	strIP		-   올바른 IP Address 패턴인지 검사할 문자열
 설명			:	입력된 문자열이 IP Address 포맷인지여부를 검사하는 함수
 반환값			:	true/false
*********************************************************************************/
function checkIP(strIP) {	
	var arrMatch = strIP.match(/^(\".*\"|[A-Za-z0-9_-]([A-Za-z0-9_-]|[\+\.])*).(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z0-9][A-Za-z0-9_-]*(\.[A-Za-z0-9][A-Za-z0-9_-]*)+)$/);
	if (arrMatch == null) return false;

	var arrIP = arrMatch[2].match(/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/);
	if (arrIP != null) {
		for (var i = 1; i <= 4; i++) {
			if (arrIP[i] > 255)  return false;
   		}
	}
	return true;
}

/*****************************************************************************************************
 함수명			:	checkRadio
 파라메터		:	check		-  라디오 버튼이름(window.document.form)까지 여야 할거 같음
 설명			:	입력된 radio 버튼 이름들중에서 체크된 것이 있나없나를 검사하는 함수
 반환값			:	true/false
******************************************************************************************************/
function checkRadio(check) {
	var temp = "no";
	for(var i=0; i < check.length; i++) {
		if (check[i].checked == true) temp = "yes";
	}
	if (temp == "yes") return true;
	else               return false;
}

/*****************************************************************************************
 함수명			:	checkSelect
 파라메터		:	o		-   check box 이름(window.document.form)까지 여야 할거 같음
 설명			:	입력된 오브젝트 check box가 선택되었는가의 여부를 검사하는 함수
 반환값			:	true/false
******************************************************************************************/
function checkSelect(o) {
	if (o.options[0].selected == true) return false;
	else                               return true;
}

/*****************************************************************************************
 함수명			:	checkDate
 파라메터		:	strDate		-   날자형식
 설명			:	입력된 날자가 올바른 날자형식인지 검사하는 함수
 반환값			:	true/false
******************************************************************************************/
function checkDate(strDate) {
	var arrDate;
	var chkDate
	
	if (strDate.indexOf("-") != -1)  arrDate = strDate.split("-");
	else                             arrDate = strDate.split("/");

	if (arrDate.length != 3)         return false;
	
	chkDate = new Date(arrDate[0] + "/" + arrDate[1] + "/" + arrDate[2]);
	
	if (isNaN(chkDate) == true ||
		(arrDate[1] != chkDate.getMonth() + 1 || arrDate[2] != chkDate.getDate())) {
		return false;
	}
	
	return true;
}

function checkDateForm(strDate, chrSplit) {
	var s1, s2;
	s1 = strDate.substr(4,1);
	s2 = strDate.substr(7,1);
	if (s1 == chrSplit && s2 == chrSplit)   return true;
	else                                    return false;
}

/*****************************************************************************************
 함수명			:	checkSSN
 파라메터		:	ssn1		-   주민번호 앞자리
                    ssn2        -   주민번호 뒷자리
 설명			:	올바른 주민등록번호 형태인지 검사하는 함수
 반환값			:	true/false
******************************************************************************************/
function checkSSN(ssn1,ssn2) {
	if ((ssn1.value == "") || (ssn1.value == null))	{
		return false;
	}
	
	var chk =0;
	var yy = ssn1.value.substring(0,2);
	var mm = ssn1.value.substring(2,4);
	var dd = ssn1.value.substring(4,6);
	var sex = ssn2.value.substring(0,1);
	
	if ((ssn1.value.length!=6)||(yy <25||mm <1||mm>12||dd<1)){
		return false;
	}

	if ((sex != 1 && sex !=2 )||(ssn2.value.length != 7 )){
		return false;
	}

	// 주민등록번호 체크//
	for (var i = 0; i <=5 ; i++){ 
		chk = chk + ((i%8+2) * parseInt(ssn1.value.substring(i,i+1)));
	}

	for (var i = 6; i <=11 ; i++){ 
		chk = chk + ((i%8+2) * parseInt(ssn2.value.substring(i-6,i-5)));
	}

	chk = 11 - (chk %11);
	chk = chk % 10;

	if (chk != ssn2.value.substring(6,7)) {
		return false;
	}
	return true;
}

//숫자만
/*****************************************************************************************
 함수명			:	n_check
 파라메터		:	Objectname		-   숫자로 이루어졌는지 체크할 오브젝트
 설명			:	입력된 오브젝트의 값이 숫자로 이루어졌는지 체크하는 함수
 반환값			:	true/false
******************************************************************************************/
function n_check(Objectname) {
	  var intErr
	  var strValue = Objectname.value
	  var retCode = 0

	  for (i = 0; i < strValue.length; i++) {
		var retCode = strValue.charCodeAt(i)
		var retChar = strValue.substr(i,1).toUpperCase()
		retCode = parseInt(retCode)

		if (retChar < "0" || retChar > "9") {
		  intErr = -1;
		  break;
		}
	  }
	  return (intErr);
}


//한글처리
/*****************************************************************************************
 함수명			:	h_check
 파라메터		:	Objectname		-   한글로 이루어졌는지 체크할 오브젝트
 설명			:	입력된 오브젝트의 값이 한글로 이루어졌는지 체크하는 함수
 반환값			:	true/false
******************************************************************************************/
function h_check(Objectname) {
	  var intErr
	  var strValue = Objectname.value
	  var retCode = 0

	  for (i = 0; i < strValue.length; i++) {
		var retCode = strValue.charCodeAt(i)
		var retChar = strValue.substr(i,1).toUpperCase()
		retCode = parseInt(retCode)

		if ((retChar < "0" || retChar > "9") && (retChar < "A" || retChar > "Z") && ((retCode > 255) || (retCode < 0))) {
		//if(retCode < 256)
		  intErr = -1;
		  break;
		}
	  }
	  return (intErr);
	}

/******************************************************************************
 함수명			:	checkNum
 파라메터		:	strValue		-   숫자인지의 여부를 판단하고자 하는값
 설명			:	입력된 값이 숫자인지 아닌지를 판단
 반환값			:	true/false
******************************************************************************/		
function checkNum(strValue){
	if(isNaN(strValue)){
		return false;
	}
	else{
		return true;
	}
}

/******************************************************************************
 함수명			:	CheckStr
 파라메터		:	strOriginal		-   대상이 되는 문자열
					strFind			-	찾고자하는 문자
					strChange		-	대체하고자 하는 문자
 설명			:	문자열중에서 특정 문자를 다른 문제로 대체하고 인식해서 
					문자길이를 알아내는 함수
 반환값			:	vData에서 앞뒤 공백이 제거된 결과
******************************************************************************/
function CheckStr(strOriginal, strFind, strChange){
	var position, strOri_Length;
	position = strOriginal.indexOf(strFind);
				
	while(position !=-1){
		strOriginal = strOriginal.replace(strFind,strChange);
		position = strOriginal.indexOf(strFind);
	}
				
	strOri_Length = strOriginal.length;
	return strOri_Length;
}


/******************************************************************************
 함수명			:	ThisPage_trim
 파라메터		:	vData		-  앞뒤 공백을 제거하기 위한 문자열(?)
 설명			:	vData의 앞뒤 공백을 제거한다.
					위의 ThisPage 에서 this.trim 즉 ThisPage.trim 로 연결됨
 반환값			:	vData에서 앞뒤 공백이 제거된 결과
******************************************************************************/
function ThisPage_trim(vData){
	if(typeof(vData)=='string'){
		var strIn = vData;
		var strOut = '';
		var blnLoop = true;
		if(strIn=='' || strIn==' ') return '';
		strOut = strIn;
		while(blnLoop){
			if(strOut.charAt(0)==' ') strOut=strOut.substr(1);
			else blnLoop=false;
		}
		if(strOut=='' || strOut==' ') return '';
		blnLoop = true;
		while(blnLoop){
			if(strOut.charAt(strOut.length-1)==' ') strOut=strOut.substr(0, strOut.length-1);
			else blnLoop=false;
		}
		return strOut;
	}
	else if(typeof(vData)=='object' && typeof(vData.length)=='number'){
		for(var idxAry=0; idxAry<vData.length; idxAry++)
			vData[idxAry] = this.trim(vData[idxAry]);
		return vData;
	}
	else return(vData);
}

/************************************************************************************************************
 함수명			:	ThisPage_isForm
 파라메터		:	vData		-  페이지의 <Form>에 존재하는 오브젝트인지 검사하는 함수
 설명			:	vData로 넘어온 Form 요소가 실제로 페이지의 Form에 존재하는 요소인지 검사하는 함수
					위의 ThisPage 에서 this.isForm 즉 ThisPage.isForm 로 연결됨
 반환값			:	True/False
************************************************************************************************************/
function ThisPage_isForm(vData){
	if(typeof(vData) == 'undefined') return(false);
	for(var idxAry=0; idxAry<window.document.forms.length; idxAry++)
		if(window.document.forms[idxAry] == vData) break;
	return (idxAry != window.document.forms.length);
}

/******************************************************************************
 함수명			:	ThisPage_isInput
 파라메터		:	vData		- Input 인지 아닌지를 조사하기 위한 오브젝트
 설명			:	vData로 요소가 Input 인지 아닌지를 되돌리는 함수
					위의 ThisPage 에서 this.isInput 즉 ThisPage.isInput 로 연결됨
 반환값			:	True/False
******************************************************************************/
function ThisPage_isInput(vData){
	if(typeof(vData)=='undefined') return(false);
	var strType = this.getType(vData);
	var intLength = this.getLength(vData);
	strType = strType.toLowerCase();
	if(strType!=''){
		for(var idxAry=0; idxAry<this.inputTypes.length; idxAry++)
			if(strType==this.inputTypes[idxAry]) break;
		return (idxAry!=this.inputTypes.length);
	}
	else if(intLength!=0){
		for(var idxAry=0; idxAry<intLength; idxAry++)
			if(!this.isInput(vData[idxAry])) break;
		return (idxAry==intLength);
	}
	else return(false);
}

/******************************************************************************
 함수명			:	ThisPage_isImage
 파라메터		:	vData		-  이미지 인지 아닌지를 조사하기 위한 오브젝트
 설명			:	vData로 요소가 이미지 인지 아닌지를 되돌리는 함수
					위의 ThisPage 에서 this.isImage 즉 ThisPage.isImage 로 연결됨
 반환값			:	True/False
******************************************************************************/
function ThisPage_isImage(vData){
	if(typeof(vData)=='undefined') return(false);
	for(var idxAry=0; idxAry<window.document.images.length; idxAry++)
		if(window.document.images[idxAry]==vData) break;
	return (idxAry!=window.document.images.length);
}

/******************************************************************************
 함수명			:	ThisPage_getTitle
 파라메터		:	vData		-  title을 잡아내기위한 오브젝트
 설명			:	vData로 요소의 title을 되돌리는 함수
					위의 ThisPage 에서 this.getTitle 즉 ThisPage.getTitle 로 연결됨
 반환값			:	vData의 title
******************************************************************************/
function ThisPage_getTitle(vData){
	if(typeof(vData)!='object' || (typeof(vData.title)!='string' && typeof(vData.title)!='number')) return '';
	else return(String(vData.title));
}

/******************************************************************************
 함수명			:	ThisPage_getType
 파라메터		:	vData		-  Type을 잡기위한 데이터
 설명			:	vData로 요소의 타입을 되돌리는 함수
					위의 ThisPage 에서 this.getType 즉 ThisPage.getType 로 연결됨
 반환값			:	vData의 타입
******************************************************************************/
function ThisPage_getType(vData){
	if(typeof(vData)!='object' || (typeof(vData.type)!='string' && typeof(vData.type)!='number')) return '';
	else return(String(vData.type));
}

/******************************************************************************
 함수명			:	ThisPage_getLength
 파라메터		:	vData		-  Length를 알아내기 위한 오브젝트 
 설명			:	vData의 Length를 되돌린다.
					위의 ThisPage 에서 this.getLength 즉 ThisPage.getLength 로 연결됨
 반환값			:	vData의 Length
******************************************************************************/
function ThisPage_getLength(vData){
	if(typeof(vData)!='object' || typeof(vData.length)!='number') return 0;
	else return(Number(vData.length));
}

/******************************************************************************
 함수명			:	phone_check
 파라메터		:	objectname		-  전화번호여부를 체크하게될 object
 설명			:	전화번호여부(0~9, -) 인지를 체크하는 함수
 반환값			:	vData의 Length

 이용예
 if(n_check(window.document.frmMain.txtPhone) == -1){
		alert("연락처 형식에 맞지 않습니다, 숫자 0 ~ 9와 '-'만 입력해주세요");
		window.document.frmMain.txtPhone.value = "";
		window.document.frmMain.txtPhone.focus();
		return;
 }
******************************************************************************/
function phone_check(Objectname) {
	var intErr
	var strValue = Objectname.value
	var retCode = 0

	for (i = 0; i < strValue.length; i++) {
		var retCode = strValue.charCodeAt(i)
		var retChar = strValue.substr(i,1).toUpperCase()
		retCode = parseInt(retCode)

		if ((retChar < "0" || retChar > "9" ) && (retChar != "-")) {
			intErr = -1;
		break;
		}
	}
	return (intErr);
}

/******************************************************************************
 함수명		:	replace_string
 파라메터		:	strOriginal		-   대상이 되는 문자열
					strFind			-	찾고자하는 문자
					strChange		-	대체하고자 하는 문자
 설명			:	문자열중에서 특정 문자를 다른 문제로 대체하는 함수
 반환값		:	
******************************************************************************/
function replace_string(strOriginal, strFind, strChange){
	var position, strOri_Length;
	position = strOriginal.indexOf(strFind);
				
	while(position !=-1){
		strOriginal = strOriginal.replace(strFind,strChange);
		position = strOriginal.indexOf(strFind);
	}
				
	return strOriginal;
}

/***************************************************************************
 함수명		:	insert_comma
 파라메터		:	strValue		-   컴마를 삽입하고자 하는 문자열
					
 설명			:	strValue의 세자리마다 금액표시처럼 컴마를 찍어 되돌리는 함수
 반환값		:	
***************************************************************************/
function insert_comma(strValue){
	
	var num = strValue;
	num = "" + num;
	//alert(num.length);
    if (num.length >= 4) {

		re = /^$|,/g; 

        // "$" and "," 입력 제거 

		num = num.replace(re, ""); 


		fl="" 
		if(isNaN(num)) { alert("문자는 사용할 수 없습니다.");return 0} 
		if(num==0) return num 
                         
		if(num<0){ 
			num=num*(-1) 
			fl="-" 
		}else{ 
			num=num*1 //처음 입력값이 0부터 시작할때 이것을 제거한다. 
		} 
        num = new String(num) 
        temp="" 
        co=3 
        num_len=num.length 
        while (num_len>0){ 
            num_len=num_len-co 
            if(num_len<0){co=num_len+co;num_len=0} 
            temp=","+num.substr(num_len,co)+temp 
        } 
                     
        return fl+temp.substr(1);
	}
	else{
		return num;
	}
}  


/******************************************************************
이미지 비율(가로)에 맞게 변경스크립트
파라미터 : target_img(변경할이미지객체),maxWidth(변경할가로이미지값)
*******************************************************************/
function imgResize(target_img,maxWidth) {
		//maxWidth  = 150;
		var newImg = new Image();
		newImg.src = target_img.src;
		w = newImg.width;
		h = newImg.height;
		if (w > maxWidth) {
			h = (maxWidth * h) / w;
			w = maxWidth;
		}
		target_img.onload = null;
		target_img.src = newImg.src;
		target_img.width = w;
		target_img.height = h;
}

/********************************************************************
이미지 사이즈에 맞게 팝업스크립트
********************************************************************/

function PopImgResize(img){ 
  img1= new Image(); 
  img1.src=(img); 
  imgControll(img); 
} 

function imgControll(img){ 
  if((img1.width!=0)&&(img1.height!=0)){ 
    viewImage(img); 
  } 
  else{ 
    controller="imgControll('"+img+"')"; 
    intervalID=setTimeout(controller,20); 
  } 
} 

function viewImage(img){ 
 W=img1.width; 
 H=img1.height; 
 O="width="+W+",height="+H; 
 imgWin=window.open("","",O); 
 imgWin.document.write("<html><head><title>미리보기</title></head>");
 imgWin.document.write("<body topmargin=0 leftmargin=0>");
 imgWin.document.write("<img src="+img+" onclick='self.close()'>");
 imgWin.document.close();

}



function phone_check(strString) {
  var intErr
  var retCode = 0

  for (i = 0; i < strString.length; i++) {
	var retCode = strString.charCodeAt(i)
	var retChar = strString.substr(i,1).toUpperCase()
	retCode = parseInt(retCode)

	if (((retChar >= "0" && retChar <= "9") || retChar == "-") != true){
	  intErr = -1;
	  //alert("aa");
	  break;
	}
	//alert("bb");
  }
  return (intErr);



}
function win_open(url,scrollbars,width,height,left,top) //method = width,height,left,top
{
		window.open(url,'','scrollbars='+scrollbars+',width='+width+',height='+height+',left='+left+',top='+top+'')
}

function ObjectControl(a)
{
	document.write(a)
}
function GotoUrl(url,index)
{
	form = document.form1
	if (index!="")
	{
		form.index.value = index
	}
	form.action = url
	form.method = "post"
	form.submit()
}
function frmProductSearch()
{
	form = document.form1
	form.action = "/customerCenter/ProductSearch.asp"
	form.method = "post"
	form.submit()
}
