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

/* <<< value of "code" >>> */ /* Also defined in st00core.jsx */
stockphoto.Burp.code_initialize     = 0;
stockphoto.Burp.code_search         = 1;
stockphoto.Burp.code_getComp        = 2;
stockphoto.Burp.code_addToCart      = 3;
stockphoto.Burp.code_removeFromCart = 4;
stockphoto.Burp.code_checkOut       = 5;
stockphoto.Burp.code_url       	    = 6;  // URLfilter
stockphoto.Burp.code_changeRel      = 7;  // User change resolution in the cart
stockphoto.Burp.code_sptrigger      = 8;  // spTrigger
stockphoto.Burp.code_result         = 9;  // Search result
stockphoto.Burp.code_download       = 10; // Search result
stockphoto.Burp.code_terminate      = 11; // terminate
stockphoto.Burp.code_chkoutComp     = 12; // checkout completed / return from DR
stockphoto.Burp.code_favorite       = 13;
stockphoto.Burp.code_doubleClick    = 14;
stockphoto.Burp.code_gpk            = 15;
stockphoto.Burp.code_openApp        = 16;
stockphoto.Burp.code_viewProviderTab= 17; // For Provider tab
stockphoto.Burp.code_submitSurvey	= 18; // For Survey
stockphoto.Burp.code_ignore         = 19;
stockphoto.Burp.code_officialLast   = 19; // <---- Last one
// --- Addition
//stockphoto.Burp.code_changeView   = 20; // changing view to Home/Folder -> defined in st00core.jsx
//stockphoto.Burp.code_favoriteIcon = 21; // changing view to Home/Folder -> defined in st00core.jsx

	stockphoto.Burp.prepLogFile=function( rec )
	{
		var fs1=undefined, fs2=undefined, fs3=undefined;
		if( ( stockphoto.Burp.logFile == undefined )||
		    ( stockphoto.Burp.logFile == "" ) )
			return;
		try
		{
			if( stockphoto.Burp.logFileInit )
			{
				try
				{
					fs1 = File( stockphoto.Burp.logFile );
					if( fs1.exists )
						fs1.remove();
				} catch(e) {;};
				try
				{
					fs2 = new File( stockphoto.Burp.logFile );
					fs2.encoding = "UTF-8";
					fs2.open( "w", "TEXT", "????" );
					fs2.close();
				} catch(e) {;};
				stockphoto.Burp.logFileInit = false;
			}
			try 
			{
				fs3 = new File( stockphoto.Burp.logFile );
				fs3.open( "e", "TEXT", "????" );
				fs3.seek( 0, 2 );
				fs3.write( rec );
				fs3.close();
			} catch(e) {;};
		} catch(e) {;};// if( stockphoto.Burp.logFile != "" )
	}

stockphoto.Burp.callSPSUIfromCache=function(	doc_id,
												code	/* code part, see the above code_xxx */,
												key		/* string */,
												value	/* string */,
												id		/* string */,
												ref		/* string */ )
{
	var obj={}, ret="", title;
	if( ( code == stockphoto.Burp.code_url )&&
		( stockphoto.Burp.omitUrl ) )
	{
		return( "" );
	}

	// output to a local drive
	if( stockphoto.Burp.logFile != "" )
	{
		switch( code )
		{
			case stockphoto.Burp.code_initialize:		title = "init"; 			break;
			case stockphoto.Burp.code_search:			title = "search"; 			break;
			case stockphoto.Burp.code_getComp:			title = "getComp"; 			break;
			case stockphoto.Burp.code_addToCart:		title = "addToCart"; 		break;
			case stockphoto.Burp.code_removeFromCart:	title = "removeFromCart"; 	break;
			case stockphoto.Burp.code_checkOut:			title = "checkOut"; 		break;
			case stockphoto.Burp.code_url:				title = "url"; 				break;
			case stockphoto.Burp.code_changeRel:		title = "changeSel"; 		break;
			case stockphoto.Burp.code_sptrigger:		title = "spTrigger"; 		break;
			case stockphoto.Burp.code_result:			title = "results"; 			break;
			case stockphoto.Burp.code_download:			title = "download"; 		break;
			case stockphoto.Burp.code_terminate:		title = "terminate"; 		break;
			case stockphoto.Burp.code_chkoutComp:		title = "checkOutComp";		break;
			case stockphoto.Burp.code_favorite:			title = "favorite";			break;
			case stockphoto.Burp.code_doubleClick:		title = "doubleClickImg";	break;
			case stockphoto.Burp.code_gpk:				title = "gpk";				break;
			case stockphoto.Burp.code_openApp:			title = "openApp";			break;
			case stockphoto.Burp.code_changeView:		title = "changeWindow"; 	break;
			case stockphoto.Burp.code_favoriteIcon:		title = "favoriteIcon";		break;
			case stockphoto.Burp.code_viewProviderTab:	title = "viewProviderTab";	break;
			case stockphoto.Burp.code_submitSurvey:		title = "submitSurvey";		break;
			default:									title = "-unknown-"; 
		}
		stockphoto.Burp.prepLogFile( '['+code+"/"+title+'] k=['+key+'] v=['+value+'] id=['+id+'] ref=['+ref+']\n' );
	} // if( stockphoto.Burp.logFile != "" )

	if( code <= stockphoto.Burp.code_officialLast )
	{
		try
		{
			obj.code  = code;
			if( key == undefined )
				 obj.key   = "";
			else obj.key   = key;
			if( value == undefined )
				 obj.value = "";
			else obj.value = value;
			if( id == undefined )
				 obj.id    = "";
			else obj.id    = id;
			if( ref == undefined )
				 obj.ref   = "";
			else obj.ref   = ref;
			if( stockphoto.Burp.sendToServer )
			{
				ret = stockphoto.impl.burp( obj );
			}
		}
		catch(e)
		{
			ret = "";
	 // fail to call C Side "burp"
		}
	}
 	if( ! stockphoto.Burp.sendToServer )
	{
		var tDt = new Date();
		ret = "Adb-"+code+"-"+tDt.getFullYear()+tDt.getMonth()+tDt.getDate()+
			  "-"+tDt.getHours()+"-"+tDt.getMinutes()+"-"+tDt.getSeconds();
	}
	return( ret );
}

