﻿function ShowRegion(IdRegion)
{
    PageMethods.GetRegion(IdRegion, GetRegion_OK, GetRegion_Error, null);
}

function GetRegion_Error(ex, ctx, methodName)
{
    alert("An error has ocurred " + ex + " " + methodName);
}

function GetRegion_OK(region, ctx, methodName)
{
    if (typeof(region.length) == "undefined")
        var innerHtml = "<ul style='position: relative; top: 25px;'class=\"division\"><li style=\"border-style:none; width:100%; height: 20px; float: none; margin-left: 0px;\"><h3>" + region.Region + "</h3></li>   ";
    else
        var innerHtml = "<ul style='white-space:nowrap; position: relative; top: 25px;' class=\"division\"><li style=\"white-space:normal; border-style:none; height: 20px; float: none; width:100%; margin-left: 0px;\"><h3>" + region[0].Region + "</h3></li>   ";
    if (region.length != 0)
    {
        for(var i = 0; i < region.length; i++) {
            if (i <= 2) {
                innerHtml += "<li class=\"top\"";
                //style='width:220px;' has been comented in order to have an auto width
                if (i == 0)
                    innerHtml += "style=\"margin-left: 0px;\"";
                innerHtml += ">";
            } 
            else if (i = 3)
                innerHtml += "<li style=\"border-style:none;\"></li><li>";
            else
                innerHtml += "<li >";
            innerHtml +=    "       <h5>" + region[i].Division +  "</h5>";
            innerHtml +=    "       <span style='display:block; white-space:nowrap' class=\"time\">" + region[i].Name + "</span>"; 
            innerHtml +=    "       <p ><a href=\"mailto:" + region[i].EmailAddress + "\">" + region[i].EmailAddress + "</a></p>";
            innerHtml +=    "   </li>";
        }
        innerHtml +=    "   </ul>";
        innerHtml +=    "<div class=\"clear\">";
        innerHtml +=    "<!-- -->";
        innerHtml +=    "</div>";
    }
    document.getElementById("divDivision").style.display = "";
    document.getElementById("divDivision").innerHTML = innerHtml;
}