   var ajaxRequest;  

   function makeAjaxRequest(url, callback) {  
      if (window.XMLHttpRequest) {  
          ajaxRequest = new XMLHttpRequest();  
      } else if (window.ActiveXObject) {  
          ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");  
      }  
    
      ajaxRequest.open("GET", url, true);  
      ajaxRequest.onreadystatechange = callback;  
      ajaxRequest.send(null);  
   }  
   
   function mAR(url, callback) {  
      if (window.XMLHttpRequest) {  
          ajaxRequest = new XMLHttpRequest();  
      } else if (window.ActiveXObject) {  
          ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");  
      }  
    
      ajaxRequest.open("GET", url, true);  
      ajaxRequest.onreadystatechange = callback;  
      ajaxRequest.send(null);  
   }  

	
function setkeystrokespage(){

	$(function(){
	
		$(document).unbind('keydown');
	
		$(document).keydown(function (e) {
		
      		    var keyCode = e.keyCode || e.which,
          arrow = {left: 37, up: 38, right: 39, down: 40 }, $status = $('#status');

      switch (keyCode) {
        case arrow.left:
			$('#galleryprevclick').click();
        	break;
        case arrow.up:
         	$('#gallerylastclick').click();
        	break;
        case arrow.right:
	 		$('#gallerynextclick').click();
        	break;
        case arrow.down:
          	$('#galleryfirstclick').click();
        	break;
      	}

		
	
		
		})
    });
}

