/*
* this is the bug-fix from prototype function 'evalScripts',
* the in IE was the evalScripts-function was bugy!
*/
String.prototype.evalScripts = function() {
  return this.extractScripts().map(function(script) { 
      script = script.replace(/^[\s]*<!--/,''); // new line
      return eval(script); 
    });
};

function voting_request(votingkey,form_id,reload_div,result_div,votingpoints,renderVotingHandler){
	var url = '/typo3conf/ext/netvajax/ajaxsrv.php';

	if(form_id && votingpoints){
		document.cookie = 'netvvotingbase_'+votingkey+form_id+'=isset; path=/;';
		new Ajax.Request(url, {
			method: 'post',
			parameters: {
				handler:'netvvotingbase-request',
				votingkey: votingkey,
				voting: votingpoints,
				uid:form_id
			}, 
			onSuccess: function (transport) {
				if(renderVotingHandler){
					new Ajax.Updater(reload_div,url, {
						method: 'post',
						evalScripts: true,
						parameters: {
							handler:renderVotingHandler,
							resultdiv:result_div,
							datarow: transport.responseText
						}
					});
				}
				else{
					$(reload_div).style.display = 'none';
				}

			}
		});
	}
	else{
		if(getCookie('netvvotingbase_'+votingkey+form_id)){
			$(reload_div).style.display = 'none';
		}
		else{
			$(reload_div).style.display = 'block';
		}
	}
}

function getCookie(name) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0,name.length))){
		return null;
	}
	if (start == -1)return null;
	var end = document.cookie.indexOf(";",len);
	if (end == -1) end = document.cookie.length;
	return unescape(document.cookie.substring(len,end));
}

