﻿function trimLeft(str) {
    if (str == null) { return null; }
    for (var i = 0; str.charAt(i) == " "; i++);
    return str.substring(i, str.length);
}
function trimRight(str) {
    if (str == null) { return null; }
    for (var i = str.length - 1; str.charAt(i) == " "; i--);
    return str.substring(0, i + 1);
}
function trim(str) { return trimLeft(trimRight(str)); }
function trimLeftAll(str) {
    if (str == null) { return str; }
    for (var i = 0; str.charAt(i) == " " || str.charAt(i) == "\n" || str.charAt(i) == "\t"; i++);
    return str.substring(i, str.length);
}
function trimRightAll(str) {
    if (str == null) { return str; }
    for (var i = str.length - 1; str.charAt(i) == " " || str.charAt(i) == "\n" || str.charAt(i) == "\t"; i--);
    return str.substring(0, i + 1);
}
function replaceAll(varb, replaceThis, replaceBy) {
    newvarbarray = varb.split(replaceThis);
    newvarb = newvarbarray.join(replaceBy);
    return newvarb;
}
function trimAll(str) {
    return trimLeftAll(trimRightAll(str));
}
// isNull(value)
//   Returns true if value is null
function isNull(val) { return (val == ""); }

// isBlank(value)
//   Returns true if value only contains spaces
function isBlank(val) {
    return isNull(trimAll(val));
}

// isInteger(value)
//   Returns true if value contains all digits
function isInteger(val) {
    if (isBlank(val)) { return false; }
    for (var i = 0; i < val.length; i++) {
        if (!isDigit(val.charAt(i))) { return false; }
    }
    return true;
}

// isNumeric(value)
//   Returns true if value contains a positive float value
function isNumeric(val) { return (parseFloat(val) == (val * 1) && parseFloat(val) >= 0); }

// isArray(obj)
// Returns true if the object is an array, else false
function isArray(obj) { return (typeof (obj.length) == "undefined") ? false : true; }

// isDigit(value)
//   Returns true if value is a 1-character digit
function isDigit(num) {
    if (num.length > 1) { return false; }
    var string = "1234567890";
    if (string.indexOf(num) != -1) { return true; }
    return false;
}

// setNullIfBlank(input_object)
//   Sets a form field to "" if it isBlank()
function setNullIfBlank(obj) { if (isBlank(obj.value)) { obj.value = ""; } }

//Basic function added
//return true if the string is valid email string
function isEmailChar(str) {
    for (i = 0; i < str.length; i++) {
        c = str.charAt(i);
        if ("~!#$%^&*(),\'`:\;?<>=+\n\t \\\"".indexOf(c, 0) > 0)
            return false;
    }
    return true;
}

//return true if the parts of email are valid
function isValidEmail(email) {

    var array = email.split("@");
    if (array.length != 2) return false;
    var first, last;
    first = array[0]; last = array[1];
    if (first.charAt(0) == '.') return false;
    if (first.charAt(first.length) == '.') return false;
    if (last.charAt(0) == '.') return false;
    if (first == "" || last == "") return false;
    first = trimLeftAll(first);
    last = trimRightAll(last);
    if (!isEmailChar(first) || !isEmailChar(last))
        return false;
    return true;
}

// return true if number is in range of number
function isInRangeOfNumber(number, from, to) {
    if (from <= number && number <= to)
        return true;
    return false;
}

// round by type
// type="L": lowerRound. Ex: roundEx(1.255, 2, "L") = 1.25
// type="U": upperRound. Ex: roundEx(1.254, 2, "U") = 1.26
// type=others:  Ex:roundEx(1.255, 2, "") = 1.26

var DEFAULT_ROUND_TYPE = "L";
function roundEx(val, digit, type) {
    var result = val;
    if (type == "L")
        result = lowerRound(val, digit);
    else if (type == "U")
        result = upperRound(val, digit);
    else
        result = round(val, digit);
    return result;
}