function setkeystrokespopup(){
	$(function(){
	
			$(document).unbind('keydown');
		$(document).keydown(function (e) {
		
      var keyCode = e.keyCode || e.which,
          arrow = {left: 37, up: 38, right: 39, down: 40 }, $status = $('#status');

      switch (keyCode) {
        case arrow.left:
			$('#galmouseprevclick').click();
        	break;
        case arrow.up:
         	$('#gallerylastclickpu').click();
        	break;
        case arrow.right:
	 		$('#galmousenextclick').click();
        	break;
        case arrow.down:
          	$('#galleryfirstclickpu').click();
        	break;
      	}

		
		})
    });
	
	
}



	
	function dispGalAdmin() {



		$(function(){
			$('div#fade').css('filter', 'alpha(opacity=40)');
			$('div#fade').fadeIn(240);
			$("div#purchaseinfopop-up").css("top", (($(window).height() - $("div#purchaseinfopop-up").outerHeight()) / 2) + $(window).scrollTop() + "px");
			$("div#purchaseinfopop-up").css("left", (($(window).width() - $("div#purchaseinfopop-up").outerWidth()) / 2) + $(window).scrollLeft() + "px");
			$('div#purchaseinfopop-up').fadeIn(240);
		});
	}

	
	function hideGalAdmin() {
		$(function(){
			$('div#fade').fadeOut(240);
			$('div#purchaseinfopop-up').fadeOut(240);
		});
	}
	
	function dispHelp(id) {
	
		if (id == '') { id=1; }
		
		makeAjaxRequest('/getdata?act=gethelp&helpid='+id,dispHelpContent);

		$(function(){
			$('div#fade').css('filter', 'alpha(opacity=40)');
			$('div#fade').fadeIn(240);
	
	
			$("div#helpwindowpop-up").css("top", (($(window).height() - $("div#helpwindowpop-up").outerHeight()) / 2) + $(window).scrollTop() + "px");
			$("div#helpwindowpop-up").css("left", (($(window).width() - $("div#helpwindowpop-up").outerWidth()) / 2) + $(window).scrollLeft() + "px");
			$('div#helpwindowpop-up').fadeIn(240);
		});

	};
	
	function closeHelp(id) {
		$(function(){
			$('div#fade').fadeOut(240);
			$('div#helpwindowpop-up').fadeOut(240);
		});

	};
	
	function logincheck(galleryid, passwordfield) {
		alert(galleryid + '/' + passwordfield);
		
		$(function(){
			location.reload();
		});
	
	}
	
	
	function dispAdminPasswordResult(galleryid, passwordfield) {
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("passwordcontent") != null) {
		         	document.getElementById("passwordcontent").innerHTML = ajaxRequest.responseText;  
				}
				
				ajResp = ajaxRequest.responseText;
				// this function needs to be dynamic... I need a refresh on good and a no refresh on bad?? how??
				if (ajResp.indexOf('Password Incorrect') == -1) {
					$(function(){
						var beepOne = $("#beep-good")[0];
						//beepOne.play(); 
					});
					closeAdminPasswordRefresh();
					
				} else {
					// do nothing - leave the text in place
					// beep
					$(function(){
						var beepOne = $("#beep-bad")[0];
						//beepOne.play(); 
					});
				}
				
				
				
	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  
	}


	function dispAJAXimageQuickPopupST() {

		// designed to only update the core image html and the image info links/info.. 
		// saves time on updating.
	
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("ajaxpopupimagecontainer") != null) {
		         	document.getElementById("ajaxpopupimagecontainer").innerHTML = ajaxRequest.responseText;  
				}


				// if this worked okay - then I need to update the image info DIV in the 
				// left gallery pane!... another call inside here

				makeAjaxRequest('/getdata?act=getAJAXImageInfoST',dispAJAXimageinfoPopup);


				// now reset components
				ResetAjaxComponents();
				setkeystrokespopup();
				
	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  

	}	



	function dispPasswordResult(galleryid, passwordfield) {
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("passwordcontent") != null) {
		         	document.getElementById("passwordcontent").innerHTML = ajaxRequest.responseText;  
				}
				
				ajResp = ajaxRequest.responseText;
				// this function needs to be dynamic... I need a refresh on good and a no refresh on bad?? how??
				if (ajResp.indexOf('Password Incorrect') == -1) {
				
					$(function(){
						var beepOne = $("#beep-good")[0];
						//beepOne.play(); 
					});
					
					closePasswordRefresh();
					
				} else {
					// do nothing - leave the text in place
					
					$(function(){
						var beepOne = $("#beep-bad")[0];
						//beepOne.play(); 
					});
				}
				
				
				
	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  
	}
	
	function dispPassword(id) {
		if (id == '') { id=1; }
		
		if (id == 'ADMIN') {
			makeAjaxRequest('/getdata?act=getadmpasswordform&galid=ADMIN',dispPasswordContent);

		} else {
			makeAjaxRequest('/getdata?act=getpasswordform&galid='+id,dispPasswordContent);
		
		}

		$(function(){
			$('div#fade').css('filter', 'alpha(opacity=40)');
			$('div#fade').fadeIn(240);
	
			$("div#passwordpop-up").css("top", (($(window).height() - $("div#passwordpop-up").outerHeight()) / 2) -100 + $(window).scrollTop() + "px");
			$("div#passwordpop-up").css("left", (($(window).width() - $("div#passwordpop-up").outerWidth()) / 2) + $(window).scrollLeft() + "px");
			$('div#passwordpop-up').fadeIn(240);
			
			
		});

	};	
	
	function closePasswordRefresh() {
		$(function(){
			$('div#fade').fadeOut(240);
			$('div#passwordpop-up').delay(1000).fadeOut(240);
			location.reload();

		});
	};
	
	function closeAdminPasswordRefresh() {
		$(function(){
			$('div#fade').fadeOut(240);
			$('div#passwordpop-up').delay(1000).fadeOut(240);
			location.reload();
			
			// set this to /admin if possible

		});
	};
	
	
	function closePassword() {
		$(function(){
			$('div#fade').fadeOut(240);
			$('div#passwordpop-up').fadeOut(240);

		});
	};

	function dispPasswordContent() {

	
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  
				if (document.getElementById("passwordcontent") != null) {
		         	document.getElementById("passwordcontent").innerHTML = ajaxRequest.responseText;  
		         	
		         	$('#passwordinput').focus();
				}
	        } else {  
	            //alert("Cannot load data!");  
	        }  
      	 }  

	}	


