﻿var xmlHttp;
function createXMLHttpRequest() {
    if (window.ActiveXObject) {
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttp = new XMLHttpRequest();
    }
}
//---------------------------------
var xmlHttp_InsertRefer;
function createXMLHttpRequest_InsertRefer() {
    if (window.ActiveXObject) {
        xmlHttp_InsertRefer = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttp_InsertRefer = new XMLHttpRequest();
    }
}
//---------------------------------
var xmlHttp_JadidTarinha;
function createXMLHttpRequest_JadidTarinha() {
    if (window.ActiveXObject) {
        xmlHttp_JadidTarinha = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttp_JadidTarinha = new XMLHttpRequest();
    }
}
//---------------------------------
var xmlHttp_PorForoshTarinha;
function createXMLHttpRequest_PorForoshTarinha() {
    if (window.ActiveXObject) {
        xmlHttp_PorForoshTarinha = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        xmlHttp_PorForoshTarinha = new XMLHttpRequest();
    }
}
//---------------------------------
function ShowSrchDiv() {
    var d = document.getElementById('divsrch');
    var t = document.getElementById('txtSrch');
    if (t.value.length > 1) {
        d.style.left = findPos(t)[0] + 'px';
        d.style.top = findPos(t)[1] + 'px';
        d.style.display = 'block';
        d.innerHTML = "<br /><img src=\"images/loading.gif\" /><br /><br />";
    }
}
//---------------------------------
function updateSrchDiv() {
    var randomnumber = Math.floor(Math.random() * 123456789);
    var srchword = document.getElementById('txtSrch').value;
    url = "content/cont_srch.aspx?s=" + document.getElementById('lbls').value + "&t=" + document.getElementById('lblt').value + "&w=" + encodeURIComponent(srchword) + "&rn=" + randomnumber;
    if (srchword.length > 1) {
        xmlHttp.open("GET", url, true);
        xmlHttp.onreadystatechange = doUpdateSrch;
        xmlHttp.send();
        return false;
    }
    else {
        $("#divsrch").fadeOut('slow');
    }
}
function doUpdateSrch() {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        var content = xmlHttp.responseText;
        if (content != "") document.getElementById('divsrch').innerHTML = xmlHttp.responseText;
        else document.getElementById('divsrch').innerHTML = "<p>" + "محصولی یافت نشد" + "</p>";
    }
}
//---------------------------------
function updatePage() {
    var randomnumber = Math.floor(Math.random() * 123456789);
    var url = "content/cont_GetHtmlDataBox.aspx?t=" + document.getElementById('lblt').value + "&s=" + document.getElementById('lbls').value + "&whatido=1" + "&r=" + randomnumber;
    xmlHttp.open("GET", url, true);
    xmlHttp.onreadystatechange = doUpdate;
    xmlHttp.send();
    return false;
}
function doUpdate() {
    if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        var resp = xmlHttp.responseText;
        document.getElementById('divCatMenuBox').innerHTML = resp;
    }
}
//----------------------------------
function updateJadidTarinha() {
    var randomnumber = Math.floor(Math.random() * 123456789);
    var url = "content/cont_GetHtmlDataBox.aspx?t=" + document.getElementById('lblt').value + "&s=" + document.getElementById('lbls').value + "&whatido=2" + "&r=" + randomnumber;
    xmlHttp_JadidTarinha.open("GET", url, true);
    xmlHttp_JadidTarinha.onreadystatechange = doupdateJadidTarinha;
    xmlHttp_JadidTarinha.send();
    return false;
}
function doupdateJadidTarinha() {
    if (xmlHttp_JadidTarinha.readyState == 4 && xmlHttp_JadidTarinha.status == 200) {
        var resp = xmlHttp_JadidTarinha.responseText;
        document.getElementById('divJadidtarinha').innerHTML = resp;
    }
}
//----------------------------------
function updatePorForoshTarinha() {
    var randomnumber = Math.floor(Math.random() * 123456789);
    var url = "content/cont_GetHtmlDataBox.aspx?t=" + document.getElementById('lblt').value + "&s=" + document.getElementById('lbls').value + "&whatido=3" + "&r=" + randomnumber;
    xmlHttp_PorForoshTarinha.open("GET", url, true);
    xmlHttp_PorForoshTarinha.onreadystatechange = doupdatePorForoshTarinha;
    xmlHttp_PorForoshTarinha.send();
    return false;
}
function doupdatePorForoshTarinha() {
    if (xmlHttp_PorForoshTarinha.readyState == 4 && xmlHttp_PorForoshTarinha.status == 200) {
        var resp = xmlHttp_PorForoshTarinha.responseText;
        document.getElementById('divPorForoshtarinha').innerHTML = resp;
    }
}
//----------------------------------
function InsertRefer() {
    var randomnumber = Math.floor(Math.random() * 123456789);
    var HTTP_REFERER = $("#HTTP_REFERER").val();
    var CurrentUrl = $("#CurUrl").val(); HTTP_REFERER = HTTP_REFERER.replace(".html", "0000000000");
    var goodcode = $("#GoodCode").val();
    var url = "content/cont_RegRefer.aspx?goodcode=" + goodcode + "&Path=" + CurrentUrl + "&RefPath=" + HTTP_REFERER + "&r=" + randomnumber;
    if (url.indexOf("&s=") == -1) url = url + "&s=" + document.getElementById('lbls').value;
    xmlHttp_InsertRefer.open("GET", url, true);
    xmlHttp_InsertRefer.onreadystatechange = doInsertRefer;
    xmlHttp_InsertRefer.send();
    return false;
}
function doInsertRefer() {
    if (xmlHttp_InsertRefer.readyState == 4 && xmlHttp_InsertRefer.status == 200) {
    }
}
//----------------------------------
$(document).ready(function () {
    $("#main").click(function () {
        $("#divsrch").fadeOut('slow');
    });
});

$(document).ready(function () {
    createXMLHttpRequest();
    updatePage();
    createXMLHttpRequest_InsertRefer();
    InsertRefer();
    if (document.getElementById('divJadidtarinha') != null) {
        createXMLHttpRequest_JadidTarinha();
        updateJadidTarinha();
    }
    if (document.getElementById('divPorForoshtarinha') != null) {
        createXMLHttpRequest_PorForoshTarinha();
        updatePorForoshTarinha();
    }

});
//----------------------------------

