function loadIndexPoll(){

	var url = "/user/poll/indexPoll.tomato";

	var request = dojo.io.bind({
		
	    url: url,
		method: "get", 
		content: { 
		},
		error: function (type, errObj){
    		alert("error");
	    },
	    load: function (type, data, evt){
	        $("indexPoll").innerHTML = data;
	    }
	});	
}

function MM_WindowOpen(url,name,att){
	window.open(url,name,att);
}

function jsSearchDate(){
	if(getSelectedValue("keyField") == "regD"){
		$("searchNotRegD").style.display = "none";
		$("searchRegD").style.display = "block";
	} else {
		$("searchNotRegD").style.display = "block";
		$("searchRegD").style.display = "none";
	}
}

function jsFileDelete(pollSeqN){
	if(confirm("È­ÀÏÀ» »èÁ¦ ÇÏ½Ã°Ú½À´Ï±î?") == true){
		var url = $F("FD_URL");

		var request = dojo.io.bind({
			
			url: url,
			method: "post", 
			content: {
				adminId: $F("adminId"),
				adminName: encodeURIComponent($F("adminName")),
				pollSeqN: pollSeqN		
			},
			error: function (type, errObj){
				alert("error");
			},
			load: function (type, data, evt){
				loadPage("pollEdit", pollSeqN);
			}
		});
	}
}

function loadChangePage(pageId, cPage) {

	var url = $F("L_URL");

	var request = dojo.io.bind({
		
	    url: url,
		method: "post", 
		content: {
			adminId: $F("adminId"),
			adminName: encodeURIComponent($F("adminName")),
			currentPage: cPage		
		},
		error: function (type, errObj){
    		alert("error");
	    },
	    load: function (type, data, evt){
	        $("contentBody").innerHTML = data;
	    }
	});
}

function loadPage(pageId, pollSeqN, pollQueSeqN) {

	if( pageId == "pollList" ) {			
		var url = $F("L_URL");
	} else if( pageId == "pollWrite" ) {
		var url = $F("W_URL");
	} else if( pageId == "pollWriteView" ) {
		var url = $F("WQ_URL");
	} else if( pageId == "pollView" ) {
		var url = $F("V_URL");
	} else if( pageId == "pollVoteResult" ) {
		var url = $F("R_URL");
	} else if( pageId == "pollEdit" ) {
		var url = $F("E_URL");
	} else if( pageId == "pollEditInfo" ) {
		var url = $F("EI_URL");
	}

	if(pageId == "pollList"){
		var request = dojo.io.bind({

			url: url,
			method: "post",
			content: {
				adminId: $F("adminId"),
				adminName: encodeURIComponent($F("adminName")),
				keyField: getSelectedValue("keyField"),
				keyWord: encodeURIComponent($F("keyWord")),
				statusC: getSelectedValue("statusC"),
				pollStartD: $F("pollStartD"),
				pollEndD: $F("pollEndD"),
				pollSeqN: pollSeqN,
				pollQueSeqN: pollQueSeqN
			},
			error: function (type, errObj){
				alert("error");
			},
			load: function (type, data, evt){
				$("contentBody").innerHTML = data;
			}
		});
	}  else {
		var request = dojo.io.bind({

			url: url,
			method: "get",
			content: {
				adminId: $F("adminId"),
				adminName: encodeURIComponent($F("adminName")),
				pollSeqN: pollSeqN,
				pollQueSeqN: pollQueSeqN
			},
			error: function (type, errObj){
				alert("error");
			},
			load: function (type, data, evt){
				$("contentBody").innerHTML = data;
			}
		});
	}	
}

function loadDualPage(pageId, pageId_1, pollSeqN){
	loadPage(pageId, pollSeqN);
	loadPage(pageId_1, pollSeqN);
}

function loadPopOpinion(pageId, pollSeqN, pollQueSeqN, pollExampleSeqN, flag){
	var url = $F("O_URL");

	url = url + "?pageId=" + pageId + "&pollSeqN=" + pollSeqN;
	url = url + "&pollQueSeqN=" + pollQueSeqN + "&pollExampleSeqN=" + pollExampleSeqN + "&flag=" + flag;

	window.open(url,'popOpinion','top=0, left=0, width=517, height=500, scrollbars=yes, resizable=no');

	
}

