﻿var error_color = "#FF0000";
var success_color = "#000000";

function QueryString()
{
    var qs = window.location.search.substring(1);
    
    var idx = -1, oldIdx, name, value, ret = new Object();
    
    for(;;){
    
        oldIdx = idx + 1;
    
        idx = qs.indexOf('=', idx);
    
        if(idx == -1) break;
        
        name = qs.substring(oldIdx,idx);
        
        oldIdx = idx + 1 ;
        
        idx = qs.indexOf('&', idx+1);
        
        if(idx == -1){
            value = qs.substring(oldIdx);
            ret[name] = value;
            break;
        }
        else
        {
            value = qs.substring(oldIdx,idx);
        
            ret[name] = value;
        }
    }

    return ret;
}

function Trim(str){return str.replace(/^\s+|\s+$/g,"");}   

function Validate(textbox,label)
{
    if(Trim(textbox.value) == "")
    {
       label.style.color = error_color;               
       $("#CamposObrigatorios").css("display","block");
    }
    else
    {
       label.style.color = success_color;
    }
}

// Função que selecciona a cor
function selectColor(parentLayer, prefix, colorCtrl, id, colorOff, colorOn) {
    var divCores = document.getElementById(parentLayer); // vai buscar o controlo "pai" das cores
    var hidCor = document.getElementById(colorCtrl); // vai buscar o controlo escondido, que irá guardar o id da cor seleccionada
    hidCor.value = id; // Atribui o id da cor ao campo escondido

    if (divCores) { // verifica se realmente existe o controlo "pai" das cores

        var arrDivs = divCores.getElementsByTagName('DIV'); // vai buscar todas as divs dentro do "pai"

        for (i = 0; i < arrDivs.length; i++) { // loopa por todas as divs
            var div = arrDivs[i];
            if (div.getAttribute('cid') != '') {
                div.style.border = 'solid 2px ' + ((div.getAttribute('cid') == id) ? colorOn : colorOff);
            }
        }
    }
       
}