stockphoto.Burp.callSPSUI=function(	doc_id,
									code	/* code part, see the above code_xxx */,
									key		/* string */,
									value	/* string */,
									id		/* string */,
									ref		/* string */ )
{
	var ret="", trueCode=code%100, j, dblNm, bOk, bNewStart;
	// call SPSUI
	try
	{
		bOk = true;
		if( trueCode < 0 )
		{
			bOk = false;
		}
		else if( trueCode == stockphoto.Burp.code_url )
		{
			if( ( trueCode == stockphoto.Burp.dispCode[  doc_id ] )&&
				( value    == stockphoto.Burp.dispValue[ doc_id ] )&&
				( ref      == stockphoto.Burp.dispRef[   doc_id ] ) )
				bOk = false;
		}
		if( bOk ) // no double url && trueCode=0,1,2
		{
			ret = stockphoto.Burp.callSPSUIfromCache( doc_id, trueCode, key, value, id, ref );
		} // no double url
	} catch(e) { ; }

	if(	code == stockphoto.Burp.code_search )
	{
		if( ret == undefined )
			ret =  "";
		if( app.preferences != undefined )
		{
			app.preferences[ "bm_searchGUID"+doc_id ] = ret;
		}
	}
	stockphoto.Burp.dispCode[  doc_id ] = trueCode;
	stockphoto.Burp.dispValue[ doc_id ] = value;
	stockphoto.Burp.dispRef[   doc_id ] = ref;
	return( ret );
}

stockphoto.Burp.setOmitBurpurl=function()
{
	stockphoto.Burp.omitUrl = true;
	app.scheduleTask( "stockphoto.Burp.omitUrl=false;", 3000, false );
}

stockphoto.Burp.getLanguages=function()
{
	var lng={};
	lng.UILang     = $.locale;
	lng.BillCnt    = "";
	lng.SearchLang = $.locale;
	if( app.preferences != undefined )
	{
		if( ( app.preferences.Language != undefined )&&
			( app.preferences.Language != "" ) )
			 lng.UILang = stockphoto.core.getValidLocale( app.preferences.Language );
		if( ( app.preferences.bm_billing_region != undefined )&&
			( app.preferences.bm_billing_region != "" ) )
			 lng.BillCnt = app.preferences.bm_billing_region;
		else lng.BillCnt = lng.UILang;
		if( ( app.preferences.bm_search_language != undefined )&&
			( app.preferences.bm_search_language != "" ) )
			 lng.SearchLang = app.preferences.bm_search_language;
		else lng.SearchLang = lng.UILang;
	} 
	if( lng.BillCnt.length > 2 )
		lng.BillCnt = ( lng.BillCnt.substr( lng.BillCnt.length-2, 2 ) ).toUpperCase();
	return( lng );
}

stockphoto.Burp.initialize=function( partnersXmlPath )
{
	// Initialize Burp
	var v, i, Bt, dt, ref, iii, lng={};
	lng = stockphoto.Burp.getLanguages();
	lll = lng.UILang;
	if( lll.length > 2 )
		lll = lll.substring( 0, 2 ) + "-" + lll.substring( 3, lll.length );
	ref = 'Version='+stockphoto.Burp.doubleQuote+stockphoto.impl.version+stockphoto.Burp.doubleQuote
		+ ' langid='+stockphoto.Burp.doubleQuote+lll+stockphoto.Burp.doubleQuote;
	stockphoto.Burp.callSPSUI( 1 /* the very first doc_id */, stockphoto.Burp.code_initialize, 
								 "", partnersXmlPath, "", ref );

	// check if randomize parameter meets
	stockphoto.Burp.doIt = true;

	// ShoppingCart / Download list
	try
	{
		stockphoto.Burp.currSc = new stockphoto.Burp.listSc();
		if( stockphoto.Burp.delayedExec != undefined )
		{
			var dExec = stockphoto.Burp.delayedExec;
			stockphoto.Burp.delayedExec = undefined;
			eval( dExec );
		}
	} catch(e) { ; }
}

stockphoto.Burp.terminate=function()
{
	var i;
	try
	{
		for( i=0; i<stockphoto.Burp.getCompList.length; i++ )
		{
			if( stockphoto.Burp.getCompList[ i ] != undefined )
			{
				delete stockphoto.Burp.getCompList[ i ];
				stockphoto.Burp.getCompList[ i ] = undefined;
			}
		}
		if(  stockphoto.Burp.currSc != undefined )
			delete  stockphoto.Burp.currSc;
		stockphoto.Burp.currSc = undefined;
		stockphoto.Burp.callSPSUI( 1 /* the first doc_id */, stockphoto.Burp.code_terminate, "", "", "", "" );
	} catch(e) { ; }
}

stockphoto.Burp.writeSearchID=function( doc_id )
{
	var fs1, fs2, fsNm;
	try
	{
		if( ( stockphoto.Burp.searchFolder[ doc_id ] != undefined )&&
		    ( stockphoto.Burp.searchFolder[ doc_id ] != "" )&&
			( stockphoto.Burp.searchId[     doc_id ] != undefined )&&
			( stockphoto.Burp.searchId[     doc_id ] != "" ) )
		{
			fsNm = stockphoto.Burp.searchFolder[ doc_id ]+"/CACHE/searchID.txt";
			fs1 = File( fsNm );
			fs1.open( "w", "TEXT", "????" );
			fs1.write( stockphoto.Burp.searchId[ doc_id ] + "\\" + stockphoto.Burp.searchPageNo[ doc_id ] + "\\" ); // this end mark is stripped when it's read
			fs1.close();
			fs2 = File( fsNm );
			if( fs2.exists )
				return( true );
		}
	} catch(e) { ; }
	return( false );
}

stockphoto.Burp.readSearchID=function( doc_id, folderPath )
{
	var fs, rec="", r;
	try
	{
		fs = File( folderPath+"/CACHE/searchID.txt" );
		fs.open( "r", "TEXT", "????" );
		try
		{
			rec = fs.read();
		} catch(e) { ; }
		fs.close();
		r = rec.split( "\\" );
		if( r.length < 2 )
		     stockphoto.Burp.searchPageNo[  doc_id ] = 1;
	    else stockphoto.Burp.searchPageNo[  doc_id ] = stockphoto.core.util.convertToInteger( r[ 1 ] );
		if(  stockphoto.Burp.searchPageNo[  doc_id ] < 1 )
		     stockphoto.Burp.searchPageNo[  doc_id ] = 1;
		if( r[0] == "" )
		{
			stockphoto.Burp.prepLogFile( "...Submit to Jedi Council: "+folderPath );
			r[0] = app.preferences[ "bm_searchGUID"+doc_id ];
		}
		return( r[0] );
	} catch(e) { ; }
	stockphoto.Burp.prepLogFile( "...It is old search!! Otherwise submit to Jedi Council: "+folderPath );
	if( ( stockphoto.Burp.searchPageNo[ doc_id ] == undefined )||
	    ( stockphoto.Burp.searchPageNo[ doc_id ] < 1 ) )
	     stockphoto.Burp.searchPageNo[  doc_id ] = 1;
	r[0] = app.preferences[ "bm_searchGUID"+doc_id ];
	if( ( r[0] != undefined )&&( r[0] != "" ) )
		return( r[0] );
	return( "unknown" );
}

