      $(function() {
      
    $('.user').tipsy({fade: true});
    
  });
  
  $(function(){
  $('#slides').bxSlider({
  
    pager: true,
    auto: true,
    autoHover: true
  });
})

$(document).ready(function(){	
		$(".follow-person").easyTooltip({
			useElement: "follow-tip",
                        xOffset:-20,
                        yOffset:-20
						   
		});
	});
	
	$(document).ready(function(){	
		$(".unfollow").easyTooltip({
			useElement: "follow-tip",
                        xOffset:-20,
                        yOffset:-20
							   
		});
	});

		$(document).ready(function(){
			
			//set the starting bigestHeight variable
			var biggestHeight = 0;
			//check each of them
			$('.equal_height').each(function(){
				//if the height of the current element is
				//bigger then the current biggestHeight value
				if($(this).height() > biggestHeight){
					//update the biggestHeight with the
					//height of the current elements
					biggestHeight = $(this).height();
				}
			});
			//when checking for biggestHeight is done set that
			//height to all the elements
			$('.equal_height').height(biggestHeight);
			
		});

		$(document).ready(function(){
			
			//set the starting bigestHeight variable
			var biggestHeight = 0;
			//check each of them
			$('.equal_location').each(function(){
				//if the height of the current element is
				//bigger then the current biggestHeight value
				if($(this).height() > biggestHeight){
					//update the biggestHeight with the
					//height of the current elements
					biggestHeight = $(this).height();
				}
			});
			//when checking for biggestHeight is done set that
			//height to all the element
                        $('.equal_location').height(biggestHeight);
			
		});

$(document).ready(function() {


	
	$("a#single_image").fancybox();
	

	$("a#inline").fancybox({
		'hideOnContentClick': false
	});


	
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
	
});
function invite()
	{
		 $('#dialog-close').click();
		 $('.invite-a').click();
	}

 
 
function validateSearchFrm(frm){
  var str=frm.search.value;
  if(str.length < 3){
      alert("Please enter atleast 3 letters to search.");
      return false;
  }
  if(str=='' || str.match(/^\s*$/)  || str=='Search Events & Profiles'){
      alert("Please enter search criteria to search.");
      return false;
  }

}


jQuery(document).ready(function() {
    // Initialise the first and second carousel by class selector.
	// Note that they use both the same configuration options (none in this case).
	jQuery('.jcarousel-skin-boston').jcarousel();
	jQuery('.jcarousel-skin-ie7').jcarousel();
	jQuery('.jcarousel-skin-table').jcarousel();
	jQuery('.jcarousel-skin-event').jcarousel();
	jQuery('.jcarousel-skin-trending').jcarousel();
        jQuery('.jcarousel-skin-bostonfollow').jcarousel();
	jQuery('.first-and-second-carousel').jcarousel();
        jQuery('.carousel_trend').jcarousel();
        jQuery('.jcarousel-skin-bostonsearch').jcarousel();
        jQuery('.jcarousel-skin-bostonfollower').jcarousel();
		  jQuery('.jcarousel-skin-calendar').jcarousel();
        
	jQuery('.block').width(10000);
	
	// If you want to use a caoursel with different configuration options,
	// you have to initialise it seperately.
	// We do it by an id selector here.
	jQuery('#third-carousel').jcarousel({
        vertical: true
    });
	
});



function displayEvent(id)
{
  $('#tooltip').html('');
	 var eventid = id;
     $.ajax({
     type: "POST",
    url: "/ajax/getevent", 
    data: "id="+eventid,
    success: function(msg){
		  $('#tooltip').html('');
		  $('#tooltip').html(msg);
		  
     }
    });  
 

	// setup tooltip for a single DIV element
	$("#"+id).tooltip({

		// each trashcan image works as a trigger
		tip: '#tooltip',

		// custom positioning
		position: 'bottom left',

		// move tooltip a little bit to the right
		offset: [-100, 150],

		// there is no delay when the mouse is moved away from the trigger
		delay: 0
	});

}



function displayUser(id)
{


	// setup tooltip for a single DIV element
	$("#"+id).tooltip({

		// each trashcan image works as a trigger
		tip: '#tooltip',

		// custom positioning
		position: 'bottom left',

		// move tooltip a little bit to the right
		offset: [-75, 225],

		// there is no delay when the mouse is moved away from the trigger
		delay: 0
	});

}
function displayName(id)
{


	// setup tooltip for a single DIV element
	$("#"+id).tooltip({

		// each trashcan image works as a trigger
		tip: '#usertip',

		// custom positioning
		position: 'bottom left',

		// move tooltip a little bit to the right
		offset: [-5, 65],

		// there is no delay when the mouse is moved away from the trigger
		delay: 0
	});

}

