 function sendComment(url) {
    var segment = "[a-zA-Z0-9._%+-/\]+";
    var regexp = new RegExp("^" + segment + "@" + segment + ".[a-zA-Z]+$");
    if (dojo.byId("name").value =="" || dojo.byId("comment").value =="")
        alert("You must complete all required fields."); 
    else if (!regexp.test(dojo.byId("email").value))
        alert("Please enter a valid email address.");
    else {
        var comment = stripHTML(dojo.byId("comment").value.replace(/'/g, "''"));
        dojo.io.bind({
            url: url,
            method: "post",
            content: {
                    pageID:  dojo.byId("pageID").value,
                    relatesToComment: dojo.byId("RelatesToComment").value,
                    name:  dojo.byId("name").value.replace(/'/g, "''"),
                    email:  dojo.byId("email").value.replace(/'/g, "''"),
                    comment: comment
            },
            load: function(load, data, e) {
                dojo.widget.byId("outer").refresh();   
            }
        });
    }
    return false;
}

function setAndDisplay(relates) {
    dojo.byId("RelatesToComment").value = relates;
    dojo.byId("postComment").style.display = "block";
}

function stripHTML( BodyCopy) 
{
    BodyCopy = BodyCopy.replace(/&nbsp;/g," ");			
    BodyCopy = BodyCopy.replace( /&amp;/g, "and" );
    BodyCopy = BodyCopy.replace( /&[a-z#0-9]+;/g, "" );
    BodyCopy = BodyCopy.replace( /&/g,"and");
    return BodyCopy.replace( new RegExp( "<[^>]+>", "g" ), "" );	
}

function checkRatingCookies(pageID) {
    if (dojo.byId("thankyou")!=null && dojo.byId("votingblock")!=null) {
        if (document.cookie.indexOf("page" + pageID + "rated")!=-1) {
            dojo.byId("votingblock").style.display="none";	
            dojo.byId("thankyou").style.display="block";
        }
    }
}

function sendRating(myrating, pageID, url) {	
    dojo.io.bind({
        url: url,
        method: "post",
        content: {
            	pageID:  pageID,
            	userID:  "noUser",
            	rating:  myrating					
        },
        load: function(load, data, e) {		
            var ratingWidget = dojo.widget.byId("rating");
            document.cookie =createCookie("page" + pageID + "rated","set_" + myrating,1);
            ratingWidget.refresh();
        }
    });
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}