function wOpen(pURL, pName, w, h, scroll, text, specialSettings){
	xLeft=(screen.width)?(screen.width-w)/2:0;
	xTop=(screen.height)?(screen.height-h)/2:0;
	xSettings = 'height='+h+',width='+w+',top='+xTop+',left='+xLeft+',scrollbars='+scroll+specialSettings

	loginHwnd = window.open(pURL,pName,xSettings);
	if(loginHwnd.window.focus){loginHwnd.window.focus();}
	if(text != "") {
		loginHwnd.document.write(text);
		loginHwnd.document.close();
	}
	return loginHwnd;
}

function login(vote){
	if(loginHwnd && !loginHwnd.closed){
		loginHwnd.focus();
		return;
	}
	loginHwnd = wOpen("http://"+window.location.host+"/jm/loginDwr?urlFrom=http://"+window.location.host+"/jm/loginDwr?function=refreshFooter("+vote+");//", "", 640, 360, "no", "");
}

function setFooter() {
	if (existHash)
		DWRUtil.setValue('footerGuide', $('votacion').innerHTML);
	else
		DWRUtil.setValue('footerGuide', $('notReg').innerHTML);
}

function changeFooter (html) {
	DWRUtil.setValue('footerGuide', html);
}

function changeVote (data) {
	JGuides.getPoints(guideId,{callback:function(dataFromServer) {refreshPoints(dataFromServer, true)}});
}

function refreshPoints (data, isNewVote) {
	if (data.totalVote != null && data.totalVote != 0) {
		label = labelVotos.replace (/##VOTE_POSITIVE##/, data.votePositive);
		label = label.replace (/##TOTAL_VOTE##/, data.totalVote);
		DWRUtil.setValue('votos', label);
		DWRUtil.setValue('votos_abajo', label);
		
		if (isNewVote) {
			label = $('tks').innerHTML;
			label = label.replace (/##VOTE_POSITIVE##/, data.votePositive);
			label = label.replace (/##TOTAL_VOTE##/, data.totalVote);
			changeFooter(label);		
		}
	}
}

function voteGuide (vote) {
	if (hasHash()) {
		DWRUtil.setValue('footerGuide', $('procesando').innerHTML);
		JGuides.voteGuide (guideId, vote, changeVote);		
	} else {
		login(vote);		
	}
	
}

function refreshFooter (vote) {
	if(loginHwnd && !loginHwnd.closed){
		window.setTimeout('voteGuide('+vote+')', 0);
	}
	loginHwnd.close();
}

function handlerVgp (errorString, exception) {
	//alert (errorString);
	DWRUtil.setValue('footerGuide', $(error).innerHTML.replace(/<!--##MSJ_ERROR##-->/, errorString));
}

function hasHash() {
	ck = getCookieValue("orguserid"); 
	return !(ck==null||ck.length < 4);
}
