/*
	NAV.JS
	All Navigation Related Script, Functions & Selector Events

	Functions: 
		buildCommunityNav( currentCommunityID ) : creates the community nav bar, multi-lingual
		oaSelect() : builds the HTML Select box with all OA's, Units contained
		changeSelection( params ) : switches the current MyAccount OA & Unit # to the selected in params
		checkCommunity() : searches all user priviledges to check if any relationship to the current community exists
		checkLotRoles( roles ) : searches the currently Selected Lot to see if the user has the specified roles 
		checkOARoles( roles ) : searches the currently Selected OA to see if the user has the specified roles 
		checkCommunityRoles( roles ) : searches the currently Selected Community to see if the user has the specified roles 
		checkSystemAndRoles( system, roles ) : seaches for relationship with System and Roles
		accountInfo() : build the accountInfo status menu
		buildMyAccountNav() : creates the secondary menu items for the MyAccount area			
		loginErrorShow( error ) : shows the login error paragragh
		loginErrorHide() : hides the login error paragraph
		breadCrumbs( communityID ) : returns all upstream communities

	Issues, Suggestions, Problems:
		Peter Liu (peter@mystrata.com)
*/

function buildCommunityNav( currentCommunityID )
{
	// NAV BAR: BURJ 
	if ( currentCommunityID == 33 || currentCommunityID == 34 || currentCommunityID == 35 || currentCommunityID == 36 || currentCommunityID == 37 )
	{
		//ADD CLASS
		if( get_cookie( 'lang' ) == "ar" )
		{
			// NAV BAR: BURJ (ARABIC)
			var html = '\
				<ul class="sf-menu burj" id="nav">\
					<li class=""><a id="homeBurj"  href="#">الصفحة الرئيسية</a></li>\
       					<li><a id="aboutBurj"  href="#">حول</a>\
						<ul>\
       							<li><a id="aboutOverviewBurj"  href="#">برج خليفة</a></li>\
       							<li><a id="aboutSurroundsBurj"  href="#">بناء الحواشي</a></li>\
							<li><a id="aboutEmaarBurj"  href="#">إعمار</a></li>\
							<li><a id="aboutGalleryBurj"  href="#">معرض</a></li>\
        					</ul>\
        				</li>\
					<li><a id="liveBurj"  href="#">العيش</a>\
						<ul>\
               						<li><a id="liveTheResidenceBurj"  href="#">الإقامة</a></li>\
               						<li><a id="liveArmaniResBurj"  href="#">شقق أرماني الفندقية</a></li>\
                      						<li><a id="liveFacilitiesBurj"  href="#">مرافق سكنية</a></li>\
                      						<li><a id="liveResidentPortalBurj"  href="#">بوابة المقيمين</a></li>\
                      						<li><a id="liveGallery"  href="#">معرض</a></li>\
						</ul>\
					</li>\
       					<li><a id="workBurj"  href="#">العمل</a>\
        					<ul>\
				                	<li><a id="workCorporateSuitesBurj"  href="#">مكاتب وأجنحة الشركات</a></li>\
       				                 	<li><a id="workGallery"  href="#">معرض</a></li>\
    				            	</ul>\
					</li>\
      				 	<li><a id="stayBurj"  href="#">البقاء</a>\
    				    		<ul>\
   				             		<li><a id="stayHotelsBurj"  href="#">فندق أرماني</a></li>\
       				                	<li><a id="stayRoomsBurj"  href="#">الغرف والأجنحة</a></li>\
       				                	<li><a id="stayFacilitiesBurj"  href="#">مرافق الفندق</a></li>\
      				                 	<li><a id="stayGallery"  href="#">معرض</a></li>\
    				            	</ul>\
					</li>\
       					<li><a id="dineBurj"  href="#">العشاء</a></li>\
      				 	<li><a id="Events"  href="#">الأحداث</a> </li>\
				</ul>';
		} else 	{ 
				// NAV BAR: BURJ (ENGLISH)
				var html = '\
					<ul class="sf-menu burj" id="nav">\
						<li class=""><a id="homeBurj"  href="#">Home</a></li>\
       						<li><a id="aboutBurj" href="#">About</a>\
					     		<ul>\
       								<li><a id="aboutOverviewBurj" href="#">Burj Khalifa</a></li>\
     					  			<li><a id="aboutSurroundsBurj" href="#">Building Surrounds</a></li>\
								<li><a id="aboutEmaarBurj"  href="#">Emaar</a></li>\
								<li><a id="aboutGalleryBurj"  href="#">Gallery</a></li>\
       							</ul>\
     					  	</li>\
  					     	<li><a id="liveBurj"  href="#">Live</a>\
							<ul>\
       					        		<li><a id="liveTheResidenceBurj"  href="#">The Residence</a></li>\
    					           		<li><a id="liveArmaniResBurj"  href="#">Armani Residences</a></li>\
					               		<li><a id="liveFacilitiesBurj"  href="#">Residential Facilities</a></li>\
       					        		<li><a id="liveResidentPortalBurj"  href="#">Residents Portal</a></li>\
    					           		<li><a id="liveGallery"  href="#">Gallery</a></li>\
							</ul>\
						</li>\
       						<li><a id="workBurj"  href="#">Work</a>\
   					     		<ul>\
					                        <li><a id="workCorporateSuitesBurj"  href="#">Offices &amp; Corporate Suites</a></li>\
       					                 	<li><a id="workGallery"  href="#">Gallery</a></li>\
					                </ul>\
						</li>\
       						<li><a id="stayBurj"  href="#">Stay</a>\
					        	<ul>\
      					                  	<li><a id="stayHotelsBurj"  href="#">Armani Hotel</a></li>\
					                        <li><a id="stayRoomsBurj"  href="#">Rooms &amp; Suites</a></li>\
       					                 	<li><a id="stayFacilitiesBurj"  href="#">Hotel Facilities</a></li>\
					                        <li><a id="stayGallery"  href="#">Gallery</a></li>\
       					         	</ul>\
						</li>\
       					 	<li><a id="dineBurj"  href="#">Dine</a></li>\
					        <li><a id="Events"  href="#">Events</a></li>\
					</ul>';
			} // END: IF LANG = AR
	} else if( currentCommunityID == 49 )
		{
			// NAV BAR: ALDAR (ARABIC)
			if( get_cookie( 'lang' ) == "ar" )
			{
				var html = '\
					<ul class="sf-menu aldar" id="nav">\
						<li class=""><a id="homeBandar"  href="#">الصفحة الرئيسية</a></li>\
						<li><a id="aboutBandar"  href="#">حول</a>\
							<ul>\
								<li><a id="alBandar"  href="#">البندر</a></li>\
								<li><a id="alRahaBeach"  href="#">شاطئ الراحة</a></li>\
								<li><a id="alDar"  href="#">الدار</a></li>\
							</ul>\
						</li>\
						<li><a id="liveBandar"  href="#">العيش</a>\
							<ul>\
								<li><a id="liveBarza"  href="#">برزة</a></li>\
								<li><a id="liveManara"  href="#">المنارة</a></li>\
								<li><a id="liveNaseem"  href="#">النسيم</a></li>\
								<li><a id="liveUnits"  href="#">وحدات وفيلات</a></li>\
								<li><a id="liveFacilities"  href="#">مرافق سكنية</a></li>\
								<li><a id="livePortal"  href="#">بوابة المقيمين</a></li>\
								<li><a id="liveGallery"  href="#">معرض</a></li>\
							</ul>\
						</li>\
						<li><a id="workBandar"  href="#">العمل</a>\
							<ul>\
								<li><a id="workHq"  href="#">HQ</a></li>\
								<li><a id="workGallery"  href="#">معرض</a></li>\
							</ul>\
						</li>\
						<li><a id="stayBandar"  href="#">البقاء</a>\
							<ul>\
								<li><a id="stayYas"  href="#">فندق ياس</a></li>\
								<li><a id="stayGallery"  href="#">معرض</a></li>\
							</ul>\
						</li>\
						<li><a id="shopBandar"  href="#">تسوق</a></li>\
						<li><a id="dineBandar"  href="#">العشاء</a>\
							<ul>\
								<li><a id="dineRes"  href="#">المطاعم والبارات</a></li>\
								<li><a id="dineGallery"  href="#">معرض</a></li>\
							</ul>\
						</li>\
						<li><a id="Events"  href="#">الأحداث</a> </li>\
					</ul>';
			} else	{ 
					// NAV BAR: ALDAR (ENGLISH)
					var html = '\
						<ul class="sf-menu aldar" id="nav">\
							<li class=""><a id="homeBandar"  href="#">Home</a></li>\
							<li><a id="aboutBandar"  href="#">About</a>\
								<ul>\
									<li><a id="alBandar"  href="#">Al Bandar</a></li>\
									<li><a id="alRahaBeach"  href="#">Al Raha Beach</a></li>\
									<li><a id="alDar"  href="#">Aldar</a></li>\
								</ul>\
							</li>\
							<li><a id="liveBandar"  href="#">Live</a>\
								<ul>\
									<li><a id="liveBarza"  href="#">Al Barza</a></li>\
									<li><a id="liveManara"  href="#">Al Manara</a></li>\
									<li><a id="liveNaseem"  href="#">Al Naseem</a></li>\
									<li><a id="liveUnits"  href="#">Units &amp; Villas</a></li>\
									<li><a id="liveFacilities"  href="#">Residential Facilities</a></li>\
									<li><a id="livePortal"  href="#">Residents Portal</a></li>\
									<li><a id="liveGallery"  href="#">Gallery</a></li>\
								</ul>\
							</li>\
							<li><a id="workBandar"  href="#">Work</a>\
								<ul>\
									<li><a id="workHq"  href="#">HQ</a></li>\
									<li><a id="workGallery"  href="#">Gallery</a></li>\
								</ul>\
							</li>\
							<li><a id="stayBandar"  href="#">Stay</a>\
								<ul>\
									<li><a id="stayYas"  href="#">Yas Hotel</a></li>\
									<li><a id="stayGallery"  href="#">Gallery</a></li>\
								</ul>\
							</li>\
							<li><a id="shopBandar"  href="#">Shop</a></li>\
							<li><a id="dineBandar"  href="#">Dine</a>\
								<ul>\
									<li><a id="dineRes"  href="#">Restaurants &amp; Bars</a></li>\
									<li><a id="dineGallery"  href="#">Gallery</a></li>\
								</ul>\
							</li>\
							<li><a id="Events"  href="#">Events</a> </li>\
						</ul>'; 
				} // END: IF LANG = AR
		} else	{
				// NAV BAR: STANDARD (ARABIC)
				$('#navigation').addClass('std');
				if( get_cookie( 'lang' ) == "ar" ) 
				{
	 				var html = '\
						<ul class="sf-menu" id="nav">\
							<li class="current"><a id="Overview"  href="#">نظرة عامة</a></li>\
							<li><a id="Developer"  href="#">التطوير العقاري</a></li>\
       							<li><a id="Units"  href="#">iالوحدات والفيلات</a></li>\
       							<li><a id="Facilities"  href="#">ملامح المجتمع</a></li>\
       							<li><a id="Gallery"  href="#">صورة معرض</a></li>\
       							<li><a id="Events"  href="#">أحداث المجتمع</a> </li>\
						</ul>';
				} else	{
						// NAV BAR: STANDARD (ENGLISH)
						var html = '\
							<ul class="sf-menu" id="nav">\
								<li class="current"><a id="Overview" href="#">Overview</a></li>\
       								<li><a id="Developer" href="#">Developer</a></li>\
       								<li><a id="Units" href="#">Units &amp; Villas</a></li>\
       								<li><a id="Facilities" href="#">Facilities</a></li>\
       								<li><a id="Gallery" href="#">Gallery</a></li>\
							</ul>';
					}
	
			} // END: IF CURRENTCOMMUNITY == 33...

	// WRITE NAVIGATION TO DIV	
	$('#navigation').html( html );

        // RUN SUPERFISH MENU
        $('ul.sf-menu').superfish(
        {
                animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
                speed:       'normal'                          // faster animation speed 
        });
}

