var urlFileAppl;
var sendData;
var getPost = 'POST';
var trueFalse = "true";

function newXMLHttpRequest(){
	var reqHttp;

	if(window.ActiveXObject){
		try{
			reqHttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try{
				reqHttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e1){
				reqHttp = null;
			}
		}
	}
	else{
		try{
			reqHttp = new XMLHttpRequest();
		}
		catch(e){
			reqHttp = null;
		}
	}

	if(reqHttp == null) errorMessage();
	return reqHttp;
}

function errorMessage(){
//	alert("ERROR : BW");
}

function openSendStatus(getPost, urlFileAppl, trueFalse, sendData,cbFunction){

	var xmlHttp = newXMLHttpRequest();
	xmlHttp.open(getPost,urlFileAppl, trueFalse);

	xmlHttp.onreadystatechange = function(){

		if(xmlHttp.readyState == 4){

			if(xmlHttp.status == 200){

				cbFunction(xmlHttp);
			}
			else{
	
				exceptionControl(xmlHttp);

			}
		}

	}

	var conType = "application/x-www-form-urlencoded; charset=UTF-8";
	xmlHttp.setRequestHeader("Content-Type", conType);
	xmlHttp.send(sendData);
}
function exceptionControl(xmlHttp){
	var exceptShow = "CODE : " + xmlHttp.status;
	exceptShow += ", Error...";
//	alert(exceptShow);
}



function DB_insert(arg_url, argArray_Name, argArray_Data){
	
	urlFileAppl = arg_url;
	sendData = "";
	for(i=0;i<argArray_Name.length;i++) {
		sendData = sendData + argArray_Name[i] + "=" +  Array_Data[i];
		if(i != argArray_Name.length-1){sendData = sendData + "&";}
	}

//sendData = "idx=" + encodeURIComponent(idx)+"&selectArg=" + encodeURIComponent(selectArg)+"&BC=" + encodeURIComponent(bc)+"&startDate=" + encodeURIComponent(startDate)+"&endDate=" + encodeURIComponent(endDate);
	openSendStatus(getPost, urlFileAppl, trueFalse, sendData, RE_Insert);

}
function DB_insert_exhibitlibrary(arg_url, argArray_Name, argArray_Data){
	urlFileAppl = arg_url;
	sendData = "";
	for(i=0;i<argArray_Name.length;i++) {
		sendData = sendData + argArray_Name[i] + "=" +  Array_Data[i];
		if(i != argArray_Name.length-1){sendData = sendData + "&";}
	}


//sendData = "idx=" + encodeURIComponent(idx)+"&selectArg=" + encodeURIComponent(selectArg)+"&BC=" + encodeURIComponent(bc)+"&startDate=" + encodeURIComponent(startDate)+"&endDate=" + encodeURIComponent(endDate);
	openSendStatus(getPost, urlFileAppl, trueFalse, sendData, RE_Insert_exhibitlibrary);

}

function regist_exhibithall(arg_url, argBookCOde, argEH_SEQ){
	
	urlFileAppl = arg_url;
	sendData = "BookCode_H=" + encodeURIComponent(argBookCOde)+"&EH_SEQ=" + encodeURIComponent(argEH_SEQ)
	/*
	for(i=0;i<argArray_Name.length;i++) {
		sendData = sendData + argArray_Name[i] + "=" +  encodeURIComponent(Array_Data[i]);
		if(i != argArray_Name.length-1){sendData = sendData + "&";}
	}
	*/

//sendData = "idx=" + encodeURIComponent(idx)+"&selectArg=" + encodeURIComponent(selectArg)+"&BC=" + encodeURIComponent(bc)+"&startDate=" + encodeURIComponent(startDate)+"&endDate=" + encodeURIComponent(endDate);
	openSendStatus(getPost, urlFileAppl, trueFalse, sendData, re_regist_exhibithall);

}

