$(function() {
	/*$('#navigation li.has-dd').hover(function() {
		$(this).addClass('has-dd-hover');
	}, function() {
		$('.sub-menu').hide();
		$('.sub-sub-menu').hide();
		$('.main-menu').show();
		$(this).removeClass('has-dd-hover');		
		return false;		
	});*/

	// advanced usage receives configuration object only
	$("#navigation li.has-dd").hoverIntent({
		sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)
		interval: 200,   // number = milliseconds of polling interval
		over: (function() {
			$(this).addClass('has-dd-hover');
			var menuID = $(this).attr('id');
			if(menuID=="mobileMenuItem"){
				$('html, body').animate({ scrollTop: $("#navigation").offset().top }, 2000);
			}
			
		}),  // function = onMouseOver callback (required)
		timeout: 500,   // number = milliseconds delay before onMouseOut function call
		out: (function() {
			$('.sub-menu').hide();
			$('.sub-sub-menu').hide();
			$('.main-menu').show();
			$(this).removeClass('has-dd-hover');		
		})    // function = onMouseOut callback (required)
	});
	
	
	$('#navigation .dropdown .main-menu a').live('click', function() {
		var href = $(this).attr('href');
		$(this).parents('.main-menu:eq(0)').hide();
		$(href).show();
		return false;
	});
	
	$('#navigation li .dropdown .sub-menu .main-btn .return').live('click', function() {
		var sub = $(this).parents('.dropdown:eq(0)').find('.sub-menu');
		var main = $(this).parents('.dropdown:eq(0)').find('.main-menu');
		sub.hide();
		main.show();
		return false;
	});
	
	$('#navigation .dropdown .sub-menu a').live('click', function() {
		var href = $(this).attr('href');
		$(this).parents('.sub-menu:eq(0)').hide();
		$(href).show();
		return false;
	});
	
	$('#navigation li .dropdown .sub-sub-menu .sub-main-btn .sub-return').live('click', function() {
		$('.sub-sub-menu').hide();
		$('#sub-menu-shopping').show();
		return false;
	});
	
	$('#navigation li .dropdown .sub-menu .main-btn,#navigation li .dropdown .sub-sub-menu .sub-main-btn').live('click', function() {
		window.location = this.id;
		return false;
	});
	
	$('#navigation .resetmenu,.right-aligned').live('click', function() {		
		
		$('.sub-menu').hide();
		$('.sub-sub-menu').hide();
		$('.main-menu').show();
		$(this).removeClass('has-dd-hover');		
		return false;		
		/*var sub = $(this).parents('.dropdown:eq(0)').find('.sub-menu');
		if(this.className=='has-dd-hover'){
			$(this).removeClass('has-dd-hover');
			//$('.dropdown:eq(0)').hide();
		}else{
			$(this).addClass('has-dd-hover');	
			//$('.dropdown:eq(0)').show();
		}*/
		return false;
	});
	
	if(indexpage=='Index'){
	//Carousel 1 Init
	$('.slider ul').jcarousel({
		wrap: 'circular',
		animation: 750,
		scroll: 1,
		visible: 3,
    buttonPrevHTML: null
	});
}
	//blink fields
	 $('.blink').
	    focus(function() {
	        if(this.title==this.value) {
	            this.value = '';
	        }
	    }).
	    blur(function(){
	        if(this.value=='') {
	            this.value = this.title;
	        }
	    });
	
	$('#close-promo').live('click', function() {
		$('#promotionSection').slideUp(1000);
		return false;
	});
	
	if($("#newsfromdropdown").find('ul li').size()<15){
		$(".news .tab-entry ul").css("overflow-y","visible");
		$(".news .tab-entry-ar ul").css("overflow-y","visible");
	}else{
		$(".news .tab-entry ul").css("overflow-y","scroll");
		$(".news .tab-entry-ar ul").css("overflow-y","scroll");
	}

	if($("#profile_countdesc").val()==300)
		var boxsize=50;
	else
		var boxsize=164;
		
	if(($("#profile_countdesc").val()<=700)||($("#profile_countataglance").val()>3)||($("#profile_countdesc").val()==300)){
		//alert($(".profile-first-column").height()+','+$(".profile-second-column").height())
		if($(".profile-first-column").height() > $(".profile-second-column").height()){
			var x=$(".profile-second-column").height()+boxsize;
			//alert(x)
			if(x>$(".profile-first-column").height())
				$(".profile-second-column").css("height",$(".profile-first-column").height()+(($(".profile-second-column").height()+boxsize)-$(".profile-first-column").height())+'px');
			else
				$(".profile-second-column").css("height",$(".profile-first-column").height()+'px');			
		}else{
			var x=$(".profile-second-column").height()+boxsize;
			$(".profile-first-column").css("height",x+'px');		
			$(".profile-second-column").css("height",x+'px');			
		}		
	}
	
	$('.today-events .contentrowEven').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	$('.today-events .contentrowOdd').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	
	$("select").selectbox();
	
	$('#content-list ul li tr').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	$('#content-list ul li tr').live('click', function(e) {
		if($(this).find('form').attr('name'))
			$(this).find('form').submit();
		else
			window.location = $(this).find('h3 a').attr('href');
		return false;		
	});
	
	$('.rssfeeds ul li').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	$('.rssfeeds ul li').live('click', function(e) {
		var href = $(this).find('.image a').attr('href');
		window.open(href);
		return false;
	});
	
	$('.tweet-list ul li tr,.feeds-list ul li tr,.beirutFive ul li tr').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	$('#feeds-list ul li tr').live('click', function(e) {
		
		if( indexpage!='Orders' ){
			$("#ContUpdate").load("/profile.php?do=incurl&contactid="+$("#contactid").val());  
			var href = $(this).find('td a').attr('href');
			window.open(href);
			return false;
		}
	});
	
	$('.tweet-list ul li tr').live('click', function(e) {
		var href = $(this).find('td input').val();
		window.open(href);
		return false;
	});
	
	$('#subEvents ul li table tr,.beirutFive ul li tr').live('click', function(e) {
		var href = $(this).find('td a').attr('href');
		window.location =href;
		return false;
	});
	
	$('.showthewholeReview').live('click', function(e) {
		//var addname = this.id.split("_morelink");
		$(".halfReview").hide();
		$('.wholeReview').show();
		
		var x=$(".profile-second-column").height()+(($(".wholeReview").height()/3)-$(".halfReview").height()-160);
		
		$(".profile-first-column").css("height",x+'px');		
		$(".profile-second-column").css("height",x+'px');
		
		//$('#somelinks'+addname).hide();
		//$('#morelinks'+addname).show();
		e.preventDefault();
		return false;
	});
	
	$('.MoreLinks').live('click', function(e) {
			var addname = this.id.split("_morelink");
			$(this).hide();
			$('.LessLinks').show();
			$('#somelinks'+addname).hide();
			$('#morelinks'+addname).show();
			e.preventDefault();
			return false;
	});
	$('.LessLinks').live('click', function(e) {
			$(this).hide();
			$('.MoreLinks').show();
			$('#morelinks'+this.id).hide();
			$('#somelinks'+this.id).show();
			e.preventDefault();
			return false;
	});
	
	$('.MenuLinks').live('click', function(e) {
		jQuery.facebox({ ajax: '/'+ this.id+'.php?indexpage='+indexpage+'&randstyle='+randstyle })
		/*jQuery.facebox(function($) { 
			alert('/city-vistas.php?indexpage='+indexpage+'&randstyle='+randstyle);
       $.get('/city-vistas.php?indexpage='+indexpage+'&randstyle='+randstyle, function(data) { $.facebox(data) })
    });*/
  });
	
	$('#embedVideo').live('click', function(e) {
		jQuery.facebox({ ajax: '/video.php?do=embedVideo&contactid='+$("#contactid").val()+'&fbobjectID='+$("#fbobjectID").val()+'&vidTitle='+$("#vidTitle").val()+'&randstyle='+randstyle })
  		event.preventDefault();
	});
	
	$('#contactthem').live('click', function(e) {
		jQuery.facebox({ ajax: '/contactthem.php?contactid='+$("#contactid").val()+'&randstyle='+randstyle })
  		event.preventDefault();
	});
	
	$('#contactsales').live('click', function(e) {
		jQuery.facebox({ ajax: '/contactsales.php?contactid='+$("#contactid").val()+'&randstyle='+randstyle })
  		event.preventDefault();
	});
	
	$('#sendtophonebtn').live('click', function(e) {
		$('.reviews-row').hide();
		$('#send_fielddiv').show();
		e.preventDefault();
	});	
	
	$(".sendtophone form .field").focus(function() { 
		$(this).val('');   
    }).blur(function() {
        if($(this).val()==''){
					var recomend=$('#recomend').val();
					if(!recomend)recomend=0;
				if(recomend>0)
					$(this).val("Your Friend's email");
				else
					$(this).val("Your phone's email");
			}					
		});
	
	$('#sendemaillink').live('click', function(e) {
		var emailaddress=$('.sendtophone form .field').val();
		if((emailaddress=='')||(emailaddress=="Your phone's email")||(emailaddress=="Your Friend's email")){
			alert("Please enter your phone's email!");
			$('.sendtophone form .field').focus();
			return false;
		}else if( !isValidEmailAddress(emailaddress)){
				alert("Please enter a valid email address!");
			$('.sendtophone form .field').focus();
			return false;
		}
		var recomend=$('#recomend').val();
		if(!recomend)recomend=0;
		$('#firstemail').val(emailaddress);
		$("#SendPhone_divaction").html('<img src="http://cdn.beirut.com/images/loaders/small/'+randstyle+'-ajax-loader.gif"/>');
		$("#SendPhone_divaction").load("/landingmobile.php?do=sendemail&emailaddress="+emailaddress+'&recomend='+recomend+'&firstemail='+emailaddress);
		e.preventDefault();
	});	
	
	$(".newurl").live('click', function (event) {
		//jQuery.facebox({ ajax: '/socialfbox.php?indexpage='+indexpage+'&randstyle='+randstyle+'&url='+this.id })
		$("#ContUpdate").load("/profile.php?do=incurl&contactid="+$("#contactid").val());  
		window.open(this.href);
		event.preventDefault();
	});

	if(initfacebox==1){
		jQuery.facebox({ ajax: '/slideshow.php?contactid='+contactid+'&type=event'})
	}
	
	if(showfacebox){
	 		jQuery.facebox({ ajax: '/'+showfacebox+'.php?randstyle='+randstyle})
	}

	$('.today-events ul li tr').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	});
	
	$('.today-events ul li tr').live('click', function(e) {
		var href = $(this).find('td a').attr('href');
		window.location = href;
	});
	
	$('.profile-first-info ul:odd, .profile-second-info ul:odd, .profile-nearby ul:odd, .rssfeeds ul:odd, .tweet-list ul:odd,.beirutFive ul:odd').addClass('odd');
	
	$('.profile-commentbox .comment-list ul li').hover(function() {
		$(this).addClass('hover');
	}, function() {
		$(this).removeClass('hover');
	})
	
	
	$('.tabs-nav ul li a').live('click', function () { 
		var href = $(this).attr('href');
		$('.tabs-nav ul li a').removeClass('active');
		$(this).addClass('active');
		$('.tab-cnt .all-tabs').hide();
		if(href=="#tab-cnt6"){
			$("#tab-cnt6").find('.tabs-content').html("<iframe src='http://widget.mibbit.com/?settings=e0a9bec7b4ef9587194b15120b4f7c83&server=us.beirut.com&channel=%23beirut&noServerMotd=true&autoConnect=true&nick=Beir_%3F%3F%3F%3F' width='760' height='555' frameborder='0'></iframe>")
		}
		if(href=="#tab-cnt3"){
			var currHtml = $("#tab-cnt3").html();
			$("#tab-cnt3").html( currHtml +'<iframe src="http://www.facebook.com/plugins/likebox.php?id=111217515558400&amp;width=760&amp;connections=26&amp;stream=true&amp;header=false&amp;height=555" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:760px; height:555px;" allowTransparency="true"></iframe>')
		}
		$(href).show();
  	//$('html, body').animate({ scrollTop: $(".tabs-nav").offset().top }, 2000);	
		return false;
	});

	$('a[rel*=facebox]').facebox();
	
	
	$(document).bind('reveal.facebox', function(){ 
		//$('#facebox').draggable(); 
  }) 

	default_src = $('.big-show a img').attr('src');
	

   $("#index li a").live('click', function (event) { 
     $('#index li a').removeClass('active');
     $(this).addClass('active');
   });
   $("#popupul  li a").live('click', function (event) { 
     $('#popupul li a').removeClass('active');
     $(this).addClass('active');
   });
		//goforit();
		//getthedate();
		
		$("#next-btn").click(function(event){
				//$("#calcnt").hide().fadeIn(1000);
				$("#calcnt").load(this.href);  
				//$("#calcnt").show().fadeIn(1000);
		    event.preventDefault();
	   });
	  $("#prev-btn").click(function(event){
	   	//$("#calcnt").hide().fadeIn(1000);
	    $("#calcnt").load(this.href);
	    //$("#calcnt").show().fadeIn(1000);
	     event.preventDefault();
	   });
	   $(".month-list .selected").click(function(event){
	    $(this).attr("class","selected clicked");
	    ajaxloader('#ContentDiv','big',$("#randstyle").val());
	    $("#ContentDiv").load(this.href);
	     event.preventDefault();
	   });

	$('#searchf').submit(function(event) {
		$("#ContentDiv").load('events.php', { 'do': "search",  search: $("#search").val(),  search_text: $("#search_text").val(),  EventType: $("#EventType").val(),  AreaID: $("#AreaID").val() ,  StartDates: $("#StartDates").val(),  reccnt: $("#reccnt").val(),  next: $("#next").val() } )
	  event.preventDefault();
	});
	
	$('#SaveInfo').live('click', function (event) {
		var deactpicval,fblinkval,disbalepageval;
		if($("#deactpic").attr('checked')){
			deactpicval=1;
		}else{ 
			deactpicval=0;
		}
		if($("#fblink").attr('checked')){
			fblinkval=1;
		}else{ 
			fblinkval=0;
		}
		if($("#disbalepage").attr('checked')){
			disbalepageval=1;
		}else{
			disbalepageval=0;
		}
		$("#vistas-popup").load('/fb-settings.php', { 'do': "save",  fblink: fblinkval,  deactpic: deactpicval,  disbalepage: disbalepageval,  fbname: $("#fbname").val() } );
		jQuery(document).trigger('close.facebox');
	  event.preventDefault();
	});
	
	$(".maplink").live('click', function (event) {
		//s. zanzo
		$("a").removeClass("active");		
		$(this).addClass("active");		
		//e. zanzo
		
		$("#g-image").attr('src',this.href)
		$("#FullMapLink").attr('href',"map-pop.php?"+this.id)
	  event.preventDefault();
	});

	$('.showinline').live('click', function (event) { 
		//$('#mainpicdiv').css("background-image", "url(http://cdn.beirut.com/css/images/loading.gif) no-repeat 10px 168px;");
		
		var temp = this.href.split("x");

		var old_imgheight=$("#mainlinkPic").height();
		var new_imgheight=temp[1];
		if((old_imgheight>new_imgheight) && (old_imgheight>350)){
			$(".profile-first-column").css("height",($(".profile-first-column").height()-234)+'px');			
			$(".profile-second-column").css("height",($(".profile-second-column").height()-234)+'px');			
		}else if(old_imgheight<new_imgheight){
			$(".profile-first-column").css("height",($(".profile-first-column").height()+234)+'px');			
			$(".profile-second-column").css("height",($(".profile-second-column").height()+234)+'px');			
		}		
		$('#mainlinkPic').attr('src',this.href);
		$('#mainlinkPic').attr('height',temp[1]);
		
		event.preventDefault();
	});
	
	
	$('#CommentGo').live('click', function (event) { 
		$('.hiddenform').toggle();
		event.preventDefault();
	});
	
	$('.row .comment-list p a').live('click', function (event) { 
		$('.comment-list').load(this.href)
		event.preventDefault();
	});
	
	$('#printgmap').live('click', function (event) { 
		printSpecial('map');
		event.preventDefault();
	});
	
	var refreshId = setInterval(function(){
		$('#alertcont p span').fadeOut("slow");
		$('#alertcont p span').load('random_alerts.php', function() {
		  $('#alertcont p span').fadeIn("slow");
		});
	}, 10000);
	
	////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////// Floating Banner Call //////////////////////////////////////
	////////////////////////////////////////////////////////////////////////////////////////////////
	 $('#Flaotbanner').floatingbanner(); 
	////////////////////////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////// Floating Banner end //////////////////////////////////////
	////////////////////////////////////////////////////////////////////////////////////////////////
	var query=$('#singleBirdRemote').val();
	$('#singleBirdRemote').click(function() {
		$(this).attr('value','');
	});
	
	$('#singleBirdRemote').blur(function() {
	  $(this).attr('value',query);
	});

	var default_text='Write a comment...';
	$('#review_text').click(function() {
		
		$(this).attr('value','');
		$(this).css('height','150px');
		$('.button_add_ReviewBox').show();
		
	});	
	$('#review_text').blur(function() {
		  if($('#review_text').val()==''){
		  	$(this).attr('value',default_text);
		  }
		  
		  if($('#review_text').val()==default_text){
		  	$(this).css('height','20px');
	  		$('.button_add_ReviewBox').hide();
		  }  
	  	
	});


	$("#orderform").change(function(event){
		var Types=get_VisibleTypes();
	  load_pageresults(Types,$("#randstyle").val());
	  //var Types=get_VisibleTypes();			
		//$("#ContentDiv").load($("#indexpage").val(), { 'do': "search",  search: 1,  AreaID: $("#AreaID").val() ,  ContactType: $("#ContactType").val(), ContactTypeName: $("#ContactTypeName").val(),  showby: $("#showby").val() ,  Types: Types   } ) 
		event.preventDefault();
	});
	
	
	$("#Branch_Dropdown").change(function(event){
		$(".B_infoClass").hide();
		var parameters=$("#Branch_Dropdown").val();
		//alert(parameters)
		
		parameters=parameters.split(",");
		//$("#Binfo_"+parameters).show();
		document.getElementById("Binfo_"+parameters[1]).style.display='';
		
		//Map Code Start here
		//$('html, body').animate({ scrollTop: $("#gmap-section").offset().top }, 2000);
		//Reload map
		loadmap(parameters[0],parameters[1],parameters[2]);
		
		//Reload nearby 
		ajaxloader('#nearbycontacts','big',$("#randstyle").val());			
		$("#nearbycontacts").load('profile.php', { 'do': "changenearby", 'contactid': parameters[0], 'longitude':parameters[3], 'latitude':parameters[4] } )

		ajaxloader('#dataSet','small',$("#randstyle").val());
		$("#dataSet").load('profile.php', { 'do': "changenearby_dataSet", 'contactid': parameters[0], 'longitude':parameters[3], 'latitude':parameters[4] } )


		//Map Code Ends here

		event.preventDefault();
	});
	
	$(".focusmap").click(function(event){
		$('html, body').animate({ scrollTop: $("#gmap-section").offset().top }, 2000);
		var parameters=this.id;
		parameters=parameters.split(",");		
		
		//Reload map
		loadmap(parameters[0],parameters[1],parameters[2]);
		
		//Reload nearby 
		ajaxloader('#nearbycontacts','big',$("#randstyle").val());			
		$("#nearbycontacts").load('profile.php', { 'do': "changenearby", 'contactid': parameters[0], 'contacttypeid':parameters[3], 'Branchid':parameters[1], 'areaName':parameters[4], 'type':parameters[2] } )

		//Map Code Ends here
		/*$('.mapfoclink').html('');
			
		var classname='.mapfoclink';
		for(var i=0;i<$(classname).length;i++){
			$(classname)[i].id	
	}*/
	
		event.preventDefault();
	});
	
	

	$("#AreaID").change(function(event){
	 //if(($("#AreaID").val()!= 'null')&&($("#AreaID").val()!= '')){
	 if($("#AreaID").val()!= 'null'){
	  var Types=get_VisibleTypes();
	  load_pageresults(Types,$("#randstyle").val());	 
	}
	 event.preventDefault();
	});	

	$("#showbyQuest").change(function(event){
		if(($("#showbyQuest").val()!= 'null')&&($("#showbyQuest").val()!= '')){
			$("#QuestionsBlock").load('/news_Load_engine.php', { 'do': "getAnswers",  query: $("#showbyQuest").val() } )
			/*var results="&nbsp;&nbsp;";
			if($("#from").val()!=0)
			var results="Showing "+ $("#from").val() +" - "+ $("#to").val() + " of "+ $("#of").val() +"";	
			$('#showResults').html(results);
			*/
 
		}
		event.preventDefault();
	});



	$("#showby").change(function(event){
		if($("#showby").val()!= 'null'){
			if($("#indexpage").val()=='RealEstate'){
				if($("#showby").val()=='No/Yes'){
					$('#PriceRange').css('visibility', 'hidden') ;
				}else	{
					$('#PriceRange').css('visibility', 'visible') ;
					
					if($("#showby").val()=='No'){ //Buy
						$('#BuyPriceRange').css('visibility', 'visible');
						$('#RentPriceRange').css('visibility', 'hidden'); 
					}else if($("#showby").val()=='Yes'){ //Rent		
						$('#BuyPriceRange').css('visibility', 'hidden');
						$('#RentPriceRange').css('visibility', 'visible');
					}					
				}
			}
			
			var Types=get_VisibleTypes();
		  load_pageresults(Types,$("#randstyle").val(),0,"showby");
		}
		event.preventDefault();
		
	});
	$("#filterby").change(function(event){
		if($("#filterby").val()!= 'null'){
		ajaxloader('#ContentDiv','big',randstyle);
			$("#ContentDiv").load($("#indexpage").val(), { 'do': "search",'search':'1' , filterby: $("#filterby").val(), rord: $("#rord").val(),  userid: $("#userid").val(), username: $("#username").val()} )
		}
		event.preventDefault();
		
	});
	$("#CommentsLink").live('click', function(event) {
	  ajaxloader('#ContentDiv','big',randstyle);
		$("#ContentDiv").load($("#indexpage").val(), { 'do': "search",'search':'1' , filterby: "comments&desc", rord: "desc",  userid: $("#userid").val(), username: $("#username").val()} )
		event.preventDefault();
	});
	
	

	$("#LikesLink").live('click', function(event) {
	  ajaxloader('#ContentDiv','big',randstyle);
		$("#ContentDiv").load($("#indexpage").val(), { 'do': "search",'search':'1' , filterby: "likes&desc", rord: "desc",  userid: $("#userid").val(), username: $("#username").val()} )
		event.preventDefault();
		
	});
	
	$("#widgetsize,.radial").change(function(event){
		var widgettype = jQuery('.radialdiv input:radio:checked').val();  	
		ajaxloader('.displaycode','small',randstyle);
		$("#grabcode").attr('href',"/Webmaster-Tools?do=dograbcode&widgetsize="+$("#widgetsize").val()+"&widgettype="+widgettype);		
		$(".displaycode").load('/Webmaster-Tools', { 'do': 'showpreview',widgetsize:$("#widgetsize").val(),widgettype:widgettype } )	  	
		event.preventDefault();		
	});

	
	$("#SubTypes").change(function(event){
		if($(this).val()!= 'null'){
			var Types=get_VisibleTypes();			
		  	load_pageresults(Types,$("#randstyle").val(),'','SubTypes');
		}
		event.preventDefault();
	});
	
	$("#SubTypes1").change(function(event){
		if($(this).val()!= 'null'){			
			
			var Types=get_VisibleTypes();
			var SubTypes=$("#SubTypes1").val();
	
			ajaxloader('#ContentDiv','big',$("#randstyle").val());
			
			$("#ContentDiv").load($("#indexpage").val(), { 'do': 'search','search': 1, AreaID: $("#AreaID").val(),  showby: $("#showby").val(),SubTypes: SubTypes, Types: Types, ContactType: $("#ContactType").val(), ContactTypeName: $("#ContactTypeName").val() } )   		
		}
		event.preventDefault();
	});
	
	
	$(".daylink").click(function(event) {
		
		if(this.className=='daylink'){
				var classname='a.checked';
				for(var i=0;i<$(classname).length;i++){
					$("#"+$(classname)[i].id).attr("class","daylink");	
				}
				$(this).attr("class","daylink checked");	
			}else{
				$(this).attr("class","daylink");
			}
		
		
		
			
		var Types=get_VisibleTypes();
		ajaxloader('#ContentDiv','big',$("#randstyle").val());
		$("#ContentDiv").load('/'+indexpage, { 'do': "search",'search': 1, AreaID: $("#AreaID").val(),  showby: this.id, calsearchdate: $("#calsearchdate").val(), Types: Types,SubTypes: $("#SubTypes").val()} )			
	
  	
  	Change_Ad("a8c465c4");//change leaderboard ad
  	Change_Ad("a2bb8a70");//change wide skyscraper ad
		event.preventDefault();
	});	
	

	$(".alink").click(function(event) {
		var indexpage=$("#indexpage").val();
		
		//if(indexpage!='Beirut')$('html, body').animate({ scrollTop: $(".vistas").offset().top }, 2000);
		if((indexpage=='JustForKids')||(indexpage=='Beirut'))disable_allselected();

		if(this.className=='alink'){//if($(this).hasClass('alink selected')) 
			$(this).attr("class","alink selected");	
		}else{
			$(this).attr("class","alink");
		}

		var Types=get_VisibleTypes();


		if((indexpage=='Events') && ((Types == 17)||(Types == 6))){
			 $('#SubTypesdiv').css('visibility', 'visible') ; 
		}else{
		 	$('#SubTypesdiv').css('visibility', 'hidden') ; 
		}
		
		if(((indexpage=='HealthCare') && (Types == '2'))||(indexpage=='Advertising'))
			 $('#ClinicType').css('visibility', 'visible') ; 
		else
		 	$('#ClinicType').css('visibility', 'hidden') ; 

		if((indexpage=='Restaurants') && (Types == '1'))
			 //$('#CuisineType').show();
			 $('#CuisineType').css('visibility', 'visible') ; 
			 
		else
			$('#CuisineType').css('visibility', 'hidden') ; 
		 	//$('#CuisineType').hide();	

		if((indexpage=='Shopping')&& ($("#subvistas").val()!=1)){
			 var types = this.id.split(",");
			 if(types.length > 1){
					ajaxloader('#newvistas','small',randstyle);			
					$("#newvistas").load('/'+indexpage, { loadsubtypes: 1,indexpage:indexpage,categoryname:this.name,  Types: this.id } )	  	
			}
		}

				
		load_pageresults(this.id,$("#randstyle").val(),'','alink');
		
		event.preventDefault();
	});		
	 
	 $(".PopUpLink,.PopUpLink selected").click(function(event) {
	 	$("#MainVistas").hide();
	 	$('#Sub_Vistas').html('<p align="center"><img src="http://cdn.beirut.com/images/loaders/'+'big'+'/'+randstyle+'-ajax-loader.gif"/></p>');		
	 	$("#Sub_Vistas").load("/vistas_nav.php", {indexpage:this.id,rowtitle:$(this).html(),randstyle:randstyle, "do":"ShowSub"})
	 	event.preventDefault();
	 });		
	 $("#gobacklinkshow").click(function(event) {
	 	$("#MainVistas").show();
	 	$("#Sub_Vistas").load("/vistas_nav.php",{"do":"empty"});
	 	event.preventDefault();
	 });		
	 $(".ShoppingLink").click(function(event) {
	 	$("#Sub_Vistas").hide();
	 	//alert(this.id)
	 	$("#Sub_Sub_Vistas").load("/vistas_nav.php", {"indexpage":"Shopping",rowtitle:$(this).html(),Types:this.id,randstyle:randstyle, "do":"ShowSubSub"})
	 	event.preventDefault();
	 });		
	 
	 $("#gobacklinkshowShoppingLink").click(function(event) {
	 	$("#Sub_Vistas").show();
	 	$("#Sub_Sub_Vistas").load("/vistas_nav.php",{"do":"empty"});
	 	event.preventDefault();
	 });		
	 
	 $("#selectall").click(function() {
	 	//$('html, body').animate({ scrollTop: $(".vistas").offset().top }, 2000);
		$('#subtypes ul li a').attr("class","alink selected");
		$('#subtypes ul li.nocheck a').attr("class","");
		var Types=get_VisibleTypes();

	  load_pageresults(Types,$("#randstyle").val(),'notypes');
	});		

	$("#selectnone").click(function() {
		//$('html, body').animate({ scrollTop: $(".vistas").offset().top }, 2000);

		$('#subtypes ul li a').attr("class","alink");		
		var Types=get_VisibleTypes();
	  load_pageresults(Types,$("#randstyle").val());
	});	
	
	$("#gobacklink").click(function() {	
		//$('html, body').animate({ scrollTop: $(".vistas").offset().top }, 2000);
		ajaxloader('#newvistas','small',$("#randstyle").val());			
		$("#newvistas").load($("#indexpage").val(), {GoBack:1,indexpage:$("#indexpage").val(),randstyle:$("#randstyle").val() } )	  	
		
	
	});	
	
	$("#backlink").click(function() {	
		ajaxloader('#newvistas','small',randstyle);			
		var indexpageA = indexpage.split("/");
		indexpage = indexpageA[0];
		$("#newvistas").load(indexpage, {GoBack:1,indexpage:indexpage,randstyle:randstyle } )	  				
	});	
	
	
	
	$(".upcomingdates").click(function() {	
		ajaxloader('#displayevents','big','green');
		
		$("#displayevents").load('/Index', { 'do':'searchevents','sdate':this.id } )	 		
		
	});	
	
	$("input[name=listType]").click(function(){
 
		if(this.value=='Event'){
			
				$('#moreinfo_tbl').css('visibility', 'visible') ;
				$('#NameBusiness').css('display', 'none') ;
				$('#NameNews').css('display', 'none') ;
				$('#NameEvent').css('display', '') ;
				$('#DetailsBusiness').css('display', 'none') ;
				$('#DetailsNews').css('display', 'none') ;
				$('#DetailsEvent').css('display', '') ;
				$('#Type_Business').css('visibility', 'hidden') ;
				$('#Type_Event').css('visibility', 'visible') ;
				$('#uploadpic_tr').css('display', '') ;
			}else if(this.value=='Business'){
				$('#moreinfo_tbl').css('visibility', 'visible') ;
				$('#NameBusiness').css('display', '') ;
				$('#NameEvent').css('display', 'none') ;
				$('#NameNews').css('display', 'none') 
				$('#DetailsBusiness').css('display', '') ;
				$('#DetailsEvent').css('display', 'none') ;
				$('#DetailsNews').css('display', 'none') ;
				$('#Type_Business').css('visibility', 'visible') ;
				$('#Type_Event').css('visibility', 'hidden') ;
				$('#uploadpic_tr').css('display', '') ;
			}else if(this.value=='News'){
				$('#moreinfo_tbl').css('visibility', 'visible') ;
				$('#NameBusiness').css('display', 'none') ;
				$('#NameEvent').css('display', 'none') ;
				$('#NameNews').css('display', '') ;
				$('#DetailsBusiness').css('display', 'none') ;
				$('#DetailsEvent').css('display', 'none') ;
				$('#DetailsNews').css('display', '') ;
				$('#Type_Business').css('visibility', 'hidden') ;
				$('#Type_Event').css('visibility', 'hidden') ;
				$('#uploadpic_tr').css('display', 'none') ;
			}else{
				$('#moreinfo_tbl').css('visibility', 'hidden') ;			
			}
		
	});
	
	
	$("#submitlisting").click(function(e) {
		
		//type
		var listingtype=$("input[@name='name']:checked").val();
		
		if($("#t_name").val()==''){
			if(listingtype=='News')
				alert('Please enter News Source Name!');
			else
				alert('Please enter '+listingtype+' Name!');
			$("#t_name").focus();
			return false;
		}
		
		if($("#t_details").val()==''){
			alert('Please enter '+listingtype+' Details!');
			$("#t_details").focus();
			return false;
		}
		
		
		if(listingtype=='Event'){
			if($("#t_etype").val()==''){
				alert('Please select event type!');
				$("#t_etype").focus();
				return false;
			}	
		}else if(listingtype=='Business'){
			if($("#t_btype").val()==''){
				alert('Please select business type!');
				$("#t_btype").focus();
				return false;
			}				
		}
					
			
		if($("#t_email").val()==''){
			alert('Please enter Your Email address!');
			$("#t_email").focus();
			return false;
		}else if( !isValidEmailAddress($("#t_email").val())){
				alert("Please enter a valid email address!");
			$('#t_email').focus();
			return false;
		}
		
		if($("#t_phonenumber").val()==''){
			alert('Please enter Your Phone Number!');
			$("#t_phonenumber").focus();
			return false;
		}	
		
		$('#submit_listingfrm').submit();
		
			e.preventDefault();
			return false;
	});
	
