﻿//------- Select a country ---------------------------------------------
function selectCountry(country) {
    location.href = "setCountry.asp?country=" + country + "&url=products.asp";
}

function gotoSearch() {
    document.forms['Form1'].submit();
}
function gotoPage(i) {
    document.getElementById("currentPage").value = i;
    document.forms['Form1'].submit();
}

function showFile(file, isImage) {
    var feature = "height=600,width=1000,status=yes,toolbar=no,menubar=no,location=yes,scrollbars=yes,resizable=yes";
    if (isImage)
        var win = window.open("ShowImage.asp?file=" + file, "image", feature);
    else
        var win = window.open(file, "file", feature);

    win.focus();
    return false;
}

//------------------- start of multiple row delete ----------------------
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;
    }
}
//------------------- end of multiple row delete ----------------------

//<------ 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;
}


function viewPort() {
    var h = window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
    var w = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;

    return { width: w, height: h }
}

