/*
@@@BUILDINFO@@@ st04AdvanceSearch.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.st04AdvanceSearch        = {};
	stockphoto.timeKeeper.st04AdvanceSearch.StTime = new Date();
}

// AdvancedSearch namespace and zstringCache instance
stockphoto.advancedSearch         = {};
stockphoto.advancedSearch.zc      = new stockphoto.zstringCache( "st04AdvanceSearch" );
stockphoto.advancedSearch.locale  = "";

stockphoto.advancedSearch.dlg     = undefined;
stockphoto.advancedSearch.dlgOn   = false;
stockphoto.advancedSearch.dlgData = [];
stockphoto.advancedSearch.pCnt    = 0;
stockphoto.advancedSearch.cCnt    = 0;
stockphoto.advancedSearch.the1st  = false;

stockphoto.advancedSearch.standardCntTab =
{
    DIALOG_LOCATION         : [50, 50, 100, 100], /* take out "   */
    SEARCH_KEYWORD_FIELD    : [180, 18],          /* [180, 20],   */
    SEARCH_LANG_DRDWN       : [100, 18],          /* [100, 20],   */
    SEARCH_RSLT_DRDWN       : [60,  18],          /* [60, 20],    */
    SEARCH_SAMPLE_KEYWORD   : [318, 18],          /* [318,20],    */
    SEARCH_PANEL_SIZE       : "[400,108]",        /* "[400,120]", */
    MEDIA_COLOR             : [200, 18],          /* [200, 20],   */
    MEDIA_BW                : [200, 18],          /* [200, 20],   */
    MEDIA_PHOTO             : [110, 18],          /* [110, 20],   */
    MEDIA_ILLUSTRATION      : [110, 18],          /* [110, 20],   */
    MEDIA_PHOTOOBJECT       : [110, 18],          /* [110, 20],   */
    MEDIA_PANEL_SIZE        : "[400,72]",         /* "[400,80]",  */
    ORIENTATION_PORTRAIT    : [200, 18],          /* [200, 20],   */
    ORIENTATION_SQUARE      : [200, 18],          /* [200, 20],   */
    ORIENTATION_LANDSCAPE   : [110, 18],          /* [110, 20],   */
    ORIENTATION_PANORAMIC   : [110, 18],          /* [110, 20],   */
    ORIENTAION_PANEL_SIZE   : "[400,72]",         /* "[400,80]",  */
    PARTNER_COLUMN_1        : [200, 18],          /* [200, 20],   */
    PARTNER_COLUMN_2        : [200, 18],          /* [200, 20],   */
    PARTNER_LISTBOX         : [300, 80],          /* [300, 80],   */
    PARTNERTIPTEXT          : [325, 80],          /* [325, 60],   */
    PARTNER_PANEL_SIZE      : "[400,220]",        /* "[400,160]", */
    CHECKBOX_1              : [325,18],
    CHECKBOX_2              : [325,18],
    OK_CANCEL_PREF          : [90, 20]            /* [90, 20]     */
};

// Following code will never be executed; but, it registers zstrings
// for future
if( stockphoto.advancedSearch.standardCntTab == undefined )
{
	var notusedText;
	notusedText = zc.get( "$$$/AdvancedSearch/Orientation/Portrait=Portrait" );
	notusedText = zc.get( "$$$/AdvancedSearch/Orientation/Landscape=Landscape" );
	notusedText = zc.get( "$$$/AdvancedSearch/Orientation/Square=Square" );
	notusedText = zc.get( "$$$/AdvancedSearch/Orientation/Panoramic=Panoramic" );
	notusedText = zc.get( "$$$/AdvancedSearch/MediaType/Photography=Photography" );
	notusedText = zc.get( "$$$/AdvancedSearch/MediaType/Illustration=Illustration" );
}

stockphoto.advancedSearch.SetStandardCnvTab=function()
{
	if ( stockphoto.advancedSearch.locale != stockphoto.core.getValidLocale() )
	{
		if ( stockphoto.core.util.loadLocaleData( "st04AdvanceSearch.par" ) )
		{
			stockphoto.advancedSearch.locale = stockphoto.core.getValidLocale();
		}
	}
}

stockphoto.advancedSearch.SetStandardCnvTab();

stockphoto.advancedSearch.bothBtnClickedAuto=function()
{
	var i;
	for( i=0; i<stockphoto.advancedSearch.dlgData.length; i++ )
	{
		if( stockphoto.advancedSearch.dlgData[i] != undefined )
			delete stockphoto.advancedSearch.dlgData[i];
		stockphoto.advancedSearch.dlgData[i] = undefined;
	}
	stockphoto.advancedSearch.dlgData = [];
	stockphoto.advancedSearch.dlg   = undefined;
	stockphoto.advancedSearch.dlgOn = false;
}

stockphoto.advancedSearch.cancelBtnClickedAuto=function()
{
	this.parent.parent.close( 2 );
	app.scheduleTask( "stockphoto.advancedSearch.bothBtnClickedAuto();\n", 2000, false ); // be sure that the resource is freed.
}

