/************************************************************************
 * @name: bPopup
 * @author: (c) Bjoern Klinggaard (http://dinbror.dk/bpopup)
 * @version: 0.5.1.min
 ************************************************************************/
(function(a){a.fn.openPopup=function(h,j){function s(){b.css({left:!o.follow[1]&&k?d:c.scrollLeft()+d,position:"absolute",top:!o.follow[0]&&l?e:c.scrollTop()+e,"z-index":o.zIndex}).appendTo(o.appendTo).hide(1,function(){a.isFunction(o.onOpen)&&o.onOpen.call(b);if(o.loadUrl!=null)switch(o.contentContainer=o.contentContainer==null?b:a(o.contentContainer),o.content){case "iframe":a('<iframe scrolling="no" frameborder="0"></iframe>').attr("src",o.loadUrl).appendTo(o.contentContainer);break;default:o.contentContainer.load(o.loadUrl)}}).fadeIn(o.fadeSpeed,function(){a.isFunction(j)&&j()});t()}function i(){o.modal&&a("#bModal").fadeOut(o.fadeSpeed,function(){a("#bModal").remove()});b.fadeOut(o.fadeSpeed,function(){o.loadUrl!=null&&o.contentContainer.empty()});o.scrollBar||a("html").css("overflow","auto");a("."+o.closeClass).die("click");a("#bModal").die("click");c.unbind("keydown.openPopup");f.unbind(".openPopup");b.data("openPopup",null);a.isFunction(o.onClose)&&setTimeout(function(){o.onClose.call(b)},o.fadeSpeed);return!1}function u(){if(n||v){var a=[c.height(),c.width()];return{"background-color":o.modalColor,height:a[0],left:m(),opacity:0,position:"absolute",top:0,width:a[1],"z-index":o.zIndex-1}}else return{"background-color":o.modalColor,height:"100%",left:0,opacity:0,position:"fixed",top:0,width:"100%","z-index":o.zIndex-1}}function t(){a("."+o.closeClass).live("click",i);o.modalClose&&a("#bModal").live("click",i).css("cursor","pointer");(o.follow[0]||o.follow[1])&&f.bind("scroll.openPopup",function(){b.stop().animate({left:o.follow[1]?c.scrollLeft()+d:d,top:o.follow[0]?c.scrollTop()+e:e},o.followSpeed)}).bind("resize.openPopup",function(){if(o.modal&&n){var a=[c.height(),c.width()];p.css({height:a[0],width:a[1],left:m()})}g=q(b,o.amsl);o.follow[0]&&(e=l?e:c.scrollTop()+g[0]);o.follow[1]&&(d=k?d:c.scrollLeft()+g[1]);b.stop().animate({left:d,top:e},o.followSpeed)});o.escClose&&c.bind("keydown.openPopup",function(a){a.which==27&&i()})}function m(){return f.width()<a("body").width()?0:(a("body").width()-f.width())/2}function q(a,b){var c=(f.height()-a.outerHeight(!0))/2-b,d=(f.width()-a.outerWidth(!0))/2+m();return[c<20?20:c,d]}a.isFunction(h)&&(j=h,h=null);o=a.extend({},a.fn.openPopup.defaults,h);o.scrollBar||a("html").css("overflow","hidden");var b=a(this),p=a('<div id="bModal"></div>'),c=a(document),f=a(window),g=q(b,o.amsl),l=o.position[0]!="auto",k=o.position[1]!="auto",e=l?o.position[0]:g[0],d=k?o.position[1]:g[1],r=navigator.userAgent.toLowerCase(),v=r.indexOf("iphone")!=-1,n=/msie 6/i.test(r)&&typeof window.XMLHttpRequest!="object";this.close=function(){o=b.data("openPopup");i()};return this.each(function(){b.data("openPopup")||(o.modal&&p.css(u()).appendTo(o.appendTo).animate({opacity:o.opacity},o.fadeSpeed),b.data("openPopup",o),s())})};a.fn.openPopup.defaults={amsl:50,appendTo:"body",closeClass:"bClose",content:"ajax",contentContainer:null,escClose:!0,fadeSpeed:250,follow:[!0,!0],followSpeed:500,loadUrl:null,modal:!0,modalClose:!0,modalColor:"#000",onClose:null,onOpen:null,opacity:0.7,position:["auto","auto"],scrollBar:!0,zIndex:9999}})(jQuery);

//SHOPPING BASKET FUNCTIONS

function addToBasket(productId, productName, productQuan, mapval, productPrice){
	document.productForm.productId.value = productId
	document.productForm.productName.value = productName 
	document.productForm.productQuan.value = productQuan
	document.productForm.Price.value = productPrice
	document.productForm.submit()
}

function doDelete(quantityInputId, productName)
{
	var strQuery = "Are you sure you want to remove the item '" + productName + "' from your basket?";
	var agree = confirm(strQuery);
	if (agree)
	{
		quantityInputId.value = 0;
		quantityForm.goToCheckout.value=0;
		quantityForm.submit()

	}
}

//END SHOPPING BASKET FUNCTIONS