stockphoto.Burp.cnv=[ // "<" means "use as is", "" means "not use it"
	// search terms
//*	{ i:"MediaTypes",       o:"MediaType",    v:0 }, // o:"<" & v:0 is commented out
		{ i:"Illustration", o:"<",            v:8 },
		{ i:"Photography",  o:"<",            v:4 },
//*	{ i:"RoyaltyFree",      o:"<",            v:0 },
//*	{ i:"MediaID",          o:"<",            v:0 },
	{ i:"Orientation",      o:"Orientation",  v:0 },
		{ i:"Landscape",    o:"ls",           v:4 },
		{ i:"Portrait",     o:"pt",           v:1 },
		{ i:"Square",       o:"<",            v:2 },
		{ i:"Panoramic",    o:"<",            v:8 },
	{ i:"ColorFormat",      o:"clr",          v:0 },
		{ i:"Color",        o:"clr",          v:1 },
		{ i:"BlackWhite",   o:"bw",           v:2 },
	{ i:"LangID",           o:"langid",       v:0 },
//*	{ i:"PointOfView",      o:"<",            v:0 },
//*	{ i:"Location",         o:"<",            v:0 },
//*	{ i:"Photographer",     o:"<",            v:0 },
//*	{ i:"MediaDate",        o:"<",            v:0 },
//*	{ i:"DownloadableSize", o:"<",            v:0 },
//*	{ i:"SpecialCode",      o:"<",            v:0 },
//*	{ i:"PromotionCode",    o:"<",            v:0 },
	//	{ i:"Keyword",      o:"trm",          v:0 }, // already handled
	{ i:"MaxHits",          o:"",             v:0 },
	{ i:"ItemsPerGroup",    o:"", 	          v:0 },
	{ i:"ThumbnailSize",    o:"",             v:0 },
		//	{ i:"and",		o:"",             v:0 }, // Should not have
		//	{ i:"AND",		o:"",             v:0 }, // Should not have
		//	{ i:"And",		o:"",             v:0 }, // Should not have
			{ i:"or",    	o:"",             v:0 },
			{ i:"OR",		o:"",             v:0 },
			{ i:"Or",		o:"",             v:0 }
];

stockphoto.Burp.cnvToCd=function( iStr )
{
	var oj={o:"",v:0}, oStr, r=iStr.split( " " );
	for( var k=0; k<r.length; k++ )
	{
		if( r[k] != "" ) 
		{
			oStr = r[k];
			for( var i=0; i<stockphoto.Burp.cnv.length; i++ )
			{
				if( r[k] == stockphoto.Burp.cnv[i].i )
				{
					switch( stockphoto.Burp.cnv[i].o )
					{
						case "":  oStr = ""; break; /* ignore */
						case "<":            break; /* use r[k] */
						default:  oStr = stockphoto.Burp.cnv[i].o;
					}
					oj.v |= stockphoto.Burp.cnv[i].v;
					break;
				}
			} // for i
			if( i < stockphoto.Burp.cnv.length )
			{	// it is a table entry
				if( oStr != "" )
				{
					if( oj.o != "" )
						oj.o += " ";
					oj.o += oStr;
				}
			}
			else
			{	// it is not in the table
				if( oj.o != "" )
					oj.o += " ";
				oj.o += r[k];
			}
		} // r[k] != ""
	} // for k
	return( oj );
}

stockphoto.Burp.convXmlEncoding=function( inStr )
{
	var i, BtV, Bt, oStr="";
	for( i=0; i<inStr.length; i++ )
	{
		BtV = inStr.charCodeAt( i );
		if( BtV < 129 )
		{ // lower ASCII
			switch( BtV ) 
			{
				case 34: /* " */ Bt = "&quot;"; break;
				case 39: /* ' */ Bt = "&apos;"; break;
				case 38: /* & */ Bt = "&amp;";  break;
				case 62: /* > */ Bt = "&gt;";   break;
				case 60: /* < */ Bt = "&lt;";   break;
				default:         Bt = inStr.charAt( i );
			}
			oStr += Bt;
		}
		else 
		{
			oStr += File.encode( inStr.charAt( i ) );
		}
	}
	return( oStr );
}


//added for Value Collection
checkIfValueCollection=function(collections)
{
  
  var collectionlist = collections.split(',');
  var bisValueCollection = true;
  for (var nCollIter = 0; nCollIter < stockphoto.providers.collections.length; ++nCollIter)
  {
    for(var ctr = 0; ctr <collectionlist.length;++ctr)
    {
     if((collectionlist[ctr] == stockphoto.providers.collections[nCollIter].CollectionName.Value )&&(stockphoto.providers.collections[nCollIter].ValueCollection == null )) 
	 {
		 	bisValueCollection = false;
		 	break;
     }
    } 
  }
  return bisValueCollection;
}


