function InsertWord(word) {
	field = document.getElementById('comment');
if (document.selection) {
field.focus();
var sel = document.selection.createRange();
sel.text = word;
sel.select();
} else if (field.selectionStart || field.selectionStart == '0') {
var start = field.selectionStart;
var end = field.selectionEnd;
var scroll = field.scrollTop;
field.value = field.value.substring(0, start) + word + field.value.substring(end, field.value.length);
field.focus();
field.selectionStart = start + word.length;
field.selectionEnd = start + word.length;
field.scrollTop = scroll;
} else {
field.value += word;
field.focus();
}
}

function delConfirm()
{
if(confirm("Silməyə əminsiniz?"))
return true;
else
return false;
}

/****** Elastic textares for Mobiland ******/
$(document).ready(function(){			
$('textarea').elastic();
});	

/*********** Get Simple info About Selected Phone *******/
function showSimple(p,b) {
	var bName=$('div#simple_'+p);
  $('a#more_'+p).fadeOut("slow");
  bName.html ("Yüklənir. Zəhmət olmasa gözləyin...");
  bName.fadeIn("slow").css("margin-top", "5px").css("margin-bottom", "5px");
  bName.load(mobiUrl+"ajax/simple_info_ph.php?b="+b+"&p="+p);
  $('#pic_'+p).css("margin-top","30px");
  return false;
}
 /******************* Show Supported Phones **************************/
 function showAdd(p,b){
 	 	$('#moreAddPar').html('<div class="second">Yüklənir. Gözləyin...</div>');
		$.ajax({
			type: "GET", url: mobiUrl+"ajax/add_info_ph.php?b="+b+"&p="+p,
			complete: function(data){
				$('#moreAdd').hide();
				$("div#add").html(data.responseText);
				$('#moreAddPar').html('<div class="second">A\u015fağıda modelin digər məlumatları göstərilib</div>');
				$.scrollTo('div#add',800);
			}
		});
		return false;
	}

/************ Similar Adv ********/
function showSimE(a,b) {
    $.jGrowl('Yüklənir…',{life:1000,theme:'orange'});
    $('#moreSim').hide();
    $('div#hiddenSim').load(mobiUrl+"ajax/show_similar_e.php?id="+a+"&type="+b);
    $.scrollTo('div#hiddenSim',800);
    return false;
}


/********** Mobiland JavaScript ***********/
function hilite(elem)
{
    elem.style.background = '#f3f3f3';
    elem.style.border = 'solid 1px #BE87FF';
}
function hilite2(elem)
{
    elem.style.background = '#e4fbae';
    elem.style.border = 'solid 1px #b3db3c';
} 
function lowlite(elem)
{
    elem.style.background = '';
    elem.style.border = 'solid 1px #FFF';
}
function lowlite2(elem)
{
    elem.style.background = '';
    elem.style.border = 'solid 1px #ccc';
}

/****************** Mobiland JavaScript ************/
    function blinkThis(elem) /* Higlite div function by AzeriFire */
    {
        $('#'+elem).css({backgroundColor: '#eee'});return;
    }
/****************** Mobiland JavaScript ************/
   function  voteUp(id,type){
       var actUrl="";
     if(type=="p"){actUrl="ajax/votes.php";}else if (type=="f"){actUrl="ajax/vote_file.php";}
    $(this).parent().html("<img src='"+mobiUrl+"images/spinner.gif'/>");
    $("span#votes_count"+id).fadeOut("fast");
    $("div#votes_count2"+id).fadeOut("fast");
        $.ajax({
            type: "POST",
            data: "action=vote_up&id="+id,
            url: mobiUrl+actUrl,
            success: function(msg)
            {
                $("span#votes_count"+id).html(msg);
                $("span#votes_count"+id).fadeIn();
                $("span#vote_buttons"+id).remove();
            }
        });
    };
    function  voteDown(id,type){
        var actUrl="";
    if(type=="p"){actUrl="ajax/votes.php";}else if (type=="f"){actUrl="ajax/vote_file.php";}
        $("span#votes_count"+id).fadeOut("fast");
    $("div#votes_count2"+id).fadeOut("fast");
    $(this).parent().html("<img src='"+mobiUrl+"images/spinner.gif'/>");
        $.ajax({
            type: "POST",
            data: "action=vote_down&id="+id,
            url: mobiUrl+actUrl,
            success: function(msg)
            {
                $("span#votes_count"+id).fadeOut();
                $("span#votes_count"+id).html(msg);
                $("span#votes_count"+id).fadeIn();
                $("span#vote_buttons"+id).remove();
            }
        });
    };
