﻿function blockNonNumbers(obj, e, isDecimal) {
    var key;
    var keychar;
    if (window.event) {
        key = window.event.keyCode;
    }
    else if (e) {
        key = e.which;
    }
    else {
        return true;
    }
    keychar = String.fromCharCode(key);
    // control keys
    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27)) return true;
    if (isDecimal) {
        if (obj.value.indexOf(',') < 0) {
            if (("0123456789,").indexOf(keychar) > -1) return true;
        }
    }
    if (("0123456789").indexOf(keychar) > -1) return true;
    return false;
}

function trimString(sString) {
    while (sString.substring(0, 1) == ' ') {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length - 1, sString.length) == ' ') {
        sString = sString.substring(0, sString.length - 1);
    }
    return sString;
}


//----------------- panel ----------------
function ShowHide(divid) {
    var elem = document.getElementById(divid);
    if (elem.className == 'ddivhidden') {
        elem.className = 'ddivshown';
    } else {
        elem.className = 'ddivhidden';
    }
}


//-------------- file upload -------------
var uploadValidFlag;
var uploadCompleteFlag;
function UploadingProgressChanged(s, e) {
    pbProgressing.SetPosition(e.progress);
    var info = e.currentFileName + "&emsp;[" + GetKBytes(e.uploadedContentLength) + " / " + GetKBytes(e.totalContentLength) + "] KBytes";
    pnlProgressingInfo.SetContentHtml(info);
}
function FileUploadStart(s, e) {
    uploadValidFlag = true;
    uploadCompleteFlag = false;
    window.setTimeout("ShowPopupProgressingPanel()", 700);
}
function FileUploadComplete(s, e) {
    if (!e.isValid)
        uploadValidFlag = false;
}
function FilesUploadComplete(s, e) {
    uploadCompleteFlag = true;
    PopupProgressingPanel.Hide();
    if (uploadValidFlag)
        window.setTimeout("alert('File uploading has been successfully completed.')", 0);
}
function ShowPopupProgressingPanel() {
    if (!uploadCompleteFlag) {
        PopupProgressingPanel.Show();
        pbProgressing.SetPosition(0);
        pnlProgressingInfo.SetContentHtml("");
    }
}
function GetKBytes(bytes) {
    return Math.floor(bytes / 1024);
}
 
function imageopen(url){
	var holder = document.all? document.all["holder"] : document.getElementById("holder");
	var image = new Image;
	image.src = url;
	image.onload=function(){
		holder.style.backgroundImage = "url('"+url+"')";
		holder.style.left = (screen.width-image.width)/2+"px";
		holder.style.top = '10px';
		holder.style.height = image.height+"px";
		holder.style.width = image.width+"px";
		holder.style.border = '#FFFFFF solid 1px';
	}
	holder.style.backgroundImage = "url('"+url+"')";
	holder.style.left = (screen.width-image.width)/2+"px";
	holder.style.top = '10px';
	holder.style.height = image.height+"px";
	holder.style.width = image.width+"px";
	holder.style.border = '#FFFFFF solid 1px';
}
function closediv(){
	var holder = document.all? document.all["holder"] : document.getElementById("holder");
	holder.style.height = '0px';
	holder.style.width = '0px';
	holder.style.backgroundImage = "url('')"; 
	holder.style.border = 'none';
}
