﻿// Utils
function ActivateAlertDiv(visstring, elem, msg) {
    var adiv = document.getElementById(elem);
    adiv.style.visibility = visstring;
    var panUpdate = document.getElementById('Result');
    var progIndicator2 = document.getElementById('AlertDiv');
    var opaqueDiv = document.getElementById('opaqueDiv');

    opaqueDiv.style.visibility = 'visible';

    panUpdate.className = "PanelUpdating";
    var marginTop = 0;
    var marginLeft = 0;
    if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent) || /WebKit[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
        var ffversion = new Number(RegExp.$1);
        if (ffversion >= 3) {
            FXon = true;
        }
        //browser = "ff"; chrome
        marginTop = document.defaultView.getComputedStyle(document.body, "").marginTop.match(/\d+/);
        marginLeft = document.defaultView.getComputedStyle(document.body, "").marginLeft.match(/\d+/);
    } else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        //IE fails on showing DIV with initially width ==0, set to true when they fix this
        var ieversion = new Number(RegExp.$1);
        if (ieversion >= 8) {
            FXon = false;
        }
        else if (ieversion >= 7) {
            FXon = false;
        }
        //browser = "ie";
        marginTop = document.body.currentStyle.marginTop.match(/\d+/);
        marginLeft = document.body.currentStyle.marginLeft.match(/\d+/);
    }
	var position = $("#Result").position();
    var toptop = position.top;
    var leftleft = position.left;
    progIndicator2.style.left = ((leftleft - 0) + ((panUpdate.offsetWidth / 2) - 0) - ((progIndicator2.offsetWidth / 2) - 0) - (marginLeft / 2 - 0)) + "px";
    progIndicator2.style.top = ((toptop - 0) + ((panUpdate.offsetHeight / 2) - 0) - ((progIndicator2.offsetHeight / 2) - 0) - (marginTop / 2 - 0)) + "px";
    opaqueDiv.style.height = panUpdate.offsetHeight + "px";
    opaqueDiv.style.width = panUpdate.offsetWidth + "px";
    opaqueDiv.style.left = (leftleft+5) + "px";
    opaqueDiv.style.top = (toptop+5) + "px";
}
///
var T = null;
function getReview() {
	
    $.ajax({
        type: "POST",
        url: "ReviewsApp/getRwidget.aspx/GetReview",
        data: "{'firstName':'Aritz','lastName':'Alson'}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            document.getElementById('Result').innerHTML = msg.d;
            var adiv = document.getElementById('AlertDiv');
            adiv.style.visibility = 'hidden';
            document.getElementById('Result').className = "mainmodule2"; // "PanelNormal";
            var opaqueDiv = document.getElementById('opaqueDiv');
            opaqueDiv.style.visibility = 'hidden';
            clearTimeout(T);
            T = setTimeout("getReview();", 1000 * 60 * 3);
        },
        beforeSend: function (msg) {
            ActivateAlertDiv('visible', 'AlertDiv', ' processing...');
        },
		timeout:5000,
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			//myErrorHandler("An error has occurred making the request: " + errorThrown);
			//alert("timeOut");
            clearTimeout(T);
			getReview();
        }
    });
}

//End Utils


