function toconvert(content)
{
  var sourceareastr = $(content).val();
  var strlen = sourceareastr.length;
  var str="";

  for (i = 0; i < strlen;  i++) { 
    var codestr = sourceareastr.charCodeAt(i);
    switch(codestr) {
  		case 184: codestr=1105;break; //eo
  		case 168: codestr=1025;break; // capital EO
  	
  		case 175: codestr=1198; break; //capital UE
  		case 191: codestr=1199; break; //ue
  		
  		case 170: codestr=1256; break; // capital OE
  		case 186: codestr=1257; break; //oe
    }

	  if (256>codestr && codestr>191) codestr=codestr+848;

	  switch(codestr) {
  		case 1111: codestr=1199;break;   //u
  		case 1031: codestr= 1198; break; //capital U
  		
  		case 1108: codestr=1257; break; //ou
  		case 1028: codestr=1256; break; //capital OU
		}
    str=str+String.fromCharCode(codestr);
  } //end for   
  
  $(content).val(str);
}

jQuery(document).ready(function() {
    jQuery("#login_username").focus(function () {
      if($('#login_username').val() == 'Хэрэглэгчийн нэр / и-мэйл') $('#login_username').val('');
    }).blur(function () {
      if($('#login_username').val() == '') $('#login_username').val('Хэрэглэгчийн нэр / и-мэйл');
    });
    
    jQuery("#login_password").focus(function () {
      if($('#login_password').val() == 'Нууц үг') $('#login_password').val('');
    }).blur(function () {
      if($('#login_password').val() == '') $('#login_password').val('Нууц үг');
    });



    jQuery("#MenuNav li.nav").mouseover(function(){
        jQuery(this).addClass("hover");
      }).mouseout(function(){
        if(jQuery(this).attr("lang") != "visible")
        {
          jQuery(this).removeClass("hover");
        }
    });

    jQuery("#MenuNav li.nav .hidden_top_menu ul li").mouseover(function(){
      jQuery(this).addClass("hover");
      }).mouseout(function(){
      jQuery(this).removeClass("hover");
    });
   
    jQuery("#small_cards_nav li a").hover(function () {
        var currentCard = jQuery(this).attr('card');
        jQuery("#small_cards_nav li a").removeClass("current");
        jQuery(this).addClass("current");
        jQuery('.small_card').hide();
        jQuery('#'+currentCard).show();
        
    });
    
    jQuery("div.tab_se li a").mouseover(function () {
      var currentTab = jQuery(this).attr('tab');
      jQuery("div.tab_se li a").removeClass("current");
      jQuery(this).addClass("current");
      jQuery('.tab_se_content').hide();
      jQuery('#'+currentTab).show();
      return false;
    });    

    jQuery("#tab_activity li").mouseover(function () {
      var currentTab = jQuery(this).attr('tab');
      jQuery("#tab_activity li").removeClass("current");
      jQuery(this).addClass("current");
      jQuery('.activity_list').hide();
      jQuery('#'+currentTab).show();
      return false;
    });
    
    
    jQuery("#activity_public li").mouseover(function () {
      var currentTab = jQuery(this).attr('tab');
      jQuery("#activity_public li").removeClass("current");
      jQuery(this).addClass("current");
      jQuery('.activity_public').hide();
      jQuery('#'+currentTab).show();
      return false;
    });
    
    jQuery("#tab_product li").mouseover(function () {
      var currentTab = jQuery(this).attr('tab');
      jQuery("#tab_product li").removeClass("current");
      jQuery(this).addClass("current");
      jQuery('.product_list').hide();
      jQuery('#'+currentTab).show();
      return false;
    });
    
    jQuery(".stabs li").click(function () {
      jQuery(".stabs li").removeClass("current");
      jQuery(this).addClass("current");
      jQuery('#publicSearchType').val(jQuery(this).attr('title'));
      return false;
    });
    
    
    jQuery("#apartmentTabs li").mouseover(function () {
      jQuery("#apartmentTabs li").removeClass("current");
      jQuery(this).addClass("current");
      jQuery('.apartmentsTable').hide();
      
      var currentTab = jQuery(this).attr('tab');
      jQuery('#'+currentTab).show();
      return false;
    });

    jQuery("#adminToolsTitle").click(function () {
        if(!jQuery('#adminToolsContent').hasClass('open')) {
            jQuery('#adminToolsContent').slideDown();
            jQuery('#adminToolsContent').addClass('open');
        }
        else {
            jQuery('#adminToolsContent').slideUp();
            jQuery('#adminToolsContent').removeClass('open');
        }
      return false;
    });

});

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};


jQuery(document).ready(function() {
    jQuery(".options_tab ul li").click(function () {
      var currentTab = jQuery(this).attr('tab');
      jQuery(".options_tab ul li").removeClass("active");
      jQuery(this).addClass("active");
      jQuery(".options_tab_content").hide();
      jQuery('#'+currentTab).show();
      return false;
    });
});

