/*
@@@BUILDINFO@@@ st06HomePage.jsx 466 16-March-2007
*/

/*************************************************************************
*
* ADOBE CONFIDENTIAL
* ___________________
*
*  Copyright 2005 Adobe Systems Incorporated
*  All Rights Reserved.
*
* NOTICE:  All information contained herein is, and remains
* the property of Adobe Systems Incorporated and its suppliers,
* if any.  The intellectual and technical concepts contained
* herein are proprietary to Adobe Systems Incorporated and its
* suppliers and may be covered by U.S. and Foreign Patents,
* patents in process, and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Adobe Systems Incorporated.
**************************************************************************/

if( ( stockphoto.timeKeeperOn != undefined )&&( stockphoto.timeKeeperOn ) )
{
	stockphoto.timeKeeper.st06HomePage        = {};
	stockphoto.timeKeeper.st06HomePage.StTime = new Date();
}

stockphoto.HomePage = {};
stockphoto.HomePage.FolderName = "";
stockphoto.HomePage.validSearchProperties = ["Keyword","LangID","MaxHits","ItemsPerGroup","ThumbnailSize","Orientation","ColorFormat","MediaTypes","Collections","Partners","SpecialCode"];
stockphoto.HomePage.CheckEachField=function( szK, szV, n ) {
	if( ( szK=="" )||( szV=="" ) ) 
	{
		return( "" );
	}
	if( szK == "FolderTitle" ) 
	{
		if( ( szV.charAt(0) == '"' )||( szV.charAt(0) == "'" ) )
		{
		     stockphoto.HomePage.FolderName = szV.substring( 1, ((szV.length)-1) );
		}
		else 
		{
			stockphoto.HomePage.FolderName = szV;
		}
		return( "" );
	}
	if( n <= 0 ) 
	{
		return( "\n"+szK+": "+szV );
	}
	return( ",\n"+szK+": "+szV );
}

stockphoto.HomePage.validateSearchProperties = function( sProperty )
{
	if (sProperty != undefined)
	{
		var iIndex = 0;
		for (iIndex=0; iIndex < stockphoto.HomePage.validSearchProperties.length; iIndex++)
		{
			if (sProperty == stockphoto.HomePage.validSearchProperties[iIndex])
			{
				return true;
			}
		}
	}
	
	return false;
}
stockphoto.HomePage.validatePartnerAndCollection = function ( sPartner , sCollection)
{
	var iIndex = 0;
	if (sPartner == undefined || stockphoto.providers == undefined || stockphoto.providers.collections == undefined)
	{
		return false;
	}
	
	var sCollString = sPartner;
	if (sCollection != undefined && sCollection != "")
	{
		sCollString = sPartner + ":" + sCollection;
	}

	try
	{
		for (iIndex=0; iIndex < stockphoto.providers.collections.length; iIndex++)
		{
			if (sCollString == stockphoto.providers.collections[iIndex].CollectionName.Value)
			{
				return true;
			}
		}
	}
	catch (e)
	{
		//stockphoto.providers.collections[iIndex].CollectionName
	}
	return false;
}


