document.observe('dom:loaded', function(){
    
    $$('a.Download').each(function(link){
				if (readCookie("electronicpayment_terms") == "agreed") { return; }
				
        // store the href url
        var url = link.readAttribute('href');

        // calls lightwindow when clicked with no cookie
        link.observe('click', function(e){
						if (readCookie("electronicpayment_terms") == "agreed") { return; }
            e.stop();
            
            // lightwindow instance
            window['termsofuse'] = new lightwindow();
            window['termsofuse'].activateWindow({
            	href: url,
            	height: 475,
            	width: 550,
            	iframeEmbed: true,
            	type: 'external'
            });
        }, link, url);                    
    });

});

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;
}