function getSystems()
{
        var params = "func=getSystems2&email=" + get_cookie( 'email' ) + "&mycomuuid=" + get_cookie( 'mycomUUID' );
        //alert( params ); return;

	//$('#cover').css('display','block');
	$('#cover').show();
        openMsgBox();
        if( get_cookie('lang') == "ar" )
        {
                var message = "ﺎﺴﺗﺮﺟﺎﻋ ﺎﻤﺘﻳﺍﺯﺎﺗ ﺎﻠﻤﺴﺘﺧﺪﻣ -- ﺎﻟﺮﺟﺍﺀ ﺍﻼﻨﺘﻇﺍﺭ";
        } else  {
                        var message = "Retrieving MyCommunity System Privileges from Strataware - Please Wait a Moment";
                }       
        $('#msgboxmsg').html( message ).show(750, function()
        {
       		$.ajax(
      		{
      		        type: "POST",
       		        async: false,
      		        url: "/cgi-bin/mycom.cgi",
        	      	data: params,
        	       	dataType: "xml",
        	       	success: function(data)
        	       	{
				console.log('success');
				if( $(data).find('RESULT').text() == "TRUE" )
				{
        	       	                var selected = 0;
        	       	                var systems = "";
	
					if( get_cookie( 'persist' ) == 'true' ) { var ttl = 999; } else { var ttl = 0; }
	
					$(data).find('RELATIONSHIP').each( function()
	                                {
		                                var communityid = $(this).find('COMMUNITYID').text();
		                                var communityurl = $(this).find('COMMUNITYURL').text();
		                                var communityname = $(this).find('COMMUNITYNAME').text();
		                                var system = $(this).find('SYSTEM').text();
		                                var region = $(this).find('REGION').text();
						if( region == '' ) { region = ' '; }
		                                var bldid = $(this).find('BLDID').text();

		                                var lotid = $(this).find('LOTID').text();
						if( lotid == '' || !lotid || lotid == undefined ) { lotid = ' '; }
		                                var lotnum = $(this).find('LOTNUM').text();
						if( lotnum == '' || !lotnum || lotnum == undefined ) { lotnum = ' '; }

		                                var email = $(this).find('RECORDID').text();
		                                var roles = $(this).find('ROLES').text();
		
		                                // WRAP UP SYSTEM RELATIONSHIPS INTO A STRING   
		                                systems += communityid + "±";
		                                systems += communityname + "±";
		                                systems += communityurl + "±";
		                                systems += system + "±";
		                                systems += region + "±";
		                                systems += bldid + "±";
		                                systems += lotid + "±";
		                                systems += lotnum + "±";
		                                systems += roles + "§";
	
	                                 	if ( selected == 0 && !get_cookie( 'selectedCommunityID' ) )
	                                 	{
	                                         	// SET SELECTED COOKIES
	                                         	set_cookie( "selectedCommunityID", communityid, ttl, "/", "", "" );
	                                         	set_cookie( "selectedCommunityURL", communityurl, ttl, "/", "", "" );
	                                         	set_cookie( "selectedCommunityName", communityname, ttl, "/", "", "" );
	                                         	set_cookie( "selectedSystem", system, ttl, "/", "", "" );
	                                         	set_cookie( "selectedRegion", region, ttl, "/", "", "" );
	                                        	set_cookie( "selectedBldID", bldid , ttl, "/", "", "" );
	                                        	set_cookie( "selectedLotID", lotid, ttl, "/", "", "" );
	                                        	set_cookie( "selectedLotNum", lotnum, ttl, "/", "", "" );
	                                        	set_cookie( "selectedRoles", roles, ttl, "/", "", "" );
	                                        	selected = 1;
	                                       	}	
	                                }); //END: EACH.RELATIONS
	
	                      		systems =  systems.substring(0, systems.length - 1);
	                      		setStorage( "systems", systems, get_cookie( 'persist' ) );
	
					// GET HOMECOMMUNITY DETAILS
					var homecommunityID = $(this).find('HOMECOMMID').text();
	                               	set_cookie( "homecommunityID", homecommunityID, ttl, "/", "", "" );
					//$('#cover').css('display','none');
					$('#cover').hide();
	                       	} else	{
						alert('It seems we cannot currently retrieve your details or your Owners Association manager has suspended your account, please contact your Owner\'s Association Manager for support');
						delete_all_cookies();
						window.location = "/";
					} // END IF RESULT==TRUE
	                }  // END: SUCCESS
	        }); // END: AJAX METHOD
	}); // END AJAX LOADER
}


