window.onload = function(){		
	popupCheck();   		        		
}

function popupCheck(){
	var popupSize = document.getElementById("popnoSize").value;
	var popNoArray = new Array();
	var index = 0;				
	for(var i=1; i<=popupSize; i++){
		if(document.getElementById("popno"+i) != null){
			popNoArray[index] = document.getElementById("popno"+i).value;
			index++;				
		} 		
	}
	showPopup(popNoArray);										
}	

function showPopup(popupNoList){
	for(var i=0; i<popupNoList.length; i++ ){
		var popupNotice = popupNoList[i]; 	 
		var cookieName = "pnotice"+popupNotice;
					
		if(getCookie(cookieName)!="done"){
			var xwidth = 300
			var yheight = 300;
			var left = eval(popupNotice.positionX);
			var top = eval(popupNotice.positionY);
			if(xwidth < 250) xwidth = 250;
							
			window.open('/bizcommon/popup/popupnotice_read.xhtml?no='+popupNotice, cookieName, "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no, width=361, height=298, left=10, top=10");
		}
	}
}

function searchPopup(searchKey, electionId){ 
	var url	= '/bizcommon/popup/popupsearch_searchPopup.xhtml?searchKey='+searchKey+'&electionId=' + electionId;
	window.open(url, 'searchPopup', "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no, width=810, height=465, left=0, top=0");
	return;
}

function searchVotePopup(searchKey, electionId){ 
		
	var url	= '/bizcommon/popup/popupsearch_searchVotePopup.xhtml?electionId=' + electionId + '&searchKey=' + searchKey;	
	
	if(searchKey == 2){
		url = url + '&nameSsn=ok';
	}
	
	window.open(url, 'searchPopup', "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no, width=810, height=565, left=0, top=0");
	return;
}

function getCookie(name){  
	var nameOfCookie=name+"=";
	var x=0;
	var xwidth = 0;
	var yheight = 0; 
	while(x<=document.cookie.length){
		var y=(x+nameOfCookie.length) 
		if(document.cookie.substring(x,y)==nameOfCookie){
			if((endOfCookie=document.cookie.indexOf(";",y))==-1)
				endOfCookie=document.cookie.length;
			return unescape(document.cookie.substring(y,endOfCookie));
		}

		x=document.cookie.indexOf(" ",x) +1; 
		if(x==0)
			break;
	}
	return "";
}

function changeBoard(value, tabId){		
	if(value == "electionFormat"){
		showAndHide("none", "", "none");
	}else if(value == "formatBoard"){
		showAndHide("none", "none", "");
	}else{
		showAndHide("", "none", "none");
	}		
	boardTabActive(tabId);
}

function boardTabActive(value) {
	var tabs = document.getElementById("ulBoardTabs");
	var items = tabs.getElementsByTagName("a");
	
	for(var i=0; i < items.length ; i++) {
		if(value == items[i].getAttribute("id")) {
			items[i].setAttribute("class", "active");
			items[i].setAttribute("className", "active");
		}else {
			items[i].removeAttribute("class");
			items[i].removeAttribute("className");
		}
	}
}

function showAndHide(notice, electionFormat, formatBoard){		
	var noticeDiv = document.getElementById("noticeDiv");
	var electionFormatDiv = document.getElementById("electionFormatDiv");
	//var formatBoardDiv = document.getElementById("formatBoardDiv");
	noticeDiv.style.display = notice;
	electionFormatDiv.style.display = electionFormat;
	//formatBoardDiv.style.display = formatBoard;
}

function searchKey(electionId){
	var searchKeyword = document.getElementById("searchKeyword");
	if(searchKeyword.value == "" || searchKeyword.value == "검색하실 내용을 입력하세요!"){
		alert("검색하실 내용을 입력해주세요.");
		searchKeyword.focus();
		return ;
	}				
	document.location.href ="main_searchMenu.xhtml?electionId=" + electionId + "&searchKeyword="+encodeURIComponent(searchKeyword.value);		
}	

function iptSearchInput(value){		
	var searchKeyword = document.getElementById("searchKeyword");
	if(value == 'y'){
		searchKeyword.value = "" ;
	}else{
		if(searchKeyword.value == ""){
			searchKeyword.value = "검색하실 내용을 입력하세요!" ;				
		}			
	}		
}
