function sfHover() {
     var sfEls = document.getElementById("navmenu").getElementsByTagName("li");
     for (var i=0; i < sfEls.length; i++) {
          sfEls[i].onmouseover = function()
          {
               this.className += " sfhover";
          }
          sfEls[i].onmouseout = function()
          {
               this.className = this.className.replace(new RegExp("sfhover\\b"), "");
          }
     }
}// end function

function previewImage(sourceLink, width, height) {
	
	var prwidth = (width+300);
	var prheight = (height+20);
	
	window.open("http://www.artsphotography.co.uk/customer/preview_image.php?im="+escape(sourceLink.href), "blank", "'toolbar=no,height=" + prheight + ",width=" + prwidth + ",resizable=yes,scrollbars=yes'");
	
	return false;
}

function previewImage2(sourceLink, width, height) {
	
	var prwidth = (width+300);
	var prheight = (height+20);
	
	window.open("http://www.artsphotography.co.uk/customer/preview_image2.php?im="+escape(sourceLink.href), "blank", "'toolbar=no,height=" + prheight + ",width=" + prwidth + ",resizable=yes,scrollbars=yes'");
	
	return false;
}


function previewImageBuy(sourceLink, width, height, id) {
	
	var prwidth = (width+300);
	var prheight = (height+20);
	
	window.open("http://www.artsphotography.co.uk/customer/preview_image.php?im="+escape(sourceLink.href)+"&id="+id, "blank", "'toolbar=no,height=" + prheight + ",width=" + prwidth + ",resizable=yes,scrollbars=yes'");
	
	return false;
}

var b = 0;	
var topUp;
var toDown;
var offset = 0;

function initScroll() {
	offset = document.getElementById("scrolling_text").offsetHeight - document.getElementById("eventlist").offsetHeight;
}

function scrollDUp() {
	toUp = setTimeout('scrollDUp()', 50);
	if (b) b -= 3;
	document.getElementById("eventlist").scrollTop = b;
}

function scrollDDown() {
	toDown = setTimeout('scrollDDown()', 50);
	if (b < offset+3) b += 3;
	document.getElementById("eventlist").scrollTop = b;
}

function stopScroll(direction) {
	if (direction == "Down")
		clearTimeout(toDown);
	else
		clearTimeout(toUp);
}

function presence(field, alertmsg) {
	with (field) {
		if (value == null || value == "") {
			alert(alertmsg);
			return false;
		} else {
			return true;
		}// end if
	}// end with
}// end function


function validate_contactFrm(thisform) {
	with (thisform)	{
		if (presence(contact_name,"Please enter your name") == false) {
			contact_name.focus();
			return false;
		}// end if
		if (presence(contact_telephone,"Please enter your telephone number") == false) {
			contact_telephone.focus();
			return false;
		}// end if
		if (presence(contact_email,"Please enter your email address") == false) {
			contact_email.focus();
			return false;
		}// end if
	}//end with
}// end function	

 

function move_in(img_name,img_src) {
	document[img_name].src=img_src;
}
function move_in_by_id(img_name,img_src) {
	document.getElementById(img_name).src=img_src;
}

function move_out(img_name,img_src) {
	document[img_name].src=img_src;
}
function move_out_by_id(img_name,img_src) {
	document.getElementById(img_name).src=img_src;
}


/* --  Your Experience SUB NAV styles -- */
function rollOver(id, classname)   {
   var item = "txtlink" + id;
   var imgitem = "imglink" + id;
   document.getElementById(item).style.color = '#DD0067';   
   document.getElementById(imgitem).className = classname;
}

function rollOut (id, classname)   {
   var item = "txtlink" + id;
   var imgitem = "imglink" + id;
   document.getElementById(item).style.color = '#669999';
   document.getElementById(imgitem).className = classname;   
}