function getpagination(page,catid,sortBy,order,sort)
	{ 
    
      $(".table").html("<div class='load'><img  src='/images/loading.gif' /></div>");
    // alert("hiii");
     var page= page;
     var catid= catid;
     var classstyle='';
     if(!catid)
         catid=1;
     if(sort!=''){
      if(order=='Desc'){
       order="Asc";
       classstyle="headerSortUp";
      }else if(order=='Asc'){
       order='Desc';
       classstyle="headerSortDown";
      }else{
       order="Asc";
       classstyle="headerSortUp";
      }
     }
   
       //alert("hii"+page); 
   $.ajax({
     type: "POST",
     url: "/ajax/getpaginationresults", 
     data: "page="+page+"&catid="+catid+"&noofrecords=4&sortBy="+sortBy+"&order="+order+"&classstyle="+classstyle+"&boston=yes",
    success: function(msg){
                $(".table").html(msg);
			
      }
    });  
    	 
  }
  
 function getattendies(eventid,operation,page){
   //alert(eventid+" "+operation+" "+page);
    var divid="#attendies"+eventid;
    $.ajax({
     type: "POST",
     url: "/ajax/whoiscoming", 
     data: "eventid="+eventid+"&operation="+operation+"&page="+page,
    success: function(msg){
           $(divid).html(msg);
			
      }
    });  
        
 
 }
 
 function getWhomToFollow(catid,operation,page,catname){
  // alert(catid+" "+operation+" "+page);
    var divid="#whomtofollow"+catid;
    $.ajax({
     type: "POST",
     url: "/ajax/whomtofollow", 
     data: "catid="+catid+"&operation="+operation+"&page="+page+"&catname="+catname,
    success: function(msg){
        //alert(msg);
           $(divid).html(msg);
			
      }
    });  
        
 
 }
  function scheditid(id)
	{
            
		 
 		$('#scheditid').val(id)
		 $('#facebook').attr('href','/facebook/index?event=getevent&event_id='+id);
		 $('#twitter').attr('href','/twitter/redirect.php?event=getevent&event_id='+id);

	}
	function scheditnullid()
	{
		
 		 $('#scheditid').val('')
		 $('#facebook').attr('href','/facebook/index');
		 $('#twitter').attr('href','/twitter/redirect.php');

	}
	function ajaxscheditid(schedid,userid)
	{ 
		    var schedid= schedid;
			var userid= userid;
 		    $.ajax({
                type: "POST",
                url: "/default/index",
                data: "schedid="+schedid+"&userid="+userid,
                 success: function(msg){
   }
  });
	}

function getFollwerId(fid)
{  
    var fid=fid;
    $('#follweruserid1').val(fid);
    $("#facebook").attr('href','/facebook/index?follweruserid='+fid);
    $("#twitter").attr('href','/twitter/redirect.php?follweruserid='+fid);

}


function showmoredesc(id){
     var eventid= id;	
      $.ajax({
                type: "POST",
                url: "/ajax/geteventdesc",
                data: "eventid="+eventid,
                 success: function(msg){  
                     $(".event_desc").html('');
                      $(".event_desc").html(msg);
                }
  });
    
    
   
}


 function daysInMonth(month,year) {
                      return new Date(year, month, 0).getDate();
                      }

function displayCalander(action,page)
{
var datetype=document.getElementById("datetype").value;
var datevalue=document.getElementById("datevalue").value;
var monthvalue=document.getElementById("monthvalue").value;
var yearvalue=document.getElementById("yearvalue").value;

var publicprofileid='';
if(document.getElementById('publicprofileid'))
publicprofileid=document.getElementById('publicprofileid').value;
loginuserid='';
if(document.getElementById('loginuserid'))
loginuserid=document.getElementById('loginuserid').value;
//alert(datetype+", "+datevalue+", "+monthvalue);
nextday(datetype,datevalue,monthvalue,yearvalue,action,publicprofileid,page,loginuserid);
}

