












var gs_PB01_ENV = "";
var gs_PB02_ENV = "";
var gs_PA01_ENV = "";
var gs_PN01_ENV = "";
var gs_PD01_ENV = "";
var gs_PD02_ENV = "";




function gf_UserEnv(as_val){

	switch(as_val){
		case "B" :
			if(gs_PB01_ENV.length > 0) {
				var arrEnv01 = gs_PB01_ENV.split("@");
				var oType = document.getElementById("chkGubunAll");
				if( arrEnv01[0].indexOf("All") > -1) {					
					
				} else {
					if(oType != null && oType != undefined ) oType.checked= false;					
					var oTypes = document.getElementsByName("chkGubun");
					for( var idx=0; idx < oTypes.length ; idx++){
						if(arrEnv01[0].indexOf(oTypes[idx].value) > -1) oTypes[idx].checked = true;					
					}					
				}
				
				if(arrEnv01.length > 1) {
					var oScopes = document.getElementsByName("chkScope");
					if(oScopes != null && oScopes != undefined ){
						for( var idx=0; idx < oScopes.length ; idx++){
							if(arrEnv01[1].indexOf(oScopes[idx].value) > -1) oScopes[idx].checked = true;		
						}
					}
				}
				
				if(arrEnv01.length > 2) {
					var oStates = document.getElementsByName("chkState");
					if(oStates != null && oStates != undefined ){
						for( var idx=0; idx < oStates.length ; idx++){
							if(arrEnv01[2].indexOf(oStates[idx].value) > -1) oStates[idx].checked = true;	
						}
					}
				}
			}
			
			if(gs_PB02_ENV.length >0){
		
				var arrVal = gs_PB02_ENV.split(",");
				var oChk = document.getElementsByName("chkField");
				for(var idx=0; idx < oChk.length; idx++){
					oChk[idx].checked= false;
					for(var jdx=0; jdx < arrVal.length; jdx++) {
						if(oChk[idx].value ==  arrVal[jdx]) oChk[idx].checked= true;
					}
				}
			}
			break;
			
		case "A" :
			if(gs_PA01_ENV.length > 0) {

				var arrEnv01 = gs_PA01_ENV.split("@");
				if( arrEnv01[0].indexOf("All") > -1) {
					var oType = document.getElementById("chkGubunAll");
					if(oType != null && oType != undefined ) oType.checked= true;
				} else {
					var oTypes = document.getElementsByName("chkGubun");
					for( var idx=0; idx < oTypes.length ; idx++){
						if(arrEnv01[0].indexOf(oTypes[idx].value) > -1) oTypes[idx].checked = true;					
					}					
				}
				
				var oScopes = document.getElementsByName("chkScope");
				if(oScopes != null && oScopes != undefined ){
					for( var idx=0; idx < oScopes.length ; idx++){
						if(arrEnv01[1].indexOf(oScopes[idx].value) > -1) oScopes[idx].checked = true;		
					}
				}
				var oStates = document.getElementsByName("chkState");
				if(oStates != null && oStates != undefined ){
					for( var idx=0; idx < oStates.length ; idx++){
						if(arrEnv01[2].indexOf(oStates[idx].value) > -1) oStates[idx].checked = true;	
					}
				}
			}
			break;
			
		case "N" :
			if(gs_PN01_ENV.length > 0) {
				var oChk = document.getElementsByName("chkGubun");
				for(var idx=0; idx < oChk.length; idx++){
					if(gs_PN01_ENV.indexOf(oChk[idx].value) > -1) oChk[idx].checked = true;
				}
			}
			break;
			
		case "D" :
			if(gs_PD01_ENV.length > 0) {
				var arrEnv01 = gs_PD01_ENV.split("@");				
				var oStates = document.getElementsByName("chkState");
				if(oStates != null && oStates != undefined ){					
					for( var idx=0; idx < oStates.length ; idx++){
						oStates[idx].checked= false;
						if(arrEnv01[2].indexOf(oStates[idx].value) > -1) oStates[idx].checked = true;	
					}
				}
			}
			
			if(gs_PD02_ENV.length >0){
				var arrVal = gs_PD02_ENV.split(",");
				var oChk = document.getElementsByName("chkField");
				for(var idx=0; idx < oChk.length; idx++){
					for(var jdx=0; jdx < arrVal.length; jdx++) {
						if(oChk[idx].value ==  arrVal[jdx]) oChk[idx].checked= true;
					}
				}
			}
			break;
	}
}