/************************************************************************************************************
(C) www.dhtmlgoodies.com, October 2005

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	

Updated:	
	March, 11th, 2006 - Fixed positioning of tooltip when displayed near the right edge of the browser.
	April, 6th 2006, Using iframe in IE in order to make the tooltip cover select boxes.
	
Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/	
var dhtmlgoodies_tooltip = false;
var dhtmlgoodies_tooltipShadow = false;
var dhtmlgoodies_shadowSize = 2;
var dhtmlgoodies_tooltipMaxWidth = 200;
var dhtmlgoodies_tooltipMinWidth = 100;
var dhtmlgoodies_iframe = false;
var tooltip_is_msie = (navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('opera')==-1 && document.all)?true:false;

function showTooltip(e,tooltipTxt)
{
	
	var bodyWidth = Math.max(document.body.clientWidth,document.documentElement.clientWidth) - 20;

	if(!dhtmlgoodies_tooltip){
		dhtmlgoodies_tooltip = document.createElement('DIV');
		dhtmlgoodies_tooltip.id = 'dhtmlgoodies_tooltip';
		dhtmlgoodies_tooltipShadow = document.createElement('DIV');
		dhtmlgoodies_tooltipShadow.id = 'dhtmlgoodies_tooltipShadow';
		
		document.body.appendChild(dhtmlgoodies_tooltip);
		document.body.appendChild(dhtmlgoodies_tooltipShadow);	
		
		if(tooltip_is_msie){
			dhtmlgoodies_iframe = document.createElement('IFRAME');
			dhtmlgoodies_iframe.frameborder='5';
			dhtmlgoodies_iframe.style.backgroundColor='#FFFFFF';
			dhtmlgoodies_iframe.src = '#'; 	
			dhtmlgoodies_iframe.style.zIndex = 100;
			dhtmlgoodies_iframe.style.position = 'absolute';
			document.body.appendChild(dhtmlgoodies_iframe);
		}
		
	}
	
	dhtmlgoodies_tooltip.style.display='block';
	dhtmlgoodies_tooltipShadow.style.display='block';
	if(tooltip_is_msie)dhtmlgoodies_iframe.style.display='block';
	
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	
	var leftPos = e.clientX + 10;
	
	dhtmlgoodies_tooltip.style.width = null;	// Reset style width if it's set 
	dhtmlgoodies_tooltip.innerHTML = tooltipTxt;
	dhtmlgoodies_tooltip.style.left = leftPos + 'px';
	dhtmlgoodies_tooltip.style.top = e.clientY + 5 + st + 'px';

	
	dhtmlgoodies_tooltipShadow.style.left =  leftPos + dhtmlgoodies_shadowSize + 'px';
	dhtmlgoodies_tooltipShadow.style.top = e.clientY + 5 + st + dhtmlgoodies_shadowSize + 'px';
	
	if(dhtmlgoodies_tooltip.offsetWidth>dhtmlgoodies_tooltipMaxWidth){	/* Exceeding max width of tooltip ? */
		dhtmlgoodies_tooltip.style.width = dhtmlgoodies_tooltipMaxWidth + 'px';
	}
	
	var tooltipWidth = dhtmlgoodies_tooltip.offsetWidth;		
	if(tooltipWidth<dhtmlgoodies_tooltipMinWidth)tooltipWidth = dhtmlgoodies_tooltipMinWidth;
	
	
	dhtmlgoodies_tooltip.style.width = tooltipWidth + 'px';
	dhtmlgoodies_tooltipShadow.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
	dhtmlgoodies_tooltipShadow.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';		
	
	if((leftPos + tooltipWidth)>bodyWidth){
		dhtmlgoodies_tooltip.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth)) + 'px';
		dhtmlgoodies_tooltipShadow.style.left = (dhtmlgoodies_tooltipShadow.style.left.replace('px','') - ((leftPos + tooltipWidth)-bodyWidth) + dhtmlgoodies_shadowSize) + 'px';
	}
	
	if(tooltip_is_msie){
		dhtmlgoodies_iframe.style.left = dhtmlgoodies_tooltip.style.left;
		dhtmlgoodies_iframe.style.top = dhtmlgoodies_tooltip.style.top;
		dhtmlgoodies_iframe.style.width = dhtmlgoodies_tooltip.offsetWidth + 'px';
		dhtmlgoodies_iframe.style.height = dhtmlgoodies_tooltip.offsetHeight + 'px';
	
	}
			
}