function oaSelect()
{
	getSystems();

	var systems = getStorage( 'systems', get_cookie( 'persist' ) );
	var system = systems.split("§");
	var htm = "<select id='comSel'>";
	for( x=0; x<=system.length-1; x++)
	{	
		var flag=0;
		var thisSystem = system[x].split("±");
		for(i=0; i<thisSystem.length; i++)
		{
			if( 	thisSystem[0] == get_cookie('selectedCommunityID') && 
			    	thisSystem[3] == get_cookie('selectedSystem') && 
			    	thisSystem[4] == get_cookie('selectedRegion') && 
			    	thisSystem[5] == get_cookie('selectedBldID') && 
			    	thisSystem[6] == get_cookie('selectedLotID') ) { flag = 1; }
		}

		if( flag )
		{
			htm += "<option value='" + system[x] +  "' SELECTED>" + thisSystem[1];
			if( thisSystem[7] != " " ) htm += " > Unit " + thisSystem[7];
			htm += " > " + thisSystem[8] + "</option>";
		} else	{
				htm += "<option value='" + system[x] +  "'>" + thisSystem[1];
				if( thisSystem[7] != " " ) htm += " > Unit " + thisSystem[7];
				htm += " > " + thisSystem[8] + "</option>";
			}
	}
	htm += "</select>";
	//alert(htm);

	$('#unitSelect').html(htm);
}

function changeSelection( system )
{
	//alert( system );
	var elements = system.split (/±/g);
	//for( i in elements ) { alert( elements[i] ); }
	if( get_cookie( 'persist' ) == 'true' ) { var ttl = 999; } else { var ttl = 0; }

       	// SET SELECTED COOKIES
        set_cookie( "selectedCommunityID", elements[0], ttl, "/", "", "" );
        set_cookie( "selectedCommunityName", elements[1], ttl, "/", "", "" );
        set_cookie( "selectedCommunityURL", elements[2], ttl, "/", "", "" );
        set_cookie( "selectedSystem", elements[3], ttl, "/", "", "" );
        set_cookie( "selectedRegion", elements[4], ttl, "/", "", "" );
        set_cookie( "selectedBldID", elements[5], ttl, "/", "", "" );
        set_cookie( "selectedLotID", elements[6], ttl, "/", "", "" );
        set_cookie( "selectedLotNum", elements[7], ttl, "/", "", "" );
        set_cookie( "selectedRoles", elements[8], ttl, "/", "", "" );
	window.location = "/myaccount";
}

function checkSystemAndRoles( system, roles )
{
	roles = roles.toLowerCase();
	//alert( "roles to match = " + roles );
	var rolesArray = roles.split(",");

	var systemCookie = unescape( get_cookie( 'selectedSystem' ) ); 
	//alert( "System Cookie = " + systemCookie );
	if( system != systemCookie ) { return 0; }

	var flag = 0;
	for( var i in rolesArray )
	{
		//alert( "Take #" + i + " role = " + rolesArray[i] );
		var pattern = eval( "/" + jQuery.trim(rolesArray[i]) + "/" );
		//alert( "pattern = " + pattern );
		var selectedRoles = unescape( get_cookie( 'selectedRoles' ) );
		//alert( "Compare it to the roles in cookies = " + selectedRoles );
		if( pattern.test( selectedRoles ) ) { return 1; }
	}
	return flag;
} 