/*=======================================================================================
	함수명 : cfg_ddsRequset / getResult / cgf_ddsRequestOpen	
	기  능 : 특허정보  원문복사 신청 함수 - /js/common/favorite_patent.jsp와 같은 함수이다.
	             양쪽 싱크 맞춰야한다.
	인  수 : 
	RETURN : 
=========================================================================================*/
function cfg_ddsRequset(chk){

	//로그인 여부 check 이전에 필요
	
		lf_openConfirm();	
		return;
	
//alert(chk);
	// logsave
//	cgf_KISTILogSave2("", "SS22", "PATENT", "V08", "", "1", "", "", "04");
	var ochk = document.getElementsByName(chk);
	var sval = "";
	for(var i=0; i < ochk.length; i++){
		if(ochk[i].checked) sval += ochk[i].value + "|";
			
	}	
	var url = "/ddsrequestsrch.co";
	var param = "colid=3&keys=" + sval ; 
	
	sendMainRequest(url,param,"POST");

	
	
	return;
}

function cfg_ddsRequset2(as_val){
	//로그인 여부 check 이전에 필요
	
		lf_openConfirm();	
		return;
	
	
	// logsave
//	cgf_KISTILogSave2("", "SS22", "PATENT", "V08", "", "1", "", "", "04");

	var url = "/ddsrequestsrch.co";
	var param = "colid=3&keys=" + as_val ; 	
	sendMainRequest(url,param,"POST");
	
	return;
}



function getResult(as_Txt){
	if(as_Txt != "") {		
		var xmlDoc = cfg_ddsXmlMake(as_Txt);
		cgf_ddsRequestOpen(xmlDoc);
	} 
	return;
}


var gs_DDS_HEADER = "PatentList";
var gs_DDS_DATA_HEAD = "Patent";
var gs_DDS_TITLE 	= "TI";
var gs_DDS_AN 	= "AN";
var gs_DDS_UN 	= "UN";
var gs_DDS_PA 	= "PA";
var gs_DDS_CN 	= "CN";

function cfg_ddsXmlMake(val){
	
	
	var arrValue = val.split("☆");
	
	var strTitle = ""; 	//발명의 명칭
	var strAN = "";		//출원번호
	var strAD = "";		//출원일자
	var strUN = "";		//공개번호
	var strUD = "";		//공개일자
	var strPi = "";		//출판상태
	var strPa = "";		//출원인
	var strCn = "";		//관리번호
	
	var xmlDoc = cfg_CreateDom();
	var PInode = xmlDoc.createProcessingInstruction("xml","version='1.0' encoding='utf-8'");
	var rootNode = xmlDoc.createElement(gs_DDS_HEADER);
		
	
	xmlDoc.appendChild(PInode);
	xmlDoc.appendChild(rootNode);
	
	
	for (var idx =0; idx < arrValue.length; idx ++){
		
		var chkString = arrValue[idx];
		var arrString = chkString.split("▶");
		
		if(arrString.length > 7 ){
			strTitle = arrString[1]; 	//발명의 명칭
			strAN = arrString[2];		//출원번호
			strAD = arrString[3];		//출원일자
			strUN = arrString[4];		//공개번호
			strUD = arrString[5];		//공개일자
			strPi = arrString[6];		//출판상태
			strPa = arrString[7];		//출원인
			strCn = arrString[0];		//관리번호
			
			
			var dataNode = xmlDoc.createElement(gs_DDS_DATA_HEAD);
			var titleNode = xmlDoc.createElement(gs_DDS_TITLE);
			var anNode = xmlDoc.createElement(gs_DDS_AN);
			var unNode = xmlDoc.createElement(gs_DDS_UN);
			var paNode = xmlDoc.createElement(gs_DDS_PA);
			var cnNode = xmlDoc.createElement(gs_DDS_CN);
			
			var titleTextNode = xmlDoc.createTextNode(strTitle);
			if(strAD != "")
				var anTextNode = xmlDoc.createTextNode(strAN + " (" + strAD + ")");
			else
				var anTextNode = xmlDoc.createTextNode(strAN);
				
			var TempStr = "";	
			if(strPi != "") TempStr = strUN + " [" + strPi + "]";
			else 		TempStr = strUN;
			
			if(strUD != "") TempStr += " (" + strUD + ")";
			
			var unTextNode = xmlDoc.createTextNode(TempStr);
			var paTextNode = xmlDoc.createTextNode(strPa);
			var cnTextNode = xmlDoc.createTextNode(strCn);
			
			
			rootNode.appendChild(dataNode);	
			dataNode.appendChild(titleNode);
			titleNode.appendChild(titleTextNode);
			
			dataNode.appendChild(anNode);
			anNode.appendChild(anTextNode);
			
			dataNode.appendChild(unNode);
			unNode.appendChild(unTextNode);
			
			dataNode.appendChild(paNode);
			paNode.appendChild(paTextNode);
			
			dataNode.appendChild(cnNode);
			cnNode.appendChild(cnTextNode);			
		}
	}
	return 	xmlDoc.xml;
}


