﻿var aMnu = new Array();var aCor = new Array();var aBoo = new Array();
var aLif = new Array();var aSur = new Array();var aNew = new Array();
var aCla = new Array();var aGal = new Array();var aFaq = new Array();
var aPro = new Array();
aMnu[0] = "tcor";aMnu[1] = "tboo";aMnu[2] = "tlif";aMnu[3] = "tsur";aMnu[4] = "tnew";
aMnu[5] = "tcla";aMnu[6] = "tgal";aMnu[7] = "tfaq";aMnu[8] = "tpro";
aCor[0] = new Array("About","mnu_lev2","about(1)");
aCor[1] = new Array("Meet our Team","mnu_lev2","about(2)");
aLif[0] = new Array("Club House","mnu_lev2","lifestyle(1)");
aLif[1] = new Array("Tennis Court","mnu_lev2","lifestyle(2)");
aLif[2] = new Array("Squash Court","mnu_lev2","lifestyle(3)");
aLif[3] = new Array("Security","mnu_lev2","lifestyle(4)");
aNew[0] = new Array("Active Events","mnu_lev2","buildEvent(1)");
aNew[1] = new Array("Past Events","mnu_lev2","buildEvent(2)");
var bStd = true;
function expMnu(vMnu)
{   
    var e = "c" + vMnu;
    var shtm = $(e).innerHTML;
    $(e).style.cursor = "wait";
    try
    {
        $(e).innerHTML = shtm + "<font size='0.3'> ...</font>";
        for (var n = 0; n < aMnu.length; n++) 
        {
            if (aMnu[n] != vMnu) 
            {
                e = "c" + aMnu[n];
                shtm = $(e).innerHTML;
                shtm = shtm.replace("<FONT size=0> ...</FONT>","");
                shtm = shtm.replace("mnu_minus.gif","mnu_plus.gif");
                $(e).innerHTML = shtm;
                delRows(aMnu[n]);
            }
        }
        switch (vMnu)
        {
            case "tcor": var aMnuItm = aCor; break;
            case "tboo":
                if ($("tboo").title == "Residence Area - not signed in")
                {
                    aBoo[0] = new Array("Login","mnu_lev2","book(1)");
                }
                else if ($("tboo").title == "Residence Area - signed in")
                {
                    aBoo[0] = new Array("Log out","mnu_lev2","book(8)");
                    aBoo[1] = new Array("Club House Booking","mnu_lev2","book(2)");
                    aBoo[2] = new Array("Squash Court Booking","mnu_lev2","book(3)");
                    aBoo[3] = new Array("Tennis Court Booking","mnu_lev2","book(4)");
                    aBoo[4] = new Array("Change your Password","mnu_lev2","book(5)");
                    //aBoo[5] = new Array("Update your details","mnu_lev2","book(6)"); 
                    aBoo[5] = new Array("Downloads","mnu_lev2","book(7)");
                    aBoo[6] = new Array("Squash Player Pool","mnu_lev2","book(9)");   
                    aBoo[7] = new Array("Report Maintenance","mnu_lev2","book(10)");   
                    aBoo[8] = new Array("Poll","mnu_lev2","book(11)");   
                     
                }
                var aMnuItm = aBoo;
                
                break;
            
            case "tlif": var aMnuItm = aLif; break;
            case "tsur": var aMnuItm = aSur; break;
            case "tnew": var aMnuItm = aNew; break;
            case "tcla": var aMnuItm = aCla; break;
            case "tgal": var aMnuItm = aGal; break;
            case "tfaq": var aMnuItm = aFaq; break;
            case "tpro": var aMnuItm = aPro; break;
        }
        var vTbl = $(vMnu);
        if (vTbl.rows.length == 1 && aMnuItm)
        {
            e = "c" + vMnu;
            shtm = $(e).innerHTML;
            shtm = shtm.replace("<FONT size=0> ...</FONT>","");
            shtm = shtm.replace("mnu_plus.gif","mnu_minus.gif");
            $(e).innerHTML = shtm;
            
            for (var n = 0; n < aMnuItm.length; n++) 
            {
                addRows(vMnu,aMnuItm[n][0],aMnuItm[n][1],aMnuItm[n][2]);
            }
        }
        else 
        { 
            e = "c" + vMnu;
            shtm = $(e).innerHTML;
            shtm = shtm.replace("<FONT size=0> ...</FONT>","");
            shtm = shtm.replace("mnu_minus.gif","mnu_plus.gif");
            $(e).innerHTML = shtm;
            delRows(vMnu);
        }
    }
    catch (e)
    {
        alert("An data error has occured. Please close the application and then try again!");
    }
    finally
    {
        $(e).style.cursor = "pointer";
    }
}
function $(e) {return document.getElementById(e);}
function tdiv(e) {return document.getElementById("divRight").innerHTML = e;}
function thead(e){return document.getElementById("topHeading").innerHTML = e;}
function tpic(e) {return document.getElementById("topPic").src = e;}
function delParentRows(vTable)
{
    var t = parent.document.getElementById(vTable);
    var nRows = t.rows.length;
    if (nRows > 1) { for (var n = nRows - 1; n > 0; n--) { t.deleteRow(n); }}
}
function delRows(vTable)
{
    t = $(vTable);
    var nRows = t.rows.length;
    if (nRows > 1) { for (var n = nRows - 1; n > 0; n--) { t.deleteRow(n); }}
}
function expDataMnu(type)
{
    var XHRO = false;
    var items, itemDesc, itemAddInf, propQty, surGraphic;
    var buildHTML;
    
    try
    {
        //init XMLHTTP object
        if (window.XMLHttpRequest) { XHRO = new XMLHttpRequest(); }       
        else if (window.ActiveXObject) { XHRO = new ActiveXObject("Microsoft.XMLHTTP"); }
       
        //get menu data
        if(XHRO) 
        {
            XHRO.open("GET", "aj_retMenuData.aspx?sType=" + type);
            XHRO.onreadystatechange = function()
            {
                
                 if (XHRO.readyState == 4 && XHRO.status == 200) 
                 {
                   
                    var xmlDoc = XHRO.responseXML;
                    items = xmlDoc.getElementsByTagName("item");
                    
                    buildHTML = "";
                    
                    for (loopIndex = 0;loopIndex < items.length; loopIndex ++)
                    {
                        itemDesc = items(loopIndex).firstChild;
                        itemAddInf = itemDesc.nextSibling;
                        if (type == "tpro")
                        {
                            propQty = itemAddInf.nextSibling;
                        }
                        if (type == "tsur")
                        {
                            surGraphic = itemAddInf.nextSibling;
                        }
                        switch (type)
                        {
                            case "tsur":
                                aSur[loopIndex] = new Array(itemDesc.firstChild.data,"mnu_lev2","buildSur(" + itemAddInf.firstChild.data + ")");
                                break;
                            case "tcla":
                                aCla[loopIndex] = new Array(itemDesc.firstChild.data,"mnu_lev2","buildClass(" + itemAddInf.firstChild.data + ")");
                                break;
                            case "tgal":
                                aGal[loopIndex] = new Array(itemDesc.firstChild.data,"mnu_lev2","buildGal(" + itemAddInf.firstChild.data + ")");
                                break;
                            case "tfaq":
                                aFaq[loopIndex] = new Array(itemDesc.firstChild.data,"mnu_lev2","buildFAQ(" + itemAddInf.firstChild.data + ")");
                                break;
                            case "tpro":
                                var sDesc = "";
                                if (itemDesc.firstChild.data.length > 25)
                                {
                                    sDesc = itemDesc.firstChild.data.substring(0,25) + "...";
                                }
                                else
                                {
                                    sDesc = itemDesc.firstChild.data;
                                }
                                aPro[loopIndex] = new Array(sDesc + " (" + propQty.firstChild.data + ")","mnu_lev2","buildProp(" + itemAddInf.firstChild.data + ")");
                                break;
                        }
                    }
                    expMnu(type)
                 }
            }
        }
        
    }
    catch (e)
    {
        alert("An data error has occured. Please close the application and then try again!");
    
    }
    finally
    {
        XHRO.send(null);
    }
}
function addParentRows(vTable,vText,vClass,vNavigate)
{
     var vTbl = parent.document.getElementById(vTable);
     var newRow = vTbl.insertRow(vTbl.rows.length);
     newRow.id = newRow.uniqueID;
     var newCell = newRow.insertCell(0);
     if (vNavigate.indexOf("(") != -1)
     {
        newCell.innerHTML = "<a style='width:100%' class='ht_link' onclick='" + vNavigate + "'>" + vText + "</a>";
     }
     else
     {
        newCell.innerHTML = "<a style='width:100%' class='ht_link' href='" + vNavigate + "?t=" + vText + "'>" + vText + "</a>";
     }
     newCell.className = vClass;
}
function addRows(vTable,vText,vClass,vNavigate)
{
     var vTbl = $(vTable);
     var newRow = vTbl.insertRow(vTbl.rows.length);
     newRow.id = newRow.uniqueID;
     newRow.className = vClass;
     var newCell = newRow.insertCell(0);
     if (vNavigate.indexOf("(") != -1)
     {
        newCell.innerHTML = "<a style='width:100%' class='ht_link' onclick='" + vNavigate + "'>" + vText + "</a>";
     }
     else
     {
        newCell.innerHTML = "<a style='width:100%' class='ht_link' href='" + vNavigate + "?t=" + vText + "'>" + vText + "</a>";
     }
     newCell.className = vClass;
     
}
function buildGal(nImgTypeId)
{
    if (bStd == false) {stdTop(); bStd = true}
    thead("Gallery");
    tdiv("Loading....");
    var sDataSource = "aj_retGalleryData.aspx?sType=galPerType&nGalleryTypeId=" + nImgTypeId;
    expDataCollector(sDataSource,"gal");
}
function cll()
{
    thead("Classifieds");tpic("images/top_classified.jpg");
    tdiv("Select your classified category on the menu to your left");
    expDataMnu('tcla')
    window.scrollTo(0,0);
}
function buildClass(type)
{
    if (bStd == false) {stdTop(); bStd = true}
    thead("Classifieds");tdiv("Loading....");tpic("images/top_classified.jpg");
    var sDataSource = "aj_retClass.aspx?ctid=" + type;
    expDataCollector(sDataSource,"cla");
}
function buildProp(type)
{
    bStd = false;
    thead("Properties");tdiv("Loading....");
    var sDataSource = "aj_retPropData.aspx?aid=" + type;
    expDataCollector(sDataSource,"pro");
}
function buildFAQ(type)
{
    if (bStd == false) {stdTop(); bStd = true}
    thead("Frequently Asked Questions");tdiv("Loading....");tpic("images/top_faq.jpg");
    var sDataSource = "aj_retFAQ.aspx?qid=" + type;
    expDataCollector(sDataSource,"faq");
}
function el()
{
    expMnu('tnew');
    buildEvent(1);
}
function buildEvent(type)
{
    if (bStd == false) {stdTop(); bStd = true}
    tdiv("Loading...."); tpic("images/top_news.jpg");
    if (type == 1)
    {
        thead("Active Events");
        var sDataSource = "aj_retEventData.aspx?sType=act";
        expDataCollector(sDataSource,"evt_act");
    }
    else if (type == 2)
    {
        thead("Past Events");
        var sDataSource = "aj_retEventData.aspx?sType=past";
        expDataCollector(sDataSource,"evt_past");
    }
    window.scrollTo(0,0);
}
function sl()
{
    thead("Surrounds");tpic("images/misc_parks.jpg");tdiv("Select your surround category on the menu to your left");
    expDataMnu('tsur')
    window.scrollTo(0,0);
}
function buildSur(nSurId)
{
    
    if (bStd == false) {stdTop(); bStd = true}
    tdiv("Loading....");
    var sDataSource = "aj_retSurround.aspx?type=st&id=" + nSurId;
    expDataCollector(sDataSource,"sur");
    window.scrollTo(0,0);
}
function pl()
{
    thead("Properties");tpic("images/top_property.jpg");tdiv("Select your agent on the menu to your left");
    expDataMnu('tpro')
    window.scrollTo(0,0);
}
function openPro()
{
    thead("Properties");tdiv("Loading....");
    var bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:100%' src='ke_propagencyD.aspx'></iframe>";
    $("divRight").innerHTML = bhtm;
}
function openCont()
{
    if (bStd == false) {stdTop(); bStd = true}
    thead("Kyalami Contact Details... (loading)");
    var bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:850px' src='ke_contact.htm'></iframe>";
    $("divRight").innerHTML = bhtm;
    window.scrollTo(0,0);
}
function openAdv()
{
    window.open("ke_advertise.aspx","_self");
}
function openPopUp(image,width,height) 
	{
	    popup = window.open(image,"","width=" + width + ",height=" + height +",resizable,scrollbars,top=100px");
    }