// CHECK USER PRIVILEDGES IN THE SCOPE OF THE ENTIRE COMMUNITY
function checkCommunity()
{
	var val = 0;
	if( get_cookie( 'userid' ) )
	{
		var priv = getStorage( 'privs', parseInt( get_cookie('persist') ) );
        	var privs = priv.split("§");
        	for(x=0; x<privs.length; x++)
        	{
        		var myprivs = privs[x].split('±');
			if( get_cookie('currentCommunityID') == myprivs[0] ) { val = 1; }
		}
		return val;
	} else { return val; }
}

// CHECK USER PRIVILEDGES IN THE SCOPE OF THE CURRENT UNIT
function checkLotRoles( role )
{
	var val = 0;
	role = role.toLowerCase();

	if( get_cookie( 'mycomUUID' ) ) 
	{
        	var systems = getStorage( 'systems', get_cookie( 'persist' ) );

        	var system = systems.split("§");
        	for(x=0; x<=system.length-2; x++)
        	{
			var thisSystem = system[x].split('±');
			if( get_cookie('selectedCommunityID') == thisSystem[9]) 
      			{
				if( get_cookie( 'selectedBldID' ) == thisSystem[4] )
				{
					if( get_cookie( 'selectedLotID' ) == thisSystem[5] )
					{
						var myregex = eval("/" + role + "/");
						if ( thisSystem[7].search(myregex) != -1 ) { val = 1; return val; }
					}
				}
			}
		}
		//alert(val);
		return val;
	} else { return val; }
}

///////////////////////////////////////////////////////////////////////////////////////
// CHECKS THIS USER SYSTEM RELATIONSHIP FOR THE COMMA SEPERATED SPECIFIED ROLE TYPES //
///////////////////////////////////////////////////////////////////////////////////////
function checkThisSystemRoles( roles )
{
	if( get_cookie('mycomUUID') == false ) { return false; }

	var val = 0;
        roles = roles.toLowerCase();
	rolesArray = roles.split(/,/g);

	for( var index in rolesArray )
	{
		//alert( "roles to test -> " + $.trim( rolesArray[index].toLowerCase() ) );
		myregex = eval("/" + $.trim(rolesArray[index].toLowerCase()) + "/");
		var selectedRoles = get_cookie('selectedRoles');
		selectedRoles = selectedRoles.toLowerCase();
		//alert( "selectedRoles = " + selectedRoles );
		//alert( "selectedRoles.search(myregex) = " + selectedRoles.search(myregex) );
		if( selectedRoles.search(myregex) != -1 ) { val = 1; return val; } 
	}
	return val;
}

/////////////////////////////////////////////////////////////////////////////////////////////
// CHECK ALL SYSTEM RELATIONSHIPS FOR THE COMMA SEPERATED SPECIFIED ROLE IN THIS COMMUNITY //
/////////////////////////////////////////////////////////////////////////////////////////////
function checkThisCommunityForSystemRoles( roles )
{
        if( get_cookie('mycomUUID') == false ) return;

        var val = 0;

 	var systems = getStorage( 'systems', get_cookie( 'persist' ) );
        var system = systems.split(/§/g);

        for( var i in system )
        {
		var systemElements = system[i].split(/±/g);
		if( systemElements[0] == get_cookie( 'currentCommunityID' ) )
		{
        		roles = roles.toLowerCase();
        		rolesArray = roles.split(/,/g);
        
			for( var index in rolesArray )
        		{
                		myregex = eval("/" + $.trim(rolesArray[index]) + "/");
                		var selectedRoles = systemElements[8].toLowerCase();
                		if( selectedRoles.search(myregex) != -1 ) { val = 1; return val; }
        		}
		}
	}
        return val;
}

function checkThisCommunityRoles( roles )
{
	if( !get_cookie('mycomUUID') ) { return; }
}

///////////////////////////////////////////////////////////////////////////////////////
// CHECKS EACH USER SYSTEM RELATIONSHIP FOR THE COMMA SEPERATED SPECIFIED ROLE TYPES //
///////////////////////////////////////////////////////////////////////////////////////
function checkAllSystemRoles( roles )
{
        if( get_cookie('mycomUUID') == false ) return;

        var val = 0;
        roles = roles.toLowerCase();
        rolesArray = roles.split(/,/g);
	var systems = getStorage( 'systems', get_cookie( 'persist' ) );
	var system = systems.split(/§/g);
	
	for( var i in system )
	{
        	for( var index in rolesArray )
        	{
        	        myregex = eval("/" + $.trim(rolesArray[index]) + "/");
        	        var systemElements = system[i].split(/±/g);
        	        if( systemElements[8].toLowerCase().search(myregex) != -1 ) { val = 1; return val; }
        	}
	}
        return val;
}


function checkAllCommunityRoles( role )
{
	var val = 0;
	role = role.toLowerCase();

        if( get_cookie( 'userid' ) )
        {
                var priv = getStorage( 'privs', parseInt( get_cookie( 'persist' ) ) );
                var privs = priv.split("§");
                for(x=0; x<privs.length; x++)
                {
                        var myprivs = privs[x].split('±');
                        var myregex = eval("/" + role + "/");
                        if ( myprivs[4].search(myregex) != -1 ) { val = 1; return val; }
                }
                return val;
        } else 	{ 
			return val; 
		}
}


///////////////////////////////////////////////////////////////////////////////////////////////
// CHECKS THE CURRENT USER SYSTEM RELATIONSHIP FOR THE COMMA SEPERATED SPECIFIED ROLE TYPES //
//////////////////////////////////////////////////////////////////////////////////////////////
function checkThisCommunityRole( role )
{
        var val = 0;
	role = role.toLowerCase();

        if( get_cookie( 'userid' ) )
        {
                //var priv = get_cookie( 'privs' );
                var priv = getStorage( 'privs', parseInt( get_cookie( 'persist' ) ) );
                var privs = priv.split("§");
                for(x=0; x<privs.length; x++)
                {
                        //alert(privs[x]);
                        var myprivs = privs[x].split('±');
                        if( get_cookie('currentCommunityID') == myprivs[0])
                        {
                               var myregex = eval("/" + role + "/");
                               //alert(" my regex: " + myregex );
                               //alert( "my regex reposnse: " + myprivs[4].search(myregex) );
                               if ( myprivs[4].search(myregex) != -1 ) { val = 1; return val; }
                        }
                }
                //alert(val);
                return val;
        } else 	{ 
			return val; 
		}
}