function cfg_CreateDom(){
	var domObj;

	if (window.ActiveXObject)
	{
		domObj = new ActiveXObject("Microsoft.XMLDOM");
		
	} else {
		// code for Mozilla, Firefox, Opera..
		var parser = new DOMParser();
		domObj = parser.parseFromString(req.responseText, "text/xml");
	}
	return domObj;
	
}


function cgf_ddsRequestOpen(xmldata){

	var memberid = "";
	var libid = "";
		
	if ((memberid == "" || memberid == "null") && libid == "etc") {
		CenterWindow('/jsp/common/dds/com_popup_help1.jsp', 'Warning', 500, 600, 0,0);
		return;
	} else if (memberid == "" || memberid =="null") {
	       	document.ddsrequestinfo.action = "/ddsrequest.co";
	} else {
	       	document.ddsrequestinfo.action = "/kistiddsrequest.co";
	}
	window.open("", "ddsWin", "width=807, height=700, scrollbars=1, menubars=0, status=0");
	document.ddsrequestinfo.target = "ddsWin";	       		
	//document.ddsrequestinfo.action = "/ddsrequest.co";
	document.ddsrequestinfo.method = "post";
	document.ddsrequestinfo.ddstype.value = 'p';
	document.ddsrequestinfo.ddsvalue.value = xmldata;
	document.ddsrequestinfo.submit();	
	
}


/* paten 고유 함수 (사용자 초기화페이지 저장) */
function gf_setUserInitPage(as_val){
	var url = "/mysearchenv.co";
	var params = "ajaxID=SaveInitPage";
	params +="&gubun=3";
	params +="&value=" + as_val;
	
	lf_openConfirm();
	
}

function gf_setUserSrchEnv(as_gubun, as_val){
	var url = "/mysearchenv.co";
	var params = "ajaxID=SaveSrchEnv";
	params +="&gubun=" + as_gubun;
	params +="&value=" + as_val;
	
	lf_openConfirm();
	

}

function gf_Result(as_data){
	alert(as_data);
}