stockphoto.advancedSearch.getPartnerAuto=function( partnerObj )
{
//Begin: ListBox for Partner's list / partnerObj={list:"", allPartners=true} at the begining
	var i, j, k=0, Nm, pList=[];
	var selectedPartners = stockphoto.advancedSearch.dlg.partner.partnerGroup.PartnerList.partnerID.selection;

	partnerObj.list        = "";
	partnerObj.allPartners = false;
	partnerObj.collection  = false;

	if( selectedPartners == null )
	{
		; //no partners are selected.
	}
	else
	{	//report list of partner selected.

		for( i=0 ; i<selectedPartners.length; i++)
		{
			Nm = ( selectedPartners[ i ] ).toString();
			for( j=0; j<stockphoto.advancedSearch.dlgData.length; j++ )
			{
				if( stockphoto.advancedSearch.dlgData[j].dispNm == Nm )
				{
					pList[k] = stockphoto.advancedSearch.dlgData[j].name;
					if( ! stockphoto.advancedSearch.dlgData[j].fromPartner )
					{
						partnerObj.collection = true;
					}
					k++;
					break;
				}
			}
		}
		if( k <= 0 )
		{
			; //no partners are selected.
		}
		else 
		{
			if( pList.length == stockphoto.advancedSearch.dlg.partner.partnerGroup.PartnerList.partnerID.items.length )
			{
				partnerObj.allPartners = true;
			}
			else
			{
				for( i=0; i<k; i++ )
				{
					if( i > 0 )
					{
						if( partnerObj.collection )
							 partnerObj.list += ",";
						else partnerObj.list += ",";
					}
					partnerObj.list += pList[i];
				}
			}
		}
		pList = [];
	}

//End: ListBox for Partner's list

/*
// Begin: check box for Partners list. Do not delete.
//	
//		var pList = eval(app.preferences.bm_partners);
//		var pLength = pList.length;
//	
//		var i;
//		var stmt;
//	
//		for (i = 0 ; i < pLength; i += 4)
//		{
//			//pick up partner name from column 1
//			stmt =  eval( "stockphoto.advancedSearch.dlg.partner.C1.p"+i );
//	
//			if( stmt.value == true )
//			{
//				if( partnerObj.list == "" )
//				{
//					partnerObj.list += pList[i+1].toString();							
//				}
//				else
//				{
//					partnerObj.list += "," + pList[i+1].toString();						
//				}
//			}
//			else
//			{
//				 partnerObj.allPartners = false;
//			}
//	
//			if( (i+2) < pLength )
//			{
//				//pick up partner name from column 2
//				stmt =  eval( "stockphoto.advancedSearch.dlg.partner.C2.p"+i );
//	
//				if( stmt.value == true )
//				{
//					if( partnerObj.list == "" )
//					{
//						partnerObj.list += pList[i+3].toString();							
//					}
//					else
//					{
//						partnerObj.list += "," + pList[i+3].toString();						
//					}
//				}
//				else
//				{
//					 partnerObj.allPartners = false;
//				}
//			}
//		}
//End: Ck box for partner's List
*/

	return( partnerObj );
}


stockphoto.advancedSearch.okBtnClickedAuto=function()
{
	var lang="", kwd, partner, partnerObj, orient="", colfmt="", mType="", numPerPg="",
		maxHits="", thumSize="", modkwd, f, zc=stockphoto.advancedSearch.zc;

	if( stockphoto.advancedSearch.dlg != null )
	{
		kwd = stockphoto.advancedSearch.dlg.search.C1.C1C1.key.text;

		if( ( kwd == "" )||( kwd == undefined ) )
		{
			stockphoto.DL.generalAlertBox( zc.get( "$$$/AdvancedSearch/Error/NoSearchTerms=Specify one or more keywords." ), 1 );
			stockphoto.advancedSearch.dlg.active = false;
			app.scheduleTask( "stockphoto.advancedSearch.dlg.active = true;", 200, false );
			return;
		}

		lang = stockphoto.advancedSearch.getLangAuto( lang );

		partnerObj = new Object();
		partnerObj.list = "";
		partnerObj.allPartners = true;

		partnerObj = stockphoto.advancedSearch.getPartnerAuto( partnerObj );

		partner = partnerObj.list;
		if( (partner == "" )&&( partnerObj.allPartners == false ) )
		{
			if( ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].Collections == undefined )||
				( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].Collections[0].Collection == undefined ) )
			     stockphoto.DL.generalAlertBox( zc.get( "$$$/AdvancedSearch/Error/NoParnters=Please select one or more search providers" ), 1 );
			else stockphoto.DL.generalAlertBox( zc.get( "$$$/AdvancedSearch/Error/NoCollections=Please select one or more collections" ), 1 );
			stockphoto.advancedSearch.dlg.active = false;
			app.scheduleTask( "stockphoto.advancedSearch.dlg.active = true;", 200, false );
			return;	
		}

		delete partnerObj;

		orient   = stockphoto.advancedSearch.getOrientAuto( orient );
		colfmt   = stockphoto.advancedSearch.getCFmtAuto( colfmt );
		mType    = stockphoto.advancedSearch.getMTypesAuto( mType );
		numPerPg = stockphoto.advancedSearch.getnumResultsAuto( numPerPg );
		maxHits  = stockphoto.prefs.GetMaxHits();
		thumSize = stockphoto.prefs.thumbnailSizes[ stockphoto.prefs.GetThumbnailSize() ];
		modkwd   = stockphoto.core.util.removeIllegalSearchChars( kwd );

		if( partnerObj.collection )
		{
			var terms =
			{
				Keyword:		modkwd,
				Collections:	partner,
				Orientation:	orient,
				ColorFormat:	colfmt,
				MediaTypes:		mType,
				LangID:			lang,
				MaxHits:		maxHits,
				ItemsPerGroup:	maxHits,
				ThumbnailSize:	thumSize
			};
		}
		else
		{
			var terms =
			{
				Keyword:		modkwd,
				Partners:		partner,
				Orientation:	orient,
				ColorFormat:	colfmt,
				MediaTypes:		mType,
				LangID:			lang,
				MaxHits:		maxHits,
				ItemsPerGroup:	maxHits,
				ThumbnailSize:	thumSize
			};
		}

		f = Folder(stockphoto.core.folder.createNewSearchFolder(modkwd));

		if( app.document == undefined )
		{
			app.browseTo(f);
		}
		stockphoto.DL.search.basicSearch(terms, f, numPerPg,app.document.id);
	}
	this.parent.parent.close( 2 );
	app.scheduleTask( "stockphoto.advancedSearch.bothBtnClickedAuto();\n", 2000, false ); // be sure that the resource is freed.
}

