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;
    });
    $("#dialog_" + myid + " .closebutton, #floatdialog_mask_dialog_" + myid).unbind('click');
    $("#hiddendata_" + myid).css({'background-image' : 'url(' + fullurl + '/images/loading.gif)', 'width': '250px', 'height': '50px', '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("File Updated successfully !");
          }
          else if($(this).html() == "installed")
          {
              $("#hiddendata_" + myid).css({'background-image' : 'none'}).html("File added successfully !");
          }
          $("#cancel_" + myid).val("Close").bind("click",function()
          {
                $(".disable_masking").hide();
                $("#floatdialog_mask_" + "dialog_" + myid).fadeOut("slow").fadeTo("", 100);
          });
          document.getElementById("cancel_" + myid).disabled = false;
    });
}

function edit_name_f(ids, filename)
{
    var ask = window.prompt("Rename " + filename + " folder", filename);
    if(ask && ask != filename)
    {
        var htm = '<form 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 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 goto_content(ids)
{
  if($(document).height()-$("#"+ids).offset().top >= $(window).height()
  				 || $("#"+ids).offset().top > $(window).height()
  				 || $(document).width()-$("#content_go").offset().left >= $(window).width()
  				 || $("#"+ids).offset().left > $(window).width()){

  					$('html, body').animate({
  						scrollTop: $("#"+ids).offset().top,
  						scrollLeft: $("#"+ids).offset().left
  					}, "slow", null, function(){

  					});

                             }
}