// return round number. Ex: lowerRound(1.255, 2) = 1.26
function round(number, digits) {
    var num = Math.pow(10, digits);
    var result = Math.round(number * num);
    result = result / num;
    return result;
}

// return round number. Ex: upperRound(1.254, 2) = 1.26
function upperRound(number, digits) {
    var num = Math.pow(10, digits);
    num = num + 0.5;
    var result = Math.round(number * num);
    result = result / num;
    return result;
}

// return round number. Ex: lowerRound(1.256, 2) = 1.25
function lowerRound(number, digits) {
    var num = Math.pow(10, digits);
    var result = parseInt(number * num);
    result = result / num;
    return result;
}
//return true if the ENTER key is pressed
function isEnterPressed(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3)
        return true;
    return false;
}
function txt_copy(txtFrom, txtTo) {
    txtTo.value = txtFrom.value;
}
// File chondat.js
function DefineBrowser() {
    // Neu trinh duyet la IE thi return "IE"
    // Neu trinh duyet la FireFox thi return "FF"

    return checkbrowser();
}
function checkbrowser() {

    var browsertype = navigator.userAgent.toLowerCase(); 
    if (browsertype.indexOf('msie') != -1) {
        
        browser = 'isIE';
        return browser;
    }
    else if (browsertype.indexOf('netscape') != -1) {
        browser = 'isNS';
        return browser;
    }
    else if (browsertype.indexOf('safari') != -1) {
        browser = 'isSF';
        return browser;
    }
    else if (browsertype.indexOf('gecko') != -1) {
        browser = 'isFF';
        return browser;
    }
}

function setMessage(divmassage, url) {

    var message = document.getElementById(divmassage)
    message.style.display = '';
    setTimeout("javascript:window.location='" + url + "';", 500);
}


