﻿function createMessXMLHttp() {
    if (typeof XMLHttpRequest != "undefined") {
        return new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        var aVersions = ["MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHttp"];

        for (var i = 0; i < aVersions.length; i++) {
            try {
                var oXmlHttp = new ActiveXObject(aVersions[i]);
                return oXmlHttp;
            }
            catch (oError) {
            }
        }
    }
    throw new Error("XMLHttp object could be created.");
}
function addMessage(MPId, mdlId, mdlVl, msgType, HidIconId, uId, sId, txttitleId, txtNameId, txtcommentId, txtmailId, txtcntryId, lblMessId, divCmmCountId) {

    txttitle = document.getElementById(txttitleId);
    txtName = document.getElementById(txtNameId);
    txtcomment = document.getElementById(txtcommentId);
    txtmail = document.getElementById(txtmailId);
    txtcntry = document.getElementById(txtcntryId);
    lblMess = document.getElementById(lblMessId);
    HidIcon = document.getElementById(HidIconId);
    divCmmCount = document.getElementById(divCmmCountId);

    var txttitleValue = "أدخل عنوان التعليق ";
    var txtMailValue = "أدخل البريد الإلكترونى ";

    if (txtName!=null&&txttitle != null && txtcomment != null && txtmail != null && txtcntry != null && lblMess != null && HidIcon != null && divCmmCount != null) {
       // if (txttitle.value.length == 0 || txttitle.value.removeSpaces() == txttitleValue.removeSpaces()) {
       //     alert("من فضلك ادخل عنوان التعليق");
       //     return;
      //  }

        if (txtcomment.value.length == 0) {
            alert("من فضلك ادخل التعليق");
            return;
        }

       // if (txtmail.value.length == 0 || txtmail.value.removeSpaces() == txtMailValue.removeSpaces()) {
      //      alert("من فضلك ادخل البريدالإلكترونى");
       //     return;
      //  }

        alert("تم إرسال التعليق بنجاح وجاري مراجعته");
        
        var _XmlHttp = createMessXMLHttp();
        var output;
        var path = "";

        path = "doServerRequest.aspx?req=AddMessage&title=" + escape(txttitle.value) + "&comment=" + escape(txtcomment.value) + "&mail=" + escape(txtmail.value) + "&cntry=" + escape(txtcntry.value) + "&MPId=" + escape(MPId) + "&mdlId=" + escape(mdlId) + "&mdlVl=" + escape(mdlVl) + "&msgType=" + escape(msgType) + "&icon=" + escape(HidIcon.value) + "&uId=" + escape(uId) + "&sId=" + escape(sId) + "&name=" + escape(txtName.value);
        _XmlHttp.open("get", path, true);
        _XmlHttp.onreadystatechange = function() {
            if (_XmlHttp.readyState == 4) {
                //                lblMess.innerHTML = _XmlHttp.responseText;
                divCmmCount.innerHTML = "<a href=\"#\"><div class=\"pic-comm\"></div></a><h3>عدد التعليقات (" + _XmlHttp.responseText + ")</h3>";
                txttitle.value = "";
                txtName.value = "";
                txtcomment.value = "";
                txtmail.value = "";
                txtcntry.value = "";
                HidIcon.value = "";

                lblMess.style.cssText = "TEXT-ALIGN: center; DISPLAY: inline; FONT-FAMILY: Tahoma; COLOR: red; FONT-SIZE: 11px;";
                lblMess.style.display = 'inline';

                
            }
        };
        _XmlHttp.send(null);
    }
    return false;
}

function setCheckIcon(hidId,value) {
    hid = document.getElementById(hidId);

    if (hid != null) {
        hid.value = value;
    }
}

