	var ALERT_IMG = 'http://img.makaan.com/images/alert.gif';
	var tbring = "<?=$_GET['bring']?>>";
	
	$(document).ready(function() {
		//FB.init({ apiKey: 'a0c7628eb371b80f5cf65d49918e77f3'});


		FB.init({ apiKey: '252001924842572'});
		if(getUrlVars()["bring"] == 1){
			$('html, body').animate({ scrollTop: $('#post-comments').offset().top - 10 }, 900, function(){
				});
		}

		if(window.screen.width == 1366){
			$("#strip_hlt").css({"position":"absolute"});
		}else{
			$("#strip_hlt").css({"position":"absolute"});
		}
		
		$(window).scroll(function() {
			$("#strip_hlt").css("top", $(window).scrollTop() + "px");
		});
	});

	function getUrlVars()
	{
		var vars = [], hash;
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
		for(var i = 0; i < hashes.length; i++)
		{
			hash = hashes[i].split('=');
			vars.push(hash[0]);
			vars[hash[0]] = hash[1];
		}
		return vars;
	}


	function manageTerms(ttid){
		if(ttid == 'show'){
			$('#div_terms').slideDown("slow");
			$('html, body').animate({ scrollTop: $('#div_terms').offset().top - 50 }, 900, function(){
				});
		}else{
			$('#div_terms').slideUp("slow");
		}
	}


	function highlight_focus(tval, tid){
		if($('#'+tid).val() == tval){
			$('#'+tid).val('');
		}
		if(tid=='qs' && $('#'+tid).val() != 'Enter Questions, Keywords or Topics'){
			document.getElementById("keyerr").style.display = 'none';
		}
	}
	function highlight_blur(tval, tid){
		if($('#'+tid).val() == tval || $('#'+tid).val() == ''){
			$('#'+tid).val(tval);
		}
		if(tid=='qs' && $('#'+tid).val() == 'Enter Questions, Keywords, or Topics'){
			$('#qs').css({'color':'#A9A9A9'});
		}
		if(tid=='dseachQues' && $('#'+tid).val() == 'Start your discussion here'){
			$('#dseachQues').css({'color':'#A9A9A9'});
		}
	} 

	function reply_counter(textid,counterid,maxKeys)
	{
		//document.getElementById('dseachQues').style.color='#6B6B6B';
		var str = $('#'+textid).val();
		var tlen = str.length;
		var len = maxKeys - str.length;
		var showstr = "<span style='color:#000000;'>" + len + "</span>" + " Characters Left";

		if(parseInt(tlen) > parseInt(maxKeys)) 
		{
			/*str = str.substring(0,maxKeys)
			$('#'+textid).val(str)
			showstr = '(Max '+ maxKeys +' Characters)';*/
			var showstr = "<span style='color:red;font-size:11px;'><b>" + len + "</b></span>" + " Characters Left";

		}
		$('#'+counterid).html(showstr) ;

		/* Code to expand textarea */

		ttl = $('#'+textid).val().length;
		if(ttl >= 300 && ttl < 500){
			$('#'+textid).attr('rows',10);
		}else if(ttl >= 500 && ttl < 800){
			$('#'+textid).attr('rows',15);
		}else if(ttl >= 800 ){
			$('#'+textid).attr('rows',24);
		}else{
			$('#'+textid).attr('rows',5);
		}


	}

	function showhidereplydiv(divid)
	{
		if(divid=='newuser'){
			document.getElementById('existing_reply').style.display='none';
			document.getElementById('eu_reply').className='existtab';
			document.getElementById('nu_reply').className='newtabon';
			document.getElementById('newuser_reply').style.display='block';
		}
		else if(divid=='existing'){
			document.getElementById('newuser_reply').style.display='none';
			document.getElementById('nu_reply').className='newtab';
			document.getElementById('eu_reply').className='existtabon';
			document.getElementById('existing_reply').style.display='block';
		}
	}

	function deletePost(id,ptype){
		var url = '/ssi/ajax/comments/delete-box.php?id='+id+'&ptype='+ptype+'';
		//alert(url);
		$('#ex2').jqm({ajax: url, onShow:myOpen});
		$('#ex2').jqm().jqmShow(); 
		$('#window2').jqmHide();

		//alert('b');
	}

	function closepopup(){
		$('#ex2').jqm({onHide:myClose});
		$('#ex2').jqmHide();
		return false;
	} 

	function del(pid,ptype)
	{
		$.post('/ssi/ajax/comments/delete-post.php', {'pid':pid, 'ptype':ptype}, hidePost, "json");
	} 

	function hidePost(d){
		if(d.success == 1){
			tusrl = "http://"+location.host+location.pathname+'?bring=1';
			location.href = tusrl;
			//closepopup();
		}
	
	}

	var myClose=function(hash) { hash.w.fadeOut(1000,function(){ hash.o.remove(); }); };
	var myOpen=function(hash) { hash.w.fadeIn(1000); }; 