/*********************** Gallery for Mobiland ************************  */

$(document).ready(function(){
     $(".thumbs a").click(function(){
        var largePath = $(this).attr("href");
        var largeAlt = $(this).attr("title");
        $("#largeImg").animate({opacity: 0}, 500);
        $("#largeImg").html("Yüklənir...");
        $("#largeImg").attr({ src: largePath, alt: largeAlt });        
        $("#largeImg").animate({opacity: 1}, 3000); return false;
    });
    
});

/***************************************** Comment BOX ********************/
$(document).keyboard('ctrl enter',function () {$("form#comments").trigger('submit')});

$(document).ready(function()
{
    $("form#comments").submit(function() /* AJAX Commenting by AzeriFire */
    {
        $("#sendCom").attr("disabled", "true"); 
        $.jGrowl('Zəhmət olmasa, gözləyin…',{life:3000,theme:'orange'});
	$.post(mobiUrl+"ajax/add_com.php",{comment:$('#comment').val(),for_id:$('#for_id').val(),type:$('#type').val()}, function(data)
        {
         if(data=='empty')
          {
		$.jGrowl("Səhv baş verdi. Şərh yerini doldurun.",{life:3000,theme:'red'});
               $('#comment').focus();
               $("#sendCom").removeAttr('disabled'); 
    
          }
          else if(data=='problem')
          {
	$.jGrowl('Naməlum səhv baş verdi. Şərh yerini doldurun…',{life:3000,theme:'red'});
               $('#comment').focus();
               $("#sendCom").removeAttr('disabled');      
          }
          else
          {
            $('#comment').val('');
	    $.jGrowl('Təşəkkür edirik, şərh əlavə edildi…',{life:3000,theme:'green'});
            $("#new_com").append(data);
            $("#sendCom").removeAttr('disabled'); 
          }
        });
 return false;
    });
    
});

/********** Show-Hide ********************/
  $(document).ready(function(){ 

    $("#show_msg").click(function () {
      $("#show_msg").hide();
      $("div#hidden_msg").fadeIn('slow');
      $("#hide_msg").css("display", "inline");
      return false;
    });
   $("#hide_msg").click(function () {
      $("div#hidden_msg").fadeOut('fast');
      $("#show_msg").show();
      $("#hide_msg").css("display", "none");
      return false;
    });

  });

 /******************* Show Supported Phones **************************/
 function viewPh(id){
 	 	$("#ajaxViewPh").attr("value", "Y\u00FCkl\u0259nir, z\u0259hm\u0259t olmasa g\u00F6zl\u0259yin...");
		$.ajax({
			type: "GET", url: mobiUrl+"ajax/sup_phones.php", data: "id="+id,
			complete: function(data){
				$("#ajaxViewPh").hide();
				$("#response").html(data.responseText);
				$("#hiddenPh").css("visibility","visible");
				$("#hiddenPh").slideDown();
			}
		});
		return false;
	}

 function checkImei(){
    $("#showImei").html("<div style='text-align:center;'><img src='"+mobiUrl+"images/spinner.gif'/> Y\u00FCkl\u0259nir, z\u0259hm\u0259t olmasa g\u00F6zl\u0259yin...</div>").fadeIn(1000);    var imei=$("#imei").val();
		var imeiVal=$("#imei").val();
		var spamVal=$("#spam").val();
		$.ajax({
			type: "GET", url: mobiUrl+"ajax/imei_check.php", data: "imei="+imeiVal+"&spam="+spamVal,
			complete: function(data){
				$("#showImei").html(data.responseText);
			}
		});
		return false;
}

function reply()
{
    $.scrollTo('#comment_div',800);
    $('#comment').focus();
    return false;
}