function DB_update(arg_url, argArray_Name, argArray_Data, argTarget){
	urlFileAppl = arg_url;
	sendData = "";
	for(i=0;i<argArray_Name.length;i++) {
		sendData = sendData + argArray_Name[i] + "=" +  encodeURIComponent(Array_Data[i]);
		if(i != argArray_Name.length-1){sendData = sendData + "&";}
	}
	switch(argTarget) {
	  case "journal":
		  openSendStatus(getPost, urlFileAppl, trueFalse, sendData,journal_update);
	  break;
	   case "exhibitlibrary":
	   	
		 openSendStatus(getPost, urlFileAppl, trueFalse, sendData, exhibitlibrary_update);
	  break;
	  default:
	  break;
	}
//sendData = "idx=" + encodeURIComponent(idx)+"&selectArg=" + encodeURIComponent(selectArg)+"&BC=" + encodeURIComponent(bc)+"&startDate=" + encodeURIComponent(startDate)+"&endDate=" + encodeURIComponent(endDate);
	

}
function re_regist_exhibithall(xmlHttp){
	var xmlHttpVals = xmlHttp.responseText; 
	
	if(xmlHttpVals == "Y"){
		alert("전시장 제작/등록이 완료되었습니다.");
		self.close();
	}
}
function RE_Insert(xmlHttp){
	var xmlHttpVals = xmlHttp.responseText; 
//	alert(xmlHttpVals);
	xmlHttpVals = xmlHttpVals.split("\t");
	if(xmlHttpVals[0] == "Y"){
		alert("전시저널이 등록되었습니다. 이북은 잠시후 확인하십시요.");
		if(xmlHttpVals[1] == "eng") {
			var paraUL = "?UL=eng";
		} else {
			var paraUL = "?UL=kor";
		}
	  location.href="/GEP/admin/admin_journal_list.php" + paraUL;
	}
}
function RE_Insert_exhibitlibrary(xmlHttp){
	var xmlHttpVals = xmlHttp.responseText;
	
	xmlHttpVals = xmlHttpVals.split("\t");
	if(xmlHttpVals[0] == "Y"){
		alert("전시 라이브러리 제작/등록이 완료되었습니다.");
		
	  location.href="/GEP/admin/admin_exhibitlibrary_list.php";
	}
}

function journal_update(xmlHttp){
	var xmlHttpVals = xmlHttp.responseText; 
//alert(xmlHttpVals);
	xmlHttpVals = xmlHttpVals.split("\t");
	if(xmlHttpVals[0] == "Y"){
		alert("수정되었습니다..");
		if(xmlHttpVals[1] == "eng") {
			var paraUL = "?UL=eng";
		} else {
			var paraUL = "?UL=kor";
		}

	  location.href="/GEP/admin/admin_journal_list.php" + paraUL;
	}
}
function exhibitlibrary_update(xmlHttp){
	
	var xmlHttpVals = xmlHttp.responseText; 

	xmlHttpVals = xmlHttpVals.split("\t");
	if(xmlHttpVals[0] == "Y"){
		alert("수정되었습니다..");
		if(xmlHttpVals[1] == "eng") {
			var paraUL = "?UL=eng";
		} else {
			var paraUL = "?UL=kor";
		}
	  location.href="/GEP/admin/admin_exhibitlibrary_list.php" + paraUL;
	}
}

function Add_Hit(argIDX, argTip) {
  urlFileAppl = "/GEP/user/_Update_Hit.php";
	sendData = "idx=" + encodeURIComponent(argIDX) + "&tip=" +  encodeURIComponent(argTip);
	
//sendData = "idx=" + encodeURIComponent(idx)+"&selectArg=" + encodeURIComponent(selectArg)+"&BC=" + encodeURIComponent(bc)+"&startDate=" + encodeURIComponent(startDate)+"&endDate=" + encodeURIComponent(endDate);
	openSendStatus(getPost, urlFileAppl, trueFalse, sendData, returnFun);
}
function returnFun() {

}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


function PostCheck(arg, argTarget) {
	
	switch(arg) {
	  case "insert":
	  	if(!Journal.BookCode_H.value){
				alert("이북 제작후에 등록하세요"); return false;
			}
			
			Array_Kor = new Array("", "목차", "주요기사1", "주요기사2");
			Array_Name = new Array("BookCode_H", "Text_Category", "Text_MainJournal1", "Text_MainJournal2");
      Array_Data = new Array(Journal.BookCode_H.value, Journal.Text_Category.value, Journal.Text_MainJournal1.value, Journal.Text_MainJournal2.value);
      for(i=0;i<Array_Name.length;i++){
      	if(!Array_Data[i]){
      		alert(Array_Kor[i] + "를 입력하세요");
      		return false;
      	}
      }
//			var BookCode_H = Journal.BookCode_H.value;
			DB_insert("./admin_journal_insert_.php", Array_Name, Array_Data);

	  break;
	  case "modify":
	  	switch(argTarget) {
		  case "journal":
			 
		  	  Array_Kor = new Array("","회차","발행일", "제목","Recommend News 제목", "글쓴이", "내용" , "목차");
		Array_Name = new Array("idx","Vol","Pubday","Title", "Text_MainJournal1", "Text_MainJournal2", "Text_MainJournal3", "Text_MainJournal4",'argGuid',"ul");
        	Array_Data = new Array(Journal_Modify.idx.value,Journal_Modify.Vol.value,Journal_Modify.Pubday.value, Journal_Modify.Title.value,Journal_Modify.Text_MainJournal1.value, Journal_Modify.Text_MainJournal2.value, Journal_Modify.Text_MainJournal3.value, Journal_Modify.Text_MainJournal4.value,Journal_Modify.guid.value,Journal_Modify.ul.value);
		for(i=0;i<Array_Name.length;i++){
      		if(!Array_Data[i]){
      			alert(Array_Kor[i] + "를 입력하세요");
	      		return false;
		  	}
		}
			  DB_update("./_admin_journal_update.php", Array_Name, Array_Data, argTarget);
		  break;
		   case "exhibitlibrary":
		   	  
		   	   Array_Kor = new Array("",  "제목", "정책");
		Array_Name = new Array("idx","Title","Text_MainJournal1","Lib_Open",'argGuid',"ul");
        	Array_Data = new Array(Journal_Modify.idx.value,Journal_Modify.Title.value, Journal_Modify.Text_MainJournal1.value,Journal_Modify.Lib_Open.value,Journal_Modify.guid.value,Journal_Modify.ul.value);
		for(i=0;i<Array_Name.length;i++){
      		if(!Array_Data[i]){
      			alert(Array_Kor[i] + "를 입력하세요");
	      		return false;
		  	}
		}
			  DB_update("./_admin_exhibitlibrary_update.php", Array_Name, Array_Data, argTarget);
		  break;
		  default:
		  break;
		}
	  break;
	  case "reset":
	  	Journal.reset();
	  break;
	  default:
	  	alert('default');
	  break;
	}
}

