<!--
document.write('<link href="/css/js.css" rel="stylesheet" type="text/css" />');

function addOnloadFunction(func) {
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
  	var currentOnload = window.onload;
    
	window.onload = function() {
	  currentOnload();
      func();
    }
  }
}

var preloadFlag = false;
var aImagesForPreload = new Array('/images/home_over.png', '/images/portfolio_over.png', '/images/albums_over.png', '/images/prices_over.png', '/images/faqs_over.png', '/images/about_us_over.png', '/images/special_offers_over.png', '/images/contact_us_pink.png', '/images/pink_tab.png', '/images/pink_tab_repeat.png', '/images/thumbnail_drop_shadow.png', '/images/portfolio_thumbnail_drop_shadow.png', '/images/blue_tab.gif', '/images/pink_tab.gif', '/images/blue_tab_repeat.gif', '/images/pink_tab_repeat.gif','framing_tips_over.png','customise_canvas_over.png');

addOnloadFunction(function(){
	preloadImages();
});

function parseGetVars(string) {
	var getVars = new Array();
	var qString = unescape(string.substring(string.indexOf('?') + 1));
	var pairs = qString.split(/\&/);

	for (var i in pairs) {
		var nameVal = pairs[i].split(/\=/);
		getVars[nameVal[0]] = nameVal[1];
	}

	return getVars;
}

function preloadImages() {
	var aImages = aImagesForPreload;
	
	document.imageArray = new Array(aImages.length);
	
	for(var i=0; i<aImages.length; i++) {
		document.imageArray[i] = new Image;
		document.imageArray[i].src = aImages[i];
  }
  
  preloadFlag = true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Fading
//

function fade(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("setOpacity('" + id + "', " + i + ")",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout("setOpacity('" + id + "', " + i + ")",(timer * speed));
            timer++;
        }
    }
}

// Set the opacity for different browsers
function setOpacity(id, opacity) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
} 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Navigation
//

function initNav() {
	var i, j, k, c, lc, ac;
	var nav = document.getElementById('navigation');
	var navcontainer = document.getElementById('navcontainer')
	var ghostNav = nav.cloneNode(true);
	ghostNav.id = 'ghostnav';
	navcontainer.appendChild (ghostNav);
	
	var c = nav.childNodes;

	for (i = 0; i < c.length; i++) {
		if (c[i].nodeName == "LI") {
			lc = c[i].childNodes;
			for (j = 0; j < lc.length; j++) {
				if (lc[j].nodeName == "A") {
					ac = lc[j].childNodes;
					for (k = 0; k < ac.length; k++) {
						if (ac[k].nodeName == "IMG") {
							var theimagenode = lc[j].removeChild(ac[k]);
							var newspannode = document.createElement("SPAN");
							newspannode.appendChild(theimagenode);
							newspannode.className = "a";
							c[i].replaceChild(newspannode, lc[j]);
						}
					}
				}
			}
		}
	}	
}