function showPurchasePrint(id) {
		makeAjaxRequest('/getdata?act=gethelp&helpid=1',dispHelpContent);

		$(function(){
		$('div#fade').css('filter', 'alpha(opacity=40)');
			$('div#fade').fadeIn(240);
	
	
			$("div#helpwindowpop-up").css("top", (($(window).height() - $("div#helpwindowpop-up").outerHeight()) / 2) + $(window).scrollTop() + "px");
			$("div#helpwindowpop-up").css("left", (($(window).width() - $("div#helpwindowpop-up").outerWidth()) / 2) + $(window).scrollLeft() + "px");
			$('div#helpwindowpop-up').fadeIn(240);
		});

	};
	
	function closePurchasePrint(id) {
		$(function(){
			$('div#fade').fadeOut(240);
			$('div#helpwindowpop-up').fadeOut(240);
		});

	};
	
    function savegalleryadmin(galleryid, sformObject) {
	var dataString = 'action=save' + 
			 '&galid='+ escape(sformObject.elements["galid"].value) + 
			 '&galname='+ escape(sformObject.elements["galname"].value) + 
 			 '&galdesc='+ escape(sformObject.elements["galdesc"].value) + 
			 '&galstatus='+ escape(sformObject.elements["galstatus"].value) + 
			 '&galimage='+ escape(sformObject.elements["galimage"].value) + 
			 '&galparent='+ escape(sformObject.elements["galparent"].value) + 
			 '&galupdating='+ escape(sformObject.elements["galupdating"].value);
	
  	  $.ajax({
 		   type: 'POST',
 		   url: '/galleryadmin/'+galleryid,
 		   data: dataString,
  		   success: function() {
  			    displayDIVPopupwMessage('The Gallery has been updated',1500);
  			     }
               });

          return false;


  	}


 	function dispAlbumInfoBar() {
 		alert('here');
 		$(function() {	$('albuminfobar').fadeIn(240);});
 	}
 	
 	
 	 function hideAlbumInfoBar() {
 	 		alert('here1');
 	 	$(function() {
			$('albuminfobar').fadeOut(240);
		});
 	}


 	function dispBasket() {  
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("basketajax") != null) {
		         	document.getElementById("basketajax").innerHTML = ajaxRequest.responseText;  
				}

	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  
	} 



	function dispOrders() {  
	
		if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("orderdisplay") != null) {
		         	document.getElementById("orderdisplay").innerHTML = ajaxRequest.responseText;  
				}

	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  
	} 

	
	function getimginfo(src, popw, poph){

		jQuery.modal('<iframe style="background-color:#000;border:1px solid #fff;" src="' + src + '" height="' + poph + '" width="' + popw + '" style="border:0">', {
		closeHTML:"",
		containerCss:{
			opacity:10,
			backgroundColor:"#fff",
			borderColor:"#222",					
			overflow:"hidden",
			padding:0
		},overlayCss: {	opacity:10,	backgroundColor:"#000"},
		overlayClose:true
		});
	}


	function loadobjs(){
	if (!document.getElementById)
	return
	for (i=0; i<arguments.length; i++){
	var file=arguments
	var fileref=""
	if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding
	if (file.indexOf(".js")!=-1){ //If object is a js file
	fileref=document.createElement('script')
	fileref.setAttribute("type","text/javascript");
	fileref.setAttribute("src", file);
	}
	else if (file.indexOf(".css")!=-1){ //If object is a css file
	fileref=document.createElement("link")
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", file);
	}
	}
	if (fileref!=""){
	document.getElementsByTagName("head").item(0).appendChild(fileref)
	loadedobjects+=file+" " //Remember this object as being already added to page
	}
	}
	}


	function alertMsg() {  
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

		    	alert(ajaxRequest.responseText);  
				

	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  
	} 


	function alertDIV() {  
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  
				displayDIVPopupwMessage(ajaxRequest.responseText, 1500);
				makeAjaxRequest('/getdata?act=updateBasketCountAjax',updateBasket);

	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  
	} 


	function displayPurchasePrintDialog() {
		if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  
				if (document.getElementById("purchprintdivcontent") != null) {
				   	document.getElementById("purchprintdivcontent").innerHTML = ajaxRequest.responseText;  
				}

	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  
	}

	function displayDIVwImage(imageid, galleryid, scriptcall) {
		// jquery to display via a message div
		// populate div before displaying it	
		
		//alert('scriptcall'+scriptcall);
		makeAjaxRequest('/getdata?act=getAJAXimagePopup&gal='+galleryid+'&image='+imageid+'&scriptcall='+scriptcall,dispAJAXimage);
		
		$(function() {

			// Show Image Window
	 	 	$("div#contentgallery").css("top", (($(window).height() - $("div#contentgallery").outerHeight()) / 2) + $(window).scrollTop() + "px");
			$("div#contentgallery").css("left", (($(window).width() - $("div#contentgallery").outerWidth()) / 2) + $(window).scrollLeft() + "px");
			$('div#contentgallery').fadeIn(240);

		});
		
		setkeystrokespopup();
		

	}
	
		function displayDIVwImageST(imageid, galleryid, scriptcall) {
		// jquery to display via a message div
		// populate div before displaying it	
		
		//alert('scriptcall'+scriptcall);
		makeAjaxRequest('/getdata?act=getAJAXimagePopupST&gal='+galleryid+'&image='+imageid+'&scriptcall='+scriptcall,dispAJAXimage);
		
		$(function() {

			// Show Image Window
	 	 	$("div#contentgallery").css("top", (($(window).height() - $("div#contentgallery").outerHeight()) / 2) + $(window).scrollTop() + "px");
			$("div#contentgallery").css("left", (($(window).width() - $("div#contentgallery").outerWidth()) / 2) + $(window).scrollLeft() + "px");
			$('div#contentgallery').fadeIn(240);

		});
		
		setkeystrokespopup();
		

	}

	function displayDIVPopupwMessage(message, idelay) {
		// jquery to display via a message div
		
		$(function() {

			// Purchase Image Window
			$('div#genericpoptext').html(message);
	 	 	$("div#genericpop-up").css("top", (($(window).height() - $("div#genericpop-up").outerHeight()) / 2) + $(window).scrollTop() + "px");
			$("div#genericpop-up").css("left", (($(window).width() - $("div#genericpop-up").outerWidth()) / 2) + $(window).scrollLeft() + "px");
			var beepOne = $("#beep-good")[0];
			//beepOne.play(); 
			$('div#genericpop-up').fadeIn(240).delay(idelay).fadeOut(240);

		});

	}


	function dispHelpContent() {  
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  
				//alert('callback');			
				if (document.getElementById("ajaxhelpcontent") != null) {
				     	document.getElementById("ajaxhelpcontent").innerHTML = ajaxRequest.responseText;  
				}

	        } else {  
	           
	           ("Cannot load data!");  
	
	        }  
      	     }  
	} 


	function dispAlbumHover(){

		if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  
				if (document.getElementById("albumhover") != null) {
		         	document.getElementById("albumhover").innerHTML = ajaxRequest.responseText;  
				}

	        } else {  
	           // alert("Cannot load data!");  
	
	        }  
      	 }  

	}



	function updateBasket() {  
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("basketcontent") != null) {
		         	document.getElementById("basketcontent").innerHTML = ajaxRequest.responseText;  
				}


				if (document.getElementById("basketcontent2") != null) {
		         	document.getElementById("basketcontent2").innerHTML = ajaxRequest.responseText;  
				}

				
	        } else {  
	            alert("Cannot load data!");  
	
	        }  
      	 }  
	} 


	function dispAJAXimage() {

	
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("contentgallery") != null) {
				
					

		         	document.getElementById("contentgallery").innerHTML = ajaxRequest.responseText;  
					
		
				}

				// if this worked okay - then I need to update the image info DIV

				makeAjaxRequest('/getdata?act=updateAJAXImageInfo',dispAJAXimageinfo);


				// now reset components
				ResetAjaxComponents();
				
	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  

	}	


