function ask(q)
{
    if(q)
    {
        if(!confirm(q))
        {
            return false;
        }
        else
        {
            return true;
        }
    }
}
function goto(url)
{
    window.open(url, "_self");
}
function gotothispage(url)
{
    window.setTimeout('goto( "' + url + '");', 1000);
}

function ask_b(q, url)
{
     if(ask(q))
     {
        goto(url);
     }
     else
     {
        return false;
     }
}

function get_id(me)
{
    return document.getElementById(me);
}

function str_replace(olds, news, text)
{
    for(var i = 0; i <= text.length; i++)
    {
        text = text.replace(olds, news);
    }

    return text;
}


function clrphrase(me, phrase)
{
    if(me.value == phrase)
    {
        me.value = "";
    }
}
function setphrase(me, phrase)
{
    if(!me.value)
    {
        me.value = phrase;
    }
}

function gotothumbnails()
{
    var hrf = location.href;
    goto(hrf.replace('icon=true', ''));
}

function gotoicon()
{
    var splt = location.search.replace('?', '').split("&");
    var frm = "";
    for(var i=0; i < splt.length; i++)
    {
        var prm =  splt[i].split("=");
        if(prm[0] != "icon" && prm[0] && prm[1])
        {
            frm += '<input type="hidden" name="' + prm[0] + '" value="' + prm[1] + '">';
        }

    }
    $("body").append('<form id="frmaction" action="" method="get"><input type="hidden" name="icon" value="true">' + frm + '</form>');
    $("#frmaction").submit();
}

function dosav(myid, fullurl)
{
    $("#dialog_" + myid + " input").each(function()
    {
        this.disabled = true;
    });
    $("#favos_" + myid).hide();

    $("#dialog_" + myid + " .closebutton, #floatdialog_mask_dialog_" + myid).unbind('click');
    $("#hiddendata_" + myid).css({'background-image' : 'url(' + fullurl + '/images/loading.gif)', 'width': '250px', 'height': '80px', 'background-position': 'center'});
    var filename = $("#favoname_" + myid).val();

    $("#hiddendata_build_" + myid).hide().load(fullurl + '/ajax.php?page=addtofavo&filename=' + str_replace(" ", "_", filename) + "&fileid=" + myid, {limit: 35}, function()
    {
          if($(this).html() == "updated")
          {
              $("#hiddendata_" + myid).css({'background-image' : 'none'}).html("<div class='clr' style='padding-top: 40px;'>File Updated successfully !</div>");
          }
          else if($(this).html() == "installed")
          {
              $("#hiddendata_" + myid).css({'background-image' : 'none'}).html("<div class='clr' style='padding-top: 40px;'>File added successfully !</div>");
          }

          window.setTimeout("close_favo_displayed(" + myid + ");", 2000);
    });
}

function close_favo_displayed(myid)
{
    $(".disable_masking").hide();
    $("#floatdialog_mask_" + "dialog_" + myid).fadeOut("slow").fadeTo("", 100);
    $("#favo_" + myid).hide();
}


function edit_name_f(ids, filename)
{
    var ask = window.prompt("Rename " + filename + " folder", filename);
    if(ask && ask != filename)
    {
        var htm = '<form action="" id="submitrename" method="post"><input type="hidden" name="ids_change" value="' + ids + '"><input type="hidden" name="foldername_change" value="' + ask + '"></form>';
        $("body").append(htm);
        $("#submitrename").submit();
    }
}

function edit_name_fil(ids, filename)
{
    var ask = window.prompt("Rename " + filename + " file", filename);
    if(ask && ask != filename)
    {
        var htm = '<form action="" id="submitrename" method="post"><input type="hidden" name="ids_change" value="' + ids + '"><input type="hidden" name="filename_change" value="' + ask + '"></form>';
        $("body").append(htm);
        $("#submitrename").submit();
    }
}

function opendirs(dirid, me)
{
   $("#" + dirid).show();

   me.src = "images/mince.jpg";
   $(me).attr('onclick', "").bind('click', function()
   {
       closdirs(dirid, me);
   });
}

function closdirs(dirid, me)
{
    $("#" + dirid).hide();
    me.src = "images/more.jpg";
   $(me).attr('onclick', "").bind('click', function()
   {
       opendirs(dirid, me);
   });
}

function checkthat(me, theclass)
{
    if(me.checked == true)
    {
        $("." + theclass).each(function()
        {

            this.checked = true;
        });
    }
    else
    {
         $("." + theclass).each(function()
        {
            $(this).attr('checked', false);
        });
    }
    getcount('thecheckboxs_', 'filescount');
}

function getcount(theclass, countid)
{
    var thecount = 0;
    $("." + theclass).each(function()
    {
        if(this.checked == true)
        {
            thecount++;
        }
    });
    $("#" + countid).html(thecount);
}

function setCookie(c_name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie=c_name+ "=" +escape(value)+
    ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
    c_start=document.cookie.indexOf(c_name + "=");
    if (c_start!=-1)
      {
      c_start=c_start + c_name.length+1;
      c_end=document.cookie.indexOf(";",c_start);
      if (c_end==-1) c_end=document.cookie.length;
      return unescape(document.cookie.substring(c_start,c_end));
      }
    }
    return false;
}
