﻿
function toggleAllCheckboxes(chk, column) {
	if(chk != null && typeof(chk.checked) != "undefined") {
		var tbl = chk.parentNode, regex = /table/i, boxes;
		while (tbl != null && !regex.test(tbl.tagName)) { tbl = tbl.parentNode; }
		boxes = getAllCheckboxes(tbl, column, false);
		if (boxes.length > 0) {
			for (var i = 0; i < boxes.length; i++) {
				boxes[i].checked = chk.checked;
			}
		}
	}
}

function getAllCheckboxes(tbl, column, includeFirst) {
	var regex = /table/i, boxes, arFinal = [];	
	if (tbl != null && typeof(tbl.rows) != "undefined") {
		for (var i = (includeFirst) ? 0 : 1; i < tbl.rows.length; i++) {
			boxes = tbl.rows[i].cells[column].getElementsByTagName("input");
			for (var j = 0; j < boxes.length; j++) {
				if (boxes[j].type == "checkbox") arFinal.push(boxes[j]);
			}
		}
	}
	return arFinal;
}

function getAllCheckboxesDivTable(div, column, includeFirst) { return _getAllInputsDivTable(div, column, includeFirst, "checkbox"); }
function getAllRadiosDivTable(div, column, includeFirst) { return _getAllInputsDivTable(div, column, includeFirst, "radio"); }

function _getAllInputsDivTable(div, column, includeFirst, type) {
	var rows, cells, boxes, arFinal = [];
	if (div != null && div.childNodes.length > 0) {
		rows = Explorica.getChildNodes(div, "div");
		for (var i = (includeFirst) ? 0 : 1; i < rows.length; i++) {
			cells = Explorica.getChildNodes(rows[i], "div");
			boxes = cells[column].getElementsByTagName("input");
			for (var j = 0; j < boxes.length; j++) {
				if (boxes[j].type == type) arFinal.push(boxes[j]);
			}
		}
	}
	return arFinal;
}

function EnableCheckValidation(cntlId, value) {
    EnableValidation(cntlId + "reqCheckNumber", value);
    EnableValidation(cntlId + "regCheckNumber", value);
}

function SetCheckValidationIsValid(cntlId, value) {
    SetValidatorIsValid(cntlId + "reqCheckNumber", value);
    SetValidatorIsValid(cntlId + "regCheckNumber", value);
}

function EnableCheckingAccountValidation(cntlId, value) {

    var lSiteCountryID = $j("#[id$='lSiteCountryID']");

    if ((lSiteCountryID[0] != null) && (lSiteCountryID.text() != "1")) {
        EnableValidation(cntlId + "valBankNumber", value);
        EnableValidation(cntlId + "regBank", value);
        EnableValidation(cntlId + "reqConBank", value);
        EnableValidation(cntlId + "comBank", value);
    }
    else {
        EnableValidation(cntlId + "valBankNumber", false);
        EnableValidation(cntlId + "regBank", false);
        EnableValidation(cntlId + "reqConBank", false);
        EnableValidation(cntlId + "comBank", false);
    }

    EnableValidation(cntlId + "reqName", value);
    EnableValidation(cntlId + "cusRouting", value);
    EnableValidation(cntlId + "reqConRouting", value);
    EnableValidation(cntlId + "comRouting", value);
    EnableValidation(cntlId + "regAccount", value);
    EnableValidation(cntlId + "reqConAccount", value);
    EnableValidation(cntlId + "comAccount", value);
}


function SetCheckingAccountValidationIsValid(cntlId, value) {

    SetValidatorIsValid(cntlId + "valBankNumber", value);
    SetValidatorIsValid(cntlId + "regBank", value);
    SetValidatorIsValid(cntlId + "reqConBank", value);
    SetValidatorIsValid(cntlId + "comBank", value);
    SetValidatorIsValid(cntlId + "reqName", value);
    SetValidatorIsValid(cntlId + "cusRouting", value);
    SetValidatorIsValid(cntlId + "reqConRouting", value);
    SetValidatorIsValid(cntlId + "comRouting", value);
    SetValidatorIsValid(cntlId + "regAccount", value);
    SetValidatorIsValid(cntlId + "reqConAccount", value);
    SetValidatorIsValid(cntlId + "comAccount", value);
}

function checkRouting(source, args) {
    var d = Explorica.makeSyncWebRequest("/Ajax/Validation.aspx", { "mode": "routing", "number": args.Value }, true);
    if (typeof (d._error) == "undefined") args.IsValid = d.valid;
    else args.IsValid = false;
}

function blurred(sender) {
    var validator = sender.Validators[0]
    return validator.evaluationfunction(validator);
}

function EnableCCValidation(cntlId, value) {
    EnableValidation(cntlId + "reqCCType", value);
    EnableValidation(cntlId + "reqBilling", value);
    EnableValidation(cntlId + "reqCCNumber", value);
    EnableValidation(cntlId + "cusNumber", value);
    EnableValidation(cntlId + "reqCCSecurity", value);
    EnableValidation(cntlId + "cusSecurity", value);
    EnableValidation(cntlId + "reqCity", value);
    EnableValidation(cntlId + "cusExpDate", value);
    EnableValidation(cntlId + "cusExpYear", value);
    EnableValidation(cntlId + "reqState", value);
    EnableValidation(cntlId + "reqFullName", value);
    EnableValidation(cntlId + "cusZip", value);
    EnableValidation(cntlId + "cusTele", value);
}

function SetCCValidationIsValid(cntlId, value) {
    SetValidatorIsValid(cntlId + "reqCCType", value);
    SetValidatorIsValid(cntlId + "reqBilling", value);
    SetValidatorIsValid(cntlId + "reqCCNumber", value);
    SetValidatorIsValid(cntlId + "cusNumber", value);
    SetValidatorIsValid(cntlId + "reqCCSecurity", value);
    SetValidatorIsValid(cntlId + "cusSecurity", value);
    SetValidatorIsValid(cntlId + "reqCity", value);
    SetValidatorIsValid(cntlId + "cusExpDate", value);
    SetValidatorIsValid(cntlId + "cusExpYear", value);
    SetValidatorIsValid(cntlId + "reqState", value);
    SetValidatorIsValid(cntlId + "reqFullName", value);
    SetValidatorIsValid(cntlId + "cusZip", value);
    SetValidatorIsValid(cntlId + "cusTele", value);
}

matchHeight = function () {

    // get all <div> elements in the document 
    var divs, contDivs, maxHeight, divHeight, d;

    divs = document.getElementsByTagName('div');
    contDivs = [];

    // initialize maximum height value 
    maxHeight = 0;

    // iterate over all <div> elements in the document 
    for (var i = 0; i < divs.length; i++) {

        // make collection with <div> elements with class attribute 'container' 
        if ((/\bcolumnLeftA\b/.test(divs[i].className))
                || (/\bcolumnLeftB\b/.test(divs[i].className))) {
            d = divs[i];
            contDivs[contDivs.length] = d;

            // determine height for <div> element 
            if (d.offsetHeight) {
                divHeight = d.offsetHeight;
            }

            else if (d.style.pixelHeight) {
                divHeight = d.style.pixelHeight;
            }

            // calculate maximum height
            if (divHeight != null) {
                maxHeight = Math.max(maxHeight, divHeight);
            }
        }
    }

    // assign maximum height value to all of container <div> elements 
    if (maxHeight > 0) {
        for (var i = 0; i < contDivs.length; i++) {
            contDivs[i].style.height = maxHeight;
        }
    }
}


