var Class = {
			  create: function() {
			    return function() {
			      this.initialize.apply(this, arguments);
			    }
			  }
			}


function addEvent(obj, type, fn)   
{   
    if (obj.addEventListener)   
        obj.addEventListener(type, fn, false);   
    else if (obj.attachEvent)   
    {   
        obj["e"+type+fn] = fn;   
        obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }   
        obj.attachEvent("on"+type, obj[type+fn]);   
    }   
}  

	
function createXMLHttpRequest(_obj) {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
    
}


function getRealOffsetTop(el) {
	
    return el ? el.offsetTop + getRealOffsetTop(el.offsetParent) : 0;
}

 

function getRealOffsetLeft(el) {
    return el ? el.offsetLeft + getRealOffsetLeft(el.offsetParent) : 0;
}



/* -----------------------------------------------------------------------------------
*  Description: 정규치환
*  Parameters: strValue 문자열, strReceptor 수용기, strEffector 작용기
----------------------------------------------------------------------------------- */
function replaceRegExp(strValue, strReceptor, strEffector){
	var objRegExp = new RegExp(strReceptor, "gi"); //정규식선언
	strValue = strValue.replace(objRegExp, strEffector);
	return strValue;
}
 
/* -----------------------------------------------------------------------------------
*  Description: 공백제거
*  Parameters: numType 타입(0 완전제거, 1 한칸으로제거)
*              strValue(입력값)
----------------------------------------------------------------------------------- */
function removeSpace(strValue, numType){
	var strEffector = ""; //작용기
	if (parseInt(numType) > 0) strEffector = " ";
	
	strValue = strValue.replace(/^\s*/, "").replace(/\s*$/, ""); //전후공백제거
	strValue = replaceRegExp(strValue, "\\s+", strEffector); //공백제거
	return strValue;
}

/* -----------------------------------------------------------------------------------
*  Description: 특수기호제거
*  Parameters: strValue(입력값)
----------------------------------------------------------------------------------- */
function removeMark(strValue){
	strValue = replaceRegExp(strValue, "[+@=*@<>()`\\,\\[\\]\"'\\\\]", " "); //특수기호제거
	strValue = removeSpace(strValue, 1); //공백제거:0(전체공백제거),1(다수공백제거)
	
	return strValue;
}

/* -----------------------------------------------------------------------------------
*  Description: 변수 초기화
*  Parameters: strType(자료형)- 'num'
*              strValue(입력값)
*              strInitValue(초기값)
----------------------------------------------------------------------------------- */
function checkNull(strValue, numType, strInitValue){
	if(typeof strValue == 'undefined' || strValue == null) strValue = ""; //초기화
	if(typeof strInitValue == 'undefined' || strInitValue == null) strInitValue = ""; //교정값초기화
	
	if(parseInt(numType) == 1){ //숫자형
		var objRegExp = /[^\d]/;
		while(objRegExp.test(strValue)) strValue = strValue.replace(objRegExp, ""); //숫자이외제거
	}
	if(strValue.length == 0) strValue = strInitValue; //교정값입력
	return strValue;
}


/* -----------------------------------------------------------------------------------
*  Description: 쿠키저장
*  Parameters: strField(쿠키필드명)
*              strValue(입력값)
*              strTerm(쿠키저장기간-일기준)
----------------------------------------------------------------------------------- */
function setSrchCookie(strField, strValue, strTerm){
	var objDateExpires = new Date();
	strTerm = checkNull(strTerm, 1, "1"); //변수초기화
	objDateExpires.setTime(objDateExpires.getTime() + 1000*60*60*24*parseInt(strTerm));

	document.cookie = strField + "=" + escape(strValue) + ";expires=" + objDateExpires.toGMTString();
}



/* -----------------------------------------------------------------------------------
*  Description: 쿠키불러오기
*  Parameters: strField(쿠키필드명)
----------------------------------------------------------------------------------- */
function getSrchCookie(strField){
	//초기화
	var strValue = ""; //쿠키필드값(반환값)
  
	strField += "=";

	if(document.cookie.length > 0) //쿠키존재확인
	{
		var numPointBegin = document.cookie.indexOf(strField); //쿠키필드값존재확인
    
		if(numPointBegin != -1)
		{
			numPointBegin += strField.length;
			numPointEnd = document.cookie.indexOf(';', numPointBegin);

			if(numPointEnd == -1)
			{
				numPointEnd = document.cookie.length;
			}
			strValue = unescape(document.cookie.substring(numPointBegin, numPointEnd)); //쿠키필드값입력
		}
	}
	return strValue;
}

/* -----------------------------------------------------------------------------------
*  Description: 이미지필드변경
*  Parameters: strNode(실행노드)- 'parent.'; ''
*              strField(필드명)
*              strValue(입력값)
*              numStatus- 0(불가); 1(실행)
----------------------------------------------------------------------------------- */
function changeImg(strNode, strField, strValue, numStatus){
	if(parseInt(numStatus) > 0){
		var objField = eval(strNode + "document"); //프레임선언
		objField.images[strField].src = "/search/" + strValue; //이미지변경
	}
}

