// Javascript source file for CNET Community Webapps

function setElementHtml(id,html) {
    var eh = document.getElementById(id);
    if (null != eh) {
        eh.innerHTML = html;
    }
}


function checkRequiredField(field, minSize, maxSize, errorMsg) {
    if (!(field.value.length >= minSize && (maxSize <=0 || field.value.length <= maxSize))) {
        alert(errorMsg);
        return false;
    }
    return true;
}


function checkField(field, minSize, maxSize, errorMsg) {
    if (field.value.length > 0 && !(field.value.length >= minSize && (maxSize <=0 || field.value.length <= maxSize))) {
        alert(errorMsg);
        return false;
    }
    return true;
}

function goToLocation(url, tag) {
    window.location = url + '?tag=' + tag;
}

function goToSingleUrlWithMessageId(url, messageId, tag) {
    window.location = url + "?messageID=" + messageId + "&tag=" + tag;
}
function goToReplyUrlWithMessageId(url, messageId, tag) {
    window.location = url + "&messageID=" + messageId + "&tag=" + tag;
}

var url = location.href;
function page(start) {
    // first, grab everything but the queryString...
    re = /(^[^\?]*)/gi;
    re.exec(url);
    var nurl = RegExp.$1 + "?start=" + start;
    // now, let's grab the queryString...
    var q = location.search;
    // now, let's split that up...
    if(q.length > 1) {
        q = q.substring(1, q.length);
    } else {
        q = null;
    }
    this.keyValuePairs = new Array();
    if(q) {
        var splitQ = q.split("&");
        for(var i=0; i < splitQ.length; i++) {
            if (!/start\=/.test(splitQ[i])) {
                nurl = nurl + "&" + splitQ[i];
            }
        }
    }
//    alert(nurl);
    window.location = nurl;
}

function getParameter(paramName) {
    var q = location.search;
    // now, let's split that up...
    if(q.length > 1) {
        q = q.substring(1, q.length);
    } else {
        q = null;
    }
    this.keyValuePairs = new Array();
    if(q) {
        var splitQ = q.split("&");
        for(var i=0; i < splitQ.length; i++) {
            // now plit that on the =
            var splitParam = splitQ[i].split("=");
            if (splitParam.length == 2 && splitParam[0] == paramName) {
                return unescape(splitParam[1]);
            }
        }
    }
}

function tbpPrePreview() {
    // nothing yet...
}
function tbpPostPreview() {
    // nothing yet...
}
function tbpPreSubmit() {
    // nothing yet...
}
function tbpPostSubmit() {
    // nothing yet...
}

