var status;
status = 0;

function logout()
 {
   $('#notification').load('library/functions.php?t=logout','',function()
    {
      $('#frame').load('library/functions.php?t=welcome');
    });
 }

function centrenotification()
 {
   var winH = $(window).height();
   var winW = $(window).width();

   winH = winH-50;

   var centerDiv = $('#notification');
   centerDiv.css('top', winH/2-centerDiv.height()/2);
   centerDiv.css('left', winW/2-centerDiv.width()/2); 
   $("#notificationbg").css({"opacity": "0.7"});  
 }

function closenotification()
 {
  $("#notificationbg").fadeOut("slow");
  $("#notification").fadeOut("slow");
 }

function askforpw(id)
 {
   centrenotification();
   $('#notification').load('library/functions.php?t=askforpw&id=' + id,'',function()
    {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");  
    });
 } 

function checkpw(id)
 {
   var pw;
   pw = $("input#pw").val();
   centrenotification();
   $('#notification').load('library/functions.php?t=checkpw&id=' + id + '&pw=' + pw,'',function()
    {
     if (status == 0)
      {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");  
      }
    });
 }

function loadimages(id)
 {
   centrenotification();
  $('#notification').html('<p>Please be patient whilst your gallery is loading</p>');
  $("#notification").css({"background-image": "url(library/loading.gif)","background-repeat":"no-repeat","background-position":"center"});  
  $('#notification').load('library/functions.php?t=loadimages','',function()
   {
     $("#notification").css({"background-image": "none"});  
     //closenotification();
     $('#frame').load('library/functions.php?t=welcome','',function()
      {
        $('#notification').load('library/functions.php?t=welcomenote&id=' + id);
      });


   });
 }

function view(id,tag)
 {
   $('#p').hide();
     $('#p').load('library/functions.php?t=img&i=' + id +'&pag=' + tag,'',function()
      {
       $('#p').fadeIn('slow');
      });
     pagination(tag,id);
 };

function pagination(pag,id)
 {
	 $('#thumb').load('library/functions.php?t=paginate&p=' + pag + '&id=' + id,'',function()
      {
        $('#pag' + pag).css({'color':'#99CC66'});
      });
 };

function add(id)
 {
	    $('#add').load('library/functions.php?t=add&i=' + id,'',function()
         {
    	    $('#tick').load('library/functions.php?t=addtick');
            $('#ttick' + id).css({'background-color' : '#6f8694'});
            $('#tthumb' + id).css({'-moz-opacity':'0.5', 'filter':'alpha(opacity=50)','opacity':'0.5','-khtml-opacity':'.5'});
         });
 };
 
function rem(id)
 {
	    $('#add').load('library/functions.php?t=rem&i=' + id,'',function()
         {
	       $('#tick').load('library/functions.php?t=remtick');
           $('#ttick' + id).css({'background-color' : '#333333'});
           $('#tthumb' + id).css({'-moz-opacity':'', 'filter':'','opacity':'','-khtml-opacity':''});
         }); 
};

function basketwelcome()
 {
   centrenotification();
   $('#notification').load('library/functions.php?t=basketwelcome','',function()
    {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");  
    });
 }

function viewbasket()
 {
	 $('#frame').load('library/functions.php?t=basket');
 };
 

function centrebasketimagepreview()
 {
   var winH = $(window).height();
   var winW = $(window).width();

   winH = winH-50;

   var centerDiv = $('#basketimagepreview');
   centerDiv.css('top', winH/2-centerDiv.height()/2);
   centerDiv.css('left', winW/2-centerDiv.width()/2);
   $("#notificationbg").css({"opacity": "0.7"});
 }

function closebasketimagepreview()
 {
  $("#notificationbg").fadeOut("slow");
  $("#basketimagepreview").fadeOut("slow");
}

function basketimagepreview(i,w,he)
 {
   he = he + 20;
   $('#basketimagepreview').width(w);
   $('#basketimagepreview').height(he);
	 //$('#frame').load('library/functions.php?t=basketimagepreview&i=' + i);
   centrebasketimagepreview();
   $('#basketimagepreview').load('library/functions.php?t=basketimagepreview&i=' + i,'',function()
    {
       $("#notificationbg").fadeIn("slow");
       $('#basketimagepreview').fadeIn("slow");
    });
 }

