 $(document).ready(function($) {
      $('a[rel*=facebox]').facebox({
        loading_image : 'loading.gif',
        close_image   : 'closelabel.gif'
      }); 
    });


var timer;  
var $gi; 
var sinceTweetId;
	
function changeClass(first,second)
    {
		if( $("a#"+first).is('.notchecked') ){
		$("a#"+first).addClass('checked');
		}
		if( $("a#"+second).is('.checked') ){
       $("a#"+second).removeClass('checked');
	   $("a#"+second).addClass('notchecked');
		}
    }		
	

function follow(id,add){
    // Don't worry with this var.
    var Request;
    var Name;
    var Opt;
    var Params;
   
    try{
        obj1 = new XMLHttpRequest();       
    } catch (e){
        try{
            obj1 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                obj1 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                alert("Your browser does not support AJAX.\nPlease update your browser or login with the main login.");
                return false;
            }
        }
    }
   if(add==1){
    var url = siteurl+"show.php?action=follow&id="+id+"&add=1";
   }
   if(add==0){
    var url = siteurl+"show.php?action=follow&id="+id+"&add=0";
   }
    obj1.open("POST", url, true);
    obj1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    obj1.setRequestHeader("Connection", "close");
    obj1.send(Params);
    obj1.onreadystatechange = function(){
            if(obj1.readyState == 4){
                //var str= new String(obj1.responseText);
                var str= trim(obj1.responseText);
					if(str==1 && add==1){
                    document.getElementById('follow_success').style.display='block';
					document.getElementById('follow_div').style.display='none';
					document.getElementById('unfollow_div').style.display='block';
                    }

                    if(str==1 && add==0){
                    document.getElementById('unfollow_success').style.display='block';
					document.getElementById('follow_div').style.display='block';
					document.getElementById('unfollow_div').style.display='none';
					document.getElementById('follow-details').style.display='none';
                    }
            }
    }
 }






function retweet(id){
    // Don't worry with this var.
    var Request;
    var Name;
    var Opt;

    var Params;
   
    try{
        obj1 = new XMLHttpRequest();       
    } catch (e){
        try{
            obj1 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                obj1 = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                alert("Your browser does not support AJAX.\nPlease update your browser or login with the main login.");
                return false;
            }
        }
    }
   
    var url = "show.php?action=retweet&id="+id;
       
    obj1.open("POST", url, true);
    obj1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    obj1.setRequestHeader("Connection", "close");
    obj1.send(Params);
    obj1.onreadystatechange = function(){
            if(obj1.readyState == 4){
                //var str= new String(obj1.responseText);
                var str= trim(obj1.responseText);
                    if(str.length>0){
                    document.getElementById('txt_tweet')=str;
                    }
            }
    }
 }

function openFavShows(hs){
if(hs==1){
document.getElementById('FavShowsDiv').style.display='block';
}else{
document.getElementById('FavShowsDiv').style.display='none';
}
}




function getEmoteChart(showid){
    // Don't worry with this var.
    var Request;
    var Name;
    var Params;
    
	

    try{
        obj2 = new XMLHttpRequest();       
    } catch (e){
        try{
            obj2 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                obj2 = new ActiveXObject("Microsoft.XMLHTTP");   
            } catch (e){
                alert("Your browser does not support AJAX.\nPlease update your browser or login with the main login.");
                return false;
            }
        }
    }

    // This is the php file with the script to update the Database.
   
        var url = siteurl+"show.php?action=showemotechart&id="+showid;
       

    obj2.open("POST", url, true);
    obj2.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    obj2.setRequestHeader("Connection", "close");
    obj2.send(Params);
    obj2.onreadystatechange = function(){
            if(obj2.readyState == 4){
               var str= trim(obj2.responseText);
            
                        
            }
    }
   
    
  }