function transparency_enable() {
  document.getElementById('overlay').style.display='block';
}

function transparency_disable() {
  document.getElementById('overlay').style.display='none';
}
 
function submit_popup_close () {
    document.getElementById('submit_popup').style.display='none';
    transparency_disable();
}

function submit_popup_open () {
    document.getElementById('submit_popup').style.display='block';
    transparency_enable();
}




/* CONTENT/SHOW play embeded video */
function playActVideo(srcId, targetId)
{
  srcId = '#' +srcId;
  targetId = '#' +targetId;
  
  $(targetId).html(unescapeHTML($(srcId).html()));
  return false;
}


function unescapeHTML(s)
{
  return s.replace(
  /&(amp|lt|gt|quot|#039);/gi,
  function(m, p1)
  {
    var map = {
      amp:  "&",
      lt:   "<",
      gt:   ">",
      quot: '"',
      '#039': "'"
    };
    return map[p1];
  });
}



/* USER/LOGIN-REGISTER */

function toggleDivRegister(value)
{
   $('#isRegister').val(value);
   
   if($('#isRegister').val() == 1)
   {
     $('#divLogin').hide();
     $('#divRegister').show();
     
     
     $('#linkRegister').html('Нэвтрэх');
     $('#loginRegisterButton').val('Бүртгүүлэх');
     
   }else{
     $('#divRegister').hide();
     $('#divLogin').show();
            
     $('#linkRegister').html('Бүртгүүлэх');
     $('#loginRegisterButton').val('Нэвтрэх');
   }
}










/*
// <img src="/images/icons/loading-black.gif" alt="Уншиж байна" title="Уншиж байна" style="display:none;" id="domainLoader" align="absmiddle"> // LOADER IMAGE

AJAX FOLLOW
$(document).ready(function()
{
  $("#linkFollow").click(function()
  {
    if(confirm('Are you sure?'))
    {
      $.ajax({ 
        url: "follower/follow", 
        data: "user_id=<?php echo $user->getId()?>",
        beforeSend: function(){
          $('#loader').show();
        },
        success: function(data)        
        {
          $('#loader').hide();
          $("#containerFollow").html(data);
        }
      });
    }
    
    return false;
  });
});*/



function ajaxVote(id, type)
{
  var resultId = "#bittte"+id+"vote";
  
  $.ajax({ 
    url: "/vote/vote", 
    data: ({bittteId : id, type : type}),
    success: function(data)
    {
      $(resultId).html(data);
    }
  });
  
  return false;
}





var isLoadingMore = false;

function showMoreActivity(tagId, categoryId, userId, searchBittteKeyword, lastId, withProfile)
{
  if (isLoadingMore) return false;
  
  $.ajax({
    url: '/public/showmore',
    data: { tagId:tagId, categoryId:categoryId, userId:userId, searchBittteKeyword:searchBittteKeyword, lastId:lastId, withProfile:withProfile },
    onLoading : function (){
      isLoadingMore = true;
      $('more_button').hide();
      $('more_indicator').show();
    },
    success: function(data) {
      isLoadingMore = false;
      
      $('more_button').show();
      $('more_indicator').hide();
      
      moreBitttes = "#moreBitttes"+lastId;
      $(moreBitttes).html(data);
    }
  });
}

function MailTo(url)
{
  jQuery('.sendFriend-dialog').dialog('close');

  jQuery('#sendFriend_form_container').load('/sendFriend/new?url='+url).dialog({
    title:  'Найздаа илгээх',
    autoOpen: false,
    resizable: false,
    width: 450,
    autoResize : true
  });
  jQuery('.sendFriend-dialog').dialog('open');
  return false;
}

function submitMail(url)
{
  jQuery.ajax({
    url: '/sendFriend/create?url='+url,
    type: 'POST',
    data: jQuery("#sendFriend_form").serialize(),
    success: function(html){
      jQuery("#sendFriend_form_container").html(html);
    }
  });

}


jQuery("#publicSearchKey").focus(function () {
  if($('#publicSearchKey').val() == 'Хайлт')
  $('#publicSearchKey').val('');  
});

jQuery("#publicSearchKey").blur(function () {
  if($('#publicSearchKey').val() == "")
  $('#publicSearchKey').val('Хайлт');
});


/*
function toggleTabs(tab, currentTab, content, currentContent)
{
    jQuery(tab+' li').removeClass("current");
    jQuery(currentTab).addClass("current");
    
    jQuery(content).hide();
    jQuery(currentContent).show();
    
    return false;
}
*/


jQuery("#publicSearchKey").focus(function () {
  if($('#publicSearchKey').val() == 'Хайлт')
  $('#publicSearchKey').val('');  
}).blur(function () {
  if($('#publicSearchKey').val() == "")
  $('#publicSearchKey').val('Хайлт');
});