function checkBlank(elementArray,showMessage){

var testVal
var failedNames = ""

testVal = ""
var failedItems = new Array()

	for (index=0;index < elementArray.length;index++){
		testVal = elementArray[index].value
		if(testVal.length < 1){
			failedItems[failedItems.length] = elementArray[index]
			failedNames = failedNames + (failedNames.length>0?",":"") + elementArray[index].name 

		}
	}
	if (showMessage && failedNames.length > 0){
		alert ("Please enter data into the following field(s): " + failedNames)	
	}
	return failedItems;

}
function checkNumeric(elementArray,showMessage){
var testVal
var failedItems = new Array()
var failedNames = ""

testVal = ""
	for (index=0;index < elementArray.length;index++){
		testVal = elementArray[index].value
		if(isNaN(testVal)){
			failedItems[failedItems.length] = elementArray[index]
			failedNames = failedNames + (failedNames.length>0?",":"") + elementArray[index].name 

		}
	}
	
	if (showMessage && failedNames.length > 0){
		alert ("The following item(s) may only contain numbers: " + failedNames)	
	}
	return failedItems
}

function checkEmail(elementArray,showMessage){
	 //make sure there's an '@' followed at some point by a '.'
	 var atLoc
	 var failedItems = new Array()
	 var failedNames = ""
	for (index=0;index < elementArray.length;index++){
		 emailStr = elementArray[index].value
		 atLoc = emailStr.indexOf("@")
		 if (atLoc > 0){
			if(emailStr.indexOf(".",atLoc) > 0){
				continue;
				
			}
		 }
		failedItems[failedItems.length] = elementArray[index]
		failedNames = failedNames + (failedNames.length>0?",":"") + elementArray[index].name 

	}
	//if we get here then the email is not valid
	if (showMessage && failedNames.length > 0){
		alert ("Please enter a valid email address for the following field(s): " + failedNames)	
	}
	return failedItems

}
 

//GOOGLE MAPS
	//<![CDATA[
	// global arrays to hold copies of the markers used by the side_bar
	var gmarkers = [];
	// global "map" variable
    var map;

    // This function picks up the click and opens the corresponding info window
    function myclick(i) {
      GEvent.trigger(gmarkers[i], "click");
    }
    
    
    function load() {
      if (GBrowserIsCompatible()) {
      	
      // this variable will collect the html which will eventualkly be placed in the side_bar
      var side_bar_html = "";
      var i = 0;
      
      
      

      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {
        var marker = new GMarker(point);
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        // save the info we need to use later for the side_bar
        gmarkers[i] = marker;
        // add a line to the side_bar html
        side_bar_html += '<a href="javascript:myclick(' + i + ')" style="float: left; margin-left: 30px; color:#000000; cursor: pointer" >' + name + '</a>';
        i++;
        return marker;
      }
      	
      	
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(54.5981, -5.9306), 15);
        
      // create the map using the global "map" variable
      map.addControl(new GSmallMapControl());
      map.addControl(new GMapTypeControl());

      // add the points    

      var point = new GLatLng( 54.5981,-5.9306);
      var marker = createMarker(point,"<div style='float: left; text-align: center; margin-left: 80px;'><strong>John H Lunn (Jewellers) Ltd</strong><br /><span style='font-weight: 100 !important'>Queen's Arcade<br />Belfast<br />BT1 5FE<br /></span></div>","<h2 style='color: #000;'>Lunn's Queen's Arcade</h2><p style='color: #aaa;'>Belfast<br />BT1 5FE<br /></p>")
      map.addOverlay(marker); 

      //var point = new GLatLng( 54.59942, -5.93037);
      //var marker = createMarker(point,"<div style='float: left; text-align: center; margin-left: 0px;'><strong>Lunns II</strong><br /><span style='font-weight: 100 !important'>7-9 Royal Avenue<br />Belfast<br />BT1 1FB</span></div>","<h2 style='color: #000;'>Lunns II</h2><p style='color: #aaa;'><br />7-9 Royal Avenue<br />Belfast<br />BT1 1FB<br /></p>")
      map.addOverlay(marker);


      var point = new GLatLng( 54.5980,-5.9256);
      var marker = createMarker(point,"<div style='float: left; text-align: center; margin-left: 0px;'><strong>John H Lunn (Jewellers) Ltd</strong><br />1 Victoria Square<br /><span style='font-weight: 100 !important'>Belfast<br>BT1 4QG</span></div>","<h2 style='color: #000;'>Lunn's Victoria Square</h2><p style='color: #aaa;'>1 Victoria Square<br />Belfast<br>BT1 4QG</p>")
      map.addOverlay(marker);
      
      var point = new GLatLng(54.9962,-7.3209);
      var marker = createMarker(point,"<div style='float: left; text-align: center; margin-left: 0px;'><strong>John H Lunn (Jewellers) Ltd</strong><br /><span style='font-weight: 100 !important'>10 Shipquay Street<br />Londonderry<br>BT48 6DN</span></div>","<h2 style='color: #000;'>Lunn's Londonderry</h2><p style='color: #aaa;'>10 Shipquay Street<br />Londonderry<br>BT48 6DN</p>")
      map.addOverlay(marker);
      




                       
                       
      // put the assembled side_bar_html contents into the side_bar div
      document.getElementById("side_bar").innerHTML = side_bar_html;
      
      }
    }

    //]]>    

