﻿// JScript File
var isProcessing = false;
var data="";

function SetPanelDisplay(titleId, panelId, imageId, collapsePath, expandPath, height)
{
    var Title = document.getElementById(titleId);
    var Panel = document.getElementById(panelId);
    var Image = document.getElementById(imageId);

    if (isProcessing == false)    
    {
        if (Panel.style.display == "" || Panel.style.display == 'none')
        {
            Panel.style.display = 'block';
            Image.src = collapsePath;
        }
        else
        {
            Panel.style.display = 'none';
            Image.src = expandPath;
        }
    }
    else
    {
        alert("Please wait while your comment is added.");
    }
    
} //End of SetPanelDisplay

function AddComment(id,BID,Name,Email,Url,Comment)
{
    if (ValidateComment(id) == false)
        return;
    document.getElementById("pnlProcessing" + id).style.display="block";
    document.getElementById("tblComment" + id).style.display="none";        
    document.getElementById("pnlMessage" + id).style.display="none";        
    isProcessing = true;
    SetData(BID, Name,Email,Url,Comment);
}
function CommentAdded(id)
{
    document.getElementById("pnlProcessing" + id).style.display="none";
    document.getElementById("tblComment" + id).style.display="none";        
    document.getElementById("pnlMessage" + id).style.display="block";        
    isProcessing = false;
    data = "";
}
function SetData(BID, Name, Email, Url, Comment)
{
    data = "<?xml version=\"1.0\" standalone=\"yes\"?>\n" 
        + "<DocumentElement>\n"
        + "<Comment>\n"
        + "<ID>"+BID+"</ID>\n"
        + "<Name><![CDATA["+Name.replace("]]>","").replace("<![CDATA[","")+"]]></Name>\n"
        + "<Email><![CDATA["+Email.replace("]]>","").replace("<![CDATA[","")+"]]></Email>\n"
        + "<Url><![CDATA["+Url.replace("]]>","").replace("<![CDATA[","")+"]]></Url>"
        + "<Description><![CDATA["+Comment.replace("]]>","").replace("<![CDATA[","")+"]]></Description>\n"
        + "</Comment>\n"
        + "</DocumentElement>\n";
}
function ValidateComment(id)
{
    var isValid = true;
    
    document.getElementById("vldreqName" + id).innerHTML = "";
    if (document.getElementById("txtName" + id).value == "")
    {
        document.getElementById("vldreqName" + id).innerHTML = "*";
        isValid = false;
    }
    
    document.getElementById("vldreqEmail" + id).innerHTML = "";
    if (document.getElementById("txtEmail" + id).value == "")
    {
        document.getElementById("vldreqEmail" + id).innerHTML = "*";
        isValid = false;
    }
    else if (/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(document.getElementById("txtEmail" + id).value) == false)
    {
        document.getElementById("vldreqEmail" + id).innerHTML = "Invalid email address.";
        isValid = false;
    }
    
    document.getElementById("vldreqUrl" + id).innerHTML = ""
    if (document.getElementById("txtUrl" + id).value != "")
        if (/^http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?$/.test(document.getElementById("txtUrl" + id).value) == false)
        {
            document.getElementById("vldreqUrl" + id).innerHTML = "Invalid url.";
            isValid = false;
        }
        
    document.getElementById("vldreqComment" + id).innerHTML = "";
    if (document.getElementById("txtComment" + id).value == "")
    {
        document.getElementById("vldreqComment" + id).innerHTML = "*";
        isValid = false;
    }
    
    return isValid;        
}