// CHECK USER PRIVILEDGES IN THE SCOPE OF THE CURRENT OWNERS ASSOCIATION
function checkOARoles( role )
{
        var val = 0;
	role = role.toLowerCase();

        if( get_cookie( 'mycommUUID' ) )
        {
                var systems = getStorage( 'systems', get_cookie( 'persist' ) );
		alert( 'system = ' + systems );
                var system = systems.split("§");
                for(x=0; x<system.length-2; x++)
                {
                        var thisSystem = system[x].split('±');
                        if( get_cookie('selectedCommunityID') == thisSystem[9])
                        {
                                if( get_cookie( 'selectedBldID' ) == thisSystem[4])
                                {
                                       var myregex = eval("/" + role + "/");
                                       //alert(" my regex: " + myregex );
                                       //alert( "my regex reposnse: " + myprivs[4].search(myregex) );
					alert( "role = " + role + "\nselectedRoles = " + thisSystem[7] );
                                       if ( thisSystem[7].search(myregex) != -1 ) { val = 1; return val; }
                                }
                        }
                }
                //alert(val);
                return val;
        } else { return val; }
}

function checkCommunityRoles( role )
{
        var val = 0;
	role = role.toLowerCase();
	// IF LOGGED IN
        if( get_cookie( 'userid' ) )
        {
                //var priv = get_cookie( 'privs' );
                var priv = getStorage( 'privs', parseInt( get_cookie( 'persist' ) ) );
                var privs = priv.split("§");
		// FOR EACH OA & LOT
                for(x=0; x<privs.length; x++)
                {
                        //alert(privs[x]);
                        var myprivs = privs[x].split('±');
			//alert( "currentCommunityID = " + get_cookie('currentCommunityID') + "\nmyprivs = " + myprivs[5] );
			// IF YOU HAVE A RELATIONSHIP WITH THIS COMMUNITY
                        //if( get_cookie('selectedCommunityID') == myprivs[5])
                        if( get_cookie('currentCommunityID') == myprivs[0])
                        {
				// IF YOU HAVE A RELATIONSHIP WITH THIS CTS
				//alert( "selectedCTS=" + get_cookie('selectedCTS') + "\nmyprivs[0] = " + myprivs[0] );
                                //if( get_cookie( 'selectedCTS' ) == myprivs[0])
                                //{
                                        var myregex = eval("/" + role + "/");
                                        //alert(" my regex: " + myregex );
                                        //alert( "my regex response: " + myprivs[4].search(myregex) );
                                        if ( myprivs[4].search(myregex) != -1 )
                                        {
                                                //alert('got here');
                                                val = 1; 
						return val;
                                        }
                                //}
                        }
                }
                //alert(val);
                return val;
        } else 	{ 
			return val; 
		}
}

// CHECK & DISPLAY ACCOUNT INFO STATUS 
function accountInfo( link )
{
	if( get_cookie( 'mycomUUID' ) == false )
	{
		if( get_cookie( 'lang' ) == 'ar')
		{
			var html = "<div id='loginout'><a href='#' id='login'>دخول</a></div> <div id='lang'><a href='#' id='en'><img src='/img/en-icon.png'></a> <a href='#' id='ar'><img src='/img/ar-icon.png'></a></div>";
			//var html = "<a href='#' id='login'>تسجيل الدخول</a>";
		} else	{
				var html = "<div id='loginout'><a href='#' id='login'>Login</a></div> <div id='lang'><a href='#' id='en'><img src='/img/en-icon.png'></a> <a href='#' id='ar'><img src='/img/ar-icon.png'></a></div>";
			}
	} else 	{
			//if( getStorage( 'systems', get_cookie('persist') ) == null ) 
			//{
			//	getSystems();
			//}
			if( link == "backto" )
			{
				if( get_cookie( 'lang' ) == 'ar' ) 
				{
					//html = " <a href='#' id='myAccount'>حسابي</a> | <a id='logout' href='#'>خروج</a>";
                                	html = "<div id='loginout'><a href='/community/" + get_cookie( 'currentCommunityURL' ) + "' id='myAccount'>الى موقع الجماعة</a> | <a id='logout' href='#'>خروج</a></div><div id='lang'><a href='#' id='en'><img src='/img/en-icon.png'></a> <a href='#' id='ar'><img src='/img/ar-icon.png'></a></div>";
				} else	{
                                		html = "<div id='loginout'><a href='/community/" + get_cookie( 'currentCommunityURL' ) + "' id='myAccount'>Back to <strong>MyCommunity</strong></a> | <a id='logout' href='#'>Logout</a></div><div id='lang'><a href='#' id='en'><img src='/img/en-icon.png'></a> <a href='#' id='ar'><img src='/img/ar-icon.png'></a></div>";
					}
			} else	{
					if( get_cookie( 'lang' ) == 'ar' )
                                	{
                                        	//html = " <a href='#' id='myAccount'>حسابي</a> | <a id='logout' href='#'>خروج</a>";
                                        	html = "<div id='loginout'><a href='/myaccount' id='myAccount'>حسابي</a> | <a id='logout' href='#'>خروج</a></div><div id='lang'><a href='#' id='en'><img src='/img/en-icon.png'></a> <a href='#' id='ar'><img src='/img/ar-icon.png'></a></div>";
                                	} else  {
                                        	        html = "<div id='loginout'><a href='/myaccount' id='myAccount'>My Account</a> | <a id='logout' href='#'>Logout</a></div><div id='lang'><a href='#' id='en'><img src='/img/en-icon.png'></a> <a href='#' id='ar'><img src='/img/ar-icon.png'></a></div>";
                                        	}
				}
		}


	$('#accountInfo').html( html );

	// RECONNECT EVENTS

	// HIDE & SHOW LOGIN SCREEN LABELS IN INPUT TEXTBOXES
	$('#loginBox .defaultVal').each(function()
	{
	        var default_value = this.value;
	        $(this).css('color', '#aaa');

	        $(this).focus( function()
	        {
	        	if( this.value == default_value )
	                {
	                	var eleId = $(this).attr("id");
	                        if( eleId == 'password' )
	                        {
	                        	$(this).hide();
	                                $('#password1').show();  // show the real password input box and focus on it
	                                $('#password1').focus();
	                        } else	{
	                                        this.value = '';
	                                      	$(this).css('color', '#333');
	                              	}
	                }
	       	});
	
		$(this).blur( function()
	        {
	        	if( this.value == '' )
	               	{
	               		var eleId = $(this).attr( "id" );
	               	        if( eleId == 'password1' )
	               	        {
	               	            	$(this).hide();  // hide the real password input box and show the fake one
	               	                $('#password').show();
	               	  	} else	{
	               	                	this.value = default_value;
	               	                	$( this ).css( 'color', '#aaa' );
	                               	}
	               	}
		});
	});

}

