﻿var root_url = 'http://localhost/floresintra';

//$(document).ready(function() { alert("ready"); });

function openDiv(open, close) {
    var oDivs = document.getElementsByTagName("DIV");
    for (var i = 0; i < oDivs.length; i++) {
        if (oDivs[i].id.substring(0, close.length) == close) {
            oDivs[i].style.display = 'none';
        }
    }

    var divOpen = document.getElementById(open);
    divOpen.style.display = 'block';
}

function vbv() {
    var wWidth = 330;
    var wHeight = 300;
    var wTop = (screen.availHeight - wHeight) / 2
    var wLeft = (screen.availWidth - wWidth) / 2
    var vbvWindow = window.open(root_url + '/vbv.aspx', 'vbv', 'width=' + wWidth + ',height=' + wHeight + ',top=' + wTop + ',left=' + wLeft);
}

function cvv() {
    var wWidth = 400;
    var wHeight = 350;
    var wTop = (screen.availHeight - wHeight) / 2
    var wLeft = (screen.availWidth - wWidth) / 2
    var vbvWindow = window.open(root_url + '/cvv.aspx', 'cvv', 'width=' + wWidth + ',height=' + wHeight + ',top=' + wTop + ',left=' + wLeft);
}

function setFocus(control, color) {
    control.style.backgroundColor = '#' + color;
}

function addCart(url, pid, addCtrl, skuCtrl, returnURL) {
    var arrAdditional = document.getElementsByTagName('input');
    var sku = document.getElementById(skuCtrl);
    var skuValue = 0;
    if (sku) {
        skuValue = sku.value;
    }
    var additionals = '';

    for (var i = 0; i < arrAdditional.length; i++) {
        if (arrAdditional[i].type == 'checkbox' && arrAdditional[i].checked && arrAdditional[i].name == addCtrl) {
            additionals += arrAdditional[i].value;
            additionals += ',';
        }
    }

    document.location.href = url + '?pid=' + pid + '&add=' + additionals + '&sku=' + skuValue + '&return=' + returnURL;
}

function cancelCart(oid, msg, url) {
    if (confirm(msg)) {
        document.location.href = url + '?oid=' + oid;
    }
}

function changeQty(control, action) {
    var txtControl = document.getElementById(control);

    if (action == 0) {
        if (parseInt(txtControl.value) > 0) {
            txtControl.value = parseInt(txtControl.value) - 1;
        }
    }
    else {
        txtControl.value = parseInt(txtControl.value) + 1;
    }
}

function chkNumeric(text) {
    var checkOK = "0123456789"
    var allValid = true;

    for (i = 0; i < text.length; i++) {
        ch = text.charAt(i);
        if (checkOK.indexOf(ch) < 0) {
            allValid = false;
        }
    }

    return allValid;
}

function copyFormFields(checkbox, fields) {
    for (pairIndex in fields.split(';')) {
        var origin = document.getElementById(fields.split(";")[pairIndex].split(',')[0])
        var destination = document.getElementById(fields.split(";")[pairIndex].split(',')[1])

        if (checkbox.checked) {
            if (origin.tagName == 'INPUT' || origin.tagName == 'TEXTAREA') {
                destination.value = origin.value;
            }
            else if (origin.tagName == 'SELECT') {
                destination.selectedIndex = origin.selectedIndex;
            }

            destination.disabled = true;
        }
        else {
            if (origin.tagName == 'INPUT' || origin.tagName == 'TEXTAREA') {
                destination.value = '';
            }
            else if (origin.tagName == 'SELECT') {
                destination.selectedIndex = 0;
            }

            destination.disabled = false;
        }

    }
}

function disableFormFields(checkbox, fields) {
    for (pairIndex in fields.split(';')) {
        var control = document.getElementById(fields.split(";")[pairIndex])

        if (control.tagName == 'INPUT' || control.tagName == 'TEXTAREA') {
            control.value = '';
        }
        else if (control.tagName == 'SELECT') {
            control.selectedIndex = 0;
        }

        control.disabled = checkbox.checked;

    }
}

function ccData(control, action) {
    var control = document.getElementById(control);
    if (control) {
        if (action == 0) {
            control.style.display = 'none';
        }
        else {
            control.style.display = 'block';
        }
    }
}

function assignValue(ctrl, value) {
    var control = document.getElementById(ctrl);

    if (ctrl) {
        control.value = value;
    }

}

/***** Verificação de entrada de apenas caracteres específicos ******/
function res(control) {
    control.value = control.value.replace(/([^0-9])/g, "");
}