// Funny Side Jquery Ajax and Live Twitter Feed

izIE6=(navigator.appVersion.indexOf('MSIE 6.')==-1)?false:true;

/*function(){$("#"+this.id.substring(4)).css({'display':'block','position':'absolute','top':parseInt($("#"+this.id).offset().top)+"px",'left':parseInt($("#"+this.id).offset().left)+"px"});},*/ 

function addHovers(){
//This is here so it can be called after sendGoogleRequest and senIndexRequest
//Its also called from funny.js for initial load of page

  $(".left3miniimage").hover(
    function(){$("#"+this.id.substring(4)).css({'display':'block'});}, 
    function(){$("#"+this.id.substring(4)).css({'display':'none'});} 
  );
  $(".left2miniimage").hover(
    function(){$("#"+this.id.substring(4)).css({'display':'block'});}, 
    function(){$("#"+this.id.substring(4)).css({'display':'none'});} 
  );
  $(".leftminiimage").hover(
    function(){$("#"+this.id.substring(4)).css({'display':'block'});}, 
    function(){$("#"+this.id.substring(4)).css({'display':'none'});} 
  );
  $(".act4span").hover(
    function(){$("#"+this.id.substring(5)).css({'display':'block'});}, 
    function(){$("#"+this.id.substring(5)).css({'display':'none'});} 
  );
  $(".act3span").hover(
    function(){$("#"+this.id.substring(5)).css({'display':'block'});}, 
    function(){$("#"+this.id.substring(5)).css({'display':'none'});} 
  );
  $(".act2span").hover(
    function(){$("#"+this.id.substring(5)).css({'display':'block'});}, 
    function(){$("#"+this.id.substring(5)).css({'display':'none'});} 
  );
  $(".act1span").hover(
    function(){$("#"+this.id.substring(5)).css({'display':'block'});}, 
    function(){$("#"+this.id.substring(5)).css({'display':'none'});} 
  );
  $(".comperespan").hover(
    function(){$("#"+this.id.substring(5)).css({'display':'block'});}, 
    function(){$("#"+this.id.substring(5)).css({'display':'none'});} 
  );

};

function sendCalendarRequest(venue,day,month,year,user,path){
  var path = (path == null) ? '' : path;
  var sReturn = "FALSE"; 

 $.ajax({
   type:"POST",
   url:path+'zzcreatecalendar09.php',
   data:'venue='+venue+'&day='+day+'&month='+month+'&year='+year+'&user='+user+'&path='+path,
   success:function(html){
	 if(path=='../'){
       $("div#divcalendarall").html(html);
	 } else {
       $("div#divcalendar").html(html);
	 }
   },
   error:function (XMLHttpRequest,textStatus,errorThrown){
	 if(path=='../'){
       $("div#divcalendarall").html("<p>Sorry but we cannot display this information at the current time.</p>");
	 } else {
       $("div#divcalendar").html("<p>Sorry but we cannot display this information at the current time.</p>");
	 }
   }
 });

 return sReturn;

}

function sendGoogleRequest(venue,targetRef,day,month,year,user,path) {
  var path = (path == null) ? '' : path;
  var sReturn = "FALSE"; 

  if(day>0){
    datar='venue='+venue+'&gigref='+targetRef+'&day='+day+'&month='+month+'&year='+year+'&user='+user+'&path='+path;
  } else {
    datar='venue='+venue+'&gigref='+targetRef+'&path='+path;
  }

 $.ajax({
   type:"POST",
   url:path+'zzcreategoogle09.php',
   data:datar,
   success:function(html){
     $("div#googlediv").html(html);
	 addHovers();
   },
   error:function (XMLHttpRequest,textStatus,errorThrown){
     $("div#googlediv").html("<p>Sorry but we cannot display this information at the current time.</p>");
   }
 });

 return sReturn;

}

function sendIndexRequest(venue,targetDiv,path) {
  var path = (path == null) ? '' : path;

 $.ajax({
   type:"POST",
   url:path+'zzindexgigs09.php',
   data:"venue="+venue+"&path="+path,
   success:function(html){
    if(html.length<100){//100 is a token NOT EMPTY figure
	  $("div#"+targetDiv).css({'display':'none'});
	  //$("p#"+targetDiv+"p").css({'display':'none'});
	} else {
	  //alert(html);
	  $("div#"+targetDiv).html(html);
	  //addHovers();
    }
   },
   error:function(XMLHttpRequest,textStatus,errorThrown){
     $("div#"+targetDiv).html("<p>Sorry but we cannot display this information at the current time.</p>");
   }
 });

}

function sendIndexAllRequest(targetDiv,path) {
  var path = (path == null) ? '' : path;

 $.ajax({
   type:"POST",
   url:path+'zzindexgigsall09.php',
   data:"path="+path,
   success:function(html){
    if(html.length<100){//100 is a token NOT EMPTY figure
	  $("div#"+targetDiv).css({'display':'none'});
	  //$("p#"+targetDiv+"p").css({'display':'none'});
	} else {
	  $("div#"+targetDiv).html(html);
	  //addHovers();
    }
   },
   error:function(XMLHttpRequest,textStatus,errorThrown){
     $("div#"+targetDiv).html("<p>Sorry but we cannot display this information at the current time.</p>");
   }
 });

}