function hideTooltip()
{
	dhtmlgoodies_tooltip.style.display='none';
	dhtmlgoodies_tooltipShadow.style.display='none';		
	if(tooltip_is_msie)dhtmlgoodies_iframe.style.display='none';		
}

//New Javascript Functions for Arts Photography
//---------------------------------------------
//Top Section contains page specific browsing
//functions. While the bottom half contains
//miscellaneous functions, for site-wide use.


/***********PAGE SPECIFIC FUNCTIONS***********/

function criteria_sub_browse() {
	// Files :
	// subject_browse.php
	// organisation_browse.php
	
	document.getElementById("c").style.display = 'none';
	document.getElementById("d").style.display = 'none';
	document.getElementById("e").style.display = 'none';
	document.getElementById("f").style.display = 'none';
	
	if(document.forms[0].search_period.value == 1) {
		document.getElementById("c").style.display = '';
		document.getElementById("d").style.display = '';
		document.getElementById("e").style.display = '';
		document.getElementById("f").style.display = '';
	}	
	
}// end function

function criteria_shoot_browse() {
	// Files :
	//photoshoot_browse.php
	
	document.getElementById("c").style.display = 'none';
	document.getElementById("d").style.display = 'none';
	document.getElementById("e").style.display = 'none';
	document.getElementById("f").style.display = 'none';
	
	if(document.forms[0].over.value == 1) {
		document.getElementById("c").style.display = '';
		document.getElementById("d").style.display = '';
		document.getElementById("e").style.display = '';
		document.getElementById("f").style.display = '';
	}	
	
}// end function

function criteria_pshoot() {
	// Files :
	// subject_browse.php
	
	document.getElementById("a").style.display = 'none';
	
	if(document.forms[0].id.value == 0) {
		document.getElementById("a").style.display = '';
	}	
	
}// end function

function delivery_same()
{
	if (document.getElementById("deli_same").checked)
	{
		document.getElementById("d1").value = document.getElementById("s1").value;
		document.getElementById("d2").value = document.getElementById("s2").value;
		document.getElementById("d3").value = document.getElementById("s3").value;
		document.getElementById("d4").value = document.getElementById("s4").value;
	}
}// end function


function delivery_same_checkout()
{
	if (document.getElementById("deli_same").checked)
	{
		document.getElementById("d1").value = document.getElementById("s1").value;
		document.getElementById("d2").value = document.getElementById("s2").value;
		document.getElementById("d3").value = document.getElementById("s3").value;
		document.getElementById("d4").value = document.getElementById("s4").value;
		document.getElementById("d5").value = document.getElementById("s5").value;
	}
}// end function

function delivery_clear()
{
	document.getElementById("deli_same").checked = false;
}

function reset_cust()
{
	document.getElementById("cust_id").value = 0;
}

function enableSubStep(step_id)
{
	document.getElementById("substep").style.display = "";
	document.getElementById("substep"+step_id).style.display = "";
}


function sfHover() {
     var sfEls = document.getElementById("nav").getElementsByTagName("li");
     for (var i=0; i < sfEls.length; i++) {
          sfEls[i].onmouseover = function()
          {
               this.className += " sfhover";
          }
          sfEls[i].onmouseout = function()
          {
               this.className = this.className.replace(new RegExp("sfhover\\b"), "");
          }
     }
}// end function


function checkedAll (id) {
		var el = document.getElementById(id);
		var checked = false;
		if (document.browseFrm.checkflag.value == 0) {
			checked = true;
			document.browseFrm.checkflag.value = 1;
		} else {
			document.browseFrm.checkflag.value = 0;
		}// end if
		
		for (var i = 0; i < el.elements.length; i++) {
		  el.elements[i].checked = checked;
		}// end FOR		
}// end function

