function writeContactInfo()
{
    var text = "";
    var encrypted = ""
    for (var i=0; i<arguments.length; i++)
    {
        if (typeof(arguments[i]) == "object")
            text = arguments[i].text;
        else
            encrypted += (i == 0 ? "" : "\u0009") + arguments[i];
    }
    document.write("<a name='writeContactInfo' zzcontactinfo='" + MDXWeb_HTMLEncode(encrypted) + "'" +
                                               (text == "" ? "" : "zzcontactinfotext='" + MDXWeb_HTMLEncode(text) + "'") + "></a>");
}

function MDXWeb_JSEncode(text)
{
    return text.replace(/\\/g,"\\\\").replace(
                        /'/g,"\\\'").replace(
                        /"/g,"\\\"").replace(
                        new RegExp(String.fromCharCode(9),"g"),"\\t").replace(
                        new RegExp(String.fromCharCode(13),"g"),"").replace(
                        new RegExp(String.fromCharCode(10),"g"),"\\n");
}

function MDXWeb_HTMLEncode(text,encodeBR)
{
    encodeBR = (encodeBR || false);
    var text = text.replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;').replace(/'/g,'&#39;');
    if (encodeBR)
        text = text.replace(/\n/g,'<br/>');
    return text
}

function writeContactInfoOnLoad()
{
    var controls = document.getElementsByName("writeContactInfo");
    for (var i=0; i<controls.length; i++)
    {
        var control = controls[i];
        var zzContactInfo = control.getAttribute("zzcontactinfo");
        var arrContactInfo = zzContactInfo.split("\u0009");
        var contactInfo = "";
        for (var j=arrContactInfo.length-1; j>=0; j--)
        {
            var temp = arrContactInfo[j];
            for (var k=temp.length-1; k>=0; k--)
                contactInfo += temp.charAt(k);
            if (j > 0)
                contactInfo += (j == arrContactInfo.length-1 ? "\u0040" : "\u002E");
        }
        var zzContactInfoText = control.getAttribute("zzcontactinfotext");
        control.innerHTML = MDXWeb_HTMLEncode(zzContactInfoText || contactInfo);
        control.href = "m" + "a" + "i" + "l" + "t" + "o" + ":" + contactInfo;
    }
}

function ContactForm_addProduct(quantityClientID, selectorClientID, selectedProductsClientID, hiddenInfoClientID)
{
    var quantityField = document.getElementById(quantityClientID);
    var selectorField = document.getElementById(selectorClientID);
    var selectedProducts = document.getElementById(selectedProductsClientID);
    var hiddenInfoField = document.getElementById(hiddenInfoClientID);

    if (selectorField.value == "")
    {
        alert(ContactForm_Resources.contactformselectedproductsselectproduct);
        selectorField.focus();
        return;
    }
    
    if (quantityField.value == "")
    {
        alert(ContactForm_Resources.contactformselectedproductsenterquantity);
        quantityField.focus();
        return; 
    }
    
    var row = selectedProducts.insertRow(-1);
    
    var cell = row.insertCell(-1);
    cell.innerHTML = quantityField.value;
    cell.className = "first";
    
    var cell2 = row.insertCell(-1);
    cell2.innerHTML = selectorField.value;
    cell2.className = "second";
    
    var btnRemove = document.createElement("a");
    btnRemove.innerHTML = "x";
    btnRemove.href = "#";
    cell2.appendChild(btnRemove);
    if (btnRemove.attachEvent)
        btnRemove.attachEvent("onclick", ContactForm_removeProduct, false);
    else
        btnRemove.addEventListener("click", ContactForm_removeProduct, false);
    
    var info = hiddenInfoField.value.split(",");
    var ctrlCounter = parseInt(info[0],10);
    var numProducts = parseInt(info[1],10) + 1;
    hiddenInfoField.value = ctrlCounter + "," + numProducts;
    
    var hiddenField = document.createElement("input");
    hiddenField.type = "hidden";
    hiddenField.name = "ContactForm_Products_" + ctrlCounter + "_" + numProducts + "_Desc";
    hiddenField.value = selectorField.value;
    cell2.appendChild(hiddenField);
    
    var hiddenField2 = document.createElement("input");
    hiddenField2.type = "hidden";
    hiddenField2.name = "ContactForm_Products_" + ctrlCounter + "_" + numProducts + "_Qty";
    hiddenField2.value = quantityField.value;
    cell2.appendChild(hiddenField2);
    
    ContactForm_updateTable(selectedProducts);
    
    selectorField.selectedIndex = 0;
    quantityField.value = "";
    selectorField.focus();
}

function ContactForm_removeProduct(event)
{
    var btnRemove = (event.srcElement || event.target);
    var selectedProducts = btnRemove.parentNode.parentNode.parentNode;
    selectedProducts.removeChild(btnRemove.parentNode.parentNode);
    ContactForm_updateTable(selectedProducts);
    return false;
}

function ContactForm_updateTable(table)
{
    table.rows[1].style.display = (table.rows.length <= 2 ? "" : "none");
}

if (window.attachEvent) { window.attachEvent("onload", writeContactInfoOnLoad); } else { window.addEventListener("load", writeContactInfoOnLoad, false); }