function check_toggle(t, c, o) {
	id = t.id.substr(0, t.id.length - 1) + '_checked';
	id = id.replace('_checked', '');
	id = id + 'sd';
	
	if($(id))
	{
		if($(id).value == "1")
		{
			t.src = o;
			$(id).value = "0";
		}
		else
		{
			t.src = c;
			$(id).value = "1";
		}
	}
}

function checkAll(name, c, o, check)
{
	
	if($$('input.hidden_selected').length > 0)
	{
		$$('input.hidden_selected').each(function(e) {
			id = e.id.replace('_checked', '');
			id = id.replace('sd', '');
			
			if(check)
			{
				e.value = 1;
				$(id+'s').src = c;
			}
			else
			{
				e.value = 0;
				$(id+'s').src = o;
			}

		});
	}
}

function getCheckedItems()
{
	var ids = [];
	if($$('input.hidden_selected').length > 0)
	{
		$$('input.hidden_selected').each(function(e) {
			if(e.value == "1")
				ids.push(e.id);
		});
	}
	
	return ids;
}

function uncheckAll()
{
	if($$('input.hidden_selected').length > 0)
	{
		$$('input.hidden_selected').each(function(e) {
			e.value = "0";
		});
	}
}

function printLightbox(error)
{
	var line = 0;
	var maxLine = 3;

	if(getCheckedItems().length == 0)
	{
		alert(error);
		return null;
	}

	var html = "<html>\n<head>\n";
	var html_extra = "";

	var linkTags = document.getElementsByTagName('link');
	for(i=0;i<linkTags.length;i++){
		if(linkTags[i].href.indexOf('pictureme.php') > -1)
			html += "<link href='" + linkTags[i].href + "' rel='stylesheet' type='text/css'/>\n";
	}
	
	html += "<style type='text/css'>\n";
	html += ".landscape{\n\twidth:100%; height:100%; margin:0px;\n\t";
	html += "filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=3);\n}\n";
	html += "table td{vertical-align:text-bottom;}";
	html += "</style>\n";
	html += "</head>\n\n<body>\n";
	html += "<table cellpadding='8' cellspacing='8'>";

	getCheckedItems().each(function(e) {
		id = 'img_title_' + e.replace('_checked', '');
		id = id.substring(0, id.length -2);

		img_t = 'thumb_' + e.replace('_checked', '');
		img_t = img_t.substring(0, img_t.length - 2);

		src = "";

		if($(img_t).tagName == 'IMG')
			src = $(img_t).src;
		else
		{
			$A($(img_t).childNodes).each(function(e){
				if(e.tagName == 'IMG')
					src = e.src;
			});
		}

		img_old = src;
		img_a = img_old.substr(0, img_old.lastIndexOf('/'));
		img_b = img_old.substr(img_old.lastIndexOf('/'), img_old.length - img_old.lastIndexOf('/'));

		img_a = img_a.replace('thumbnail', 'preview');
		img_b = img_b.replace('t.', 'p.').replace('T.', 'P.');

		img_src = img_a + img_b;

		var img = new Image();
		img.src = img_old;

		line++;
		html += "<td valign=\"bottom\">";
		html += "<img src='" + img_src + "' /><br/>\n";
		html += $(id).innerHTML+"<br/>\n";
		html += "</td>\n";

		if(line == maxLine)
		{
			html += "\n</tr>\n\n<tr>";
			line = 0;
		}
	});

	html += "</tr>\n</table>\n</body>\n</html";

	var newWindow = window.open("", 'printWindow','toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=1,width=1024,height=700');
	newWindow.document.write(html);
	newWindow.document.close();
	newWindow.print();

	return false;
}

/*
AUTHOR:		Justin Mitchell
DATE:		26/01/2010

This function will print the lightbox sidebar box. Unlike the print function above,
the images don't need to be checked to be printed.
*/

function printLightboxBox(error)
{
	var line = 0;
	var maxLine = 3;

	if($$('img.lightbox_thumb').length == 0)
	{
		alert(error);
		return null;
	}
	
	var html = "<html>\n<head>\n";
	var html_extra = "";
	
	var linkTags = document.getElementsByTagName('link');
	for(i=0;i<linkTags.length;i++){
		if(linkTags[i].href.indexOf('pictureme.php') > -1)
			html += "<link href='" + linkTags[i].href + "' rel='stylesheet' type='text/css'/>\n";
	}
	
	html += "<style type='text/css'>\n";
	html += ".landscape{\n\twidth:100%; height:100%; margin:0px;\n\t";
	html += "filter: progid:DXImageTransform.Microsoft.BasicImage(Rotation=3);\n}\n";
	html += "table td{vertical-align:text-bottom;}";
	html += "</style>\n";
	html += "</head>\n\n<body>\n";
	html += "<table cellpadding='8' cellspacing='8'>";

	$$('img.lightbox_thumb').each(function(e) {
		id = e.id.replace('lightbox_thumb_','');

		img_old = e.src;
		img_a = img_old.substr(0, img_old.lastIndexOf('/'));
		img_b = img_old.substr(img_old.lastIndexOf('/'), img_old.length - img_old.lastIndexOf('/'));

		img_a = img_a.replace('thumbnail', 'preview');
		img_b = img_b.replace('t.', 'p.').replace('T.', 'P.');

		img_src = img_a + img_b;

		var img = new Image();
		img.src = img_old;

		line++;
		html += "<td valign=\"bottom\">";
		html += "<img src='" + img_src + "' /><br/>\n";
		html += $('title_lightbox_' + id + '_id').value + "<br/>\n";
		html += $('title_lightbox_' + id + '_title').value + "<br/>\n";
		html += "</td>\n";

		if(line == maxLine)
		{
			html += "\n</tr>\n\n<tr>";
			line = 0;
		}
	});

	html += "</tr>\n</table>\n</body>\n</html";

	var newWindow = window.open("", 'printWindow','toolbar=0,scrollbars=yes,location=0,statusbar=0,menubar=0,resizable=1,width=1024,height=700');
	newWindow.document.write(html);
	newWindow.document.close();
	newWindow.print();
	
	return false;
}

function to_mc_check(message) {
	if (getCheckedItems().length > 0){
		return confirm(message);  
	}else{
		return false;
	}
}