stockphoto.HomePage.PromotionURL = function( isrcStr, doc_id ) 
{
	var reqStr, srcStr, nsrcStr, i, iSt, ch, szK, szV, n=0, x;
	var numPerPg, ThePromo, f, request={}, terms={};
	var doc = stockphoto.core.findDoc( doc_id );
	reqStr	= "terms={";
	srcStr	=  isrcStr;
	nsrcStr	= srcStr.length;
	iSt	= -1;
	szK	= "";
	szV	= "";
	ThePromo= "Promotion";
	stockphoto.HomePage.FolderName = ThePromo;
	for( i=1; i<nsrcStr; i++ ) 
	{
		ch = srcStr.charAt(i);
		if( iSt < 0 ) 
		{
			if( ch == '?' ) 
			{
				iSt = 0;
			}
		} 
		else 
		{
			if( iSt == 0 ) 
			{
				if( ch == '=' )
				{
					iSt = 1;
				}
				else 
				{
					szK += ch;
				}
			} 
			else 
			{
				if( ch == '&' ) 
				{
					szV = unescape(szV);
					if (stockphoto.HomePage.validateSearchProperties(szK))
					{
						x = stockphoto.HomePage.CheckEachField( szK,szV,n );
					}
					if( x != "" ) 
					{
						reqStr += x;
						n++;
					}
					iSt = 0;
					szK = "";
					szV = "";
				} else 
					szV += ch;
			}
		}
	}
	szV = unescape(szV);
	if (stockphoto.HomePage.validateSearchProperties(szK))
	{
		x = stockphoto.HomePage.CheckEachField( szK,szV,n );
	}
	if( x != "" )
	{
		reqStr += x;
	}
	else	
	{
		if( reqStr.length < 9 )
		{
			return;
		}
	}
	reqStr += "\n};\n";
	
	try
	{
		eval( reqStr );
	}
	catch(exception)
	{
		if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_AlertBox ) )
		{
			return stockphoto.alertBox.alertBox(stockphoto.alertBox.coreComponentID );
		}
	}


	
		// If the URL parameter has a Partners and SpecialCode attributes, then combine them together to form a Collections attribute
	if (terms != undefined)
	{
		if ((terms.Partners != undefined) && (terms.SpecialCode != undefined))
		{
			if (stockphoto.HomePage.validatePartnerAndCollection(terms.Partners,terms.SpecialCode))
			{
				terms.Collections = terms.Partners + ":" + terms.SpecialCode;
			}
		}
	
		if (terms.Partners != undefined) { delete terms.Partners; }
		if (terms.SpecialCode != undefined) { delete terms.SpecialCode; }
	}
		
	if( ( stockphoto.HomePage.FolderName == ThePromo )&&
	    ( terms.Keyword != undefined )&&
	    ( terms.Keyword != "" ) )
	{
		stockphoto.HomePage.FolderName = terms.Keyword;
	}

	numPerPg= stockphoto.DL.getThumbPerGroup();
	
	// <BoxCar3> Defaulting settings for Browse keywords...
	var oDefaultSettings = eval(stockphoto.search.defaultSettings.toSource());
	stockphoto.search.settings[doc_id] = stockphoto.DL.NavBar.setIsDefault(doc_id, oDefaultSettings);
	
	// <BoxCar3> Passing doc_id as a parameter to the createNewSearchFolder function...
	f	= Folder( stockphoto.core.folder.createNewSearchFolder( stockphoto.HomePage.FolderName , doc_id ) );

	// Nav bar records for keyword display
	if( terms.PromotionCode != undefined )
	{
		terms.keywordForPromotion = stockphoto.HomePage.FolderName;
	}

	if (undefined != terms.MediaTypes)
	{
		var iLocTextPhotoObjects = terms.MediaTypes.indexOf(textPhotoObjects);
		if (-1 != iLocTextPhotoObjects)
		{
			stockphoto.search.searchMediaTypes[doc_id] = stockphoto.core.util.appendSearchParam(stockphoto.search.searchMediaTypes[doc_id], stockphoto.search.textPhotoObjects);
			terms.MediaTypes.splice(iLocTextPhotoObjects, textPhotoObjects.length);
		}
		
		if (-1 != terms.MediaTypes.indexOf(textPhotography) || "" == terms.MediaTypes)
		{
            stockphoto.search.searchMediaTypes[doc_id] = stockphoto.core.util.appendSearchParam(stockphoto.search.searchMediaTypes[doc_id], stockphoto.search.textPhotography);
        }
        if (-1 != terms.MediaTypes.indexOf(textIllustration) || "" == terms.MediaTypes)
		{
            stockphoto.search.searchMediaTypes[doc_id] = stockphoto.core.util.appendSearchParam(stockphoto.search.searchMediaTypes[doc_id], stockphoto.search.textIllustration);
        }
	}

	if( stockphoto.DL.isAlreadyLoaded( stockphoto.DL.jsx_NavBar ) ) 
	{
		stockphoto.NavExtFnc.setXandY( 0, 0, doc_id );
		stockphoto.NavExtFnc.ProgressGIFOn( doc_id ); // when new search starts
		stockphoto.NavExtFnc.SetNoMoreImgField( false, doc_id );
	}
	stockphoto.DL.search.basicSearch(terms, f, numPerPg, doc_id);
	stockphoto.HomePage.FolderName = "";
}

stockphoto.HomePage.SwitchTopNavBar=function( a, bSrc, bDst, bRepeat ) 
{ // returning true is finish
	if( ( a.document != undefined )&&
	    ( a.document.topNavbar != undefined ) ) 
	{
		if( a.document.topNavbar.visible == bSrc ) 
		{
			//a.document.topNavbar.visible = bDst;
			stockphoto.eventHandler.pathAnalyzer.ChangeNavVisiblity( a.document, bDst, "HomePage.SwitchTopNavBa" );
		}
		return( true );
	}
	return( false );
}

stockphoto.HomePage.displayStartPageMenu=function( t ) 
{
	stockphoto.eventHandler.pathAnalyzer.ChangeNavVisiblity( app.document, false, "HomePage.displayStartPageMenu" );
	if( t < 60 ) // 30 sec.
	{
		app.scheduleTask( 'stockphoto.HomePage.displayStartPageMenu('+(t+1)+');', 500, false );
	}
}

stockphoto.HomePage.displayStartPage = function( doc_id ) 
{
	var doc;
	if( doc_id == undefined )
	{
	     doc = app.document;
	}
	else 
	{
		doc = stockphoto.core.findDoc( doc_id ); 
	}
	if( ( doc != undefined )&&
	    ( doc.thumbnail != undefined )&&
	    ( doc.topNavbar!= undefined )&&
	    ( stockphoto.core.init.loadBMScripts() ) ) 
	{
		if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_NavBar ) ) 
		{ // Just to be sure that NavBar thing has been loaded
		
		    //Forcefully setting it to full mode
			if( stockphoto.core.BoxCar.NavBar.GetIsCompactFlag( doc_id, 0 ) == 1 ) 
			{
			   stockphoto.core.BoxCar.NavBar.SetIsCompactFlag( 1, doc_id, 0 );
			}
			stockphoto.eventHandler.pathAnalyzer.ChangeContentPaneMode( doc, "web" );
			stockphoto.core.html.setUrlFilter( doc );
			stockphoto.core.log.logString( 0, "06 #1.->Home" );
			stockphoto.core.NavBar.SwitchNavBar( "displayStartPage", 0, 0, doc );
			//doc.topNavbar.visible = true;
			stockphoto.eventHandler.pathAnalyzer.ChangeNavVisiblity( doc, true, "HomePage.displayStartPage" );
			if( app.document.thumbnail.path != stockphoto.places.home.path )
			{
 				doc.thumbnail  = new Thumbnail( "stockphoto://home" );
			}
		}
	}
	return 0;
}

if( ( stockphoto.timeKeeperOn != undefined )&&( stockphoto.timeKeeperOn ) )
{
	stockphoto.core.util.edTime( stockphoto.DL.jsx_HomePage );
}



