function addAnswer(){
	oAnswer = document.all['answerQuestion'];
	dAnswer = document.all['questionAnswer_on'];	
	oPosition = document.all['answerPosition'];
	dPosition = document.all['lstAnswer'];	

	if (util.trim(oAnswer.value)=="") {
		util.WindowExclamation("Favor informar a resposta da pergunta.");
		oAnswer.focus();
		oAnswer.value = "";
		return false;
	} 
	if (oPosition.value=="") {
		util.WindowExclamation("Favor informar a ordem da resposta.");
		oPosition.focus();
		return false;
	} 
	
	for (var o=0;o<dAnswer.options.length;o++) {
		oValue = dAnswer.options.item(o).value;
		oValue = oValue.substring(0,oValue.indexOf("||"));
		if (oValue==oAnswer.value) {
			util.WindowExclamation("A resposta já existe para a enquete.");
			return false;
		}
	}
	var optionAnswer = new Option(oAnswer.value,oAnswer.value+'||'+oPosition.value);
	var optionPosition = new Option(oPosition.value,oPosition.value);
	util.addOption(dAnswer,optionAnswer,optionAnswer.value,false); 
	util.addOption(dPosition,optionPosition,optionPosition.value,false); 
}

function delAnswer(){
	dAnswer = document.all['questionAnswer_on'];	
	dPosition = document.all['lstAnswer'];	
	dAnswer[dAnswer.selectedIndex]=null;
	dPosition[dPosition.selectedIndex]=null;
}
function removeAnswer(){
	dAnswer = document.all['questionAnswer_on'];	
	if (dAnswer.length>0) {
		if (dAnswer.selectedIndex>=0) {
			xFWeb.openWindow(380,150,'DeleteAnswer.jsp');
		}else{
			util.WindowExclamation("Selecione uma associaçãoes de recursos para remover.");
		}
	}else{
		util.WindowExclamation("Não existe associaçãoes de recursos para remover.");
	}
}
function Synchronize(oSource,oDestiny){
	if (oSource.length == 0) {
		return false;
	}
	pos = oSource.selectedIndex;
	obj = document.all[oDestiny];
	for (var o=0;o<oSource.options.length;o++) {
		oSource.options.item(o).selected = false;
	}
	
	oSource.options[pos].selected = true;
	
	for (i=1;i < arguments.length;i++) {
		for (var o=0;o<obj.options.length;o++) {
			obj.options.item(o).selected = false;
		}
		obj.options[pos].selected = true;
	}

}

/* Call function as setCookie("cookiename" , cookievalue, lifetime, cookiepath)
with the lifetime required in days, -1 to delete a cookie or zero
for a temporary cookie. The Cookie Path is optional.*/

function setCookie(cookie_name, cookie_value, cookie_life, cookie_path) {
  var today = new Date()
  var expiry = new Date(today.getTime() + cookie_life * 24*60*60*1000)
  if (cookie_value != null && cookie_value != ""){
    var cookie_string =cookie_name + "=" + escape(cookie_value)
    if(cookie_life){ cookie_string += "; expires=" + expiry.toGMTString()}
    if(cookie_path){ cookie_string += "; path=" + cookie_path}
 	document.cookie = cookie_string
  }
} // Based on JavaScript provided by Peter Curtis at www.pcurtis.com -->

/* Call function as getCookie("cookiename") It returns the value of a cookie
if set or null. Beware of potential ambiguities in names of cookies -
getCookie is simple and will match the end of a string so xyname 
will also be matched by yname and ame. */
 
function getCookie(name) {
  var index = document.cookie.indexOf(name + "=")
  if (index == -1) { return null}
  index = document.cookie.indexOf("=", index) + 1
  var end_string = document.cookie.indexOf(";", index)
  if (end_string == -1) { end_string = document.cookie.length }
  return unescape(document.cookie.substring(index, end_string))
} // Based on JavaScript provided by Peter Curtis at www.pcurtis.com -->



function votar(frm){
var votou = false;
var gCookieName;
var gCookieValueRet;
var suport = false;
var votedIndex = 0;
gCookieName="STBCOOKIETEST";
gCookieValue="STB_TESTING_COOKIE";
gCookieValueRet="???"
setCookie(gCookieName,gCookieValue,1,"");
gCookieValueRet=getCookie(gCookieName);
	if (gCookieValueRet!=null){
		suport = true;	  
	} else {
		suport = false;
	}
	
	for(var i= 0; i < frmVotePol.AnswerId.length; i++){
		votou = votou || frmVotePol.AnswerId[i].checked;
		if(votou){
			votedIndex = i;
			break;
		}
	}
	
	if(votou){
//		if(!suport){
//			alert("O seu Browser não suporta cookies.\n Para votar na enquete você deve habilitar cookies no seu Browser.");
// 		    return false;
//		} else {
			window.open ('enquete_aux.jsp?PollId='+frmVotePol.PollId.value+'&AnswerId='+frmVotePol.AnswerId[votedIndex].value,'enquete','width=290,height=500');
//		}
	} else {
		alert("Favor escolher uma das opções da enquete.");
		return false;
	}
}


function processar(frm,processador,opcoes){
var votou = false;
var gCookieName;
var gCookieValueRet;
var suport = false;
var votedIndex = 0;

gCookieName="STBCOOKIETEST";
gCookieValue="STB_TESTING_COOKIE";
gCookieValueRet="???"
setCookie(gCookieName,gCookieValue,1,"");
gCookieValueRet=getCookie(gCookieName);
	if (gCookieValueRet!=null){
		suport = true;	  
	} else {
		suport = false;
	}
	
	for(var i= 0; i < frmVotePol.AnswerId.length; i++){
		votou = votou || frmVotePol.AnswerId[i].checked;
		if(votou){
			votedIndex = i;
			break;
		}
	}
	
	if(votou){
		window.open(processador+'?PollId='+frmVotePol.PollId.value+'&AnswerId='+frmVotePol.AnswerId[votedIndex].value,'enquete',opcoes);
	} else {
		alert("Favor escolher uma das opções da enquete.");
		return false;
	}
}