stockphoto.advancedSearch.getLangAuto=function( lang )
{
	var name = stockphoto.advancedSearch.dlg.search.C1.C1C2.langID.selection;
	lang     = stockphoto.LangCountry.GetCodeFromSearchLanguageName( name );
	var l_c  = lang.split( "_" );
	lang = l_c[0] + "-" + l_c[1];
	return lang;
}

stockphoto.advancedSearch.getnumResultsAuto=function( numRslts )
{
	numRslts = "25"; //make this the default if in case we can't get a valid value.

	var index = stockphoto.advancedSearch.dlg.search.C2.C2C2.numRslt.selection.index;
	numRslts = stockphoto.prefs.thumbPerGroup[index];
	return numRslts;
}

stockphoto.advancedSearch.clearsOrientAuto=function()
{
	stockphoto.advancedSearch.dlg.orient.C1.portrait.value  = false;
	stockphoto.advancedSearch.dlg.orient.C1.square.value    = false;
	stockphoto.advancedSearch.dlg.orient.C2.land_s.value    = false;
	stockphoto.advancedSearch.dlg.orient.C2.panoramic.value = false;
}

stockphoto.advancedSearch.getOrientAuto=function( orient )
{
	var zc = stockphoto.advancedSearch.zc;
	var textLandscape = "Landscape";
	var textPanoramic = "Panoramic";
	var textSquare = "Square";
	var textPortrait = "Portrait";

	if( ( stockphoto.advancedSearch.dlg.orient.C1.portrait.value )&& 
	    ( stockphoto.advancedSearch.dlg.orient.C2.land_s.value )&&
		( stockphoto.advancedSearch.dlg.orient.C1.square.value )&& 
	    ( stockphoto.advancedSearch.dlg.orient.C2.panoramic.value ) )
	{
		return orient = "";
	}

	if( stockphoto.advancedSearch.dlg.orient.C1.portrait.value == true )
		orient = textPortrait;

	if( stockphoto.advancedSearch.dlg.orient.C2.land_s.value == true )
	{
		if( orient == "" )
			orient = textLandscape;
		else
			orient = orient + " OR " + textLandscape;
	}

	if( stockphoto.advancedSearch.dlg.orient.C1.square.value == true )
	{
		if( orient == "" )
			orient = textSquare;
		else
			orient = orient + " OR " + textSquare;
	}

	if( stockphoto.advancedSearch.dlg.orient.C2.panoramic.value == true )
	{
		if( orient == "" )
			orient = textPanoramic;
		else
			orient = orient + " OR " + textPanoramic;
	}

	return orient;
}

stockphoto.advancedSearch.clearsMTypesAuto=function()
{
	stockphoto.advancedSearch.dlg.mTypes.C2.photo.value = false;
	stockphoto.advancedSearch.dlg.mTypes.C2.illustration.value = false;
	stockphoto.advancedSearch.dlg.mTypes.C2.photoobject.value = false;
}

stockphoto.advancedSearch.getMTypesAuto=function( mtype )
{
	var zc = stockphoto.advancedSearch.zc;
	var textIllustration = "Illustration";
	var textPhotography = "Photography";
	var textPhotoObject = "PhotoObject";

	if( ( stockphoto.advancedSearch.dlg.mTypes.C2.photo.value )&& 
	    ( stockphoto.advancedSearch.dlg.mTypes.C2.illustration.value ) )
	{
		return mtype = "";
	}


	if( stockphoto.advancedSearch.dlg.mTypes.C2.photo.value == true )
	{
		mtype = textPhotography;
	}

	if( stockphoto.advancedSearch.dlg.mTypes.C2.illustration.value == true )
	{
		if( mtype == "" )
			mtype = textIllustration;
		else
			mtype = mtype + " OR " + textIllustration;
	}

	return mtype;
}

stockphoto.advancedSearch.clearsCFmtAuto=function()
{
	stockphoto.advancedSearch.dlg.mTypes.C1.color.value = false;
	stockphoto.advancedSearch.dlg.mTypes.C1.bw.value = false;
}