function sendListAppearancesRequest(venue,targetDiv,aktref) {

  $("div#"+targetDiv).html("<br /><span>Getting Data...</span>");

  $.ajax({
    type:"POST",
    url:'listappearancesinner.php',
    data:'venue='+venue+'&aktref='+aktref,
    success:function(html){
      $("div#"+targetDiv).html(html);
    },
    error:function(XMLHttpRequest,textStatus,errorThrown){
      $("div#"+targetDiv).html("<p>Sorry but we cannot display this information at the current time.</p>");
    }
  });

}

function sendAppearancesRequest(obj) {
  var postdata='';
  postdata+="venue="+jQuery.trim($("#venue").val());
  postdata+="&order="+jQuery.trim($("#order").val());
  //alert(postdata);
  sendAppearancesRequestInner(postdata);					
}

//function sendAppearancesRequestInner(targetDiv,venue,order) {
function sendAppearancesRequestInner(postdata) {

  $("#divappearances").html("<br /><p class=\"maintextgreyvp\">Getting Data...</p>");

  $.ajax({
    type:"POST",
    url:'appearancesinner.php',
    data:postdata,
    //data:'venue='+venue+'&order='+order,
    success:function(html){
      $("#divappearances").html(html);
    },
    error:function(XMLHttpRequest,textStatus,errorThrown){
      $("#divappearances").html("<p>Sorry but we cannot display this information at the current time.</p>");
    }
  });

}

/*
First Name
Last Name
Email Address
Date of birth (Day Drop Down, Month Drop Down, Year Drop Down)
Address line 1
Address line 2
City 
County
Postcode
Country
Weekly mailing list opt-out (checkbox)
Favourite Comedian(s) (text area)

*/

function sendMembershipForm(obj) {
  var postdata='';
  postdata+="firstname="+jQuery.trim($("#firstname").val());
  postdata+="&lastname="+jQuery.trim($("#lastname").val());
  postdata+="&email="+jQuery.trim($("#email").val());
  postdata+="&address1="+jQuery.trim($("#address1").val());
  postdata+="&address2="+jQuery.trim($("#address2").val());
  postdata+="&city="+jQuery.trim($("#city").val());
  postdata+="&county="+jQuery.trim($("#county").val());
  postdata+="&postcode="+jQuery.trim($("#postcode").val());
  postdata+="&country="+jQuery.trim($("#country").val());
  postdata+="&optout="+$("#optout").attr('checked'); 
  postdata+="&message="+jQuery.trim($("#message").val());
  postdata+="&day="+jQuery.trim($("#day").val());
  postdata+="&month="+jQuery.trim($("#month").val());
  postdata+="&year="+jQuery.trim($("#year").val());
  //alert(postdata);
  postMembershipForm(postdata);					
}


function postMembershipForm(postdata) {

 $('#button').hide();$("#submitcomment").html('Sending Data....');

 $.ajax({
   type:"POST",
   url:'zzmembership.php',
   data:postdata,
   /*
   complete:function(res,status){
	//if(status=="success")alert(typeof res.responseText);
	if(status=="success")alert(res.responseText.length);
   },*/  
   success:function(msg){
     //Had to fudge the test using lengths because i was having trouble with types or jquery is returning crap !!!
     if(msg.length==4){
	   //alert('success');
	   $("#membershipdiv").html('<p class="maintextgreyvp"><span class="redsubheadings">Success!</span><br />Thank you for joining The Funny Side Membership Club.</p>');
	 } else if(msg.length==5){
	   //Server had trouble sending email to contact. so get them to try again ????
	   //alert('error');	 
	 } else {
	   temp=msg.split(' ');
	   temp2=temp[1];
       //alert(temp[1]);
       c=temp2.length;
       for (i=0;i<c;i++){ 
         switch(temp2.charAt(i)) {
         case 'f': $("#firstnamecomment").html('Invalid First Name'); break;
         case 'l': $("#lastnamecomment").html('Invalid Last Name'); break;
         case 'e': $("#emailcomment").html('Invalid Email Address'); break;
         case 'a': $("#address1comment").html('Invalid Address'); break;
         case 'c': $("#citycomment").html('Invalid City'); break;
         case 'p': $("#postcodecomment").html('Invalid Post Code'); break;
         case 'y': $("#countrycomment").html('Invalid Country'); break;
         case 'd': $("#datecomment").html('Invalid Date'); break;
		 }
       } 
       $('#button').show();$("#submitcomment").html('');
	 }
   },
   error:function(XMLHttpRequest,textStatus,errorThrown){
     //alert('error');	 
   }
 });

}

/*
$(document).ready(function() {//can have multiple document ready functions

  //addHovers();

  $("#twitterdiv").getTwitter({
		userName:"thefunnyside",
		numTweets:1,
		loaderText:"Loading tweets...",
		slideIn:false,
		//slideDuration: 750,
		showHeading:true,
		headingText:"Latest Tweet:",
		showProfileLink:true,
		showTimestamp:true
   });
  
});
*/