﻿function gotoEdit(i) {
    openWindow(i)
}
function gotoSearch() {
    document.forms[0].submit();
}
function gotoPage(i) {
    document.getElementById("currentPage").value = i;
    document.forms[0].submit();
}

//------------------------ to select/clear text onmouseover / onmouseout ------------
function selectNode(node) {
    var selection, range, doc, win;

    if ((doc = node.ownerDocument) && (win = doc.defaultView)
        && typeof win.getSelection != 'undefined'
        && typeof doc.createRange != 'undefined'
        && (selection = window.getSelection()) && typeof selection.removeAllRanges != 'undefined') {
        range = doc.createRange();
        range.selectNode(node);
        selection.removeAllRanges();
        selection.addRange(range);
    }
    else if (document.body && typeof document.body.createTextRange != 'undefined' && (range = document.body.createTextRange())) {
        range.moveToElementText(node);
        range.select();
    }
}


function clearSelection() {
    if (document.selection)
        document.selection.empty();
    else if (window.getSelection)
        window.getSelection().removeAllRanges();
}
//------------------------ end of select/clear text onmouseover / onmouseout ------------
function gotoBodyCopy1(id) {
    location.href = "showContent.asp?id=" + id + "&body1=true";
}

function gotoBodyCopy2(id) {
    location.href = "showContent.asp?id=" + id;
}

function ConfirmDelete(FormName, FieldName) {
    if (0 == GetSelectedRowCount(FormName, FieldName)) {
        alert('Please select item(s) to delete.');
        return false;
    }
    if (confirm('Are you sure you want to delete the selected ones?')) {
        document.forms[FormName].command.value = "Delete"
        document.forms[FormName].submit();
    }
    return false;
}

function GetSelectedRowCount(FormName, FieldName) {
    if (!document.forms[FormName])
        return 0;
    var objCheckBoxes = document.forms[FormName].elements[FieldName];
    if (!objCheckBoxes)
        return 0;
    var countCheckBoxes = objCheckBoxes.length;
    if (!countCheckBoxes && objCheckBoxes.checked)
        return 1;
    else {
        var count = 0;
        for (var i = 0; i < countCheckBoxes; i++)
            if (objCheckBoxes[i].checked) count++;
        return count;
    }
}

//<------ select all / deselect all with checkbox ------>
function SetAllCheckBoxes(FormName, FieldName, CheckValue) {
    if (!document.forms[FormName])
        return;
    var objCheckBoxes = document.forms[FormName].elements[FieldName];
    if (!objCheckBoxes)
        return;
    var countCheckBoxes = objCheckBoxes.length;
    if (!countCheckBoxes)
        objCheckBoxes.checked = CheckValue;
    else
    // set the check value for all check boxes
        for (var i = 0; i < countCheckBoxes; i++)
        objCheckBoxes[i].checked = CheckValue;
}


//<------ end of select all / deselect all with checkbox ------>

function trim(stringToTrim) {
    return stringToTrim.replace(/^\s+|\s+$/g, "");
}

function validateRequiredField(field, alerttxt) {
    with (field) {
        if (value == null || value == "")
        { alert(alerttxt); return false; }
        else { return true }
    }
}

function IsNumeric(strString)
//  check for valid numeric strings	
{
    var strValidChars = "0123456789.-";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

function IsPositiveInteger(strString)
//  check for valid numeric strings
{
    var strValidChars = "0123456789";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++) {
        strChar = strString.charAt(i);
        if (strValidChars.indexOf(strChar) == -1) {
            blnResult = false;
        }
    }
    return blnResult;
}

//For display big image for product - ProDetail.asp
function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent)
        while (1) {
        curtop += obj.offsetTop;
        if (!obj.offsetParent)
            break;
        obj = obj.offsetParent;
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