function getTotChart(showid){
    // Don't worry with this var.
    var Request;
    var Name;
    var Params;
    
	

    try{
        obj3 = new XMLHttpRequest();       
    } catch (e){
        try{
            obj3= new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                obj3 = new ActiveXObject("Microsoft.XMLHTTP");   
            } catch (e){
                alert("Your browser does not support AJAX.\nPlease update your browser or login with the main login.");
                return false;
            }
        }
    }

    // This is the php file with the script to update the Database.
   
        var url = siteurl+"show.php?action=showtotchart&id="+showid;
       

    obj3.open("POST", url, true);
    obj3.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    obj3.setRequestHeader("Connection", "close");
    obj3.send(Params);
    obj3.onreadystatechange = function(){
            if(obj3.readyState == 4){
               var str= trim(obj3.responseText);
                 
                        
            }
    }
   
   
  }









function getSearch(id,module,emote){
    // Don't worry with this var.
    var Request;
    var Name;
    var Opt;
    var Params;
    var page;
    var results = "";
	

    try{
        obj1 = new XMLHttpRequest();       
    } catch (e){
        try{
            obj1 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                obj1 = new ActiveXObject("Microsoft.XMLHTTP");   
            } catch (e){
                alert("Your browser does not support AJAX.\nPlease update your browser or login with the main login.");
                return false;
            }
        }
    }

    // This is the php file with the script to update the Database.
    if(emote>0){
        if(module==0){
        var url = siteurl+"show.php?action=checknewtweet&mode=mem&id="+id+"&emote="+emote;
        }else{
        var url = siteurl+"show.php?action=checknewtweet&mode=all&id="+id;
        }
    }else{
        if(module==0){
        var url = siteurl+"show.php?action=checknewtweet&mode=mem&id="+id;
        }else{
        var url = siteurl+"show.php?action=checknewtweet&mode=all&id="+id;
        }
    }   

    obj1.open("POST", url, true);
    obj1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    obj1.setRequestHeader("Connection", "close");
    obj1.send(Params);
    obj1.onreadystatechange = function(){
            if(obj1.readyState == 4){
                var str= trim(obj1.responseText);

				var arrtotalstr=str.split('----');
	                if(arrtotalstr.length>1){
                    if(arrtotalstr[1].length>0){
						 $("ol#update").prepend((arrtotalstr[1]));
                         $("ol#update li:first").hide().slideDown("slow");
                         $("ol#update li:gt(29)").remove(); 
						
						
						 }
					if(document.getElementById('current_records').value==0){
					var total_record=arrtotalstr[0];
					document.getElementById('norecord').innerHTML='';
					document.getElementById('current_records').value=arrtotalstr[0];
					}else{
						total_record=document.getElementById('current_records').value;
						document.getElementById('current_records').value=parseInt(total_record) + parseInt(arrtotalstr[0]);
						var total_record = parseInt(total_record) + parseInt(arrtotalstr[0]);
					}
					
                }
				

               
            }
    }
   
    clearTimeout(timer);

    if(document.getElementById('pausevalue').value=='0'){
        if(module==0){
        timer = setTimeout("getSearch("+id+",0,"+emote+")", 20000);
        }else{
        timer = setTimeout("getSearch("+id+",1,0)", 300000);
        }
    }
 }
 
 
 
 
 
 function conversation(tweetid,divid,tdid,curtweet){
    // Don't worry with this var.
    var Request;
    var Name;
    var Opt;
    var Params;
    var page;
    var results = "";
	

    try{
        obj = new XMLHttpRequest();       
    } catch (e){
        try{
            obj = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                obj = new ActiveXObject("Microsoft.XMLHTTP");   
            } catch (e){
                alert("Your browser does not support AJAX.\nPlease update your browser or login with the main login.");
                return false;
            }
        }
    }

    // This is the php file with the script to update the Database.
   
        var url = siteurl+"show.php?action=showconversation&tweetid="+tweetid+"&curtw="+curtweet;
       

    obj.open("POST", url, true);
    obj.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    obj.setRequestHeader("Connection", "close");
    obj.send(Params);
    obj.onreadystatechange = function(){
            if(obj.readyState == 4){
                var str= trim(obj.responseText);
                var arrtotalstr=str.split('----');
				if(arrtotalstr.length>1){
                    if(arrtotalstr[1].length>0){
						
	               	$("div#"+divid).html(arrtotalstr[1]).slideDown("slow");
					 document.getElementById(tdid).innerHTML='<a href="javascript:void(0);" onclick="hide('+"'"+tweetid+"'"+','+"'"+divid+"'"+','+"'"+tdid+"'"+','+"'"+curtweet+"'"+');">Hide Conversation</a>';			
					                           }
			
										}
    								}
   
    
 }
  

 }