function gf_SaveSrchEnv(as_gubun){
	var sRetVal = "";
	if(as_gubun == "PB01" || as_gubun == "PA01" || as_gubun == "PD01"){		
		sRetVal = "";
		var oType = document.getElementById("chkGubunAll");
		if(oType != null && oType != undefined ){
			if(oType.checked){
				sRetVal = "All,";
			} else {
				var oTypes = document.getElementsByName("chkGubun");
				for( var idx=0; idx < oTypes.length ; idx++){
					if(oTypes[idx].checked) sRetVal += oTypes[idx].value + ",";					
				}
			}
			if(sRetVal !="" && sRetVal.length >1) sRetVal = sRetVal.substring(0, sRetVal.length-1);
		}
		sRetVal += "@";
		var oScopes = document.getElementsByName("chkScope");
		if(oScopes != null && oScopes != undefined ){
			for( var idx=0; idx < oScopes.length ; idx++){
				if(oScopes[idx].checked) sRetVal += oScopes[idx].value + ",";
			}
			if(sRetVal !="" && sRetVal.length >1) sRetVal = sRetVal.substring(0, sRetVal.length-1);
		}		
		sRetVal += "@";
		var oStates = document.getElementsByName("chkState");
		if(oStates != null && oStates != undefined ){
			for( var idx=0; idx < oStates.length ; idx++){
				if(oStates[idx].checked) sRetVal += oStates[idx].value + ",";
			}
			if(sRetVal !="" && sRetVal.length >1) sRetVal = sRetVal.substring(0, sRetVal.length-1);				
		}
	}else if(as_gubun == "PB02" || as_gubun == "PD02"){
		var oChk = document.getElementsByName("chkField");
		for(var idx=0; idx < oChk.length; idx++){
			if(oChk[idx].checked) sRetVal += oChk[idx].value + ",";
		}
		if(sRetVal !="" && sRetVal.length >1) sRetVal = sRetVal.substring(0, sRetVal.length-1);				
	}else if(as_gubun == "PN01"){
		var oChk = document.getElementsByName("chkGubun");
		for(var idx=0; idx < oChk.length; idx++){
			if(oChk[idx].checked) sRetVal += oChk[idx].value ;
		}
	}
	gf_setUserSrchEnv(as_gubun, sRetVal);
}

/* history 조합검색 */
function lf_CombineSearch(seq, dpid, vquery, equery, dquery){
		var arrEdit = new Array();
		var arrCol = new Array();
		arrEdit = equery.split("@");
		var sDBtype = "";
		var sScope = "";
		var sState = "";
		
		for (var i=1; i < arrEdit.length ; i++){
			arrCol = arrEdit[i].split(":");
			if(arrCol[0] == "chkGubun"){
				switch(arrCol[1]){
					case "ko" :
						sDBtype = sDBtype |  parseInt(1);		
						break;
					case "us" :
						sDBtype = sDBtype |  parseInt(2);		
						break;
					case "ep" :
						sDBtype = sDBtype |  parseInt(4);		
						break;
					case "wo" :
						sDBtype = sDBtype |  parseInt(8);		
						break;
					case "ja" :
						sDBtype = sDBtype |  parseInt(16);		
						break;
					default :
						break;
				
				}
			} else if(arrCol[0] == "chkScope") {
				if(arrCol[1] == "10") sScope += "특허,";
				else if (arrCol[1] == "20") sScope += "실용,";
				if(sScope !="" && sScope.length >1) sScope = sScope.substring(0, sScope.length-1);
			} else if(arrCol[0] == "chkState") {
				if(arrCol[1] == "P") sState += "공개,";
				else if (arrCol[1] == "R") sState += "공고/등록,";
				if(sState !="" && sState.length >1) sState = sState.substring(0, sState.length-1);
			}
			
		}
		document.SearchForm.dp_type.value = sDBtype;
		document.SearchForm.dp_scope.value = sScope;
		document.SearchForm.dp_state.value = sState;
		document.SearchForm.vquery.value = vquery;
		document.SearchForm.dquery.value = dquery;
		document.SearchForm.equery.value = equery;
		document.SearchForm.isHistorySave.value = "true";
		document.SearchForm.historySeq.value = seq;			
		document.SearchForm.submit();
}


function lf_reExecute(seq, dispid, cType)
{
	http = jQuery.ajax( {
		url: "/getHistory.co",
		type: "POST",
		data: {	seq: seq},
		complete:function(res, status) {
			result = jQuery.trim(res.responseText);
			arrQuery = result.split("★");
			viewquery = arrQuery[0];
			if(arrQuery.length > 1) editquery = arrQuery[1];
			if(arrQuery.length > 2) dispquery = arrQuery[2];
			lf_ReRun(seq, dispid, viewquery, editquery, dispquery,  cType);
		}
	});
}