/*Search new start*/
	function formatItem(row) {
		if(row[2]){
			return "<img src='"+row[2]+"'>"+row[0]+"<br>"+row[3];
		}else{
			return row[0];
		}
	}
	function formatResult(row){
		return row[0].replace(/(<.+?>)/gi, '');
	}
	
	function getUrlVars(href){ 
		
    var vars = [], hash; 
    
    var specialhashes = href.slice(href.indexOf('?') + 1).split('url='); 
    thisurl=specialhashes[1];
    var hashes = href.slice(href.indexOf('?') + 1).split('&'); 
    
    for(var i = 0; i < hashes.length; i++) { 
        var parmname=hashes[i].substring(0,hashes[i].indexOf('='));
        var parmvalue=hashes[i].substring(hashes[i].indexOf('=') + 1,hashes[i].length);
        
        vars.push(parmname);
        if(parmname=="url"){
        	vars[parmname] = thisurl; 
        }else{
        	vars[parmname] = parmvalue; 
        }
    } 
    return vars; 
	}
	
	$("#singleBirdRemote").autocomplete("/lookup.php", {
		scrollHeight:323,
		selectFirst: false,
		formatItem: formatItem
		
	});
		
	$("#singleBirdRemote").result(function(event, data, formatted) {
	
	stringValue = data[1];
	if( stringValue.indexOf("yellowpages.com.lb") == -1){
		$(this).parent().next().find("input").val(data[1]);
		window.location=data[1];			
	}else{
		var OpenWindow=window.open(data[1],"logwindow",'left=100,top=100,height=500,width=600,scrollbars=yes,toolbar=0,resizable=,addressbar=0');
		OpenWindow.focus();
	}
							
		
	});
	
	
	
	$("#clear").click(function() {
		$(":input").unautocomplete();
	});
