function clearform(which,action){
    if (action==1) {
        which.style.backgroundPosition = '0 -300px';
    } else {
        if (which.value=="") {
            which.style.backgroundPosition = '0 0';
        }
    }
}


function clearform2(which,text){

    var $txt = text
    if (which.value==$txt) {
        which.value='';
    } else if (which.value=="") {
        which.value=$txt;
    }

}

function change_blockNai(id1,id2,bl_id1,bl_id2)
{
    
 var a=$(id1).attr("class");
 var b=$(id2).attr("class");
 if(a=="sel")
    {
    $(id2).attr("class","sel");
    $(id1).attr("class","");
    $(bl_id1).hide();
    $(bl_id2).show(0);

    }
  if(b=="sel")
    {
    $(id1).attr("class","sel");
    $(id2).attr("class","");
    $(bl_id2).hide();
    $(bl_id1).show(0);


        }
 //var a=$("#komentirano").attr("id");

}

function UserVote(vote,artid)
{

$.post("../../_scripts_vote.php",{vote:vote,artid:artid},function(data) {alert(data)});
}

function QuizSwitch()
{
    $("#tab1").toggle();
    $("#tab2").toggle();
    }

function Quiz_vote(artid)
{
var vi=$("input[@name=voteit]:checked").val();
if(vi) $.post("../../_scripts_qvote.php",{vote:vi,artid:artid},function(data) 
    {  res=data.split("|");
            
        alert(res[2]);
        if(parseInt(res[1])) 
        {$("#qid1").html(parseInt(res[3]));
          // //alert($("#asid"+ii).css("width"));
          for(var ii=1;ii<6;ii++) 
          {
          var ki=3+ii;  
          $("#aid"+ii).html(parseInt(res[ki])); 
          var kw=100*(parseInt(res[ki])/parseInt(res[3]));
          $("#asid"+ii).css("width",parseInt(kw)+"px"); 
          }
                
            QuizSwitch();
        }
    });
else alert("Моля гласувайте");
}

 function changeFont(inc,id){
   var p=document.getElementById(id);
     if(p.style.fontSize){
      var size=parseFloat(p.style.fontSize.replace("em",""));
     }else{
      var size=1.1;  //tuk slagame default stoinosta da se vidi ot css faila :)
     }
    if(!inc)  size=1.1;
    if((size+inc)<= 2.1 && (size+inc)>=0.3)
      p.style.fontSize=size+inc + 'em';
    }

function setCheck(id){
 if(id)
  document.getElementById(id).value=1;
}


   
    //$(".gallerybig a").click( galleryNext );
	//$(".gallerybig .ppic").click( galleryPrev );
   
    function galleryNext(event)
    {

    var res=$(".gallerybig").attr("id");
        var article = /gallery([0-9]*)/i.exec( res );

    var res=$("#glarge img").attr("id");
    var t = /image([0-9]*)/i.exec( res );

    var res=$("#glarge img").attr("name");
    var allpic = /image([0-9]*)/i.exec( res );

        var offset=parseInt(t[1])+1;

    if(offset>0)
        {$(".ppic").show();
        }
    if(offset==(parseInt(allpic[1])-1))   $(".npic").hide();
	
    $("#glarge img").attr("id","image"+offset);
    $.get("/_script_gallery_get.php", {"aID":article,"offset":offset} , galleryResult );
    }
 
    function galleryPrev(event)
    {
        var res=$(".gallerybig").attr("id");
        var article = /gallery([0-9]*)/i.exec( res );

    var res=$("#glarge img").attr("id");
        var t = /image([0-9]*)/i.exec( res );
	var res=$("#glarge img").attr("name");
    var allpic = /image([0-9]*)/i.exec( res );
    
	var offset=parseInt(t[1])-1;
        if(offset<1)
        {
        $(".ppic").hide();
        $(".npic").show();
        }
	 if(offset==(parseInt(allpic[1])-2))   $(".npic").show();	
    $("#glarge img").attr("id","image"+offset);
    $.get("/_script_gallery_get.php", {"aID":article,"offset":offset} , galleryResult );
    }
  
 function galleryResult(data)
   {

        var res=data.split("|");
        var r=parseInt(res[1]);
        var h=res[2];
        var url=res[3];
    if(r)
    {
        $("#glarge img").hide().attr({"src": "/"+url+"?"+new Date().getTime()})
    $("#glarge").attr("style","height:"+h+"px;");
    $("#glarge>img").load(function(){$("#glarge>img:hidden").fadeIn("slow")});
    }
    else
    {
    $(".npic").hide();
        var res=$("#glarge img").attr("id");
        var t = /image([0-9]*)/i.exec( res );

    var offset=parseInt(t[1])-1;
        if(offset<1) $(".ppic").hide();
    $("#glarge img").attr("id","image"+offset);
    }
   }

function coloranswer(dlid,ddid) {
    $table  = document.getElementById( dlid );
    allSelects = $table.getElementsByTagName( 'dd' );
    for( cA = 0; cA < allSelects.length; cA++)
    {
        allSelects[ cA ].className = '';
        document.getElementById(ddid).className = 'checked';
    }
}