stockphoto.Burp.writeSearchRec=function( doc_id, request, pageNm, searchLang, bMore /* 0 or 100 for more */ )
{	// return sraech language
	var ref, e, key, oj={o:"",v:0}, lng={}, oo={ l:"", id:""};
	try
	{
		lng = stockphoto.Burp.getLanguages();
		ref = "";
		for( e in request.searchTerms )
		{
			if( request.searchTerms[e] != "" )
			{
				if( e == "Keyword" )
				{
					key  = "SearchString";
					oj.o = request.searchTerms[e]; // use as is
				}
				else 
				{
					oj  = stockphoto.Burp.cnvToCd( e );
					key = oj.o;
					oj  = stockphoto.Burp.cnvToCd( request.searchTerms[e] );
					if( e == "LangID" )
					{
						oo.l = oj.o;
					}
				}
				if( ( key != "" )&&( oj.o != "" ) )
				{
					if( ref != "" )
						ref += " ";
					if( oj.v != 0 )
					{
					  ref += ( key+"="+stockphoto.Burp.doubleQuote+             (oj.v)                    +stockphoto.Burp.doubleQuote );
					}     
					else 
					{
					  ref += ( key+"="+stockphoto.Burp.doubleQuote+ stockphoto.Burp.convXmlEncoding(oj.o) +stockphoto.Burp.doubleQuote );
					  //AK:added by aman for value collection
            		  if(key =="Collections")
					  {
					  	ref += " ";
					  	var bIsValueCollection = checkIfValueCollection(oj.o);
					  	var logStatusForValueCollection;
					  	if(false == stockphoto.core.displayValueCollectionFeatureflag) 
					  	{
					  		logStatusForValueCollection = "disabled";
					  	}
					  	else
					  	{
					  		if(true == bIsValueCollection)
					  		{ 
					  			logStatusForValueCollection="yes"; 
					  		}	
					  		else 
					  		{
					  	 		logStatusForValueCollection="no"; 
					  		}
					  	}
					  	ref += ( "ValueCollection="+stockphoto.Burp.doubleQuote+ stockphoto.Burp.convXmlEncoding(logStatusForValueCollection) +stockphoto.Burp.doubleQuote );
					  }
					 //AK:end of added by aman for value collection 
					}  
				}
			}
			
		}
		
		//AK:added for Masked Images and Value Collection.
		if(undefined == request.searchTerms.Collections )
		{
			ref += " ";
			ref += ( "ValueCollection="+stockphoto.Burp.doubleQuote+ stockphoto.Burp.convXmlEncoding("no") +stockphoto.Burp.doubleQuote ); 
		}
		
		var  listObj = stockphoto.DL.NavBar.GetDrawerSettings(doc_id);
		
		if((true == stockphoto.core.displayPhotoObjectCollectionFeatureflag) && (true == listObj.mediaType.photoobject) && 
			(true == stockphoto.Burp.isAnyMaskedCollectionSelected(doc_id,request.searchTerms.Collections))) 
		{
			ref += " ";
			ref += ( "MaskedImage="+stockphoto.Burp.doubleQuote+ stockphoto.Burp.convXmlEncoding("yes") +stockphoto.Burp.doubleQuote ); 
		}
		else
		{
			if(false == stockphoto.core.displayPhotoObjectCollectionFeatureflag)
			{
				ref += " ";
				ref += ( "MaskedImage="+stockphoto.Burp.doubleQuote+ stockphoto.Burp.convXmlEncoding("disabled") +stockphoto.Burp.doubleQuote ); 
			}
			else
			{
				ref += " ";
				ref += ( "MaskedImage="+stockphoto.Burp.doubleQuote+ stockphoto.Burp.convXmlEncoding("no") +stockphoto.Burp.doubleQuote ); 
			}
		}
	 //AK:end of added by aman
	// add Search language
		if( oo.l == "" )
		{
			if( ( searchLang != undefined )&&( searchLang != "" ) )
				 oo.l = searchLang;
			else oo.l = lng.SearchLang;
			oj = stockphoto.Burp.cnvToCd("LangID");
			if( ref != "" )
				ref += " ";
		    ref += ( oj.o+"="+stockphoto.Burp.doubleQuote+ oo.l +stockphoto.Burp.doubleQuote );
		}
		oo.id = stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_search + bMore, "SearchType", stockphoto.Burp.searchFrom[ doc_id ], "", ref /* UTF-8 string */ );
		if( ( oo.id == undefined )||( oo.id == "" ) )
			stockphoto.Burp.prepLogFile( ".....No Search ID" );
	} catch(e) { ; }
	return( oo );
}

//added by aman to check if some masked image collection is selected or not.
stockphoto.Burp.isAnyMaskedCollectionSelected=function(doc_id,collections)
{
	var isMaskedCollectionSelected = false;
	
	if(undefined != doc_id)
	{
        var  listObj = stockphoto.DL.NavBar.GetDrawerSettings(doc_id);
    	
        if (undefined != collections)
    	{
    		for (var nCollIter = 0; nCollIter < stockphoto.providers.collections.length; ++nCollIter)
        	{
    			if((undefined != stockphoto.providers.collections[nCollIter].MaskedImage)
           	   && (undefined != stockphoto.providers.collections[nCollIter].MaskedImage.Value)
          	   && ("0" != stockphoto.providers.collections[nCollIter].MaskedImage.Value)&& ( true == listObj.collectionSelected[nCollIter] ) ) //if it is a Photo collection
    			{
    				isMaskedCollectionSelected = true;
    				break;
    			}
    		}
    	}
    	else
    	{
    		isMaskedCollectionSelected = true;
    	}
	}
	return isMaskedCollectionSelected;
}
//added by aman

stockphoto.Burp.search=function( doc_id, request )
{
	var oo={};
	try
	{
		if( stockphoto.Burp.searchFrom[ doc_id ] == undefined )
			stockphoto.Burp.searchFrom[ doc_id ] = "unknown";
		oo = stockphoto.Burp.writeSearchRec( doc_id, request, "1", "", 0 );
		stockphoto.Burp.searchId[       doc_id ] = oo.id;  
		stockphoto.Burp.searchLang[     doc_id ] = oo.l;
		stockphoto.Burp.searchFolder[   doc_id ] = request.folder;
		stockphoto.Burp.searchWritten[  doc_id ] = false;
		stockphoto.Burp.searchPageNo[   doc_id ] = 1;
	} catch(e) { ; }
}

stockphoto.Burp.moreSearch=function( doc_id, request )
{
	try
	{
		( stockphoto.Burp.searchPageNo[ doc_id ] )++;
		stockphoto.Burp.searchFrom[ doc_id ] = "btn";
		stockphoto.Burp.writeSearchID( doc_id );
	} catch(e) { ; }
}

stockphoto.Burp.XofY=function( doc_id, type, msg, pageNo /* can be undefined */ )
{	// type = 0: pageFull
	//		= 1: allThumbnailsMoved
	//		= 2: yFinal
	try
	{
		if( pageNo == undefined )
			 p = 1;
		else p = pageNo;
		if( ( stockphoto.Burp.searchId[ doc_id ] != undefined )&&
			( stockphoto.Burp.searchId[ doc_id ] != "" ) )
			stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_result, "ProviderResult", msg, stockphoto.Burp.searchId[ doc_id ], 
									   "PageNum="+stockphoto.Burp.doubleQuote+(""+p)+stockphoto.Burp.doubleQuote );

	} catch(e) { ; }
}

stockphoto.Burp.viewProviderTabReport = function (doc_id, sType, sProviderName, sMediaId )
{
	// type = idca => image ID was shown in all the places
	// type = ica => image ID was shown only in the Provider tab - this will help us in generating reports
	
	var sProviderId;
	var sPartnerName = stockphoto.core.getPartnerNameFromPartnerDisplayName(sProviderName);
	sProviderId = stockphoto.partnerNameToFilenameCode(sPartnerName); 
	if (sProviderId == undefined)
	{
		sProviderId = "";
	}
	try
	{
		if( sType != "" )
			stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_viewProviderTab, "EventSubType", sType, "", 
									   "mid=" +stockphoto.Burp.doubleQuote+( sMediaId ) +stockphoto.Burp.doubleQuote
									  +" pid="+stockphoto.Burp.doubleQuote+( sProviderId ) +stockphoto.Burp.doubleQuote);
	}
	catch (e)
	{
		;
	}
}

