// JavaScript Document
var ajax;
var viewer;
var total;
function get_cart() {

 ajax =  new Ajax.Updater(
         'cart',        // DIV id must be declared before the method was called
         'gallery_cart.php',        // URL
         {                // options
         method:'get' , onSuccess :function(){
		//new Effect.Highlight('cart', {startcolor:'#FFFFFF', endcolor:'#DFEBEE', duration:.3});
new Effect.Highlight('cart', {startcolor:'#b2bfbf', endcolor:'#FFFFFF', duration:.3,queue:'end', onSuccess :function(){
		//new Effect.Highlight('cart', {startcolor:'#FFFFFF', endcolor:'#DFEBEE', duration:.3});
//alert(t.responseText);
			 
		 },
    onFailure: function(t) {
        //alert('Error ' + t.status + ' -- ' + t.statusText);
    }
		 
		 })	; 
			 
		 }
             });

}

function showResponse(req)
{
$('cart').innerHTML = req.responseText;
}
function update_cart(imageID){
get_cart();
}
function num_submit(){ 
document.getElementById('num_images').submit();
}
function show_viewer(imageID){
	
	//alert(document.getElementById('photo_viewer').style.display );
	
	 document.getElementById('photo_viewer_body').innerHTML = "<p>Loading Requested Photo</p>";
	if(document.getElementById('viewer_bg').style.display == 'none'){
	//new Effect.toggle('viewer_bg',"appear" ,{duration:1}); 
	new Effect.Opacity('viewer_bg',
    { duration: 1.0, 
      transition: Effect.Transitions.linear,
	  beforeUpdate: function(){
		  document.getElementById('viewer_bg').style.display = 'block';
	  },
      from: 0, to: 0.2 });
	new Effect.Opacity('photo_v',
    { duration: 1.0, 
      transition: Effect.Transitions.linear,
	  beforeUpdate: function(){
		  document.getElementById('photo_v').style.display = 'block';
	  },
      from: .5, to: 1 ,
	  queue : 'end'});
	//document.getElementById('viewer_bg').style.display == "block";
	}
	if(document.getElementById('photo_v').style.display == 'none'){
	//new Effect.toggle('photo_v',"appear" ,{duration:1}); 
	//document.getElementById('photo_viewer').style.display == "block";
	}
	 viewer =  new Ajax.Updater(
         'photo_viewer_body',        // DIV id must be declared before the method was called
         'photo_viewer.php',        // URL
         {                // options
         method:'post' ,postBody:'imageID=' + imageID, onSuccess :function(){
		//new Effect.Highlight('cart', {startcolor:'#FFFFFF', endcolor:'#DFEBEE', duration:.3});
//alert(t.responseText);
			 
		 },
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
    }
             });
	return false;
	
}
function hide_viewer(){
	new Effect.BlindUp('photo_v' ,{duration:.3,queue:'end'});
	new Effect.BlindUp('viewer_bg' ,{duration:.3,queue:'end'});
}
function add_to_cart(imageID){
	photoName = $('image_name_' + imageID).name;
    $('shopping_cart_text').innerHTML = 'Adding ' + photoName + ' to cart';
   new Ajax.Request('cart_update.php', {method:'post', postBody:'imageID=photo_' + imageID,onSuccess: function(t) {
      //  alert(t.responseText);
		$('shopping_cart_text').innerHTML = '';
   		get_cart();
    },
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
}
					})
   return false;
}
function sizeClick(imageID){
	//alert($('sizes_' + imageID).value + " - " + imageID + " - " + $('num_' + imageID).value);
	if($(imageID + '_bw').checked == true){
		var bw = 1;
	}else{
		var bw = 0;	
	}
	add_size_to_order($('sizes_' + imageID).value, imageID,$('num_' + imageID).value,bw);
	
}
function add_size_to_order(sizeID,imageID,qty,bw){
	$('order_text_' + imageID).innerHTML = 'Updating';
   new Ajax.Request('cart_add_size.php', {method:'post', postBody:'imageID=' + imageID + '&sizeID=' + sizeID + '&qty=' + qty+ '&bw=' + bw,onSuccess: function(t) {
      // alert(t.responseText);
		$('order_text_' + imageID).innerHTML = '';
   		update_sizes(imageID);
    },
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
}
					})
   return false;
	
}
function update_sizes(imageID){
	
viewer =  new Ajax.Updater(
         'order_sizes_' + imageID,        // DIV id must be declared before the method was called
         'cart_sizes.php',        // URL
         {                // options
         method:'post' ,postBody:'imageID=' + imageID, onSuccess :function(){
		//new Effect.Highlight('cart', {startcolor:'#FFFFFF', endcolor:'#DFEBEE', duration:.3});
//alert(t.responseText);
			 new Effect.Highlight('order_sizes_' + imageID, {startcolor:'#b2bfbf', endcolor:'#FFFFFF', duration:.3,queue:'end'});
		update_total();
		 },
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
    }
             });	
}