// ¼³¹®Á¤º¸¿¡¼­ ±âÅ¸ Æ÷ÇÔ¿©ºÎ
function jsEtcCheckIt(){
	if($("etcYnC").checked == true){
		$("etc").style.display = "block";
	} else {
		$("etc").style.display = "none";
	}
}
function jsExEtcAdd(){
	if(jsGetCheckBoxCheckedValue("etcYnC") == 'Y'){
		$("exEtc").style.display = "block";
	} else {
		$("exEtc").style.display = "none";
	}
}

// ¼³¹®Á¤º¸¿¡¼­ º¸±âÇ×¸ñ Ãß°¡
function jsExItemAdd(cnt,cnt2){

	if(cnt < 1){
		cnt = 1;
	}		

	if(cnt2 != "add"){
		var tmpN = cnt;

		if(window.navigator.appName == "Netscape"){
			for(var i=cnt; i>=1; i--){
				var tableId = document.getElementById("tblEx"); // Å×ÀÌºíÁöÁ¤

				var tableTr = tableId.insertRow(-1);
				var tableTd = tableTr.insertCell(-1);

				tableTd.innerHTML = "<div id='ex"+i+"'><input name='example_V' id='exampleV_"+i+"' type='text'  class='fo_admin' style='width:450px' /></div>";
			}
		} else {
			for(var i=1; i<=cnt; i++){
				var tableId = document.getElementById("tblEx"); // Å×ÀÌºíÁöÁ¤

				var tableTr = tableId.insertRow(-1);
				var tableTd = tableTr.insertCell(-1);
				
				tableTd.innerHTML = "<div id='ex"+i+"'><input name='example_V' id='exampleV_"+i+"' type='text'  class='fo_admin' style='width:450px' /></div>";
			}
		}

		$("tmpCnt").value = tmpN + 1;
	} else {
		if($F("tmpCnt") == ""){
			$("tmpCnt").value = 1;
		}
		var tableId = document.getElementById("tblEx"); // Å×ÀÌºíÁöÁ¤

		var tmpN_1 = parseInt($("tmpCnt").value);

		if(window.navigator.appName == "Netscape"){			
			var tableTr = tableId.insertRow(-1);
			var tableTd = tableTr.insertCell(-1);
		} else {
			var tableTr = tableId.insertRow();
			var tableTd = tableTr.insertCell();
		}
		tableTd.innerHTML = "<div id='ex"+tmpN_1+"'><input name='example_V' id='exampleV_"+tmpN_1+"' type='text'  class='fo_admin' style='width:300px' /></div>";
		
		$("tmpCnt").value = tmpN_1 + 1;
	}		
}
// ¼³¹®Á¤º¸¿¡¼­ º¸±âÇ×¸ñ »èÁ¦
function jsExItemDel(){

	var tableId = document.getElementById("tblEx"); // Å×ÀÌºíÁöÁ¤

	$("tmpCnt").value = parseInt($("tmpCnt").value) - 1;

	var no = parseInt($F("tmpCnt")) - 1;

	if(no >= 0){
		tableId.deleteRow(no);
	} else {
		alert("´õ ÀÌ»ó »èÁ¦ÇÒ ÇàÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.");
		return;
	}
	
}	

// ¼³¹®Á¶»ç ±âº»Á¤º¸ ÀúÀå
function loadWriteAdd(pageId, pollSeqN, fileCnt){

	if(jsInputValueCheckIt("subjectV","Á¦¸ñÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä") == false){ return; }
	if(jsInputValueCheckIt("writeNameV","ÀÛ¼ºÀÚ¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä") == false){ return; }
	if(jsInputValueCheckIt("pollStartD","¼³¹®±â°£ ½ÃÀÛÀÏÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä") == false){ return; }
	if(jsInputValueCheckIt("pollEndD","¼³¹®±â°£ Á¾·áÀÏÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä") == false){ return; }

	if(jsInputDateValueCheckIt("pollStartD", "pollEndD", "¼³¹®Á¶»ç ¼³Á¤ÀÌ Àß¸ø µÇ¾ú½À´Ï´Ù.\n\n´Ù½Ã ¼±ÅÃÇØ ÁÖ¼¼¿ä") == false) { return ; }	

	$("pollWrite").action = $F("W_URL");
	$("subjectV").value = encodeURIComponent($F("subjectV"));
	$("writeNameV").value = encodeURIComponent($F("writeNameV"));

	var request = dojo.io.bind({
		url: $F("W_URL"),
		mimetype: "text/html",
		formNode: $("pollWrite"),
		error: function (type, errObj){
			alert("error");
		},
		load: function (type, data, evt){
			loadPage('pollWriteView',pollSeqN);
		}
	});	
}