/***************** Contact ************/
function doContSend(){
	$.jGrowl('Z\u0259hm\u0259t olmasa g\u00F6zl\u0259yin...',{life:3000,theme:'orange'});
	var name =jQuery.trim($('#name').val());
	var mail =jQuery.trim( $('#mail').val());
	var phone =jQuery.trim( $('#phone').val());
	var message =jQuery.trim( $('#message').val());
	if(name=="")
	 {
	  $.jGrowl('Səhv baş verdi! Ad yeri boş ola bilməz',{life:3000,theme:'red'});
	  return false;
	 }
	if(mail=="")
	    {
	 $.jGrowl('Səhv baş verdi! E-poçt ünvanı boş ola bilməz',{life:3000,theme:'red'});
	 return false;
	    }
	if(message=="" || message.length<10)
	    {
	 $.jGrowl('Səhv baş verdi! İsmarıcın mətni 10 simvoldan az ola bilməz',{life:3000,theme:'red'});
	 return false;
	    }
	$("#send").attr("disabled", true);
	$.ajax({
   	type: "POST",
   	url: "ajax/send_contact.php",
   	data: "name="+name+"&mail="+mail+"&phone="+phone+"&message="+message,
   	success: function(msg){
	if(msg=="nameError")
	 {
	 $.jGrowl('Səhv baş verdi! Ad yeri boş ola bilməz',{life:3000,theme:'red'});
	 $("#send").attr("disabled", false);
	 return false;
	}
	else if(msg=="msgError")
	{
	$.jGrowl('Səhv baş verdi! İsmarıcın mətni 10 simvoldan az ola bilməz',{life:3000,theme:'red'});
	$("#send").attr("disabled", false);
	return false;
	}
	else if(msg=="mailError")
	{
	 $.jGrowl('Səhv baş verdi! E-poçt ünvanında yanlışlıq var',{life:3000,theme:'red'});
	 $("#send").attr("disabled", false);
	 return false;
	}
	else if(msg=="success")
	{
	    $.jGrowl('Təşəkkür edirik, məktubunuz göndərildi',{life:3000,theme:'green'});
	$('#name').attr("value","");
	$('#mail').attr("value","");
	$('#phone').attr("value","");
	$('#message').attr("value","");
	$("#send").attr("disabled", false);
	}
	else
	{
	$.jGrowl('Səhv baş verdi!Məktub göndərilmədə problem yarandı.<br/> Bir azdan yenidən cəhd edin',{life:3000,theme:'red'});
	$("#send").attr("disabled", false);
	 return false;
	}
 }
  });

};

/*****   Do thanks **************/
 function doThx(id){
     $("#thxBut").attr("value", "Yüklənir.Zəhmət olmasa gözləyin...");
 	 	$.ajax({
			type: "POST", url: mobiUrl+"ajax/thx_file.php", data: "id="+id,
			complete: function(data){
				$("#thx_"+id).html(data.responseText);
			}
		});
		return false;
}

function showBlock(blockName)
{
   $("div#"+blockName).slideDown("fast");
   $.scrollTo('div#'+blockName,800);
}

$(function()
{
	$('.ph_menu_body').jScrollPane({showArrows:true});
    //$('.menu_body').jScrollPane({showArrows:true});
});

var containerId = '#tabs-container';
var tabsId = '#tabs';

$(document).ready(function(){
	// Preload tab on page load
	if($(tabsId + ' LI.current A').length > 0){
		loadTab($(tabsId + ' LI.current A'));
	}
	
    $(tabsId + ' A').click(function(){
    	if($(this).parent().hasClass('current')){ return false; }
    	
    	$(tabsId + ' LI.current').removeClass('current');
    	$(this).parent().addClass('current');
    	
    	loadTab($(this));    	
        return false;
    });
});

function loadTab(tabObj){
    if(!tabObj || !tabObj.length){ return; }
    $(containerId).addClass('loading');
    $(containerId).html('<span class="redTxt">Y\u00FCkl\u0259nir, z\u0259hm\u0259t olmasa g\u00F6zl\u0259yin....</span>');
    
    $(containerId).load(tabObj.attr('href'), function(){
        $(containerId).removeClass('loading');
        $(containerId).fadeIn('fast');
    });
}