stockphoto.advancedSearch.getCFmtAuto=function(colfmt)
{
	var zc = stockphoto.advancedSearch.zc;

	if( ( stockphoto.advancedSearch.dlg.mTypes.C1.color.value )&& 
	    ( stockphoto.advancedSearch.dlg.mTypes.C1.bw.value ) )
	{
		return colfmt = "";
	}

	if( stockphoto.advancedSearch.dlg.mTypes.C1.color.value == true )
		colfmt = "Color";

	if( stockphoto.advancedSearch.dlg.mTypes.C1.bw.value == true )
	{
		if( colfmt == "" )
			colfmt = "BlackWhite";
		else
			colfmt = colfmt + " OR BlackWhite";
	}

	return colfmt;
}

stockphoto.advancedSearch.AdvanceSearch=function( doc_id )
{
	if( stockphoto.advancedSearch.dlg != undefined )
	{
		stockphoto.advancedSearch.dlg.active = true;
		return;
	}
	stockphoto.advancedSearch.AdvancedSearchDialogMainAuto(4);
}

stockphoto.advancedSearch.clearTheList=function()
{
	if( stockphoto.advancedSearch.the1st )
	{
		var i, pID=stockphoto.advancedSearch.dlg.partner.partnerGroup.PartnerList.partnerID;
		for( i=0; i<pID.items.length; i++ )
		{
			pID.items[i].selected = false;
		}
		stockphoto.advancedSearch.the1st = false;
	}
}

stockphoto.advancedSearch.RadioPressed=function( k )
{
	if( k == 1 )
	{
		stockphoto.advancedSearch.dlg.partner.C1.chk1.value = true;
		stockphoto.advancedSearch.dlg.partner.C2.chk2.value = false;
		var i, pID=stockphoto.advancedSearch.dlg.partner.partnerGroup.PartnerList.partnerID;
		for( i=0; i<pID.items.length; i++ )
		{
			pID.items[i].selected = true;
		}
		stockphoto.advancedSearch.the1st = true;
	}
	else
	{
		stockphoto.advancedSearch.dlg.partner.C1.chk1.value = false;
		stockphoto.advancedSearch.dlg.partner.C2.chk2.value = true;
		stockphoto.advancedSearch.clearTheList();
	}
}

stockphoto.advancedSearch.onClickTheList=function()
{
	var i, n=0, pID=stockphoto.advancedSearch.dlg.partner.partnerGroup.PartnerList.partnerID;
	for( i=0; i<pID.items.length; i++ )
	{
		if( pID.items[i].selected )
			n++;
	}
	stockphoto.advancedSearch.the1st = false;
	if( n == pID.items.length )
	     stockphoto.advancedSearch.RadioPressed( 1 );	
	else stockphoto.advancedSearch.RadioPressed( 2 );	
}

