﻿
function checkAll(chkAll) {
    var frm = document.forms[0];
    for (i = 0; i < frm.elements.length; i++) {
        if (frm.elements[i].type == "checkbox") {
            frm.elements[i].checked = chkAll.checked;
        }
    }
}

function checkDelete() {
    var frm = document.forms[0];
    var flg = false;
    for (i = 0; i < frm.elements.length; i++) {
        if (frm.elements[i].type == "checkbox") {
            if (frm.elements[i].id == 'chkAll') continue;
            if (frm.elements[i].checked) { flg = true;break;}
        }
    }
    if (flg == false) 
    {
        alert('Please select at least 1 item to delete');
        return false;
    }
    else
    {
        if (confirm('Are you sure to delete selected items')) 
        {
            return true;
        }
       
    }
    return false;
}

function checkDelete(messageConfirm) {
    var frm = document.forms[0];
    var flg = false;
    for (i = 0; i < frm.elements.length; i++) {
        if (frm.elements[i].type == "checkbox") {
            if (frm.elements[i].id == 'chkAll') continue;
            if (frm.elements[i].checked) { flg = true; break; }
        }
    }
    if (flg == false) {
        alert('Please select at least 1 item to delete');
        return false;
    }
    else {
        if (confirm(messageConfirm)) {
            return true;
        }

    }
    return false;
}

function sortList(id) {
var lb = document.getElementById(id);
arrTexts = new Array();

for(i=0; i<lb.length; i++) {
arrTexts[i] = lb.options[i].text;
}

arrTexts.sort();

for (i = 0; i < lb.length; i++) {
    lb.options[i].text = arrTexts[i];
    lb.options[i].value = arrTexts[i];
}
}


function openWindow(filename, winname, width, height) {
    var features, top, left;

    left = (window.screen.width - width) / 2;
    top = (window.screen.height - height) / 2;
    features = "width=" + width + ",height=" + height + ",top=" + top + ",left=" + left;
    void (window.open(filename, winname, features));
}

//openMeExt('Sendmail.aspx?Link='.concat(escape(location.href)), 0, 0, 0, 0, 0, 0, 1, 1, 480, 500, 0, 0, '', 0);
	
function openMeExt(vLink, vStatus, vResizeable, vScrollbars, vToolbar, vLocation, vFullscreen, vTitlebar, vCentered, vHeight, vWidth, vTop, vLeft, vID, vCounter) {
    var sLink = (typeof (vLink.href) == 'undefined') ? vLink : vLink.href;
    winDef = '';
    winDef = winDef.concat('status=').concat((vStatus) ? 'yes' : 'no').concat(',');
    winDef = winDef.concat('resizable=').concat((vResizeable) ? 'yes' : 'no').concat(',');
    winDef = winDef.concat('scrollbars=').concat((vScrollbars) ? 'yes' : 'no').concat(',');
    winDef = winDef.concat('toolbar=').concat((vToolbar) ? 'yes' : 'no').concat(',');
    winDef = winDef.concat('location=').concat((vLocation) ? 'yes' : 'no').concat(',');
    winDef = winDef.concat('fullscreen=').concat((vFullscreen) ? 'yes' : 'no').concat(',');
    winDef = winDef.concat('titlebar=').concat((vTitlebar) ? 'yes' : 'no').concat(',');
    winDef = winDef.concat('height=').concat(vHeight - 140).concat(',');
    winDef = winDef.concat('width=').concat(vWidth).concat(',');

    if (vCentered) {
        winDef = winDef.concat('top=').concat((screen.height - vHeight) / 2).concat(',');
        winDef = winDef.concat('left=').concat((screen.width - vWidth) / 2);
    }
    else {
        winDef = winDef.concat('top=').concat(vTop).concat(',');
        winDef = winDef.concat('left=').concat(vLeft);
    }

    if (typeof (vCounter) == 'undefined') {
        vCounter = 0;
    }

    if (typeof (vID) == 'undefined') {
        vID = 0;
    }

    if (vCounter) {
        sLink = buildLink(vID, sLink);
    }

    open(sLink, '_blank', winDef);

    if (typeof (vLink.href) != 'undefined') {
        return false;
    }
}

function getURL() {
    var url= window.location.href; 
    var ret;
    if (url.indexOf("?") > -1) 
    {
        ret = url.split("?");
        return ret[0];
    }
    else
        return url;

}

function isPhone(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46)
        return false;
    return true;
}
function isNumberKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
function RemovePrefix0(obj, defaultValue) {
    if (obj.value == "") obj.value = defaultValue;
    if (obj.value.length > 1 && obj.value.charAt(0) == "0") {
        temp = obj.value;
        temp = temp / 1;
        obj.value = temp;
    }
}

function changeLanguage(strMode) {
    //default get_var to chang : Lang=strMode
    strLocation = window.location.toString();
    strMode = strMode.toString();
    strLocation = strLocation.replace(strLocation.substring(strLocation.indexOf('#'), strLocation.indexOf('#') > 0 ? strLocation.length : 0), '');
    strLocation = strLocation.replace('&Lang=' + strLocation.charAt(strLocation.indexOf('&Lang=') + 6) + strLocation.charAt(strLocation.indexOf('&Lang=') + 7), '');
    strLocation = strLocation.replace('Lang=' + strLocation.charAt(strLocation.indexOf('Lang=') + 5) + strLocation.charAt(strLocation.indexOf('Lang=') + 6), '');
    if (strLocation.indexOf('?') > -1) {
        strLocation += '&Lang=' + strMode;
    }
    else {
        strLocation += '?Lang=' + strMode;
    }
    window.location = strLocation;
}
