﻿//=======================================================================
// Name     : FileUploadManager
// Author   : TienPQ
// Date     : 2007/11/05
//=======================================================================
function FileUploadManager(objID, codeBase, width, height, classID) {
    if (width == "") width = 400;
    if (height == "") height = 300;

    document.write('<table style="width:' + width + '"><tr><td align="right">');

    document.write('<input type="button" onclick="return ' + objID + '_AddFile();" value="Add Files" />');
    document.write('<input type="button" onclick="return ' + objID + '_AddFolder();" value="Add Folder" />');
    document.write('<input type="button" onclick="return ' + objID + '_RemovewFile();" value="RemoveFile" />');
    document.write('<input type="button" onclick="return ' + objID + '_RemoveAll();" value="RemoveAll" />');
    
    document.write('</td></tr><tr><td>');

    document.write("<OBJECT id='" + objID + "' codeBase='" + codeBase + "' width='" + width + "' height='" + height + "' classid='" + classID + "'>");
    document.write("<param name='UploadURL' value='http://vnshare.vn/FileUpload/DirectoryUpload.aspx'>");
    document.write("<param name='SerialKey' value=''>");
    document.write("</OBJECT>");

    document.write('</td></tr></table>');

    document.write('<script type="text/javascript">');
    
    document.write('function ' + objID + '_AddFile() {');
    document.write("var obj = document.getElementById('" + objID + "');");
    document.write(' if (obj != null) {obj.ShowAddFilesDialog();}}');

    document.write('function ' + objID + '_AddFolder() {');
    document.write("var obj = document.getElementById('" + objID + "');");
    document.write(' if (obj != null) {obj.ShowAddFolderDialog();}}');

    document.write('function ' + objID + '_RemovewFile() {');
    document.write("var obj = document.getElementById('" + objID + "');");
    document.write(' if (obj != null) {obj.RemoveSelectedFiles();}}');


    document.write('function ' + objID + '_RemoveAll() {');
    document.write("var obj = document.getElementById('" + objID + "');");
    document.write(' if (obj != null) {obj.RemoveAllFiles();}}');

    document.write('</script>');
}

function AddParamPowUpload(p_objID, p_isUploadStruct, p_saveFilePath) {

//    window.open('/FileUpload/FileUploadMonitor.aspx?FileUploaderID=' + p_objID);
    
    var powUpload = document.getElementById(p_objID)
    powUpload.RemoveAllFormItems()
    for (i = 0; i < powUpload.FileCount; i++) {
        var file = powUpload.GetItem(i);
        var filename = file.FullName
        powUpload.AddFormItem("CreationTime_" + i, file.CreationTime);
        powUpload.AddFormItem("LastAccessTime_" + i, file.LastAccessTime);
        powUpload.AddFormItem("LastWriteTime_" + i, file.LastWriteTime);
        powUpload.AddFormItem("SelectedPath_" + i, file.SelectedPath);
    }
    powUpload.AddFormItem("UploadStructure", p_isUploadStruct);
    powUpload.AddFormItem("SaveFilePath", p_saveFilePath);
}

function FileUploadMonitor(objID, codeBase, width, height, classID) {
    document.write("<OBJECT id='" + objID + "' codeBase='" + codeBase + "' width='" + width + "' height='" + height + "' classid='" + classID + "' VIEWASTEXT></OBJECT>");
}



function getX() {
    if (document.all) return (window.document.body.clientWidth + 10)
    else if (document.getElementById) return window.top.outerWidth;
    else return window.top.outerWidth - 12;
}

function getY() {
    if (document.all) return (window.top.document.body.clientHeight + 29)
    else if (document.getElementById) return window.top.outerHeight;
    else return window.top.outerHeight - 31;
}

function CenterWindow() {
    var width = window.screen.availWidth;
    var height = window.screen.availHeight;
    var x = window.getX();
    var y = window.getY();

    window.moveTo((width - x) / 2, (height - y) / 2);

    window.focus();
}

function WindowOpen(url, title, width, height, scrollbars) {
    var screenWidth = window.screen.availWidth;
    var screenHeight = window.screen.availHeight;

    var top = (screenHeight - height - 20) / 2;
    var left = (screenWidth - width) / 2;

    title = window.open(url, title, 'top = ' + top + ', left = ' + left + ',width=' + width + ', height=' + height + ', resizable=no, status=yes, toolbar=no, menubar=no, scrollbars=' + scrollbars);
    title.focus();
}

function WindowShowModalDialog(url, title, width, height) {
    var screenWidth = window.screen.availWidth;
    var screenHeight = window.screen.availHeight;

    var top = (screenHeight - height - 20) / 2;
    var left = (screenWidth - width) / 2;

    window.showModalDialog(url, title, 'dialogWidth=' + width + 'px;dialogHeight=' + height + 'px;center:Yes;help:No;resizable:No;status:No;');
}


function WindowOpenResize(p_url, p_title, p_top, p_left, p_width, p_height, p_resize, p_scrollbars) {
    if (p_top == '') {
        var screenHeight = window.screen.availHeight;
        var top = (screenHeight - height - 20) / 2;
    }
    else
        top = p_top;

    if (p_left == '') {
        var screenWidth = window.screen.availWidth;
        var left = (screenWidth - width) / 2;
    }
    else
        left = p_left;

    title = window.open(p_url, p_title, 'top = ' + top + ', left = ' + left + ',width=' + p_width + ', height=' + p_height + ', resizable=' + p_resize + ', status=yes, toolbar=no, menubar=no, scrollbars=' + p_scrollbars);
    title.focus();
}

function WindowResize(width, height) {
    var screenWidth = window.screen.availWidth;
    var screenHeight = window.screen.availHeight;

    var top = (screenHeight - height - 20) / 2;
    var left = (screenWidth - width) / 2;

    window.resizeTo(width, height);
    window.moveTo(left, top);
    window.focus();
}

function PageMoveValid(p_movePageControl, p_totalPage) {
    if (p_movePageControl.value.length == 0)
        return false;

    if ((p_movePageControl.value > p_totalPage) ||
		p_movePageControl.value == 0 ||
		!p_movePageControl.value.trim().isnumber())
        return false;

    return true;
}

function SetFocusOnEnter(e, btn) {
    var keynum;
    if (window.event) // IE
        keynum = e.keyCode;
    else if (e.which) // Netscape/Firefox/Opera
        keynum = e.which;

    if (keynum == 13) {
        document.getElementById(btn).click();
        return true;
    }
}

function flashObject(file, width, height) {
    document.write("<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0' width='" + width + "' height='" + height + "'>");
    document.write("<param name=movie value='" + file + "'>");
    document.write("<param name=quality value=high>");
    document.write("<param name='wmode' value='Transparent' />");
    document.write("<embed src='" + file + "' quality=high pluginspage='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='" + width + "' height='" + height + "'>");
    document.write("</embed></object>");
}