
function cmsSetFullCookie(name, value, expires, path, domain, secure) {
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime(today.getTime());

    /*
    if the expires variable is set, make the correct
    expires time, the current script below will set
    it for x number of days, to make it for hours,
    delete * 24, for minutes, delete * 60 * 24
    */
    if (expires) {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date(today.getTime() + (expires));

    document.cookie = name + "=" + escape(value) + ((expires) ? ";expires=" + expires_date.toGMTString() : "") + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "") + ((secure) ? ";secure" : "");
}


function cmsWindowOpenLink(pThis, pName, pFeatures, pReplace) {
    var oNewWindow = window.open(pThis.href, pName, pFeatures, pReplace);
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}

function cmsWindowOpen(pUrl, pName, pFeatures, pReplace) {
    var oNewWindow = window.open(pUrl, pName, pFeatures, pReplace);
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
    }
}

function cmsPopupImage(pUrl, pName) {
    var oNewWindow = window.open(pUrl, pName, 'directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no');
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}

function cmsPopupImageSmall(pUrl, pName) {
    var oNewWindow = window.open(pUrl, pName, 'height=250,width=250,directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no');
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}

function cmsPopupAnchor(pAnchor, pName) {
    var oNewWindow = window.open(pAnchor.href, pName, 'directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no');
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}


function cmsPopupAnchorSmall(pAnchor, pName) {
    var oNewWindow = window.open(pAnchor.href, pName, 'height=250,width=250,directories=no,toolbar=no,location=no,menubar=no,status=no,titlebar=no');
    if (oNewWindow == null) {
        alert('Enable popups for this function.');
        return true;
    }
    return false;
}

function cms_cbToggle(pID, pSelected) {
    $("#" + pID + " input[type='checkbox']").each(function() {
        this.checked = pSelected;
    });
}

function cms_cbToggleInverse(pID, pSelected) {
    $("#" + pID + " input[type='checkbox']").each(function() {
        this.checked = !this.checked;
    });
}


function imgButtonSearch_ClientClick(pId) {
    var otb = document.getElementById(pId);
    if (otb == null) {
        return true;
    }

    window.location.href = '/rmi/Search&' + encodeURI(otb.value);
}

function tbClearEntry(pThis, pValue) {
    if (pThis.value == pValue) {
        pThis.value = '';
    }
}

function fnTrapEnterKD(btnId, e) {
    var btn = document.getElementById(btnId);
    var key;

    if (btn == null) {
        return;
    }

    if (window.event) {
        //IE
        key = window.event.keyCode;
        if (key == 13) {
            btn.click();
            event.keyCode = 0;
        }
    }
    else {
        //firefox
        key = e.which;
        if (key == 13) {
            btn.click();
        }
    }
}

function IsValidEmail(pEmail)
{
    if (pEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
        return true;
    }
    else {
        return false;
    }
}

function IsValidObjEmail(pTexbox) {

    var string = pTextbox.value;
    
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {
        return true;
    }
    else {
        return false;
    }
}

function submitFormPaypal(pItemName) {
    $('#item_name', document.forms['form_paypal']).val(pItemName);
    document.forms['form_paypal'].submit();
}
