﻿//TEXT INPUT
function wcTextBoxEnterKeyPressCheck(ev, eCode) {
    var cCode;

    if (ev && ev.which) {
        ev = ev;
        cCode = ev.which;
    }else{
        ev = event;
        cCode = ev.keyCode; 
    }
    if (cCode == 13) {
        try{
            eval(eCode);                
        }catch(err){
            //NOTHING
        }

        return false 
    }else{
        return true 
    }

}

function wcInputFocus(wcInput, bgcolor) {
    wcInput.style.backgroundColor = bgcolor;
}

String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
};

function aTop(obj) {
    var vTop = 0;
    do {
        vTop += obj.offsetTop;
        obj = obj.offsetParent;
    } while (obj);
    return vTop;
}

function aLeft(obj) {
    var vTop = 0;
    do {
        vTop += obj.offsetLeft;
        obj = obj.offsetParent;
    } while (obj);
    return vTop;
}


// MODAL WAIT

function ShowModalWait() {
    $find('ModalWait').show()
}
function HideModalWait() {
    $find('ModalWait').hide()
}


// RADIO CHECKBOX

function wcRadioCheckbox_Hover(obj, efx) {
    //VALUE OBJ
    var val = document.getElementById(obj.id + "Value");
    if (val.value == 0) {
        if (efx == 'in') {
            obj.style.backgroundPosition = "0px -23px";
        } else {
            obj.style.backgroundPosition = "0px 0px";
        }
    }
}
function wcRadioCheckbox_Check(obj,gf,max) {
    //VALUE OBJ
    var count = 0;
    if (max == 0) {
        count = -1;
    }
    if (max != 0) {
        if (document.getElementById(obj.id + "Value").value == 0) {
            $('.' + gf).each(
            function(intIndex) {
                if ($("#" + $(this)[0].id + "Value")[0].value == 1) { count += 1; };
            }
        )
        }
    }
    if (count <= (max-1)) {
        var val = document.getElementById(obj.id + "Value");
        if (val.value == 0) {
            val.value = 1;
            obj.style.backgroundPosition = "0px -46px";
        } else {
            val.value = 0;
            obj.style.backgroundPosition = "0px -23px";
        }
    }
}
function wcRadioCheckbox_Radio(obj, gf, v) {
    //VALUE OBJ
    var val = document.getElementById(obj.id + "Value");
    var group = document.getElementById(gf);
    if (val.value == 0) {
        $('.' + gf).css("background-position", "0px 0px");
        $('.' + gf).each(
            function(intIndex) {
                $("#" + $(this)[0].id + "Value")[0].value = 0;
            }
        )
        val.value = 1;
        group.value = v;
        obj.style.backgroundPosition = "0px -69px";
    }
}

function wcRadioCheckBox_Validate(objid, mess) {
    if (eR(objid).value == 0) {
        alert(mess);
        return false;
    } else {
        return true;
    }
}

// ROLLOVERBUTTON

function wcRollOverButton_Hover(obj, imu) {
    obj.src = imu;
}

function wcGO(url, ne) {
    if (ne == 1) {
        window.open(url,'TheRainmakerNetwork','width=600,height=500,resizable,menubar,scrollbars,toolbar');
    } else {
        window.location = url;
    }
}

//MAGIC LIST
var wcMagicListAcceptEnter = true;
function wcMagicListChangeAcceptanceTRUE() {
    wcMagicListAcceptEnter = true;
}
function wcMagicListChangeAcceptanceFALSE() {
    wcMagicListAcceptEnter = false;
}
function wcMagicListAddItem(MagicListID) {
    if (wcMagicListAcceptEnter == false) { return false }
    var eList = eR(MagicListID + "_wcMagicList_ul");
    var eRow = eR(MagicListID + "_wcMagicListTopTable_ItemArea");
    var eTextBox = eR(MagicListID + "_wcMagicList_txt");
    var eValue = eR(MagicListID + "_wcMagicListValues");
    if (eValue.value.indexOf("{" + eTextBox.value.toLowerCase().trim() + "}") != -1 || eTextBox.value.trim().length == 0) {
        eTextBox.value = "";
        return false
    };
    eValue.value += "{" + eTextBox.value.toLowerCase().trim() + "}";
    var date = new Date()
    var ticks = date.getTime()
    var ListItem = document.createElement("li");
    ListItem.setAttribute("ID", "wcMagic" + ticks);
    ListItem.setAttribute("onclick", "wcMagicListRemoveItem('wcMagic" + ticks + "','" + eValue.id + "','" + eRow.id + "')");
    ListItem.innerHTML = '<table cellpadding="0" cellspacing="0" onmouseover="wcMagicListItemIN(this)" onmouseout="wcMagicListItemOUT(this)"><tr><td class="wcMagicList_item_tbl">' + eTextBox.value.trim() + '</td><td class="wcMagicList_item_tblbtn"></td></tr></table>';
    eList.appendChild(ListItem);
    eRow.style.display = "block";
    eTextBox.value = "";
}
function wcMagicListRemoveItem(ItemID, ValueID, RowID) {
    if (eR(ItemID).textContent == undefined) {
        eR(ValueID).value = eR(ValueID).value.replace("{" + eR(ItemID).innerText.toLowerCase() + "}", "");
    } else {
        eR(ValueID).value = eR(ValueID).value.replace("{" + eR(ItemID).textContent.toLowerCase() + "}", "");
    }
    if (eR(ValueID).value == "") {
        //HIDE
        eR(RowID).style.display = "none";
    }
    eR(ItemID).parentNode.removeChild(eR(ItemID));
    //e(ItemID).removeNode(true);

}
function wcMagicListItemIN(Item) {
    Item.firstChild.firstChild.childNodes[0].style.backgroundImage = "url(/images/wcMagicList_btn_left_hover.png)";
    Item.firstChild.firstChild.childNodes[1].style.backgroundImage = "url(/images/wcMagicList_btn_right_hover.png)";
}
function wcMagicListItemOUT(Item) {
    Item.firstChild.firstChild.childNodes[0].style.backgroundImage = "url(/images/wcMagicList_btn_left.png)";
    Item.firstChild.firstChild.childNodes[1].style.backgroundImage = "url(/images/wcMagicList_btn_right.png)";
}
function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function wcMagicListClientShown(source, args) {
    wcMagicListChangeAcceptanceFALSE();
    source._completionListElement.style.top = (aTop(source._element) + source._element.offsetHeight) + "px";
}




//DROP DOWN
function wcDropDownClientShown(source, args) {
    if (aTop(source._element) + source._element.offsetHeight - 4 + source._optionListControl.offsetHeight > $(window).height() + $(window).scrollTop()) {
        //SETTOP
        var xa = 0;
        if (jQuery.browser.safari) xa = -1;
        if (jQuery.browser.mozilla) xa = -1;
        if (jQuery.browser.mozilla) source._optionListControl.style.width = (source._optionListControl.offsetWidth - 7) + "px";
        if (jQuery.browser.msie) xa -= source._getOptionListItemHeight() + 4;
        if (jQuery.browser.opera) xa = 3;
        source._optionListControl.style.top = (aTop(source._element) - source._optionListControl.clientHeight + xa) + "px";
    } else {
        //SETBOT
        var xa = -4;
        if (jQuery.browser.msie) xa = 12;
        source._optionListControl.style.top = (aTop(source._element) + source._element.clientHeight + xa) + "px";
    }

}