function dispAJAXimageOptionsPopup() {

		// designed to only update the core image html with an options list 
		// for facebook like/link, send a friend, remind me, updates, etc..
	
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("ajaxpopupimagecontainer") != null) {
		         	document.getElementById("ajaxpopupimagecontainer").innerHTML = ajaxRequest.responseText;  
				}


				// now reset components
				ResetAjaxComponents();
				setkeystrokespopup();
				
	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  

	}	


function dispAJAXimageQuickPopup() {

		// designed to only update the core image html and the image info links/info.. 
		// saves time on updating.
	
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("ajaxpopupimagecontainer") != null) {
		         	document.getElementById("ajaxpopupimagecontainer").innerHTML = ajaxRequest.responseText;  
				}


				// if this worked okay - then I need to update the image info DIV in the 
				// left gallery pane!... another call inside here

				makeAjaxRequest('/getdata?act=getAJAXImageInfo',dispAJAXimageinfoPopup);


				// now reset components
				ResetAjaxComponents();
				setkeystrokespopup();
				
	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  

	}	

	function dispAJAXimageinfoPopup() {

	
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  
				if (document.getElementById("popupimageinfosection") != null) {
		         	document.getElementById("popupimageinfosection").innerHTML = ajaxRequest.responseText;  
				}
	        } else {  
	            //alert("Cannot load data!");  
	        }  
      	 }  

	}	


	function dispAJAXimageinfo() {

	
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("pic_title") != null) {
		         	document.getElementById("pic_title").innerHTML = ajaxRequest.responseText;  
				
				}


				
	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  

	}	