function isReady(div){
  if(document.getElementById(div).value!='1')
   return false;
  else
   return true;

}


function oracul_ans()
    {
    $("#oracul_ans").hide();
    p=$("#oracul_question").val();
        //alert(p);

    if(p!="") $.post("_script_oracul.php",{"question":p},function(data){$("#oracul_ans").html(data);$("#oracul_ans").show(1000);});

    }
function luck_ans(input)
    {
    $("#luck_ans").hide();
    p=$("input[@name=luck_opt]:checked").val();
    if(p==1||p==2) $.post("_script_luck.php",{"type":p,"luckcat":input},function(data){$("#luck_ans").html(data);$("#luck_ans").show(1000);});
    }

function makefavorite(id)
{
$.post("/_script_makefav.php",{"article":id},function(data){alert(data);});
}

function delfavorite(id)
{
$.post("_script_delfav.php",{"article":id},function(data){
    var d=data.split("|");
    alert(d[3]);
    if(d[1]==1) $("#tr_"+d[2]).remove(); });
}


function makefriend(id)
{
$.post("_script_makefriend.php",{"user":id},function(data){alert(data);});
}

function friend_confirm(id)
{       
        var replay=confirm("Искате ли да приемете предложението за приятелство?");
        if(replay!='')
        {   
        $.post("_script_makeconfirm.php",{"user":id},function(data){
                var res=data.split("|");
                if(res[2]==1)
                    {
                        
                    }
             alert(res[1]);});
        }       
        
}

function friend_delete(id)
{   
        var replay=confirm("Искате ли да изтриете приятелството?");
        if(replay!='')
        {   
        $.post("_script_makedel.php",{"user":id},function(data)
            {var res=data.split("|");
                if(res[2]==1)
                    {}
             alert(res[1]);});
        }
}



function sel_avatar()
{
$("#activ_gallery").html('<img src="/html/im/load.gif" alt="Зареждане..." border="0" />');
$.get("_script_avatars.php",{"article":0},
function(data) {var str=data;   
$("#TB_window").html(str);
$("#TB_window").show();
$("#activ_gallery").html("<a href='javascript:;' onclick='javascript:close_avatar();' class='close_gal'>Затвори галерията</a>");

});

}
function close_avatar()
{
    $("#TB_window").hide();
    $("#activ_gallery").html("<a href='javascript:;' onclick='javascript:sel_avatar();'>Избери аватар от галерията</a>");
}

function profil2_1(str)
{
$('#user_avatar').val(str);
$('#user_avatar_type').val('3');
$('#activ_avatar').attr('src','/forum/images/avatars/gallery/'+str);
}
function profil2_2()
{
    var t=$("#extra_gadje").attr("checked");
    
    if(t==true) $("#div_gadje").show();
    else $("#div_gadje").hide();
    
}
function cal_shownote(id)
{
    if($("#cal_view"+id).attr('class')=='opened') 
        {$("#cal_note"+id).hide();
            $("#cal_view"+id).attr("class","closed")
        }
    else    
    {
        $("#cal_note"+id).show();
            $("#cal_view"+id).attr("class","opened")}
}

function cal_changepic()
{   $("#type_pic").attr('src','/html/im/notes/'+$("#note_type").val()+'.gif');
}

function cal_edit_note(id)
{   
    $("#note"+id).attr('style','background-color:#FCE7EC;');
    var oldid=$("#cal_id").html();
    $.get("_script_calform.php",{"id":id},function(data) {var res=data.split("|;|");$("#cal_form").html(res[1]);$("#cal_id").html(res[2])});
    if(oldid) $("#note"+oldid).attr('style','background-color:none;');
    }
function cal_delete_note(id)
{
    var replay=confirm("Искате ли да изтриете записа?");
    if(replay!='')
    {   
    var oldid=$("#cal_id").html();  
    if(oldid) $("#note"+oldid).attr('style','background-color:#FEC7DD;');   
    $.get("_script_caldelete.php",{"id":id},function(data) {var res=data.split("|"); if(res[1]==1) $("#note"+res[2]).remove();});
    $.get("_script_calform.php",{"id":0},function(data) {var res=data.split("|;|");$("#cal_form").html(res[1]);$("#cal_id").html(res[2])});
    }
}

function notes_tab(id,all,offset,day)
{
    if(id==1) 
        {
        //$("#seltab1").attr("class","seltab"); 
          $("#seltab2").attr("class","");
          $("#seltab3").attr("class","");
          $("#cal_list").load("_script_day.php",{"all":all,"offset":offset,"day":day});
        }   
    if(id==2) 
        {
        //  $("#seltab1").attr("class","");
          $("#seltab2").attr("class","seltab"); 
          $("#seltab3").attr("class","");
          $("#cal_list").load("_script_notes.php",{"all":all,"offset":offset,"week":1,"day":day});
        }
    if(id==3) 
        {
          //$("#seltab1").attr("class",""); 
          $("#seltab2").attr("class","");   
          $("#seltab3").attr("class","seltab"); 
          $("#cal_list").load("_script_notes.php",{"all":all,"offset":offset});
        }
        
}

