// minimal standard.js for landing pages

// inserts tracking code into download links, and sets tracking variables

var path = "http://www.datablade.com/cgi-bin/software.html/";
var nd_path = "https://ndcasino.wagerlogic.com/Casino/CU/00/index.html";

function returnclickhandler(obj,hrefstored){
	if(typeof(obj.onclick)=='function'){
		var oldhandler=obj.onclick;
	}
	return function(e){
		// ------------------------------------------------- tracking code starts here. Use 'obj' instead of 'this'
		//GA code 
		pageTracker._trackPageview('/download/InterCasino-euro-english-Installer.exe');
		// ------------------------------------------------- tracking code ends here
		if(oldhandler){ oldhandler(e); }
	}
}

function returnloadhandler(){
	if(typeof(window.onclick)=='function'){
		var oldhandler=window.onload;
	}
	return function(){
		if(oldhandler){ oldhandler(); }
		if (document.getElementsByTagName) {
			var hrefs = document.getElementsByTagName('a');
		} else if(document.all) {
			var hrefs = document.all.tags('a');
		}
		if(hrefs){
			var trackingcode=unescape(getCookie('src_cd'));
			if(trackingcode && trackingcode=='undefined'){ trackingcode=false; }
			for (i=0;i<hrefs.length;i++){
				var hrefstored=hrefs[i].href;
				var a=hrefs[i].href.split('/');
				if(hrefs[i].href.indexOf(path) != -1){
					if(trackingcode){ hrefs[i].href = path+trackingcode+'/'+a[a.length-1]; }
					hrefs[i].onclick=returnclickhandler(hrefs[i],hrefstored);
				} else if (hrefs[i].href.indexOf(nd_path) != -1) {
					hrefs[i].href=nd_path+"?referrer="+trackingcode;
					//alert(hrefs[i].href);
				}
			}
		}
	}
}

function getCookie(Name) {   	

	var search = Name + "="   

	if (document.cookie.length > 0) { 
	
	// if there are any cookies      
	offset = document.cookie.indexOf(search)       

	if (offset != -1) { 
		// if cookie exists          
		offset += search.length          
		// set index of beginning of value         
		end = document.cookie.indexOf(";", offset)          
		// set index of end of cookie value         
		if (end == -1)             
			end = document.cookie.length         
			return unescape(document.cookie.substring(offset, end))      
		}    
	}
}

window.onload=returnloadhandler();