﻿//--- Design & Code by VietVo - vietvo.btr@gmail.com


function ds_isEmailAddress_Validator(val) {
    var patternEmail = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return patternEmail.test(val);
}
function ds_isPhone_Validator(val) {
    var patternPhone = new RegExp(/^(((\(\+\d+\))|(\+\d+))(-|\.|\s)+)?(\d|-|\.|\s){6,16}$/i);
    return patternPhone.test(val);
}
function ds_isIDNumber_Validator(val) {
    var patternPhone = new RegExp(/^(\d|\s){9,11}$/i);
    return patternPhone.test(val);
}
function ds_changeLanguage(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;
}
function ds_check_form_submit() {   
    frm = document.forms[0];
    for (i = 0; i < frm.elements.length; i++) {       
        ef = frm.elements[i];
        if (ef.className.indexOf('require_value') >= 0) {
            if (ef.value == '') {
                ef.focus();
                ef.select();
                return false;
            }
        }
        if (ef.className.indexOf('require_select') >= 0) {
            if (ef.value == '' || ef.value == '-1') {
                ef.focus();               
                return false;
            }
        }

    }
    return true;
}
function ds_check_form_submit_obj(frm) {    
    for (i = 0; i < frm.elements.length; i++) {
        ef = frm.elements[i];
        if (ef.className.indexOf('require_value') >= 0) {
            if (ef.value == '') {
                ef.focus();
                ef.select();
                return false;
            }
        }
        if (ef.className.indexOf('require_select') >= 0) {
            if (ef.value == '' || ef.value == '-1') {
                ef.focus();
                return false;
            }
        }

    }
    return true;
}
function ds_check_form_submit_method_admin(error) {
    frm = document.forms[0];
    for (i = 0; i < frm.chkID.length; i++) {       
        if ( frm.chkID[i].checked) {
            return true;
        }
    }
    alert(error);
    return false;
}
function ds_check_form_submit_number() {
    frm = document.forms[0];
    for (i = 0; i < frm.elements.length; i++) {
        ef = frm.elements[i];
        if (ef.className.indexOf('require_value') >= 0) {
            if (ef.value == '') {
                ef.focus();
                ef.select();
                return false;
            }
        }
        if (ef.className.indexOf('require_select') >= 0) {
            if (ef.value == '' || ef.value == '-1') {
                ef.focus();
                return false;
            }
        }
        if (ef.className.indexOf('require_number') >= 0) {
            if (!ds_isNumber(ef.value)) {
                ef.focus();
                return false;
            }
        }
        if (ef.className.indexOf('require_none_negative') >= 0) {
            if (!ds_isNumber_NoneNegative(ef.value)) {
                ef.focus();
                return false;
            }
        }
        if (ef.className.indexOf('require_greater_than_zero') >= 0) {
            if (!ds_isNumber_GreaterThanZero(ef.value)) {
                ef.focus();
                return false;
            }
        }
    }
    return true;
}
function ds_check_form_submit_checkall(val) {
    frm = document.forms[0];
    for (i = 0; i < frm.chkID.length; i++) {
        frm.chkID[i].checked=val;        
    }
}
function ds_ranPass(size) {
    chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz!@#$%^&*_+=-~`:;'<>,.?";   
    randomstring = '';
    for (i = 0; i < size; i++) {
        rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum, rnum + 1);
    }
    return randomstring;
}