/*Search new ends*/

	$(".plink").click(function(event) {
			ajaxloader('#ContentDiv','big',$("#randstyle").val());
			if($("#indexpage").val()=='User'){
				$("#ContentDiv").load($("#indexpage").val(), { 'do': "nav",'next': this.id,'search':'1' , filterby: $("#filterby").val(), rord: $("#rord").val(),  userid: $("#userid").val(), username: $("#username").val()} )
			}else{
				var Types=get_VisibleTypes();			
				$("#ContentDiv").load($("#indexpage").val(), { 'do': "nav",'next': this.id,'search':'1' , AreaID: $("#AreaID").val(), calsearchdate: $("#calsearchdate").val(),  showby: $("#showby").val(), Types: Types,  SubTypes: $("#SubTypes").val(), ContactType: $("#ContactType").val(), ContactTypeName: $("#ContactTypeName").val() } )
			}
			
		Change_Ad("a8c465c4");//change leaderboard ad
  		Change_Ad("a2bb8a70");//change wide skyscraper ad
	});	
	
	
	$(".rssplink").click(function(event) {
			ajaxloader('#feedslistdiv','big',$("#randstyle").val());
			$("#feedslistdiv").load('profile.php', { 'do': "nav",'next': this.id, contactid: $("#contactid").val()} )
			return false;
	});	

	
	$('.go-btn3').live('click', function(event) {		
		ajaxloader('.typeadv','big',randstyle);
		$(".typeadv").load('/Advertising', { level: 1, action: $(this).attr('id') } )						
		event.preventDefault();
	});
	
		$('.visitlink').live('click', function(event) {		
		window.location = this.href;		
		event.preventDefault();
	});
	
	$("#moreinfo_subButton").live('click', function(event) {
		var randstyle=$("#randstyle").val();
		var contactid=$("#contactid").val();
		var t_fname=$("#t_fname").val();
		var t_email=$("#t_email").val();
		var t_phone=$("#t_phone").val();
		var t_comments=$("#t_comments").val();
		var pagename=$("#pagename").val();
		
		if(t_fname==''){
			alert('Please enter your name!');
			$("#t_fname").focus();
			return false;
		}
		if(t_email==''){
			alert('Please enter your email address!');
			$("#t_email").focus();
			return false;
		}else if( !isValidEmailAddress(t_email)){
				alert("Please enter a valid email address!");
			$('#t_email').focus();
			return false;
		}

		/*if(t_phone==''){
			alert('Please enter your phone number!');
			$("#t_phone").focus();
			return false;
		}*/
		
		if(t_comments==''){
			alert('Please enter your comment!');
			$("#t_comments").focus();
			return false;
		}		
		
	  $("#havemoreinfo").html('<p align="center" style="width:600px;height:150px;"><br><BR><BR><img src="http://cdn.beirut.com/images/loaders/big/'+$("#randstyle").val()+'-ajax-loader.gif"/></p>');
		$("#havemoreinfo").load(pagename, { 'do': 'sendEmail','contactid':contactid,'t_fname':t_fname,'t_email':t_email,'t_phone':t_phone,'t_comments':t_comments} );
		
		event.preventDefault();
	});
	
	
		var col = $('#ul0');

		if(!isNaN(col.outerHeight())){
		        commheight=parseInt(col.outerHeight());
		        $('#side-a').css({ 'height': commheight + 'px' });
		        $('#comments').css({ 'height': (commheight - 43) + 'px' });
	
		}
	
	
		$(".reviews-row p .raiting-btn.yes").live('click', function (event) {
	          if(this.id=='novote'){
	                alert("You have already rated this!");
	          }else{
	                $(".reviews-row").load(this.href,{'do':"vote" , voteval:1});
	          }
	           event.preventDefault();
	        });
	
	       
	$(".deleteReview").live('click', function (event) {
		var reviewInfo=this.id.split('_');
		$("#Review_"+reviewInfo[0]).load($("#gotopage").val(),{'do':"deleteReview",reviewID:reviewInfo[0],contactid:reviewInfo[1]});
		$("#Review_"+reviewInfo[0]).hide();
		event.preventDefault();
	});
	  
	$('#RatingAllowed').live('click', function (event) {
		
		$("#ratingValue_div").load('/profile.php', { 'do': "refreshRating",'action':'add',contactid: $("#contactid").val() } )                		
	  	event.preventDefault();
	});
	
	$('#noRating').live('click', function (event) {
		alert("You already have a rating.");
	  	event.preventDefault();
	});
		
	$('.addNewReview').live('click', function (event) {
	      
	       if ( $("#review_text").val().length > 500){
	                alert("You can not post a comment with more than 500 characters");
	                return false;
	        }
	
	        if ($("#review_text").val()== '' && $("#thankscomment").is(':visible')){
	               $("#thankscomment").toggle();
	               $('.hiddenform').toggle();
	               return false;
	        }
	        if ($("#review_text").val()== 'Write a comment...' ){
	               return false;
	        }
	
	        if ($("#comments").val()== '') return false;
        	$("#ReviewsBox_div").load('/profile.php', { 'do': "postReview",  review_text: $("#review_text").val(),contactid: $("#contactid").val() } )
                $("#ratingValue_div").load('/profile.php', { 'do': "refreshRating",contactid: $("#contactid").val() } )                			  	
                $('#review_text').attr('value','');
                $('.hiddenform').toggle();
                $("#thankscomment").show();
                $("#submitcomment").html("Submit another comment");
                $("#start").attr('value','1' );
                var col = $('#ul0');
                if(!isNaN(col.outerHeight())){
                        commheight=parseInt(col.outerHeight());
                        $('#side-a').css({ 'height': commheight + 'px' });
                        $('#comments').css({ 'height': (commheight - 43) + 'px' });
                }
                event.preventDefault();
	});
	
	
	$(".PostNewReview").click(function(event){
		if ( $("#review_text").val().length > 500){
	                alert("You can not post a comment with more than 500 characters");
	                return false;
	        }
	        if ($("#review_text").val()== '' && $("#thankscomment").is(':visible')){
	               $("#thankscomment").toggle();
	               $('.hiddenform').toggle();
	               return false;
	        }
	        
	        try{
	        	if ($('#postToFBComm').attr('checked')){
	        	var params = {};
	        	params['message'] = $("#review_text").val();
			params['name'] = postToFBCaption;
			params['description'] = postToFDescr;
			params['link'] = postToFBLink;
			params['picture'] = postToFBPhoto;
			params['caption'] = 'www.beirut.com';//postToFBCaption
			FB.api('/me/feed', 'post', params, function(response) {
			if (!response || response.error) {
				//alert('Error occured');
			}else{
				alert('Review posted to your Facebook wall!');
			}
			});
        	}
	        }catch(e){
	        }
        	$("#ReviewsBox_div").load($("#gotopage").val(), { 'do': "postReview",  review_text: $("#review_text").val(),contactid: $("#contactid").val(),photoid: $("#photoid").val(),fbobjectID: $("#fbobjectID").val() } )
        	
        	//$('.hiddenform').toggle();
                $('#review_text').attr('value',default_text);
		$('#review_text').css('height','20px');
	  	$('.button_add_ReviewBox').hide();
	  	event.preventDefault();
	});
	
	$('.PostNewLike').live('click', function (event) {
		
		$("#LikeBox_div").load($("#gotopage").val(), { 'do': "likeObject",'ajaxCall' : '1',contactid: $("#contactid").val(),photoid: $("#photoid").val(),fbobjectID: $("#fbobjectID").val() } )
                event.preventDefault();
	});
	
	$(".showmore-btn").click(function(event){
			var temp = this.id.split("_link_");
			var actiondiv=temp[0];
			ajaxloader('#'+actiondiv,'small',randstyle);
			$("#"+actiondiv).load($("#gotopage").val(),{'do':'showmore',start:temp[1],contactid: $("#contactid").val(),fbobjectID: $("#fbobjectID").val(),photoid: $("#photoid").val()});
	    return false;
	    event.preventDefault();
	});
	
	$("#navigatePrev").click(function(event){
		change_photo(this.href,$("#randstyle").val());
		event.preventDefault();
	});
	
	$("#navigateNext").click(function(event){
		change_photo(this.href,$("#randstyle").val());
		event.preventDefault();
	});
	
	$("#navigateImg").click(function(event){
		change_photo(this.href,$("#randstyle").val());
		event.preventDefault();
	});
	
	$(document).keyup(function(e){
	    if (e.keyCode == 37) { 
	     if($(".navigate").find('#navigatePrev')){
	    		var gotoaddress=$("#navigatePrev").attr('href');
				alert(gotoaddress)
	    		if(gotoaddress)
	    			change_photo(gotoaddress,$("#randstyle").val());
		}
	       e.preventDefault();
	       return false;
	    }
	    
	    if (e.keyCode == 39) { 
	    	if($(".navigate").find('#navigateNext')){
	    		var gotoaddress=$("#navigateNext").attr('href');
	    		if(gotoaddress)
	    			change_photo(gotoaddress,$("#randstyle").val());
		}
		e.preventDefault();
	       return false;
	    }
	});
	
	$(".printmenu").live('click', function(e) {
	 	$(".infodetails").print();
	  e.preventDefault();
	});		
	
});