function newnote()
{
    $.get("_script_calform.php",{"id":0,"d":date.print("%d.%m.%Y")},function(data) {var res=data.split("|;|");$("#cal_form").html(res[1]);$("#cal_id").html(res[2])});
$("#cal_day").val(date.print("%d.%m.%Y"));
}


function change_tab(tabnum,tabchoser,tabdiv,scripta)
{

$p=$("#"+tabchoser);
$lis = $('li>a', $p);
tabnum=tabnum-1;

if($lis.filter('a:eq('+tabnum+')').attr("class")) ;
else 
    {
    $lis.removeClass("sell");
    $lis.filter('a:eq('+tabnum+')').addClass("sell");
    $("#"+tabdiv).load(scripta,{"b":tabnum});
    }
}

function countLink(wordID,fatherID,target)
{

	if(target=="_self")
		this.document.location.href="/countwords/"+wordID+"/"+fatherID+"/";
	else 
		window.open("/countwords/"+wordID+"/"+fatherID+"/");
}

$(document).ready(function() {


if(document.getElementById('husername') != null) {
if (document.getElementById('husername').value!=='') {
    clearform(document.getElementById('husername'),1);
    clearform(document.getElementById('hpassword'),1);
}
}
}); 

function pageScroll() {
    scrolldelay = setTimeout('pageScroll()',100); // scrolls every 100 milliseconds
  if (document.getElementById("profilesearch").style.display != 'none') {
   window.scrollBy(0,350); // horizontal and vertical scroll increments
   clearTimeout(scrolldelay);
  }  
}

function showSearch()
{
    $("#profilesearch").show();
    pageScroll();
}

function hideSearch()
{
    $("#profilesearch").hide("slow");
}

function add_email()
{
    var n=$("#vir_num").val();
    n=parseInt(n);
    
    //console.log($("#viral_name"+n).val());
    var test1=$("#viral_name"+n).val();
    var test2=$("#viral_email"+n).val();
    //var re5digit=/^\d{5}$/
    
    //var pr1 =patt1.test($("#viral_name"+n).val());
    var re=/^[A-Za-z АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЮЯабвгдежзийклмнопрстуфхцчшщъьюя]{3,}$/
    var re2=/^[A-Za-z_.АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЮЯабвгдежзийклмнопрстуфхцчшщъьюя]{2,}@[A-Za-z_.АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЮЯабвгдежзийклмнопрстуфхцчшщъьюя]{2,}$/
    var pr1= test1.search(re);
    var pr2= test2.search(re2);
    
    //console.log( pr1);
    //console.log( pr2);
    num=n+1;
    if($("#viral_name"+n).val()&&$("#viral_email"+n).val()&&!pr1&&!pr2)
    {
    var t2='<div style="float:left; width:230px;" id="vir_name'+num+'"><label style="width:30px;" for="viral_name'+num+'">Име:</label><input type="text" style="width:160px;" name="viral_name'+num+'" id="viral_name'+num+'" value="" class="text"   /></div>'+'<div style="float:left; width:230px;" id="vir_email'+num+'"><label style="width:45px;" for="viral_email'+num+'">E-mail:</label><input type="text" style="width:160px;" name="viral_email'+num+'" id="viral_email'+num+'" value="" class="text"  /></div>';
    
    $(t2).insertBefore("#brbr");
    
    $("#viral_name"+n).css("background-color","#fff");
    $("#viral_email"+n).css("background-color","#fff");
    $("#viral_name"+n).attr("readonly","readonly");
    $("#viral_email"+n).attr("readonly","readonly");
    $("#vir_num").val(num);
    }
    else 
        {//border:solid 1px red;background-color:#F9ACAC;
        if(pr1==-1) $("#viral_name"+n).css("background-color","#F9ACAC");
        if(pr2==-1)$("#viral_email"+n).css("background-color","#F9ACAC");
            
        }
}
function rem_email()
{
    var n=$("#vir_num").val();
    n=parseInt(n);
    if(n>1)
    {
    $("#vir_name"+n).remove();
    $("#vir_email"+n).remove();
    num=n-1;
    $("#vir_num").val(num);
    }
    
}



function love_match()
{
    $("#lovematchdiv").hide();
    var fs=$("#fsign").val();
    var ss=$("#ssign").val();
    $("#lovematchdiv").load("_script_lovematch.php",{"fsign":fs,"ssign":ss},function(){
        $("#lovematchdiv").animate({opacity: 'show'}, 500);
        //$("#slove").css("border","1px solid #ff0000");
        //alert();
        var w=parseInt($("#slove").html())*10;
        $("#slove").animate({ width:w+"px"}, 1000);
         var w=parseInt($("#ssex").html())*10;
        $("#ssex").animate({ width:w+"px"}, 1000); 
       }    );
}
function ascendant()
{
    $("#ascendant").hide();
    var fs=$("#s_zodia").val();
    var ss=$("#s_hour").val();
    
    $("#ascendant").load("_script_ascendant.php",{"s_zodia":fs,"s_hour":ss},function()
       {$("#ascendant").show();
        //$("#ascendant").animate({opacity: 'show'}, 500);
        }   );
}