stockphoto.Burp.submitSurveyReport = function (doc_id, sSurveyType, sProviderName, sMediaId, iProviderPaneCount, sAnsIndex, sAns )
{

	var sProviderId;
	var sPartnerName = stockphoto.core.getPartnerNameFromPartnerDisplayName(sProviderName);
	sProviderId = stockphoto.partnerNameToFilenameCode(sPartnerName); 
	if (sProviderId == undefined)
	{
		sProviderId = "";
	}
	try
	{
		if( sSurveyType != "" )
			stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_submitSurvey, "srvid", "SurveyGPK", "", 
									   " mid=" +stockphoto.Burp.doubleQuote+( sMediaId ) +stockphoto.Burp.doubleQuote
									  +" pid="+stockphoto.Burp.doubleQuote+( sProviderId ) +stockphoto.Burp.doubleQuote
                                      +" srvcnt=" + stockphoto.Burp.doubleQuote+( iProviderPaneCount )+stockphoto.Burp.doubleQuote
                                      +" srvsubcnt='1'"
                                      +" srvix=" + stockphoto.Burp.doubleQuote+( sAnsIndex )+stockphoto.Burp.doubleQuote
                                      +" srvans=" + stockphoto.Burp.doubleQuote+( sAns )+stockphoto.Burp.doubleQuote
                                      );
	}
	catch (e)
	{
		;
	}
}


stockphoto.Burp.getCompReportEsc=function( doc_id, pathin, nTry )
{
	stockphoto.Burp.getCompReport( doc_id, unescape( pathin ), nTry );
}
stockphoto.Burp.getCompReport=function( doc_id, pathin, nTry )
{	// can't return !!
	var p, fsin, fsinNm, fssId, fsCSrc, j, source="bg", p, fsNm, fsObj, fsRec, p1, r1, p2, script, doubleClkNm, /*-dbl- tagName,*/ orgCompSource, path;
	try
	{
		var xmp     = stockphoto.core.util.GetXMPObj( pathin );
		var mediaID = "";
		if( ( xmp != undefined )&&( xmp.KindOfImage != "Thumbnail"  ) )
			mediaID = xmp.MediaID;
		if( ( mediaID == "" )&&( nTry < 10 ) )
		{
			script = 'stockphoto.Burp.getCompReportEsc('+doc_id+',"'+( escape( pathin ) )+'",'+(nTry+1)+');';
			app.scheduleTask( script, 500, false );
			return;
		}

		fsin   = File( pathin );
		fsinNm = unescape(fsin.name);
		path   = unescape( fsin.fsName );
		if( stockphoto.Burp.searchId[ doc_id ] == undefined )
			 fssId = "unknown";
		else fssId = stockphoto.Burp.searchId[ doc_id ];
		if( stockphoto.Burp.getCompSource[ doc_id ] == undefined )
			 fsCSrc = "";
		else fsCSrc = stockphoto.Burp.getCompSource[ doc_id ];

		if( fsCSrc == "dc" )
		{
			source = "dc";
		}
		else 
		{
			// so fsCSrc == "gpk", "btn", "rtclk", "bg"
			if( stockphoto.Burp.getCompList[ doc_id ] != undefined )
			{
				var jj;
				for( jj=0; jj<stockphoto.Burp.getCompList[ doc_id ].currGC.length; jj++ )
				{
					p = ( stockphoto.Burp.getCompList[ doc_id ].currGC[ jj ].Nm ).indexOf( fsinNm );
					if( ( stockphoto.Burp.getCompList[ doc_id ].currGC[ jj ].sId == fssId )&&
						( ( p == 0 )||( p == 4 )||( p == 5 ) ) )
						break;
				}
				if( jj < stockphoto.Burp.getCompList[ doc_id ].currGC.length )
				{	// In the table
					source = stockphoto.Burp.getCompList[ doc_id ].currGC[ jj ].f;
					stockphoto.Burp.getCompList[ doc_id ].currGC[ jj ].f = ""
				}
				else
				{	// Not in the predefined table
					source = "bg";
				}
			} // done with fsCSrc == "gpk", "btn", "rtclk", "bg"
		}

		if( mediaID == "" )
		{
			var xmp1    = stockphoto.core.util.GetXMPObj( path );
			if( ( xmp1 != undefined )&&( xmp1.KindOfImage != "Thumbnail"  ) )
				mediaID = xmp1.MediaID;
			if( mediaID == "" )
			{
				p = path.indexOf( ".jpg" );
				if( p >= 0 ) 
				{
					fsNm = path.substring( 0, p ) + "_medReq.xml";
					fsObj = File( fsNm );
					if( fsObj.exists )
					{
						fsRec = "";
						try
						{
							fsObj.open( "r" );
							fsRec = fsObj.read();
							fsObj.close();
						} catch(e) { ; }
						if( fsRec != "" )
						{
							p1 = fsRec.indexOf( '<ID Value="' );
							if( p1 >= 0 )
							{
								r1 = fsRec.substring( p1+11, fsRec.length );
								p2 = r1.indexOf( '"' );
								if( p2 >= 0 )
									mediaID = r1.substring( 0, p2 );
							}
						}
					}
				}
			}
		}
		if( mediaID == "" )
		{
			if( stockphoto.Burp.getCompMediaID[ doc_id ] != undefined )
				mediaID = stockphoto.Burp.getCompMediaID[ doc_id ];
		}
		if( mediaID == "" )
			 mediaID = "unknown";
		else stockphoto.Burp.getCompMediaID[ doc_id ] = mediaID;
		var name = ( File( path ) ).name;
		var nn   = name.split( "_" );
		var pid, ln=nn[0].length;
		if( ln < 2 )
			 pid = nn[0].toUpperCase();
		else pid = ( nn[0].substr( ln-2, 2 ) ).toUpperCase();
		if( stockphoto.Burp.searchId[ doc_id ] == undefined )
			stockphoto.Burp.searchId[ doc_id ] = "";
		if( source != "" )
			stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_getComp, "EventSubType", source, stockphoto.Burp.searchId[ doc_id ], 
									   "mid=" +stockphoto.Burp.doubleQuote+( mediaID ) +stockphoto.Burp.doubleQuote
									  +" pid="+stockphoto.Burp.doubleQuote+(   pid   ) +stockphoto.Burp.doubleQuote /*-dbl, doubleClkNm*/ );
	} catch(e) { ; }
}