function change_photo(objhref,randstyle){
	$('html, body').animate({ scrollTop: $(".album-data").offset().top }, 2000);
	var parameters = objhref.split("/");
	ajaxloader('#photoalbum-content','big',randstyle);		
	$('#photoalbum-content').load('/photo.php',{'do':'changePhoto','ajaxCall' : '1',albumid: parameters[4],photoid: parameters[5],indx: parameters[6],randstyle: randstyle});		
	Change_Ad("a8c465c4");//change leaderboard ad
  	Change_Ad("a2bb8a70");//change wide skyscraper ad	    
	return false;	
}
function setNavigation() {
	var nav_width = $('#navigation').width();
	var ul_width = $('#navigation .nav-ul').width();
	var search_width = $('#navigation #search .small-formmenu').outerWidth() - parseInt(nav_width - ul_width);
	console.log(search_width);
	$('#navigation #search').css('width', search_width);
}

function pageLoaded() {
	$('#navigation li').each(function() {
		if ($(this).find('.dropdown').length) {
			$(this).addClass('has-dd');
		};
	});
	var width = parseInt($('#navigation').width()) - parseInt($('#navigation > ul').width());
	$('#navigation > ul').css('padding-left', width);
	$('#search').css('width', width - 10);
}

function get_VisibleTypes() {
	var Types='';
	
	var classname='a.selected';
	for(var i=0;i<$(classname).length;i++){
		if($(classname)[i].id)
			Types +=$(classname)[i].id+",";			
	}
	if(Types)Types = Types.slice(0,Types.length-1); 
	
	if((Types=='')&& ($("#subvistas").val()==1))
		Types=$("#Types").val();

	return Types;
}