function nextday(datetype,datevalue,monthvalue,yearvalue,action,publicprofileid,page,loginuserid)
{  

       	 var datetype = datetype.charAt(0).toUpperCase() + datetype.slice(1);
         var datevalue=datevalue;
		 var publicprofileid=publicprofileid;
	 var monthvalue =monthvalue;
         var yearvalue =yearvalue;
	  var action =action;
	  var daysinmonth;
         // alert("yearvalue: "+yearvalue+" monthval: "+monthvalue+"datevalue: "+datevalue);
 	   if(parseInt(monthvalue)==parseInt(12)  && action=='next' && datetype=="month"){
               monthval=parseInt(1);
               yearvalue=parseInt(yearvalue)+parseInt(1); 
              // alert("month value is 12 ------ yearvalue: "+yearvalue+" monthval: "+monthval);               
           }
           if(parseInt(monthvalue)==parseInt(1)  && action=='previous' && datetype=="month"){
               monthval=parseInt(12);
               yearvalue=parseInt(yearvalue)-parseInt(1);
               // alert("month value is 1 ------ yearvalue: "+yearvalue+" monthval: "+monthval);      
           }
           
	       
       daysinmonth = daysInMonth(monthvalue,yearvalue); //31
	     // if(parseInt(daysinmonth)<parseInt(datevalue) || parseInt(0)>parseInt(datevalue) )
	      // return false; 
               	      
   $('.boston_content').html("<img  src='/images/loading.gif' />");

     $.ajax({
    type: "POST",
    url: "index",
    data: "mode="+datetype+"&date="+datevalue+"&month="+monthvalue+"&action="+action+"&year="+yearvalue+"&publicprofileid="+publicprofileid+"&page="+page+"&loginuserid="+loginuserid,
    success: function(msg){
              	if(datetype=="Month")
		   {
                        //alert(msg);
			    if(monthvalue!=parseInt(12) && monthvalue!=parseInt(1)){
			    if(action=='next')
			      var monthval=parseInt(monthvalue)+parseInt(1);
                            else  if(action=='previous')
                              var monthval=parseInt(monthvalue)-parseInt(1);                         
                          }
                
                 $('#monthvalue').val(parseInt(monthval));
                 $('#yearvalue').val(parseInt(yearvalue));
                 
                 $('.boston_content').html(''); 
                 $('.boston_content').html(msg);
 	                    
 		}
  }
  }); 
  

}	

function fetchmoreevnts(start,div,tab){
  //alert(start);
  var divid=div+start;
  $("#"+divid).html("<div class='load'><img  src='/images/loading.gif' /></div>");
  $.ajax({
     type: "POST",
     url: "/ajax/fetcheventsformycal", 
     data: "start="+start+"&div="+div+"&tab="+tab,
    success: function(msg){
		//alert(msg);
		$('#'+divid).html(msg);
		
		
      }
    });  
}



function signup_validate()
	 {  
		var flag2=true;
		
		var username = $('#username').val();
		var email = $('#email').val();
  
                  if(!checkEmpty('username')){
                     
                     $('#err_username').text('Username should not be empty');
                     flag2=false;
                 }else{
                     $('#err_username').text('');
                 }
                  

		  if(!checkEmpty('email'))
		 {
			   $('#err_email').text('Email should not be empty');
			    flag2=false;
		 }else if(!checkEmailFormat('email'))
		 {
			  $('#err_email').text('Enter valid email');
			   flag2=false;
		 }else
		 {
			   $('#err_email').text('');
		 }
	
		   return flag2;
			   
	 }
       
function checkEmailFormat(textidval)
{
    var flag1=true;
    var emailPattern=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    var elementValue=$("#"+textidval).val();
    if(elementValue=='')
    {
         $('#'+textidval).css({"border":"1px dashed #FF99CC"});
         flag1=false;
    }
    if(!emailPattern.test(elementValue))
    {
        $('#'+textidval).css({"border":"1px dashed #FF99CC"});
        flag1=false;
    }
    else
    {
	   $('#'+textidval).css({"border":"1px solid #E5F0FB"});
	}
	 
    return flag1;
}

function checkEmpty(idval)
{
	var flag=true;
	var chkval=$("#"+idval).val();
	if(chkval=="")
	{      
		$('#'+idval).css({"border":"1px dashed #FF99CC"});
		flag=false;
	}
	else
	{
		$('#'+idval).css({"border":"1px solid #E5F0FB"});

	}
	return flag;
}