function getSearchLounge(id,module,emote){
    // Don't worry with this var.
    var Request;
    var Name;
    var Opt;
    var Params;
    var page;
    var results = "";
    try{
        obj1 = new XMLHttpRequest();       
    } catch (e){
        try{
            obj1 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                obj1 = new ActiveXObject("Microsoft.XMLHTTP");   
            } catch (e){
                alert("Your browser does not support AJAX.\nPlease update your browser or login with the main login.");
                return false;
            }
        }
    }
   
    // This is the php file with the script to update the Database.
    
        if(module==0){
        var url = siteurl+"show.php?action=checknewloungetweet&mode=loungemember";
        }else{
        var url = siteurl+"show.php?action=checknewloungetweet&mode=loungeall";
        }
    
    obj1.open("POST", url, true);
    obj1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    obj1.setRequestHeader("Connection", "close");
    obj1.send(Params);
    obj1.onreadystatechange = function(){
            if(obj1.readyState == 4){
                var str= trim(obj1.responseText);
                var arrtotalstr=str.split('----');

                if(arrtotalstr.length>1){
					
                    if(arrtotalstr[1].length>0){
                   $("ol#update").prepend((arrtotalstr[1]));
                   $("ol#update li:first").hide().slideDown("slow");
				     $("ol#update li:gt(29)").remove(); 
                    }
					if(document.getElementById('current_records').value==0){
					var total_record=arrtotalstr[0];
					document.getElementById('norecord').innerHTML='';
					document.getElementById('current_records').value=arrtotalstr[0];
					}else{
						total_record=document.getElementById('current_records').value;
						document.getElementById('current_records').value=parseInt(total_record) + parseInt(arrtotalstr[0]);
						var total_record = parseInt(total_record) + parseInt(arrtotalstr[0]);
					}
                }
           
              
            }
    }
   
    clearTimeout(timer);

    if(document.getElementById('pausevalue').value=='0'){
        if(module==0){
        timer = setTimeout("getSearchLounge(-1,0)", 20000);
        }else{
        timer = setTimeout("getSearchLounge(-1,1)", 300000);
        }
    }
 }

function trim(str)
{
    s = str.replace(/^(\s)*/, '');
    s = s.replace(/(\s)*$/, '');
    return s;
}

function appendEmote(emote){
    document.getElementById('txt_tweet').value=document.getElementById('txt_tweet').value+emote;
}



// customize by sachin
var http = createRequestObject();

function createRequestObject() 
{
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		ro = new XMLHttpRequest();
	}
	return ro;
}


function add_favorate_show(user_id,show_id)
{
	var url = siteurl+"show.php?action=add_favorate_shows&user_id="+user_id+"&show_id="+show_id;
	http.open('get', url);
    http.onreadystatechange = add_favorate_show_response;
    http.send(null);
	document.getElementById("link-show-"+show_id).innerHTML='<a class="redtext" href="javascript:void(0);" onclick="remove_favorate_show('+user_id+','+show_id+');">REMOVE FROM FAVORITES</a>';	
	
}
function add_favorate_show1(user_id,show_id)
{
	var url = siteurl+"show.php?action=add_favorate_shows&user_id="+user_id+"&show_id="+show_id;
	http.open('get', url);
    http.onreadystatechange = add_favorate_show_response;
    http.send(null);
	document.getElementById("link-show-"+show_id).innerHTML='<a  href="javascript:void(0);" onclick="remove_favorate_show1('+user_id+','+show_id+');">REMOVE FROM FAVORITES</a>';	
	
}

function add_my_favorate_show_by_txt_box(user_id,show_id)
{
	//alert('alert testing comment');

	//alert('{SITE_URL}applaud.php?user_id='+user_id+'&story_id='+story_id);
	//return;
	var url = siteurl+"show.php?action=add_my_favorate_show_by_txt_box&user_id="+user_id+"&show_id="+show_id;
	//alert(url);
	//return;
	http.open('get', url);
    http.onreadystatechange = add_my_favorate_show_by_txt_box_response;
    http.send(null);
	document.getElementById("link-show-"+show_id).innerHTML='<a class="greentext" href="javascript:void(0);" onclick="remove_favorate_show1('+user_id+','+show_id+');">REMOVE FROM FAVORITES</a>';
	
}