stockphoto.advancedSearch.AdvancedSearchDialogMainAuto=function( dialogType )
{
	var zc = stockphoto.advancedSearch.zc;
	var i, j, jc, jp, partners=[], collections=[], dwsl, searchLangIndex, 
	    searchRsltIndex, dlgtmp, iconPath, winButtonStyle, macButtonStyle,
		listOfPartners, nCol;

	this.SetDlgData=function( name, dispnm, fromPartner, nCol )
	{
		this.name        = name;
		if( ( dispnm != undefined )&&( dispnm.Value != undefined ) )
		     this.dispNm = dispnm.Value;
		else this.dispNm = name;
		this.fromPartner = fromPartner;
		if( fromPartner )
		{
			 if( nCol > 0 )
		          this.bDupl = true;  // to exclude the <partners> section
		     else this.bDupl = false; 

		}
		else this.bDupl  = false;
	}

	// second instance check
	if( stockphoto.advancedSearch.dlgOn )
	{
		return;
	}

	// Load partner's xml
	if( stockphoto.core.BoxCar.AnalyzeXmlFileObj == undefined )
	{
		stockphoto.core.BoxCar.AnalyzeXmlFileObj = new stockphoto.core.BoxCar.AnalyzeXmlFile( stockphoto.core.init.partnersXMLfsObj, stockphoto.core.BoxCar.HTMLUtil.CheckKeys );
		if( ( stockphoto.core.BoxCar.AnalyzeXmlFileObj == undefined )||
		    ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners == undefined ) )
		{
			// we failed to load partner's xml
			return;
		}
	}
	stockphoto.advancedSearch.dlgOn = true;

	partners = stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].Partner;
	if( ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].Collections == undefined )||
	    ( stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].Collections[0].Collection == undefined ) )
	{
		collections = [];
	} 
	else
	{
		collections = stockphoto.core.BoxCar.AnalyzeXmlFileObj.Partners[0].Collections[0].Collection;
	};
	nCol = collections.length;
	
	stockphoto.advancedSearch.dlg = new Window( 'window', stockphoto.advancedSearch.zc.get( "$$$/AdvancedSearch/Dialog/Title=Advanced Search" ) );
	stockphoto.advancedSearch.dlg.closeOnKey = "OSCmnd+W";

	stockphoto.advancedSearch.dlg.location = stockphoto.advancedSearch.standardCntTab.DIALOG_LOCATION;

	dwsl = stockphoto.core.util.getDocumentWindowSizeAndLocation();

	if( dwsl.location != undefined )
	{
		stockphoto.advancedSearch.dlg.location.x = dwsl.location.x + stockphoto.advancedSearch.dlg.location.x;
		stockphoto.advancedSearch.dlg.location.y = dwsl.location.y + stockphoto.advancedSearch.dlg.location.y;
	}

	//*****************************SEARCH PANEL*****************************

	searchLangIndex = app.preferences.bm_srclang;
	searchRsltIndex = app.preferences.bm_srcNumRslt;

	//instruction on how to search
	stockphoto.advancedSearch.dlg.tip      = stockphoto.advancedSearch.dlg.add( "statictext { alignment: 'left', text: ''}" );
	stockphoto.advancedSearch.dlg.tip.text = zc.get( "$$$/AdvancedSearch/Dialog/SearchText/Instruction=Initiate a new search with following criteria" );

	//panel for the search keyword, search language and number of results.


	dlgtmp = "panel {alignment:'left', text:'', orientation:'colum',"
	       + " size:" + stockphoto.advancedSearch.standardCntTab.SEARCH_PANEL_SIZE+","
	       + " C1: Group { orientation: 'row', alignChildren: 'left',"
	       + " C1C1: Group { key: EditText { text:''} },"
	       + " C1C2: Group { langID: DropDownList {} } },"
	       + " C12: Group { alignChildren: 'left', C12C1: Group { sample: StaticText { text:''} } },"
	       + " C2: Group { orientation:'row',"
	       + " C2C1: Group {numRsltLabel:  StaticText { text: ''} },"
	       + " C2C2: Group {numRslt:  DropDownList { } } } } ";
    // panel {alignment:'left', text:'', orientation:'colum', size:[400,120], C1: Group { orientation: 'row', alignChildren: 'left', C1C1: Group { key: EditText { text:''} }, C1C2: Group { langID: DropDownList {} } }, C12: Group { alignChildren: 'left', C12C1: Group { sample: StaticText { text:''} } }, C2: Group { orientation:'row', C2C1: Group {numRsltLabel:  StaticText { text: ''} }, C2C2: Group {numRslt:  DropDownList { } } } }

	stockphoto.advancedSearch.dlg.search = stockphoto.advancedSearch.dlg.add( dlgtmp );

	//set up the text strings.
	stockphoto.advancedSearch.dlg.search.text                      = zc.get( "$$$/AdvancedSearch/Dialog/SearchText/Title=Search by keywords or image IDs" );
	stockphoto.advancedSearch.dlg.search.C2.C2C1.numRsltLabel.text = zc.get( "$$$/AdvancedSearch/Dialog/SearchText/Results=Thumbnails per search group: " );
	stockphoto.advancedSearch.dlg.search.C12.C12C1.sample.text     = zc.get( "$$$/AdvancedSearch/Dialog/SearchText/Tip=e.g. London, cat, green" );

	//set up the size of each of the field so everything lines up.
	stockphoto.advancedSearch.dlg.search.C1.C1C1.key.size = stockphoto.advancedSearch.standardCntTab.SEARCH_KEYWORD_FIELD;

	stockphoto.advancedSearch.dlg.search.C1.C1C2.langID.size = stockphoto.advancedSearch.standardCntTab.SEARCH_LANG_DRDWN;

	stockphoto.advancedSearch.dlg.search.C2.C2C2.numRslt.size = stockphoto.advancedSearch.standardCntTab.SEARCH_RSLT_DRDWN;

	stockphoto.advancedSearch.dlg.search.C12.C12C1.sample.size = stockphoto.advancedSearch.standardCntTab.SEARCH_SAMPLE_KEYWORD;

	//Search language drop downlist
	if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_LangCountry ) )
	{
		for( i=0 ; i<stockphoto.prefs.languages.length; i++ )
		{
			stockphoto.advancedSearch.dlg.search.C1.C1C2.langID.add( "item", stockphoto.prefs.languages[i] );
		}
	}

	//number of thumbs per group.
	if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_Preference ) )
	{
		//set the default selection for Search Language.
		//do it here because .GetLanguage is in ST10 script.
		stockphoto.advancedSearch.dlg.search.C1.C1C2.langID.selection = stockphoto.prefs.GetSearchLanguageIndex();

		//Number of ThumbPerGroup dropdownlist
		for( i=0; stockphoto.prefs.thumbPerGroup[i]!=undefined; i++ )
		{
			stockphoto.advancedSearch.dlg.search.C2.C2C2.numRslt.add( "item", stockphoto.prefs.thumbPerGroup[i].toString() );
		}

		//set the default selection for number of ThumbPerGroup
		stockphoto.advancedSearch.dlg.search.C2.C2C2.numRslt.selection = stockphoto.prefs.GetThumbPerGroupIndex();
	}
		
	//*****************************Media Types ck boxes*****************************	

	dlgtmp = "panel { alignment:'left', text:'', orientation:'row', alignChildren:'left',"
	       + " size:" + stockphoto.advancedSearch.standardCntTab.MEDIA_PANEL_SIZE+","
	       + " C1:Group { orientation:'colum', alignChildren:'left', color:Checkbox { text:''}, bw:Checkbox { text:'' } },"
	       + " C2:Group { orientation:'colum', alignChildren:'left', photo:Checkbox {text:'' }, illustration:Checkbox { text:'' }, photoobject:Checkbox { text:'' } } }";

	stockphoto.advancedSearch.dlg.mTypes = stockphoto.advancedSearch.dlg.add( dlgtmp );

	stockphoto.advancedSearch.dlg.mTypes.text = zc.get( "$$$/AdvancedSearch/Dialog/MediaTypes/Title=Media Types" );

	stockphoto.advancedSearch.dlg.mTypes.C1.color.text        = zc.get( "$$$/AdvancedSearch/Dialog/MediaTypes/C1/color/Text=Color" );
	stockphoto.advancedSearch.dlg.mTypes.C1.color.size        = stockphoto.advancedSearch.standardCntTab.MEDIA_COLOR;

	stockphoto.advancedSearch.dlg.mTypes.C1.bw.text           = zc.get( "$$$/AdvancedSearch/Dialog/MediaTypes/C1/bw/Text=Black and White" );
	stockphoto.advancedSearch.dlg.mTypes.C1.bw.size           = stockphoto.advancedSearch.standardCntTab.MEDIA_BW;

	stockphoto.advancedSearch.dlg.mTypes.C2.photo.text        = zc.get( "$$$/AdvancedSearch/Dialog/MediaTypes/C2/photo/Text=Photography" );
	stockphoto.advancedSearch.dlg.mTypes.C2.photo.size        = stockphoto.advancedSearch.standardCntTab.MEDIA_PHOTO;

	stockphoto.advancedSearch.dlg.mTypes.C2.illustration.text = zc.get( "$$$/AdvancedSearch/Dialog/MediaTypes/C2/illustration/Text=Illustration" );
	stockphoto.advancedSearch.dlg.mTypes.C2.illustration.size = stockphoto.advancedSearch.standardCntTab.MEDIA_ILLUSTRATION;

    stockphoto.advancedSearch.dlg.mTypes.C2.photoobject.text = zc.get( "$$$/AdvancedSearch/Dialog/MediaTypes/C2/photoobject/Text=photoobject" );
	stockphoto.advancedSearch.dlg.mTypes.C2.photoobject.size = stockphoto.advancedSearch.standardCntTab.MEDIA_PHOTOOBJECT;
	
	with( stockphoto.advancedSearch.dlg.mTypes )
	{
		C1.color.value		  = true;  //set default
		C1.bw.value		      = true;
		C2.photo.value		  = true;
		C2.illustration.value = true;
		C2.photoobject.value = true;
	}

	//*****************************orientation ck boxes*****************************	

	dlgtmp = "panel { alignment:'left', text:'', orientation:'row', alignChildren:'left',"
		   + " size:" + stockphoto.advancedSearch.standardCntTab.ORIENTAION_PANEL_SIZE+","
		   + " C1:Group {orientation:'colum', alignChildren:'left', portrait:Checkbox { text:'' }, square:Checkbox { text:'' }},"
		   + " C2:Group {orientation:'colum', alignChildren:'left', land_s:Checkbox { text:'' }, panoramic:Checkbox { text:'' } } }";

	stockphoto.advancedSearch.dlg.orient = stockphoto.advancedSearch.dlg.add( dlgtmp );

	//stockphoto.advancedSearch.dlg.orient.margins = 8;  //space between columns.

	stockphoto.advancedSearch.dlg.orient.text = zc.get( "$$$/AdvancedSearch/Dialog/Orientation/Title=Orientation" );

	stockphoto.advancedSearch.dlg.orient.C1.portrait.text  = zc.get( "$$$/AdvancedSearch/Dialog/Orientation/C1/portrait/Text=Portrait" );
	stockphoto.advancedSearch.dlg.orient.C1.portrait.size  = stockphoto.advancedSearch.standardCntTab.ORIENTATION_PORTRAIT;

	stockphoto.advancedSearch.dlg.orient.C1.square.text    = zc.get( "$$$/AdvancedSearch/Dialog/Orientation/C1/square/Text=Square" );
	stockphoto.advancedSearch.dlg.orient.C1.square.size    = stockphoto.advancedSearch.standardCntTab.ORIENTATION_SQUARE;

	stockphoto.advancedSearch.dlg.orient.C2.land_s.text    = zc.get( "$$$/AdvancedSearch/Dialog/Orientation/C2/land_s/Text=Landscape" );
	stockphoto.advancedSearch.dlg.orient.C2.land_s.size    = stockphoto.advancedSearch.standardCntTab.ORIENTATION_LANDSCAPE;

	stockphoto.advancedSearch.dlg.orient.C2.panoramic.text = zc.get( "$$$/AdvancedSearch/Dialog/Orientation/C2/panoramic/Text=Panoramic" );
	stockphoto.advancedSearch.dlg.orient.C2.panoramic.size = stockphoto.advancedSearch.standardCntTab.ORIENTATION_PANORAMIC;

	with( stockphoto.advancedSearch.dlg.orient )
	{
		C1.portrait.value  = true;  //set default
		C1.square.value    = true;
		C2.land_s.value    = true;
		C2.panoramic.value = true;
	}

	// Begin Use List box for Partners List
	dlgtmp = "panel { alignment:'left', text:'',  orientation:'column', alignChildren:'column',"
	       + " size:" + stockphoto.advancedSearch.standardCntTab.PARTNER_PANEL_SIZE+","
		   + " C1:Group {orientation:'colum', alignChildren:'left', chk1:RadioButton { text:'' }},"
		   + " C2:Group {orientation:'colum', alignChildren:'left', chk2:RadioButton { text:'' }},"
	       + " partnerGroup:Group { orientation:'column', alignChildren:'left',"
	       + " PartnerList:Group { partnerID:ListBox {properties:{multiselect:true}} },"
	       + " PartnerTip:Group { orientation:'row',  alignChildren:'top',";

	if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_AlertBox ) )
	{
		iconPath = stockphoto.alertBox.makeAlertIconPath( 3, stockphoto.isWin );
		if( iconPath != "" )
		{
			dlgtmp += " 		AlertIcon:Image { ";
			dlgtmp += "icon:'";
			dlgtmp +=  iconPath;
			dlgtmp +=  "' },"
		}
	}
	dlgtmp += "		pTip:Group { sample:StaticText {text:'',properties:{multiline:true}}}}}}";

	stockphoto.advancedSearch.dlg.partner = stockphoto.advancedSearch.dlg.add( dlgtmp );

	stockphoto.advancedSearch.dlg.partner.C1.chk1.text  = zc.get( "$$$/AdvancedSearch/Dialog/Collection/chk1/Text=Search all collections" );
	stockphoto.advancedSearch.dlg.partner.C1.chk1.size  = stockphoto.advancedSearch.standardCntTab.CHECKBOX_1;
	stockphoto.advancedSearch.dlg.partner.C2.chk2.text  = zc.get( "$$$/AdvancedSearch/Dialog/Collection/chk2/Text=Search only the following collections" );
	stockphoto.advancedSearch.dlg.partner.C2.chk2.size  = stockphoto.advancedSearch.standardCntTab.CHECKBOX_2;

	stockphoto.advancedSearch.dlg.partner.C1.chk1.onClick = function() { stockphoto.advancedSearch.RadioPressed(1) };
	stockphoto.advancedSearch.dlg.partner.C2.chk2.onClick = function() { stockphoto.advancedSearch.RadioPressed(2) };

	stockphoto.advancedSearch.dlg.partner.partnerGroup.PartnerList.partnerID.size = stockphoto.advancedSearch.standardCntTab.PARTNER_LISTBOX;

	if( stockphoto.isWin )
	{
		stockphoto.advancedSearch.dlg.partner.partnerGroup.PartnerTip.pTip.sample.text = zc.get( "$$$/AdvancedSearch/Dialog/Provider/Panel/TipWin=For multiple selection, hold down Control key while you select or deselect multiple items." );
	}
	else
	{
		stockphoto.advancedSearch.dlg.partner.partnerGroup.PartnerTip.pTip.sample.text = zc.get( "$$$/AdvancedSearch/Dialog/Provider/Panel/TipMac=For multiple selection, hold down Command key while you select or deselect multiple items." );
	}

	stockphoto.advancedSearch.dlg.partner.partnerGroup.PartnerTip.pTip.sample.preferredSize = stockphoto.advancedSearch.standardCntTab.PARTNERTIPTEXT;