function dispAJAXpageWithPopUp(imageid, galleryid) {

		
	     if (ajaxRequest.readyState == 4) {  

	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("contentfull") != null) {
		         	document.getElementById("contentfull").innerHTML = ajaxRequest.responseText;  

					displayDIVwImage(imageid,galleryid, 'True');

					// now reset components
					ResetAjaxComponents();
					setkeystrokespopup();
				}
				
	        } else {  
	            alert("Cannot load data!");  
	
	        }  
      	 }  

	}	
	
	
	function dispAJAXpage() {

	
	     if (ajaxRequest.readyState == 4) {  

	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("contentfull") != null) {
		         	document.getElementById("contentfull").innerHTML = ajaxRequest.responseText;  

					// now reset components
					ResetAjaxComponents();
					setkeystrokespage();

				}
				
	        } else {  
	            alert("Cannot load data!");  
	
	        }  
      	 }  

	}	


function returnDoNothing() {

	
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				// do nothing!
				
	        } else {  
	            //alert("Cannot load data!");  
	
	        }  
      	 }  

	}	

function sendmsg(sformObject) {
	var dataString = 'act=sendordersms&send=true' + 
			 '&custmobile='+ escape(sformObject.elements["custmobile"].value) + 
			 '&smsfrom='+ escape(sformObject.elements[	"smsfrom"].value) + 
 			 '&smsmessage='+ escape(sformObject.elements["smsmessage"].value);
 	$.ajax({
 		   type: 'POST',
 		   url: '/getdata',
 		   data: dataString,
  		   success: function(data) {
  			    displayDIVPopupwMessage(data,1500);
  			     }
         });


          return false;


} 
  	
  	
function updateBasketwMessageOPDialog() {  
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("addbutton") != null) {
		         	document.getElementById("addbutton").innerHTML = 'Thank You'; 
 
					basketaddmsg = ajaxRequest.responseText;

					makeAjaxRequest('/getdata?act=updateBasketCountAjax',updateBasket);
					// message has been sent back to calling DIV, now display a proper message and 
					// fade out this and the other div.

					
					$('div#purchaseinfopop-up').delay(10).fadeOut(240);
					$('div#fade').delay(4000).fadeOut(240);
					displayDIVPopupwMessage(basketaddmsg, 4000);

				}		

				//alert('Basket Updated');
	        } else {  
	            alert("An error has occurred - sorry! Please try again.");  
	
	        }  
      	 }  
	} 


	function updateBasketwMessage() {  
	     if (ajaxRequest.readyState == 4) {  
	        if (ajaxRequest.status == 200) {  

				if (document.getElementById("basketcontent") != null) {
		         	document.getElementById("basketcontent").innerHTML = ajaxRequest.responseText;  
				}


				if (document.getElementById("basketcontent2") != null) {
		         	document.getElementById("basketcontent2").innerHTML = ajaxRequest.responseText;  
				}

				alert('Basket Updated');
	        } else {  
	            alert("Cannot load data!");  
	
	        }  
      	 }  
	} 