var reply_parent_id = 0;
var repdiv = 1;
var grep_name = '';
var gthis_submit = '';
var rep_type = 0; // 0 for first reply , value means comment Id
var gcmt_id = 0;

function postReply(tcmtid, repType, tname, tthis){
	
	reply_parent_id = repType;
	repdiv = 1;
	grep_name = tname;
	gthis_submit = tthis;
	gcmt_id = tcmtid;

	login_box_button_show_hide();
	
	if(repType != 0){ // reply of reply
		repdiv = 2;
	}

	var tcmt = $.trim($('#reply'+repdiv+'_text_'+tcmtid).val());
	var tcmturl = $('#reply'+repdiv+'_url_'+tcmtid).val();
	$('.texterror').html('');
	$('.login_class').html('');
	$('.submit_reply_div1').show();
	if(tcmt == ''){
		$('#reply'+repdiv+'_err_'+tcmtid).html('<img width="10" vspace="3" height="10" border="0" align="absmiddle" src="http://img.makaan.com/images/alert.gif">&nbsp;Please enter the comment.');
		return false;
	}

	if(tcmt.length > 1000){
		$('#reply'+repdiv+'_err_'+tcmtid).html('<img width="10" vspace="3" height="10" border="0" align="absmiddle" src="http://img.makaan.com/images/alert.gif">&nbsp;Your reply has exceeded 1000 characters, please modify.');
		return false;
	}

	var tis_notify = 0;
	if($('#cmtemailme').is(':checked')){
		tis_notify = 1;
	}

	if(is_makaan_user == 'Y' || is_fb_user == 'Y'){
		
		if(repType != 0){ // reply of reply
			reply_parent_id = tcmtid;
			tcmtid = repType;
		}

		$.post('/ssi/ajax/comments/post-reply.php', {'reply_type':repdiv,'reply_parent_id':reply_parent_id, 'article_id':article_id,'comment_id':tcmtid, 'cmt':tcmt, 'weburl':tcmturl, 'is_notify':tis_notify}, callBackReplyCmt, 'json');

	}else{
		target_function = 1;
		tval = $('#reply_login_frm').html();
		$('#reply'+repdiv+'_submit_div_'+tcmtid).hide();
		login_cancel = 'reply'+repdiv+'_login_'+tcmtid;
		show_after_cancel = 'reply'+repdiv+'_submit_div_'+tcmtid;
		$('#reply'+repdiv+'_login_'+tcmtid).html(tval);
		$('#reply'+repdiv+'_login_'+tcmtid).slideDown('slow',function(){
			$('html, body').animate({ scrollTop: $('#reply'+repdiv+'_login_'+tcmtid).offset().top - 50 }, 900, function(){});
		});
	}

}