function buildMyAccountNav()
{
	var nav;
	$('#navigation').addClass('myaccount');

	if( get_cookie('lang') == "ar" )
	{

		// MY ACCOUNT MENU
               var nav = '\
<ul id="nav" class="sf-menu" >\
        <li><a href="#" id="myAccNavDash">نظرة عامة</a></li>';

                if( get_cookie( 'selectedSystem' ) == 'Strataware' )
                {
                        nav += '\
        <li><a href="#" id="myAccNavComInfo">مجتمع المعلومات</a>\
                <ul>\
                        <li><a href="#" id="myAccNavGeneral">معلومات عامة</a></li>\
                        <li><a href="#" id="myAccNavInsur">تفاصيل التأمين</a></li>';

                        if( checkThisSystemRoles( 'Tenant') == 0 )
                        {
                                nav += '\
                        <li><a href="#" id="myAccNavBoard">اللجنة معلومات الاتصال</a></li>';
                        }

                        nav += '\
                        <li><a href="#" id="myAccNavSvcProv">مقدمي الخدمات تفاصيل</a></li>';
                        if(     get_cookie('selectedCommunityID') != 33 &&
                                get_cookie('selectedCommunityID') != 34 &&
                                get_cookie('selectedCommunityID') != 35 &&
                                get_cookie('selectedCommunityID') != 36 &&
                                get_cookie('selectedCommunityID') != 37 )
                        {
                                nav += '\
                        <li><a href="#" id="myAccNavWall">المجتمع الجدار</a></li>';
                        }
                        nav += '\
			<li><a href="#" id="myAccNavWhatsOn">أحداث المجتمع</a></li>\
                </ul>\
        </li>';
                }

		// FINANCIALS SECTION
                if( checkThisSystemRoles('Tenant') != 1 )
                {
                        nav += '\
        <li><a href="#" id="myAccNavAccounts">المعلومات المالية</a>\
                <ul>';

                        if( get_cookie('selectedLotID') != " " )
                        {
                                nav += '\
                        <li><a href="#" id="myAccNavSvcChg">رسوم خدمة بلدي وجباية</a></li>';
                        }

                        if( get_cookie( 'selectedSystem' ) == 'Strataware' && checkThisSystemRoles( 'oaManager,oaBoardMember' ) == 1 )
                        {
                                nav += '\
                        <li><a href="#" id="myAccNavGenLeg">العام ليدجر</a></li>\
                        <li><a href="#" id="myAccNavBalSht">الميزانية العمومية</a></li>\
                        <li><a href="#" id="myAccNavAnnBgt">الميزانية السنوية</a></li>';
                        }
                        nav += '\
                </ul>\
        </li>';
                }

		// SERVICE SECTION
                nav += '\
        <li class="parentItem"><a href="#" id="myAccNavSvc">خدمات المجتمع</a>';

                if( get_cookie( 'selectedLotID' ) != " " )
                {
                        nav += '\
                <ul>\
                        <li><a href="#" id="myAccNavSvcSvc">طلب الخدمة</a></li>\
                        <li><a href="#" id="myAccNavSvcMaint">تطلب الصيانة</a></li>\
                </ul>';
                } else if ( get_cookie( 'selectedLotID' ) == " " && checkThisSystemRoles( 'oaManager' ) == 1 )
                        {
                                nav += '\
                <ul>\
                        <li><a href="#" id="myAccNavSvcReq">العمل تطلب الأمر</a></li></ul>';
                        }

                nav += '\
        </li>\
        <li><a href="#" id="myAccNavDocs">نظام إدارة الوثائق</a></li>\
        <li><a href="#" id="myAccNavMsgs">رسالة النظام</a>\
                <ul>\
                        <li><a href="#" id="myAccNavNoticesCom">مجتمع إشعارات</a></li>\
                        <li><a href="#" id="myAccNavNoticesSystem">نظام المناقصات</a></li>';
						
				if( checkThisSystemRoles( 'oaManager' ) == 1 )
                	{						
						nav += '<li><a href="#" id="myAccNavSms">SMS Messaging</a></li>';
					}
                nav  +='</ul></li>';

                nav += '\
        <li><a href="#" id="myAccNavdmin">تفضيلات</a>\
                <ul>\
                        <li><a href="#" id="myAccNavMyProfile">ملفي الشخصي</a></li>\
                        <li><a href="#" id="myAccNavNotifications">إعدادات الإخطار</a></li>\
                        <li><a href="#" id="myAccNavChangePass">تغيير كلمة السر</a></li>\
                </ul>\
        </li>';

                if( checkThisSystemRoles( 'oaManager' ) == 1 )
                {
                        nav += '\
        <li><a href="#" id="myAccNavAdmin">نظام الإدارة</a>\
                <ul>\
                        <li><a href="#" id="myAccNavMngUsers">إدارة المستخدم</a></li>\
                        <li><a href="#" id="myAccNavNotifSets">البريد الإلكتروني دفتر العناوين</a></li>\
                </ul>\
        <\li>';
		}

                nav += '\
</ul>';
	} else	{
			// MY ACCOUNT MENU - ENGLISH
			var nav = '\
<ul id="nav" class="sf-menu" >\
 	<li><a href="#" id="myAccNavDash">DASHBOARD</a></li>';

			if( get_cookie( 'selectedSystem' ) == 'Strataware' )
			{
				nav += '\
	<li><a href="#" id="myAccNavComInfo">COMMUNITY</a>\
		<ul>\
			<li><a href="#" id="myAccNavGeneral">General Info</a></li>\
			<li><a href="#" id="myAccNavInsur">Insurance</a></li>';

				if( checkThisSystemRoles( 'Tenant' ) == 0 )
				{	
					nav += '\
			<li><a href="#" id="myAccNavBoard">Board/Committee Members</a></li>';
				}

				nav += '\
			<li><a href="#" id="myAccNavSvcProv">Service Providers</a></li>';
				if( 	get_cookie('selectedCommunityID') != 33 &&
					get_cookie('selectedCommunityID') != 34 &&
					get_cookie('selectedCommunityID') != 35 &&
					get_cookie('selectedCommunityID') != 36 &&
					get_cookie('selectedCommunityID') != 37 )
				{
					nav += '\
			<li><a href="#" id="myAccNavWall">Community Wall</a></li>';
				}
				nav += '\
			<li><a href="#" id="myAccNavWhatsOn">What\'s On</a></li>\
		</ul>\
	</li>';
			}

			// FINANCIALS SECTION
			if( checkThisSystemRoles( 'Tenant' ) == 0 )
			{
				nav += '\
	<li><a href="#" id="myAccNavAccounts">FINANCIALS</a>\
		<ul>';

				if( get_cookie('selectedLotID') != " " )
				{
					nav += '\
			<li><a href="#" id="myAccNavSvcChg">My Service Charges/Levies</a></li>';
				}
				
				if( get_cookie( 'selectedSystem' ) == 'Strataware' && checkThisSystemRoles( 'oaManager,oaBoardMember' ) == 1 )
				{
					nav += '\
			<li><a href="#" id="myAccNavGenLeg">General Ledger</a></li>\
			<li><a href="#" id="myAccNavBalSht">Balance Sheet</a></li>\
			<li><a href="#" id="myAccNavAnnBgt">Annual Budget</a></li>';
				}
				nav += '\
		</ul>\
	</li>';
			}

			// SERVICE SECTION
			nav += '\
	<li class="parentItem"><a href="#" id="myAccNavSvc">SERVICES</a>';

			if( get_cookie( 'selectedLotID' ) != " " )
			{
				nav += '\
		<ul>\
      			<li><a href="#" id="myAccNavSvcSvc">Service Requests</a></li>\
			<li><a href="#" id="myAccNavSvcMaint">Maintenance Requests</a></li>\
		</ul>';
			} else if ( get_cookie( 'selectedLotID' ) == " " && checkThisSystemRoles( 'oaManager' ) == 1 )
				{
					nav += '\
		<ul>\
			<li><a href="#" id="myAccNavSvcReq">Service Requests</a></li></ul>';
				}

			nav += '\
	</li>\
       	<li><a href="#" id="myAccNavDocs">DOCUMENTS</a></li>\
       	<li><a href="#" id="myAccNavMsgs">MESSAGES</a>\
		<ul>\
			<li><a href="#" id="myAccNavNoticesCom">Community Notices</a></li>\
			<li><a href="#" id="myAccNavNoticesSystem">System Notices</a></li>';
			
			if( checkThisSystemRoles( 'oaManager' ) == 1 )
                	{						
						nav += '<li><a href="#" id="myAccNavSms">SMS Messaging</a></li>';
					}
                nav  +='</ul></li>';
			

			// PREFERENCES SECTION
			nav += '\
	<li><a href="#" id="myAccNavdmin">PREFERENCES</a>\
		<ul>\
			<li><a href="#" id="myAccNavMyProfile">My Profile</a></li>\
			<li><a href="#" id="myAccNavNotifications">Notification Settings</a></li>\
			<li><a href="#" id="myAccNavChangePass">Change Password</a></li>\
		</ul>\
	</li>';
			// ADMINISTRATION SECTION
			if( checkThisSystemRoles( 'oaManager' ) == 1 )
                        {
                                nav += '\
	<li><a href="#" id="myAccNavAdmin">ADMINISTRATION</a>\
		<ul>\
			<li><a href="#" id="myAccNavMngUsers">Manage Users</a></li>\
                        <li><a href="#" id="myAdminSets">Admin Settings</a></li>\
		</ul>\
	<\li>';
                        }
			
			nav += '\
</ul>';
		} // END: IF

	// REPLACE NAV BAR AREA
	$('#navigation').html( nav );

	// START SUPER FISH ON SECONDMENU ITEMS
        $('ul#nav').superfish(
        {
                animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
                speed:       'normal'                          // faster animation speed 
        });
}

