﻿// JScript File

var Info = 
{ 
	m_pageType : 0,
	m_infocontainer : null,
	m_btns : [ ],
	m_listingwaitdiv: null,
	m_waitingAsyncServiceCall : false,
	
	Init:function( theType, theinfobox )
	{
		this.m_pageType = theType;
		this.m_listingwaitdiv = $get("listingoverlaywait");
		this.m_infocontainer = $get( theinfobox );
		
		var divs = Info.m_infocontainer.getElementsByTagName("DIV" );
		for( var i = 0; i < divs.length; i++ )
			this.m_btns.push( divs[i] );
	},

	Load:function(  ) 
	{
		if( this.m_infocontainer == null ) return;
		$clearHandlers( this.m_infocontainer );
		$addHandler( this.m_infocontainer, "click", this.infoClick );

		if( Map.m_zoneID > 0 && this.m_listingwaitdiv != null )  
		{
			ServiceClasses.ListingsService.set_timeout(10000);
			this.m_listingwaitdiv.style.display = "block";
			ret = ServiceClasses.ListingsService.GetListingSamples( this.m_pageType, Map.m_zoneID, this.listingsuccessCallback, this.listingfailedCallback   );
		}
	},

	addExtraButton:function(  ctrl ) 
	{
		while( ctrl.className.startsWith( "infobox" ) == false )
		{
			ctrl = ctrl.parentNode;
			if( ctrl.nodeName !== "DIV" )	return;
		}
		for( var i =0; i< this.m_btns.length; i++ )
			if( this.m_btns[i] == ctrl )
				return;
		this.m_btns.push( ctrl );			
	},

	selectionClick:function( )
	{
		if( Map.m_zoneID > 0 && this.m_listingwaitdiv != null )  
		{
			$get( "listingcontentcontainer").style.display = "none";
			this.m_listingwaitdiv.style.display = "block";
			ret = ServiceClasses.ListingsService.GetListingSamples( this.m_pageType, Map.m_zoneID, this.listingsuccessCallback, this.listingfailedCallback   );
			Info.m_waitingAsyncServiceCall = true;
		}
		else
			Info.closemodalmap( );
	},
	
	infoClick:function( eventElement )
	{
		Info.infoButtonClick( eventElement.target );
	},
	
	infoButtonClick:function( button )
	{
		while( button.className.startsWith( "infobox" ) == false )
		{
			button = button.parentNode;
			if( button.nodeName !== "DIV" )	return;
		}

		for( var i = 0; i < Info.m_btns.length; i++ )
		{
			if( Info.m_btns[i].className.startsWith( "infobox" ) == false )
				continue;
				
			if( Info.m_btns[i] == button )
			{
				Info.m_btns[i].className = "infobox activebox point";
				var img = Info.m_btns[i].getElementsByTagName("IMG" )[0];
				img.src = img.src.replace(/blank/, "active" );
				if( Info.m_btns[i].getAttribute( "id" ) === "homebox" )
				{
					$get( "mainboxcontainer" ).style.display = "block";
					var feedbox = $get( "feedboxcontainer" ); 
					feedbox.style.display = "none";
					feedbox.getElementsByTagName("IFRAME" )[0].src = Master.m_path + "Feeds/Loading.aspx";
					continue;
				}
					
				Info.m_btns[i].style.height = "65px";
				Info.m_btns[i].style.borderBottomColor = "White"; 

				var pageurl = button.getElementsByTagName("INPUT" )[0].getAttribute( "value" );
				if( pageurl.startsWith( "http" ) == false )
				{
					pageurl = Master.m_path + pageurl;			
					if( pageurl.indexOf( "?" ) > 0 ) pageurl = pageurl + "&theme=" + Master.m_theme;
					else pageurl = pageurl + "?theme=" + Master.m_theme;
					if( typeof Map != 'undefined' )
					{
						if( pageurl.indexOf( "?" ) > 0 ) pageurl = pageurl + "&zone=" + Map.m_zoneID;
						else	pageurl = pageurl + "?zone=" + Map.m_zoneID;
					}
				}			
				$get( "mainboxcontainer" ).style.display = "none";
				var feedbox = $get( "feedboxcontainer" ); 
				feedbox.style.display = "block";
				feedbox.getElementsByTagName("IFRAME" )[0].src = pageurl;
			}
			else if( Info.m_btns[i].className == "infobox activebox point" )
			{
				var img = Info.m_btns[i].getElementsByTagName("IMG" )[0];
				img.src = img.src.replace(/active/, "blank" );
				Info.m_btns[i].className = "infobox point";
				Info.m_btns[i].style.height = "";
				Info.m_btns[i].style.borderBottomColor = ""; 
			}
		}
	},

	listingsuccessCallback:function( result ) 
	{
		Info.m_listingwaitdiv.style.display = "none";
		Info.closemodalmap( );

		if( result == null ) return;
		var obj = Sys.Serialization.JavaScriptSerializer.deserialize( result ); 
		$get( "listingcontent").innerHTML = obj.ListHtml;
		if( obj.ListHtml != "" )
			$get( "listingcontentcontainer").style.display = "block";
	},

	listingfailedCallback:function( error )
	{
		Info.m_listingwaitdiv.style.display = "none";
		Info.closemodalmap( );
	},
	
	finished:function( )
	{
		return (Info.m_waitingAsyncServiceCall == false);
	},
	
	closemodalmap:function( )
	{
		Info.m_waitingAsyncServiceCall = false;
		
		var themodalmap = $get( "modalmap" );
		if( themodalmap != null && themodalmap.style.display != "none" )
		{
			if( ( typeof(Category) === 'undefined'  || Category.finished( ) ) &&
				 ( typeof(Listing) === 'undefined'  || Listing.finished( ) ) )
				Map.hideModalMap( null ); 
		}
	}
}


// Notify ScriptManager that this is the end of the script.
if ( typeof(Sys) !== 'undefined' ) Sys.Application.notifyScriptLoaded( );