function PopUp(argURL) {
	window.open(argURL,'window','location=no, directories=no,resizable=no,status=no,toolbar=no,menubar=no, width=700,height=700,left=0, top=0, scrollbars=yes');
}
////전시회
function ChecksEBook(argEDSEQ,argESSEQ,argFlag) {
	urlFileAppl = "/GEP/user/_return_Exist.php";
	argTip = "Checks";
      sendData = "EDSEQ=" + argEDSEQ + "&ESSEQ=" + argESSEQ +"&TIP=" + argTip +"&FLAG=" + argFlag;
	openSendStatus(getPost, urlFileAppl, trueFalse, sendData, RE_Checks);
}
function RE_Checks(xmlHttp){
	var xmlHttpVals = xmlHttp.responseText; 

	xmlHttpVals = xmlHttpVals.split("\t");
	if(xmlHttpVals[0] =="") {
//		PopUp("http://ebookmaker.gep.or.kr/exhibition_index.php?EDSEQ=" + xmlHttpVals[1] + "&ESSEQ=" +  xmlHttpVals[2]);
		PopUp("http://web.ditofly.co.kr/exhibition_index.php?EDSEQ=" + xmlHttpVals[1] + "&ESSEQ=" +  xmlHttpVals[2]);
	} else {
		alert("이미 생성되어있습니다.");
	}
}
////전시장
function ChecksEBook02(argEHDSEQ,argFlag) {
	urlFileAppl = "/GEP/user/_return_Exist.php";
	
	argTip = "Checks02";
      sendData = "EHSEQ=" + argEHDSEQ+"&TIP=" + argTip +"&FLAG=" + argFlag;
	openSendStatus(getPost, urlFileAppl, trueFalse, sendData, RE_Checks02);
}
function RE_Checks02(xmlHttp){
	var xmlHttpVals = xmlHttp.responseText; 

	xmlHttpVals = xmlHttpVals.split("\t");
	if(xmlHttpVals[0] =="") {
		PopUp("http://web.ditofly.co.kr/exhibithall_index.php?EHSEQ=" + xmlHttpVals[1]);
	} else {
		alert("이미 생성되어있습니다.");
	}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function Fun_Exist(argSEAQ, argFlag){    //전시회 e북 생성 여부 판단
	urlFileAppl = "/GEP/user/_return_Exist.php";
	argTip = "Exist";
      sendData = "SEQ=" + argSEAQ+"&TIP=" + argTip+"&FLAG=" + argFlag;
  //    alert(sendData);
	openSendStatus(getPost, urlFileAppl, trueFalse, sendData, RE_Exist);
}
function RE_Exist(xmlHttp) {
	var xmlHttpVals = xmlHttp.responseText; 

	if(!xmlHttpVals){
		alert("제작된 e북이 없습니다.");
	} else {
		var oButton_Style = document.getElementById("oButton");
		oButton_Style.OnClick=Rise7.openEBookFull(xmlHttpVals);
	}
}

function LinkInfo(guid, skin){
	var status = "width=400,height=350,screenX=0,left=0,screenY=0,top=0,resizable=yes,toolbar=no,status=false,menubar=no,scrollbars=no";
	var info = window.open('/r7web/linkInfo.php?guid='+guid+'&skin='+skin,'info',status);
	info.focus();
}
function old_LinkInfo(guid){
	var status = "width=400,height=350,screenX=0,left=0,screenY=0,top=0,resizable=yes,toolbar=no,status=false,menubar=no,scrollbars=no";
	var info = window.open('/r7web/linkInfo.php?guid='+guid,'info',status);
	info.focus();
}