function hidebasket(id,pag)
 {
   $("#notificationbg").hide();
   $("#notification").hide();  
   $('#frame').load('library/functions.php?t=welcome&i=' + id + '&p=' + pag + '&id=' + id);
 };
 
function removeitem(id)
 {
	 $('#frame').load('library/functions.php?t=remitem&i='+id,'',function()
      {
	    $('#frame').load('library/functions.php?t=basket');
      }); 
 };


 function addproduct(id)
  {
    $('#frame').load('library/functions.php?t=addproduct&i=' + id);
  };


function saveproduct(option, img_id, product, size, colour, quant)
 {

   switch (option)
    {
     case 'type':
       $('#optssize').hide();
       $('#optscolour').hide();
       $('#optsquant').hide();
       $('.productoption').css({'-moz-opacity':'0.4', 'filter':'alpha(opacity=40)','opacity':'0.4','-khtml-opacity':'.4'});
       $('#productoption' + product).css({'-moz-opacity':'1', 'filter':'alpha(opacity=100)','opacity':'1','-khtml-opacity':'1'});
       $('#optssize').load('library/functions.php?t=saveproduct&option=type&i=' + img_id + '&product=' + product).fadeIn("slow");
     break;

     case 'size':
       $('.size').css({'color':'#7392a5'});
       $('#size' + size).css({'color':'#99CC66'});
       $('#optscolour').load('library/functions.php?t=saveproduct&option=size&i=' + img_id + '&size=' + size + '&product=' + product).fadeIn("slow");
     break;

    case 'colour':
       $('.colour').css({'color':'#7392a5'});
       $('#colour' + colour).css({'color':'#99CC66'});
       $('#optsquant').load('library/functions.php?t=saveproduct&option=colour&i=' + img_id + '&size=' + size + '&product=' + product + '&colour=' + colour).fadeIn("slow");
    break;

    case 'quantity':
       $('#frame').load('library/functions.php?t=saveproduct&option=quant&i=' + img_id + '&size=' + size + '&product=' + product + '&quantity=' + quant + '&colour=' + colour,'',function()
        {
          $('#frame').load('library/functions.php?t=basket');
        });
    break;
   }

 }

 function showproductproperties(i,j,k)
  {
   centrenotification();
   $('#notification').load('library/functions.php?t=showproductproperties&i=' + i + '&j=' + j + '&k=' + k,'',function()
    {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");  
    });
  }


/*


 function saveproducttype(id,product)
  {
    $('#optssize').hide();
    $('#optsquant').hide();
    $('.productoption').css({'-moz-opacity':'0.4', 'filter':'alpha(opacity=40)','opacity':'0.4','-khtml-opacity':'.4'});
    $('#productoption' + product).css({'-moz-opacity':'1', 'filter':'alpha(opacity=100)','opacity':'1','-khtml-opacity':'1'});
    $('#optssize').load('library/functions.php?t=saveproducttype&i=' + id + '&product=' + product).fadeIn("slow");
  };

 function saveproductsize(id,size,product)
  {
   $('.size').css({'color':'#7392a5'});
   $('#size' + size).css({'color':'#99CC66'});
   $('#optsquant').load('library/functions.php?t=saveproductsize&i=' + id + '&size=' + size + '&product=' + product).fadeIn("slow");
  };

function saveproductquantity(id,size,product,quant)
 {
   $('#frame').load('library/functions.php?t=saveproductquant&i=' + id + '&size=' + size + '&product=' + product + '&quantity=' + quant,'',function()
    {
      $('#frame').load('library/functions.php?t=basket');
    });
 };
*/
function showproductinfo(id,img)
 {
   status = 1;
   $('#photo').load('library/functions.php?t=showproductinfo&i=' + id + '&img=' + img);
 }