function criteria_3() {
	// Files :
	document.getElementById("a").style.display = 'none';
	document.getElementById("b").style.display = 'none';
	document.getElementById("c").style.display = 'none';
	document.getElementById("d").style.display = 'none';
	document.getElementById("e").style.display = 'none';
	document.getElementById("f").style.display = 'none';
	
	if(document.forms[0].search_tc.value > 0) {
		document.getElementById("a").style.display = '';
		document.getElementById("b").style.display = '';
	}	
	
	if(document.forms[0].search_period.value == 7) {
		document.getElementById("c").style.display = '';
		document.getElementById("d").style.display = '';
		document.getElementById("e").style.display = '';
		document.getElementById("f").style.display = '';
	}	
}// end function

function criteria_4() {
	// Files :
	document.getElementById("a").style.display = 'none';
	document.getElementById("b").style.display = 'none';
	document.getElementById("c").style.display = 'none';
	document.getElementById("d").style.display = 'none';
	document.getElementById("e").style.display = 'none';
	document.getElementById("f").style.display = 'none';
	
	if(document.forms[0].over.value != 0) {
		
	document.getElementById("a").style.display = '';
	document.getElementById("b").style.display = '';
	document.getElementById("c").style.display = '';
	document.getElementById("d").style.display = '';
	document.getElementById("e").style.display = '';
	document.getElementById("f").style.display = '';
	
	}
}// end function

/***********************************************/






/***********BROWSING FILTER FUNCTIONS***********/

function setOffset(value)
{
	document.forms[0].offset.value = value;
}

function setLimit(value)
{
	document.forms[0].limit.value = value;
}

/***********************************************/








/***********MISC SITE WIDE FUNCTIONS***********/

// whitespace characters
var whitespace = " \t\n\r";

//The function below is used to selecte multiple check
//boxes when "check all" is clicked.							

function IsNumeric(strString, message)
{
	var strValidChars = "0123456789.";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			alert(message);
			return false;
		}
	}
	return true;
}


//The function below is used to selecte multiple check
//boxes when "check all" is clicked

function checkAll (frmNumber, selection_name) { 

       // Check to Un / Check all
       var TotalBoxes = 0;
       var TotalOn = 0;
       var status = true;
       var selection_len = selection_name.length;
              
       for (var i = 0; i < document.forms[frmNumber].elements.length; i++) {
              var e = document.forms[frmNumber].elements[i];
              if ( e.name.substring(0, selection_len) == selection_name ) {
                     TotalBoxes++;
                     if (e.checked || e.disabled) {
                           TotalOn++;
                     }//end if
              }// end if
       }// end FOR

       if (TotalBoxes == TotalOn) {
              status = false;
       }// end if
              
       for (var i = 0; i < document.forms[frmNumber].elements.length; i++) {      
              var e = document.forms[frmNumber].elements[i];  
              if ( e.name.substring(0, selection_len) == selection_name && e.disabled == false )
                     e.checked = status;
       }// end FOR          

}// end function


//Functions below are for use with form validation
//The isEmpty and isWhitespace functions were taken straight from
//Netscape's JavaScript development site, http://developer.netscape.com.

function presence(field, alertmsg) {
	with (field) {
		if (value == null || value == "") {
			alert(alertmsg);
			return false;
		} else {
			return true;
		}// end if
	}// end with
}// end function

// Check whether string s  empty.
function isEmpty(s)
{ return ((s == null) || (s.length == 0)) }


function isWhitespace (s)
{
   var i;

   if (isEmpty(s)) return true;

   for (i = 0; i < s.length; i++)
   {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
   }

   return true;
}


function ForceEntry(val) {
   var strInput = new String(val.value);

   if (isWhitespace(strInput)) {
        return false;
   } else
        return true;

}

