// Add an on click event to all external links
// Open the survey modal window and pass in the external url they are trying to go to.

var surveyYes = readCookie('tookIDSafetySurvey');
var surveyRefused = readCookie('refusedIDSafetySurvey');
//document.write("surveyYes: " + surveyYes + " - surveyRefused: " + surveyRefused);
/*Event.observe(window, 'load', function() {
	$$('a[href!=""]').each(function(exLink){
	if (surveyYes != 1 && surveyRefused != 1)
	{
		if(exLink.readAttribute('href').startsWith('http') && exLink.readAttribute('href').startsWith('http://www.surveymonkey.com/') != 1 && exLink.readAttribute('href').startsWith('http://idsafety.matrixdev.net') != 1 && exLink.readAttribute('href').startsWith('http://idsafety.org/') != 1 && exLink.readAttribute('href').startsWith('http://www.idsafety.org/') != 1 && exLink.readAttribute('href').startsWith('https://idsafety.org/') != 1 && exLink.readAttribute('href').startsWith('https://www.idsafety.org/') != 1) {
			exLink.writeAttribute('target','');
			$(exLink).observe('click', respondToClick);
			return false;
		}
	}	
	});*/

	function respondToClick(event) {
	
		var element = event.element();
		var curLink = element.readAttribute('href');
	  	Modalbox.show('Survey', '/survey/?refer='+escape(curLink));
		Event.stop(event);
		return false;
	
	}
});

function readCookie(name) 
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) 
	{
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}