﻿// JScript 文件

function OpenWindow(url, name, width, height) {
    var iTop = (window.screen.height - height) / 2;
    var iLeft = (window.screen.width - width) / 2;
    window.open(url, name, "Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=yes,Width=" + width + " ,Height=" + height + ",top=" + iTop + ",left=" + iLeft);
}

function OpenModalDialog(url, args, w, h) {
    var return_Value = window.showModalDialog(url, args, "dialogWidth:" + w + ";dialogHeight:" + h + ";help:no;scroll:yes;center:yes;toolbar=no,location=no,resizable:no;status:no;");
    return return_Value;
}

function win_back_return(strText) {
    window.returnValue = strText;
    window.close();
}

function OpenUpFileWin_SingleImageFile(UpFileUrl, ParentID, hidImageUrlID, UpFileType, UpFilePath, UpFileMaxLength) {
    var url = "";
    url = UpFileUrl + "?ParentID=" + escape(ParentID) + "&FileType=SingleImageFile&UpFileType=" + escape(UpFileType) + "&UpFilePath=" + escape(UpFilePath) + "&UpFileMaxLength=" + escape(UpFileMaxLength);
    var return_value = OpenModalDialog(url, window, '600px', '250px');
    if (return_value != null) {
        document.getElementById(hidImageUrlID).value = return_value;
    }
    return true;
}

function OpenUpFileWin_AttFile(UpFileUrl, ParentID, hidCurrentAllFileLengthID, UpFileType, UpFilePath, CurrentAllFileLength, AllFileLength, UpFileMaxLength) {
    var url = "";
    url = UpFileUrl + "?ParentID=" + escape(ParentID) + "&FileType=AttFile&UpFileType=" + escape(UpFileType) + "&UpFilePath=" + escape(UpFilePath) + "&CurrentAllFileLength=" + CurrentAllFileLength + "&AllFileLength=" + escape(AllFileLength) + "&UpFileMaxLength=" + escape(UpFileMaxLength);
    var return_value = OpenModalDialog(url, window, '600px', '450px');
    if (return_value != null) {
        document.getElementById(hidCurrentAllFileLengthID).value = return_value;
    }
    return true;
}

function OpenUpFileWin_AttFile_NetWork(ParentID, AttSign, hidCurrentAllFileLengthID, UpFileType, UpFilePath, CurrentAllFileLength, AllFileLength, UpFileMaxLength) {
    var url = "";
    url = "/Modules/UpFile/UpFile_NetWork.aspx?ParentID=" + escape(ParentID) + "&AttSign=" + escape(AttSign) + "&UpFileType=" + escape(UpFileType) + "&UpFilePath=" + escape(UpFilePath) + "&CurrentAllFileLength=" + CurrentAllFileLength + "&AllFileLength=" + escape(AllFileLength) + "&UpFileMaxLength=" + escape(UpFileMaxLength);
    var return_value = OpenModalDialog(url, window, '600px', '450px');
    if (return_value != null) {
        document.getElementById(hidCurrentAllFileLengthID).value = return_value;
    }
    return true;
}

function OpenUpFileWin_UpImageData(UpFileUrl, ParentID, UpFileType, UpFileMaxLength) {
    var url = "";
    url = UpFileUrl + "?ParentID=" + escape(ParentID) + "&UpFileType=" + escape(UpFileType) + "&UpFileMaxLength=" + escape(UpFileMaxLength);
    var return_value = OpenModalDialog(url, window, '600px', '450px');
    return true;
}

function OpenUpFileWin_DocumentDatum(UpFileUrl, DocumentID, ProjectID, DatumID, UpFileType, UpFileMaxLength) {
    var url = "";
    url = UpFileUrl + "?DocumentID=" + escape(DocumentID) + "&ProjectID=" + escape(ProjectID) + "&DatumID=" + escape(DatumID) + "&UpFileType=" + escape(UpFileType) + "&UpFileMaxLength=" + escape(UpFileMaxLength);
    var return_value = OpenModalDialog(url, window, '600px', '450px');
    return true;
}

function SelectAllCheckboxes(spanChk) {

    // Added as ASPX uses SPAN for checkbox
    var oItem = spanChk.children;
    var theBox = (spanChk.type == "checkbox") ?
        spanChk : spanChk.children.item[0];
    xState = theBox.checked;
    elm = theBox.form.elements;

    for (i = 0; i < elm.length; i++)
        if (elm[i].type == "checkbox" &&
              elm[i].id != theBox.id) {
        //elm[i].click();
        if (elm[i].checked != xState)
            elm[i].click();
        //elm[i].checked=xState;
    }
}

function GetPortalContentByAjax(URL, ListControlID) {
    return new Ajax.Updater({ success: ListControlID }, URL, { asynchronous: true, method: 'post', evalScripts: true });
}

//操作文本编辑器
function SetFckEdit(FckName, SetValue) {
    var oEditor = FCKeditorAPI.GetInstance(FckName);
    oEditor.InsertHtml(SetValue);
}


//处理验证码
function getValidImg(PageUrl, ObjName) {
    var PageUrl = PageUrl + '?validid=' + selectFrom(1, 1000);
    document.getElementById(ObjName).src = PageUrl;
    document.getElementById(ObjName).style.display = 'block';
    return false;
}

function selectFrom(iFirstValue, iLastValue) {
    var iChoces = Math.abs(iLastValue - iFirstValue) + 1;
    return Math.floor(Math.random() * iChoces + iFirstValue);
}

