function fetch_object(idname)
{
        if (document.getElementById)
        {
                return document.getElementById(idname);
        }
        else if (document.all)
        {
                return document.all[idname];
        }
        else if (document.layers)
        {
                return document.layers[idname];
        }
        else
        {
                return null;
        }
}


//Подсветка пунктов меню

function toggle_filter(field,item)
{

        if (field.checked)
        {
                item.style.filter='Alpha(opacity=100)';
        }
        else
        {
                item.style.filter='Gray() Alpha(opacity=40)';
        }

}

function toggle_checked(field,item,color)
{
        if (field.checked)
        {
                item.style.backgroundColor=color;
        }
        else
        {
                item.style.backgroundColor="white";
        }
}

function lightbar(item,color)
{
        safecolor=item.style.backgroundColor;
        item.style.backgroundColor = color;
}

function unlightbar(item)
{
        item.style.backgroundColor = safecolor;
}

function editrecord_openwindow(url,hash)
{
        result = window.open(url, 'att' + hash,'width=1000,height=700,scrollbars=yes,titlebar=no,statusbar=no');

}

function attachment_openwindow(url,hash)
{
        result = window.open(url, 'att' + hash,'width=700,height=500,top=10,scrollbars=yes,titlebar=no,statusbar=no');

}

function toggle_collapse(obj)
   {
        obj0 = fetch_object(obj);
        if (obj0.style.display)
           {obj0.style.display='';}
        else
           {obj0.style.display='none';};
   }

function collapse_off(obj)
   {
        obj0 = fetch_object(obj);
        obj0.style.display='none';
        resize();
   }

function collapse_on(obj)
   {
        obj0 = fetch_object(obj);
        obj0.style.display='block';
   }

function EditorExecCommand( command_param,par,obj)
   {
        ob=fetch_object(obj);
        var tr = ob.document.selection.createRange();
        tr.select();
        tr.execCommand(command_param,false,par);
        ob.focus();
   }

function PutCommandButton (comm,val,par,scrfile,obj)
        {
                //document.write('<input UNSELECTABLE="on" type="button" onClick="EditorExecCommand(\''+comm+'\',\''+par+'\',\''+obj+'\');" value="'+val+'">');
                document.write('<input ONMOUSEOVER="javascript:lightbar(this,\'#ffffff\');" ONMOUSEOUT="javascript:unlightbar(this);" STYLE="border-left:solid 1 #fafafa;border-top:solid 1 #fafafa;border-bottom:solid 1 #fafafa;" UNSELECTABLE="on" type="image" src="/images/editor/'+scrfile+'.gif" onClick="EditorExecCommand(\''+comm+'\',\''+par+'\',\''+obj+'\');return false;" value="'+val+'">');
        }

function PutDivider ()
        {
                document.write('<IMG SRC="/images/editor/separator.gif" BORDER=0>');
        }


function put_buttons(f)
{
        PutCommandButton("Bold","B","","bold",f);
        PutCommandButton("Italic","I","","italic",f);
        PutCommandButton("Underline","U","","underline",f);
        PutDivider();
        PutCommandButton("JustifyLeft","Left","","justifyleft",f);
        PutCommandButton("JustifyCenter","Cen","","justifycenter",f);
        PutCommandButton("JustifyRight","Right","","justifyright",f);
        PutCommandButton("JustifyFull","Full","","justifyfull",f);
 //       PutCommandButton("JustifyNone","None","","justifynone",f);
        PutDivider();
        PutCommandButton("Outdent"," &laquo; ","","outdent",f);
        PutCommandButton("Indent"," &raquo; ","","indent",f);
        PutDivider();
        PutCommandButton("InsertOrderedList","OL","","insertorderedlist",f);
        PutCommandButton("InsertUnorderedList","UL","","insertunorderedlist",f);
        PutDivider();
        PutCommandButton("FormatBlock","h1","<H1>","h1",f);
        PutCommandButton("FormatBlock","h2","<H2>","h2",f);
        PutCommandButton("FormatBlock","h3","<H3>","h3",f);

        PutDivider();
}

function fill_attachments(obj,att,tbl,pv)
{

        obj=attachments;
        u=0;
        res="<TABLE WIDTH='100%' CLASS=tbl1><TR CLASS=hd1><TD WIDTH=30px>ID<TD WIDTH=*>Название<TD WIDTH='100px'>Имя файла<TD WIDTH='30px'>Тип<TD WIDTH='50px'>Размер<TD WIDTH=10%>Edit<TD WIDTH=10%>Delete<TR><TD>";

        for(i=0;i<att.length;i++)
        {
                u=1-u;
                res+="<TR STYLE='"+((u==0)?"":"background-color:white")+"'>";
                for(j=0;j<att[i].length;j++)
                   {
                        res+="<TD><A HREF='/attach.php?id="+att[i][0]+"' TARGET='_blank'>"+att[i][j]+"</A></TD>";
                   }
                res+="<TD><INPUT TYPE='button' STYLE='width:100%' VALUE='Ред.' ONCLICK='javascript:attachment_openwindow(\"index.php?id=cinemar_record_edit&table_name=data_attachments&params=addattach:2;table1:"+tbl+";parent_value:"+pv+"&value="+att[i][0]+"\",\"ea"+att[i][0]+"\")'>";
                res+="<TD><INPUT TYPE='button' STYLE='width:100%' VALUE='Уд.'>";
        }
        res+="</TABLE>";
        return res;
        alert("hi");
}

function toggleTADI(ta,ed,bt)
   {
        if (ta.style.display=="none")
           {
                ta.style.display="";
                ed.style.display="none";
                ta.value=ed.innerHTML;
                ta.style.height=ed.style.height;
                bt.value="ta";

           }
        else
           {
                ta.style.display="none";
                ed.style.display="";
                ed.innerHTML=ta.value;
                bt.value="html";

           }
   };

function resize(){
        var sizey=document.body.clientHeight ;
        var sizex=document.body.clientWidth ;
        obj = document.getElementById('mine');
        objs = document.getElementById('savebar');

        var d = 50;
        var sizexo = obj.offsetWidth;
        var mmm = Math.round ((sizex/2) - (sizexo/2));

        var mm = mmm + 'px';

        window.status= mm;

        obj.style.left = mm;
        objs.style.left = mm;

        obj.style.height=sizey-d;
        objs.style.top=sizey-d;


        //alert ("R");
};


function createXmlHttpRequestObject()
{
        var xmlHttp;
        if(window.ActiveXObject)
        {
                try {xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
                catch (e) {xmlHttp = false;}
        }
        else
        {
                try {xmlHttp = new XMLHttpRequest();}
                catch (e) {xmlHttp = false;}
        }
        if (!xmlHttp)
                alert("Error creating the XMLHttpRequest object.");
                else return xmlHttp;
}