function callBackReplyCmt(d){
	if(d.success == 1){
		if(d.rep_type == 1){
			tstr = $('#sdumb').html();
			tstr = tstr.replace(/#cmtid#/g, d.comment_id);
		}else if(d.rep_type == 2){
			tstr = $('#tdumb').html();
		}
		tstr = tstr.replace(/#refid#/g, d.rep_id);
		tstr = tstr.replace(/#reply#/g, d.cmt);
		tstr = tstr.replace(/#fullname#/g, d.name);
		tstr = tstr.replace(/#memberid#/g, d.member_id);
		tstr = tstr.replace(/#weburl#/g, d.weburl);
		tstr = tstr.replace(/#cityurl#/g, d.cityurl);
		tstr = tstr.replace(/#cityname#/g, d.cityname);


		thead = '';
		tsep = '';
		if($(gthis_submit).attr('refcnt') == 0){
			if(d.rep_type == 1){
				thead = $('#ANS_HEADER_DUMB').html();
				thead = thead.replace(/#fullname#/g, grep_name);
				$('#ANS_HEADER_'+d.comment_id).html(thead);
				$(gthis_submit).attr('refcnt', 1);
			}else if(d.rep_type == 2){
				thead = $('#REP_HEADER_DUMB').html();
				thead = thead.replace(/#fullname#/g, grep_name);
				$('#REP_HEADER_'+d.reply_parent_id).html(thead);
				$(gthis_submit).attr('refcnt', 1);
			}

		}else{
			if(d.rep_type == 1){
				tsep = '<div class="nseperator2"></div>';
			}else if(d.rep_type == 2){
				tsep = '<div class="nseperator3"></div>';
			}
		}

		if(d.rep_type == 1){
			$('#post_'+d.comment_id).after(tstr+tsep);
			if(d.weburl != '' && d.weburl != null){
				$('#rep1_url_'+d.rep_id).show();
			}

			if(d.cityurl != '' && d.cityurl != null){
				$('#rep1_country_'+d.rep_id).show();
			}
		}else if(d.rep_type == 2){
			$('#REP1_'+d.reply_parent_id).after(tstr+tsep);
			if(d.weburl != '' && d.weburl != null){
				$('#rep2_url_'+d.reply_parent_id).show();

			}

			if(d.cityurl != '' && d.cityurl != null){
				$('#rep2_country_'+d.reply_parent_id).show();
			}
		}
		
		

		//$('#cmt').val('');
		//$('#cmturl').val('http://');

		if(d.rep_type == 1){
			$('#reply'+d.rep_type+'_login_'+d.comment_id).slideUp('slow',function(){
				$('#reply'+repdiv+'_'+d.comment_id).slideUp('slow',function(){
					$('html, body').animate({ scrollTop: $('#ANS_HEADER_'+d.comment_id).offset().top - 50 }, 900, function(){
						$('#alertmsg').html("You reply has been successfully posted");
						$('#strip_hlt').slideDown('slow');
						setTimeout("hide_highliter()", '4000');
					
					});
					$('#reply'+repdiv+'_submit_div_'+d.comment_id).slideDown('slow');
					$('#rep1_but_'+d.comment_id).show();
					
				});
			});
		}else if(d.rep_type == 2){
			$('#reply'+d.rep_type+'_login_'+d.reply_parent_id).slideUp('slow',function(){
				$('#reply'+repdiv+'_'+d.reply_parent_id).slideUp('slow',function(){
					$('html, body').animate({ scrollTop: $('#REP_HEADER_'+d.reply_parent_id).offset().top - 50 }, 900, function(){
						$('#alertmsg').html("You reply has been successfully posted");
						$('#strip_hlt').slideDown('slow');
						setTimeout("hide_highliter()", '4000');
				
					});
					$('#reply'+repdiv+'_submit_div_'+d.reply_parent_id).slideDown('slow');
					$('#rep2_but_'+d.reply_parent_id).show();

				});
			});
		}



		$('#reply'+d.rep_type+'_login_'+d.comment_id).slideUp('slow',function(){
			$('#reply'+repdiv+'_'+d.comment_id).slideUp('slow',function(){
				$('html, body').animate({ scrollTop: $('#ANS_HEADER_'+d.comment_id).offset().top - 50 }, 900, function(){});
				$('#reply'+repdiv+'_submit_div_'+d.comment_id).slideDown('slow');
			});
		});
	}else{
		$('#ferrmsg').html(d.error);
	}

}

function login_box_button_show_hide(){
	$('.sub_existing_login').show();
	$('.sub_existing_login_load').hide();
	$('.sub_new_login').show();
	$('.sub_new_login_load').hide();
}


function postCmt(){
	var tcmt = $.trim($('#cmt').val());
	var tcmturl = $('#cmturl').val();

	login_box_button_show_hide();
	

	$('#ferrmsg').html('');
	if(tcmt == ''){
		$('#ferrmsg').html('<img width="10" vspace="3" height="10" border="0" align="absmiddle" src="http://img.makaan.com/images/alert.gif">&nbsp;Please enter the comment.');
		return false;
	}

	if(tcmt.length > 1000){
		$('#ferrmsg').html('<img width="10" vspace="3" height="10" border="0" align="absmiddle" src="http://img.makaan.com/images/alert.gif">&nbsp;Your comment has exceeded 1000 characters, please modify.');
		return false;
	}
	
	var tis_notify = 0;
	if($('#cmtemailme').is(':checked')){
		tis_notify = 1;
	}
	

	if(is_makaan_user == 'Y' || is_fb_user == 'Y'){
		
		$.post('/ssi/ajax/comments/post-comments.php', {'article_id':article_id, 'cmt':tcmt, 'weburl':tcmturl, 'is_notify':tis_notify}, callBackPostCmt, 'json');

	}else{
		target_function = 0;
		tval = $('#reply_login_frm').html();
		$('#postdiv').hide();
		login_cancel = 'postlogindiv';
		show_after_cancel = 'postdiv';
		$('#postlogindiv').html(tval);
		$('#postlogindiv').slideDown('slow',function(){
			$('html, body').animate({ scrollTop: $('#postlogindiv').offset().top - 50 }, 900, function(){});
		});
	}
}









function callBackPostCmt(d){
	if(d.success == 1){
		tstr = $('#fdumb').html();
		tstr = tstr.replace(/#refid#/g, d.cmt_id);
		tstr = tstr.replace(/#tcomment#/g, d.cmt);
		tstr = tstr.replace(/#fullname#/g, d.name);
		tstr = tstr.replace(/#memberid#/g, d.member_id);
		tstr = tstr.replace(/#cityname#/g, d.cityname);
		tstr = tstr.replace(/#cityurl#/g, d.cityurl);

		if(d.weburl != ''){
			tstr = tstr.replace(/#weburl#/g, d.weburl);
		}


		$('#appendcmt').after(tstr);

		if(d.weburl != '' && d.weburl != null){
			$('#cmt_url_'+d.cmt_id).show();
		}

		if(d.cityurl != '' && d.cityurl != null){
			$('#cmt_country_'+d.cmt_id).show();
		}

		trepStr = $('#share_post_txt_'+d.cmt_id).html();
		var ttans = "Check my comment on MakaanIQ.com: "+d.cmt;
		if(d.cmt.length > 335){
			ttans = d.cmt.substr(0,332) + '...';
		}
		trepStr = trepStr.replace(/#comment_plus_url#/g, ttans+" "+page_short_url);
		$('#share_post_txt_'+d.cmt_id).html(trepStr);

		$('#cmt').val('');
		$('#cmturl').val('http://');
		$('#postlogindiv').slideUp('slow',function(){
			$('#postdiv').slideDown('slow');
			tpv = $('#cmt_total').html();
			if(parseInt(tpv,10) == 0){
				$('#appendcmt').css({'padding-top':'20px'});
				$('#post_container').css({'border-top':'1px solid #BCDEFA'});
				$('.nseperator').eq(0).remove();
			}

			tpv = parseInt(tpv,10) + 1;
			$('#cmt_total').html(tpv);
			$('.cmttext').show();
			
			$('html, body').animate({ scrollTop: $('.cmttext').offset().top - 50 }, 900, function(){
				$('#alertmsg').html("You comment has been successfully posted");
				$('#strip_hlt').slideDown('slow');
				setTimeout("hide_highliter()", '4000');
			});
		});
	}else{
		$('#ferrmsg').html(d.error);
		closeLoginDiv();

	}
}

function showReply(tid, tcase){
	if(tcase == 1){ //reply
		$('#reply1_'+tid).slideDown('slow');
		$('#rep1_but_'+tid).hide();
	
	}else if(tcase == 2){ // reply of reply
		$('#reply2_'+tid).slideDown('slow');
		$('#rep2_but_'+tid).hide();
	
	}
}



function insert_replydiv()
{
	
	if($('#usernamereply').val() == "" && $('#pwdreply').val() == "")
	{
		document.getElementById('errmsgreply').innerHTML = "<img src='"+IMG_SERVER+"/images/alert.gif' width='10' height='10' align='absmiddle' vspace='3' border=0>&nbsp;Please enter your username and password.";
		document.$('#usernamereply').focus();

	}else if($('#usernamereply').val() == "" || $('#usernamereply').val() == "Username") {	
		document.getElementById('errmsgreply').innerHTML = "<img src='"+IMG_SERVER+"/images/alert.gif' width='10' height='10' align='absmiddle' vspace='3' border=0>&nbsp;Please enter your username.";
		$('#errmsgreply').show();
		$('#usernamereply').focus();

	}else if($('#pwdreply').val() == "" || $('#pwdreply').val() == "Password") {
		document.getElementById('errmsgreply').innerHTML = "<img src='"+IMG_SERVER+"/images/alert.gif' width='10' height='10' align='absmiddle' vspace='3' border=0>&nbsp;Please enter your password.";
		$('#errmsgreply').show();
		$('#pwdreply').focus();

	}else
	{
		document.getElementById('errmsgreply').innerHTML ='';
		//$('#errmsgreply').hide();
		//$('#loading').show();
		$('.sub_existing_login_load').show();
		$('.sub_existing_login').hide();

		$.post('/ssi/ajax/comments/ajax-content.php', {'process':'login', 'userid':$('#usernamereply').val(), 'password':$('#pwdreply').val()}, login_replyresponse, 'json');
	}
	return false;
}

function login_replyresponse(d){
	if(d.success == 1){
		is_makaan_user = 'Y';
		$('.toplinks').eq(0).attr('href',"javascript:doLogout()").html('Logout');
		if(target_function == 0){
			postCmt();
		}
		if(target_function == 1){
			tcmtid = gcmt_id;
			repType = rep_type;
			tname = grep_name;
			tthis = gthis_submit;
			//console.log("cmtid - "+tcmtid+' repty-'+repType+' tname-'+repType+' sub_this-'+tthis);
			postReply(tcmtid, repType, tname, tthis);
		}
	}else{
		$('#errmsgreply').html(d.error);
		
		$('#errmsgreply').show();
		$('.sub_existing_login_load').hide();
		$('.sub_existing_login').show();
	}

}


function insert_new_user_reply()
{	
	$('#newname_reply').css({'border':'1px solid #A7C4E3'});
	$('#email_reply').css({'border':'1px solid #A7C4E3'});
	$('#mobile_reply').css({'border':'1px solid #A7C4E3'});
	$('#city_reply').parent().css({'border':'0px solid'});
	$('.terms_cond').css({'border':'0px solid '});
	$('#new_err_reply').html('');
	if($('#newname_reply').val() == "" || $('#newname_reply').val() == "Name"){
		$('#newname_reply').css({'border':'1px solid red'});
		$('#new_err_reply').show();
		$('#new_err_reply').html("<img src='"+IMG_SERVER+"/images/alert.gif' width='10' height='10' align='absmiddle' vspace='3' border=0>&nbsp;Please enter the name.");
		return false;
	}
	if($('#email_reply').val() == "" || $('#email_reply').val() == "Email" ){
		$('#email_reply').css({'border':'1px solid red'});
		$('#new_err_reply').show();
		$('#new_err_reply').html("<img src='"+IMG_SERVER+"/images/alert.gif' width='10' height='10' align='absmiddle' vspace='3' border=0>&nbsp;Please enter the email.");
		return false;
	}
	if($('#mobile_reply').val() == "" || $('#mobile_reply').val() == "Mobile"){
		$('#mobile_reply').css({'border':'1px solid red'});
		$('#new_err_reply').show();
		$('#new_err_reply').html("<img src='"+IMG_SERVER+"/images/alert.gif' width='10' height='10' align='absmiddle' vspace='3' border=0>&nbsp;Please enter the mobile number.");
		return false;
	}
	if($('#city_reply').find('option:selected').attr('value') == ""){
		$('#city_reply').parent().css({'border':'1px solid red'});
		$('#new_err_reply').show();
		$('#new_err_reply').html("<img src='"+IMG_SERVER+"/images/alert.gif' width='10' height='10' align='absmiddle' vspace='3' border=0>&nbsp;Please select city.");
		return false;
	}
	var tterm = 0;
	if(!$('#term_reply').is(':checked')){
		tterm = 0;
		$('#term_reply').css({'border':'1px solid red'});
		$('#term_reply').css('outline-color', 'red'); 
		$('#term_reply').css('outline-style', 'solid'); 
		$('#term_reply').css('outline-width', 'thin'); 
		if($.browser.msie ){
			$('#term_reply').css({'background':'#fff'});
		}
		$('#new_err_reply').show();
		$('#new_err_reply').html("<img src='"+IMG_SERVER+"/images/alert.gif' width='10' height='10' align='absmiddle' vspace='3' border=0>&nbsp;Accept Privacy Policy and Terms of Use.");
		return false;
	}else{
		tterm = 1;
	}
	//$('#loading').show();
	$('.sub_new_login_load').show();
	$('.sub_new_login').hide();
	$.post('/ssi/ajax/comments/register-user.php', {'name':$('#newname_reply').val(), 'email':$('#email_reply').val(), 'terms':tterm, 'mobile':$('#mobile_reply').val(), 'city':$('#city_reply').find('option:selected').attr('value')}, reg_response, 'json');
	return false;
}


function reg_response(d){
	if(d.success == 1){
		
		$.post('/ssi/ajax/comments/ajax-content.php', {'process':'login', 'userid':d.username, 'password':d.password}, login_replyresponse, 'json');
	}else{
		$('#new_err_reply').show();
		$('.sub_new_login').show();
		$('.sub_new_login_load').hide();
		$('#new_err_reply').html(d.error);
	}
}


function sharePost(id){
	var url= $('.share_class:checked').val();
	var tradio = $('.share_class:checked').attr('refv');
	if(tradio != "facebook"){
		window.open (url, "mywindow","location=1,status=1,scrollbars=1, width=500,height=500");
	}else{
		var ttl = $('.share_class:checked').attr('rtitle');;
		var tpre = "Check my comment on MakaanIQ.com: ";
		var tshrt_url = $('.share_class:checked').attr('rurl');
		var tans = $('.ques_border:first > div').html();
		if(tans.length > 160){
			tans = tans.substr(0,157)+'...';
		}
		var tshr_txt = tpre + tans +' '+ tshrt_url;
		$.post('/ssi/ajax/comments/discuss-fb-share.php', {'fb_title':ttl, 'fb_desc':tshr_txt, 'fb_url': 'http://forums.makaan.com/hi--q840/home-buying-market-information-c1s12/'}, fb_share_post, "json");
		
		
		
		/*
		var tshr_txt = $("#share_post_txt_"+id).val();
		
		FB.ui({ method: 'feed', 
			message: tshr_txt,
			name: ttl,
			link: location.href,
			picture: 'http://img.makaan.com/images/logo.gif',
			caption: 'Makaan.com Discussion Forum',
			description: tshr_txt,
			message:''});*/
	}

	$("#share_container_"+id).remove();
	$('#rep1_but_'+id).show();
}	


function fb_share_post(d){
	if(d.success == 1){
		var turl = "http://devfin.makaan.com/fb-share.php?fbtype=share&fbid="+d.fbid;
		window.open(turl,'','width=680,height=480');
	}

}




function closeLoginDiv(){
    $('#'+login_cancel).slideUp('slow', function(){
            $('#'+login_cancel).html('').hide();
            $('#'+show_after_cancel).slideDown('slow');
    });

}



/* Tooltip Code Starts */



/* Login And Logout + FB Login And Logout Starts */



function hide_highliter(){
	$('#strip_hlt').slideUp('slow',function(){
		$('#strip').slideDown('slow');
	});
}


function post_logout_status(d)
{
	if(d.success == 1)
	{
		//window.location.reload();
		is_makaan_user = 'N';
		$('.toplinks').eq(0).attr('href',"/login.php").html('Login');
		$('#alertmsg').html("You have successfully logged out");
		$('#strip_hlt').slideDown('slow');
		setTimeout("hide_highliter()", '12000');

	}
}

function doLogout()
{
	$.post('/ssi/ajax/comments/ajax-content.php', {'process':'logout'}, post_logout_status, 'json');
}


//Facebook  functionality start

function checkFBLogin()
{
	FB.login(FBResponse);
	
} 

function  FBLogout(response)
{	
	FB.logout(handleSessionResponse);
	
} 

function handleSessionResponse(response)
{
	if (!response.session){
		$.post('/ssi/ajax/comments/discuss-fb-logout.php', {}, logoutPost, "json");
	}

} 


function FBResponse(response)
{
	if (response.session) {
		//alert('Hello there');
		FB.api(
			{
				method: 'fql.query',
				query: 'SELECT name, pic FROM profile WHERE id=' + FB.getSession().uid
			},
			function(response) {
				var user = response[0];
				//console.log(response[0])
				var tname = response[0].name;
				$.post('/ssi/ajax/comments/discuss-fb-login.php', {'fbuid': FB.getSession().uid, 'fbname':tname}, loggedInPost, "json");
				
			}
		);


	 //$.post('/ssi/ajax/discuss-fb-login.php', {'fbuid': tuid, 'fbuname':tuname, ''})
	}else{
		//alert("Successfully logged Out.")
	}

} 

function loggedInPost(d){
	if(d.success == 1){
		is_fb_user = 'Y';
		$('.toplinks').eq(0).attr('href',"javascript:FBLogout();").html('FB Logout');

		if(target_function == 0){
			postCmt();
		}
		if(target_function == 1){
			tcmtid = gcmt_id;
			repType = rep_type;
			tname = grep_name;
			tthis = gthis_submit;
			//console.log("cmtid - "+tcmtid+' repty-'+repType+' tname-'+repType+' sub_this-'+tthis);
			postReply(tcmtid, repType, tname, tthis);
		}
	}
}

function logoutPost(d){
	if(d.success == 1){
		is_fb_user = 'N';
		$('.toplinks').eq(0).attr('href',"/login.php").html('Login');
	}
}

//Facebook  functionality ends




/* Login And Logout + FB Login And Logout Ends */







function findWindowVisibleArea()
{
	var winW = 630, winH = 460;
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			winH = window.innerHeight;
			winW = window.innerWidth;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winH = document.body.offsetHeight;
			winW = document.body.offsetWidth;
		}
	}
	return [winW,winH];
}

function findObjPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		curtop = (curtop-document.body.scrollTop);
		curleft = (curleft-document.body.scrollLeft);
		return [curleft,curtop];
	}
}

function getVerticlePosition(obj,hgt)
{
	var posy = 0;
	var pos = 'T';
	var eleHeight = 0;
	var posArr = findObjPos(obj);
	var winVisibleArr = findWindowVisibleArea( );
	
	posy = posArr[1];
	
	if(obj.tagName == 'IMG')
		eleHeight = obj.height;
	else if(obj.tagName == 'DIV')
		eleHeight = obj.style.height;
	else
		eleHeight = 20;
	if(winVisibleArr[1]- (eleHeight+posy) > hgt){
		pos = 'T';
	}else{
		pos = 'D';
	}
	return pos;
}

function getHorizontalPosition(obj,hgt)
{
	var posx = 0;
	var pos = 'L';
	var eleHeight = 0;
	var posArr = findObjPos(obj);
	var winVisibleArr = findWindowVisibleArea( );
	posx = posArr[0];
	
	if(posx < (winVisibleArr[0]/2)){
		pos = 'R';
	}else{
		pos = 'L';
	}
	return pos;
}

function fillBubbleContent(id)
{
	return dataArr[id];
} 

function doTrim(A){return A.replace(/^\s+|\s+$/g,"")}
function hideBubbleInfo(C)
{
	var B="";var A=false;
	if(buubleMSIE){
		B=window.event.srcElement.id;
		if(
			B.substring(0,2)=="co" || 
			window.event.toElement.id=="buubleTop" ||
			window.event.toElement.id=="buubleBottom" ||
			window.event.toElement.id=="buubleContent" ||
			window.event.fromElement.id=="buubleContent" || 
			window.event.srcElement.id=="buubleContent" || 
			window.event.srcElement.parentNode.id=="buubleObj"
		)
		{
			A=true
		}
		if(window.event.toElement.id=="null"||window.event.toElement.id=="")
		{
			A=false
		}
		if(!A)
		{
			buubleObj.style.display="none"
		}
	} else{
		B=C.relatedTarget.id;
		if(B.substring(0,2)=="co"||B.substring(0,10)=="buubleContent"||B=="buubleObj"||B=="buubleContent")
		{
			A=true
		}
		if(!A&&C.relatedTarget.parentNode.id!="buubleObj"&&C.relatedTarget.id!="buubleContent")
		{
			buubleObj.style.display="none"
		}
	}
}
function getBubbleTopPos(A)
{
	var B=A.offsetTop;
	while((A=A.offsetParent)!=null)
	{
		if(A.tagName!="HTML")
		{
			B+=A.offsetTop
		}
	}
	return B
}
function getBubbleLeftPos(A)
{
	var B=A.offsetLeft;
	while((A=A.offsetParent)!=null)
	{
		if(A.tagName!="HTML")
		{
			B+=A.offsetLeft
		}
	}
	return B
}
function urlDecode(E)
{
	var A="0123456789ABCDEFabcdef";var D="";var B=0;
	while(B<E.length)
	{
		var C=E.charAt(B);
		if(C=="+")
		{
			D+=" ";B++
		}else{
			if(C=="%")
			{
				if(B<(E.length-2)&&A.indexOf(E.charAt(B+1))!=-1&&A.indexOf(E.charAt(B+2))!=-1)
				{
					D+=unescape(E.substr(B,3));
					B+=3
				}else{
					alert("Bad escape combination near ..."+E.substr(B));D+="%[ERROR]";B++
				}
			}else{
				D+=C;B++
			}
		}
	}
	return D
}
var xOffset=5;
var yOffset=0;
var buubleObj=false;
var buubleMSIE=false;
if(navigator.userAgent.indexOf("MSIE")>=0){buubleMSIE=true}
var currentBubbleObj=false;
var Sz = 'Large';
function showBubbleInfo(A,B,Pos,Size){
	A=urlDecode(A);
	currentBubbleObj=B;
	if(Size != 'undefined')
		Sz = Size;
	if(!buubleObj)
	{
		buubleObj=document.getElementById("buubleObj");
		D=document.getElementById("buubleContent");
		H=document.getElementById("buubleTop");
		I=document.getElementById("buubleBottom");
		
		B.onmouseout=function(E)
		{
			hideBubbleInfo(E)
		};
		D.onmouseout=function(E)
		{
			hideBubbleInfo(E)
		}
		H.onmouseout=function(E)
		{
			hideBubbleInfo(E)
		}
		I.onmouseout=function(E)
		{
			hideBubbleInfo(E)
		}
	}else{
		B.onmouseout=function(E)
		{
			hideBubbleInfo(E)
		}
	}
	
	A+="<br>";
	if(A==null||doTrim(A)=="<br>")
	{
		document.getElementById("buubleObj").style.display="none";
	}else{
		document.getElementById("buubleContent").innerHTML=A;
		document.getElementById("buubleObj").style.display="block";
	}

	var heightObj = (document.getElementById("buubleObj").clientHeight+30);
	var widthObj = document.getElementById("buubleObj").clientHeight;
	
	Mode = 'R';
	
	var classInfo = getBubbleClass(Mode,Sz);
	document.getElementById("buubleObj").className=classInfo[0];
	document.getElementById("buubleContent").className=classInfo[1];
	document.getElementById("buubleTop").className=classInfo[2];
	document.getElementById("buubleBottom").className=classInfo[3];
	//buubleObj.style.display="block";
	

	if(Mode == 'L')
	{
		var leftmask = D.offsetWidth;
		var topmask = '0';
	}else if(Mode == 'R')
	{
		var leftmask = '-'+B.width;
		var topmask = '0';
	}else if(Mode == 'T')
	{
		//var leftmask = (widthObj-((B.offsetWidth)));
		var leftmask = -30;
		var topmask = '-'+B.offsetHeight;
	}else if(Mode == 'D')
	{
		//var leftmask = (widthObj-((B.offsetWidth)/2));
		var leftmask = -30;
		var topmask = (heightObj-(B.offsetHeight+20));
	}
	positionBubble(B,leftmask,topmask)
}

function getBubbleClass(mode,Sz)
{
	var clObj = clContent = clTop = clBottom = "";
	if(mode == 'L')
	{
		clObj = "buubleObjL";
		clContent = "buubleContentL";
		clTop = "buubleTopL";
		clBottom = "buubleBottomL";
	}else if(Mode == 'R')
	{
		clObj = "buubleObjR";
		clContent = "buubleContentR";
		clTop = "buubleTopR";
		clBottom = "buubleBottomR";
	}else if(Mode == 'T')
	{
		clObj = (Sz=="Small") ? "buubleObjTSm" : "buubleObjT";
		clContent = (Sz=="Small") ? "buubleContentTSm" : "buubleContentT";
		clTop = (Sz=="Small") ? "buubleTopTSm" : "buubleTopT";
		clBottom = (Sz=="Small") ? "buubleBottomTSm" : "buubleBottomT";
	}else if(Mode == 'D')
	{
		clObj = (Sz=="Small") ? "buubleObjDSm" : "buubleObjD";
		clContent = (Sz=="Small") ? "buubleContentDSm" : "buubleContentD";
		clTop = (Sz=="Small") ? "buubleTopDSm" : "buubleTopD";
		clBottom = (Sz=="Small") ? "buubleBottomDSm" : "buubleBottomD";
	}
	return [clObj,clContent,clTop,clBottom]
}

function positionBubble(B,leftmask,topmask)
{
	if(!B)
	{
		B=currentBubbleObj
	}
	var D="";var C=0;var A=0;
	if(B)
	{
		D=" if block";
		C=(getBubbleLeftPos(B)- leftmask);
		A=(getBubbleTopPos(B)- topmask);
	}
	var E=document.getElementById("buubleContent").offsetWidth+document.getElementById("buubleTop").offsetWidth;buubleObj.style.left=C+"px";buubleObj.style.top=A+"px"
}


/* Tooltip Code Ends */




/* JQModal JS STARTS */

;(function($) {
$.fn.jqm=function(o){
var p={
overlay: 50,
overlayClass: 'jqmOverlay',
closeClass: 'jqmClose',
trigger: '.jqModal',
ajax: F,
ajaxText: '',
target: F,
modal: F,
toTop: F,
onShow: F,
onHide: F,
onLoad: F
};
return this.each(function(){if(this._jqm)return H[this._jqm].c=$.extend({},H[this._jqm].c,o);s++;this._jqm=s;
H[s]={c:$.extend(p,$.jqm.params,o),a:F,w:$(this).addClass('jqmID'+s),s:s};
if(p.trigger)$(this).jqmAddTrigger(p.trigger);
});};

$.fn.jqmAddClose=function(e){return hs(this,e,'jqmHide');};
$.fn.jqmAddTrigger=function(e){return hs(this,e,'jqmShow');};
$.fn.jqmShow=function(t){return this.each(function(){t=t||window.event;$.jqm.open(this._jqm,t);});};
$.fn.jqmHide=function(t){return this.each(function(){t=t||window.event;$.jqm.close(this._jqm,t)});};

$.jqm = {
hash:{},
open:function(s,t){ var h=H[s],c=h.c,cc='.'+c.closeClass,z=(parseInt(h.w.css('z-index'))),z=(z>0)?z:3000,o=$('<div></div>').css({height:'100%',width:'100%',position:'fixed',left:0,top:0,'z-index':z-1,opacity:c.overlay/100});if(h.a)return F;h.t=t;h.a=true;h.w.css('z-index',z);

 if(c.modal) {if(!A[0])L('bind');A.push(s);}
 else if(c.overlay > 0)h.w.jqmAddClose(o);
 else o=F;

 h.o=(o)?o.addClass(c.overlayClass).prependTo('body'):F;
 if(ie6||ie7){$('html,body').css({height:'100%',width:'100%'});if(o){o=o.css({position:'absolute'})[0];for(var y in {Top:1,Left:1})o.style.setExpression(y.toLowerCase(),"(_=(document.documentElement.scroll"+y+" || document.body.scroll"+y+"))+'px'");}}

 if(c.ajax) {var r=c.target||h.w,u=c.ajax,r=(typeof r == 'string')?$(r,h.w):$(r),u=(u.substr(0,1) == '@')?$(t).attr(u.substring(1)):u;
  r.html(c.ajaxText).load(u,function(){if(c.onLoad)c.onLoad.call(this,h);if(cc)h.w.jqmAddClose($(cc,h.w));e(h);});}
 else if(cc)h.w.jqmAddClose($(cc,h.w));

 if(c.toTop&&h.o)h.w.before('<span id="jqmP'+h.w[0]._jqm+'"></span>').insertAfter(h.o);	
 (c.onShow)?c.onShow(h):h.w.show();e(h);
 return F;
},
close:function(s){var h=H[s];if(!h.a)return F;h.a=F;
 if(A[0]){A.pop();if(!A[0])L('unbind');}
 if(h.c.toTop&&h.o)$('#jqmP'+h.w[0]._jqm).after(h.w).remove();
 if(h.c.onHide)h.c.onHide(h);else{h.w.hide();if(h.o)h.o.remove();} return F;
},
params:{}};
var s=0,H=$.jqm.hash,A=[],ie6=$.browser.msie&&($.browser.version == "6.0"),ie7=$.browser.msie&&($.browser.version == "7.0"),F=false,
i=$('<iframe src="javascript:false;document.write(\'\');" class="jqm"></iframe>').css({opacity:0}),
e=function(h){if(ie6)if(h.o)h.o.html('<p style="width:100%;height:100%"/>').prepend(i);else if(!$('iframe.jqm',h.w)[0])h.w.prepend(i); f(h);},
f=function(h){try{$(':input:visible',h.w)[0].focus();}catch(_){}},
L=function(t){$()[t]("keypress",m)[t]("keydown",m)[t]("mousedown",m);},
m=function(e){var h=H[A[A.length-1]],r=(!$(e.target).parents('.jqmID'+h.s)[0]);if(r)f(h);return !r;},
hs=function(w,t,c){return w.each(function(){var s=this._jqm;$(t).each(function() {
 if(!this[c]){this[c]=[];}this[c].push(s);});});};
})(jQuery);


//$(this).click(function(){for(var i in {jqmShow:1,jqmHide:1})for(var s in this[i])if(H[this[i][s]])H[this[i][s]].w[i](this);return F;});

/* jQModal JS Ends*/
