<!-- // JavaScript Document

var d = document;

function createObject()
{	//CREATE AN AJAX OBJECT TO QUERY A TABLE IN A FILE CALLED UPDATE.PHP IN EACH DIRECTORY
	var ajaxRequest;
	try				{	ajaxRequest = new XMLHttpRequest(); } 
	catch (e)	{	try				{	ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");	} 
						catch (e)	{	try		{	ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");	}
						catch (e)	{	alert("Your browser does not support the technology this website uses. Please upgrade your browser!");		
											return false;	}
					}					}
	return ajaxRequest;
}

//GET THE SERVER NAME TO USE ABSOLUTE URLS WHERE NEEDED
function serverName()
{
	var server; var url = location.href;
	if(url.indexOf("localhost") != -1)			{	server = ".."; }
	else if(url.indexOf("klstudios") != -1)	{	if(url.indexOf("_office") != -1)	{ server = "http://www.printbureau.klstudios.ie/_office"; } 
															else										{ server = "http://www.printbureau.klstudios.ie/"; 	}	
	} else if(url.indexOf("_office") != -1)	{ server = "http://www.printbureau.ie/_office"; } 
	else												{ server = "http://www.printbureau.ie"; }
	return server;
}

//DISPLAY A HIDDEN ID TAG AND IF OPPOSITE IS SET, HIDE OPPOSITE THE DIVID
function showDiv(divID,type,opposite)
{
	var x = d.getElementById(divID).style;
	if(type == "display")	{	x.display = "block"; if(opposite)		{	d.getElementById(opposite).style.display = "none"; } }
	else						{	x.visibility = "visible"; if(opposite)	{  d.getElementById(opposite).style.visibility = "hidden"; } }
}

function hideDiv(divID,type,opposite)
{
	var x = d.getElementById(divID).style;
	if(type == "display")	{	x.display = "none"; if(opposite) 		{	d.getElementById(opposite).style.display = "block"; } }
	else						{	x.visibility = "hidden"; if(opposite)	{  d.getElementById(opposite).style.visibility = "visible"; } }
}

function showMenu(nav_id,what)
{
	var arr = Array('hidden','visible'); d.getElementById(nav_id).style.visibility=arr[what];
}

//GET THE SELECTED INDEX VALUE OF A SELECT BOX AND RETURN IT TO THE FUNCTION CALLING IT
function getSelectedIndex(cellID)
{
	var selectedItem = d.getElementById(cellID).selectedIndex;
	var selectedvalue = d.getElementById(cellID).options[selectedItem].value;
	return selectedvalue;
}

function showHelp(type)
{
	var i = d.getElementById("legendClick");
	if(type == "open")	{ i.href = "javascript:void(showHelp('close'))"; i.title = "Close the Help Window"; d.getElementById("legendData").style.display = "block"; }
	else						{ i.href = "javascript:void(showHelp('open'))"; i.title = "Open a the Help Window with explanations of the icons shown"; d.getElementById("legendData").style.display = "none"; }
}

//CHANGE A PAGE AUTOMATICALLY FROM A SELECT BOX TO UPDATE A VIEW, ALSO ADDING ANY PAGER AND SEARCH CRITERA TO THE URL
function changeThisPage(selectBox)
{
	if(selectBox)	{ var url = getSelectedIndex(selectBox); }
	else			 	{ var url = getSelectedIndex("changePage"); }
	window.location = url;
}

//ADD ANY PAGER OR SEARCH CRITERA TO THE URL IF NECCASSERY
function gotoPage(filename,first,searching,order)
{
	var url = filename;
	if(first != 0) 
		{	if(first>0) 			{	if(url.indexOf("?") == -1)	{ url = url + "?"; } else { url = url + "&"; } url = url + "first=" + first; }
			if(searching != 0)	{	if(url.indexOf("?") == -1)	{ url = url + "?"; } else { url = url + "&"; } url = url + "search=" + searching; }
			if(order != 0)		{	if(url.indexOf("?") == -1)	{ url = url + "?"; } else { url = url + "&"; } url = url + "order=" + order; }
			window.location = url;
		}
}

function terms()
{
	window.open(serverName()+"/home/terms.php",'','width=800,height=500,scrollbars=1');
}

function verifyNow()
{
	if(d.getElementById("submitOrder").value == "Send my Order >")
		{
			if(d.getElementById("verifyOrder").checked == false)
				{
					alert("Please confirm that you accept our terms and conditions of sale"); return false;
				}
			else
				{
					return true;
				}
		}
	else
		{
			return true;
		}
}

function changeFormCountry(country,cell1,cell2)
{
	var url = serverName() + "/_lib/ajax.php?country=" + getSelectedIndex(country); var ajaxRequest = createObject();	
	ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4) 
				{
					d.getElementById(cell1).value = ajaxRequest.responseText;
					if(d.getElementById(cell2)) { d.getElementById(cell2).value = ajaxRequest.responseText; }
				}			
			}
		ajaxRequest.open("GET",url, true);
		ajaxRequest.send(null); 
}