//	stockphoto.advancedSearch.dlg.partner.text = zc.get( "$$$/AdvancedSearch/Dialog/Provider/Panel/Text=Providers" );
	stockphoto.advancedSearch.dlg.partner.text = zc.get( "$$$/AdvancedSearch/Dialog/Provider/Panel/chk0/Text=Collections" );

	jp = 0; // jp = # from partners
	for( i=0; i<partners.length; i++ ) 
	{
		if( ( partners[i].PartnerName != undefined )&&
		    ( partners[i].PartnerName.Value != undefined ) )
		{
			stockphoto.advancedSearch.dlgData[jp] = new this.SetDlgData( partners[i].PartnerName.Value,
																		 partners[i].PartnerDisplayName, true, nCol );
			if( stockphoto.advancedSearch.dlgData[jp] != undefined ) 
			{
				jp++;
			}
		}
	}
	jc = jp; // jc - jp = # from collections
	for( i=0; i<collections.length; i++ ) 
	{
		if( ( collections[i].CollectionName != undefined )&&
		    ( collections[i].CollectionName.Value != undefined ) )
		{
			stockphoto.advancedSearch.dlgData[jc] = new this.SetDlgData( collections[i].CollectionName.Value,
																		 collections[i].CollectionDisplayName, false, nCol );
			if( stockphoto.advancedSearch.dlgData[jc] != undefined )
			{
				var pNm = ( collections[i].CollectionName.Value ).split( ':' );
				for( j=0; j<jp; j++ )
				{
					if( stockphoto.advancedSearch.dlgData[j].name == pNm )
					{
						stockphoto.advancedSearch.dlgData[j].bDupl = true;
					}
				}
				jc++;
			}
		}
	}
	for( i=0; i<jc; i++ )
	{
		if( ! stockphoto.advancedSearch.dlgData[i].bDupl )
		{
			stockphoto.advancedSearch.dlg.partner.partnerGroup.PartnerList.partnerID.add( "item", stockphoto.advancedSearch.dlgData[i].dispNm );
		}
	}

	stockphoto.advancedSearch.pCnt = jp;
	stockphoto.advancedSearch.cCnt = jc-jp;
	
	stockphoto.advancedSearch.RadioPressed( 1 );

	listOfPartners = stockphoto.advancedSearch.dlg.partner.partnerGroup.PartnerList.partnerID;
	listOfPartners.selection = listOfPartners.items;
	listOfPartners.onChange  = stockphoto.advancedSearch.onClickTheList;