function disable_allselected() {
	$('#subtypes ul li a').attr("class","alink");	
}

function load_pageresults(displaytypes,schemecolor,notypes,submitter) {
	
	var Types='';
	var indexpage=get_pagename();
	
	var indexpageA = indexpage.split("/");
	indexpage = indexpageA[0];
	
	if(($("#indexpage").val()!='Beirut')&&(notypes!='notypes'))
		Types=get_VisibleTypes();
	
	if(($("#indexpage").val()=='Shopping')&& ($("#subvistas").val()!=1))
		Types=displaytypes;
	
	//alert(Types);
	
	//if(!Types)
	//	Types=$("#Types").val();
	//	
	//alert(Types);
	
//if( ((indexpage=='Restaurants')&& ($("#1").className=='alink')) || ( ($("#indexpage").val()=='Events') && ($("#17").className=='alink')) || ( ($("#indexpage").val()=='Events') && ($("#6").className=='alink')) ||((indexpage=='RealEstate')&&(submitter=='showby')) || ((indexpage=='HealthCare')&& ($("#2").className=='alink')) || (indexpage!='Advertising')|| (indexpage!='Bank-Products')|| (indexpage!='Movies'))
//		var SubTypes="";
//Else
		var SubTypes=$("#SubTypes").val();
//	alert(SubTypes);
	
	ajaxloader('#ContentDiv','big',schemecolor);
	
	if((indexpage=='Events')||(indexpage=='ThingsToDo')){
		/*if(submitter=="showby"){
			$("#"+$('a.checked')[0].id).attr("class","daylink");
			var showby=$("#showby").val();
		}else{
			if($('a.checked')[0].id)
				var showby=$('a.checked')[0].id;
			else
				var showby=$("#showby").val();
		}*/
		var showby=$("#showby").val();
		
		$("#ContentDiv").load('/'+indexpage, { 'do': "search",'search': 1, AreaID: $("#AreaID").val(),  showby: showby, calsearchdate: $("#calsearchdate").val(), Types: Types,SubTypes: SubTypes} )			
	}else{
		if($("#indexpage").val()=='Beirut'){
			$("#ContentDiv").load(displaytypes, { 'do': "loadcontent",'type': displaytypes} )
  		}else{
  			$("#ContentDiv").load(indexpage, { 'do': 'search','search': 1, AreaID: $("#AreaID").val(),  showby: $("#showby").val(),SubTypes: SubTypes, Types: Types, ContactType: $("#ContactType").val(), ContactTypeName: $("#ContactTypeName").val() } ) 
  		}
  }
  	
  	Change_Ad("a8c465c4");//change leaderboard ad
  	Change_Ad("a2bb8a70");//change wide skyscraper ad
  	
}