function add_my_favorate_show_by_txt_box_response() 
{
	if(http.readyState == 4)
	{
        var response = http.responseText;
		alert(response);
		//location.reload(true);
	}
}

function add_favorate_show_response() 
{
	if(http.readyState == 4)
	{
        var response = http.responseText;
	}
}


function remove_favorate_show(user_id,show_id)
{
	var url = siteurl+"show.php?action=remove_favorate_shows&user_id="+user_id+"&show_id="+show_id;
	http.open('get', url);
	http.onreadystatechange = remove_favorate_show_response;
	http.send(null);
	document.getElementById("link-show-"+show_id).innerHTML='<a class="greentext" href="javascript:void(0);" onclick="add_favorate_show('+user_id+','+show_id+');">ADD TO FAVORITES</a>';
	
}
function remove_favorate_show1(user_id,show_id)
{
	var url = siteurl+"show.php?action=remove_favorate_shows&user_id="+user_id+"&show_id="+show_id;
	http.open('get', url);
	http.onreadystatechange = remove_favorate_show_response;
	http.send(null);
	document.getElementById("link-show-"+show_id).innerHTML='<a href="javascript:void(0);" onclick="add_favorate_show('+user_id+','+show_id+');">ADD TO FAVORITES</a>';
	
}

function rmv_my_favorate_show(user_id,show_id)
{
	var url = siteurl+"show.php?action=remove_favorate_shows&user_id="+user_id+"&show_id="+show_id;
	http.open('get', url);
	http.onreadystatechange = remove_favorate_show_response;
	http.send(null);
	document.getElementById("lst-myshows-"+show_id).innerHTML='';
}

function add_my_favorate_show1(user_id,show_id)
{
	var url = siteurl+"show.php?action=add_favorate_shows&user_id="+user_id+"&show_id="+show_id;
	http.open('get', url);
	http.onreadystatechange = add_favorate_show_response1;
	http.send(null);
	document.getElementById("lst-myshows-"+show_id).innerHTML='';
}
function add_favorate_show_response1() 
{
	if(http.readyState == 4)
	{
        var response = http.responseText;
		//return response;
		
		//alert(response);
		//location.reload(true);
	}
}

function remove_favorate_show_response() 
{
	if(http.readyState == 4)
	{
        var response = http.responseText;
	}
}


function remove_my_favorate_show(user_id,show_id)
{
	var url = siteurl+"show.php?action=remove_favorate_shows&user_id="+user_id+"&show_id="+show_id;
	http.open('get', url);
	http.onreadystatechange = remove_my_favorate_show_response;
	http.send(null);
	document.getElementById("li-shows-listings-"+show_id).innerHTML='';
}


function remove_my_favorate_show_response() 
{
	if(http.readyState == 4)
	{
        var response = http.responseText;
	}
}