// ¼³¹®Á¶»ç ±âº»Á¤º¸ ¼öÁ¤
function loadEditAdd(pageId, pollSeqN, fileCnt){

	if(jsInputValueCheckIt("subjectV","Á¦¸ñÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä") == false){ return; }
	if(jsInputValueCheckIt("writeNameV","ÀÛ¼ºÀÚ¸¦ ÀÔ·ÂÇØ ÁÖ¼¼¿ä") == false){ return; }
	if(jsInputValueCheckIt("pollStartD","¼³¹®±â°£ ½ÃÀÛÀÏÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä") == false){ return; }
	if(jsInputValueCheckIt("pollEndD","¼³¹®±â°£ Á¾·áÀÏÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä") == false){ return; }

	if(jsInputDateValueCheckIt("pollStartD", "pollEndD", "¼³¹®Á¶»ç ¼³Á¤ÀÌ Àß¸ø µÇ¾ú½À´Ï´Ù.\n\n´Ù½Ã ¼±ÅÃÇØ ÁÖ¼¼¿ä") == false) { return ; }	

	if(confirm("¼öÁ¤ ÇÏ½Ã°Ú½À´Ï±î?") == true){
		$("pollEdit").action = $F("E_URL");
		$("subjectV").value = encodeURIComponent($F("subjectV"));
		$("writeNameV").value = encodeURIComponent($F("writeNameV"));
		var request = dojo.io.bind({
			url: $F("E_URL"),
			mimetype: "text/html",
			formNode: $("pollEdit"),
			error: function (type, errObj){
				alert("error");
			},
			load: function (type, data, evt){
				loadPage('pollWriteView',pollSeqN);
			}
		});		
	} else {
		loadPage('pollWriteView',pollSeqN);
	}
}

function jsShowExample(flag){
	if($("queFormC_1").checked == true){
		$("exView1").style.display = "block";
		$("exView2").style.display = "none";
	} else if($("queFormC_2").checked == true){
		$("exView1").style.display = "none";
		$("exView2").style.display = "block";
	}
}

// ¼³¹®Á¶»ç Á¤º¸ ÀúÀå
function loadWriteInfoAdd(pageId, pollSeqN){

	if(jsInputValueCheckIt("questionV","¹®Ç×À» ÀÔ·ÂÇØ ÁÖ¼¼¿ä") == false){ return; }

	if(jsGetCheckBoxCheckedValue("queFormC_1") == 'Y'){				//¹®Á¦ À¯ÇüÀÌ °´°ü½ÄÀÏ¶§

		for(var i=1; i<=parseInt($("tmpCnt").value)-1;i++){
			if(jsInputValueCheckIt("exampleV_"+i,"º¸±â"+i+"ÀÇ ³»¿ëÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä.") == false){ return; }
		}

		var questionV = $F("questionV");
		var queFormC = jsGetRadioButtonCheckedValue('queFormC');
		var etcYnC = jsGetCheckBoxCheckedValue('etcYnC');
		var exampleVs = jsGetEncodeArray('example_V');
		var selectCntN = $F("selectCntN");

		var request = dojo.io.bind({
			url: $F("WQ_URL"),
			method: "post", 
			content: {
				pollSeqN: pollSeqN,
				questionV: encodeURIComponent(questionV),
				queFormC: queFormC,
				etcYnC: etcYnC,
				exampleVs: exampleVs,
				selectCntN: selectCntN
			},
			error: function (type, errObj){
				alert("error");
			},
			load: function (type, data, evt){
				alert("ÀúÀå µÇ¾ú½À´Ï´Ù.");
				loadPage('pollWriteView',pollSeqN);
			}
		});
	} else if($("queFormC_2").checked == true){			//¹®Á¦ À¯ÇüÀÌ ÁÖ°ü½ÄÀÏ¶§
		var questionV = $F("questionV");
		var queFormC = jsGetRadioButtonCheckedValue('queFormC');
		var etcYnC = jsGetCheckBoxCheckedValue('etcYnC');

		var request = dojo.io.bind({
			url: $F("WQ_URL"),
			method: "post", 
			content: {
				pollSeqN: pollSeqN,
				questionV: encodeURIComponent(questionV),
				etcYnC: etcYnC,
				queFormC: queFormC
			},
			error: function (type, errObj){
				alert("error");
			},
			load: function (type, data, evt){
				alert("ÀúÀå µÇ¾ú½À´Ï´Ù.");
				loadPage('pollWriteView',pollSeqN);
			}
		});
	}
}

