// Example:
// simplePreload( '01.gif', '02.gif' ); 
function simplePreload()
{ 
  var args = simplePreload.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}

//
// set page to show via page variable
//
function setPage(value) {
	setQueryString('page', value);
}

//
// set the querystring arg value
//
function setQueryString(argname, value) {
	var url = window.location.href.toString();
	var query = window.location.search.substring(1);
	var rExp = new RegExp(argname + "=[a-z0-9]+");
	url = url.substring(0, url.indexOf('?'));
	if (query.search(rExp) != -1)
	{
		query = query.replace(rExp, argname + '=' + value);
	} else {
		query += ((query.length > 0) ? '&' : '') + argname + '=' + value;
	}
	window.location.href = url +'?'+ query;
}

//
// select the a value from dropdown list and populate a textbox value 
//
function populateTextboxFromDropdown(which, target) {
	if (which.selectedIndex != 0) {
		target.value=which[which.selectedIndex].value;
	}
}

//
// selects a drop down list option by it's value
//
function selectOptionByValue(which, val) {
	for (i=0; i<which.options.length; i++) {
		if (which.options[i].value == val) {
			which.options[i].selected = true;
		}
	}
}

// date drop down selection boxes
function DateDropDownGenerator(n)
{
	var d=new Date();
	this.name = "dd";
	this.day = '';
	this.month = '';	
	this.year = '';
	this.lblDay = '';
	this.lblMonth = '';
	this.lblYear = '';	
	this.monthNames = '';
	this.InsertDayDropDown=function(){document.write("<select class=\"dropdownDay\" name=\""+this.name+"_day\"><option value=\"\">"+this.lblDay+"</option>");for(var i=1;i<=31;i++){document.write("<option value=\""+i+"\""+((i==this.day)?"selected":"")+">"+i+"</option>");}document.write("</select>");}
	this.InsertMonthDropDown=function(){var months=(this.monthNames=='')?Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"):this.monthNames;document.write("<select class=\"dropdownMonth\" name=\""+this.name+"_month\"><option value=\"\">"+this.lblMonth+"</option>");for(var i=0;i<months.length; i++){document.write("<option value=\"" + (i+1) + "\""+(((i+1)==this.month)?"selected":"")+">" + months[i] + "</option>");}document.write("</select>");}
	this.InsertYearDropDown=function(){document.write("<select class=\"dropdownYear\" name=\""+this.name+"_year\"><option value=\"\">"+this.lblYear+"</option>");for(var i=d.getFullYear()-50;i<=d.getFullYear()+10;i++){document.write("<option value=\""+i+"\""+((i==this.year)?"selected":"")+">"+i+"</option>");}document.write("</select>");}
	this.Generate=function(){this.InsertDayDropDown();this.InsertMonthDropDown();this.InsertYearDropDown();}
}

// swap preview image
function swapPreviewImage(id) {
	document.images['PreviewImage'].src = 'Image.php?id='+id
}

function swapDownloadLink(id, filename, filesize) {
	e = document.getElementById("DownloadLink");
	if (id==0)
		e.innerHTML = '';
	else
		e.innerHTML = '<a href="BinaryFile.php?id='+id+'">'+filename+'</a> <span style="font-size:x-small; white-space:nowrap;">('+filesize+')</span>';
}