﻿// generics.js

// The page feedback display element.


var tempResult_Generic;
var path;
var height = 0;
var width = 0;
if (window.navigator.appName == 'Microsoft Internet Explorer') {
    if (window.navigator.appVersion.search(6.0) != -1) {
        height = '538px'
        width = '576px'

    }
    else {
        height = '535px'
        width = '570px'
    }
}
else {
    height = '525px';
    width = '570px'
}
// This function intializes the global variables and
// assigns default values to the generated proxy.
function pageLoad_Generic() {
    //alert(SiteUrlForControls);

    try {
        $.ajax({
            type: "POST",
            url: SiteUrlForControls + "/GetAllStoreLocaterDetails.aspx",
            data: "{'MerchantId':'" + merchantIdStore + "','MasterMerchantId':'" + MasterMId + "','SiteAccType':'" + SiteAccType + "','Productid':'" + JProductid + "'}",
            beforeSend: function(xhr) {
                xhr.setRequestHeader("Content-type",
                           "application/json; charset=utf-8");

            },
            dataType: "json",
            success: function(msg) {
                tempResult_Generic = msg;
                SucceededCallback_Generic(msg, 'getChildStores');
            }

        });

    }
    catch (ex) {
    }

}


// Get a generic Dictionary.

// Get an Array.
function properCase(a) {
    var b = "";
    var notyet = true;
    for (i = 0; i <= a.length; i++) {
        m = a.substr(i, 1)
        b += (notyet) ? m.toUpperCase() : m.toLowerCase();
        notyet = (m.toUpperCase() == m.toLowerCase())
    }
    return b;

}

function gotoWindowOpen(count) {
    var z = JSON.parse(tempResult_Generic);
    var record = z[count];
    var siteurl = record.SiteUrl + "/ProductDetails.aspx?pid=" + record.ProductID_Child
    window.open(siteurl, 'mywindow', 'width=700,height=500,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');
}
// Callback function invoked when the call to 
// the Web service methods succeeds. 
function SucceededCallback_Generic(data, methodName) {
    var message;
    var z = JSON.parse(data);
    try {

        switch (methodName) {

            case ("getChildStores"):
                {
                    var i = 0;
                    var message = new Array();
                    var strStateCompare = "";
                    tempResult_Generic = data;

                    var i = 0;

                    for (var cou = 0; cou < z.length; cou++) 
                    {
                        var record = z[cou];
                        if (record.IsCorporate && record.SiteType != "RE") 
                        {

                            path = record.SiteUrl + "/Productdetails.aspx?Pid=" + record.ProductID_Child;

                         try {
                                btnYAMLBuyOnline.style.display = "";
                                pnlBuyOnline.style.display = "";
                            }
                            catch (ex) {
                            }
                          
                        }

                    }
                    
                    break;
                }

            case ("GetServerTime"):
                {
                    var i = 0;

                    for (var cou = 0; cou < z.length; cou++) {
                        var record = z[cou];
                        // message[i] = "List element " + i + ": " + result[item].AreaId;
                        if (record.CityId == drpCity_Generic.value) {
                            if (drpState_Generic)
                                drpState_Generic.options[i + 1] = new Option(record.StateName, record.StateId)
                            i++;

                        }
                    }
                    break;
                }

            default:
                {
                    DisplayMessage("Method unknown");

                }
        }
    }
    catch (ex) {
    }

}

// Callback function invoked when the call to 
// the Web service methods fails.
function FailedCallback_Generic(error, userContext, methodName) {
    if (error !== null) {
        error.get_message();
    }
}

function openIsCorporate() {
    document.location.href = path;
}