function copyBilling()
{
	var pass = "";
	if(d.getElementById("copyDetails").checked == true)
		{
			d.getElementById("dadd1").value = d.getElementById("badd1").value;
			if(d.getElementById("badd1").value == "") { pass = "first line of"; }
			d.getElementById("dadd2").value = d.getElementById("badd2").value; 
			d.getElementById("dpostcode").value = d.getElementById("bpostcode").value; 
			if(d.getElementById("bpostcode").value == "")	{ pass = "postcode for"; }
			d.getElementById("dcity").value = d.getElementById("bcity").value; 
			if(d.getElementById("bcity").value == "") { pass = "city or county in"; }			
			if(pass != "") { alert("Please fill the " + pass + " your billing address"); }
		}
	else
		{
			d.getElementById("dadd1").value = d.getElementById("dadd2").value = 	d.getElementById("dpostcode").value = d.getElementById("dcity").value = "";
		}
}

function showAddNewImage(dothis)
{
	d.getElementById("addNewImageShadow").style.visibility = dothis; d.getElementById("addNewImage").style.visibility = dothis;
	if(dothis == "hidden")
		{
			d.getElementById("image_image").value = ""; d.getElementById("image_name").value = ""; d.getElementById("image_order").value = 1; 
		}
}

function checkAddNewImage()
{
	var msg = "Please complete the upload form :\r\n"; cellValue = d.getElementById("image_image").value;
	var check = cellValue.indexOf(".jpg");			check = check + cellValue.indexOf(".jpeg");
	check = check + cellValue.indexOf(".JPG");	check = check + cellValue.indexOf(".JPEG");
	check = check + cellValue.indexOf(".gif");		check = check + cellValue.indexOf(".GIF");
	check = check + cellValue.indexOf(".png");	check = check + cellValue.indexOf(".PNG");
	if(d.getElementById("image_name").value == "")	{ msg = msg + "Please complete a name for your image\r\n"; }
	if(d.getElementById("image_image").value == "")	{ msg = msg + "Please add an image to be uploaded\r\n"; }
	else if(check == -8) { msg = msg + "The image you are trying to upload is not a valid file. You can upload jpg, png or gif files only.\r\n" };
	if(msg == "Please complete the upload form :\r\n") { return true; } else 	{ alert(msg); return false; }
}

function getPrice(div_id,unit_step)
{
	//create variable
	var priceid = d.getElementById("product_price_id").value;
	var qty = d.getElementById("product_qty_"+div_id).value;
	
	if(qty > 0)
		{
			var result = qty % unit_step;
			if(result != 0) 
				{ 
					old_qty = qty; qty = (qty-result)+unit_step; 
					d.getElementById("product_qty_"+div_id).value = qty;
					alert("This product is sold in multiples of " + unit_step + ". For this reason your quantlity has been amended from " + old_qty + " to " + qty);
				}
			
			var url = serverName() + "/_lib/ajax.php?priceid="+priceid+"&qty="+qty;
			var ajaxRequest = createObject();
			ajaxRequest.onreadystatechange = function()
				{
					if(ajaxRequest.readyState == 4) 
						{
							d.getElementById("product_price_"+div_id).innerHTML = ajaxRequest.responseText;
						}		
				}
			ajaxRequest.open("GET",url, true); ajaxRequest.send(null);	
		}
}

function fbs_click()
{ 
	u=location.href;t=document.title; 
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&amp;t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

function checkProductForm()
{
	var total_rows = d.getElementById("total_rows").value; var total = 0;
	for ( var x = 1; x <= total_rows; x++) { total += d.getElementById("product_qty_"+x).value; }
	if(total == 0) { alert("You have not selected any products"); return false; } else { return true; }
}

function updateCell(cell_id,type)
{
	if(type == "checkbox")
		{
			var x = d.getElementById(cell_id+"_price");
			if(d.getElementById(cell_id).checked==true) { x.style.color = "#028"; } else { x.style.color = "#ccc"; }
		}
	else if(type == "select")
		{
			var id = getSelectedIndex(cell_id); 
			var url = serverName() + "/_lib/ajax.php?wording="+id;
			var ajaxRequest = createObject();
			ajaxRequest.onreadystatechange = function()
				{
					if(ajaxRequest.readyState == 4) 
						{
							d.getElementById("wording_td").innerHTML = ajaxRequest.responseText;
						}		
				}
			ajaxRequest.open("GET",url, true); ajaxRequest.send(null);
		}
	d.getElementById("submitOrder").value = "> Update Prices";
	d.getElementById("subTotal").value = 0;
}

function getProduct(product_id)
{
	d.getElementById("productImage").style.border = "0px";
	d.getElementById("productImage").style.paddingTop = "100px";
	d.getElementById("productImage").style.width = d.getElementById("productImage").style.height = "40px";
	d.getElementById("productImage").src = serverName()+"/_images/load.gif";
	setTimeout("ajaxProduct('product',"+product_id+")",1000);
}

function ajaxProduct(get,id)
{
	url = serverName() + "/_lib/ajax.php?"+get+"="+id;
	var ajaxRequest = createObject();
	ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4) 
				{
					d.getElementById("productData").innerHTML = ajaxRequest.responseText;
				}		
		}
	ajaxRequest.open("GET",url, true); ajaxRequest.send(null);
}

function menuTwo(nav_action)
{
	showMenu('servNav',nav_action);
	showMenu('servNavTwo',nav_action);
}

function downloadFile(file_id)
{
	window.open(serverName()+"/home/download.php?folder=downloads&file="+file_id);
}
-->