function newToggleTab(n, toggle) {
	if (preloadFlag) {
		if (toggle == 0) {
			n.className = n.className.replace(" expanded", "");
			n.className = n.className.substr(0, n.className.indexOf(' '));
		} else {			
			// The need for e.g. homeExpanded here is to get round IE6's
			// chained class selector bug
			n.className += " expanded " + n.className + "Expanded";
		}
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Form validation
//

function validate(strForm) {
	var errorText = "";
	if (strForm.first_name && (strForm.first_name.value == "")) {
		errorText += "You must enter enter your first name.\n";
	}
	if (strForm.surname && (strForm.surname.value == "")) {
		errorText += "You must enter enter your surname.\n";
	}
	if (strForm.email && (strForm.email.value == "")) {
		errorText += "You must enter your email address.\n";
	}
	
	if (strForm.subject && (strForm.subject.value == "")) {
		errorText += "Please enter the subject of the email.\n";
	}

	if (strForm.message && (strForm.message.value == "")) {
		errorText += "Please type in your message before sending.\n";
	}
	
	if (errorText != "") {
		alert(errorText);
		return false;
	}
}

/*
function validate(strForm, password_required) {
	var error = "";
	if (strForm.client) {
		if (strForm.client.value == "") {
			error += "The client name must not be left empty.\n";
		}
	}

	if (strForm.username) {
		if (strForm.username.value == "") {
			error += "The username must not be left empty.\n";
		}
	}

	if (strForm.password) {
		if ((password_required = 1) && (strForm.password.value == "")) {
			error += "Please supply a password for this user.\n";
		} else if ((strForm.password.value != "") && (strForm.password_conf.value == "")) {
			error += "Please confirm the password.\n";
		} else if (strForm.password.value != strForm.password_conf.value) {
			error += "The passwords do not match. Please try again.\n";
		}
	}

	if (error != "") {
		alert (error);
		return false;
	} else {
		return true;
	}
}
*/

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Functions use on the add products page
//

function setOptions(select_input, total, selected) {
	while (select_input.options.length<(total+1)) {
		select_input.options[select_input.options.length] = new Option(select_input.options.length, select_input.options.length);
	}

	while ((select_input.options.length>(total+1)) && (select_input.options.length > 1)) {
		select_input.options[(select_input.options.length)-1] = null;
	}

	for (var i=0; i<select_input.options.length; i++) {
		if (i==selected) {
			select_input.options[i].selected = "selected";
		}
	}
}


function updateExtraPrintOptions(theselect) {
	var num_products = 0;
	var thisform=theselect.form;
	var el=thisform.elements['products_id[]'];
	var qty;
	var extra_product_ids = new Array();
	var extra_product_values = new Array();
	var total_extras = 0;
	
	for (var i=0; i<el.length; i++){
	  if (parseInt((thisform.elements['categories_id[' + parseInt(el[i].value) + ']'].value)) != 4) {
			qty =  parseInt((thisform.elements['quantity[' + parseInt(el[i].value) + ']'].value));
			num_products=(!isNaN(qty))?num_products+qty:num_products;
	  } else {
		  qty =  parseInt((thisform.elements['quantity[' + parseInt(el[i].value) + ']'].value));
		  extra_product_values[parseInt(el[i].value)] = qty;
		  extra_product_ids[extra_product_ids.length] = parseInt(el[i].value);
		  total_extras += qty;
	  }
	}

	i = extra_product_ids.length-1;

	while (total_extras > num_products) {
		if (extra_product_values[extra_product_ids[i]] > 0) {
			extra_product_values[extra_product_ids[i]]--;
			total_extras--;
		} else {
			i--;
		}
	}
	var extras_left = num_products - total_extras;
	
	for (var i=0; i<extra_product_ids.length; i++){
		setOptions(thisform.elements['quantity[' + extra_product_ids[i] + ']'], extra_product_values[extra_product_ids[i]]+extras_left, extra_product_values[extra_product_ids[i]]);
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Confirmations
//

function confirmEmpty() {
	return confirm('Are you sure you want to empty your basket?');
}

function confirmDelete(name, folder) {
	return confirm('You are about to delete the album named \''+name+'\'\nand any user accounts associated with it.\nThe \''+folder+'\' folder and it\'s contents will remain on the\nserver until you delete it.\n\nAre you sure?');
}

function confirmDeleteFolder(folder) {
	return confirm('You are about to delete the folder \''+folder+'\' and it\'s contents from the server.\n\nAre you sure?');
}

function confirmDeleteUser(username) {
	return confirm('Are you sure you want to delete the user \''+username+'\'?');
}

function popup(oLink) {
	var windowName = window.name;
	if (!window.opener) {
		href = oLink.href.indexOf('?') < 0 ? oLink.href + "?popup=1" : oLink.href;
		var popupWindow = window.open(href, "popup", "status=1, toolbar=0, width=650, height=410, scrollbars=yes");
		if (popupWindow) {
			popupWindow.focus();
			return false;
		}
	}
}

var externalWindow;

function openInExternalWindow(oLink) {
	if (!externalWindow) {
		externalWindow = window.open(oLink.href, "external");
	} else {
		externalWindow.location.href = oLink.href;
	}

	if (externalWindow) {
		externalWindow.focus();
		return false;
	}
}

//-->