function Change_Ad(ad_id) {
	//obj = document.getElementById(ad_id); 
	//obj.src = obj.src.replace(/cb=[a-zA-Z0-9-_]+(&.*)?/, 'cb='+Math.floor(Math.random()*99999999999)+'$1');
}

function ajaxloader(divname,size,schemecolor) {	
	$(divname).html('<p align="center"><br><BR><BR><img src="http://cdn.beirut.com/images/loaders/'+size+'/'+schemecolor+'-ajax-loader.gif"/></p>');		
}

function get_pagename(){	
	return window.location.pathname.replace('/','');
}

function displayResultsRecords(from, to, Total,rslttype){
  var results="&nbsp;&nbsp;";
  
  if((rslttype=='search') && (Total>20)){
  	var results="Showing first 20 results only. Please refine your search.";
  }else{
  	if(from!=0)
  		var results="Showing "+ from +" - "+ to + " of "+ Total +"";	
  }
 $('.paginationtext,#showResults').html(results);
}

function Nosubmit(e){
/*	
if(navigator.appName == "Netscape"){
	
var key=e.which
}else{
var key=e.keyCode;
}
if(key==13){
	if($(".ac_results").find("li").size()==1){
		//alert($(".ac_results").find("li:eq(0) a").attr("href"));
		$(".ac_results").find("li:eq(0)").focus();
		alert($(".ac_results").html());
		//window.location=$("#singleBirdRemote").val();
		return false;
	}else{
		return false;
	}
	return false;
}*/

}