var imgCheck;
var selString;
var numToSelect;
var initialised = false;

function setImgCheckSize(arSize)
{
	imgCheck = new Array(arSize);
	numToSelect = arSize;
	initialised = true;
}

function imgChosen(imgNum) {
	var found = -1;
	var empty = -1;
	var photoID = "photo"+imgNum;
	var dotID = "dot"+imgNum;
	
	if (initialised)
	{
		for (i=0; i<imgCheck.length; i++)
		{
			if (imgCheck[i] == null && empty == -1) {empty = i;}
			if (imgCheck[i] == imgNum) {found = i;}
		}
		
		if (found == -1)
		{
			if (empty == -1)
			{
				alert ("You have selected too many images, please deselect an image first.");
				return false;
			}
			else
			{
				document.getElementById(photoID).style.borderColor = "#ec008c";
				var dotSrc = document.getElementById(dotID).src;
				var lioSlash = dotSrc.lastIndexOf('/');
				document.getElementById(dotID).src = dotSrc.substring(0,lioSlash+1)+"dot_selected.gif";
				imgCheck[empty] = imgNum;
			}
		}
		else 
		{
			document.getElementById(photoID).style.borderColor = "#efefef";
			var dotSrc = document.getElementById(dotID).src;
			var lioSlash = dotSrc.lastIndexOf('/');
			document.getElementById(dotID).src = dotSrc.substring(0,lioSlash+1)+"dot_unselected.gif";
			imgCheck[found] = null;
		}
		
		selString = "";
		for (i=0; i<imgCheck.length; i++)
		{
			if (imgCheck[i] != null) selString = selString+imgCheck[i]+";";
		}
		document.getElementById("selImgs").value = selString;
	}
}

function checkImgChosen(pkrules)
{
	var empty = -1;
	var ecount = 0;
	for (i=0; i<imgCheck.length; i++)
	{
		if (imgCheck[i] == null) {empty = i; ecount++;}
	}
	
	if (pkrules){
		if (ecount == imgCheck.length){
			alert ("You need to select at least 1 image for a pack.");
			return false;
		}
	}
	else if (empty > -1) {
		alert ("You have not selected enough images, you need to select "+numToSelect);
		return false;
	}
	else return true;
}

function productType()
{
	document.getElementById("a").style.display = "none";
	document.getElementById("b").style.display = "none";
	document.getElementById("c").style.display = "none";
	document.getElementById("d").style.display = "none";

	if (document.getElementById("ptype").value == 1)
	{
		document.getElementById("a").style.display = "";
		document.getElementById("b").style.display = "";		
		document.getElementById("c").style.display = "";
		document.getElementById("d").style.display = "";
	}
}

function loadRange(range_id)
{
	document.getElementById("rangeid").value = range_id;
	document.orderform.submit();
}

function loadPres(pres_id)
{
	document.getElementById("presid").value = pres_id;
	document.orderform.submit();
}

var prodArr = new Array();
var chkKeys = new Array();

function loadProduct()
{
	var pid = document.getElementById("sel_product").value;
	
	var gridh = "";
	var numh = "";
	var ppre = "";
	var pkh = "none";
	
	if (prodArr[pid][2].length < 1)	{gridh = "none"; numh = "none";}
	if (prodArr[pid][5] != "Pack")	{pkh = "";}
	if (prodArr[pid][6].length < 1) {ppre = "none";}
	
	document.getElementById("gridh1").style.display = gridh;
	document.getElementById("gridh2").style.display = gridh;
	document.getElementById("numh1").style.display = numh;
	document.getElementById("numh2").style.display = numh;
	document.getElementById("pkh1").style.display = pkh;
	document.getElementById("pkh2").style.display = pkh;
	document.getElementById("pkh3").style.display = pkh;
	document.getElementById("pkh4").style.display = pkh;
	document.getElementById("mmou").style.display = ppre;
	
	document.getElementById("num_images").innerHTML = prodArr[pid][1];
	document.getElementById("grid").innerHTML = prodArr[pid][2];
	document.getElementById("print").innerHTML = prodArr[pid][4];
	document.getElementById("frame").innerHTML = prodArr[pid][3];
	document.getElementById("type").innerHTML = prodArr[pid][5];
	document.getElementById("desc").innerHTML = prodArr[pid][7];
	document.getElementById("prod_img").src = prodArr[pid][6];
}