stockphoto.Burp.updateGClist=function( doc, fLabel )
{
	this.updGC=function( doc, fLabel )
	{
		var i, k=0, sId, doc_id;
		doc_id = doc.id;
		if( stockphoto.Burp.searchId[ doc_id ] == undefined )
			 sId = "unknown";
		else sId = stockphoto.Burp.searchId[ doc_id ];
		this.currGC = [];
		if( stockphoto.Burp.getCompList[ doc_id ] != undefined )
		{
			for( i=0; i<stockphoto.Burp.getCompList[ doc_id ].currGC.length; i++ )
			{
				if( stockphoto.Burp.getCompList[ doc_id ].currGC[ i ].f != "" )
				{
					this.currGC[ k ]     = {};
					this.currGC[ k ].sId = stockphoto.Burp.getCompList[ doc_id ].currGC[ i ].sId;
					this.currGC[ k ].Nm  = unescape(stockphoto.Burp.getCompList[ doc_id ].currGC[ i ].Nm);
					this.currGC[ k ].f   = stockphoto.Burp.getCompList[ doc_id ].currGC[ i ].f;
					k++;
				}
			}
		}
		for( i=0; i<doc.selections.length; i++ )
		{
			this.currGC[ k ]     = {};
			this.currGC[ k ].sId = sId; 
//			this.currGC[ k ].Nm  = File( stockphoto.core.util.getDisplayPath(doc.selections[ i ],"") ).name;
			this.currGC[ k ].Nm  = unescape(File( ( stockphoto.core.util.getDisplayPath( doc.selections[ i ], "updateGClist()" ) ) ).name);
			this.currGC[ k ].f   = fLabel;
			k++;
		}
	} 
	// stockphoto.Burp.getCompList[ doc_id ].currGC[ k ].{ sId, Nm, f }
	try
	{
		if( doc != undefined )
		{
			var newCurrGC = new this.updGC( doc, fLabel );
			if( newCurrGC != undefined )
			{
				if( stockphoto.Burp.getCompList[ doc.id ] != undefined )
					delete stockphoto.Burp.getCompList[ doc.id ];
				stockphoto.Burp.getCompList[ doc.id ] = newCurrGC;
			}
		}
	} catch(e) { ; }
}

stockphoto.Burp.addToGClist=function( doc, fLabel, sPath )
{
	this.updGC=function( doc, fLabel, sName, idx )
	{
		var i, k=0, sId, doc_id, bDone=false;;
		doc_id = doc.id;
		if( stockphoto.Burp.searchId[ doc_id ] == undefined )
			 sId = "unknown";
		else sId = stockphoto.Burp.searchId[ doc_id ];
		this.currGC = [];
		if( stockphoto.Burp.getCompList[ doc_id ] != undefined )
		{
			for( i=0; i<stockphoto.Burp.getCompList[ doc_id ].currGC.length; i++ )
			{
				if( stockphoto.Burp.getCompList[ doc_id ].currGC[ i ].f != "" )
				{
					this.currGC[ k ] = {};
					if( unescape(stockphoto.Burp.getCompList[ doc_id ].currGC[ i ].Nm) == unescape(sName) )
					{
						this.currGC[ k ].sId = stockphoto.Burp.getCompList[ doc_id ].currGC[ i ].sId;
						this.currGC[ k ].Nm  = unescape(sName);
						this.currGC[ k ].f   = fLabel;
						bDone = true;
					}
					else
					{
						this.currGC[ k ].sId = stockphoto.Burp.getCompList[ doc_id ].currGC[ i ].sId;
						this.currGC[ k ].Nm  = unescape(stockphoto.Burp.getCompList[ doc_id ].currGC[ i ].Nm);
						this.currGC[ k ].f   = stockphoto.Burp.getCompList[ doc_id ].currGC[ i ].f;
					}
					k++;
				}
			}
		}
		if( ! bDone )
		{
			this.currGC[ k ]     = {};
			this.currGC[ k ].sId = sId; 
			this.currGC[ k ].Nm  = unescape(sName);
			this.currGC[ k ].f   = fLabel;
			k++;
		}
	} 
	var i, sName, sNm = ( File( sPath ).name ).toLowerCase();
	try
	{
		if( doc != undefined )
		{
			for( i=0; i<doc.selections.length; i++ )
			{
//				if( sNm == ( File( ( doc.selections[ i ] ).displayPath ).name ).toLowerCase() )
				if( sNm == ( File( ( stockphoto.core.util.getDisplayPath( doc.selections[ i ] ), "addToGClist()-1" ) ).name ).toLowerCase() )
					break;
			}
			if( i < doc.selections.length )
//				 sName = File( ( doc.selections[ i ] ).displayPath ).name;
				 sName = File( ( stockphoto.core.util.getDisplayPath( doc.selections[ i ] ), "addToGClist()-2" ) ).name;
			else sName = "";
			var newCurrGC = new this.updGC( doc, fLabel, sName, i );
			if( newCurrGC != undefined )
			{
				if( stockphoto.Burp.getCompList[ doc.id ] != undefined )
					delete stockphoto.Burp.getCompList[ doc.id ];
				stockphoto.Burp.getCompList[ doc.id ] = newCurrGC;
			}
		}
	} catch(e) { ; }
}

stockphoto.Burp.cleanGClistAtGpkEnd=function( doc_id, bGpknly )
{
	var i;
	try
	{
		if( stockphoto.Burp.getCompList[ doc_id ] != undefined )
		{
			for( i=0; i<stockphoto.Burp.getCompList[ doc_id ].currGC.length; i++ )
			{
				if( ( ! bGpknly )||( stockphoto.Burp.getCompList[ doc_id ].currGC[i].f == "bg" ) )
					stockphoto.Burp.getCompList[ doc_id ].currGC[i].f  = "";
			}
		}
	} catch(e) { ; }
}