// ¼³¹®Á¶»ç Á¤º¸ ¼öÁ¤
function loadWriteInfoEdit(pageId, pollSeqN){

	if(jsInputValueCheckIt("questionV","¹®Ç×À» ÀÔ·ÂÇØ ÁÖ¼¼¿ä") == false){ return; }

	if(jsGetCheckBoxCheckedValue("queFormC_1") == 'Y'){				//¹®Á¦ À¯ÇüÀÌ °´°ü½ÄÀÏ¶§

		for(var i=1; i<=parseInt($("tmpCnt").value)-1;i++){
			if(jsInputValueCheckIt("exampleV_"+i,"º¸±â"+i+"ÀÇ ³»¿ëÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä.") == false){ return; }
		}

		var questionV = $F("questionV");
		var queFormC = jsGetRadioButtonCheckedValue('queFormC');
		var etcYnC = jsGetCheckBoxCheckedValue('etcYnC');
		var exampleVs = jsGetEncodeArray('example_V');

		var request = dojo.io.bind({
			url: $F("EI_URL"),
			method: "post", 
			content: {
				pollIdC: $F("pollIdC"),
				tableName: $F("pollIdC"),
				pollSeqN: pollSeqN,
				questionV: encodeURIComponent(questionV),
				queFormC: queFormC,
				etcYnC: etcYnC,
				exampleVs: exampleVs
			},
			error: function (type, errObj){
				alert("error");
			},
			load: function (type, data, evt){
				alert('ÀúÀå µÇ¾ú½À´Ï´Ù.');
				loadPage('pollWriteInfo',pollSeqN);
			}
		});
	} else if($("queFormC_2").checked == true){			//¹®Á¦ À¯ÇüÀÌ ÁÖ°ü½ÄÀÏ¶§
		var questionV = $F("questionV");
		var queFormC = jsGetRadioButtonCheckedValue('queFormC');
		var etcYnC = jsGetCheckBoxCheckedValue('etcYnC');

		var request = dojo.io.bind({
			url: $F("EI_URL"),
			method: "post", 
			content: {
				pollIdC: $F("pollIdC"),
				tableName: $F("pollIdC"),
				pollSeqN: pollSeqN,
				questionV: encodeURIComponent(questionV),
				etcYnC: etcYnC,
				queFormC: queFormC
			},
			error: function (type, errObj){
				alert("error");
			},
			load: function (type, data, evt){
				alert('ÀúÀå µÇ¾ú½À´Ï´Ù.');
				loadPage('pollWriteInfo',pollSeqN);
			}
		});
	}
}

function loadWriteInfoDel(pageId, pollSeqN, pollQueSeqN){
	var msg = "¼±ÅÃÇÏ½Å ¹®Ç×À» »èÁ¦ ÇÏ½Ã°Ú½À´Ï±î?";

	if(confirm(msg) == true){
		var request = dojo.io.bind({
			url: $F("WID_URL"),
			method: "post", 
			content: {
				pollSeqN: pollSeqN,
				pollQueSeqN: pollQueSeqN
			},
			error: function (type, errObj){
				alert("error");
			},
			load: function (type, data, evt){
				alert('»èÁ¦ µÇ¾ú½À´Ï´Ù.');
				loadPage('pollWriteView',pollSeqN);
			}
		});
	}
}

