function createCookie(name, value, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var ca = document.cookie.split(';');
	var nameEQ = name + "=";
	for (var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name, "", -1);
}

<!-- Place this tag in your head or just before your close body tag -->


function social_button() {
	if (social_sites[ref] != undefined) {
		document.write(social_sites[ref]);
	} else {
		document.write('<!-- Referrer: "'+ref+'" not in data set -->'+social_sites['default']);
	}
}

var url = location.href;
var url_parts = url.split('?');
var main_url = url_parts[0]; 

var social_sites = new Array();
social_sites['default']								= '<g:plusone></g:plusone><script type="text/javascript" src="https://apis.google.com/js/plusone.js">{lang:"en-GB"}</script>';
social_sites['digg.com'] 							= "<script type='text/javascript'>(function() {var s = document.createElement('SCRIPT'), s1 = document.getElementsByTagName('SCRIPT')[0];s.type = 'text/javascript';s.async = true;s.src = 'http://widgets.digg.com/buttons.js';s1.parentNode.insertBefore(s, s1);})();</script><a class='DiggThisButton DiggMedium'></a>";
social_sites['www.stumbleupon.com'] 				= "<script src='http://www.stumbleupon.com/hostedbadge.php?s=5'></script>";
social_sites['www.delicious.com'] 					= "<img src=\"http://static.delicious.com/img/delicious.small.gif\" height=\"10\" width=\"10\" alt=\"Delicious\" /><a href=\"http://delicious.com/save\" onclick=\"window.open('http://delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=550,height=550'); return false;\"> Bookmark this on Delicious</a>";
social_sites['apps.facebook.com'] 					= '<script src="http://widgets.fbshare.me/files/fbshare.js"></script><fb:like href="'+main_url+'" layout="box_count" show_faces="false" font="verdana"></fb:like>';
social_sites['www.facebook.com'] 					= '<script src="http://widgets.fbshare.me/files/fbshare.js"></script><fb:like href="'+main_url+'" layout="box_count" show_faces="false" font="verdana"></fb:like>';
social_sites['www.reddit.com'] 						= '<script type="text/javascript" src="http://www.reddit.com/button.js?t=3"></script>';
social_sites['technorati.com']						= '<a href="http://technorati.com/faves?sub=addfavbtn&add=http://rnp.conservativeassociation.org" title ="technorati fave"><img src="http://static.technorati.com/pix/fave/tech-fav-1.gif" title="Technorati fave" /></a>';
social_sites['twitter.com']							= '<script type="text/javascript" src="http://tweetmeme.com/i/scripts/button.js"></script>';
social_sites['buzz.yahoo.com']						= '<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"></script>';
social_sites['my.yahoo.com']						= '<script type="text/javascript" src="http://d.yimg.com/ds/badge2.js" badgetype="square"></script>';
social_sites['www.google.com']						= '<g:plusone></g:plusone><script type="text/javascript" src="https://apis.google.com/js/plusone.js">{lang:"en-GB"}</script>';
social_sites['plus.google.com']						= '<g:plusone></g:plusone><script type="text/javascript" src="https://apis.google.com/js/plusone.js">{lang:"en-GB"}</script>';
social_sites[location.hostname] 					= '<!-- '+location.hostname+' -->';

var ref = document.referrer;
var cookie_ref = readCookie('referrer');
if (ref != undefined && ref != '') {
	ref = ref.match(/:\/\/([^/]+)/)[1];
	if (ref != location.hostname) {
		createCookie('referrer',ref,0);
	} else {
		ref = cookie_ref;
	}
}