stockphoto.Burp.listSc=function()
{
	if( ( app.preferences != undefined )&&
		( app.preferences.bm_ShoppingCartCount != undefined )&&
		( app.preferences.bm_ShoppingCartCount > 0 ) )
	{
		try
		{
			var i, j, k, Nm, Rec, r=[], s=[], dn;
			this.iMax = app.preferences.bm_ShoppingCartCount;
			this.item = [];
			for( i=0; i<this.iMax; i++ )
			{
				this.item[i] = {};
				dn  = 0;
				Nm  = "bm_scItem"+i+"_MediaXML";
				Rec = app.preferences[ Nm ];
				r   = Rec.split( "&" );
				for( j=0; j<r.length; j++ )
				{
					s = ( r[j] ).split( "=" );
					if( s.length > 1 )
					{
						if(      s[0] == "MediaID" )    { this.item[i].MediaID    =              s[1];   dn |= 1; }
						else if( s[0] == "PurchaseID" ) { this.item[i].PurchaseID =              s[1];   dn |= 2; }
						else if( s[0] == "Price" )      { this.item[i].Price      =              s[1];   dn |= 4; }
						else if( s[0] == "Currency" )   { this.item[i].Currency   =              s[1];   dn |= 8; }
						else if( s[0] == "PartnerID" )  { this.item[i].PartnerID  = File.decode( s[1] ); dn |= 16; }
						if( dn == 31 ) break;
					}
				} // j
				this.item[i].nRes = app.preferences[ "bm_scItem"+i+"_ResolutionCount" ];
				if( ( this.item[i].nRes == undefined )||( this.item[i].nRes < 0 ) )
					this.item[i].nRes = 0;
				this.item[i].Res  = [];
				for( k=0; k<this.item[i].nRes; ++k )
				{
					this.item[i].Res[k] = {};
					dn  = 0;
					Nm  = "bm_scItem"+i+"_Resolution"+k;
					Rec = app.preferences[ Nm ];
					r   = Rec.split( "&" );
					for( j=0; j<r.length; j++ )
					{
						s = ( r[j] ).split( "=" );
						if( s.length > 1 )
						{
							if(      s[0] == "PurchaseID" ) { this.item[i].Res[k].PurchaseID = s[1]; dn |= 1; }
							else if( s[0] == "Price" )      { this.item[i].Res[k].Price      = s[1]; dn |= 2; }
							if( dn == 3 ) break;
						}
					} // j
				} // k
			} // i
			return;
		} catch(e) {;}
	}
	this.iMax   = 0;
}

stockphoto.Burp.convTo2LetterCode=function( partner )
{
	var ij, lpartner=partner.toLowerCase();;
	for( ij=0; ij<stockphoto.Burp.Name_ID_Tab.length; ij++ )
	{
		if( lpartner == stockphoto.Burp.Name_ID_Tab[ ij ].Name )
			return( stockphoto.Burp.Name_ID_Tab[ ij ].id );
	}
	return( partner );
}

stockphoto.Burp.checkSc=function( doc_id )
{
	var i, j, MediaID, currSc, nPrev, nCurr, ref, lng={};
	try
	{
		currSc = new stockphoto.Burp.listSc();
		if( currSc != undefined )
		{
			nCurr = currSc.iMax;
			if( ( stockphoto.Burp.currSc == undefined )||( stockphoto.Burp.currSc.iMax < 1 ) )
				 nPrev = 0;
			else nPrev = stockphoto.Burp.currSc.iMax;
			// Insert
			for( i=0; i<nCurr; i++ )
			{
				MediaID = currSc.item[i].MediaID;
				for( j=0; j<nPrev; j++ )
				{
					if( MediaID == stockphoto.Burp.currSc.item[j].MediaID )
						break;
				}
				if( j >= nPrev )
				{	// no Prev -> new one
					lng = stockphoto.Burp.getLanguages();
					ref = 'mid='     +stockphoto.Burp.doubleQuote+ (MediaID)                                                     +stockphoto.Burp.doubleQuote
						+ ' purchid='+stockphoto.Burp.doubleQuote+ (currSc.item[i].PurchaseID)                                   +stockphoto.Burp.doubleQuote
						+ ' pid='    +stockphoto.Burp.doubleQuote+ stockphoto.Burp.convTo2LetterCode(currSc.item[i].PartnerID)   +stockphoto.Burp.doubleQuote
						+ ' bc='     +stockphoto.Burp.doubleQuote+ (lng.BillCnt)                                                 +stockphoto.Burp.doubleQuote;
					stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_addToCart, "EventSubType", stockphoto.Burp.addCartSource, "", ref );
				} 
			} // i
			for( j=0; j<nPrev; j++ )
			{
				MediaID = stockphoto.Burp.currSc.item[j].MediaID;
				for( i=0; i<nCurr; i++ )
				{
					if( MediaID == currSc.item[i].MediaID )
						break;
				} // i
				if( ( i >= nCurr )&&
					( stockphoto.Burp.currSc.item != undefined )&&
					( stockphoto.Burp.currSc.item[j] != undefined ) )
				{	// no Curr -> removed
					stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_removeFromCart, "mid", MediaID, "", 
											   'pid='+stockphoto.Burp.doubleQuote+stockphoto.Burp.convTo2LetterCode(stockphoto.Burp.currSc.item[j].PartnerID)+stockphoto.Burp.doubleQuote );
				}
			} // j
			if(  stockphoto.Burp.currSc != undefined )
				delete  stockphoto.Burp.currSc;
			stockphoto.Burp.currSc = currSc;
		} // if( currSc != undefined )
	} catch(e) { ; }
}

stockphoto.Burp.checkOutClear=function()
{
	var currSc;
	try
	{
		currSc = new stockphoto.Burp.listSc();
		if( currSc != undefined )
		{
			if(  stockphoto.Burp.currSc != undefined )
				delete  stockphoto.Burp.currSc;
			 stockphoto.Burp.currSc = currSc;
		}
	} catch(e) { ; }
}

stockphoto.Burp.checkOutComplete=function( doc_id, paramPath )
{
	var fs, rec, obj={ OrderID:"", PartnerID:"", MediaID:"", PurchaseID:"" }, idx=-1, e=[], value="", subval, orderID="";
	try
	{
		fs = new File( paramPath );
		if( fs != undefined )
		{
			if( fs.exists )
			{
				if( fs.open( "r", "TEXT", "????" ) )
				{
					while( true ) 
					{
						try
						{
							rec = fs.readln(); 
						} catch(e) { rec = ""; }
						if( rec != "" )
						{
							if( rec == "beginItem" )
							{
								idx++;
								obj.PartnerID  = "unknown";
								obj.MediaID    = "unknown";
								obj.PurchaseID = "unknown";
							}
							else if( rec == "endItem" )
							{
								if( ( obj.checkoutStatus == "COMPLETE"  )||
									( obj.checkoutStatus == "SUBMITTED" ) )
								{
									if( obj.OrderID != "" )
										orderID = obj.OrderID;
									subval = ( stockphoto.Burp.convTo2LetterCode( obj.PartnerID ) )+","+( obj.MediaID )+","+( obj.PurchaseID );
									if( value != "" )
										value += ";";
									value += subval;
								} // if( obj.checkoutStatus == "COMPLETE" )
							}
							else
							{
								e = rec.split( "=" );
								if( e.length == 2 )
								{
									obj[ e[0] ] = e[1];
								} // if( e.length == 2 )
							}
						}
						if( ( rec == "" )||( fs.eof ) )
						{
							break;
						}
					} // while( true ) 
					fs.close();
					stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_chkoutComp, "CheckoutResult", value, orderID, "" );
				} // fs.open( "r", "TEXT", "????" );
			} // if( fs.exists )
			delete fs;
		} // if( fs != undefined )
	} catch(e) { ; }
}