// End Use List box for Partners List

/*
//	//  Begin CheckBox for Partner's List. Do not delete.
//	
//		var C1_Beg = "C1:Group {orientation:'colum', alignChildren:'left',";
//		var C1_End = "},"; //end of the group C1
//	
//		var Gap_Beg = "GapColun:Group {orientation:'colum', alignChildren:'left',";
//		var Gap_End = "},"; //end of the group Gap
//	
//		var C2_Beg = "C2:Group {orientation:'colum', alignChildren:'left',";
//		var C2_End = "},"; //end of the group C2
//	
//		var C1  = "";
//		var Gap = "";
//		var C2  = "";
//	
//		var pList = eval(app.preferences.bm_partners);
//		var pLength = pList.length;
//	
//		//prefsize = stockphoto.advancedSearch.standardCntTab.PARTNER_PREF1;
//	
//		for (i = 0 ; i < pLength; i += 4)
//		{
//			C1 += "p"+ i.toString() +":Checkbox{ text:' " + pList[i] + " '}, ";
//			if( (i+2) < pLength )
//			{
//				C2  += "p" + i.toString() + ":Checkbox{ text:' " + pList[i+2] + " '}, ";
//			}
//		}
//	
//		var Panel_Beg = "panel { alignment:'left', text:'', orientation:'row', alignChildren:'left', ";
//		Panel_Beg += "size:" + stockphoto.advancedSearch.standardCntTab.PARTNER_PANEL_SIZE+","
//		var Panel_End = "}";
//	
//		var res = Panel_Beg;
//	
//		if( C1 != "" )
//		{
//			res += C1_Beg;		  //column 1 of partners
//			res += C1;
//			res += C1_End;
//		}
//	
//		if( C2 != "" )
//		{
//			res += C2_Beg;		  //column 2 of partners
//			res += C2;
//			res += C2_End;
//		}
//	
//		res += Panel_End; //end of the statement.
//	
//		stockphoto.advancedSearch.dlg.partner      = stockphoto.advancedSearch.dlg.add( res );
//		stockphoto.advancedSearch.dlg.partner.text = zc.get( "$$$/AdvancedSearch/Dialog/Provider/Panel/Text=Providers" );
//	
//		with( stockphoto.advancedSearch.dlg.partner )
//		{
//			var stmt;
//	
//			for (i = 0 ; i < pLength; i += 4)
//			{
//				stmt = eval("C1.p" + i);
//				stmt.value = true;
//				stmt.size = stockphoto.advancedSearch.standardCntTab.PARTNER_COLUMN_1;
//	
//				if( (i+2) < pLength )
//				{
//					stmt = eval("C2.p" + i);
//					stmt.value = true;
//					stmt.size = stockphoto.advancedSearch.standardCntTab.PARTNER_COLUMN_2
//				}
//			}
//		}
//	
//End CheckBox for Partner's List. Do not delete.
*/
	
	//***********************************************************//
	//****************OK And Cancel buttons**********************//
	//***********************************************************//
	winButtonStyle = "group { alignment:'right', orientation:'row', alignChildren:'right', okBtn:Button{text:''},      cancelBtn:Button {text:''}}";
	macButtonStyle = "group { alignment:'right', orientation:'row', alignChildren:'right', cancelBtn:Button {text:''}, okBtn:Button{text:''}}";

	if( stockphoto.isWin )
		 dlgtmp = winButtonStyle;
	else dlgtmp = macButtonStyle;

	stockphoto.advancedSearch.dlg.btns = stockphoto.advancedSearch.dlg.add( dlgtmp );

	stockphoto.advancedSearch.dlg.btns.okBtn.text     = zc.get( "$$$/AdvancedSearch/Dialog/Btns/OK=Search" );
	stockphoto.advancedSearch.dlg.btns.cancelBtn.text = zc.get( "$$$/AdvancedSearch/Dialog/Btns/Cancel=Cancel" );

	stockphoto.advancedSearch.dlg.btns.okBtn.preferredSize     = stockphoto.advancedSearch.standardCntTab.OK_CANCEL_PREF;
	stockphoto.advancedSearch.dlg.btns.cancelBtn.preferredSize = stockphoto.advancedSearch.standardCntTab.OK_CANCEL_PREF;

	with( stockphoto.advancedSearch.dlg.btns )
	{
		okBtn.onClick		   = stockphoto.advancedSearch.okBtnClickedAuto;
		stockphoto.advancedSearch.dlg.defaultElement = okBtn;
		cancelBtn.onClick	   = stockphoto.advancedSearch.cancelBtnClickedAuto;
		stockphoto.advancedSearch.dlg.cancelElement  = cancelBtn;
	}
	stockphoto.advancedSearch.dlg.onClose = function() { app.scheduleTask( "stockphoto.advancedSearch.bothBtnClickedAuto();\n", 2000, false ); };										

	// display the dialog
	return( stockphoto.advancedSearch.dlg.show() );
}

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

