/*
 * write embed tag for mac plugin
 */
function writeMacPlugin(){
    if( navigator.userAgent.match(/Mac|PPC/)){
        document.write( "<embed name='PrintCreationsPlugin' width='0' height='0' type='application/x-PrintWebkit'></embed>" );
    }
}

/*
 * write object tag for windows plugin
 */
function writeIEPlugin(){
    document.write('<OBJECT codeBase="' + document.getElementById('win_plugin_url1').href +'#version=2,2,255,181" ');
    document.write('id="heatax" height="600" width="800" data="data:application/x-oleobject;base64,xA3DyyjPm06QNm4IaiUTmgADAACvUgAAAz4AAA==" classid="clsid:CBC30DC4-CF28-4E9B-9036-6E086A25139A" name="heatax" VIEWASTEXT>');
    document.write('<div class="noactivex">');
    document.write('<SPAN STYLE="color:red">您需要安装ActiveX控件来使用Brother CreativeCenter。请关闭此窗口，并返回到上一页安装ActiveX控件。<\/SPAN>');
    document.write('<br/><br/><a href="#" class="si-cn-close" onClick="window.close(); return false;"></a>');
    document.write('</div>');
    document.write('<\/OBJECT>');
}

/*
 * edit operation for mac
 */
function download(url,prjid,prjName)
{
// 2007/10/30 Ins Y.Yamada ---------------------------------
    var plugin  = document.embeds["PrintCreationsPlugin"];
    var version = plugin.getVersion();
    var nowVersion = "2.2.255.181";
    if(version != nowVersion)
    {
        alert("你已经安装了最新版本的Print Creations Plug-In程序");
    }else{
        plugin._imageURL = url;
        plugin._prjID = prjid;
        plugin._prjName = prjName;
        plugin.startTemplateDownload();
    }
/* 2007/10/30 Del Y.Yamada ---------------------------------
    var plugin  = document.embeds["PrintCreationsPlugin"];

    plugin._imageURL = url;
    plugin._prjID = prjid;
    plugin._prjName = prjName;
    plugin.startTemplateDownload();
-- 2007/10/30 End Y.Yamada -------------------------------*/
    //alert(plugin.getPrintPaperNum());
}


/*
 * 
 */
function ShowPage()
{
    var userAgent = navigator.userAgent;

    if( navigator.platform == "Win32" )
    {

    }
    //else if( document.getElementById("idIsMac").value =="1" )
    else if( userAgent.match(/Mac|PPC/))
    {
            var plugin  = document.embeds["PrintCreationsPlugin"];
        alert("The printed page(s) number is " + plugin.getPrintPaperNum());
    }
}


/*
 * display edit screen
 */
function showDialog(templates, classcode, fileDirMac)
{
    var userAgent = navigator.userAgent;
    if( navigator.platform == "Win32" )
    {
        if( userAgent.indexOf("MSIE")>=1 )
        {
// 2007/10/31 Ins Y.Yamada ---------------------------------
                var hei = 825;
                var wid = 830;

                if(hei > screen.avilHeight){hei = screen.avilHeight;}
                if(wid > screen.avilWidth){wid = screen.avilWidth;}
/* 2007/10/30 Del Y.Yamada ---------------------------------
                var hei = 780;
                var wid = 830;

                if(hei > screen.height){hei = screen.height;}
                if(wid > screen.width){wid = screen.width;}
-- 2007/10/30 End Y.Yamada -------------------------------*/
                var showURL = "";
                showURL = showURL + "../../../compose/index.htm";

                var dialogPram = "";
                dialogPram = dialogPram + "dialogHeight:" + hei + "px;";
                dialogPram = dialogPram + "dialogWidth:" + wid + "px;";
                dialogPram = dialogPram + "center:yes;";
                dialogPram = dialogPram + "scroll:yes;";
                dialogPram = dialogPram + "status:no;";
                dialogPram = dialogPram + "help:no;";
                dialogPram = dialogPram + "resizable:yes;";
                dialogPram = dialogPram + "dependent:yes;";
                
                window.showModalDialog(showURL, self, dialogPram);
                
        }
        else
        {
            alert("这个站点需要IE6或更高版本");
        }
    }
    else if( userAgent.match(/Mac|PPC/))
    {
        if( userAgent.indexOf("Safari")>=1 )
        {
            download(templates,classcode,fileDirMac);
        }
        else
        {
            alert("这个站点需要Safari 1.4或更高版本");
        }
    }
    else
    {
        alert("这个站点需要安装Windows或Mac OS");
    }

}


/*
 * initialize ActiveX object
 */
function init()
 {
     try
     {
        var obj = document.all("heatax");
        if( window.dialogArguments != undefined && window.dialogArguments.file != undefined && window.dialogArguments.pattern != undefined ){
            //alert( window.dialogArguments.file );
            obj.IStartup(window.dialogArguments.file, window.dialogArguments.pattern, "");
        }
    }
    catch(e)
    {
        //window.setTimeout("AutoClose()",5000);
    }
}

/*
 * 
 */
function ShowPrintedPages()
{
        var obj = document.all("heatax");
        if( null != obj )
        {
            alert( "The printed page(s) number is " + obj.nPrintedPages );
            //alert( obj.OutPutPages("") );
        }
}


/*
 * auto window close function 
 */
function AutoClose()
{
    window.close();
}