function openPre()
{
    openPopUp("http://kyalami.sungula.com/SUN_LOGIN.aspx",500,300);
    //window.open("http://kyalami.sungula.com/SUN_LOGIN.aspx","_blank");
    //window.open("/eacs/index.asp","_blank");
    //thead("Pre-clearance");tdiv("Loading....");
    //var bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:300px' src='http://kyalami.sungula.com/SUN_LOGIN.aspx'></iframe>";
    //$("divRight").innerHTML = bhtm;
    //tdiv(bhtm);
    //window.scrollTo(0,0);
}
function book(type)
{
    if (bStd == false) {stdTop(); bStd = true}
    var bhtm = "<table style='width:90%' align='center'><br/><tr><td>You are not authorized to access this page.</td></tr><tr><td>&nbsp;</td></tr><tr><td>If you are a Kyalami Estates resident, please login above to access this page.</td></tr></table>";
    switch (type)
    {
        case 1: 
            thead("Login");tpic("images/top_security.jpg");
            bhtm = "<iframe frameborder='0' style='width:90%; background-color:#ffffff; height:200px' src='ke_reslogin.aspx'></iframe>"; break; 
        case 2:
            thead("Bookings - Club House"); tpic("images/top_clubhouse.jpg");
            bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:430px' src='ke_bookClubhouse.aspx'></iframe>";
            break; 
        case 3: 
            thead("Bookings - Squash Court"); tpic("images/book_squash.jpg");
            bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:800px' src='ke_bookSquash.aspx'></iframe>"; 
            break; 
        case 4: 
            thead("Bookings - Tennis Court"); tpic("images/top_tennis.jpg");
            bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:1100px' src='ke_bookTennis.aspx'></iframe>"; 
            break;
        case 5: 
            thead("Change Password"); tpic("images/top_security.jpg");
            bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:200px' src='ke_bookPassw.aspx'></iframe>"; 
            break;
        case 6: 
            thead("Update your details"); tpic("images/top_security.jpg");
            bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:1350px' src='http://kesubmit.gemsolutions.co.za'></iframe>"; 
            break;
        case 7: 
            thead("Downloads"); tpic("images/top_security.jpg");
            bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:200px' src='ke_downloads.aspx'></iframe>"; 
            break;
        case 8: 
            window.open ('ke_logoff.aspx','_self');
            break;
        case 9: 
            thead("Squash Court - Players"); tpic("images/book_squash.jpg");
            bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:1100px' src='ke_pool.aspx'></iframe>"; 
            break;
        case 10: 
            thead("Report Maintenance"); tpic("images/top_clubhouse.jpg");
            bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:1100px' src='ke_reportMaint.aspx'></iframe>"; 
            break;
        case 11: 
            thead("Poll"); tpic("images/top_clubhouse.jpg");
            bhtm = "<iframe frameborder='0' style='width:100%; background-color:#ffffff; height:1100px' src='ke_Poll.htm'></iframe>"; 
            break;
    }
    tdiv(bhtm);
    
}
function ll()
{
    thead("Life Style"); tdiv("Select your Life Style category on the menu to your left");
    expDataMnu('tlif')
    lifestyle(1)
}
function lifestyle(type)
{
    if (bStd == false) {stdTop(); bStd = true}
    tpic("images/top_clubhouse.jpg");tdiv("Loading....");
    var bhtm = "";
    switch (type)
    {
        case 1: 
            thead("Lifestyle - Club House");tpic("images/top_clubhouse.jpg");
            bhtm = "<iframe frameborder='0' style='background-color:#ffffff; width:100%; height:550px' src='ke_clubhouse.htm'></iframe>"; break;
        case 2: 
            thead("Lifestyle - Tennis Court");tpic("images/top_tennis.jpg")
            bhtm = "<iframe frameborder='0' style='background-color:#ffffff; width:100%; height:950px' src='ke_tenniscourt.htm'></iframe>"; break;
        case 3: 
            thead("Lifestyle - Squash Court");tpic("images/book_squash.jpg");
            bhtm = "<iframe frameborder='0' style='background-color:#ffffff; width:100%; height:450px' src='ke_squashcourt.htm'></iframe>"; break;
        case 4: 
            thead("Lifestyle - Security");tpic("images/top_security.jpg");
            bhtm = "<iframe frameborder='0' style='background-color:#ffffff; width:100%; height:1400px' src='ke_security.htm'></iframe>"; break;
    }
    tdiv(bhtm);
    window.scrollTo(0,0);
}
function al()
{
    expMnu('tcor');
    about(1);
}
function about(type)
{
    if (bStd == false) {stdTop(); bStd = true}
    tdiv("Loading....");
    var bhtm;
    switch (type)
    {
        case 1: 
            thead("About Kyalami Estates");tpic("images/top_corporate.jpg");
            bhtm = "<iframe frameborder='0' style='background-color:#ffffff; width:100%; height:500px' src='ke_corporate.htm'></iframe>"; break;
        case 2: 
            thead("Kyalami Estates Management");tpic("images/top_corporate.jpg");
            bhtm = "<iframe frameborder='0' style='background-color:#ffffff; width:100%; height:1700px' src='ke_management.htm'></iframe>"; break;
    }
    tdiv(bhtm);
    window.scrollTo(0,0);
}
function propParam(prop)
{
    var ebtn = "ppbtn" + prop;
    var ediv = "ppdiv" + prop;
    var efra = "ppfra" + prop;
    $(ediv).innerHTML = "Loading...";
    //$(efra).innerHTML = "Loading Pictures...";
    if ($(ebtn).value == "More Details")
    {
        var sDataSource = "aj_retPropParam.aspx?nPropId=" + prop;
        expDataCollector(sDataSource,"propar",prop);
        $(ebtn).value = "Hide Details";
        $(ediv).style.height = "150px";
        $(efra).style.height = "150px";
        $(efra).style.visibility = "visible";
        $(efra).src = "ke_proppicsD.aspx?nPropertyId=" + prop;
    }
    else
    {
        $(ebtn).value = "More Details";
        $(ediv).style.height = "0px";
        $(efra).style.height = "0px";
        $(efra).style.visibility = "hidden";
    }
}