// called to show on first screen (start)
function srDoesFundExist() {
	if (document.getElementsByName("selectedfund")) var selectedfundsitems = document.getElementsByName("selectedfund");
	if (document.getElementById("srSectionDiv") && document.getElementsByName("selectedfund")) {
		var docel = document.getElementById("srSectionDiv");
		if (selectedfundsitems[0]) {
			docel.innerHTML = ajax('./ajax/srIsEmpty.php', 'id='+selectedfundsitems[0].value);
			if (docel.innerHTML=="") docel.style.display = "none";
			else docel.style.display = "block";
		}
	}
}


// buttons on start screen

// current reports
function doOnline() {
	document.getElementById("t").innerHTML="online";
	document.getElementById("divLogin").style.display="block";
	document.getElementById("txtLUsername").focus();
}
function doPDF() {
	document.getElementById("t").innerHTML="pdf";
	document.getElementById("divLogin").style.display="block";
	document.getElementById("txtLUsername").focus();
}
// archived reports
function doArchives() {
	document.getElementById("t").innerHTML="archives";
	document.getElementById("divLogin").style.display="block";
	document.getElementById("txtLUsername").focus();
}

// login screen
function attemptLogin() {
	var t = document.getElementById("t").innerHTML;
	var u = encodeURIComponent(document.getElementById("txtLUsername").value);
	var p = encodeURIComponent(document.getElementById("txtLPassword").value);
	var a = encodeURIComponent(document.getElementById('sactive').innerHTML);
	
	var fundid = document.getElementsByName("selectedfund")[0].value;
	
	if ( ajax("ajax/srRetrieve.php", "type=login&y="+t+"&u="+u+"&p="+p+"&fund="+fundid+"&fundid="+fundid) != "0" ) {
		hideLoginDiv();
		if ( t == "online" ) srViewOnline();
		if ( t == "pdf" ) srDownloadPDF();
		if ( t == "archives" ) srViewArchives();
		return false;
	} else {
		alert("Incorrect credentials, please try again.");
		return false;
	}
}
// hide login screen
function hideLoginDiv() {
	document.getElementById("txtLUsername").value = "";
	document.getElementById("txtLPassword").value = "";
	document.getElementById("divLogin").style.display = "none";
	document.getElementById("t").innerHTML="";
}

// show viewonline page
function srViewOnline() {
	var fid = document.getElementsByName("selectedfund")[0].value;
	form = document.createElement("form");
	form.method = "GET";
	form.action = "http://salamancacapital.com/report.php";
	form.target = "_blank";
	hidden = document.createElement('input');
	hidden.type = 'hidden';
	hidden.setAttribute('Name', "fid");
	hidden.setAttribute('Value', fid);
	form.appendChild(hidden);
	document.body.appendChild(form);
	form.submit();
}

function srDownloadPDF() {
	window.open("current_pdf/08-05-12-EREOF-report-May.pdf");
	//window.open("ajax/exportPdf.php?mf="+theMainFund);
}
function srViewArchives() {
	var fid = document.getElementsByName("selectedfund")[0].value;
	document.getElementById("divArchives").innerHTML = ajax("ajax/srRetrieve.php", "type=archives&fund="+fid);
	document.getElementById("divArchives").style.display = "block";
}

// show pages
function showPage(fundid,pagenumber) {
	document.getElementById("srContent").innerHTML = ajax("ajax/srRetrieve.php", "fid="+fundid+"&pn="+pagenumber+"&type=online");
}

// body
function reportCleanup() {
	ajax('./ajax/reportCleanup.php','');
}