/* -----------------------------------------------------------------------------------
*  Description: HTML필드변경(innerHTML)
*  Parameters: strNode(실행노드)- 'parent.'; ''
*              strField(필드명)
*              strValue(입력값)
*              numStatus- 0(불가); 1(실행)
----------------------------------------------------------------------------------- */
function changeTxt(strNode, strField, strValue){
	var objField = eval(strNode + "document.all." + strField); //필드객체선언
	objField.innerHTML = strValue;
}

/* -----------------------------------------------------------------------------------
*  Description: 문자열길이제한
*  Parameters: strValue 입력값, numLimitLength 제한길이
----------------------------------------------------------------------------------- */
function getSubstring(strValue, limitLen, ellipsis){
	var pos = 0; //현위치게이지
  
	if(strValue.length > (limitLen / 2)){
		for (var i = 0; i < strValue.length; i++){
			pos += (strValue.charCodeAt(i) > 127)? 2 : 1; //2byte,1byte문자
      
			if(pos > limitLen){ //제한길이초과시
				strValue = strValue.substring(0, i) + ellipsis; //후미생략기호추가
				break;
			}
		}
	}
	return strValue;
}


//한글분해 Map
var firstSoundsMap = new Array(
			"ㄱ", "ㄲ", "ㄴ", "ㄷ", "ㄸ", "ㄹ", "ㅁ", "ㅂ", "ㅃ", "ㅅ",
			"ㅆ", "ㅇ", "ㅈ", "ㅉ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"); //초성
var middleSoundsMap = new Array(
			"ㅏ", "ㅐ", "ㅑ", "ㅒ", "ㅓ", "ㅔ", "ㅕ", "ㅖ", "ㅗ", "ㅗㅏ",
			"ㅗㅐ", "ㅗㅣ", "ㅛ", "ㅜ", "ㅜㅓ", "ㅜㅔ", "ㅜㅣ", "ㅠ", "ㅡ", "ㅡㅣ",
			"ㅣ"); //중성
var lastSoundsMap = new Array(
			"", "ㄱ", "ㄲ", "ㄱㅅ", "ㄴ", "ㄴㅈ", "ㄴㅎ", "ㄷ", "ㄹ", "ㄹㄱ",
			"ㄹㅁ", "ㄹㅂ", "ㄹㅅ", "ㄹㅌ", "ㄹㅍ", "ㄹㅎ", "ㅁ", "ㅂ", "ㅂㅅ", "ㅅ",
			"ㅆ", "ㅇ", "ㅈ", "ㅊ", "ㅋ", "ㅌ", "ㅍ", "ㅎ"); //종성

//한글조합 Map
var firstSoundsEngMap = new Array(
			"r", "R", "s", "e", "E", "f", "a", "q", "Q", "t",
			"T", "d", "w", "W", "c", "z", "x", "v", "g"); //초성

var middleSoundsEngMap = new Array(
			"k", "o", "i", "O", "j", "p", "u", "P", "h", "hk", 
			"ho", "hl", "y", "n", "nj", "np", "nl", "b", "m", "ml",
			"l"); //중성

var lastSoundsEngMap = new Array(
			"", "r", "R", "rt", "s", "sw", "sg", "e", "f", "fr", "fa",
			"fq", "ft", "fx", "fv", "fg", "a", "q", "qt", "t", "T",
			"d", "w", "c", "z", "x", "v", "g"); //종성


/**
* 한글분해
* @param strValue 입력값, numAcDrt 방향(0 양쪽, 1 정방, 2 역방)
**/
function disassembleHangul(strValue, numAcDrt){
	var ordinaryVal = ""; //한글분해 정방
	var reverseVal = ""; //한글분해 역방
	var tempVal = "";
	strValue = removeSpace(removeMark(strValue), 0);				
	for(var i = 0; i < strValue.length; i++){
		var numCharValue = (strValue.charCodeAt(i) - 0xAC00); //44032
		
		if(numCharValue < 0 || numCharValue > 11172){ //한글이외 및 한글자음 처리
			tempVal = strValue.charAt(i);

		}else{ //한글 처리
			tempVal = firstSoundsMap[Math.floor(numCharValue / 588)];
			tempVal += middleSoundsMap[Math.floor((numCharValue % 588) / 28)];
			tempVal += lastSoundsMap[Math.floor((numCharValue % 588) % 28)];
		}
		
		ordinaryVal += tempVal;
		reverseVal = tempVal + reverseVal;
	}
	switch(parseInt(numAcDrt)){
		case 0:
			//strValue = "<word>" + ordinaryVal + "<in>acField";
			strValue = ordinaryVal;
		break;
		case 1:
			//strValue = "<word>" + reverseVal + "<in>acFieldR";
			strValue = reverseVal;
		break;
		default:
			//strValue = "<word>" + ordinaryVal + "<in>(acField,acFieldR)";
			strValue = ordinaryVal;
		break;
	}
	return strValue;
}

