﻿/**********************************************************************
* Communication & Information Services (www.cis.com.vn)
* Author : SonP (sonpm@cis.com.vn)
* History: 20/10/2007 Created
**********************************************************************/
/*** CROSS-BROWSER COMPATIBILITY ***/
var isIE = (navigator.userAgent.indexOf("MSIE")>=0? true: false);
var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var isDyn = (isDOM || isIE4 || isNS4);

function getRef(id) {
    if (isDOM) return document.getElementById(id);
    if (isIE4) return document.all[id];
    if (isNS4) return document.layers[id];
}

function getSty(id) {
    return (isNS4 ? getRef(id) : getRef(id).style);
}

function getBrowser() {
    if (navigator.userAgent.indexOf("MSIE")!=-1)
        return 0;
    if (navigator.userAgent.indexOf("Firefox")!=-1)
        return 1;
    return -1;
}

function setCookie(name, value, days) {
    try {
	    var expires;
	    
	    if (days == null)
	        days = 30;
    	
	    var date = new Date();
	    date.setTime(date.getTime() + (days*24*60*60*1000));
	    expires = "; expires=" + date.toGMTString();

	    document.cookie = name + "=" + value + expires + "; path=/";
    }
    catch (err) {}
}

function getCookie(name) {
    try {
	    name += "=";
	    var ca = document.cookie.split(';');
	    for(var i = 0; i < ca.length; i++) {
		    var c = ca[i];
		    while (c.charAt(0)==' ') c = c.substring(1,c.length);
		    if (c.indexOf(name) == 0) return c.substring(name.length, c.length);
	    }
	    return null;
    }
    catch (err) {}
}


function checkAllBoxes(name, value)
{
    try {
        var checkboxes = document.forms[0].elements[name];
        var count = checkboxes.length;
        if (!count)
            checkboxes.checked = value;
        else
            for(var i = 0; i < count; i++)
            {
                if (getRef(checkboxes[i].value + 'DIV').style.display != "none")
                    checkboxes[i].checked = value;
            }
    }
    catch (err) {}
}

function getBoxesValue(name)
{
    try {
        var returnValue = '';
        var checkboxes = document.forms[0].elements[name];
        var count = checkboxes.length;
        if (!count)
        {
            if (checkboxes.checked) 
                returnValue = '\'' + checkboxes.value + '\',';
        }
        else
        {
            for(var i = 0; i < count; i++)
            {
			    if (checkboxes[i].checked)
			    {
			        returnValue += '\'' + checkboxes[i].value + '\',';
			    }
			}
	    }
	    return returnValue;
    }
    catch (err) {}    
}

function showAllBoxes(name)
{
    try {
        var checkboxes = document.forms[0].elements[name];
        var count = checkboxes.length;
        for(var i = 0; i < count; i++)
            getRef(checkboxes[i].value + 'DIV').style.display = "inline";
    }
    catch (err) {logInfo('showAllBoxes', err);}
}

function showBoxes(name, begin)
{
    try {
        var checkboxes = document.forms[0].elements[name];
        var count = checkboxes.length;
        for(var i = 0; i < count; i++)
        {
            if (checkboxes[i].value.substring(0, 1) == begin)
                getRef(checkboxes[i].value + 'DIV').style.display = "inline";
            else
                getRef(checkboxes[i].value + 'DIV').style.display = "none";
        }
    }
    catch (err) {}
}

/*###########################*/
var logCount = 0;

function logInfo(subject, content) {
//    c = new Date();
//    
//    if (logCount > 30) {
//        logCount = 0;
//        getRef('Info').innerHTML = '';
//    }
//    
//    getRef('Info').innerHTML += '[' + formatHMS(c.getHours()) + ':' + formatHMS(c.getMinutes()) + 
//        ':' + formatHMS(c.getSeconds()) + '.' + formatMS(c.getMilliseconds()) + '] ' + 
//        subject + ': ' + content + '<br>';
//    
//    logCount++;
    
}

function formatHMS(hms) {
    if (hms < 10) return '0' + hms;
    return hms;
}

function formatMS(ms) {
    if (ms < 10) return '00' + ms;
    if (ms < 100) return '0' + ms;
    return ms;
}
/*###########################*/


//function cancelPostBack()
//{
//    try
//    {
//        var prm = Sys.WebForms.PageRequestManager.getInstance();
//        if (prm.get_isInAsyncPostBack()) {
//            prm.abortPostBack();
//        }
//        stopTimer();
//    }
//    catch (err) {}
//}

//function update() {
//    try {
//        var timer = $find('UpdateTimer');
//        timer._raiseTick();
//    }
//    catch (err) {}
//}

//function stopTimer() {
//    try {
//        var timer = $find('UpdateTimer');
//        timer._stopTimer();
//    }
//    catch (err) {}
//}

function getRadioValue(radio) {
    var radioObj = document.getElementsByName(radio);
    var count = radioObj.length;
    if (!count)
        if (radioObj.checked) return radioObj.value;
        else return null;
    else
        for(var i = 0; i < count; i++)
            if (radioObj[i].checked) return radioObj[i].value;
    return null;
}

function setRadioValue(radio, value) {
    var radioObj = document.getElementsByName(radio);
    var count = radioObj.length;
    if (!count)
        radioObj.checked = (radioObj.value == value);
    else
        for(var i = 0; i < count; i++)
            radioObj[i].checked = (radioObj[i].value == value);
}


var oS = new Array(40);

function rMOver(row)
{
    try {
        for (i=0; i< row.cells.length; i++)
        {
            oS[i] = row.cells[i].style.cssText;
            
            row.cells[i].style.cssText += "background-color:#808685;";
        }
    }
    catch (err) {}
}

function rMOut(row)
{
    try {
        for (i=0; i<row.cells.length; i++)
        {
            row.cells[i].style.cssText = oS[i];
        }
    }
    catch (err) {}
}

function showObj(id, show) {
    try {getRef(id).style.display = (show?'inline':'none');} catch (err) {logInfo('showObj', err);}
}
function showHeader(id, show) {
    try {
        getRef(id).style.visibility = (show?'visible':'hidden');
    } catch (err) {logInfo('showHeader', err);}    
}