stockphoto.Burp.changePriceBegin=function( doc_id, arg )
{
	;
}

stockphoto.Burp.changePrice=function( doc_id, arg )
{
	var r=[], k, radioNo, i, iMax, j, jMax;
	if( stockphoto.Burp.currSc != undefined )
	{
		try
		{
			r		= arg.split( '+' ); // r[0]=#, r[1]=Price, r[2]=Descriptin
			k		= stockphoto.core.util.convertToInteger( r[ 0 ] );
			radioNo = 0;
			iMax	= stockphoto.Burp.currSc.iMax;
			for( i=0; i<iMax; i++ )
			{
				jMax = stockphoto.Burp.currSc.item[i].nRes;
				for( j=0; j<jMax; j++ )
				{
					if( k == radioNo )
					{
						if( stockphoto.Burp.currSc.item[i]._sel == undefined )
						{
							stockphoto.Burp.currSc.item[i]._sel = j;
						}
						else
						{
							if( stockphoto.Burp.currSc.item[i]._sel != j )
							{
								stockphoto.Burp.currSc.item[i]._sel = j;
								stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_changeRel, "mid", stockphoto.Burp.currSc.item[i].MediaID, "",
														   "pid="     + stockphoto.Burp.doubleQuote + stockphoto.Burp.convTo2LetterCode( stockphoto.Burp.currSc.item[i].PartnerID         ) + stockphoto.Burp.doubleQuote
														  +" purchid="+ stockphoto.Burp.doubleQuote +                                  ( stockphoto.Burp.currSc.item[i].Res[j].PurchaseID ) + stockphoto.Burp.doubleQuote );
							}
						}
						return;
					}
					radioNo++;
				} // j
			} // i
		} catch(e) { ; }
	} // if( stockphoto.Burp.currSc != undefined )
}

stockphoto.Burp.changePriceEnd=function( doc_id, arg )
{
	var r=[];
	try
	{
		r = arg.split( "+" );
		stockphoto.Burp.currSc_Sum         = r[0];
		stockphoto.Burp.currSc_SumCurrency = r[1];
	} catch(e) { ; }
}

stockphoto.Burp.endShCart=function( doc_id, arg )
{	// called when CheckOut button in ShoppingCart dialog
	; // do nothing
}

stockphoto.Burp.dlComplete=function( doc_id, mediaID, purchaseID, orderID, partnerID )
{
	var dlSource, mID, pID, oID, vID, ref;
	try
	{
		if( stockphoto.Burp.downloadSource[ doc_id ] == undefined )
			 dlSource = "dl";
		else dlSource = stockphoto.Burp.downloadSource[ doc_id ];
		if( mediaID == undefined )
			 mID = "";
		else mID = mediaID;
		if( purchaseID == undefined )
			 pID = "";
		else pID = purchaseID;
		if( orderID == undefined )
			 oID = "";
		else oID = orderID;
		if( partnerID == undefined )
			 vID = "";
		else vID = stockphoto.Burp.convTo2LetterCode( File.decode( partnerID ) );
		ref = 'mid='     + stockphoto.Burp.doubleQuote + mID + stockphoto.Burp.doubleQuote
			+ ' purchid='+ stockphoto.Burp.doubleQuote + pID + stockphoto.Burp.doubleQuote
			+ ' pid='    + stockphoto.Burp.doubleQuote + vID + stockphoto.Burp.doubleQuote
			+ ' oid='    + stockphoto.Burp.doubleQuote + oID + stockphoto.Burp.doubleQuote; 
		stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_download, "EventSubType", dlSource, "", ref );
	} catch(e) { ; }
}

stockphoto.Burp.URLFilter=function( doc_id, url )
{
	var u=[], a=[], p=[], k, noArg=0, linkIDRef=""; // , bLang=false, bCount=false, bBill=false;
	try
	{
		if( url.indexOf( "file://localhost" ) >= 0 )
		{	// shopping cart
			stockphoto.Burp.checkSc( doc_id ); 
		}
		else
		{
			u = url.split( "?" ); // u[0] = URL / u[1] = args
			if( ( u[1] != undefined )&&( u[1] != "" ) )
			{
				a = ( u[1] ).split( "&" );
				for( k=0; k<a.length; k++ )
				{
					p     = ( a[k] ).split( "=" );
					if( p[0] == "linkID" )
						 linkIDRef = "linkID="+stockphoto.Burp.doubleQuote+p[1]+stockphoto.Burp.doubleQuote;
					else noArg++; // # of args excluding "linkID"
				} // k
			} // set args string
			if( u[0] == stockphoto.core.html.urlForBMHome )
			{	// Home page
			     stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_url, "", "", "", "linkID="+stockphoto.Burp.doubleQuote+"0"+stockphoto.Burp.doubleQuote );
			}
			else
			{
				if( linkIDRef != "" )
				     stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_url, "", "", "", linkIDRef );
			}
		}
	} catch(e) { ; }
}

stockphoto.Burp.spTrigger=function( doc_id, args )
{
	try
	{
		if( args.sptrigger != "localHTML" )
			stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_sptrigger, "Trigger", args.sptrigger, "", "" );
	} catch(e) { ; }
}

stockphoto.Burp.openApp=function( doc_id, thumb, bOpenStandard, kindOfImage, meta )
{
	var sType, name, nn, pid;
	try
	{
		if( ( kindOfImage != "Thumbnail" )&&( kindOfImage != "Comp" )&&( kindOfImage != "Purchased" ) )
			return;
		if( bOpenStandard )
			 sType = "gpk";
		else sType = "rtclk";
		if( ( meta == undefined )||( meta.MediaID == undefined )||( meta.MediaID == "" ) )
			return;
//		name = ( File( thumb.displayPath ) ).name;
		name = ( File( stockphoto.core.util.getDisplayPath( thumb, "openApp()" ) ) ).name;
		nn   = name.split( "_" );
		var ln=nn[0].length;
		if( ln < 2 )
			 pid = nn[0].toUpperCase();
		else pid = ( nn[0].substr( ln-2, 2 ) ).toUpperCase();
		stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_openApp, "EventSubType", sType, "",
								   "mid=" +stockphoto.Burp.doubleQuote+( meta.MediaID ) +stockphoto.Burp.doubleQuote
								  +" pid="+stockphoto.Burp.doubleQuote+(      pid     ) +stockphoto.Burp.doubleQuote );
	} catch(e) {;}
}

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

