﻿function GetGeoValue(GeoProperty, elemID)
{
    $(document).ready(
        function()
        {
            if(GeoProperty != null && GeoProperty != "")
            {
                switch(GeoProperty.toLowerCase())
                {
                    case "city":
                        cit = GetCookie("city");
                        if(cit == null || cit == "")
                            cit = geoplugin_city();
                        SetValue(cit, elemID);
                    break;
                    case "state":
                        st = GetCookie("state");
                        if(st == null || st == "")
                            st = geoplugin_region();
                        SetValue(st, elemID);
                    break;
                    default:
                        st = GetCookie(GeoProperty.toLowerCase());
                        if(st != null && st != "")
                            SetValue(st, elemID);
                    break;
                }
            }
        }
    )
}
function SetCookie(val, key)
{
    var options = { path: '/', expires: 180 };
    $.cookie(key, val, options)
}
function GetCookie(key)
{
    return $.cookie(key);
}
function SetValue(val, id)
{
    c = $("#" +id);
    try
    {
        c.val(val);
    }
    catch(e)
    {
        try
        {
            c.text(val);
        }
        catch(e)
        {
            try
            {
                c.html(val);
            }
            catch(e)
            {
            }
        }
    }
}