function closeproductinfo(img)
 {
   if (status == 1)
    {
     $('#photo').load('library/functions.php?t=closeproductinfo&img=' + img + '&i=' + img);
     status = 0;
    }
 }

function closeopt()
  {
	$('#frame').load('library/functions.php?t=basket');
  };

function removeprint(product,image,key)
 {
   $('#frame').load('library/functions.php?t=removeprint&key=' + key + '&image=' + image + '&product=' + product,'',function()
    {
      $('#frame').load('library/functions.php?t=basket');
    });
 };
 
 function voucher()
  {
	  var val;
	  val = $("input#vou").val();
	  if (val.length > 5)
	   {
	    $('#v').load('library/functions.php?t=voucher&val=' + val,'',function()
         {
//     		var tot;
//	    	tot = $("input#tot").val();
//		    $('#total').load('library/functions.php?t=recalc&tot=' + tot);
            $('#frame').load('library/functions.php?t=basket');
         });
	   }
  };

function wrongvoucher()
 {
   centrenotification();
   $('#notification').load('library/functions.php?t=wrongvoucher','',function()
    {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");  
    });
 }

function clearvoucher()
 {
   $('#v').load('library/functions.php?t=clearvoucher','',function()
    {
      $('#frame').load('library/functions.php?t=basket');
    });
 };
 
 function delivery(id,add,minus)
  {
    var tot;
	tot = $("input#tot").val();
    $('#deliver').load('library/functions.php?t=deliver&tot=' + tot + '&add=' + add + '&minus=' + minus + '&id=' + id,'',function()
     {
       $('#total').load('library/functions.php?t=deliver_calc&tot=' + tot + '&add=' + add + '&minus=' + minus + '&id=' + id);
     });
  };

function agreetoterms()
 {
   $("#notificationbg").fadeOut("slow");
   $("#notification").fadeOut("slow");

   $('#terms').load('library/functions.php?t=agreetoterms');
 }
function showterms()
 {
   $('#frame').load('library/functions.php?t=showterms');
 }
function ppal()
 {
   centrenotification();
   $('#notification').load('library/functions.php?t=paypal','',function()
     {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");  
     });
 }
function checkppal()
 {
   var forename;
   var surname;
   var email;
   forename = $("#first_name").val();
   surname = $("#last_name").val();
   email = $("#email").val();

   if (forename == 'forename') {forename = '';}
   if (surname == 'surname') {surname = '';}
   if (email == 'email address') {email = '';}

     $('p#chckppl').load('library/functions.php?t=checkppal&email=' + email + '&forename=' + forename + '&surname=' + surname);
 }

function sendppal()
 {
     $('#notification').html('<p>Please be patient whilst we send your information to paypal</p>');
     $("#notification").css({"background-image": "url(library/loading.gif)","background-repeat":"no-repeat","background-position":"center"});
     
 }

function ppna()
 {
   centrenotification();
   $('#notification').load('library/functions.php?t=ppna','',function()
    {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");  
    });
 }

function closeppn()
 {
  $("#notificationbg").fadeOut("slow");
  $("#notification").fadeOut("slow",function()
   {
     window.location = "http://www.evagoras.co.uk/gallery2/"
   }); 
 }


function productwarning()
 {
   centrenotification();
   $('#notification').load('library/functions.php?t=productwarning','',function()
    {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");  
    });
 }
function closeproductwarning()
 {
   $('input#notif').attr('checked', false);
   $("#notificationbg").fadeOut("slow");
   $("#notification").fadeOut("slow");
 }
function getdetails()
 {
   $('#frame').load('library/functions.php?t=getdetails');
 }

function checkcheque()
 {
   var forename;
   var surname;
   var email;
   var landline;
   var mobile;
   var address;
   var city;
   var postcode;
   var country;
   var instructions;
   forename = $("input#forename").val();
   surname = $("input#surname").val();
   email = $("input#email").val();
   landline = $("input#landline").val();
   mobile = $("input#mobile").val();
   address = $("input#address").val();
   city = $("input#city").val();
   postcode = $("input#postcode").val();
   country = $("input#country").val();
   instructions = $("textarea#instructions").val();

   centrenotification();
   $('#notification').load('library/functions.php?t=checkcheque&forename='+ escape(forename) +'&surname='+ escape(surname) +'&email='+ escape(email) +'&landline='+ escape(landline) +'&mobile='+ escape(mobile) +'&address='+ escape(address) +'&postcode='+ escape(postcode),'',function()
    {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");  
    });
 }