// ¼³¹®Á¶»ç ¿ì¸®ÀÇ ÀÇ°ß Ãß°¡
function loadTailAdd(pageId, pollSeqN){
	if(jsInputValueCheckIt("contentL","¿ì¸®ÀÇ ÀÇ°ß ³»¿ëÀ» ÀÔ·ÂÇØ ÁÖ¼¼¿ä") == false){ return; }
	if(hasCheckedRadio('emoticonC') == false){
		alert("ÀÌ¸ðÆ¼ÄÜÀ» ¼±ÅÃÇØ ÁÖ¼¼¿ä.");
		return;
	}
	if(jsByteLength("contentL") >= 100){
		alert("ÀÇ°ßÀº 50ÀÚ ¹Ì¸¸À¸·Î ÀÔ·ÂÇØ ÁÖ¼¼¿ä.");
		return;
	}
	var contentL = $F("contentL");
	var emoticonC = jsGetRadioButtonCheckedValue('emoticonC');
	var writeNameV = $F("writeNameV");
	var writeIdV = $F("writeIdV");

	var request = dojo.io.bind({
	    url: $F("VT_URL"),
		method: "post", 
		content: {
			pollIdC: $F("pollIdC"),
			tableName: $F("pollIdC"),
			pollSeqN: pollSeqN,
			emoticonC: emoticonC,
			writeNameV: encodeURIComponent(writeNameV),
			writeIdV: writeIdV,
			contentL: encodeURIComponent(contentL)
			
		},
		error: function (type, errObj){
    		alert("error");
	    },
	    load: function (type, data, evt){
	    	alert('ÀúÀå µÇ¾ú½À´Ï´Ù.');
	        $("pollViewTail").innerHTML = data;
	    }
	});
}

// ¼³¹®Á¶»ç ¿ì¸®ÀÇ ÀÇ°ß Ãß°¡
function loadTailDel(pageId, pollSeqN, tailSeqN){
	
	if(confirm("ÀÇ°ß±ÛÀ» »èÁ¦ ÇÏ½Ã°Ú½À´Ï±î?") == false){ return; }		

	var request = dojo.io.bind({
	    url: $F("VTD_URL"),
		method: "post", 
		content: {
			pollIdC: $F("pollIdC"),
			tableName: $F("pollIdC"),
			tailSeqN: tailSeqN,
			pollSeqN: pollSeqN
		},
		error: function (type, errObj){
    		alert("error");
	    },
	    load: function (type, data, evt){
	    	alert('»èÁ¦ µÇ¾ú½À´Ï´Ù.');
	        loadPage('pollViewTail',pollSeqN);
	    }
	});
}

function jsTailDisplay(id){
	if(id == 'tailShort'){
		$("tailShort").style.display = "none";
		$("tailLong").style.display = "block";
	} else if(id == 'tailLong'){
		$("tailShort").style.display = "block";
		$("tailLong").style.display = "none";
	}
}

function jsDeleteCheckIt(pageId, pollSeqN){

	if(confirm("¼±ÅÃÇÏ½Å ¼³¹®Á¶»ç¸¦ »èÁ¦ ÇÏ½Ã°Ú½À´Ï±î?") == false){ return; }		

	var request = dojo.io.bind({
	    url: $F("D_URL"),
		method: "post", 
		content: {
			pollSeqN: pollSeqN
		},
		error: function (type, errObj){
    		alert("error");
	    },
	    load: function (type, data, evt){
	    	alert('»èÁ¦ µÇ¾ú½À´Ï´Ù.');
	        loadChangePage('pollList',1);
	    }
	});
}

