﻿var CurrentID = "";
var CurrentCommentDiv;
var adjacentHtml = "";
var ShowTopic = "";
var HideTopic = "";

function Hide(divID) {
    var div = document.getElementById(divID);
    eval(divID + "=div.innerHTML");
    div.innerHTML = "";
    div.style.visibility = "hidden";
}
function Show(divID) {
    var div = document.getElementById(divID);
    eval("div.innerHTML=" + divID);
    div.style.visibility = "visible";
}
function OpenTopic(divID, sender) {
    //alert(sender);
    var div = document.getElementById(divID);
    var currDiv = document.getElementById("div" + divID);
    if (divID == CurrentID) {
        CurrentID = "";
        this.Hide(divID);
        sender.innerHTML = ShowTopic;
        currDiv.style.backgroundImage = "url(/i/open.gif)";
    }
    else {
        sender.innerHTML = HideTopic;
        if (CurrentID != "") {
            var oldDiv = document.getElementById("div" + CurrentID);
            var oldA = document.getElementById("a" + CurrentID);
            oldDiv.style.backgroundImage = "url(/i/open.gif)";
            oldA.innerHTML = ShowTopic;
            this.Hide(CurrentID);
        }
        currDiv.style.backgroundImage = "url(/i/close.gif)";
        CurrentID = divID;
        this.Show(divID);
    }
}
function PrepareProductCommentInsert(ProductID) {
    hiddParent.value = 0;
    hiddProduct.value = ProductID;
    $("#divCommentForm").toggle();
    var txtHeader = document.getElementById("txtHeader");
    txtHeader.value = hiddProductName.value;
    $("#txtComment").val('');
    $("#txtComment").focus();
}
function PrepareCommentInsert(ParentID, ProductID) {

    if (CurrentCommentDiv && CurrentCommentDiv.id != "divComment_" + ParentID) {
        CurrentCommentDiv.innerHTML = "";
    }
    if (CurrentCommentDiv && CurrentCommentDiv.id == "divComment_" + ParentID) {
        CurrentCommentDiv.innerHTML = "";
        CurrentCommentDiv = null;
        return false;
    }
    hiddParent.value = ParentID;
    hiddProduct.value = ProductID;
    CurrentCommentDiv = document.getElementById("divComment_" + ParentID);
    CurrentCommentDiv.innerHTML = this.adjacentHtml;
    var txtHeader = document.getElementById("txtHeader");
    if (hiddProductName) {
        txtHeader.value = ParentID > 0 ? "RE:" : hiddProductName.value + ":";
    }
    else {
        txtHeader.value = ParentID > 0 ? "RE:" : "";
    }
    var txtComment = document.getElementById("txtComment");
    txtComment.value = "";
    if (ParentID == 0) {
        CurrentCommentDiv.style.display = "block";

    }
}
var div;
var hiddParent;
var hiddProduct;
var hiddProductName;
function InitForum() {
    hiddProduct = document.getElementById("hiddProductID");
    hiddParent = document.getElementById("hiddParentID");
    hiddProductName = document.getElementById("hiddProductName");
    if (!hiddProductName || hiddProductName.value == "")
        hiddProductName = null;
    div = document.getElementById("divComment_0");
    this.adjacentHtml = div.innerHTML;
    div.innerHTML = "";
}
function CheckSubmit() {

    if (hiddParent.value == 0) {
        var txtHeader = document.getElementById("txtHeader");
        if (txtHeader.value == "")
            return false;
        else
            return true;
    }
}
var LeftRE = new RegExp("<", "igm");
var RightRE = new RegExp(">", "igm");
function checkForTags(sender) {
    if (sender.value.match(LeftRE) || sender.value.match(RightRE)) {
        sender.value = sender.value.replace(LeftRE, " ");
        sender.value = sender.value.replace(RightRE, " ");
    }
}

