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

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

function regStart(formURL) {
	if (readCookie('uciregcheck') == null) {
		tb_show('', formURL + '?TB_iframe=true&height=500&width=600&modal=true');
	}		
}

function regFinish() {
	createCookie('uciregcheck','true',180);
	self.parent.tb_remove();
}

function regClear() {
	eraseCookie('uciregcheck');
}

var curractk;
var currPDF;
function regCheck(actk,formURL,pdfURL) {
	curractk = actk;
	currPDF = pdfURL;
	if (readCookie('uciregcheck') == null) {
		tb_show('', formURL + '?TB_iframe=true&height=500&width=620&modal=true');
	}
	else {
		trackDownload();
	}			
}
function regComplete() {
	createCookie('uciregcheck','true',180);
	tb_remove();
	trackDownload()
}
function trackDownload() {
	url = "http://www.insitemetrics.com/imv2/uRMJ/uniformv2.php";
	url += "?actk="+curractk; //unique action key
	//alert(url);
	img = new Image(0,0);
 	img.src = url;
	
	//document.location = currPDF;
	//call this to slow down the process
	redirectme();	
}
var been=0;
function redirectme() {
	if(been>0){
		document.location = currPDF;
	}	
	else {
	  	been++;
		z=setTimeout("redirectme()",2000);
	}
}