// ÅõÇ¥ÇÏ±â
function loadVoteCheck(pageId, pollSeqN){
	var no = jsGetArray('no');
	var queType = jsGetArray('queType');
	var etcYn = jsGetArray('etcYn');
	var pollQueSeq = jsGetArray('pollQueSeq');

	var displayNoNs = Array(no.length);
	var disAnswerVs = Array(no.length);
	var etcAnswerVs = Array(no.length);
	var etcAnswerYnCs = Array(no.length);
	var tmpDisplay;

	var fieldType = jsGetArray("fieldType");

	for(var i=0; i<no.length; i++){
		var tmpexaNo = "exaNo"+(i+1);
		var exaNo = jsGetArray(tmpexaNo);

		if(queType[i] == "01"){					// °´°ü½Ä ´äº¯ÀÏ°æ¿ì
			if(fieldType[i] == "radio") {
				var ex = jsGetRadioButtonCheckedValue("ex"+(i+1));
			} else if(fieldType[i] == "checkbox"){
				var ex = jsGetCheckBoxCheckedValues("ex"+(i+1));
			}
			
			if(ex == ""){
				alert((i+1) + "¹ø ¹®Ç×ÀÇ ¼³¹®¿¡ ´äÇØ ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.");
				return;
			} else {
				displayNoNs[i] = ex;
				disAnswerVs[i] = "";
				etcAnswerVs[i] = "";
				etcAnswerYnCs[i] = "N";
			}
			
			if(ex == exaNo){				// °´°ü½Ä ÀÏ¶§ ±âÅ¸ ´äº¯ÀÏ°æ¿ì
				var etc = "etc"+(i+1);
				if($F(etc) == ""){
					alert((i+1) + "¹ø ¹®Ç×ÀÇ ±âÅ¸¸¦ ¼±ÅÃÇÏ¼Ì½À´Ï´Ù. ±âÅ¸ÀÇ°ßÀ» ÀÔ·ÂÇØ ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.");
					$(etc).focus();
					return;
				} else {
					displayNoNs[i] = ex;
					disAnswerVs[i] = "";
					etcAnswerVs[i] = encodeURIComponent($F(etc));
					etcAnswerYnCs[i] = "Y";
				}
			}			
			
		} else if(queType[i] == "02"){		// ÁÖ°ü½Ä ´äº¯ÀÏ°æ¿ì
			var ex = "ex"+(i+1);
			if($F(ex) == ""){
				alert((i+1) + "¹ø ¹®Ç×ÀÇ ¼³¹®¿¡ ´äÇØ ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.");
				$(ex).focus();
				return;
			} else {
				displayNoNs[i] = 1;
				disAnswerVs[i] = encodeURIComponent($F(ex));
				etcAnswerVs[i] = "";
				etcAnswerYnCs[i] = "N";
			}
		}
	}

	var request = dojo.io.bind({
	    url: $F("V_URL"),
		method: "post", 
		content: {
			pollSeqN: pollSeqN,
			pollQueSeq: pollQueSeq,
			displayNoNs: displayNoNs,
			disAnswerVs: disAnswerVs,
			etcAnswerVs: etcAnswerVs,
			etcAnswerYnCs: etcAnswerYnCs,
			queType: queType,
			etcYn: etcYn

		},
		error: function (type, errObj){
    		alert("error");
	    },
	    load: function (type, data, evt){
	    	alert('ÅõÇ¥¿¡ Âü¿©ÇØ ÁÖ¼Å¼­ °¨»ç ÇÕ´Ï´Ù.');
	        loadPage('pollVoteResult',pollSeqN);
	    }
	});
}

function loadAttachFileDelete(pageId, pollSeqN, fileSeqN){
				
	var msg = "¼±ÅÃÇÏ½Å È­ÀÏÀ» »èÁ¦ ÇÏ½Ã°Ú½À´Ï±î?";
	if(confirm(msg) == true){
		var request = dojo.io.bind({
			url: $F("FD_URL"),
			method: "post", 
			content: {
				pollIdC: $F("pollIdC"),
				tableName: $F("pollIdC"),
				pollSeqN: pollSeqN,
				fileSeqN: fileSeqN
			},
			error: function (type, errObj){
				alert("error");
			},
			load: function (type, data, evt){					
				alert('»èÁ¦ µÇ¾ú½À´Ï´Ù.');
				loadPage(pageId, pollSeqN);
			}
		});
	}

}