function followUnfollowinpublicprofile(id)
{
    var userid = id;
    var style = $('#follow_public').attr("class");
    
    if(style=='public_followon')
        style='public_followed';
    else
        style='public_followon';
      $.ajax({
     type: "POST",
    url: "/ajax/getfollowunfollwuser", 
    data: "id="+userid+"&ispublicprofile=yes",
    success: function(msg){
  	//$('#tooltip').html(msg); 
                //follow_public
                $('#follow_public').removeClass().addClass(style);
                alert(msg);
       }
    });
    
}

function getWhomToFollow(catid,operation,page,catname){
  // alert(catid+" "+operation+" "+page);
    var divid="#whomtofollow"+catid;
    $.ajax({
     type: "POST",
     url: "/ajax/whomtofollow", 
     data: "catid="+catid+"&operation="+operation+"&page="+page+"&catname="+catname,
    success: function(msg){
        //alert(msg);
           $(divid).html(msg);
			
      }
    });  
        
 
 }
 
function getUser(id)
{

   var userid = id;

      $.ajax({
     type: "POST",
    url: "/ajax/getuserinwhotofollow", 
    data: "id="+userid,
    success: function(msg){
       
  		 $('.username').html(msg); 
       }
    });
     		
}
function followUnfollow(id,liid)
{  
    var style = $('#'+liid).attr("class");
    
    if(style=='follow-person')
        style='unfollow';
    else
        style='follow-person';
    
    var userid = id;
      $.ajax({
     type: "POST",
    url: "/ajax/getfollowunfollwuser", 
    data: "id="+userid,
    success: function(msg){
  		following();
                $('#'+liid).removeClass().addClass(style);
				
       }
    });
    
}

function following(){
		$.ajax({
                 type: "POST",
                 url: "/ajax/following", 
                data: "followid=test",
                 success: function(msg){
                   
				   $('#ajaxfoolower').html('');
                    $('#ajaxfoolower').html(msg);
			         
			   
                   }
                });  
                            
                        
                    
                }
	

 function scheditTestEvent(localhost)
 {

		 var fbcheck = $('#facebookcheck:checked').val();
		  var etitle = $('#event_title').val();
		  var ecount = $('#event_count').val();
		 var f_appid = $('#f_appid').val();
		 var tcheck=$('#twittercheck:checked').val();

			  if(tcheck=='twitter')
				 {
					treturn=postTweet(etitle,ecount,localhost,fbcheck);
				
				 }
				  if(fbcheck=='facebook')
				 {
				   freturn= postToFeed(f_appid,localhost,etitle);                                   
				 }  
                                 if(tcheck!='twitter' && fbcheck!='facebook'){
                                     document.eventform.submit(); 
                                 }


 }
function postTweet(etitle,ecount,localhost,fbcheck)
{
    if(fbcheck=='tweet'){
	 var etitle = $('#event_title').val();
	 var ecount = $('#event_count').val();
    }
	var eventid=$('#event_id').val();	
	var shorturl=$('#shorturl').val();
	//var elink='http://'+localhost+'/event/getevent/index?id='+eventid;
	// var statusMessage = "I'm planning to attend : "+etitle+" with "+ecount+" others - Join Me! - "+shorturl ;
	var statusMessage =  "CHECK OUT this cool event at MY EVENTS on BostonDotCom ["+shorturl+"]! via @SCHEDITboston"
	//window.open ("http://twitter.com/home?status="+statusMessage,"schedittweet");
	window.open("http://twitter.com/home?status="+statusMessage, "schedittweet", "width=650, height=360,0,status=0,");
	
       if(fbcheck!='facebook' && fbcheck!='tweet')
          document.eventform.submit();
        return true;

}
function postToFeed(f_appid,localhost,etitle) {
					// FB.init({appId: f_appid, status: true, cookie: true});
                                       // alert('hi');                                      
			var eventid=$('#event_id').val();
			var eventdesc=$('#event_desc').val();
			var pic='http://'+localhost+'/images/schedit_logo.png';
			var elink='http://'+localhost+'/event/eventdetails?id='+eventid;
              var ecount = $('#event_count').val();
              var shorturl=$('#shorturl').val();
                        
               var etitle1="I'm planning to attend : "+etitle+" with "+ecount+" others - Join Me! -> " ;
					// calling the API ...
					
					var obj = {
					  method: 'feed',
					  link:elink,
					  picture: pic,
					  name: etitle,
					  caption: etitle1,
					  description: eventdesc
					};
                                        
					function callback(response) {
						if(response==null){                                               
						   document.eventform.submit();   
						}
					  document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
					  //alert(response);                                         
                       document.eventform.submit();  
					}                                       
					FB.ui(obj, callback);
                                        
                                        
                                        
		return true;
      }


