﻿IPC = {};
IPC.homePageTestimonial = function () {
    IPC.AjaxRequest('service.asmx/GetRecentOneTestimonial', '{}', function (result) {
        var results = eval('(' + result + ')');
        var data = '';
        if (results.HasError == undefined) {
            data += '<div class="float-left txtcent textmsg"><img  width="106px" height="101px" src="' + results.imagePath + '" /><br />';
            data += '<strong >' + results.username.split(' ')[0].toString() + '<BR />' + results.username.split(' ')[1].toString() + '</strong></div>';
            data += '<p>' + results.title + '</p>'
            $('#testimonialcontainer').empty()
            .html(data);

        }

    }, function () { });
};
IPC.submitconsultationForm = function (A, B, C, E, F, G, H, I) {
    
        IPC.AjaxRequest("service.asmx/submitconsultation", "{'name':'" + A + "','address':'" + B + "','ph':'" + C + "','mobile':'"+I+"','email':'" + E + "','day':'" + F + "','date':'" + G + "','time':'" + H + "',}", function (result) {
            var results = eval('(' + result + ')');
            if (results == 'success') {
                alert('Thank You for the details. Our Medical Representative will get back to shortly');
            }
        }, function () { });
};
IPC.dashboardPublication = function () {
    IPC.AjaxRequest("service.asmx/getPublications", "{'count':'2'}", function (result) {
        var results = eval('(' + result + ')');
        if (result.HasError == undefined) {
            var i = 0, data = '';
            data += ' <div class="itemboxhead float-left clear"><img src="resources/images/icon/publication.jpg"><span><a href="http://www.ipc-india.org/publications/">Cardiology Publications</a></span></div>'

            for (i = 0; i < results.length; i++) {
                if (i == 0) {
                    if (results[i].PublicationType == 'Book')
                        data += '<div class="publicationitem float-left txtcent lclear"><img  width="77px" height="81px" src="' + results[i].Thumbnail + '" /><br>' + results[i].Title + '<br><a href="publications/booksdetails.aspx?id=' + results[i].ID + '"><img src="resources/images/btnknowmore.jpg" alt="Know More" /></a></div>';
                    else
                        data += '<div class="publicationitem float-left txtcent lclear"><img  width="77px" height="81px"  src="' + results[i].Thumbnail + '" /><br>' + results[i].Title + '<br><a href="publications/cddetails.aspx?id=' + results[i].ID + '"><img src="resources/images/btnknowmore.jpg" alt="Know More" /></a></div>';
                } else {
                    if (results[i].PublicationType == 'Cd')
                        data += '<div class="publicationitem float-left txtcent"><img  width="77px" height="81px"  src="' + results[i].Thumbnail + '" /><br>' + results[i].Title + '<br><a href="publications/booksdetails.aspx?id=' + results[i].ID + '"><img src="resources/images/btnknowmore.jpg" alt="Know More" /></a></div>';
                    else
                        data += '<div class="publicationitem float-left txtcent"><img  width="77px" height="81px" src="' + results[i].Thumbnail + '" /><br>' + results[i].Title + '<br><a href="publications/cddetails.aspx?id=' + results[i].ID + '"><img src="resources/images/btnknowmore.jpg" alt="Know More" /></a></div>';
                }
            }
            $('#publications').empty()
            .append(data);
        }







    }, function () { });
};
IPC.dashboardAnnoucment = function () {
    IPC.AjaxRequest('service.asmx/getAnnoucements', '{count:2}', function (result) {
        var results = eval('(' + result + ')');
        var data = '';
        data += ' <div class="itemboxhead float-left clear"><img src="resources/images/icon/news.jpg" /><span><a href="http://ipc-india.org/media/News.aspx"> News &amp; Event</a></span></div>';
        if (results.HasError == undefined) 
        {
            if (results) 
            {
                data += '<ul class="clear">';
                //   var data = '';
                for (var i = 0; i < results.length; i++) 
                {
                    data += ' <li><strong>' + results[i].Title + '</strong><br /><br />' + results[i].Description + '</li>';
                }
                data += ' </ul>';

            }
            $('#announments').empty()
            .append(data);
        }
    }, function () { });
}
IPC.dashboardArticles = function() {
    IPC.AjaxRequest("service.asmx/getArticals", "{'count':'5'}", function(result) {
        var results = eval('(' + result + ')');
        var data = '';
        data += '<div class="itemboxhead float-left clear"><img src="resources/images/icon/articles.jpg" /><span><a href="http://ipc-india.org/blog/">Recent Blog Posts </a></span></div>';
        if (results.HasError == undefined) {
            if (results) {
                data += '<ul class="clear">';
                //   var data = '';
                for (var i = 0; i < results.length; i++) {
                    data += ' <li><strong>' + results[i].Title + '</strong><br /></li>';
                }
                data += ' </ul>';

            }
            $('#Articals').empty()
            .append(data);
        }
    }, function() { });
};



IPC.initDefaultPage = function () {
    IPC.homePageTestimonial();
    IPC.dashboardPublication();
    IPC.dashboardArticles();
    IPC.dashboardAnnoucment();
};
IPC.submitPatientPaidEnquiry = function (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X) {
    IPC.AjaxRequest('service.asmx/submitPatientPaidEnquiry',
    function () {
        var param = "{";
        param += "'name':'" + A + "',";
        param += "'age':'" + B + "',";
        param += "'sex':'" + C + "',";
        param += "'heartattack':'" + D + "',";
        param += "'bloodpresure':'" + E + "',";
        param += "'diabetes':'" + F + "',";
        param += "'obes':'" + G + "',";

        param += "'ecg':'" + H + "',";
        param += "'Dyslipidemia':'" + I + "',";

        param += "'smokealhocol':'" + J + "',";
        param += "'familyhistory':'" + K + "',";
        param += "'heamoglobin':'" + L + "',";
        param += "'fbs':'" + M + "',";
        param += "'pmbs':'" + N + "',";
        param += "'screatinine':'" + O + "',";
        param += "'totalcholestrol':'" + P + "',";
        param += "'triglyceride':'" + Q + "',";
        param += "'hdl':'" + R + "',";
        param += "'ldl':'" + S + "',";
        param += "'vldl':'" + T + "',";
        param += "'email':'" + U + "',";
        param += "'mobile':'" + V + "',";
        param += "'address':'" + W + "',";
        param += "'complaint':'" + X + "',";

        param += "}";
    },
     function (reuslt) {
         var results = eval('(' + reuslt + ')');
         alert(results);
     }, function () { });
};
IPC.AjaxRequest = function (url, params, successcallback, errorcallback) {
    $.ajax({
        type: "POST",
        url: url,
        data: params,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: successcallback,
        error: errorcallback
    });
};