// play movie file
function PlayFile(strSource, ctlID) {
    var width = 300;
    var height = 300;
    var s;
    if (strSource.indexOf(".flv") > 0 || strSource.indexOf(".mp4") > 0) {
        s = " <object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' ";
        s += " codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0' ";
        s += " width='" + width + "' ";
        s += " height='" + height + "' ";
        s += " bgcolor='#FFFFFF'>";
        s += " <param name='movie' value='images/FLVscrubber2.swf?file=" + strSource + "&bufferTime=3&autoStart=true'/>";
        s += " <param name='quality' value='high' />";
        s += " <param name='allowScriptAccess' value='sameDomain'/>";
        s += " <param name='allowFullScreen' value='true'/>";
        s += " <embed src='images/FLVscrubber2.swf?file=" + strSource + "&bufferTime=3&autoStart=true&loop=true'";
        s += " quality='high' allowScriptAccess='sameDomain' pluginspage='http://www.macromedia.com/go/getflashplayer'";
        s += " type='application/x-shockwave-flash'  width='" + width + "' height='" + height + "' style='background-color:#FFFFFF' />";
        s += " </object>";
    }
    else {
        s = "<OBJECT id=winMediaPlayerID ";
        s += "codeBase=http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715 ";
        s += "type=application/x-oleobject height=" + height + " ";
        s += "standby=\"Loading Microsoft Windows Media Player components...\" ";
        s += "width=" + width + " classid=CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6 ";
        s += "name=winMediaPlayerID>";
        s += "<PARAM NAME=\"URL\" VALUE=\"" + strSource + "\"> ";
        s += "<PARAM NAME=\"rate\" VALUE=\"1\">";
        s += "<PARAM NAME=\"balance\" VALUE=\"0\">";
        s += "<PARAM NAME=\"currentPosition\" VALUE=\"0\">";
        s += "<PARAM NAME=\"defaultFrame\" VALUE=\"0\">";
        s += "<PARAM NAME=\"playCount\" VALUE=\"999\">";
        s += "<PARAM NAME=\"CursorType\" VALUE=\"-1\">";
        s += "<PARAM NAME=\"autoStart\" VALUE=\"1\">";
        s += "<PARAM NAME=\"autoplay\" VALUE=\"1\">";
        s += "<PARAM NAME=\"currentMarker\" VALUE=\"0\">";
        s += "<PARAM NAME=\"invokeURLs\" VALUE=\"-1\">";
        s += "<PARAM NAME=\"volume\" VALUE=\"50\">";
        s += "<PARAM NAME=\"mute\" VALUE=\"0\">";
        s += "<PARAM NAME=\"stretchToFit\" VALUE=\"-1\">";
        s += "<PARAM NAME=\"windowlessVideo\" VALUE=\"0\">";
        s += "<PARAM NAME=\"enabled\" VALUE=\"1\">";
        s += "<PARAM NAME=\"fullScreen\" VALUE=\"0\">";
        s += "<PARAM NAME=\"enableContextMenu\" VALUE=\"0\">";
        s += "<PARAM NAME=\"enableErrorDialogs\" VALUE=\"0\"> \n";

        s += "<Embed id='winMediaPlayerIDFF' type='application/x-mplayer2' pluginspage='http://www.microsoft.com/windows/windowsmedia/download/' filename='" + strSource + "' src='" + strSource + "' Name='winMediaPlayerIDFF' ";
        s += "width='" + width + "' ";
        s += "height='" + height + "' ";
        s += "AutoSize='1' ";
        s += "AutoStart='1' ";
        s += "AutoPlay='1' ";
        s += "ClickToPlay='1' ";
        s += "DisplaySize='1' ";
        s += "EnableContextMenu='0' ";
        s += "EnableFullScreenControls='1' ";
        s += "EnableTracker='1' ";
        s += "Mute='0' ";
        s += "PlayCount='999' ";
        s += "ShowControls='1' ";
        s += "ShowAudioControls='1' ";
        s += "ShowDisplay='0' ";
        s += "ShowGotoBar='0' ";
        s += "ShowPositionControls='1' ";
        s += "ShowStatusBar='1' ";
        s += "ShowTracker='1'> ";
        s += "</embed> ";
        s += "</OBJECT>";
    }
    ctlID.innerHTML = s;
}
function OpenPopUp(url,name,width,height) {
    var x = (window.screen.width - width) / 2;
    var y = (window.screen.height - height) / 2;
    var windowAttr = 'menubar=no,status=yes,resizable=no,scrollbars=yes,toolbar=no,width=' + width + ',top=' + y + ',height=' + height + ',left=' + x;
    window.open(url, name, windowAttr);
    return false;
//window.open('http://www.pageresource.com/jscript/jex5.htm','mywindow','width=400,height=200,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes') 

}
//get valu query string
function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i = 0; i < gy.length; i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji)
            return ft[1];

    }
}
function ClickImage(folder, imageSource, index, group, matin) {


    //get current index
    var current = 1;
    for (var i = 1; i <= 5; i++) {
        var currentLinkSelect = document.getElementById('div_' + group + '_' + matin + '_' + i);
        if (currentLinkSelect) {
            if (currentLinkSelect.className == 'pic_icon_ac') {
                current = i;
                break;
            }
        }
    }
    var indexShow = folder;
    //get index image is show
    var arrImage = new Array();
    arrImage = imageSource.split('|');
    indexShow = indexShow + arrImage[index - 1].toString();

    document.getElementById('img_' + group + '_' + matin).src = indexShow;
    document.getElementById('lnk_' + group + '_' + matin + '_' + current).className = 'link_photo';
    document.getElementById('lnk_' + group + '_' + matin + '_' + current).style.cursor = '';
    document.getElementById('div_' + group + '_' + matin + '_' + current).className = 'pic_icon';


    document.getElementById('lnk_' + group + '_' + matin + '_' + index).className = 'link_photo';
    document.getElementById('div_' + group + '_' + matin + '_' + index).className = 'pic_icon_ac';
    document.getElementById('lnk_' + group + '_' + matin + '_' + index).style.cursor = 'default';

}
/// <reference path="../ChangePassword.aspx" />
 function OpenPopupSendToFriend(matindang,maloaitd) {
            var w = 595;
            var h = 600;
            var wleft = (screen.width - w) / 2;
            var wtop = (screen.height - h) / 2;
            // IE5 and other old browsers might allow a window that is
            // partially offscreen or wider than the screen. Fix that.
            // (Newer browsers fix this for us, but let's be thorough.)
            if (wleft < 0) {
                w = screen.width;
                wleft = 0;
            }
            if (wtop < 0) {
                h = screen.height;
                wtop = 0;
            }
            var pURL = 'Popup/SendToFriend.aspx?matd=' + matindang + '&loaitd=' + maloaitd ;
            //var pURL='map.html';
            pInfo = 'toolbar=0,';
            pInfo += 'location=0,';
            pInfo += 'directories=0,';
            pInfo += 'status=0,';
            pInfo += 'menubar=0,';
            pInfo += 'scrollbars=1,';
            pInfo += 'resizable=0,';
            pInfo += 'width=' + w + 'px,';
            pInfo += 'height=' + h + 'px,';
            pInfo += 'left=' + wleft + ',';
            pInfo += 'top=' + wtop + ',';
            pInfo += 'text-align:center';
            window.open(pURL, 'SendToFriend', pInfo, true);
        }
        function OpenPopupContact(matindang) {
            var w =950;
            var h = 630;
            var wleft = (screen.width - w) / 2;
            var wtop = (screen.height - h) / 2;
            // IE5 and other old browsers might allow a window that is
            // partially offscreen or wider than the screen. Fix that.
            // (Newer browsers fix this for us, but let's be thorough.)
            if (wleft < 0) {
                w = screen.width;
                wleft = 0;
            }
            if (wtop < 0) {
                h = screen.height;
                wtop = 0;
            }
            var pURL = 'Popup/Contact.aspx?id=' + matindang;
            //var pURL='map.html';
            pInfo = 'toolbar=0,';
            pInfo += 'location=0,';
            pInfo += 'directories=0,';
            pInfo += 'status=0,';
            pInfo += 'menubar=0,';
            pInfo += 'scrollbars=1,';
            pInfo += 'resizable=0,';
            pInfo += 'width=' + w + 'px,';
            pInfo += 'height=' + h + 'px,';
            pInfo += 'left=' + wleft + ',';
            pInfo += 'top=' + wtop + ',';
            pInfo += 'text-align:center';
            window.open(pURL, 'Contact', pInfo, true);
        }
        function setSelectionRange(ctr,lstPopupError) {
          
            var inputField = ctr;
            if (inputField != null && inputField.value.length > 0) {
                if (inputField.createTextRange) {
                    var FieldRange = inputField.createTextRange();
                    FieldRange.moveStart('character', inputField.value.length);
                    FieldRange.collapse();
                    FieldRange.select();
                }
            }
//            if (DisFocus('eMessagePopupLogin,eMessagePopupSearch,eMessagePopupContactUS'))
//            ctr.blur();
            //DisFocus(ctr, 'eMessagePopupLogin,eMessagePopupSearch,eMessagePopupContactUS');
        }

        function CancelTabKey(evt) {
          
            evt = (evt || window.event);
            key = (evt.keyCode || evt.charCode || evt.which || 0);
            if (key == 9) {
                if (checkbrowser() == 'isIE')
                    evt.returnValue = false;
                else {
                    evt.preventDefault();
                    evt.stopPropagation();
                }
            }
        }
        function DisableParentForm(btn) {
          
            document.getElementById(btn).onkeydown = CancelTabKey;

        }
      
 