/* 재실행 */
function lf_ReRun(seq, dpid, vquery, equery, dquery, cType){
		var arrEdit = new Array();
		var arrCol = new Array();
		
		arrEdit = equery.split("@");
		var sDBtype = "";
		var sScope = "";
		var sState = "";				
		
		for (var i=1; i < arrEdit.length ; i++){
			arrCol = arrEdit[i].split(":");
			if(arrCol[0] == "chkGubun"){
				switch(arrCol[1]){
					case "ko" :
						sDBtype = sDBtype |  parseInt(1);		
						break;
					case "us" :
						sDBtype = sDBtype |  parseInt(2);		
						break;
					case "ep" :
						sDBtype = sDBtype |  parseInt(4);		
						break;
					case "wo" :
						sDBtype = sDBtype |  parseInt(8);		
						break;
					case "ja" :
						sDBtype = sDBtype |  parseInt(16);		
						break;
					default :
						break;
				
				}
			} else if(arrCol[0] == "chkScope") {
				if(arrCol[1] == "10") sScope += "특허,";
				else if (arrCol[1] == "20") sScope += "실용,";
				if(sScope !="" && sScope.length >1) sScope = sScope.substring(0, sScope.length-1);
			} else if(arrCol[0] == "chkState") {
				if(arrCol[1] == "P") sState += "공개,";
				else if (arrCol[1] == "R") sState += "공고/등록,";
				if(sState !="" && sState.length >1) sState = sState.substring(0, sState.length-1);
			}
			
		}
		if(cType == "F"){
			document.SearchForm.bexecute_flag.value = false;
		}else{
			document.SearchForm.bexecute_flag.value = true;
		}
		document.SearchForm.dp_type.value = sDBtype;
		document.SearchForm.dp_scope.value = sScope;
		document.SearchForm.dp_state.value = sState;
		document.SearchForm.vquery.value = vquery;
		document.SearchForm.dquery.value = dquery;
		document.SearchForm.equery.value = equery;
		document.SearchForm.isHistorySave.value = "true";
		document.SearchForm.historySeq.value = seq;	
		document.SearchForm.submit();
}

function gf_citeinlog(svccode, controlno, source)
{

	var srcsite		= "PAT";
	var dbtype		= "PATENT";

	//if(controlno.length > 0)
	//{
	//	dbtype = controlno.substring(0, 4);
	//}
	
	//Ajax 호출 - 통계저장한다.
	http = jQuery.ajax( {
		url: "/linkcenterlogsaveAjax.co",
		type: "POST",
		data: {	
			svccode: svccode,	
			controlno: controlno,	
			srcsite: srcsite,	 
			dbtype:	dbtype,
			source: source
		}, 
		async:false,
		complete:function(res, status) {
			result = jQuery.trim(res.responseText);
		}
	});

}

function gf_citeinlogwithart(arg1, arg2, arg3, arg4)
{

	gf_citeinlog( arg1, arg2, arg3);
	
	window.open(arg4, '_blan');

}

//'10-2009-7016494','ko','KUPA','10-2009-0097960','20090916','','','KOR1020097016494'
/*
String applicationNumber = ContextUtil.getParameter(request, "an");
		String country = ContextUtil.getParameter(request, "country");
		String dbt = ContextUtil.getParameter(request, "dbt");
		String un = ContextUtil.getParameter(request, "un");	//공개번호
		String ud = ContextUtil.getParameter(request, "ud");	//공개일자
		String rn = ContextUtil.getParameter(request, "rn");	//등록번호
		String pi = ContextUtil.getParameter(request, "pi");	//출판상태


*/
function gf_gotoKIPRISPlus(an, country, dbt, un, ud, rn, pi, cn, en, ed)
{
	http = jQuery.ajax( {
		url: "/patentFullText.co",
		type: "POST",
		data: {	
			an: an, country : country, dbt : dbt, 
			un : un, ud : ud, rn:rn, pi:pi,
			en : en, ed : ed
			
		}, 
		async:false,
		complete:function(res, status) {
			result = jQuery.trim(res.responseText);
			if(result.substring(0,7) == 'Failure') {
				alert(result);
			} else {
				//alert(result);
				cgf_CenterWindow( result,"patent_win", 800, 655, 1,1);
			}			
		}
	});
}