function addToProducts(id, imcount, layout, fsize, isize, type, src, desc)
{
	if (!fsize) fsize = "(not applicable)";
	prodArr[id] = new Array(id, imcount, layout, fsize, isize, type, src, desc);
}

function addChkKey(chk_num)
{
	chkKeys[chkKeys.length] = chk_num;
}

function allocationPreview(p_id, c_id)
{
	var allocLine = "";
	if (checkAllocation())
	{
		for (i=0; i<chkKeys.length; i++) 
		{
			var selectVal = document.getElementById("location"+chkKeys[i]).value;
			allocLine += selectVal+":"+chkKeys[i]+";";
			window.open ('customer_allocation.php?alloc='+allocLine+p_id+";"+c_id, 'mywindow','menubar=1,resizable=1,width=450,height=450');
		}
	}
}

function checkAllocation()
{
	var chosenString = "";
	
	for (i=0; i<chkKeys.length; i++)
	{
		var selectVal = document.getElementById("location"+chkKeys[i]).value;
		if (selectVal != "-")
		{
			if (chosenString.indexOf(selectVal) > -1)
			{
				alert ("You have duplicate selections. Only 1 image may be placed in a region.");
				return false;
			}
			chosenString = chosenString + selectVal;
		}
		else
		{
			alert ("You have unallocated photos. Please ensure all regions have an allocated photos");
			return false;
		}
	}
	return true;
}

var mCount = 0;
var kCount = 0;
var mouldArr = new Array();
var mouldKArr = new Array();

function addMould(mid, mname, fname)
{
	mItem = new Array(mname, mid, fname);
	
	mouldArr[mCount++] = mItem;
}

function addMKey(key)
{
	mouldKArr[kCount++] = key;
}

function loadMould()
{
	mould_selected = document.getElementById("sel_mould").value;
	
	for (var l=0; l<mouldArr.length; l++)
	{
		if (mouldArr[l][1] == mould_selected)
		{
			document.getElementById("mould_img").src = mouldArr[l][2];
		}
	}
}

function narrowMoulds()
{
	toNarrow = document.getElementById("mouldTypes").value.toLowerCase();
	
	document.getElementById("sel_mould").options.length = 0;

	var p = 0;
	
	for (var m=0; m<mouldArr.length; m++)
	{
		ttext = mouldArr[m][0].toLowerCase();
		if (mouldArr[m][0].toLowerCase().indexOf(toNarrow) > -1 || toNarrow == "all") 
		{
			document.getElementById("sel_mould").options[p++] = new Option(mouldArr[m][0],mouldArr[m][1]);
		}
	}
	
	loadMould();
}

var catDescs = new Array();

function addCategoryDesc(cat_id, cat_desc)
{
	catDescs.push(new Array(cat_id, cat_desc));
}

function loadCatDesc(cat_id) {
	for (var i=0; i<catDescs.length; i++) {
		if (catDescs[i][0] == cat_id) {
			document.getElementById("secDescInsert").innerHTML = catDescs[i][1];
			break;
		}
	}
	return false;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function hideTemplates()
{
	document.getElementById("hhg1").style.display = "none";
	document.getElementById("hhg2").style.display = "none";
}

function showTemplates()
{
	document.getElementById("hhg1").style.display = "inline";
	document.getElementById("hhg2").style.display = "inline";
}

function calculateVAT(input_name)
{
	if (IsNumeric(input_name.value, "Value must be a number!"))
	input_name.value = (input_name.value / 1.175).toFixed(2);
}
/***********************************************/