function cheque()
 {
   $("#notificationbg").fadeOut("slow");
   $("#notification").fadeOut("slow");

   var forename;
   var surname;
   var email;
   var landline;
   var mobile;
   var address;
   var city;
   var postcode;
   var country;
   var instructions;
   forename = $("input#forename").val();
   surname = $("input#surname").val();
   email = $("input#email").val();
   landline = $("input#landline").val();
   mobile = $("input#mobile").val();
   address = $("input#address").val();
   city = $("input#city").val();
   postcode = $("input#postcode").val();
   country = $("input#country").val();
   instructions = $("textarea#instructions").val();
   $('#frame').load('library/functions.php?t=cheque&forename='+ escape(forename) +'&surname='+ escape(surname) +'&email='+ escape(email) +'&landline='+ escape(landline) +'&mobile='+ escape(mobile) +'&address='+ escape(address) +'&city='+ escape(city) +'&postcode='+ escape(postcode) +'&country='+ escape(country) +'&instructions='+ escape(instructions),'',function()
     {
       $('#frame').load('library/functions.php?t=basket');
     });
 }

function clearemailbasket()
 {
  $("#emailbasket").val('');
  $("#emailbasket").css({'color':'#333333'});
 }
function emailbasket()
 {
  var email;
  email = $("#emailbasket").val();
  $('#frame').load('library/functions.php?t=emailbasket&email='+ escape(email),'',function()
     {
       $('#frame').load('library/functions.php?t=basket');
     });
 }

function saveBasketInfo()
 {
   centrenotification();
   $('#notification').load('library/functions.php?t=saveBasket_requestInfo','',function()
    {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");  
    });
 }

function saveBasket()
 {
   var email;
   email = $("#email").val();

   //check for duff data
   if (email.length < 6)
    {
      $("#checkBasket").html('Please check your email address, it does not seem to be valid.');
    }
   else
    {
      $('#notification').load('library/functions.php?t=saveBasket&email=' + email,'',function()
       {
        $("#notificationbg").fadeIn("slow");
        $("#notification").fadeIn("slow");  
       });

    }

 }

function saveBasketDB()
 {
   var email;
   email = $("#email").val();

   //check for duff data
   if (email.length < 6)
    {
      $("#checkBasket").html('Please check your email address, it does not seem to be valid.');
    }
   else
    {
      $('#checkBasket').load('library/functions.php?t=saveBasketDB&email=' + email);
    }

 }

function restoreInfo(id)
 {
   centrenotification();
   $('#notification').load('library/functions.php?t=restoreInfo&id=' + id,'',function()
    {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");  
    });
 }

function restoreBasket(id)
  {
   var email;
   email = $("#email").val();
   var code;
   code = $("#code").val();
   $('#notification').load('library/functions.php?t=restoreBasket&email=' + email + '&code=' + code + '&id=' + id,'',function()
    {
       $("#notificationbg").fadeIn("slow");
       $("#notification").fadeIn("slow");
    });
}

function notifyname()
 {
  $("#name").css({'color':'#333333'});
 }
function notifyemail()
 {
  $("#email").css({'color':'#333333'});
 }
function notifyme(id)
 {
  var email;
  var name;

  email = $("#email").val();
  name = escape($("#name").val());

  $('#notification').load('library/functions.php?t=notifyme&name=' + name + '&email=' + email + '&id=' + id);
 }

function clr(id)
 {
  $("#" + id).val('');
  $("#" + id).css({'color':'#333333'});
 }

function remText(id,v)
 {
   var newVal;

      newVal = $("#" + id).val();
      switch(newVal)
       {
         case '':
         $("#" + id).val(v);
         break;
         case v:
         $("#" + id).val('');
         break;
       }
  
 }