function openWindow(p_url, p_name, p_width, p_height)
{       
    var w = 480, h = 340;
    if (document.all || document.layers) {
        w = screen.availWidth;
        h = screen.availHeight;
    }
    
    var popW = p_width, popH = p_height;
    var leftPos = (w-popW)/2, topPos = (h-popH)/2;
    var wndPopup = window.open(p_url, p_name,
                   "width=" + popW + ",height=" + popH +
                   ",top=" + topPos + ",left=" + leftPos +
                   ",screenX=" + leftPos + ",screenY=" + topPos +
                   ",toolbar=no,location=no,directories=no,status=no" +
                   ",menubar=no,scrollbar=no,resizable=yes,copyhistory=yes");
    //wndPopup.focus();
    return wndPopup;
}

function showProductInfo(nPrdId)
{   
    openWindow("product.asp?PrdId=" + nPrdId, "ProductInfo", 500, 280);
}

function switchLanguage()
{
	var sUrl = document.location.href
	document.location.href = "admin.asp?action=lang&url=" + sUrl
}

//-----------------------------------------------------
function trim(str) {
    var nLf, nRt, nLen
    nLen = str.length
    nLf = 0
    nRt = nLen
    
    while (nLf < nLen && str.charAt(nLf) == ' ') nLf++;
    while (nRt >nLf && str.charAt(nRt-1) == ' ') nRt--;
            
    return str.substring(nLf, nRt);
}

//-----------------------------------------------------
function resetForm(frm) {
	if (confirm("Huy bo cac thay doi?")) frm.reset()
}

function confirmDeletion(frm, sInfo) {
	return confirm("Ban thuc su muon XOA " + sInfo + " nay ?")
}
//-----------------------------------------------------
function checkEmpty(objField, sName) {
    if(trim(objField.value)=="") {
        alert("Ban chua nhap '" + sName + "'")
        objField.focus()
        return false
    }
    return true
}

function checkEmpty2(objField1, objField2, sName) {
	var v1, v2
	v1 = objField1.value
	v2 = objField2.value
    if(trim(v1)=="" && trim(v2)=="") {
        alert("Ban chua nhap '" + sName + "'")
        objField1.focus()
        return false
    }
    return true
}

function checkEmpty2Fields(objField1, objField2, sName1, sName2) {
    if(trim(objField1.value)=="" && trim(objField2.value)=="") {
        alert("Ban chua nhap '" + sName1 + "' hoac '" + sName2 + "'")
        objField1.focus()
        return false
    }
    return true
}