function loginErrorShow( error )
{
        $("#loginBox #loginForm #error").html( error );
        $("#loginBox #loginForm #error").show();
}

function loginErrorHide()
{
        $("#loginBox #loginForm #error").hide();
}


function breadCrumbs( communityid )
{
	var crumbs = "";
	var params = "func=breadcrumbs&communityid=" + communityid;
        $.ajax(
        {
                type: "POST",
                async: true,
                url: "/cgi-bin/mycom.cgi",
                data: params,                
		dataType: "xml",
                success: function(data, textStatus, XMLHttpRequest)
                {
                        //alert(XMLHttpRequest.responseText);
                        var xmlDoc = XMLHttpRequest.responseXML;
                        var result = xmlDoc.getElementsByTagName("RESULT")[0].childNodes[0].nodeValue;
                        if (result == "TRUE")
                        {
				for(i=xmlDoc.getElementsByTagName('COMMUNITY').length-1; i>0; i--)
				{
					if( i == xmlDoc.getElementsByTagName('COMMUNITY').length-1 ) {} else { crumbs += "&gt"; }
					crumbs += "<span class='link'><a href=" + xmlDoc.getElementsByTagName('URL')[i].childNodes[0].nodeValue + ">" + xmlDoc.getElementsByTagName('NAME')[i].childNodes[0].nodeValue + "</a></span>";
				}
			}
        		document.getElementById('breadCrumbs').innerHTML = crumbs;
		}
	});
}

function makeMyHomePage( currentCommunityURL )
{
        if( !get_cookie( 'homepageURL' ) || currentCommunityURL != get_cookie( 'homepageURL' ) )
        {
                $('#makeMyHome').html( '</h1><a href="#" id="homepage">(Make this my homepage)</a>' );
        } else	{
                	$('#makeMyHome').html( '' );
		}
}