function isInt(x) { 
   var y=parseInt(x); 
   if (isNaN(y)) return false; 
   return x==y && x.toString()==y.toString(); 
 } 
function Change_Iframe_source(urltogo){
	$("#urlcont").attr('src', urltogo); 
}


function substractcountComments(textareaID,initialcount,totalvar,countertd){
	var element=document.getElementById(textareaID);	   
	var currentcount=element.value.length;	
	if(currentcount<=totalvar){
		var remaining=totalvar-currentcount;
		document.getElementById(countertd).innerHTML=remaining;
		return false;
	}
	if(initialcount>currentcount){
		var remaining=initialcount-currentcount;
		document.getElementById(countertd).innerHTML=remaining;
	}else{
		var maintainplus = '';
		var tweettext=element.value;
		for(var i=0;i<totalvar;i++){
			maintainplus += tweettext.charAt(i);
		}	
		element.value = maintainplus;
		return false;		 
	}
}

function isValidEmailAddress(emailAddress) {
	var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
	return pattern.test(emailAddress);
};


function substractcountTextarea(initialcount,totalvar,countertd,textareaID){	
	var element=document.getElementById(textareaID);	   
	var currentcount=element.value.length;	
	if(currentcount<=totalvar){
		var remaining=totalvar-currentcount;
		document.getElementById(countertd).innerHTML=remaining;
		return false;
	}
	if(initialcount>currentcount){
		var remaining=initialcount-currentcount;
		document.getElementById(countertd).innerHTML=remaining;
	}else{
		var maintainplus = '';
		var tweettext=element.value;
		for(var i=0;i<totalvar;i++){
			maintainplus += tweettext.charAt(i);
		}	
		element.value = maintainplus;
		return false;		 
	}
}