function getFollowingSearch(id,emote){
    // Don't worry with this var.
    var Request;
    var Name;
    var Opt;
    var Params;
    var page;
    var results = "";
    try{
        obj1 = new XMLHttpRequest();       
    } catch (e){
        try{
            obj1 = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                obj1 = new ActiveXObject("Microsoft.XMLHTTP");   
            } catch (e){
                alert("Your browser does not support AJAX.\nPlease update your browser or login with the main login.");
                return false;
            }
        }
    }
   
    // This is the php file with the script to update the Database.
    if(emote>0){
        if(module==0){
        var url = siteurl+"show.php?action=checknewfollowing&mode=mem&id="+id+"&emote="+emote;
        }else{
        var url = siteurl+"show.php?action=checknewfollowing&mode=all&id="+id;
        }
    }else{
        var url = siteurl+"show.php?action=checknewfollowing&mode=mem&id="+id;
    }   

    obj1.open("POST", url, true);
    obj1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    obj1.setRequestHeader("Connection", "close");
    obj1.send(Params);
    obj1.onreadystatechange = function(){
            if(obj1.readyState == 4){
                var str= trim(obj1.responseText);

				var arrtotalstr=str.split('--');

                if(arrtotalstr.length>1){
                    if(arrtotalstr[1].length>0){
						$("ol#update").prepend(arrtotalstr[1]);
	                    $("ol#update li:first").hide().slideDown("slow");
                    }
					if(document.getElementById('current_records').value==0){
					var total_record=arrtotalstr[0];
					document.getElementById('norecord').innerHTML='';
					document.getElementById('current_records').value=arrtotalstr[0];
					}else{
			//		if(document.getElementById('current_records').value>0){
						total_record=document.getElementById('current_records').value;
						document.getElementById('current_records').value=parseInt(total_record) + parseInt(arrtotalstr[0]);
						var total_record = parseInt(total_record) + parseInt(arrtotalstr[0]);
					}
                }

                if(arrtotalstr[0]>0 && total_record>25)
                {
                    var total = arrtotalstr[0];
                    for (var x = 0; x < arrtotalstr[0] ; x++){
                        $('ol#update li:last').remove();
                    }
                }
            }
    }
   
    clearTimeout(timer);

    if(document.getElementById('pausevalue').value=='0'){
     
        timer = setTimeout("getFollowingSearch("+id+",0)", 5000);
     //   }
    }
 }

function onEnterGoForAddShow(event,user_id){
	if(event.keyCode == 13){
		var show_string = trim(document.getElementById('txtAddMyShow').value);
		if(show_string.length > 0){
					
					// ajax code
					var Request;
					var Name;
					var Opt;
					var Params;
					var page;
					var results = "";
					try{
						obj1 = new XMLHttpRequest();       
					} catch (e){
						try{
							obj1 = new ActiveXObject("Msxml2.XMLHTTP");
						} catch (e) {
							try{
								obj1 = new ActiveXObject("Microsoft.XMLHTTP");   
							} catch (e){
								alert("Your browser does not support AJAX.\nPlease update your browser or login with the main login.");
								return false;
							}
						}
					}
				
				var url = siteurl+"show.php?action=fetch_cond_shows&show_str="+show_string+"&user_id="+user_id;
				
				obj1.open("POST", url, true);
				obj1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				obj1.setRequestHeader("Connection", "close");
				obj1.send(Params);
				obj1.onreadystatechange = function(){
					if(obj1.readyState == 4){
						//var str= new String(obj1.responseText);
						var response_str= trim(obj1.responseText);
						document.getElementById('wrap_myshows_ajax_reponse_links').innerHTML=response_str;
					}
				}
		}
	}
}


function showsLimit(user_id){

	var str= document.getElementById('txtAddMyShow').value;
	
	if(str.length==0){
		//alert('Enter the text in Search box');
		document.getElementById('txtAddMyShow').focus();
		return false;
	}
	
	
	var st = trim(document.getElementById('txtAddMyShow').value);
	if(st.length == 0){
		//alert("Enter the text in Search box");
		document.getElementById('txtAddMyShow').value="";
		document.getElementById('txtAddMyShow').focus();
		return false;
	}
	
	// ajax code
		var Request;
		var Name;
		var Opt;
		var Params;
		var page;
		var results = "";
		try{
			obj1 = new XMLHttpRequest();       
		} catch (e){
			try{
				obj1 = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try{
					obj1 = new ActiveXObject("Microsoft.XMLHTTP");   
				} catch (e){
					alert("Your browser does not support AJAX.\nPlease update your browser or login with the main login.");
					return false;
				}
			}
		}
		
		var show_string = trim(document.getElementById('txtAddMyShow').value);
		
		var url = siteurl+"show.php?action=fetch_cond_shows&show_str="+show_string+"&user_id="+user_id;
		
		obj1.open("POST", url, true);
		obj1.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		obj1.setRequestHeader("Connection", "close");
		obj1.send(Params);
		obj1.onreadystatechange = function(){
			if(obj1.readyState == 4){
				//var str= new String(obj1.responseText);
				var response_str= trim(obj1.responseText);
				document.getElementById('wrap_myshows_ajax_reponse_links').innerHTML=response_str;
			}
		}
				
}

