var domain = "http://www.yvoschaap.com/vote/";
var changediv = "voter";
var showgraph = 0;

function createVoteFrame(url){ 
        		var Iframe = document.createElement('iframe'); 
                Iframe.id = 'DOMIframe'; 
                Iframe.name = 'DOMIframe'; 
                Iframe.src = url; 
                Iframe.style.display = 'none'; 
        		document.body.appendChild(Iframe);
				document.getElementById(changediv).innerHTML = "Thank You!";
} 


function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}


function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function vote(vote,divcont) {
	var comment ="";
	var docref="";

	if(vote == -1)
		comment = prompt('What is your reason for a negative vote?', 'Reason:');
	if(vote == 1)
		comment = prompt('What is your reason for a positive vote?', 'Reason:');

	if(document.referrer){
		docref= document.referrer;
	}

	url = domain+"?voter="+vote+"&comment="+escape(comment)+"&docref="+escape(docref);
	
	changediv = divcont;
	
	createVoteFrame(url);
	expire = 60*60*24;
	setCookie('voted',1);
}


    var sText = "<div class=\"votingapi\" style=\"width: 150px; font-size: .9em;\">";
    //sText += "Site: <strong><a href=\""+location.href+"\">"+document.title.slice(0,50) +"</a></strong><br />";
	if(!getCookie('voted')){
    	sText += "Vote for  <strong><a href=\""+location.href+"\">"+document.title.slice(0,30) +"</a>:</strong> <span id=\"voter\"><a href=\"javascript:vote('1','voter')\"><img src=\""+domain+"thumb_up_1.gif\" border=\"0\" alt=\"I like the site\"></a> / <a href=\"javascript:vote('-1','voter')\"><img src=\""+domain+"thumb_down_1.gif\" border=\"0\" alt=\"I don't like the site\"></a></span><br />";
		//sText += "<span id=\"commenter\"><input name=\"comment\" value=\"\" type=\"text\"  maxlength=\"100\" onblur=\"comment('"+domain+"?comment="+escape(this.value)+"','commenter');\"></span><br />";
	}else{
		sText += "You voted for <strong><a href=\""+location.href+"\">"+document.title.slice(0,30) +"</a></strong>.<br />";	
	}
	if(showgraph)
		sText +="<img src=\""+domain+"graph.php\" width=\"150\" height=\"110\" />";
	sText +="<br /><span style=\"text-align: center; width: 140px;\">[ <a href=\""+domain+"\">website report</a> ]</span>";
	sText +="</div>";
    document.write(sText);