/* 
 *
 * 1001 Genomes Data Policy Check Audit 
 *
 * written 2010 by Joffrey Fitz
 * 
 */

var container_div;
var stored_content = "";


function init() {
	container_div = document.getElementById("content_container");
	stored_content = container_div.innerHTML;

	if( test_location() ) {
		if(! test_cookie() ) {
			show_policy();
		}
	}
}

function test_location() {
//	if(window.location.href.match(/\/MPICao2010\/releases\//) or window.location.href.match(/\/MPISchneeberger2010\/releases\//)) { 
//	alert(window.location.href);
	if(window.location.href.match(/\/MPICao2010\/releases\//) || window.location.href.match(/\/MPISchneeberger2010\/releases\//) ) {
		return 1;
	}
	else {
		return 0;
	}
}

function test_cookie() {
	if (document.cookie == "1001Genomes=DataCenterAccess") {
		stored_cookie = document.cookie;
		return 1;
	} else {
  		return 0;
	}
}

function set_cookie() {
	var expire_date = new Date();
//	var period = expire_date.getTime() + (24 * 60 * 60 * 1000); // 24 hours
// 	var period = expire_date.getTime() + ( 1 * 60 * 1000); // 1 min
	var period = expire_date.getTime() + (1 * 60 * 60 * 1000); // 1h
	expire_date.setTime(period);
	document.cookie = "1001Genomes=DataCenterAccess; expires=" + expire_date.toGMTString();
	if( document.cookie == "" ) {
		alert("Please enable cookies to remember your Data Usage Policy agreement.");
	}
}

function show_policy() {
	new Ajax.Updater('content_container', '/layout_files/data_policy/policy.html', { method: 'get' });
}

function enableButton() {
	cb = document.getElementById('yesido_cb');
	b  = document.getElementById('agree_b');
	if(cb.checked)
		{b.disabled=false}
	else {b.disabled=true}
}

function showData() {
	set_cookie();
	container_div.innerHTML = stored_content;
}

