﻿//Microsoft Ajax Library automatically calls the pageLoad function when the load stage of the client page lifecycle is entered. 
function pageLoad(sender, e){
	
	$(".unitRow").css("visibility", "visible"); //GalleryControl (Home), GalleryViewContainer (SRP)
    $("#mycarousel").css("visibility", "visible"); //SlideShowControl [incl. in BrochureHeaderContainer] (Brochure)
	
	//SearchCriteriaControl (Home, SRP)
	$("input[@type=checkbox]:first", "div#allAreasCk").click(function(){
        if (this.checked) { $("div#neighborhoods").checkCheckboxes();} else { $("div#neighborhoods").unCheckCheckboxes(); }
	});
    
    //SearchResultsControl
    $(".commHd").click(function(){
	    $(this).toggleClass('commHdClosed');
	    var commTempId = $(this).attr('id');
	    var commId = ('#' + 'commGroup' + commTempId);
	    $(commId).slideToggle();
	});
	$('.availUnitRow').hover(
	    function () {
            $(this).css("backgroundColor", "#daeafb");
          }, 
          function () {
            $(this).css("backgroundColor", "");
        }
	);
	$('.propertyListRow').hover(
	    function () {
            $(this).css("backgroundColor", "#eeeeee");
          }, 
          function () {
            $(this).css("backgroundColor", "");
        }
	);	
	//SearchResultsControl
	$('.comm').mouseover(function(){
	    var commTempId = $(this).attr('id');
	    $('.propertyGrey',this).css("color", "#0b4983");
	});
    $('.comm').mouseout(function(){
	    var commTempId = $(this).attr('id');
	    $('.propertyGrey',this).css("color", "#d2d0d0");
	});
	$('.viewMoreUnits').click(function(){
	    $(this).toggleClass('viewMoreOpen');
	    //added from click handler below for same element
	    var viewMoreTempId = $(this).attr('id');
	    var viewMoreId = ('#' + 'viewMoreGroup' + viewMoreTempId);
	    $(viewMoreId).toggle();
	});
//	$('.viewMoreUnits').click(function(){
//	    var viewMoreTempId = $(this).attr('id');
//	    var viewMoreId = ('#' + 'viewMoreGroup' + viewMoreTempId);
//	    $(viewMoreId).toggle();
//	});
    $('.viewPhoto').cluetip({
        insertionElement:'body',
        hoverClass:'photoClass',
        cluetipClass:'viewPhotoBubble', 
        activation:'click', 
        dropShadow:false, 
        positionBy:'fixed', 
        topOffset:-155,
        leftOffset:10,
        width:380, 
        cursor:'pointer',
        onShow: function(){
            var IdObj = $('.photoClass').attr('href');
            var IdObjArr = IdObj.toString().split('=');
            
            var tempUrl = IdObjArr[1];
            var tempArr = tempUrl.toString().split('&');
            var photoUrl = tempArr[0];

            tempUrl = IdObjArr[2];
            tempArr = tempUrl.toString().split('&');
            var propertyName = tempArr[0];

            var photoName =  propertyName + " - " + IdObjArr[3];

            //photoUrl
            $('.viewPhotoHd').html(propertyName);
            $('.viewPhotoImg').html("<img src='" + photoUrl + "' alt='" + photoName + "' title='" + photoName + "' />");
        }
    });
	$('.viewPhoto').mouseout(function(){
	    $('.viewPhoto').removeClass('photoClass');
//	    $('.viewPhotoHd').html('');
//	    $('.viewPhotoImg').html('');
	});
	
	//PhotoGalleryControl (Brochure page), SlideShowControl (Brochure page)
	$('.lgPhotoLink').click(function(){
        var IdObj = $(this).attr('href');
        var IdObjArr = IdObj.toString().split('&');
        var IdObjArrLen = IdObjArr.length;
        var lgPhotoUrl = IdObjArr[IdObjArrLen - 3];
        var lgPhotoCaption = IdObjArr[IdObjArrLen - 2];
        if(lgPhotoCaption!=null) lgPhotoCaption = unescape(lgPhotoCaption);
        var lgPhotoAlt = IdObjArr[IdObjArrLen - 1];
        $('#largePhotoContainer').html("<img src='" + lgPhotoUrl + "' title='"+ lgPhotoAlt + "' alt='"+ lgPhotoAlt + "' />");
        $('#largePhotoCaption').html(lgPhotoCaption);
    });
	
	//Launch Large Photo Modal Window (Brochure page)
	$('#largePhoto').jqm({toTop: true})
	    .jqmAddTrigger($('.largePhoto'))
	
	//Launch Send To Friend Modal Window (Brochure page)
    $('#sendToFriend').jqm({toTop: true})
		.jqmAddTrigger($('.sendToFriend'));
	
	//Register Function to retrieve the AJAX Request object for GuestCard asynchronous submission.
	Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(GuestCardSubmissionStatus);
	
	//Register Function to retrieve the AJAX Request object for UnitDetail asynchronous submission.
	Sys.WebForms.PageRequestManager.getInstance().add_initializeRequest(UnitDetailSubmissionStatus);
    
    // oliver ET 305 changes start 
    // deleted a couple chunks
    // added the following
    var guestCardContactOption;
    var unitDetailsContactOptions;
   
    $("#gcContactMethod input:radio").click(function() {
       guestCardContactOption = this;
    });
   
    $("#ud-contactRadios input:radio").click(function() {
       unitDetailsContactOptions = this;
    });
	
	    //Launch Guest Card Modal Window - on SRP and Brochure
    $('#guestCard')
       .jqm({
           toTop: true,
           onShow: function(hash) {
               
               if (guestCardContactOption) {
                   $(guestCardContactOption).attr("checked", true);
               }
               hash.w.show();
					window.scrollTo(0, 0);
           },
           onHide: function(hash) {
               if (guestCardContactOption) {
                   $(guestCardContactOption).attr("checked", true);
               }
               hash.w.hide();
               if (hash.o) { hash.o.remove(); }
           }
       })
       .jqmAddTrigger('a.guestCard');
       
       // oliver ET 305 changes end
    
	$('a.guestCard').click(function(){
        var link = $(this);  //the anchor element as a jquery object
        var gcId = link.attr('id');
        var title = link.attr('title');

        $('#ctl00_Body_GuestCard1_gcUnitId4Unit').val('');
        $('#ctl00_Body_GuestCard1_gcUnitPrice4Unit').val('');
        if (title != undefined) {
            var tmp = title.split("|");
            if (tmp.length > 3) {
                gcUnitPrice = GetGcUnitPrice(title)
                gcUnit = GetGcUnitId(title);
                $('#ctl00_Body_GuestCard1_gcUnitId4Unit').val(gcUnit);
                $('#ctl00_Body_GuestCard1_gcUnitPrice4Unit').val(gcUnitPrice);
            }
        } 
             
        if(gcId==undefined)
        {
            //gcId=getQueryVariable("PropertyId");
            gcId=getQueryVariable("PId");
        }
        $('#ctl00_Body_GuestCard1_gcPropId').val(gcId);
        
        //in SRP page, property info has been added to the "rel" attribute of the link
        var linkRel = link.attr('rel');
        if (linkRel != null && linkRel != "" && linkRel != undefined) {
            // SRP
            var linkRelArray = linkRel.split('|');
            var gcPropertyInfo = {
               name: linkRelArray[0],
               addr: linkRelArray[1],
               city: linkRelArray[2],
               state: linkRelArray[3],
               zip: linkRelArray[4],
               phone: linkRelArray[5]
            };
            var gcBldg;
            var gcUnit;        
            var gcFpc;
            $('#gc-name').html(gcPropertyInfo.name); 
            $('.gcCommName').val(gcPropertyInfo.name);
	        $('#gc-address').html(gcPropertyInfo.addr); 
	        $('#gc-city').html(gcPropertyInfo.city);
	        $('#gc-state').html(gcPropertyInfo.state);
	        $('#gc-zip').html(gcPropertyInfo.zip);
	        $('#gc-phone').html(gcPropertyInfo.phone);
        } else {
            // Brochure page - need to refactor
            var gcNameId = (".gc-name" + gcId);
            var gcAddrId = (".gc-address" + gcId);
            var gcCityId = (".gc-city" + gcId);
            var gcStateId = (".gc-state" + gcId);
            var gcZipId = (".gc-zip" + gcId);
            var gcPhoneId = (".gc-phone" + gcId);
            var gcBldgId=(".gc-bldg" + gcId);
            var gcUnitId=(".gc-unit" + gcId);
            var gcFpcId=(".gc-fpc" + gcId);
            
            var gcName = $(gcNameId).html();
            var gcAddr = $(gcAddrId).html();
            var gcCity = $(gcCityId).html();
            var gcState = $(gcStateId).html();
            var gcZip = $(gcZipId).html();
            var gcPhone = $(gcPhoneId).html();
            var gcBldg= $(gcBldgId).html();
            var gcUnit= $(gcUnitId).html();        
            var gcFpc=$(gcFpcId).html();
            
            $('#gc-name').html(gcName);
            $('.gcCommName').val(gcName);
	        $('#gc-address').html(gcAddr);
	        $('#gc-city').html(gcCity);
	        $('#gc-state').html(gcState);
	        $('#gc-zip').html(gcZip);
	        $('#gc-phone').html(gcPhone);
        };       
	    var gcFpcIdFromLink=null;
        var gcBldgIdFromLink=null;
        var gcUnitIdFromLink=null;
        
        
        if(title != undefined)
        {
            gcFpcIdFromLink=GetGcFpcId(title);
            gcBldgIdFromLink=GetGcBldgId(title);
            gcUnitIdFromLink=GetGcUnitId(title); 
        }
        
        if(gcFpc==undefined)
        {
            gcFpc=gcFpcIdFromLink;
        }
        if(gcBldg==undefined)
        {
            gcBldg=gcBldgIdFromLink;
        }
        if(gcUnit==undefined)
        {   
            gcUnit=gcUnitIdFromLink;
        }
        oscGuestCardInit(gcId,gcUnit); // Omniture for any guest card pop

        
	    $('#gc-bldg').html(gcBldg);
	    $('#gc-unit').html(gcUnit);
	    $('#gc-fpc').html(gcFpc);       

        if(gcBldg!=undefined)
        {
            $('#ctl00_Body_GuestCard1_gcBldgId').val(gcBldg);
        }
        else
        {
            $('#ctl00_Body_GuestCard1_gcBldgId').val("");
        }
        
        if(gcUnit!=undefined)
        {
            $('#ctl00_Body_GuestCard1_gcUnitId').val(gcUnit);
        }
        else
        {
            $('#ctl00_Body_GuestCard1_gcUnitId').val("");
        }
        
        if(gcFpc!=undefined)
        {
            $('#ctl00_Body_GuestCard1_gcFpcId').val(gcFpc);
            //pre select bed room configuration
            var ddl=document.getElementById("ctl00_Body_GuestCard1_ddlBedrooms");
	        ddl.selectedIndex=gcFpc-1;
        }
	    
	    //pre select move in date
	    var txtMoveInDate=document.getElementById("ctl00_Body_SearchCriteriaControl1_moveInDate");
	    var txtMoveInDateBrochure=document.getElementById("ctl00_Body_FloorplansContainer1_MoveInControl1_moveInDate");	    
	    var txtMoveInDateLanding=document.getElementById("ctl00_Body_landingMoveInDate");
	    
	    var moveInDateValue=null;
	    if(txtMoveInDate!=undefined)
	    {	    
	        moveInDateValue=txtMoveInDate.value;	    
	    }
	    if(txtMoveInDateBrochure!=undefined)
	    {	    
	        moveInDateValue=txtMoveInDateBrochure.value;	    
	    }	
	    if(txtMoveInDateLanding!=undefined)
	    {	    
	        moveInDateValue=txtMoveInDateLanding.value;	    
	    }	
	   
	    if(txtMoveInDate==undefined && txtMoveInDateBrochure==undefined)
	    {
            // brochure maps gc
            var gcMoveInDateId = (".gc-moveindate" + gcId);
            var gcMoveInDate = $(gcMoveInDateId).html();
            $('#gc-moveindate').html(gcMoveInDate);
            if (gcMoveInDate != null)
            {
                var index1 = gcMoveInDate.indexOf('/', 0);
                var index2 = gcMoveInDate.indexOf('/', index1 + 1);
                var index3 = gcMoveInDate.indexOf(' ', index2 + 1);
                moveInDateValue = gcMoveInDate.substring(0, index3);
            }
	    }
               
	    var txtMoveInDategc=document.getElementById("ctl00_Body_GuestCard1_MoveInDate");
	    txtMoveInDategc.value=moveInDateValue;
	    
	});
	
    //Launch Apt Detail Modal Window (Brochure page)
    $('#unitDetail')
       .jqm({
           toTop: true,
           onShow: function(hash) {
               if (unitDetailsContactOptions) {
                   $(unitDetailsContactOptions).attr("checked", true);
               }
               hash.w.show();
					window.scrollTo(0, 0);
           },
           onHide: function(hash) {
               if (unitDetailsContactOptions) {
                   $(unitDetailsContactOptions).attr("checked", true);
               }
               hash.w.hide();
               if (hash.o) { hash.o.remove(); }
           }
       }).jqmAddTrigger('.viewDetails');
    // oliver ET 305 changes end

	//UnitSelectionControl in Brochure page
	$('.viewDetails').click(function(){
	    var linkId=$(this).attr('id');
	    var linkIdInt=parseInt(linkId);
	    var counterStr=null;
	    var gcId=getQueryVariable("PId");
	    var gcNameId = (".gc-name" + gcId);
	    var gcName = $(gcNameId).html();
        $('.vdCommName').val(gcName);
        
	    if(linkIdInt<10)
	    {
	        counterStr='0'+linkId;
	    }
	    else
	    {
	        counterStr=linkId;
	    }
	    
	    var hiddenId='ctl00_Body_FloorplansContainer1_UnitSelectionControl1_rptAvailableUnits_ctl'+counterStr+'_amenities';// DIME 7369 +linkId;
        var inputStringField=document.getElementById(hiddenId);
        var inputString=inputStringField.value;
	    var seperator1="|";
	    var seperator2=",";
	    if(inputString!=undefined)
	    {
	            var vdRent=GetSplit(inputString,0,seperator1);
	            if(vdRent!=undefined)
	            {
	                $('#vd-rent').html(vdRent);
	                $('#ctl00_Body_AptDetailControl1_gcUnitPrice4Unit').val(vdRent);
	            }
	            var vdDate=GetSplit(inputString,1,seperator1);
	            if(vdDate!=undefined)
	            {
	                var mIndex=vdDate.indexOf("M");
	                var timeIndex=mIndex-9;
	                vdDate=vdDate.substring(0,timeIndex-1);
	                $('#vd-date').html(vdDate);
	            }
	            var objList = document.getElementById('amenitiesList');
				objList.innerHTML="";			
				var j=0;
	            var vdSqft=GetSplit(inputString,2,seperator1);
	            if(vdSqft!=undefined)
	            {
	                vdSqft=vdSqft+" Sq. Ft.";
	                //create the new nodes
				    objListElement = document.createElement('li');
				    objTextNode = document.createTextNode(vdSqft);
				
				    //now connect them to the list
				    objListElement.appendChild(objTextNode);
				    objList.appendChild(objListElement);
				    j++;
	            }

	        var vdFloorPlanImage=GetSplit(inputString,3,seperator1);
	        if(vdFloorPlanImage!=undefined)
	        {	            
	            var floorPlanImageControl=document.getElementById("vd-floorplanimage");
	            if(floorPlanImageControl!=undefined)
	            {
	                floorPlanImageControl.src=vdFloorPlanImage;	                
	            }	            
	            
	        }

	        
	        var vdPropId=GetSplit(inputString,4,seperator1);
	        if(vdPropId!=undefined)
	        {
	            $('#ctl00_Body_AptDetailControl1_vdGcPropId').val(vdPropId);
	        }
	        
	        var vdBldgId=GetSplit(inputString,5,seperator1);
	        if(vdBldgId!=undefined)
	        {
	            $('#ctl00_Body_AptDetailControl1_vdGcBldgId').val(vdBldgId);
	        }
	        var vdUnitId=GetSplit(inputString,6,seperator1);
	        if(vdUnitId!=undefined)
	        {
	            $('#ctl00_Body_AptDetailControl1_vdGcUnitId').val(vdUnitId);
	            $('#ctl00_Body_AptDetailControl1_gcUnitId4Unit').val(vdUnitId);
	        }
	        // DIME 7929/7640 OLL start
	        if(vdPropId!=undefined&&vdBldgId!=undefined&&vdUnitId!=undefined)
	            var leaseLinkControl=document.getElementById("vd-leaseLink");
	            if(leaseLinkControl!=undefined)
	            {
	                // try to identify the lease div in the brochure header 
	                var leaseNowDiv=document.getElementById("ctl00_Body_BrochureHeaderContainer1_onlineLeasingLink");
	                // identify the unit lease div
	                var leaseUnitDiv=document.getElementById("ctl00_Body_AptDetailControl1_udLease");  
	                if(leaseNowDiv==null&&leaseUnitDiv!=null) {
	                    // the lease div in the brochure header does not exist so hide it in the view details gc
	                    leaseUnitDiv.style.visibility='hidden'; //leaseUnitDiv.style.visibility;
	                }
	                else {
    	                // the div will be shown so set the link
    	                leaseLinkControl.href="Javascript:oscLeaseInit('unit','"+vdPropId+"');popTheLease('"+vdPropId+"','"+vdBldgId+"','"+vdUnitId+"');";	                
	                }
	            }	            
	        // DIME 7929/7640 OLL end

	        oscGuestCardInit(vdPropId,vdUnitId);
	        var moveInDateField=document.getElementById("ctl00_Body_FloorplansContainer1_MoveInControl1_moveInDate");
	        if(moveInDateField!=undefined)
	        {
	            var vdmoveInDate=moveInDateField.value;
	            $('#ctl00_Body_AptDetailControl1_vdGcMoveInDate').val(vdmoveInDate);
	        }
	        
	            var vdAmenities=GetSplit(inputString,7,seperator1);

				if(vdAmenities!=undefined&&vdAmenities!='')
				{
				    vdAmenities=vdAmenities.slice(0,-1);
				    var vdAmenity=GetSplit(vdAmenities,j-1,seperator2);
				}
				while(vdAmenity!=undefined&&vdAmenities!='')
				{
				    vdAmenity=GetSplit(vdAmenities,j-1,seperator2);
				    if(vdAmenity!=undefined)
				    {
				            //create the new nodes
				            objListElement = document.createElement('li');
				            objTextNode = document.createTextNode(vdAmenity);
				
				            //now connect them to the list
				            objListElement.appendChild(objTextNode);
				            objList.appendChild(objListElement);
				            j++;
				    }
				}
				// start DIME 7506 View Details guest card not writing bedroom count to guestcard table
				// 
                var gcId = vdPropId;
                var gcFpcId=(".gc-fpc" + gcId);
                var gcFpc=$(gcFpcId).html();

                if(gcFpc!=undefined)
                {
                    $('#ctl00_Body_AptDetailControl1_vdGcFpcId').val(gcFpc);
                }
				// ned DIME 7506 
				
	    }    
	});

    initEqCarousel();
    
    //SlideShowControl in Brochure
    $('#mycarousel').jcarousel({scroll: 1});

}
function SearchResults_Dispose() {
    //alert("SearchResultsControl_Dispose called!");
    jQuery(".commHd").unbind('click');
    jQuery('.availUnitRow').unbind('mouseenter');
    jQuery('.availUnitRow').unbind('mouseleave');
    jQuery('.propertyListRow').unbind('mouseenter');
    jQuery('.propertyListRow').unbind('mouseleave');
    jQuery('.comm').unbind('mouseenter');
    jQuery('.comm').unbind('mouseleave');
    jQuery('.viewMoreUnits').unbind('click');
    jQuery('.viewPhoto').unbind();
    jQuery('html').unbind('click');
    jQuery('a.guestCard').unbind('click');
    jQuery('jqmWindow').unbind();
    jQuery("#gcContactMethod input:radio").unbind('click');
    jQuery("#ud-contactRadios input:radio").unbind('click');
    jQuery('#AjaxProgressIndicator').unbind();
}