function disassembleHangul2(strValue, numAcDrt){
	var ordinaryVal = ""; //한글분해 정방
	var reverseVal = ""; //한글분해 역방
	var tempVal = "";
	strValue = removeSpace(removeMark(strValue), 0);				
	
	for(var i = 0; i < strValue.length; i++){
		var numCharValue = (strValue.charCodeAt(i) - 0xAC00); //44032
		
		if(numCharValue < 0 || numCharValue > 11172){ //한글이외 및 한글자음 처리
			tempVal = strValue.charAt(i);

		}else{ //한글 처리
			tempVal = firstSoundsEngMap[Math.floor(numCharValue / 588)];
			tempVal += middleSoundsEngMap[Math.floor((numCharValue % 588) / 28)];
			tempVal += lastSoundsEngMap[Math.floor((numCharValue % 588) % 28)];
		}
		
		ordinaryVal += tempVal;
		reverseVal = tempVal + reverseVal;
	}
	
	switch(parseInt(numAcDrt)){
		case 0:
			//strValue = "<word>" + ordinaryVal + "<in>acField";
			strValue = ordinaryVal;
		break;
		case 1:
			//strValue = "<word>" + reverseVal + "<in>acFieldR";
			strValue = reverseVal;
		break;
		default:
			//strValue = "<word>" + ordinaryVal + "<in>(acField,acFieldR)";
			strValue = ordinaryVal;
		break;
	}
	
	return strValue;
}

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/gi, ""); 
} 
String.prototype.strip = function() {
    return this.replace(/^\s+/, '').replace(/\s+$/, '');
}
String.prototype.stripTags = function() {
    return this.replace(/<\/?[^>]+>/gi, '');
}

function assembleHangul(strValue){
	// 변수 초기화
	var firstSoundsEngMapCode = 0;
	var middleSoundsEngMapCode  = 0;
	var lastSoundsEngMapCode   = 0;
	
	var resultValue = "";

	for(var idx=0; idx<strValue.length; idx++){
		
		//초성
		firstSoundsEngMapCode = getHangulCode('firstSoundsEngMap', strValue.substring(idx, idx+1));
		idx++;
		
		//중성
		tempMedialCode = getHangulCode('middleSoundsEngMap', strValue.substring(idx, idx+2));

		if( tempMedialCode != -1 ){
			middleSoundsEngMapCode = tempMedialCode;
			idx += 2;

		}else{
			middleSoundsEngMapCode = getHangulCode('middleSoundsEngMap', strValue.substring(idx, idx+1));
			idx++;
		}

		//종성
		tempFinalCode = getHangulCode('lastSoundsEngMap', strValue.substring(idx, idx+2));

		if( tempFinalCode != -1){
			lastSoundsEngMapCode = tempFinalCode;
			tempMedialCode = getHangulCode('middleSoundsEngMap', strValue.substring(idx+2, idx+3));
	
			if( tempMedialCode != -1){
				lastSoundsEngMapCode = getHangulCode('lastSoundsEngMap', strValue.substring(idx, idx+1));
			}else{
				idx++;
			}
		}else{
			tempMedialCode = getHangulCode('middleSoundsEngMap', strValue.substring(idx+1, idx+2));
	
			if( tempMedialCode != -1 ){
				lastSoundsEngMapCode = 0;
				idx--;
			}else{
				lastSoundsEngMapCode = getHangulCode( 'lastSoundsEngMap', strValue.substring( idx, idx + 1 ) );
				if( lastSoundsEngMapCode == -1 ) lastSoundsEngMapCode = 0;
			}
		}
	
		resultValue += String.fromCharCode(0xAC00 + firstSoundsEngMapCode + middleSoundsEngMapCode + lastSoundsEngMapCode);
	}
	
	return resultValue;
}

function getHangulCode( typeVar, charVar ){
	var returnCode; // 리턴 코드 저장 변수
	var isFind = false; // 문자를 찾았는지 체크 변수

	if( typeVar == 'firstSoundsEngMap' ){
		for( var i = 0; i < firstSoundsEngMap.length; i++ ){
			if( firstSoundsEngMap[i] == charVar ){
				returnCode = i * 21 * 28;
				isFind = true;
				break;
			}
		}
	}else if( typeVar == 'middleSoundsEngMap' ){
		for( var i = 0; i < middleSoundsEngMap.length; i++ ){
			if( middleSoundsEngMap[i] == charVar ){
				returnCode = i * 28;
				isFind = true;
				break;
			}
		}
	}else if( typeVar == 'lastSoundsEngMap' ){
		for( var i = 0; i < lastSoundsEngMap.length; i++ ){
			if( lastSoundsEngMap[i] == charVar ){
				returnCode = i + 1;
				isFind = true;
				break;
			}
		}
	}
	if( isFind == false ) returnCode = -1; // 값을 찾지 못했을 경우 -1 리턴
	return returnCode;
}


function onThumbImg(img){
	
	if(img){
		document.getElementById("thumb").src =  thumbImgArray[img];
		document.getElementById("imgLink").href = thumbUrlArray[img]; // 
		document.getElementById("modelName").innerHTML=  thumbModelArray[img];
		document.getElementById("thumbDiv").style.display = "";
	}
}

function offThumbImg(){
	document.getElementById("thumbDiv").style.display = "none";
}