function loadAccountsArea()
{
	// GET SYSTEMS
	var params = "func=getSystems2&email=" + get_cookie( 'email' ) + "&mycomuuid=" + get_cookie( 'mycomUUID' );
        //alert( params ); return;

        $('#cover').show();
        openMsgBox();
        if( get_cookie('lang') == "ar" )
        {
                var message = "ﺎﺴﺗﺮﺟﺎﻋ ﺎﻤﺘﻳﺍﺯﺎﺗ ﺎﻠﻤﺴﺘﺧﺪﻣ -- ﺎﻟﺮﺟﺍﺀ ﺍﻼﻨﺘﻇﺍﺭ";
        } else  {
                        var message = "Retrieving MyCommunity System Privileges from Strataware - Please Wait a Moment";
                }       
        $('#msgboxmsg').html( message ).hide().show(900, function()
        {
                $.ajax(
                {
                        type: "POST",
                        async: true,
                        url: "/cgi-bin/mycom.cgi",
                        data: params,
                        dataType: "xml",
                        success: function(data)
                        {
                                if( $(data).find('RESULT').text() == "TRUE" )
                                {
                                        var selected = 0;
                                        var systems = "";

                                        if( get_cookie( 'persist' ) == 'true' ) { var ttl = 999; } else { var ttl = 0; }

                                        $(data).find('RELATIONSHIP').each( function()
                                        {
                                                var communityid = $(this).find('COMMUNITYID').text();
                                                var communityurl = $(this).find('COMMUNITYURL').text();
                                                var communityname = $(this).find('COMMUNITYNAME').text();
                                                var system = $(this).find('SYSTEM').text();
                                                var region = $(this).find('REGION').text();
                                                if( region == '' ) { region = ' '; }
                                                var bldid = $(this).find('BLDID').text();
                                                var lotid = $(this).find('LOTID').text();
                                                if( lotid == '' || !lotid || lotid == undefined ) { lotid = ' '; }
                                                var lotnum = $(this).find('LOTNUM').text();
                                                if( lotnum == '' ) { lotnum = ' '; }
                                                var email = $(this).find('RECORDID').text();
                                                var roles = $(this).find('ROLES').text();

                                                // WRAP UP SYSTEM RELATIONSHIPS INTO A STRING   
                                                systems += communityid + "±";
                                                systems += communityname + "±";
                                                systems += communityurl + "±";
                                                systems += system + "±";
                                                systems += region + "±";
                                                systems += bldid + "±";
                                                systems += lotid + "±";
                                                systems += lotnum + "±";
                                                systems += roles + "§";

						if ( selected == 0 && !get_cookie( 'selectedCommunityID' ) )
                                                {
                                                        // SET SELECTED COOKIES
                                                        set_cookie( "selectedCommunityID", communityid, ttl, "/", "", "" );
                                                        set_cookie( "selectedCommunityURL", communityurl, ttl, "/", "", "" );
                                                        set_cookie( "selectedCommunityName", communityname, ttl, "/", "", "" );
                                                        set_cookie( "selectedSystem", system, ttl, "/", "", "" );
                                                        set_cookie( "selectedRegion", region, ttl, "/", "", "" );
                                                        set_cookie( "selectedBldID", bldid , ttl, "/", "", "" );
                                                        set_cookie( "selectedLotID", lotid, ttl, "/", "", "" );
                                                        set_cookie( "selectedLotNum", lotnum, ttl, "/", "", "" );
                                                        set_cookie( "selectedRoles", roles, ttl, "/", "", "" );
                                                        selected = 1;
                                                }
                                        }); //END: EACH.RELATIONS

                                        systems =  systems.substring(0, systems.length - 1);
                                        setStorage( "systems", systems, get_cookie( 'persist' ) );

                                        // GET HOMECOMMUNITY DETAILS
                                        var homecommunityID = $(this).find('HOMECOMMID').text();
                                        set_cookie( "homecommunityID", homecommunityID, ttl, "/", "", "" );
                                        //$('#cover').css('display','none');
                                        $('#cover').hide();


					// POPULATE OA SELECTION BOX
        				var systems = getStorage( 'systems', get_cookie( 'persist' ) );
        				var system = systems.split("§");
        				var htm = "<select id='comSel'>";
       					for( x=0; x<=system.length-1; x++)
        				{
                				var flag=0;
                				var thisSystem = system[x].split("±");
                				for(i=0; i<thisSystem.length; i++)
                				{
                        				if( thisSystem[0] == get_cookie('selectedCommunityID') &&
                                			thisSystem[3] == get_cookie('selectedSystem') &&
                                			thisSystem[4] == get_cookie('selectedRegion') &&
                                			thisSystem[5] == get_cookie('selectedBldID') &&
                                			thisSystem[6] == get_cookie('selectedLotID') ) { flag = 1; }
                				}

						if( flag )
                				{
                        				htm += "<option value='" + system[x] +  "' SELECTED>" + thisSystem[1];
                        				if( thisSystem[7] != " " ) htm += " > Unit " + thisSystem[7];
                        				htm += " > " + thisSystem[8] + "</option>";
                				} else  {
                                				htm += "<option value='" + system[x] +  "'>" + thisSystem[1];
                                				if( thisSystem[7] != " " ) htm += " > Unit " + thisSystem[7];
                                				htm += " > " + thisSystem[8] + "</option>";
                        				}
       				 	}
        				htm += "</select>";

        				$('#unitSelect').html(htm);

					// LOAD DASHBOARD
					var comSel = $('#comSel').html();
        				var com = get_cookie('selectedCommunityID');
        				if( com == 266 || com == 287 || com == 288 || com == 289 || com == 290 || com == 291 || com == 292 || com == 293 || com == 294 || com == 295 || com == 296 || com == 297 || com == 298 || com == 299 || com == 300 || com == 301 || com == 302 || com == 303 || com == 210 || com == 284 || com == 267 || com == 271 || com == 272 || com == 274 || com == 275 || com == 275 || com == 276 || com == 277 || com == 278 || com == 279 || com == 280 || com == 281 || com == 282 || com == 305 || com == 306 || com == 307 || com == 308 || com == 309 || com == 49 )
        				{
                				$('body').addClass('aldar');
                				$('#header').html( aldarHeader );
                				$('#footer').html( aldarFooter );
                				$('#developer-info').hide();
                				$('#comSel').html( comSel );
        				} else  {
                        				populateOAMngAdvert();
                				}

        				if( get_cookie('lang') == "en" || !get_cookie('lang') )
        				{
                				$('#lang-btn-ar').html( "<a id='arabic' href='#'>Arabic</a>" );
                				var url = get_cookie('selectedCommunityURL');
                				var name = get_cookie('selectedCommunityName');
                				if( name == "Al Zeina Precinct A" || name == "Al Zeina Precinct B" || name == "Al Zeina Precinct C" || name == "Al Zeina Precinct D" || name == "Al Zeina Precinct E" || name == "Al Zeina Precinct F" || name == "Al Zeina Precinct G" ) { name = "Al Zeina"; url = "alzeina"; }
                				$('#backToConnect').html("<a id=backBtn class=top-button href=/community/" + url + ">" + name + " Community</a>" );
                				$('#loginBtn').html('Logout');
        				} else  {
                        				$('#lang-btn-ar').html( "<a id='english' href='#'>Arabic</a>" );
                        				$('#backToConnect').html("<a id=backBtn class=top-button href=/community/" + get_cookie('selectedCommunityURL') + ">عودة إلى مجتمعي</a>" );
                        				$('#loginBtn').html('خروج');
							$('.aldar #header').css('background','url(/img/aldar-images/headers/account-header-ar.png) no-repeat');
							$('#footer .foo-img').attr('src','/img/aldar-images/footer-community-ar.jpg');
                				}
        				accountInfo( 'backto' );
        				buildMyAccountNav();
        				//populateOAMngAdvert();
        				populateDash();
                                } else  {
                                                alert('It seems we cannot currently retrieve your details or your Owners Association manager has suspended your account, please contact your Owner\'s Association Manager for support');
                                                delete_all_cookies();
                                                window.location = "/";
                                        } // END IF RESULT==TRUE
                        }  // END: SUCCESS
                }); // END: AJAX METHOD
        }); // END AJAX LOADER
}