function update_total(){
	
	total =  new Ajax.Updater(
         'order_total',        // DIV id must be declared before the method was called
         'cart_total.php',        // URL
         {                // options
         method:'get' , onSuccess :function(){
		//new Effect.Highlight('cart', {startcolor:'#FFFFFF', endcolor:'#DFEBEE', duration:.3});
//alert(t.responseText);
			 new Effect.Highlight('order_total', {startcolor:'#b2bfbf', endcolor:'#FFFFFF', duration:.3,queue:'end'});
	
		 },
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
    }
             });	
	
}
function cartClick(imageID, linkVar){
	//alert($('sizes_' + imageID).value + " - " + imageID + " - " + $('num_' + imageID).value);
	if($(linkVar + '_bw').value == 0){
		var bw = 0;
	}else{
		if($(linkVar + '_bw').checked == true){
			var bw = 1;
		}else{
			var bw = 0;
		}
	}
	add_size_to_cart($(linkVar + '_size_select').value, imageID,$(linkVar + '_num_select').value,bw);
	
}
function add_size_to_cart(sizeID,imageID,qty,bw){
	//$('order_text_' + imageID).innerHTML = 'Updating';
	photoName = $('image_name_' + imageID).name;
    $('shopping_cart_text').innerHTML = 'Adding ' + photoName + ' to cart';
   new Ajax.Request('cart_add_size.php', {method:'post', postBody:'imageID=' + imageID + '&sizeID=' + sizeID + '&qty=' + qty + '&bw=' + bw,onSuccess: function(t) {
        //alert(t.responseText);
		 $('shopping_cart_text').innerHTML = '';
   		get_cart();
    },
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
}
					})
   return false;
	
}
function paymentMethod(){
	paymentVal = $('payment').value;
	if(paymentVal == 4 || paymentVal == 5 || paymentVal == 6){
		$('credit').style.display = 'block';	
	}else{
		$('credit').style.display = 'none';
	}
}

function popitup(url,width,height) {
	newwindow=window.open(url,'name','height='+height+',width='+width+',resizable=1,scrollbars=1');
	if (window.focus) {newwindow.focus()}
	return false;
}
function helpPopUp(categoryID){
	popitup('ordering_help.php?categoryID='+categoryID,800,600);
	return false;
}
function sendFriendEmail(gallery){
	var yourName = $('emailFriendYourName').value;
	if(yourName == ""){
		alert("Please enter your name, so your friend knows who is emailing them!");
		$('emailFriendYourName').focus();
		return false;
	}
	var friendEmail = $('emailFriendFriendEmail').value;
	if(friendEmail == ""){
		alert("Please enter your friends email address!");
		$('emailFriendFriendEmail').focus();
		return false;
	}
	$('sendSlideshowToFriendMessage').innerHTML = "Sending Email...";
	 new Ajax.Request('ajax.emailFriend.php', {method:'post', postBody:'yourName=' + yourName + '&gallery=' + gallery + '&friendEmail=' + friendEmail,onSuccess: function(t) {
        //alert(t.responseText);
		 $('sendSlideshowToFriendMessage').innerHTML = 'Email Sent!';
   		 new Effect.Highlight('sendSlideshowToFriendMessage', {startcolor:'#b2bfbf', endcolor:'#FFFFFF', duration:.3,queue:'end'});
    },
    onFailure: function(t) {
        alert('Error ' + t.status + ' -- ' + t.statusText);
	}
					})

}