function postTofacebook(localhost,eventid,etitle,eventdesc,eventpic,ecount,shorturl) {
					                                  
			//var eventid=$('#event_id').val();
			//var eventdesc=$('#event_desc').val();
			var pic='http://'+localhost+eventpic;
			var elink='http://'+localhost+'/event/eventdetails?id='+eventid;
             // var ecount = $('#event_count').val();
              //var shorturl=$('#shorturl').val();
                     title="Come follow my 'Hyper-Social' events calendar on Boston.com!";   
               var etitle1="I'm planning to attend : "+etitle+" with "+ecount+" others - Join Me! " ;
					// calling the API ...
					
					var obj = {
					  method: 'feed',
					  link:elink,
					  picture: pic,
					  name: title,
					  caption: etitle1,
					  description: eventdesc
					};
                                        
					function callback(response) {
						if(response==null){                                               
						   document.eventform.submit();   
						}
					  //document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
					  //alert(response);                                         
                      
					}                                       
					FB.ui(obj, callback);
                                        
                                        
                                        
		return true;
      }

	   function submitFrm(){
            var frm=document.welcomeFrm;
            frm.action="/signup/channel";
            frm.submit();
            
        }

function alphanumeric(alphane,spanele,availabilityele)
{ 
	 var numaric = alphane;
         if(numaric.length>0){
         
        var flag1=true;
        var a='';        
	for(var j=0; j<numaric.length; j++)
		{
		  var alphaa = numaric.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) ||  hh==8 || hh==32 ||  (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {
                      //$('#'+spanele).text('');
                      
                      
		  }
		else	{
                         //alert("Your Alpha Numeric Test Failed");
                         a='yes';
                         $('#'+availabilityele).text('');
                          $('#'+spanele).text('User name should not contain special characters');
                         flag1=false;
		  }
                  
                  if(a==''){
                      $('#'+spanele).text('');
                  }
                      
 		}
                return flag1;
         }
 
}

function checkEmailFormat(textidval,spanele)
{
    var flag1=true;
    var emailPattern=/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
    var elementValue=$("#"+textidval).val();
    if(elementValue=='')
    {
         $('#'+spanele).css({"border":"1px dashed #FF99CC"});
         $('#'+textidval).text('Enter valid email');
         flag1=false;
    }
    if(!emailPattern.test(elementValue))
    {
        $('#'+spanele).text('Enter valid email');
        $('#'+textidval).css({"border":"1px dashed #FF99CC"});
        flag1=false;
    }
    else
    {
        $('#'+spanele).text('');
	   $('#'+textidval).css({"border":"1px solid #E5F0FB"});
	}
	 
    return flag1;
}

function checkEmpty(idval)
{
	var flag=true;
	var chkval=$("#"+idval).val();
	if(chkval=="")
	{
		$('#'+idval).css({"border":"1px dashed #FF99CC"});
		flag=false;
	}
	else
	{
		$('#'+idval).css({"border":"1px solid #E5F0FB"});

	}
	return flag;
}
function checkuserprofilename(val,act_profilename){
         //alert(val);
         if(act_profilename != val && val.length > 0){
              if(!alphanumeric(val,'err_username','availability')){
                   return false;
              }else{
         
         $.ajax({
      type: "POST",
      url: "/ajax/profilenameavailability",
      data: "profilename="+val,
      success: function(msg){
          //alert(msg);
		  if(msg)
		  {
                        
                        $('#err_username').text('');
			$('#availability').removeClass().addClass('red');
                        $('#availability').text('Profile name already exists');
  			
		  }else{
                       $('#err_username').text('');
                      $('#availability').removeClass().addClass('green');
                        $('#availability').text('available');
                  }
		
           }
         });
 
         }
         }
         
     }
function checkusername(val,act_username){
         //alert(val);
    if(act_username != val  && val.length > 0){
          if(!alphanumeric(val,'err_name','available')){
                   return false;
              }else{
         $.ajax({
      type: "POST",
      url: "/ajax/usernameavailability",
      data: "username="+val,
      success: function(msg){
          //alert(msg);
		  if(msg)
		  {
                        $('#err_name').text('');
			$('#available').removeClass().addClass('red');
                        $('#available').text('User name already exists');
  			
		  }else{
                        $('#err_name').text('');
                        $('#available').removeClass().addClass('green');
                        $('#available').text('available');
                  }
		
           }
         });
         
              }
 
         }
         
     }
