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

// ImgDetail namespace and zstringCache instance
stockphoto.imgDetail = {};
stockphoto.imgDetail.zc = new stockphoto.zstringCache( "st17ImgDetail" );

// z-string constants
stockphoto.imgDetail.zstr_SelKey1="$$$/ImageDetail/Dialog/KwdDesc=Select keywords below and click Find Similar to search for similar images.";
stockphoto.imgDetail.zstr_SelKey2="$$$/ImageDetail/Dialog/KeywordHelp=To find similar images, select keywords & click Find Similar";
stockphoto.imgDetail.zstr_SelKey3="$$$/ImageDetail/Dialog/KeywordShared=Shared Keywords";
stockphoto.imgDetail.zstr_SelKey4="$$$/ImageDetail/Dialog/KeywordWhole=All Keywords";
stockphoto.imgDetail.zstr_NotSupported="$$$/ImageDetail/Dialog/NotSupprtedLabel=Not Supported";

// Editted z-string
stockphoto.imgDetail.zstr_dlgTitle = "$$$/gpk3/title=Image Details"; // Watson 1259116 used to be "Get Price and Keywords"
stockphoto.imgDetail.zstr_viewKWds = "$$$/ImageDetail/Dialog/ViewKeywords=Find Similar Images"; // Watson 1259529, used to be "View keywords"

stockphoto.imgDetail.key_Gpk  = "btn"; 

// Data structure
stockphoto.gpk3               ={};
stockphoto.gpk3.CnvTab        ={};
stockphoto.gpk3.gpk3No        =0;
stockphoto.gpk3.gpk3Dt        =[];
stockphoto.gpk3.gpk3Sys       =[];
stockphoto.gpk3.gpk3ThumbArray=[];

// Status code - same values must be define in st17ImgDetail.htm
stockphoto.gpk3.gpk3_start             = 0;
stockphoto.gpk3.gpk3_noXmp             = 1; // error
stockphoto.gpk3.gpk3_getCompInProgress = 2;
stockphoto.gpk3.gpk3_getCompError      = 4;
stockphoto.gpk3.gpk3_getCompDone       = 8;

stockphoto.gpk3.gpk3_getReslInProgress = 16;
stockphoto.gpk3.gpk3_getReslError      = 32;
stockphoto.gpk3.gpk3_getReslDone       = 64;

stockphoto.gpk3.gpk3_allDone           = 128;
stockphoto.gpk3.gpk3_compSkipped       = 256;

stockphoto.gpk3.gpk3_allError		   = stockphoto.gpk3.gpk3_noXmp | stockphoto.gpk3.gpk3_getCompError | stockphoto.gpk3.gpk3_getReslError;
stockphoto.gpk3.gpk3_allComplete	   = stockphoto.gpk3.gpk3_allDone | stockphoto.gpk3.gpk3_getReslDone | stockphoto.gpk3.gpk3_getCompDone;

stockphoto.gpk3.gpk3_dtType            = 0; // bit 1: Add (#) to Search Key ords ........ gpkaddno
											//     2: place border ...................... gpkborder
											//	   4: image selection by single click ... gpkimgsel
											//     8: 4-division allowed ................ gpkdiv4
											//	  16: keyword progress display .......... gpkkeyprgrs
											//	  32: dialog progress display ........... gpkprogress

// stockphoto.gpk3.KWSpiningWheel type
stockphoto.gpk3.KWSpiningWheel_unknown      =0;
stockphoto.gpk3.KWSpiningWheel_addToCart    =1;
stockphoto.gpk3.KWSpiningWheel_downloadComp =2;
stockphoto.gpk3.KWSpiningWheel_editComp     =4;

	// Debugging Aid
	stockphoto.gpk3debug              ={};
	stockphoto.gpk3debug.logFile      =undefined;
	stockphoto.gpk3debug.rec          ="";
	stockphoto.gpk3debug.logFileInit  =true;
	try
	{
		// gpklog: "gpk.log"
		// gpkaddno: true
		// gpkborder: true
		// gpkimgsel: true
		// gpkdiv4: true
		// gpkkeyprgrs: true
		// gpkprogress: true
		if( stockphoto.core.log.DebugINIData.gpklog != undefined )
		{
			if( stockphoto.core.log.DebugINIData.gpklog.charAt(0) != '/' )
				 stockphoto.gpk3debug.logFile = ( Folder( stockphoto.core.folder.getMyShoppingCartFolder() ) ).parent+"/"+stockphoto.core.log.DebugINIData.gpklog;
			else stockphoto.gpk3debug.logFile = stockphoto.core.log.DebugINIData.gpklog;
		}
		if( ( stockphoto.core.log.DebugINIData.gpkaddno != undefined )&&
			( stockphoto.core.log.DebugINIData.gpkaddno ) )
		    stockphoto.gpk3.gpk3_dtType |= 1; // add # to search keys
		if( ( stockphoto.core.log.DebugINIData.gpkborder != undefined )&&
			( stockphoto.core.log.DebugINIData.gpkborder ) )
			stockphoto.gpk3.gpk3_dtType |= 2; // place border
		if( ( stockphoto.core.log.DebugINIData.gpkimgsel != undefined )&&
			( stockphoto.core.log.DebugINIData.gpkimgsel ) )
			stockphoto.gpk3.gpk3_dtType |= 4; // image selection by sigle click
		if( ( stockphoto.core.log.DebugINIData.gpkdiv4 != undefined )&&
			( stockphoto.core.log.DebugINIData.gpkdiv4 ) )
			stockphoto.gpk3.gpk3_dtType |= 8; // 4-division allowed
		if( ( stockphoto.core.log.DebugINIData.gpkkeyprgrs != undefined )&&
			( stockphoto.core.log.DebugINIData.gpkkeyprgrs ) )
			stockphoto.gpk3.gpk3_dtType |= 16; // keywords progress display
		if( ( stockphoto.core.log.DebugINIData.gpkprogress != undefined )&&
			( stockphoto.core.log.DebugINIData.gpkprogress ) )
			stockphoto.gpk3.gpk3_dtType |= 32; // dialog progress display
	} catch(e) {;};
	stockphoto.gpk3debug.write2LogFile=function( rec )
	{
		var fs1=undefined, fs2=undefined, fs3=undefined;
		if( ( stockphoto.gpk3debug.logFile == undefined )||
		    ( stockphoto.gpk3debug.logFile == "" ) )
			return;
		try
		{
			if( stockphoto.gpk3debug.logFileInit )
			{
				try
				{
					fs1 = File( stockphoto.gpk3debug.logFile );
					if( fs1.exists )
						fs1.remove();
				} catch(e) {;};
				try
				{
					fs2 = new File( stockphoto.gpk3debug.logFile );
					fs2.encoding = "UTF-8";
					fs2.open( "w", "TEXT", "????" );
					fs2.close();
				} catch(e) {;};
				stockphoto.gpk3debug.logFileInit = false;
			}
			try
			{
				fs3 = new File( stockphoto.gpk3debug.logFile );
				fs3.open( "e", "TEXT", "????" );
				fs3.seek( 0, 2 );
				fs3.write( rec );
				fs3.close();
			} catch(e) {;};
		} catch(e) {;};// if( stockphoto.gpk3debug.logFile != "" )
	}

stockphoto.gpk3.jsProgressCallbacks =
{
	doClose: function() 
	{   
		if ((stockphoto.gpk3.gpk3Sys != undefined)
            && (stockphoto.gpk3.gpk3Sys[ app.document.id ] != undefined))
		{
            stockphoto.gpk3.gpk3Sys[ app.document.id ].bprogressDialog = false; 
        }
		return true; 
	},
	willClose: function() 
	{ 
		if ((stockphoto.gpk3.gpk3Sys != undefined)
            && (stockphoto.gpk3.gpk3Sys[ app.document.id ] != undefined))
		{
            stockphoto.gpk3.gpk3Sys[ app.document.id ].bprogressDialog = false; 
        }
		return true; 
	}
}
stockphoto.gpk3.showSpinnerDialog=function( doc_id )
{
	if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_AlertBox ) )
	{
		if( stockphoto.gpk3.gpk3Sys[ doc_id ] == undefined )
			stockphoto.gpk3.gpk3Sys[ doc_id ]  = {};
		if( stockphoto.gpk3.gpk3Sys[ doc_id ].bprogressDialog )
		{
			; // dialog is already up, no need to do anything
		}
		else
		{
			var CnvTab = {};
			CnvTab.LN1_STR2 = stockphoto.alertBox.zc.get( stockphoto.alertBox.localizedStr4ErrMsg.MESSAGE_ES_TRYING );
			if( stockphoto.DL.HTMLUtil.SubLocalHTMLbyDocID( stockphoto.core.folder.getTemplateFolder() + "/st17ImgDetailProgress.htm",
															CnvTab, "gpk3Progress_"+doc_id+".htm", doc_id ) )
			{
				stockphoto.gpk3.gpk3Sys[ doc_id ].progressDialog  = new Dialog("file:"+stockphoto.HTMLUtil.fsOut.fsName );
				if( stockphoto.gpk3.gpk3Sys[ doc_id ].progressDialog != undefined )
				{
					stockphoto.gpk3.gpk3Sys[ doc_id ].bprogressDialog       = true;
					stockphoto.gpk3.gpk3Sys[ doc_id ].progressDialog.modal  = true;
					stockphoto.gpk3.gpk3Sys[ doc_id ].progressDialog.title  = stockphoto.imgDetail.zc.get(stockphoto.imgDetail.zstr_dlgTitle);
					stockphoto.gpk3.gpk3Sys[ doc_id ].progressDialog.width  = 250;
					stockphoto.gpk3.gpk3Sys[ doc_id ].progressDialog.height = 120;
					stockphoto.gpk3.gpk3Sys[ doc_id ].progressDialog.center();				
					stockphoto.gpk3.gpk3Sys[ doc_id ].progressDialog.open( stockphoto.gpk3.jsProgressCallbacks );
//					stockphoto.gpk3.gpk3Sys[ doc_id ].progressDialog.place( 0.0, 0.0 );		
				}
			}
		}
	} // if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_AlertBox ) )
}
stockphoto.gpk3.hideSpinnerDialog=function( doc_id )
{
	if( ( stockphoto.gpk3.gpk3Sys[ doc_id ] != undefined )&&
		( stockphoto.gpk3.gpk3Sys[ doc_id ].bprogressDialog != undefined )&&
		( stockphoto.gpk3.gpk3Sys[ doc_id ].bprogressDialog ) )
	{
		stockphoto.gpk3.gpk3Sys[ doc_id ].bprogressDialog = false;
		stockphoto.gpk3.gpk3Sys[ doc_id ].progressDialog.closing = true;
	}	
}

stockphoto.gpk3.ShowGettingImagesFromES=function( doc_id )
{
//	stockphoto.NavExtFnc.ShowGettingImagesFromES( doc_id );
	// progress dialog
	stockphoto.gpk3.showSpinnerDialog( doc_id );
}
stockphoto.gpk3.HideWheelFromES=function( doc_id )
{
//	stockphoto.NavExtFnc.HideWheelFromES( doc_id );
	stockphoto.gpk3.hideSpinnerDialog( doc_id );
}

// <BoxCar3>
// sMetadata - string from Metadata txt (xml serialized as text)
// oSourceObj - [Optional] If this is not 'undefined', the new metadata will be added to this object
// sFirstLevelDelim - [Optional] Delimiter between the key/value groups [ Default = '&&&' ]
// sSecondLevelDelim - [Optional] Delimiter between the individual key/value pairs [ Default = '&&' ]
stockphoto.imgDetail.ExtractMetadataFromString = function( sMetadata, oSourceObj, sFirstLevelDelim, sSecondLevelDelim )
{
    var oMeta = oSourceObj;

    // If we don't have oSourceObj, create a new template
    if (oMeta == undefined)
    {
        oMeta = { Keywords: [ ] };
    }

    // No string, no gain
    if (sMetadata == undefined)
    {
        return oMeta;
    }

    // Default 1st level delim is &&&
    if (sFirstLevelDelim == undefined)
    {
        sFirstLevelDelim = '&&&';
    }

    // Default 2nd level delim is &&
    if (sSecondLevelDelim == undefined)
    {
        sSecondLevelDelim = '&&';
    }

    // Get the first line. We don't want any \n-s in keys/values
    var arMetaLines = sMetadata.split('\n');
    var sLine = arMetaLines[0];

    var arParamGroups = sLine.split(sFirstLevelDelim);
    for (iParamGroup in arParamGroups)
    {
        var arParams = arParamGroups[iParamGroup].split(sSecondLevelDelim);
        for (iParam in arParams)
        {
            var sParam = arParams[iParam];

            var arEqSplit = sParam.split('=');
            if (arEqSplit.length < 2)
            {
                continue;
            }

            // Pick out the last and penultimate items (value and key)
            var sValue = arEqSplit.pop().replace(/\"/g,'\\"');
            var sKey = arEqSplit.pop().replace(/\"/g,'\\"');

            // If it's a keyword, add it to the array
            if (sKey == 'kw')
            {
                oMeta.Keywords.push(sValue);
            }
            else // otherwise, set it as a member of oMeta
            {
                var sEvalStr = 'oMeta.' + sKey + ' = "' + sValue + '";';
                eval(sEvalStr);
            }
        } // arParams
    } // arParamGroups

    return oMeta;
}

// <BoxCar3>
// Returns undefined in case of an error. Otherwise, the Metadata object [ .Keywords contains all the keywords in Media Metadata ]
// sMetadataFilePath - Path of the file containing metadata (txt format). event.metadataPath from GetInfo.
// bRetainAfterLoad - If false or undefined, the file will be deleted after Load succeeds.
// Example: var oMetaData = stockphoto.imgDetail.LoadMetadataFromFile( event.metadataPath );
stockphoto.imgDetail.LoadMetadataFromFile = function( sMetadataFilePath, bRetainAfterLoad )
{
    var oMeta = undefined;

    if (sMetadataFilePath == undefined)
    {
        return oMeta;
    }

	var metaFile = new File(sMetadataFilePath);

	if ((metaFile.exists) && (metaFile.open('r') == true))
	{
        try
        {
    		// The first line has no first level delim, and second level delim = '&'
    		var sLine = metaFile.readln();
            var oMeta = stockphoto.imgDetail.ExtractMetadataFromString( sLine, undefined, undefined, '&' );

    		// The second line uses default delims (&&& and &&)
    		sLine = metaFile.readln();
    		oMeta = stockphoto.imgDetail.ExtractMetadataFromString( sLine, oMeta);
    	}
    	catch (ex)
    	{
    	   oMeta = undefined;
        }
		finally
        {
            metaFile.close();
        }

        // Delete if specified so...
        if ((oMeta != undefined) && (bRetainAfterLoad != true))
        {
            metaFile.remove();
        }
	}

	return oMeta;

}

// <BoxCar3>
// Returns undefined in case of an error. Otherwise, the Metadata object [ .Keywords contains all the keywords in Media Metadata ]
// sMetadataStr - string containing metadata (txt format). event.metadataText from GetInfo.
// Example: var oMetaData = stockphoto.imgDetail.LoadMetadataFromString( event.metadataText );
stockphoto.imgDetail.LoadMetadataFromString = function( sMetadataStr )
{
    var oMeta = undefined;

    if (sMetadataStr == undefined)
    {
        return oMeta;
    }

    var arMetadataLines = sMetadataStr.split('\n');

    if (arMetadataLines == undefined)
    {
        return oMeta;
    }

    // The first line has no first level delim, and second level delim = '&'
    var sLine = arMetadataLines[0];
    var oMeta = stockphoto.imgDetail.ExtractMetadataFromString( sLine, undefined, undefined, '&' );

    if (arMetadataLines.length >= 2)
    {
        // The second line uses default delims (&&& and &&)
        sLine =  arMetadataLines[1];
        oMeta = stockphoto.imgDetail.ExtractMetadataFromString( sLine, oMeta);
    }
    return oMeta;
}

stockphoto.gpk3.countTask=0;
stockphoto.gpk3.executeTask=function( cmd )
{
	stockphoto.gpk3.countTask--;
	eval( cmd );
}

stockphoto.gpk3.scheduledTask=function( doc_id, cmd )
{
	var t;
 	if(      stockphoto.gpk3.countTask < 3 )  { t=10; }
	else if( stockphoto.gpk3.countTask < 6 )  { t=30; }
	else if( stockphoto.gpk3.countTask < 10 ) { t=60; }
	else if( stockphoto.gpk3.countTask < 15 ) { t=100; } else { t=200; }
	stockphoto.gpk3.countTask++;
	if( stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
		app.scheduleTask( 'stockphoto.gpk3.executeTask("'+cmd+'");', t, false );
}

// -------------------------------------------------------- sendErrorReport
stockphoto.gpk3.sendErrorReport=function( doc_id, idx, errorCode )
{
	stockphoto.gpk3.sendStatusReport( doc_id, idx, errorCode ); // status = error - no Xmp
	stockphoto.gpk3.sendDisplayImageInfo( doc_id, idx, stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].aPath,
													   stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].aHeight,
													   stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].aWidth,
													   stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sFname );
}
// -------------------------------------------------------- setupSlot
	stockphoto.gpk3.scheNoXmp=function( doc_id, idx )
	{
		if( stockphoto.gpk3.gpk3Dt[ doc_id ].isw )
		{
			stockphoto.gpk3.gpk3Dt[ doc_id ].isw = false;
			stockphoto.gpk3.gpk3Dt[ doc_id ].idx = idx;
			stockphoto.gpk3.displayGpk3( doc_id, false ); // send html to proceed / at scheNoXmp()
		}
		stockphoto.gpk3.sendStatusReport( doc_id, idx, stockphoto.gpk3.gpk3_noXmp ); // status = error - no Xmp
		stockphoto.gpk3.sendDisplayImageInfo( doc_id, idx, "../images/imgDetail/NotSupportedBig.jpg", 0, 0, "" );
	}
stockphoto.gpk3.setupSlot=function( doc_id, idx )
{
	if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
		return( 0 );
	var selPath, selFs, retval={}, xmp, bRet=0;
	selPath = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath;
	selFs   = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sFs;
	stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sFname = selFs.name;

	// check the xmp
	try
	{
		xmp = stockphoto.core.util.GetXMPObj( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath );
	} catch(e) { xmp = undefined; }
	if( xmp == undefined )
	{
		if( stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
			/* in setupSlot() */ app.scheduleTask( 'stockphoto.gpk3.scheNoXmp('+doc_id+','+idx+');', 5, false );
	}
	else
	{
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp = xmp;
		bRet = stockphoto.gpk3.gpk3getImgToShow( selPath, selFs, xmp, retval );
		// bRet == 1 ... .jpg file with xmp, retval.imagePath = selPath
		//		== 2|6 . file w/ xmp, retval.imagePath = local "ImgNotAvailBig.jpg" path
		//      == 8 ... remote Version Cue file
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].aPath = retval.imagePath;
		if( ( retval.imageWidth != undefined )&&( retval.imageHeight != undefined )&&
			( retval.imageWidth != ""        )&&( retval.imageHeight != ""        ) )
		{
			stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].aHeight = stockphoto.core.util.convertToInteger( "0"+retval.imageHeight );
			stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].aWidth  = stockphoto.core.util.convertToInteger( "0"+retval.imageWidth  );
		}
		else
		{
			stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].aHeight = 0;
			stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].aWidth  = 0;
		}
	}
	stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].imgType = bRet;
	return( bRet );
}
// -------------------------------------------------------- startUpTask
stockphoto.gpk3.startUpTask=function( doc_id, idx )
{
	var i, bRet;
	if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
		return;
   	for( i=idx; ((i<idx+2)&&(i<stockphoto.gpk3.gpk3Dt[ doc_id ].no)); i++ )
	{
	   	bRet = stockphoto.gpk3.setupSlot( doc_id, i );
		if( bRet <= 0 )
		{
			; // already sendStatusReport() & stockphoto.gpk3.sendDisplayImageInfo() are called
		}
   		else 
		{
			stockphoto.gpk3.scheduledTask( doc_id, 'stockphoto.gpk3.gpk3SetEachImgWithKeywordandResolution('+ doc_id +','+ i +','+ false+');' );
		}
	}
	if( i < stockphoto.gpk3.gpk3Dt[ doc_id ].no )
	{
		stockphoto.gpk3.scheduledTask( doc_id, 'stockphoto.gpk3.startUpTask('+ doc_id +','+ i +');' );
	}
}

// -------------------------------------------------------- setupImgDisp
stockphoto.gpk3.setupImgDisp=function( doc_id, idx )
{
	var ret={};
	if( ( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].dispType & 2 ) != 0 )
	{
		ret.iPath   = escape( stockphoto.HTMLUtil.ConvertToIEAddress( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].aPath ) );
		ret.iHeight = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].aHeight;
		ret.iWidth  = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].aWidth;
		ret.iFname  = escape( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sFname );
	}
	else if( ( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].imgType & 1 ) != 0 )
	{
		ret.iPath   = escape( stockphoto.HTMLUtil.ConvertToIEAddress( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath ) );
		ret.iHeight = 0;
		ret.iWidth  = 0;
		ret.iFname  = escape( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sFname );
	}
	else
	{
		ret.iPath   = "";
//		ret.iPath   = escape( stockphoto.HTMLUtil.ConvertToIEAddress( unescape( File( "../images/imgDetail/white.jpg" ).fsName ) ) );
		ret.iHeight = 0;
		ret.iWidth  = 0;
		ret.iFname  = "";
	}
	return( ret );
}
// -------------------------------------------------------- sendKeysByFreq
stockphoto.gpk3.sendKeysByFreq=function( doc_id )
{
	var i, m, nMax, execmd, r="", script, fact;
	var i1Max, i1x, i1, i2Min, i2Max, i2, jMax, iT, j, Shared=[], r2="", wKey, k=0;
	if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
		return;
	if( ( stockphoto.gpk3.gpk3_dtType & 1 ) != 0 )
	{	// send Keywords with frequency info.
		nMax = stockphoto.gpk3.gpk3Dt[ doc_id ].noOfSortedKeys;
		m    = stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreqNo;
		if(      stockphoto.gpk3.gpk3Dt[ doc_id ].no < 9 )   fact = 10;
		else if( stockphoto.gpk3.gpk3Dt[ doc_id ].no < 99 )  fact = 100;
		else if( stockphoto.gpk3.gpk3Dt[ doc_id ].no < 999 ) fact = 1000;
		else                                                 fact = 1000000;
		for( i=0; ((i<m)&&(i<nMax)); i++ )
		{
			if( stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ i ].k != "" )
			{
				if( r != "" )
					r += ",";
				r += ( (fact-stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ i ].n).toString() +"\177"+ stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ i ].k +" (" +stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ i ].n+ ")");
			}
		}
		if( stockphoto.gpk3debug.logFile != undefined )
		{
			stockphoto.gpk3debug.rec ='\nfromScript_AllKeyWds: '+r+'\n-----\n\n';
			stockphoto.gpk3debug.write2LogFile( stockphoto.gpk3debug.rec );
		}
		script = 'fromScript_AllKeyWds( "var args={ fact:'+fact+', ky:\''+escape( r )+'\' };" );';
	}
	else
	{
		this.CompKey=function( s1, n1, s2, n2 )
		{
			var i, iMax, c1, c2;
			if( n1 < n2 )
				 iMax = n1;
			else iMax = n2;
			for( i=0; i<iMax; i++ )
			{
				c1 = s1.charCodeAt( i );
				c2 = s2.charCodeAt( i );
				if( c1 < c2 )
					return( -1 );
				if( c1 > c2 )
					return(  1 );
			}
			if( n1 < n2 )
				return( -1 );
			if( n1 > n2 )
				return(  1 );
			return( 0 );
		} // this.CompKey()
		this.AllKeySort=function( ar, arLen, bAllKey, CompKey )
		{
			var i, iMax, i1, i2, s1, s2, n1, n2, bSwap=true;
			this.iTab = [];
			for( i=0; i<arLen; i++ )
			{
				this.iTab[ i ] = i;
			}
			for( iMax=arLen; ((iMax>1)&&(bSwap)); iMax-- )
			{
				i1    = this.iTab[ 0 ];
				if( bAllKey )
					 s1 = ar[ i1 ].k;
				else s1 = ar[ i1 ];
				n1    = s1.length;
				bSwap = false;
				for( i=1; i<iMax; i++ )
				{
					i2 = this.iTab[ i ];
					if( bAllKey )
						 s2 = ar[ i2 ].k;
					else s2 = ar[ i2 ];
					n2 = s2.length;
					if( CompKey( s1, n1, s2, n2 ) > 0 )
					{
						bSwap = true;
						this.iTab[ i-1 ] = i2;
						this.iTab[  i  ] = i1;
					}
					else
					{
						i1 = i2;
						s1 = s2;
						n1 = n2;
					}
				}
			}
		} // this.AllKeySort()
		nMax  = stockphoto.gpk3.gpk3Dt[ doc_id ].no;
		( stockphoto.gpk3.gpk3Dt[ doc_id ].keyProcessed )++;
		if( stockphoto.gpk3.gpk3Dt[ doc_id ].keyProcessed < nMax )
		{
			script = 'fromScript_AllKeyWds( "var args={ fact:'+10+', ky:\'1\177'+escape( 'none' )+', sky:\'1\177'+escape( 'none' )+'\' };" );';
		}
		else 
		{
			i1Max = stockphoto.gpk3.gpk3Dt[ doc_id ].c1.length;
			for( i1x=33; i1x<=i1Max; i1x++ )
			{
				if( i1x == i1Max )
					 i1 = 0;
				else i1 = i1x;
				if( stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ] != undefined )
				{
					i2Min = stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2min;
					i2Max = stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2max;
					for( i2=i2Min; i2<=i2Max; i2++ )
					{
						if( stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ] != undefined )
						{
							jMax = stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ].length;
							if( jMax > 0 )
							{
								iT = new this.AllKeySort( stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ], jMax, true, this.CompKey );
								if( iT != undefined )
								{
									for( j=0; j<jMax; j++ )
									{
										ii = iT.iTab[ j ];
										if( i1 != 0 )
											 wKey = String.fromCharCode( i1 )+String.fromCharCode( i2 )+stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ][ii].k;
										else wKey = String.fromCharCode( i2 )+stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ][ii].k;
										if( stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ][ ii ].n == nMax )
										{
											Shared[ k ] = wKey;
											k++;
										}
										if( r != "" )
											r += ",";
										if( i1 != 0 )
											 r += wKey;
										else r += wKey;
									} // j
									delete iT;
								} // iT
							} // jMax
						} // if( stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ] != undefined )
					} // for( i2=i2Min; i2<=i2Max; i2++ )
				} // if( stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ] != undefined )
			} // for( i1=0; i1<i1Max; i1++ )
			iT = new this.AllKeySort( Shared, Shared.length, false, this.CompKey );
			if( iT != undefined )
			{
				for( j=0; j<iT.iTab.length; j++ )
				{
					ii = iT.iTab[ j ];
					if( r2 != "" )
						r2 += ",";
					r2 += Shared[ ii ];
					}
				delete iT;
			}
			script = 'fromScript_AllKeyWdsBC3( "var args={ fact:'+0+', ky:\''+escape( ',_-_-_,'+r )+'\', sky:\''+escape( ',_-_-_,'+r2 )+'\' };" );';
		}
	}
	try
	{
		if( stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
			stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.execJS( script );
	} catch(e) {;}

}

// -------------------------------------------------------- sendDisplayImageInfo
stockphoto.gpk3.sendDisplayImageInfo=function( doc_id, idx, iPath, iHeight, iWidth, iFname )
{
	var dPath, script;
	if( iPath.charAt( 0 ) == '.' )
		 dPath = iPath; // like "../images/spacer.gif"
	else dPath = stockphoto.HTMLUtil.ConvertToIEAddress( iPath );
	script = 'fromScript_displayImageInfo( "var args={ idx:'+idx+', iPath:\''+escape(dPath)+'\', iHeight:'+iHeight+', iWidth:'+iWidth+', iFname:\''+iFname+'\'}" );';
	if( stockphoto.gpk3debug.logFile != undefined )
	{
		stockphoto.gpk3debug.write2LogFile( "\n"+script+"\n-----\n\n" );
	}
	try
	{
		if( stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
			stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.execJS( script );
	} catch(e) {;}
}

// -------------------------------------------------------- sendStatusReport
stockphoto.gpk3.sendStatusReport=function( doc_id, idx, code )
{	// Error and stockphoto.gpk3.gpk3_getReslDone
	stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status |= code;
	var script = 'fromScript_gotStatusReport( "var args={ idx:'+idx+', status:\''+stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status+'\'}" );';
	if( stockphoto.gpk3debug.logFile != undefined )
	{
		stockphoto.gpk3debug.write2LogFile( "\n"+script+"\n-----\n\n" );
	}
	try
	{
		if( stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
			stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.execJS( script );
	} catch(e) {;}
}

// -------------------------------------------------------- sendOkReport
stockphoto.gpk3.sendCompleteReport=function( doc_id, idx, g, e )
{
	stockphoto.gpk3.sendStatusReport( doc_id, idx, stockphoto.gpk3.gpk3_allDone );
}

// -------------------------------------------------------- getPrice3fin
stockphoto.gpk3.getPrice3fin=function( doc_id )
{
	if( stockphoto.gpk3.gpk3Sys[ doc_id ] != undefined )
	{
		if( ( stockphoto.gpk3.gpk3Sys[ doc_id ].dialog != undefined )&&
			( stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog ) )
		{
			stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.closing = true;
		}
		stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog = false;
	}
	/*B*//*-dblnew-*/ stockphoto.Burp.getCompSource[ doc_id ] = "";  // clear getComp
	/*B*/ stockphoto.Burp.cleanGClistAtGpkEnd( doc_id, true );
}
// -------------------------------------------------------- getPrice3allFin
stockphoto.gpk3.getPrice3allFin=function()
{
	var doc_id;
	for( doc_id=0; doc_id<stockphoto.gpk3.gpk3No; doc_id++ )
		stockphoto.gpk3.getPrice3fin( doc_id );
}

				// ------------------------------------ gpk3loadResolutionFromEachLine
				stockphoto.gpk3.gpk3loadResolutionFromEachLine=function( doc_id, idx, args )
				{
					var j, CurrencyOrPrice, firstSet, secondSet, OneParam;
					var foundPrice       = false;
					var foundPurchaseID  = false;
					var foundDescription = false;

					var szCurr  = "";
					var szPrice = "";

					var parametersArray = args.line.split("&&");
					for( j=0; j<parametersArray.length; j++ )
					{
						if( parametersArray[j] != "" )
						{
							OneParam = parametersArray[j].split("=");
							if( OneParam.length > 1 )
							{
								switch( OneParam[0] )
								{
									case "PurchaseID":
										stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].purchaseID[ args.wT ] = OneParam[ 1 ];
										foundPurchaseID =true;
										break;
									case "Description":
										stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].desc[ args.wT ] = stockphoto.DL.MiscDlgs.DecodeXMLString( OneParam[ 1 ] );
										foundDescription = true;
										break;
									case "Currency":
									case "Price":
										CurrencyOrPrice = parametersArray[j].split("&");
										firstSet  = CurrencyOrPrice[0].split("=");
										secondSet = CurrencyOrPrice[1].split("=");

										if (firstSet != undefined)
										{
											if (firstSet[0] == "Currency")
											{
												szCurr = firstSet[1];
											}
											else if (firstSet[0] == "Price")
											{
												szPrice = firstSet[1];
											}
										}

										if (secondSet != undefined)
										{
											if (secondSet[0] == "Currency")
											{
												szCurr = secondSet[1];
											}
											else if (secondSet[0] == "Price")
											{
												szPrice = secondSet[1];
											}
										}
										break;
								} // switch
							} // if( parametersArray[j] != "" )
						} // for j
					} // args.line is processed

			   		if( szCurr == args.currencyType )
					{
						var BoxCarPrice
									= stockphoto.DL.HTMLUtil.ConvertToPriceString( szPrice, true );
						if( BoxCarPrice != undefined )
						{
								stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].price[ args.wT ] = BoxCarPrice.v1 + BoxCarPrice.v2;
						}
						else
						{
								stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].price[ args.wT ] = szPrice+" ("+szCurr+")";
						}
						foundPrice = true;
					}
					else
					{
						if( szPrice != "" )
						{
							if( szCurr == "" )
							{
								szCurr = "???";
							}
							stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].price[ args.wT ] = szPrice+" ("+szCurr+")";
							foundPrice = true;
						}
					}

					if ((foundPrice == false) || (foundDescription  == false) || (foundPurchaseID == false))
					{
						args.noError = false; //do not go on.
					}
					else
					{
						//initialize the next set of data to N/A string.
						if( args.wT < 9 )
						{
							args.wT++;
							stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].purchaseID[ args.wT ] = stockphoto.gpk3.szNA;
							stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].desc[ args.wT ]       = stockphoto.gpk3.szNA;
							stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].price[ args.wT ]      = stockphoto.gpk3.szNA;
						}
						args.proc( args );
					}
				} // gpk3loadResolutionFromEachLine
			// -------------------------------------------- gpk3loadResolution
			stockphoto.gpk3.gpk3loadResolution=function( thumb, doc_id, idx )
			{
				var resolutionXMLPath = thumb;
				var fullPathIndex     = resolutionXMLPath.lastIndexOf(".");
				var infoFilePath;
				var args={};

				this.getNextLine=function( Args )
				{
					if( !( Args.eof ) )
					{
						Args.line = Args.inFileFs.readln();
						Args.lineOK = true;
						if( Args.inFileFs.eof )
							Args.eof = true;
					}
					else
					{
					    Args.lineOK = false;
						Args.line = "";
					}
				}

				args.currencyType = stockphoto.DL.getCurrencyType();
				args.wT           = 0;
				args.noError      = true;
				args.line         = "";
				args.lineOK       = true;  // Does current line contain valid data?
				args.eof          = false;
				args.proc         = this.getNextLine;

				if (fullPathIndex <= 0)
				{	// no extension
					infoFilePath = 	resolutionXMLPath + ".txt";
				}
				else
				{      // it has an extentsion.
					infoFilePath = resolutionXMLPath.slice(0, resolutionXMLPath.lastIndexOf(".")) + ".txt";
				}

				args.inFileFs = new File( infoFilePath );

				var currencyType = stockphoto.DL.getCurrencyType();
				var result = false;

				stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].purchaseID[ 0 ] = stockphoto.gpk3.szNA;
				stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].desc[ 0 ]       = stockphoto.gpk3.szNA;
				stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].price[ 0 ]      = stockphoto.gpk3.szNA;

				if (args.inFileFs.exists)
				{
					args.inFileFs.open( "r" );

					// handle the first line - MediaXML
					this.getNextLine( args ); // line = args.inFileFs.readln(); //save time dump the 1stline
					this.getNextLine( args );

					if ( ( ! args.inFileFs.eof )&&( args.noError ) )
					{
                        while ( args.lineOK && args.noError )
    					{
    						stockphoto.gpk3.gpk3loadResolutionFromEachLine( doc_id, idx, args );
    					} // while
					}

					args.inFileFs.close();
					result = true;
				}

				if( ! args.noError )
				{
					result  = false;
					args.wT = 0;
				}

				stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].noResolution = args.wT;
				return( result );
			}
		// ------------------------------------------------ resInfoEventHandler
		stockphoto.gpk3.resInfoEventHandler = function(event)
		{
			var bOk=false;
			switch( event.eventName )
			{
				case "complete":
						if( ! stockphoto.gpk3.gpk3Sys[ this.doc_id ].bdialog )
							return;
						if( (true == this.getKeywords) && ( event.metadataPath != undefined )&&( event.metadataPath != "" ) )
						{
						    var oMetaData = stockphoto.imgDetail.LoadMetadataFromFile( event.metadataPath );
						    stockphoto.gpk3.gpk3Dt[ this.doc_id ].e[ this.idx ].meta = oMetaData;
						    stockphoto.gpk3.setDataFrmMetaData(this.doc_id, this.idx);														
						} 
					    stockphoto.gpk3.gpk3Dt[ this.doc_id ].e[ this.idx ].xmlFilePath = event.metadataXMLPath;

						if( ( event.path != undefined )&&( event.path != "" ) )
						 {
							if( stockphoto.gpk3.gpk3loadResolution( event.path, this.doc_id, this.idx ) )
							{
								stockphoto.gpk3.sendStatusReport(   this.doc_id, this.idx, stockphoto.gpk3.gpk3_getReslDone ); // Resolution OK
								stockphoto.gpk3.sendCompleteReport( this.doc_id, this.idx, stockphoto.gpk3.gpk3Dt[ this.doc_id ], stockphoto.gpk3.gpk3Dt[ this.doc_id ].e[ this.idx ] );
								bOk = true;
							}
						}
						
						if( ! bOk )
							stockphoto.gpk3.sendErrorReport( this.doc_id, this.idx, stockphoto.gpk3.gpk3_getReslError ); // C side error
			
			            if (this.downloadComp)
                        {
							stockphoto.gpk3.scheduledTask( this.doc_id, 'stockphoto.gpk3.gpk3SetEachImgWithDownloadComp('+ this.doc_id +','+ this.idx +');' );
						}							
						return;
						
				case "status":
						if( event.status == "error")
						{
							stockphoto.gpk3.sendErrorReport( this.doc_id, this.idx, stockphoto.gpk3.gpk3_getReslError ); // C side error
						}
			} // switch
		}
	// ---------------------------------------------------- getResolution
	stockphoto.gpk3.getResolution=function( doc_id, idx, downloadComp, getKeywords )
	{
		var sPath, sFs;
		if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
			return;
		if( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].noResolution > 0 )
		{	// we completed the resolution process in another way
			stockphoto.gpk3.sendStatusReport(   doc_id, idx, stockphoto.gpk3.gpk3_getReslDone ); // Resolution OK
			stockphoto.gpk3.sendCompleteReport( doc_id, idx, stockphoto.gpk3.gpk3Dt[ doc_id ], stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ] );
			return;
		}

        if (undefined == downloadComp)
        {
			downloadComp = true;
        }
        if (undefined == getKeywords)
        {
			getKeywords = true;
        }
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status |= stockphoto.gpk3.gpk3_getReslInProgress;
		sPath = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath;
		sFs   = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sFs;

		// Get billing country
		var billing = stockphoto.core.BoxCar.LangCountry.getBillingCountry();
		var params;

		if (true == getKeywords)
		{
            params =
            {
				BillingCountry: billing,
				FetchInfo:      stockphoto.core.getInfo.FetchAllInfo
			}
		}
		else
		{
            params =
            {
				BillingCountry: billing
			}
		}

		stockphoto.core.util.addStockPhotoMetadata( sPath, params );

		var iRequest =
		{
			params:       params,
			sourcePath:   sFs,
			folder:       stockphoto.gpk3.BMtempFolderFs,
			baseName:     "~"+unescape( stockphoto.core.util.getBaseName( sPath ) ),
			eventHandler: stockphoto.gpk3.resInfoEventHandler,
			doc_id:       doc_id,
			idx:	      idx,
			downloadComp: downloadComp,
			getKeywords: getKeywords
		}
		try
		{
			stockphoto.core.SendProxyCredentials();
			stockphoto.impl.getInfo( iRequest );
		}
		catch(e)
		{
			;
		}
	}
		// ------------------------------------------------ setFrequencies
		stockphoto.gpk3.setFrequencies=function( doc_id, sk )
		{
			var i, i_1, j, k, k_1, m, n, iMax, newLen, nMax=0, bSwap=true;
			var ind=[], newSk=[], newRange=[], oldSk=[], oldRange=[];
			if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
				return;
			newLen = sk.length;
			for( i=0; i<newLen; i++ )
				ind[ i ] = i;
			// sort by freqiencies (ascending)
			for( iMax=newLen; ((bSwap)&&(iMax>1)); iMax-- )
			{
				bSwap = false
				for( i=1; i<iMax; i++ )
				{
					i_1 = i - 1;
					k   = ind[  i  ];
					k_1 = ind[ i_1 ];
					if( sk[ k_1 ].n > sk[ k ].n )
					{
						bSwap       = true;
						ind[ i_1 ]  = k;
						ind[  i  ]  = k_1;
					} // swap i needed
				} // i=1,2,..,iMax
			} // iMax=lenlen-1,..,2
			for( i=0, m=0; i<newLen; i++ )
			{
				k = ind[ newLen - i - 1 ]; // descending order
				newSk[ i ]   = {};
				newSk[ i ].k =       sk[ k ].k;
				newSk[ i ].n = ( n = sk[ k ].n );
				if( newRange[ n ] ==undefined )
				{
					newRange[ n ]    = {};
					newRange[ n ].st = i;
				}
				newRange[ n ].ed = i;
				if( nMax < n )
					nMax = n;
			}
			ind = []; // purge data

			// eliminate the same record
			for( i=0, m=0; i<stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreqNo; i++ )
			{
				// check the change
				for( j=0; j<newLen; j++ )
				{
					if( stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ i ].k == newSk[ j ].k )
						break;
				}
				if( j >= newLen )
				{	// this is the one that is NOT updted
					oldSk[ m ]   = {};
					oldSk[ m ].k =       stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ i ].k;
					oldSk[ m ].n = ( n = stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ i ].n );
					if( oldRange[ n ] == undefined )
					{
						oldRange[ n ]    = {};
						oldRange[ n ].st = m;
					}
					oldRange[ n ].ed = m;
                        m++;
					if( nMax < n )
						nMax = n;
				} // this is the old data in oldSk.
			} // for i
			for( i=stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreqNo-1; i>=0; i-- )
				stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ i ] = {}
			stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreqNo = 0;
			stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq   = []; // initialize
			for( j=nMax, m=0; j>0; j-- )
			{
				// register new
				if( newRange[ j ] != undefined )
				{
					for( i=newRange[ j ].st; i<=newRange[ j ].ed; i++, m++ )
					{
						stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ m ]   = {};
						stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ m ].k = newSk[ i ].k;
						stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ m ].n = newSk[ i ].n;
					}
				}
				// register old
				if( oldRange[ j ] != undefined )
				{
					for( i=oldRange[ j ].st; i<=oldRange[ j ].ed; i++, m++ )
					{
						stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ m ]   = {};
						stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ m ].k = oldSk[ i ].k;
						stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreq[ m ].n = oldSk[ i ].n;
					}
				}
			}
			stockphoto.gpk3.gpk3Dt[ doc_id ].keyByFreqNo = m;
		}
		// ------------------------------------------------ setMetaDataAndKWds
		stockphoto.gpk3.setMetaDataAndKWds=function( doc_id, idx, compPath, keywordArrayIn, from, bNewMethod )
		{
			var script, keyStr, m, searchKey, l, i1, i2, cRest, j, jMax, maxOccur, cNm, sk=[],
				keywordArray=[], kyCap=[], wky, wkyEach;
			// massage the coming keywords

			if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
				return( true );
			for( m=0, l=0; m<keywordArrayIn.length; m++ )
			{
				if( bNewMethod )
					 wky  = (                      keywordArrayIn[ m ]     ).split( ' ' );
				else wky  = ( File.decode( escape( keywordArrayIn[ m ] ) ) ).split( ' ' );
				searchKey = "";
				for( j=0; j<wky.length; j++ )
				{
					wkyEach = wky[ j ];
					if( ( wkyEach != "" )&&( wkyEach != " " ) )
					{
						i1 = ( wkyEach ).charCodeAt( 0 );
						if( ( i1 >= 97 )&&( i1 <= 122 ) )
						{
							wkyEach = String.fromCharCode( i1-32 ) + ( wkyEach ).substring( 1, ( wkyEach ).length );
						}
						if( j > 0 )
							searchKey += ' ';
						searchKey += wkyEach;
					}
				} // j, we have searchKey
				if( searchKey != "" )
				{
					wkyEach = searchKey.toUpperCase();
					for( j=0; j<l; j++ )
					{
						if( kyCap[ j ] == wkyEach )
							break;
					}
					if( j >= l )
					{
						keywordArray[ l ] = searchKey;
						kyCap[ l ]        = wkyEach;
						l++;
					}
				}
			}

			if( compPath == "" )
			{
				cNm = "";
			}
		    else
			{
				cNm = stockphoto.HTMLUtil.ConvertToIEAddress( compPath );
			}
			// here partner name is partner display name. So we need to get the partner name from the partner display name first
			var partnerName = stockphoto.core.getPartnerNameFromPartnerDisplayName(stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].PartnerName);

			var RefID = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].RefID;
			
			script = 'fromScript_CompOk( "args={ idx:'+idx+', iPath:\''+escape( cNm )+'\', '
				   + 'MediaID:\''    +escape( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].MediaID     )+'\', '
				   + 'RefID:\''    + RefID +'\', '
				   + 'MediaTitle:\'' +escape( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].MediaTitle  )+'\', '
				   + 'PartnerName:\''+escape( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].PartnerName )+'\' };" );';
			if( stockphoto.gpk3debug.logFile != undefined )
			{
				stockphoto.gpk3debug.rec ='\nfromScript_CompOk( "args={ idx:'+idx+', compPath:\''+cNm+'\', ' +'\n'
				   + 'MediaID:\''    +stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].MediaID     +'\', ' +'\n'
				   + 'RefID:\''    +RefID+'\', ' +'\n'
				   + 'MediaTitle:\'' +stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].MediaTitle  +'\', ' +'\n'
				   + 'PartnerName:\''+stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].PartnerName +'\' };" );' +'\n-----\n\n';
				stockphoto.gpk3debug.write2LogFile( stockphoto.gpk3debug.rec + '\n-----\n\n*** Raw KeyWords ***\n');
				stockphoto.gpk3debug.rec = "";
				for( j=0; j<keywordArray.length; j++ )
				{
					if( stockphoto.gpk3debug.rec.length > 60 )
					{
						stockphoto.gpk3debug.write2LogFile( stockphoto.gpk3debug.rec );
						stockphoto.gpk3debug.rec = "";
					}
					if( stockphoto.gpk3debug.rec != "" )
						stockphoto.gpk3debug.rec += ",";
					stockphoto.gpk3debug.rec += keywordArray[ j ];
				}
				if( stockphoto.gpk3debug.rec != "" )
					stockphoto.gpk3debug.write2LogFile( stockphoto.gpk3debug.rec );
				stockphoto.gpk3debug.write2LogFile( '\n*** ------------ ***\n\n' );
			}
			try
			{
				if( stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
					stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.execJS( script );
			} catch(e) {;}

			if( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].SearchKey.length < 1 )
			{
				keyStr = "";
				for( m=0; m<keywordArray.length; m++ )
				{
					searchKey = keywordArray[ m ];
					stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].SearchKey[ m ] = searchKey;
					l  = searchKey.length;
					i1 = searchKey.charCodeAt( 0 );
					if( i1 > 255 ) 
					{	// double byte
						i2    = i1;
						i1    = 0;
						cRest = searchKey.substring( 1, l );
					}
					else
					{
						if( l < 2 )
						{
							i2    = 0;
							cRest = "";
						}
						else
						{
							i2 = searchKey.charCodeAt( 1 );
							if( l < 3 )
								 cRest = "";
							else cRest = searchKey.substring( 2, l );
						}
					}
					if( keyStr != "" )
						keyStr += ",";
					keyStr += ( '1\177'+searchKey );
					if( stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ] == undefined )
						stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ] = { t2min:99999999, t2max:-99999999, t2:[] };
					if( stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2min > i2 ) stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2min = i2;
					if( stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2max < i2 ) stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2max = i2;

					if( stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ] == undefined )
						stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ] = [];

					jMax = stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ].length;
					for( j=0; j<jMax; j++ )
					{
						if( cRest == stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ][ j ].k )
						{
							maxOccur = ++( stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ][ j ].n );
							if( maxOccur > stockphoto.gpk3.gpk3Dt[ doc_id ].maxOccurence )
							{
								stockphoto.gpk3.gpk3Dt[ doc_id ].maxOccurence = maxOccur;
							}
							break;
						}
					}
					if( j >= jMax )
					{
						stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ][ jMax ]   = {};
						stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ][ jMax ].k = cRest;
						stockphoto.gpk3.gpk3Dt[ doc_id ].c1[ i1 ].t2[ i2 ][ jMax ].n = 1;
						if( stockphoto.gpk3.gpk3Dt[ doc_id ].maxOccurence <= 0 )
							stockphoto.gpk3.gpk3Dt[ doc_id ].maxOccurence = 1;
						maxOccur = 1;
					}
					sk[ m ]   = {};
					sk[ m ].n = maxOccur;
					sk[ m ].k = searchKey;
				} // m

				// send keywords for this image
				script = '\nfromScript_KeyWds( "args={ idx:'+idx+', ky:\''+escape( keyStr )+'\' };" );';
				if( stockphoto.gpk3debug.logFile != undefined )
				{
					stockphoto.gpk3debug.write2LogFile( script+'\n-----\n\n' );
				}
				try
				{
					if( stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
						stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.execJS( script );
				} catch(e) {;}

				// Accumlate aggregate keywords info. -> send report to Html
				stockphoto.gpk3.setFrequencies( doc_id, sk );

				// rport to HTML
				stockphoto.gpk3.sendKeysByFreq( doc_id );

			} // if( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].SearchKey.length < 1 )

			return( true );
		}
	// ---------------------------------------------------- setDataFrmComp
	stockphoto.gpk3.setDataFrmComp=function( doc_id, idx, stepSw )
	{
		var xmp, obj, bGet, k;
		if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
			return( false );
		if( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp == undefined )
		{	
			stockphoto.gpk3.sendErrorReport( doc_id, idx, stockphoto.gpk3.gpk3_noXmp ); // status = error - no Xmp
			return( false );
		}
		xmp  = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp;

		obj  = xmp.Media;
		bGet = 0;
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].MediaID = xmp.MediaID;
		if ((stockphoto.core.ImageID.ID == stockphoto.core.ImageIDs.MediaID) || (xmp.ASPRefID == undefined)
							|| (xmp.ASPRefID == "") || (xmp.ASPRefID == xmp.MediaID))
		{
			stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].RefID = xmp.MediaID;
		}
		else
		{
			stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].RefID = stockphoto.core.getASPRefFromPartner(xmp.Media["bmsp:Media/bmsp:PartnerName"],xmp.MediaID);
		}
		for( k in obj )
		{
			if( obj[k] != "null" )
			{
				if( k.indexOf( "Media/bmsp:MediaTitle" ) >= 0 )
				{
					stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].MediaTitle = File.decode( escape( obj[k] ) );
					bGet |= 1;
					if( bGet == 3 )
						break;
				}
				else if( k.indexOf( "Media/bmsp:PartnerName" ) >= 0 )
				{
					// Since the ProviderName metadata is changed to 'Adobe Stock Photos', we need fetch the PartnerName here and get the PartnerDisplayName from the Partners.xml
					stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].PartnerName = stockphoto.partnerNameToPartnerDisplayName(File.decode( escape( obj[k] ) ));
					bGet |= 2;
					if( bGet == 3 )
						break;
				}
			} // if( obj[k] != "null" )
		} // for( k in obj )


		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status |= stockphoto.gpk3.gpk3_getCompDone; // #.1
		stockphoto.gpk3.setMetaDataAndKWds( doc_id, idx, stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].cPath /* pass to html */, xmp.SearchKeywords, "setDataFrmComp", false );
	}

	stockphoto.gpk3.setDataFrmMetaData=function( doc_id, idx )
	{
		var xmp, obj, bGet, k;
		if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
			return( false );
		if( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].meta == undefined )
		{
			stockphoto.gpk3.sendErrorReport( doc_id, idx, stockphoto.gpk3.gpk3_noXmp ); // status = error - no meta
			return( false );
		}
		xmp  = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].meta;

		obj  = xmp.Media;
		bGet = 0;
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].MediaID = xmp.MediaID;
		if ((stockphoto.core.ImageID.ID == stockphoto.core.ImageIDs.MediaID) || (stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp.ASPRefID == undefined)
							|| (stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp.ASPRefID == "") || (stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp.ASPRefID == xmp.MediaID))
		{
			stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].RefID = xmp.MediaID;
		}
		else
		{
			stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].RefID = stockphoto.core.getASPRefFromPartner(xmp.PartnerID,xmp.MediaID);
		}
	
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].MediaTitle = xmp.MediaTitle;
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].PartnerName = xmp.PartnerID;

		stockphoto.gpk3.setMetaDataAndKWds( doc_id, idx, stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].cPath /* pass to html */, xmp.Keywords, "setDataFrmComp", true );
	}



	// ---------------------------------------------------- gpk3restoreMetadata
	stockphoto.gpk3.gpk3restoreMetadata=function( doc_id, path, properties, idx )
	{
		if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
			return;
		if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_GetComp ) )
		{
			stockphoto.getComp.restoreMetadata( doc_id, path, properties );
			stockphoto.gpk3.scheduledTask( doc_id, 'stockphoto.gpk3.setDataFrmComp('+(doc_id)+','+(idx)+',0);' );
		}
		else
		{
			stockphoto.gpk3.sendErrorReport( doc_id, idx, stockphoto.gpk3.gpk3_getCompError );
		}
	}
		// ------------------------------------------------ gpk3getImgToShow
		stockphoto.gpk3.gpk3getImgToShow=function( sPath, sFs, xmp, retval )
		{	// return bit1: file is .jpg
			//			 2: file with xmp meta data / defImg copy is already in BM temp
			//			 6: file with xmp meta data / defImf copy is made to BM temp (no comp at this time)
			//			 8: remote Version Cue file
			//			 0: np xmp meta data -> can not display anything in gpk
			// --> stored in stockphoto.gpk3.gpk3Dt[ doc_id ].e[ i ].imgKind thru gpk3setImgToShowData()
			var svLevel, bRet=0, names, partnerName, MediaID;
			svLevel = $.level;
			$.level = 0;
			var defImg    = new File(stockphoto.gpk3.tempFolder+"/images/ImgDetail/ImgNotAvailBig.jpg");
			var pathFound = false;

			// Init the return values
			retval.imagePath     = unescape( defImg.fsName );
			retval.downloadImage = false;

			try
			{

				var pIndex   = sPath.lastIndexOf(".");
				var xtension = unescape( sPath.slice( pIndex + 1, sPath.length ) );

				if( sFs.exists )  //check for not Version Cue remote file
				{
					if( xtension.toLowerCase() == "jpg" )  // is a jpg extension.
					{
						retval.imagePath = sPath;
						pathFound        = true;
						bRet             = 1;
					}
				}
				else
				{
					bRet |= 8;
				}

				if( ! pathFound ) // not local jpg file
				{
					if (xmp != undefined)
					{	// Not local jpg file but it has meta data
						try
						{
							names       = xmp.Media["bmsp:Media/bmsp:PartnerName"].split(" ");
							partnerName = "";
							for( var n in names )
							{
								partnerName += names[ n ];
							}
							MediaID = xmp.MediaID;
						}
						catch(e)
						{
							partnerName = "Acme";
							var dt  = new Date();
							MediaID = ""+(( 10000000*dt.getHours()) + (100000*dt.getMinutes()) + (1000*dt.getSeconds()) + (dt.getMilliseconds()));
						}
						var imgname = partnerName + "-" + MediaID + "-ImgNotAvailBig.jpg";
						var dstPath = stockphoto.gpk3.BMtempFolder + "/" + imgname;
						var dstFile = new File( dstPath );

						bRet |= 2;
						if( !dstFile.exists )
						{
							defImg.copy( dstFile );
							retval.downloadImage = true;
							bRet |= 4;
						}

						retval.imagePath = unescape( dstFile.fsName );

						try
						{
							var img = new Thumbnail( sFs.exists ? sFs : sPath );
							var md  = img.synchronousMetadata; // [NOTE] We NEED the latest metadata here - ASP needs to compute HTML image width/height accordingly.
							md.namespace = "http://ns.adobe.com/tiff/1.0/";
							retval.imageWidth  = md["tiff:ImageWidth"];
							retval.imageHeight = md["tiff:ImageLength"];
						} catch(e) {;}
					}
				}
			} catch(e) {;};
			$.level = svLevel;
			return( bRet );
		}
	// ---------------------------------------------------- gpk3getCompEventHandler
	stockphoto.gpk3.gpk3getCompEventHandler=function( event )
	{
		var thumb, gpkDstPath="", src, dst, dstFolder, dstThumbFolder, dst, bOk=false, xmp;
		switch( event.eventName )
		{
			case "complete":
					if( ! stockphoto.gpk3.gpk3Sys[ this.doc_id ].bdialog )
						return( false );
					if( ( event.path != undefined )&& ( event.path != "" ) )
					{
						gpkDstPath = event.path;
						src        = new File( gpkDstPath );

						dstFolder = File( this.folderOfThumbToReplace );
						if( dstFolder.exists )
						{
							dstThumbFolder	= new Thumbnail( dstFolder );

							//replace the source thumbnail.
							if( stockphoto.core.menu.isInFolderHierarchy( dstThumbFolder, stockphoto.places.recentSearches ) == true )
							{
								dst = new File( this.folderOfThumbToReplace + "/" + src.name );
								if( dst.exists )
								{
									var dstThumb = new Thumbnail( dst.fsName );
									dstThumb.refresh("metadata");
									var properties = [ ];
									var m = dstThumb.metadata; // We don't need synchronous Metadata here
									if( m != undefined )
									{
										var rating;
										var label;
										var	ns = "http://ns.adobe.com/xap/1.0/";
										m.namespace = ns;
										rating = m.Rating;
										if( ( rating != undefined )&&( rating.length > 0 ) )
										{
											properties.push( { namespace: ns, key: "Rating", value: rating } );
										}
										label = m.Label;
										if( ( label != undefined )&&( label.length > 0 ) )
										{
											properties.push( { namespace: ns, key: "Label", value: label } );
										}
										delete m;
										m = undefined;
									}
									src.copy( dst );
									gpkDstPath = dst;
									dstThumb.verifyExternalChanges();
									var refreshed = dstThumb.refresh();
									if( properties.length > 0 )
									{
										if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_GetComp ) )
										{
											gpkDstPath = "";
											stockphoto.gpk3.scheduledTask( this.doc_id, "stockphoto.gpk3.gpk3restoreMetadata("+(this.doc_id)+",'"+encodeURI(dst.fsName)
																		  +"', '"+(properties.toSource())+"',"+(this.idx)+");" );
										}
									}
									var oDstMeta = dstThumb.synchronousMetadata;
									if ("undefined" != typeof oDstMeta)
									{
                                        oDstMeta.namespace = "http://ns.adobe.com/StockPhoto/1.0/";
                                        stockphoto.gpk3.gpk3Dt[ this.doc_id ].e[ this.idx ].xmp = oDstMeta;
                                    }
								}
							} // if  (stockphoto.core.menu.isInFolderHierarchy(dstThumbFolder, stockphoto.places.recentSearches) == true)
						} // if (file.exists)

						// src.remove();
						stockphoto.impl.deleteGetComp( this.sourcePath );
						
					} // if (event.path != undefined && event.path != "")
					if( gpkDstPath != "" )
					{
						if( ( File( gpkDstPath ) ).copy( stockphoto.gpk3.gpk3Dt[ this.doc_id ].e[ this.idx ].cPath ) )
						{
							if( stockphoto.Burp.doIt ) // in getComp.GetAndCopyComp_Body
							{
							/*B*/	try
							/*B*/	{	// Obtain mediaID
							/*B*/		stockphoto.Burp.getCompReport( this.doc_id, gpkDstPath, 0 )
							/*B*/	} catch(e) { ; }
							}
							stockphoto.gpk3.sendStatusReport(   this.doc_id, this.idx, stockphoto.gpk3.gpk3_getCompDone );
						}
						else
						{
							stockphoto.gpk3.sendErrorReport( this.doc_id, this.idx, stockphoto.gpk3.gpk3_getCompError ); // copy error
						}
					}
					return( true );

		case "status":
			if( event.status == "error")
			{
				stockphoto.impl.deleteGetComp( this.sourcePath );
				stockphoto.gpk3.sendErrorReport( this.doc_id, this.idx, stockphoto.gpk3.gpk3_getCompError ); // C side error
				
			}
	} // switch( event.eventName )
	return( false );
} // end of gpk3getCompEventHandler()

stockphoto.gpk3.gpk3SetEachImgWithKeywordandResolution=function( doc_id, idx, downloadComp )
{
	if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
		return;
	
	stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status |= stockphoto.gpk3.gpk3_getReslInProgress;
	if (undefined == downloadComp)
	{
	  downloadComp = true;
	}
	if (downloadComp == false)
	{
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status |= stockphoto.gpk3.gpk3_compSkipped ;
    }
	sFs = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sFs;
	stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp = stockphoto.core.util.GetXMPObj( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath );
	if( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp == undefined )
	{
		stockphoto.gpk3.sendErrorReport( doc_id, idx, stockphoto.gpk3.gpk3_noXmp ); // status = error - no Xmp
		return;
	}
    var xmp = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp;
    
	if ( ( xmp.SearchKeywords == undefined )||( xmp.SearchKeywords == "" ) )
	{
	   stockphoto.gpk3.scheduledTask( doc_id, 'stockphoto.gpk3.getResolution('+doc_id+','+idx+','+ downloadComp+','+ true +')' );
    }
	else
	{
       stockphoto.gpk3.scheduledTask( doc_id, 'stockphoto.gpk3.getResolution('+doc_id+','+idx+','+ downloadComp+','+ false +')' );
       stockphoto.gpk3.scheduledTask( doc_id, 'stockphoto.gpk3.setDataFrmComp('+(doc_id)+','+(idx)+',0);' );
	}   

	if( stockphoto.gpk3.gpk3Dt[ doc_id ].isw )
	{
		stockphoto.gpk3.gpk3Dt[ doc_id ].isw = false;
		stockphoto.gpk3.gpk3Dt[ doc_id ].idx = idx;
		stockphoto.gpk3.displayGpk3( doc_id, true ); // send html to proceed / atgpk3SetEachImgWithDownloadComp()
	}
	if( ( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].imgType & 1 ) != 0 )
	{	// local jpg file -> thumbnail can be displayed
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].dispType = 1;
		stockphoto.gpk3.sendDisplayImageInfo( doc_id, idx, stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath, 0, 0, "" );
	}
}
// -------------------------------------------------------- gpk3SetEachImgWithDownloadComp
stockphoto.gpk3.gpk3SetEachImgWithDownloadComp=function( doc_id, idx )
{	// return true if preparation thread is dispatched
	var sFs, sName, p00;
	if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
		return;
	/*B*/ stockphoto.Burp.getCompSource[ doc_id ] = "bg"; // gpk3SetEachImgWithDownloadComp
	this.getComp=function( doc_id, idx, sel, sPath )
	{
		var SName, mediaID;
		if (stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status & stockphoto.gpk3.gpk3_getCompInProgress)
		  return (false);
		SName = stockphoto.core.util.getBaseName(sPath );
		if (!stockphoto.core.menu.isInFolderHierarchy(stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sel, stockphoto.places.recentSearches))
		{
			mediaID = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp.MediaID;
			SName = mediaID;
		}

		var sFs=stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sFs;
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status |= stockphoto.gpk3.gpk3_getCompInProgress;
		var params =
		{
			BillingCountry: "",
			DoNotExtractMetadata: "yes",
			XmlFilePath: stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmlFilePath
		}; 	//Compose the Getcomp Argument

		stockphoto.core.util.addStockPhotoMetadata( sPath, params );

		var getCompReq =
		{
			params:       				params,
			sourcePath:   				sFs,
			appPath:      				"",
			folder:       				stockphoto.gpk3.BMtempFolderFs,
			folderOfThumbToReplace:		new Folder( sel.spec.path ),
			baseName:     				SName,
			eventHandler:				stockphoto.gpk3.gpk3getCompEventHandler,
			onComplete:   				undefined,
			reportErr:	  				false,
			imgCopied: 	  				true,
			doc_id:						doc_id,
			idx:						idx
		};
		
		// Watson : 1293558 -- Begin
		var value = stockphoto.impl.getComp( getCompReq );
		
		//if download comp is already running for an image, stockphoto.impl.getComp returns an object otherwise it does not return anything
		if (undefined == value )
			return (true);
		else
			return (false);
		// Watson : 1293558 -- End
	} // this.getComp

	// Get xmp and if it it's comp
	sFs = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sFs;

	var dstThumb = new Thumbnail( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath);
	dstThumb.verifyExternalChanges();
	dstThumb.refresh();
	var oDstMeta = dstThumb.synchronousMetadata;
	if ("undefined" != typeof oDstMeta)
	{
           oDstMeta.namespace = "http://ns.adobe.com/StockPhoto/1.0/";
          stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp = oDstMeta;
	}

	if( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp == undefined )
	{
		stockphoto.gpk3.sendErrorReport( doc_id, idx, stockphoto.gpk3.gpk3_noXmp ); // status = error - no Xmp
		return( false );
	}

	// check if xmp is Comp
	if( ( ( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].imgType & 1 ) == 0 )|| // not local jpg
		( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp.KindOfImage == undefined )||
		( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp.KindOfImage == "" )||
		( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].xmp.KindOfImage == "Thumbnail" ) )
	{	// Thumbnail / gpk3SetEachImgWithDownloadComp()
		var bDoIterationTillComp;
		if( ( stockphoto.core.log.DebugINIData.Watson1281302 == undefined ) ||
			( stockphoto.core.log.DebugINIData.Watson1281302 == "yes" ) )
			 bDoIterationTillComp = true;
		else bDoIterationTillComp = false;
		
		// Watson : 1293558 -- Begin
		sName = sFs.name;
		p00   = sName.lastIndexOf(".");
		if( p00 >= 0 )
			 sName = ( sName.substring( 0, p00 ) ) + ".jpg";
		else sName = sName + ".jpg";

		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].cPath = unescape( File( stockphoto.gpk3.BMtempFolder+"/"+sName ).fsName );
		var result =	this.getComp( doc_id, idx, stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sel, stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath );
		
		if (true == result)
		  return (true);

		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].cPath="";
		// Watson : 1293558 -- End
		if ((idx == 0) && 
		    (stockphoto.core.menu.isInFolderHierarchy(stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sel, stockphoto.places.recentSearches)) && 
		    (stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog)&&
			( bDoIterationTillComp ))
		{
			app.scheduleTask('stockphoto.gpk3.gpk3SetEachImgWithDownloadComp('+( doc_id )+','+( idx )+');',1000,false );
		}
	}
	else
	{	// Comp
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status |= stockphoto.gpk3.gpk3_getCompDone;
		stockphoto.gpk3.sendDisplayImageInfo( doc_id, idx, stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath, 0, 0, "" );
		stockphoto.gpk3.sendStatusReport( doc_id, idx, stockphoto.gpk3.gpk3_getCompDone );
	}
	return( true );
}
			// -------------------------------------------- stockphoto.gpk3.getNextLine4Mem
			stockphoto.gpk3.getNextLine4Mem=function( args )
	   		{
				if( ! args.eof )
				{
					do
				   {
						( args.srcJdx )++;
						if( args.srcJdx >= args.srcJdxMax )
						{
							( args.srcIdx )++;
							if( args.srcIdx >= args.srcIdxMax )
							{
								args.eof = true;
								return;
							}
							args.each      = ( args.src[ args.srcIdx ] ).split( "\015" );
							args.srcJdxMax = ( args.each ).length;
							args.srcJdx    = 0;
						}
						args.line = args.each[ args.srcJdx ];
					} while( args.line == "" );
				} // if( ! args.eof )
			}


stockphoto.gpk3.execAddToCart=function( doc_id, idx, String_i_And_ResIndex, k )
{
		var j, ResIndex, cartArray = new Array(1);
		if( idx < 0 )
		{
			ResIndex = 0;
			for( j=0; j<stockphoto.gpk3.gpk3Dt[ doc_id ].no; j++ )
				cartArray[ j ] = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ j ].sPath;
		}
		else
		{
			ResIndex     = parseInt( String_i_And_ResIndex.substring( k+1, (String_i_And_ResIndex.length) ) );
			cartArray[0] = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath;
		}
		if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_AddToCart ) )
		{
			/*B*/ stockphoto.Burp.addCartSource = "gpk";
			stockphoto.addToCart.AddGroupThumbsToCart_Body( cartArray, ResIndex, undefined, doc_id ); // ??? not sure
		}
}
stockphoto.gpk3.execDownloadCom=function( doc_id, idx )
{
	var sPath = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath ;
	//3rd parameter, pass true to indicate it is being call from ImageDetail
	//4th parameter, not report error = false;
	/*B*/ stockphoto.Burp.getCompSource[ doc_id ] = stockphoto.imgDetail.key_Gpk; // gpk3.execDownloadCom
	var onComplete = {};
	cmdStr = "onComplete.compReceived = function(thumb, imgCopied) { };";
	eval(cmdStr);
	cmdStr = "onComplete.confirmDone = function(result) { };";
	eval(cmdStr);
	/*B*/ stockphoto.Burp.getCompSource[ doc_id ] = stockphoto.imgDetail.key_Gpk; // _gpk3_downloadAllComp
	/*B*/	stockphoto.Burp.addToGClist( app.document, stockphoto.imgDetail.key_Gpk, sPath );
	stockphoto.DL.GetComp.GetAndCopyComp( sPath, onComplete, true, false); // ??? not sure
}
stockphoto.gpk3.execEditComps=function( doc_id, idx, ied )
{
	var filePath;
	if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
		return;
	if( idx > ied )
	{
		if( stockphoto.gpk3 != undefined )
			stockphoto.gpk3.KWSpiningWheel( doc_id, false /* turmimg OFF */, true /* not to schedule */, stockphoto.gpk3.KWSpiningWheel_editComp ); 
		stockphoto.gpk3.getPrice3fin( doc_id );
		return;
	}

	if( ( ( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status & stockphoto.gpk3.gpk3_getCompDone ) != 0 )&&
		( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].cPath != "" ) )
		filePath = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].cPath;	 
	else 
		filePath = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].sPath;
	
	// Do not get comp for purchased images. Open it directly 
	if (File(filePath).exists)
	{
		thumb = new Thumbnail(File(filePath));
		var	m = thumb.synchronousMetadata;
		m.namespace = "http://ns.adobe.com/StockPhoto/1.0/";
		if ( m.KindOfImage == "Purchased" )
		{
			thumb.open();
		}
		else
		{
			/*B*/ stockphoto.Burp.getCompSource[ doc_id ] = "gpk";
			stockphoto.DL.GetComp.GetAndOpenComp( filePath, "" );
		}
	}
	else
	{
		/*B*/ stockphoto.Burp.getCompSource[ doc_id ] = "gpk";
		stockphoto.DL.GetComp.GetAndOpenComp( filePath, "" );
	}

	/* in execEditComps() */ app.scheduleTask( "stockphoto.gpk3.execEditComps("+( doc_id )+","+( idx+1 )+","+( ied )+");", 10, false );
}
stockphoto.gpk3.KWSpiningWheel=function( doc_id, bOnOff, bScheduled, fromWhere /* see stockphoto.gpk3.KWSpiningWheel_xxx */ )
{
	if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
		return;
	if( ( fromWhere == stockphoto.gpk3.KWSpiningWheel_addToCart )||
		( fromWhere == stockphoto.gpk3.KWSpiningWheel_downloadComp )||
		( fromWhere == stockphoto.gpk3.KWSpiningWheel_editComp ) )
	{
		stockphoto.gpk3.showSpinnerDialog( doc_id );
	}
	if( bScheduled )
	{
		if( stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
		{
			if( bOnOff )
			{
				stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.execJS( 'KWSpiningWheel( "1" );' );
			}
			else 
			{
				stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.execJS( 'KWSpiningWheel( "0" );' );
				stockphoto.gpk3.hideSpinnerDialog( doc_id );
			}
		}
	}
	else
	{
		if( stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
			/* KWSpiningWheel */ app.scheduleTask( 'stockphoto.gpk3.KWSpiningWheel('+doc_id+','+bOnOff+','+true+','+fromWhere+');', 10, false );
	}			

}
stockphoto.gpk3.setArguments=function( docIdStr )
{
	var i, Bt, args={};
	var a=docIdStr.split(',');
	for( i=0; i<a.length; i++ )
	{
		e=(a[i]).split("=");
		if( e.length > 1 )
		{
			Bt = ( e[1] ).charAt(0);
			if( ( Bt =='"' )||( Bt =="'" ) )
			     args[ e[0] ] = ( e[1] ).substr( 1, (e[1]).length-2 );
			else args[ e[0] ] = stockphoto.core.util.convertToInteger( e[1] );
		}
	}
	return( args );
}
stockphoto.gpk3.jsCallbacks =
{
			_gpk3debug_Write: function( dbgStrIn )
			{
				var z;
				z = unescape( dbgStrIn );
				if( stockphoto.gpk3debug.logFile != undefined )
				{
					stockphoto.gpk3debug.write2LogFile( z );
				}
			},
	/*B*/	_burpUrl_omitBurpUrl: function()
	/*B*/	{
	/*B*/		stockphoto.Burp.omitUrl = false;
	/*B*/ 	},
	// ------------------------------------
	_cbimgDetail_ChangeDisplayImage: function( DocIDString_i_And_BackOrNext_tabNo )
	{	// Ret.doc_id, Ret.str=index+","+n n:0=back n:1=next
		var Ret = stockphoto.HTMLUtil.GetDocIDFromHTMLString( DocIDString_i_And_BackOrNext_tabNo, "_cbimgDetail_ChangeDisplayImage" );
		var String_i_And_BackOrNext_tabNo = Ret.str;
		var k = String_i_And_BackOrNext_tabNo.indexOf( ',' ); // gurantee k>=0
		var i = parseInt( String_i_And_BackOrNext_tabNo.substring( 0, k ) );
		var doc_id  = Ret.doc_id, idx;
		var bRetIdx = i;
		
		//<Boxcar 4> - the BC3 code assumed that the pane is pane1 always.The tab no is also passed to the function to decide whether it is pane1 or pane3
		var iIndexForTab = String_i_And_BackOrNext_tabNo.indexOf( ';' );
		var sTabNo = String_i_And_BackOrNext_tabNo.substring( iIndexForTab + 1,  String_i_And_BackOrNext_tabNo.length)
		
		stockphoto.gpk3.gpk3Dt[ doc_id ].tabNo = sTabNo; // It can be Get Price tab or Privider tab
		if( Ret.str.charAt( k+1 ) == "1" )
		{	// Next
			idx = i + 1;
			if( idx < stockphoto.gpk3.gpk3Dt[ doc_id ].no )
			{
				stockphoto.gpk3.gpk3Dt[ doc_id ].idx = idx;
				if( ( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status & stockphoto.gpk3.gpk3_compSkipped ) != 0 )
				{
					stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status = stockphoto.gpk3.gpk3_start;
					stockphoto.gpk3.scheduledTask( doc_id, 'stockphoto.gpk3.gpk3SetEachImgWithDownloadComp('+doc_id+','+idx+');' );
				}
				stockphoto.gpk3.scheduledTask( doc_id, "stockphoto.gpk3.displayGpk3( "+doc_id+","+true+" );" );
				bRetIdx = idx;
			}
		}
		else
		{	// Back
			idx = i - 1;
			if( idx >= 0 )
			{
				stockphoto.gpk3.gpk3Dt[ doc_id ].idx = idx;
				if( ( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status & stockphoto.gpk3.gpk3_compSkipped ) != 0 )
				{
					stockphoto.gpk3.scheduledTask( doc_id, 'stockphoto.gpk3.gpk3SetEachImgWithDownloadComp('+doc_id+','+idx+');' );
					stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ].status = stockphoto.gpk3.gpk3_start;
				}
				stockphoto.gpk3.scheduledTask( doc_id, "stockphoto.gpk3.displayGpk3( "+doc_id+","+false+" );" );
				bRetIdx = idx;
			}
		}
		return( bRetIdx );
	},
	_cbimgDetail_getResDescription: function( DocIdString_i_And_ResIndex )
	{ 	// Ret.doc_id, Ret.str=index+","+Resolution index
		var Ret = stockphoto.HTMLUtil.GetDocIDFromHTMLString( DocIdString_i_And_ResIndex, "_cbimgDetail_getResDescription" );
		var String_i_And_ResIndex = Ret.str;
		var k = String_i_And_ResIndex.indexOf( ',' ); // gurantee k>=0
		var i = parseInt( String_i_And_ResIndex.substring(   0, k ) );
		var j = parseInt( String_i_And_ResIndex.substring( k+1, (String_i_And_ResIndex.length) ) );
		return( stockphoto.gpk3.gpk3Dt[ Ret.doc_id ].e[ i ].desc[ j ] );
	},
	_cbimgDetail_getNoOfReslutions: function( DocIdAndString_i )
	{ 	// Ret.doc_id, Ret.str=index
		var Ret = stockphoto.HTMLUtil.GetDocIDFromHTMLString( DocIdAndString_i, "_cbimgDetail_getNoOfReslutions" );
		var i   = parseInt( Ret.str );
		return( stockphoto.gpk3.gpk3Dt[ Ret.doc_id ].e[ i ].noResolution );
	},
	_cbimgDetail_getPrice: function( DocIdString_i_And_ResIndex )
	{ 	// Ret.doc_id, Ret.str=index+","+ResolutionIndex
		var Ret = stockphoto.HTMLUtil.GetDocIDFromHTMLString( DocIdString_i_And_ResIndex, "_cbimgDetail_getPrice" );
		var String_i_And_ResIndex = Ret.str;
		var k = String_i_And_ResIndex.indexOf( ',' ); // gurantee k>=0
		var i = parseInt( String_i_And_ResIndex.substring(   0, k ) );
		var j = parseInt( String_i_And_ResIndex.substring( k+1, (String_i_And_ResIndex.length) ) );
		var p = stockphoto.gpk3.gpk3Dt[ Ret.doc_id ].e[ i ].price[ j ];
		return( p.toString() );
	},
	_cbimgDetail_badReslutionsFound: function( DocIdAndString_i )
	{	//returns 1 if Resultion file is missing or corrupted.
		//return 0 otherwise.
		var Ret = stockphoto.HTMLUtil.GetDocIDFromHTMLString( DocIdAndString_i, "_cbimgDetail_getNoOfReslutions" );
		var i   = parseInt( Ret.str );
		return( 0);  //We have not determine anything about the xml file

	},
	_cbimgDetail_getFileSize: function ( DocIdString_i_And_Index )
	{
		var Ret = stockphoto.HTMLUtil.GetDocIDFromHTMLString( DocIdString_i_And_Index, "_cbimgDetail_getFileSize" );
		var String_i_And_Index = Ret.str;
		var k = String_i_And_Index.indexOf( ',' ); // gurantee k>=0
		var i = parseInt( String_i_And_Index.substring( 0, k ) );
		return( "" );
	},
	_cbimgDetail_execAddToCart: function( DocIdString_i_And_ResIndex )
	{
		var Ret = stockphoto.HTMLUtil.GetDocIDFromHTMLString( DocIdString_i_And_ResIndex, "_cbimgDetail_execAddToCart" );
		var String_i_And_ResIndex = Ret.str;
		var k = String_i_And_ResIndex.indexOf( ',' ); // gurantee k>=0
		var i = parseInt( String_i_And_ResIndex.substring( 0, k ) );
		stockphoto.gpk3.KWSpiningWheel( Ret.doc_id, true, false, stockphoto.gpk3.KWSpiningWheel_addToCart );
		/* in _cbimgDetail_execAddToCart() */ app.scheduleTask( "stockphoto.gpk3.execAddToCart( "+Ret.doc_id+","+ i+",'"+ String_i_And_ResIndex+"',"+ k+");", 1500, false );
	},
	_cbimgDetail_execDownloadComp: function( DocIdAndString_i )
	{
		var Ret = stockphoto.HTMLUtil.GetDocIDFromHTMLString( DocIdAndString_i, "_cbimgDetail_execDownloadComp" );
		var i = parseInt( Ret.str );
		stockphoto.gpk3.KWSpiningWheel( Ret.doc_id, true, false, stockphoto.gpk3.KWSpiningWheel_downloadComp );
		/* in _cbimgDetail_execDownloadComp() */ app.scheduleTask( "stockphoto.gpk3.execDownloadCom("+( Ret.doc_id )+","+( i )+" );", 1500, false );
	},
	_cbsurveyBeep: function(value)
	{
	app.beep();
	},
	_cbimgDetail_execViewShoppingCart: function( DocIdAndString_i )
	{
		var Ret = stockphoto.HTMLUtil.GetDocIDFromHTMLString( DocIdAndString_i, "_cbimgDetail_execViewShoppingCart" );
		/* in _cbimgDetail_execViewShoppingCart() */ app.scheduleTask( "stockphoto.DL.ShoppingCart.ShoppingCartX("+(Ret.doc_id)+");", 10, false );
	},
	_cbimgDetail_execPrint: function( DocIdAndString_i )
	{
		var Ret = stockphoto.HTMLUtil.GetDocIDFromHTMLString( DocIdAndString_i, "_cbimgDetail_execPrint" );
		/* in _cbimgDetail_execPrint() */ app.scheduleTask( "stockphoto.gpk3.gpk3Sys["+ (Ret.doc_id) +"].dialog.print()", 10, false); // standard all.schedule
	},

	_cbNav_RunHelpFile: function(iii)
	{
        stockphoto.DL.MiscDlgs.HelpTopic( stockphoto.core.helpTopicBase );
    },

	// ------------------------------------
	_gpk3_addAllTmgToCart: function( docIdStr )
	{
		var args = stockphoto.gpk3.setArguments( docIdStr );
		stockphoto.gpk3.KWSpiningWheel( args.doc_id, true, false, stockphoto.gpk3.KWSpiningWheel_addToCart );
	    /* in _gpk3_addAllTmgToCart() */ app.scheduleTask( "stockphoto.gpk3.execAddToCart("+args.doc_id+","+(-1)+",'00000',"+0+");", 1500, false );
	},
	_gpk3_search: function( docIdStr )
	{	// gpk will be close by him
		var args = stockphoto.gpk3.setArguments( docIdStr );
		if (args.ky == "") 
		{
			stockphoto.DL.generalAlertBox(stockphoto.imgDetail.zc.get("$$$/ImageDetail/Error/NoKeywords=No keywords selected."), 1);
			return;
		}
		var script = 'stockphoto.DL.search.basicSearchFromES( "'+args.ky+'","'+args.ky+'",'+args.doc_id+',"");';
/*B*/	stockphoto.Burp.searchFrom[ args.doc_id ] = "gpk";
		/* in _gpk3_search() */ app.scheduleTask( script,10, false ); // standard app.schedule
	},
	_gpk3_downloadAllComp: function( docIdStr )
	{
		var args = stockphoto.gpk3.setArguments( docIdStr );
		stockphoto.gpk3.KWSpiningWheel( args.doc_id, true, false, stockphoto.gpk3.KWSpiningWheel_downloadComp );
		/*B*/ stockphoto.Burp.cleanGClistAtGpkEnd( args.doc_id, false );
		/*B*/ stockphoto.Burp.getCompSource[ args.doc_id ] = stockphoto.imgDetail.key_Gpk; // _gpk3_downloadAllComp
		/*B*/ stockphoto.Burp.updateGClist( app.document, stockphoto.imgDetail.key_Gpk );
		/* in _gpk3_downloadAllComp() */ app.scheduleTask( 'stockphoto.DL.GetComp.KeepComp('+args.doc_id+');', 1500, false );
	},
	_gpk3_execEditComps: function( docIdStr )
	{
		var i, k, args = stockphoto.gpk3.setArguments( docIdStr ); // type=0 idx=n
		stockphoto.gpk3.KWSpiningWheel( args.doc_id, true, false, stockphoto.gpk3.KWSpiningWheel_editComp );
		if (args.selectedIndex == undefined)
		{
			stockphoto.core.openWith.selectedIndex[args.doc_id] = -1;
		}
		else
		{
			stockphoto.core.openWith.selectedIndex[args.doc_id] = args.selectedIndex;
		}
		if( stockphoto.core.checkDblClick.doc[ args.doc_id ] == undefined )
		{
			stockphoto.core.checkDblClick.doc[ args.doc_id ]              = {};
			stockphoto.core.checkDblClick.doc[ args.doc_id ].editCompList = [];
		//	stockphoto.core.checkDblClick.doc[ args.doc_id ].selList      = [];
			stockphoto.core.checkDblClick.doc[ args.doc_id ].selListNo    = 0;
		}
		for( i=args.ist, k=0; i<=args.ied; i++, k++ )
		{
			stockphoto.core.checkDblClick.doc[ args.doc_id ].editCompList[ k ] = unescape( stockphoto.core.util.getBaseName( stockphoto.core.util.getDisplayPath( stockphoto.gpk3.gpk3Dt[ args.doc_id ].e[ i ].sel, "_gpk3_execEditComps()" ) ) );
		}
		stockphoto.core.checkDblClick.doc[ args.doc_id ].editCompListNo     = k
		stockphoto.core.checkDblClick.doc[ args.doc_id ].editCompListProced = 0;
		/* in _gpk3_execEditComps() */ app.scheduleTask( "stockphoto.gpk3.execEditComps("+( args.doc_id )+","+( args.ist )+","+( args.ied )+");", 1500, false );
	},
	// ------------------------------------
	_gpk3_startBackGround: function( docIdStr )
	{
		var i, iMax, bRet, args=stockphoto.gpk3.setArguments( docIdStr );
//		if( ( stockphoto.gpk3.gpk3_dtType & 32 ) != 0 )
			stockphoto.gpk3.HideWheelFromES( args.doc_id );
		stockphoto.gpk3.gpk3Dt[ args.doc_id ].noOfSortedKeys = args.nKeys + args.nKeys;
		iMax = stockphoto.gpk3.gpk3Dt[ args.doc_id ].no;
		if( iMax > 5 )
			iMax = 5;
		
		for( i=0; ((i<iMax)&&(i<stockphoto.gpk3.gpk3Dt[ args.doc_id ].no)); i++ )
		{
			// data set
			bRet = stockphoto.gpk3.setupSlot( args.doc_id, i );
			if( bRet <= 0 )
			{
				; // already sendStatusReport() & stockphoto.gpk3.sendDisplayImageInfo() are called
			}
			else if( ( i == 0 )||( bRet != 1 ) )
			{
				stockphoto.gpk3.scheduledTask( args.doc_id, 'stockphoto.gpk3.gpk3SetEachImgWithKeywordandResolution('+ args.doc_id +','+ i +','+true+');' );
			}
			else
			{	// jpg file
				stockphoto.gpk3.scheduledTask( args.doc_id, 'stockphoto.gpk3.gpk3SetEachImgWithKeywordandResolution('+ args.doc_id +','+ i +','+false+');' );			
			}
		}
		if( i < stockphoto.gpk3.gpk3Dt[ args.doc_id ].no )
		{
			stockphoto.gpk3.scheduledTask( args.doc_id, 'stockphoto.gpk3.startUpTask('+ args.doc_id +','+ i +');' );
		}
	},
		
		_burp_viewProviderTab: function ( docIdStr )
	{
		var args=stockphoto.gpk3.setArguments( docIdStr );
		
		if ((args != undefined) && (args.doc_id != undefined)) // we check this here because the receiving function doesnt do this check
		{
			//sending the eventtype, mediaId and provider name to the Burp classes
			/*B*/ stockphoto.Burp.viewProviderTabReport( args.doc_id, args.type,args.partnerName,args.mid );
		}
		var bRetShowSurvey;
		if (stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_Preference ))
		{
			stockphoto.prefs.incrementProviderTabCount();
			// if the Survey is submitted check will go here once survey back end is ready
			if (stockphoto.core.survey.GPK.showSurvey == false)
			{
				bRetShowSurvey = false;
			}
			else
			{
				var iProviderCount = stockphoto.prefs.getProviderTabCount();
				var bMaxCountCheck;
				
				if (stockphoto.core.survey.GPK.maxCount == -1)
				{
					bMaxCountCheck = false;
				}
				else
				{
					bMaxCountCheck = true;
				}
				
				if (iProviderCount >= stockphoto.core.survey.GPK.minCount)
				{
					if (bMaxCountCheck == false)
					{
						bRetShowSurvey = true;
					}
					else if (bMaxCountCheck == true)
					{
						if (iProviderCount <= (stockphoto.core.survey.GPK.minCount + stockphoto.core.survey.GPK.maxCount))
						{
							bRetShowSurvey = true;
						}
						else
						{
							bRetShowSurvey = false;
						}
					}
				}
				else
				{
					bRetShowSurvey = false;
				}
			}
		}
		return bRetShowSurvey;
	},
	_gpk3_submitSurvey: function( docIdStr )
	{
		var args=stockphoto.gpk3.setArguments( docIdStr );

		if ((args != undefined) && (args.doc_id != undefined))
		{
            stockphoto.prefs.setSurveySubmitted(1);
            stockphoto.core.survey.GPK.showSurvey = false;
            
			//send the ansIndex and ans string to the Burp classes
			/*B*/
			/*B*/ stockphoto.Burp.submitSurveyReport( args.doc_id, "GPKSurvey", args.partnerName, args.mid,  
                        stockphoto.prefs.getProviderTabCount(), args.ansIndex, args.ans );
			/*B*/
			/*B*/
		}
		
	},
	// ------------------------------------
	_gpk3_closeDialog: function( docIdStr )
	{
		var args=stockphoto.gpk3.setArguments( docIdStr );
		
		if ((args != undefined) && (args.doc_id != undefined)
            && (stockphoto.gpk3.gpk3Sys != undefined)
            && (stockphoto.gpk3.gpk3Sys[ args.doc_id ] != undefined)
            && (stockphoto.gpk3.gpk3Sys[ args.doc_id ].bdialog == true))
		{
			stockphoto.gpk3.gpk3Sys[ args.doc_id ].dialog.closing = true;
			stockphoto.gpk3.gpk3Sys[ args.doc_id ].bdialog		  = false;
		}
	},
	doClose: function() 
	{   
		if ((stockphoto.gpk3.gpk3Sys != undefined)
            && (stockphoto.gpk3.gpk3Sys[ app.document.id ] != undefined))
		{
            stockphoto.gpk3.gpk3Sys[ app.document.id ].bdialog = false; 
        }
		return true; 
	},
	willClose: function() 
	{ 
		if ((stockphoto.gpk3.gpk3Sys != undefined)
            && (stockphoto.gpk3.gpk3Sys[ app.document.id ] != undefined))
		{
		  stockphoto.gpk3.gpk3Sys[ app.document.id ].bdialog = false; 
		}
		return true; 
	}
}

// -------------------------------------------------------- getPrice3
		stockphoto.gpk3.initDtTab=function( doc_id )
		{
			var idxMax    = stockphoto.gpk3.gpk3Dt[ doc_id ].no;
			var ini_iPath = "../images/spacer.gif";
			var i, lines="";
			for( i=1; i<=idxMax; i++ )
			{
				lines += ( '\011\011{status:0, p1status:-1, dttype:'+stockphoto.gpk3.gpk3_dtType+', timeOut:0, imgType:0, dispType:0, MediaTitle:"", PartnerName:"", MediaID:"",RefID:"", keyWords:"", '
						 + 'iPath:"'+( ini_iPath )+'", iHeight:0, iWidth:0, iFname:"", prevDisp:""'
						 + '}' );
				if( i != idxMax )
					lines += ",\n";
			}
			return( lines );
		}
		stockphoto.gpk3.initImgData=function( doc_id )
		{
			var brd, m, pw, ph, iw, ih, ns, i, j, jj, k, kMax, ln, srcFile, txtcol, txtwd, txtfamily, txtsize, eee;
			m  = stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.m;
			pw = stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.pw;
			ph = stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.ph;
			iw = stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.iw;
			ih = stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.ih;
			ns = m + m - 1
			txtcol    = "#333333";
			txtfamily = stockphoto.NavBar.zc.get(stockphoto.NavExtFnc.FontNames());
			txtsize   = "10px";
			th        = 10; // == txtsize
			if( ( stockphoto.gpk3.gpk3_dtType & 2 ) != 0 )
				 brd  = 1;
			else brd  = 0;
			kMax 	  = stockphoto.gpk3.gpk3Dt[ doc_id ].no;
			k    	  = 0;
			for( i=0; k<kMax; i++ )
			{
				if( i != 0 )
				{
					ln += '\n\011\011<tr id="tr_'+i+' name="tr_'+i+'" width="'+( pw-brd-brd )+'" height="'+( ih )+'">\n';
					if( ns > 1 )
						 ln += '\011\011\011<td style="visibility:hidden">\n';
					else ln += '\011\011\011<td style="visibility:hidden" colspan="'+ns+'">\n';
					ln += ( '\011\011\011\011<img id="trimg_'+i+'" name="trimg_'+i+'" src="../images/spacer.gif" '
						  + 'height="'+( ih )+'" width="'+( pw-brd-brd )+'">\n'+'\011\011\011</td>\n\011\011</tr>\n\n\011\011<tr>\n' );
				}
				else
				{
					ln = '\n\011\011<tr>\n';
				}
				for( j=0; j<( m ); j++ )
				{
					if( j != 0 )
					{
						ln += ( '\011\011\011<td style="visibility:hidden">\n\011\011\011\011<img src="../images/spacer.gif"  id="tdspace_'+k
							  + '" name="tdspce_'+( k )+'" height="'+( ph )+'" width="'+( iw-brd-brd )+'">\n\011\011\011</td>\n' );
					}
					srcFile = "../images/spacer.gif";
					eee	= '\011\011\011<td id="td_'+( k )+'" name="td_'+( k )+'">\n\011\011\011\011<table border="'+brd
						+ '" cellspacing="0" cellpadding="0" id="tdtab_'+( k )+'" name="tdtab_'+( k )+'" width="'+( pw-brd-brd )
						+ '" height="'+( ph )+'">\n\011\011\011\011\011<tr>\n'
						+ '\011\011\011\011\011\011<td>\n\011\011\011\011\011\011\011'
						+ '<img src="../images/spacer.gif" id="tdimgsp_'+( k )+'" name="tdimgsp_'+( k )+'" width="'+( pw-brd-brd )+'" height="'+1+'">\n'
						+ '\011\011\011\011\011\011</td>\n\011\011\011\011\011</tr>\n\011\011\011\011\011<tr>\n'
						+ '\011\011\011\011\011\011<td align="center">\n\011\011\011\011\011\011\011<img align="center" valign="bottom" usemap="#mtdimg_'+k
						+ '" src="'+srcFile+'" width="'+( pw-brd-brd )+'" height="'+( ph-th )
						+ '" id="tdimg_'+( k )+'" name="tdimg_'+( k )+'">\n\011\011\011\011\011\011\011<map name="mtdimg_'+( k )+'">\n'
						+ '\011\011\011\011\011\011\011\011<area share="rect" coords="0,0,'+(pw)+','+(ph)+'" nohref onClick=multiImgSel('+( k )+')>\n'
						+ '\011\011\011\011\011\011\011</map>\n\011\011\011\011\011\011</td>\n\011\011\011\011\011</tr>\n'
						+ '\011\011\011\011\011<tr>\n\011\011\011\011\011\011<td>\n\011\011\011\011\011\011\011<table width='+( pw-2 )+'>\n'
						+ '\011\011\011\011\011\011\011\011<tr>\n\011\011\011\011\011\011\011\011\011<td width='+( pw-2 )+' nowrap>\n'
						+ '\011\011\011\011\011\011\011\011\011\011<div id="tdtxt_'+k
						+ '" style="color:'+( txtcol )+'; width:'+( pw-brd-brd )+'px; visibility:hidden; font-family:'+( txtfamily )
						+ ';font-size:'+( txtsize )+'; font-weight:bold; align:center"><center><a id="txtwd_a_'+( k )+'">...</a>'
						+ '</center></div>\n\011\011\011\011\011\011\011\011\011</td>\n\011\011\011\011\011\011\011\011</tr>\n'
						+ '\011\011\011\011\011\011\011</table>\n\011\011\011\011\011\011</td>\n'
						+ '\011\011\011\011\011</tr>\n\011\011\011\011</table>\n\011\011\011</td>\n';
					ln += eee;
					k++;
				} // for( j=0; j<( m ); j++ )
				ln += '\n\011\011</tr>\n';
			} // for( i=0; ((i<( m ))&&(k<kMax)); i++ )
			return( ln );
		}
		stockphoto.gpk3.displayGpk3=function( doc_id, bProcNext )
		{	// set stockphoto.gpk3.gpk3Dt[ doc_id ].idx in advance
			// Must be set Htm's variables that were set previously
			//		var glbcnst_index     =%_IINDEX%_;
			//		<img src="%_DetailImg%_" alt="" border="0" id="JPGImg" name="JPGImg" style="visibility:hidden" %_DetailImgWidth%_ %_DetailImgHeight%_>
			var doc_id, idx, sPath, eObj;
			if( ! stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
				return;
			idx   = stockphoto.gpk3.gpk3Dt[ doc_id ].idx;
			eObj = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx ];
			sPath = eObj.sPath;

			var inCompFolder = stockphoto.core.menu.isInFolderHierarchy(eObj.sel, stockphoto.places.comps);
			var inPurchasedFolder = stockphoto.core.menu.isInFolderHierarchy(eObj.sel, stockphoto.places.purchases);
			
			var inPreviousSearchFolder = stockphoto.core.menu.isInFolderHierarchy(eObj.sel, stockphoto.places.recentSearches); 
			
			var isThumbnail = false;
			
			if ("undefined" != typeof(eObj) && undefined != eObj.xmp && undefined != eObj.xmp.KindOfImage)
			{
				isThumbnail = ("Thumbnail" == eObj.xmp.KindOfImage);
			}

			var s   = stockphoto.gpk3.setupImgDisp( doc_id, idx );
			var ss	= 'nglb_correctIdx={idx:'+idx
					+ ',imgType:'    +eObj.imgType
					+ ',dispType:'   +eObj.dispType
					+ ',iPath:"'     +s.iPath +'"'  // escaped
					+ ',iHeight:'    +s.iHeight
					+ ',iWidth:'     +s.iWidth
					+ ',iFname:"'    +s.iFname +'"' // escaped
					+ ',container:"' +escape( stockphoto.gpk3.gpk3Dt[ doc_id ].contNo )+'"'
					+ ',tableNo:"'   +escape( stockphoto.gpk3.gpk3Dt[ doc_id ].tabNo )+'"'
					+ ',inCompFolder:' +inCompFolder
					+ ',inPurchasedFolder:' +inPurchasedFolder 
					+ ',inPreviousSearchFolder:' +inPreviousSearchFolder
					+ ',isThumbnail:' +isThumbnail + '};'; 
			if( stockphoto.gpk3debug.logFile != undefined )
			{
				stockphoto.gpk3debug.rec = '\nfrom_ ... nglb_correctIdx={idx:'+idx
					+ ',imgType:'    +eObj.imgType
					+ ',dispType:'   +eObj.dispType
					+ ',iPath:"'     +s.iPath +'"'  // escaped
					+ ',iHeight:'    +s.iHeight
					+ ',iWidth:'     +s.iWidth
					+ ',iFname:"'    +s.iFname +'"' // escaped
					+ ',container:"' +escape( stockphoto.gpk3.gpk3Dt[ doc_id ].contNo )+'"'
					+ ',tableNo:"'   +stockphoto.gpk3.gpk3Dt[ doc_id ].tabNo+'"'
					+ ',inCompFolder:' +inCompFolder
					+ ',inPurchasedFolder:' +inPurchasedFolder 
					+ ',inPreviousSearchFolder:' +inPreviousSearchFolder
					+ ',isThumbnail:' +isThumbnail + '};' +'\n-----\n\n';
				stockphoto.gpk3debug.write2LogFile( stockphoto.gpk3debug.rec );
			}
			script  = "correctIdx( '"+( escape( ss ) )+"' );";
			try
			{
				if( stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog )
					stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.execJS( script );
			} catch(e) {;}
			if( bProcNext )
			{
				var idx1 = idx + 1;
				if( ( idx1 < stockphoto.gpk3.gpk3Dt[ doc_id ].no )&&
					( ( stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx1 ].status & stockphoto.gpk3.gpk3_compSkipped ) != 0 ) )
				{
					stockphoto.gpk3.gpk3Dt[ doc_id ].e[ idx1 ].status = stockphoto.gpk3.gpk3_start;
					stockphoto.gpk3.scheduledTask( doc_id, 'stockphoto.gpk3.gpk3SetEachImgWithDownloadComp('+doc_id+','+idx1+');' );
				}
			}
		}
stockphoto.gpk3.setStyleSheet=function( doc_id )
{
	if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_NavBar ) )
	{
		var stylesheet = File( stockphoto.core.folder.getTempFolder()+"/"+stockphoto.core.CurrentProcessID+"/stockphoto.css" );
		if( ! stylesheet.exists )
			stockphoto.NavExtFnc.CreateStyleSheet( doc_id );
		return( true );
	}
	return( false );
}
// If the OpenWith Array has no elements, then the "Open with..." text in the Image detail button should become "Edit" and it should open with default application
stockphoto.gpk3.getOpenWithString = function()
{

	if (0 == stockphoto.core.openWith.noShow )
	{
		return "$$$/ImageDetail/Dialog_Button/EditComp=Edit";
	}
	else
	{
		return "$$$/ImageDetail/Dialog/OpenWith=Open With...";
	}
}
stockphoto.gpk3.getPrice3Primary=function( doc_id, contNo /* container1 */, tabNo /* pane1/pane2 */, ThumbArray )
{
	var i, ii, doc, sFs, sPath, tmpPath;
	if (stockphoto.NavBar.zcSearch != undefined)
	{
		delete stockphoto.NavBar.zcSearch;
	}
	stockphoto.NavBar.zcSearch       = new stockphoto.zstringCache( stockphoto.core.zstringFiles.NavBar, stockphoto.core.getASPSearchLangLocale() );
	stockphoto.NavBar.zcSearch.dict  = stockphoto.core.zstringFiles.NavBar + '.txt';

	doc = stockphoto.NavExtFnc.FromDocIdToDoc( doc_id );
	if( doc == undefined )
		return( false );

	/*B*/ stockphoto.Burp.updateGClist( doc, "bg" );

	if(	( ! stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_GetComp  ) )||
		( ! stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_HTMUtil  ) )||
		( ! stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_AlertBox ) )||
		( ! stockphoto.DL.LoadBasicSearchAndPreference() ) )
	{
		return( false );
	}

	stockphoto.gpk3.tempFolder     = stockphoto.core.folder.getTempFolder();
	stockphoto.gpk3.BMtempFolder   = stockphoto.gpk3.tempFolder+"/"+stockphoto.core.CurrentProcessID;
	stockphoto.gpk3.BMtempFolderFs = new Folder( stockphoto.gpk3.BMtempFolder );
	stockphoto.gpk3.szNA           = stockphoto.imgDetail.zc.get( "$$$/ImageDetail/Error/NotAvailable=N/A" );

	// Dispatch the preparation thread
	if( stockphoto.gpk3.gpk3Sys[ doc_id ] == undefined )
	{
		stockphoto.gpk3.gpk3Sys[ doc_id ] = { bdialog:false, scheN:0, sche:[] };
	}
	else
	{
		stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog = false;
		stockphoto.gpk3.gpk3Sys[ doc_id ].scheN   = 0;
		stockphoto.gpk3.gpk3Sys[ doc_id ].sche    = [];
	}
	if( stockphoto.gpk3.gpk3Dt[  doc_id ] == undefined )
	{
		stockphoto.gpk3.gpk3Dt[  doc_id ] = { isw:true, no:0, e:[], contNo:"container1", tabNo:"pane1" };
	}
	else
	{
		stockphoto.gpk3.gpk3Dt[  doc_id ].isw    = true;
		stockphoto.gpk3.gpk3Dt[  doc_id ].no     = 0;
		stockphoto.gpk3.gpk3Dt[  doc_id ].e      = [];
		stockphoto.gpk3.gpk3Dt[  doc_id ].contNo = "container1";
		stockphoto.gpk3.gpk3Dt[  doc_id ].tabNo  = "pane1";
	}

	// container/tab
	if( ( contNo != undefined )&&( contNo != "" ) )
	{
		stockphoto.gpk3.gpk3Dt[ doc_id ].contNo = contNo;
	}
	if( ( tabNo != undefined )&&( tabNo != "" ) )
	{
		stockphoto.gpk3.gpk3Dt[ doc_id ].tabNo = tabNo;
	}

	// Initialize for histogram
	stockphoto.gpk3.gpk3Dt[  doc_id ].maxOccurence = 0;
	stockphoto.gpk3.gpk3Dt[  doc_id ].c1           = [];

	// KeyByFreq table
	stockphoto.gpk3.gpk3Dt[  doc_id ].keyByFreq    = [];
	stockphoto.gpk3.gpk3Dt[  doc_id ].keyByFreqNo  = 0;
	stockphoto.gpk3.gpk3Dt[  doc_id ].keyProcessed = 0;

	for( i=0, ii=0; ii<ThumbArray.length; ii++ )
	{
	    //Watson: 1338257
	    //If selected image is a container or is not an ASP image, then do not add it to GPK window
		if( ("undefined" == typeof ThumbArray[ ii ]) || (ThumbArray[ ii ].container ) || !(stockphoto.core.util.isBMImageFile(ThumbArray[ ii ])))
			continue;
		// define object
		// Workaround for Bridge 316 -BEGIN-
		tmpPath = stockphoto.core.util.fixPathName( ThumbArray[ ii ].path );

        // Handle VersionCue files different. We need to use Thumbnail.spec.fsName, and use app.acquirePhysicalFiles
        // (as discussed with the VersionCue team)
        if ( ("VersionCue" == ThumbArray[ ii ].location) && ("undefined" != typeof ThumbArray[ ii ].spec)
                    && ("undefined" != typeof ThumbArray[ ii ].spec.fsName) )
        {
            var arVCThumbs = [ ThumbArray[ ii ] ];
            app.acquirePhysicalFiles(arVCThumbs);
            tmpPath = ThumbArray[ ii ].spec.fsName;
        }

		// Workaround for Bridge 316 -END-
		stockphoto.gpk3.gpk3Dt[ doc_id ].e[ i ]  = {
			sel          : ThumbArray[ ii ],        // Thumbnail object
			sPath        : tmpPath,
			sFs          : new File( tmpPath ),
			sFname       : "",
			aPath        : undefined,
			aHeight      : 0,
			aWidth       : 0,
			cPath        : "",
			xmp          : undefined,
			imgType      : 0, // bRet == 1 ... .jpg file with xmp, retval.imagePath = selPath
					  //	  == 2|6 . file w/ xmp, retval.imagePath = local "ImgNotAvailBig.jpg" path
					  //      == 8 ... remote Version Cue file
			dispType     : 0, // == 1 ... not Comp yet
					  // == 2 ... Comp
			status       : stockphoto.gpk3.gpk3_start, // status = start
			noResolution : 0,
			purchaseID   : [],
			desc         : [],
			price        : [],
			MediaTitle   : "N/A",
			PartnerName  : "N/A",
			SearchKey    : []
		}
		i++;
	}
	if( i <= 0 )
	{
		stockphoto.gpk3.getPrice3fin( doc_id );
		return( false );
	}
	stockphoto.gpk3.gpk3Dt[ doc_id ].no  = i;
	stockphoto.gpk3.gpk3Dt[ doc_id ].idx = 0;

	stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz = {};
	if( stockphoto.gpk3.gpk3Dt[ doc_id ].no <= 1 )
	{
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.m  = 1;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.pw = 458;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.ph = 411;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.iw = 0;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.ih = 0;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.cx = 62;
	}
	else if( ( stockphoto.gpk3.gpk3Dt[ doc_id ].no <= 4 )&&
			 ( ( stockphoto.gpk3.gpk3_dtType & 8 ) != 0 ) )
	{
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.m  = 2;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.pw = 216;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.ph = 206;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.iw = 26;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.ih = 21;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.cx = 29;
	}
	else
	{
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.m  = 3;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.pw = 117;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.ph = 117;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.iw = 26;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.ih = 21;
		stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.cx = 16;
	}

	// at the end to update no. of dialogs
	if( doc_id >= stockphoto.gpk3.gpk3No )
		stockphoto.gpk3.gpk3No = doc_id + 1;

	// set up for Conversion table
	var iDocID   = doc_id + 30000;
	var strDocID = "5"+iDocID; // i.e. "it is "53xxxx"

	with (stockphoto.imgDetail)
	{
		stockphoto.gpk3.CnvTab  = {

			NEWGPK            :"gpk",

			CONTAINERNUMBER	 : stockphoto.gpk3.gpk3Dt[  doc_id ].contNo,
			TABNUMBER         : stockphoto.gpk3.gpk3Dt[  doc_id ].tabNo,
			PRIMARYFONT       : stockphoto.NavBar.zc.get( stockphoto.NavExtFnc.FontNames() ),
			OP_AND            : stockphoto.NavBar.zcSearch.get( "$$$/NavBar/Operations/OP_AND=AND" ),
			CONSTDOC_ID       : doc_id,

			MAXNOOFIMG        : stockphoto.gpk3.gpk3Dt[ doc_id ].no,
			function_SetDt    : "stockphoto.gpk3.initDtTab",
			function_SetImgs  : "stockphoto.gpk3.initImgData",

			MEDIAIDDATA       : "",
			SEARCHKEYWORDDATA : "",

			DOCUMENTID        :strDocID.substr( 2,4 ), // DocumentID must be 4 characters long
			TOTALINDEX        :( stockphoto.gpk3.gpk3Dt[ doc_id ].no ).toString(),
			CLOSEBUTTON       :zc.get("$$$/ImageDetail/Dialog_Button/Close=Close"),
			SEARCHAGAIN       :zc.get("$$$/ImageDetail/Dialog_Button/SearchAgain=Search Again"),
			PRICELBL          :zc.get("$$$/ImageDetail/Dialog/Price=Price"),
			FileResText       :zc.get("$$$/ImageDetail/Dialog/FileSizeRes=Size/Resolution"),
			ProviderText      :zc.get("$$$/ImageDetail/Dialog/Provider=Provider") + ":",
			ProviderTag		  :zc.get("$$$/ImageDetail/Dialog/Provider=Provider"),
			TitleText         :zc.get("$$$/ImageDetail/Dialog/Title=Title:"),

			ImageIDText       :zc.get("$$$/ImageDetail/Dialog/ImageID=Image ID:"),
			DESCRIPTION       :zc.get("$$$/ImageDetail/Dialog/Description=Description:"),
			ADDTOCARTBUTTON   :zc.get("$$$/ImageDetail/Dialog_Button/AddToCart=Add To Cart"),
			DOWNLOADCOMPBUTTON:zc.get("$$$/ImageDetail/Dialog_Button/DownloadComp=Download Comp..."),
			EDITCOMPBUTTON    :zc.get("$$$/ImageDetail/Dialog_Button/EditComp=Edit"),
			_OF_              :zc.get("$$$/ImageDetail/Dialog/of= of "),
			CHIP_FONTSIZE     :zc.get("$$$/ImageDetail/Dialog/chipfont=10px"),
			CHIP_WIDTH        :zc.get("$$$/ImageDetail/Dialog/chipwidth=30"),
			PRINT_TIPS        :zc.get("$$$/ImageDetail/Dialog/printtip=Print"),
			DL_COMP_TIPS      :zc.get("$$$/ImageDetail/Dialog/dlcomptip=Download Comp..."),
			ADD_TO_CART       :zc.get("$$$/ImageDetail/Dialog/addToCarttip=Add To Cart"),
			SHOPPING_CART     :zc.get("$$$/ImageDetail/Dialog/shoppingCart=Shopping Cart"),
			HELP              :zc.get("$$$/ImageDetail/Dialog/Help=Help"),
			KEYWORDS          :zc.get("$$$/ImageDetail/Dialog/Keywords=Keywords"),
			FINDSIMILAR		  :zc.get("$$$/ImageDetail/Dialog/FindSimilar=Find Similar"),// constant added for Find Similar
			ABOUTTHISIMAGE    :zc.get("$$$/ImageDetail/Dialog/AboutThisImage=About this Image"),
			INLOADKEYWORDS    :zc.get("$$$/ImageDetail/Dialog/InLoadKeywords=Loading Keywords..."),
			REFERENCE		  :zc.get("$$$/ImageDetail/Dialog/Reference=Reference"),
			GETPRICES		  :zc.get("$$$/ImageDetail/Dialog/GetPrices=Get Prices"),
			SHOWPROVIDER	  :zc.get("$$$/ImageDetail/Dialog/ShowProvider=Show Image ID and Provider"),
			PROVIDERID		  :zc.get("$$$/ImageDetail/Dialog/ProiverId=Provider ID:"),
			CUSTOMERPOLL	  :zc.get("$$$/ImageDetail/Dialog/CustomerPoll=CUSTOMER QUICK POLL"),
			POLLQUESTION	  :zc.get("$$$/ImageDetail/Dialog/PollQuestion=Why do you need the provider information?"),
			POLLANS1		  :zc.get("$$$/ImageDetail/Dialog/PollAns1=To give to my art buyer"),
			POLLANS2		  :zc.get("$$$/ImageDetail/Dialog/PollAns2=To buy from the provider"),
			POLLANS3		  :zc.get("$$$/ImageDetail/Dialog/PollAns3=To buy from Adobe"),
			POLLANS4		  :zc.get("$$$/ImageDetail/Dialog/PollAns4=Other"),
			SUBMIT		  	  :zc.get("$$$/ImageDetail/Dialog/Submit=Submit"),
			OPENWITH		  :zc.get(stockphoto.gpk3.getOpenWithString()),
			GETPRICE		  :zc.get("$$$/ImageDetail/Dialog/GetPrice=Get Price"),
			VIEWKEYWORDS      :zc.get(stockphoto.imgDetail.zstr_viewKWds),
			NOTSUPPORTEDTEXT  :zc.get(stockphoto.imgDetail.zstr_NotSupported),
			
			OPENWITHARR		  :stockphoto.core.openWith.displayMenu.toSource(),
			
			OPENNOSHOW        :stockphoto.core.openWith.noShow,
			

			KEYWORDHELP       :zc.get(zstr_SelKey2),
			KeySubSelShared   :zc.get(zstr_SelKey3),
			KeySubSelWhole    :zc.get(zstr_SelKey4),

			IMGDEFAULTHEIGHT  : 411,
			IMGDEFAULTWIDTH   : 458,

			IMGADJ_M	 : stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.m,
			IMGADJ_PW : stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.pw,
			IMGADJ_PH : stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.ph,
			IMGADJ_IW : stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.iw,
			IMGADJ_IH : stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.ih,
			IMGADJ_CX : stockphoto.gpk3.gpk3Dt[ doc_id ].imgSz.cx
		};
		stockphoto.gpk3.CnvTab.STATE0TEXT        =stockphoto.alertBox.zc.get(stockphoto.alertBox.localizedStr4ErrMsg.MESSAGE_ES_TRYING);
		stockphoto.gpk3.CnvTab.ERRORINGETTINGIMGE=stockphoto.alertBox.zc.get(stockphoto.alertBox.localizedStr4ErrMsg.ERROR_WEBSERVICE_NOTFOUND);
		stockphoto.gpk3.CnvTab.ERRORINDWLDIMGE=stockphoto.alertBox.zc.get(stockphoto.alertBox.localizedStr4ErrMsg.ERROR_ADAPTER_DOWNLOAD_ERROR);		
		stockphoto.gpk3.CnvTab.INPROGRESSTEXT    =stockphoto.gpk3.CnvTab.STATE0TEXT; // Cause' we cann't have the same z-string key
	}

	stockphoto.core.util.loadLocaleData( "st17ImgDetail.par" );

	if( stockphoto.gpk3.gpk3Dt[ doc_id ].no <= 1 )
	{
		stockphoto.gpk3.CnvTab.IMAGE4SIZE_VIS = "visible";
		stockphoto.gpk3.CnvTab.KWIMAGEPRE_VIS = "hidden";
	}
	else
	{
		stockphoto.gpk3.CnvTab.IMAGE4SIZE_VIS = "hidden";
		stockphoto.gpk3.CnvTab.KWIMAGEPRE_VIS = "visible";
	}
	stockphoto.gpk3.CnvTab.KEYWORDSPRE_VIS = "visible";
	stockphoto.gpk3.CnvTab.KEYWORDS_VIS = "hidden";

	// fill the value for toolchip width/height if not in PAR file
	// This is cut-and-paste from line 1148, and it is used for the second dialog and after.
	if( stockphoto.gpk3.CnvTab.Print_N_width  == undefined ) stockphoto.gpk3.CnvTab.Print_N_width  =  50;
	if( stockphoto.gpk3.CnvTab.Print_N_height == undefined ) stockphoto.gpk3.CnvTab.Print_N_height =  10;
	if( stockphoto.gpk3.CnvTab.HELP_N_width   == undefined ) stockphoto.gpk3.CnvTab.HELP_N_width   =  50;
	if( stockphoto.gpk3.CnvTab.HELP_N_height  == undefined ) stockphoto.gpk3.CnvTab.HELP_N_height  =  10;
	if( stockphoto.gpk3.CnvTab.CART_N_width   == undefined ) stockphoto.gpk3.CnvTab.CART_N_width   =  100;
	if( stockphoto.gpk3.CnvTab.CART_N_height  == undefined ) stockphoto.gpk3.CnvTab.CART_N_height  =  10;
	if( stockphoto.gpk3.CnvTab.DL_COMP_width  == undefined ) stockphoto.gpk3.CnvTab.DL_COMP_width  =  135;
	if( stockphoto.gpk3.CnvTab.BUY_N_width    == undefined ) stockphoto.gpk3.CnvTab.BUY_N_width    =  90;

	if( stockphoto.gpk3.CnvTab.TAB_LEFTCAP_width   == undefined ) stockphoto.gpk3.CnvTab.TAB_LEFTCAP_width   = 19;
	if( stockphoto.gpk3.CnvTab.TAB_PRICE_width     == undefined ) stockphoto.gpk3.CnvTab.TAB_PRICE_width     = 50;
	if( stockphoto.gpk3.CnvTab.TAB_OVERLAP_width   == undefined ) stockphoto.gpk3.CnvTab.TAB_OVERLAP_width   = 24;
	if( stockphoto.gpk3.CnvTab.TAB_KEYWORKS_width  == undefined ) stockphoto.gpk3.CnvTab.TAB_KEYWORKS_width  = 70;
	if( stockphoto.gpk3.CnvTab.TAB_RIGHTCAP_width  == undefined ) stockphoto.gpk3.CnvTab.TAB_RIGHTCAP_width  = 26;
	if( stockphoto.gpk3.CnvTab.TAB_STOKE_width     == undefined ) stockphoto.gpk3.CnvTab.TAB_STOKE_width     =
		725 - stockphoto.gpk3.CnvTab.TAB_LEFTCAP_width - stockphoto.gpk3.CnvTab.TAB_PRICE_width - stockphoto.gpk3.CnvTab.TAB_OVERLAP_width -
		stockphoto.gpk3.CnvTab.TAB_KEYWORKS_width - stockphoto.gpk3.CnvTab.TAB_RIGHTCAP_width;
	if( stockphoto.gpk3.CnvTab.TITLE_NUM_CHAR      == undefined ) stockphoto.gpk3.CnvTab.TITLE_NUM_CHAR  = 32;
	if( stockphoto.gpk3.CnvTab.DESP_NUM_CHAR       == undefined ) stockphoto.gpk3.CnvTab.DESP_NUM_CHAR   = 60;
	if( stockphoto.gpk3.CnvTab.BUTTON_HEIGHT       == undefined ) stockphoto.gpk3.CnvTab.BUTTON_HEIGHT   = "22px";
	if( stockphoto.gpk3.CnvTab.BUTTON_FONTSIZE     == undefined ) stockphoto.gpk3.CnvTab.BUTTON_FONTSIZE = "11px";
	if( stockphoto.gpk3.CnvTab.OPENWITH_FONTSIZE   == undefined ) stockphoto.gpk3.CnvTab.OPENWITH_FONTSIZE= "11px";
	if( stockphoto.gpk3.CnvTab.ADDCART_WIDTH       == undefined ) stockphoto.gpk3.CnvTab.ADDCART_WIDTH   = "80";
	if( stockphoto.gpk3.CnvTab.DLCOMP_WIDTH        == undefined ) stockphoto.gpk3.CnvTab.DLCOMP_WIDTH    = "120";
	if( stockphoto.gpk3.CnvTab.EDCOMP_WIDTH        == undefined ) stockphoto.gpk3.CnvTab.EDCOMP_WIDTH    = "92";
	if( stockphoto.gpk3.CnvTab.CLOSEB_WIDTH        == undefined ) stockphoto.gpk3.CnvTab.CLOSEB_WIDTH    = "50";
	if( stockphoto.gpk3.CnvTab.SURVEYTEXTCOLS_PC   == undefined ) stockphoto.gpk3.CnvTab.SURVEYTEXTCOLS_PC = "30";
	if( stockphoto.gpk3.CnvTab.SURVEYTEXTCOLS_MAC  == undefined ) stockphoto.gpk3.CnvTab.SURVEYTEXTCOLS_MAC = "22";
	if( stockphoto.gpk3.CnvTab.OPENWITHLEFT_PC 	   == undefined ) stockphoto.gpk3.CnvTab.OPENWITHLEFT_PC = 370;
	if( stockphoto.gpk3.CnvTab.OPENWITHLEFT_MAC	   == undefined ) stockphoto.gpk3.CnvTab.OPENWITHLEFT_MAC = 375;
	if( stockphoto.gpk3.CnvTab.OPENWITHTOP_PC  	   == undefined ) stockphoto.gpk3.CnvTab.OPENWITHTOP_PC  = 540;
	if( stockphoto.gpk3.CnvTab.OPENWITHTOP_MAC 	   == undefined ) stockphoto.gpk3.CnvTab.OPENWITHTOP_MAC  = 540;
	if(stockphoto.isWin)
	{
			stockphoto.gpk3.CnvTab.SURVEYTEXTCOLS = stockphoto.gpk3.CnvTab.SURVEYTEXTCOLS_PC;
			stockphoto.gpk3.CnvTab.OPENWITHLEFT = stockphoto.gpk3.CnvTab.OPENWITHLEFT_PC;
			stockphoto.gpk3.CnvTab.OPENWITHTOP  = stockphoto.gpk3.CnvTab.OPENWITHTOP_PC;
	}
	else  // stockphoto.isMac
	{
			stockphoto.gpk3.CnvTab.SURVEYTEXTCOLS = stockphoto.gpk3.CnvTab.SURVEYTEXTCOLS_MAC;
			stockphoto.gpk3.CnvTab.OPENWITHLEFT = stockphoto.gpk3.CnvTab.OPENWITHLEFT_MAC;
			stockphoto.gpk3.CnvTab.OPENWITHTOP  = stockphoto.gpk3.CnvTab.OPENWITHTOP_MAC;
	}
	if( stockphoto.gpk3.CnvTab.TAB_FONT_Weight     == undefined ) stockphoto.gpk3.CnvTab.TAB_FONT_Weight  = "bold";
	if( stockphoto.gpk3.CnvTab.TAB_FONT_Size       == undefined ) stockphoto.gpk3.CnvTab.TAB_FONT_Size    = "11px";
	if( stockphoto.gpk3.CnvTab.TAB_FONT_Color      == undefined ) stockphoto.gpk3.CnvTab.TAB_FONT_Color   = "#666666";
	if( stockphoto.gpk3.CnvTab.TAB_HOVER_Color     == undefined ) stockphoto.gpk3.CnvTab.TAB_HOVER_Color  = "#000";

	if( stockphoto.gpk3.CnvTab.TAB_ACTIVE_FONT_Weight     == undefined ) stockphoto.gpk3.CnvTab.TAB_ACTIVE_FONT_Weight     = "bold";
	if( stockphoto.gpk3.CnvTab.TAB_ACTIVE_FONT_Size       == undefined ) stockphoto.gpk3.CnvTab.TAB_ACTIVE_FONT_Size       = "11px";
	if( stockphoto.gpk3.CnvTab.TAB_ACTIVE_FONT_Color      == undefined ) stockphoto.gpk3.CnvTab.TAB_ACTIVE_FONT_Color      = "#666666";
	if( stockphoto.gpk3.CnvTab.TAB_ACTIVE_HOVER_Color     == undefined ) stockphoto.gpk3.CnvTab.TAB_ACTIVE_HOVER_Color     = "#000";

	if( stockphoto.gpk3.CnvTab.TAB_KWLINK_FONT_Color      == undefined ) stockphoto.gpk3.CnvTab.TAB_KWLINK_FONT_Color   = "#027abb";

	// defult set to be the first image
	stockphoto.gpk3.CnvTab.IINDEX    = 0;
	stockphoto.gpk3.CnvTab.DetailImg = stockphoto.gpk3.gpk3Dt[ doc_id ].e[ 0 ].sPath;

	// Open the dialog / The rest of job will be passed to callback: _gpk3_startBackGround()
	if( stockphoto.DL.HTMLUtil.SubLocalHTMLbyDocID( stockphoto.core.folder.getTemplateFolder() + "/st17ImgDetail.htm",
													stockphoto.gpk3.CnvTab, "gpk3_"+doc_id+".htm", doc_id ) )
	{
		stockphoto.gpk3.gpk3Sys[ doc_id ].dialog  = new Dialog("file:"+stockphoto.HTMLUtil.fsOut.fsName );
		if( stockphoto.gpk3.gpk3Sys[ doc_id ].dialog != undefined )
		{
			stockphoto.gpk3.gpk3Sys[ doc_id ].bdialog       = true;
			stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.modal  = true;
			stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.title  = stockphoto.imgDetail.zc.get(stockphoto.imgDetail.zstr_dlgTitle);
			stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.width  = 725;
			stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.height = 545;
			if( stockphoto.Burp.doIt ) // in doLocalHTML
			{
			/*B*/	try
			/*B*/	{
			/*B*/		stockphoto.Burp.setOmitBurpurl();
			/*B*/	} catch(e) { ; }
			}
			stockphoto.gpk3.gpk3Sys[ doc_id ].dialog.open( stockphoto.gpk3.jsCallbacks );
			return( true );
		}// stockphoto.gpk3.gpk3Sys[ doc_id ].dialog is created
	} // stockphoto.DL.HTMLUtil.SubLocalHTMLbyDocID()
	return( false );
} // stockphoto.gpk3.getPrice3()

stockphoto.gpk3.getPrice3Sub=function( doc_id, contNo /* container1 */, tabNo /* pane1/pane2 */ )
{
	var bOk=false;
	if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_NavBar ) )
	{
		var doc = stockphoto.NavExtFnc.FromDocIdToDoc( doc_id );
		if( doc != undefined )
		{
			if( stockphoto.gpk3.getPrice3Primary( doc_id, contNo /* container1 */, tabNo /* pane1/pane2 */, doc.selections ) )
				bOk = true;
		}
	}
  	if(   ! bOk )
//	if( ( ! bOk )&&( ( stockphoto.gpk3.gpk3_dtType & 32 ) != 0 ) )
		stockphoto.gpk3.HideWheelFromES( doc_id );
}
stockphoto.gpk3.getPrice3=function( doc_id, contNo /* container1 */, tabNo /* pane1/pane2 */ )
{
   if (("undefined" != typeof stockphoto.gpk3.gpk3Sys) 
        && ("undefined" != typeof stockphoto.gpk3.gpk3Sys[ doc_id ]) 
        && ("undefined" != typeof stockphoto.gpk3.gpk3Sys[ doc_id ].bprogressDialog)
        && (true == stockphoto.gpk3.gpk3Sys[ doc_id ].bprogressDialog))
   {
      return;
   }

   stockphoto.core.SendProxyCredentials(); 	
   
   // Start download comp of first ASP image
   var doc = stockphoto.core.findDoc( doc_id );
   if (undefined != doc)
   {
	   var ThumbArray = doc.selections; 
	   var i;
	   for( i=0; i<ThumbArray.length; i++ )
	   {
		  //If selected image is a container or is not an ASP image, then do nothing
		  if( ("undefined" == typeof ThumbArray[ i ]) || (ThumbArray[ i ].container ) || !(stockphoto.core.util.isBMImageFile(ThumbArray[ i ])))
				continue;

		  // if the image is already a comp or purchased image then do nothing.
		  if ((!stockphoto.core.util.isBMCompImage(ThumbArray[ i ])) && (!stockphoto.core.util.isBMPurchasedImage(ThumbArray[ i ])))
		  {
			  var tmpPath = stockphoto.core.util.fixPathName( ThumbArray[ i ].path );
			  if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_GetComp ) ) 
			  {   
				 stockphoto.getComp.GetComp_Body( tmpPath, undefined, undefined, undefined ,false, "", false, undefined, 0, true, -1);
			  }
		  }
		  break;
	   }
	}

	if( stockphoto.gpk3.setStyleSheet( doc_id ) )
	{
		stockphoto.gpk3.ShowGettingImagesFromES(doc_id);
		// Close the previous gpk
		stockphoto.gpk3.getPrice3fin( doc_id );
		app.scheduleTask( 'stockphoto.gpk3.getPrice3Sub('+doc_id+',"'+contNo+'","'+tabNo+'");', 1500, false );
	}
}

stockphoto.gpk3.getPrice3ByOpenSub=function( doc_id )
{
	var bOk=false;
	if( stockphoto._CheckBillingCountry( "imgDetail.getPrice", app.document ) == 2 )
	{
		if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_NavBar ) )
		{
			var doc = stockphoto.NavExtFnc.FromDocIdToDoc( doc_id );
			if( doc != undefined )
			{
				if( stockphoto.Burp.doIt ) // in DL.MiscDlgs.aboutPreference
				{
				/*B*/	try
				/*B*/	{
				/*B*/ 		stockphoto.Burp.gpkSource = "dc";
				/*B*/		stockphoto.Burp.callSPSUI( doc_id, stockphoto.Burp.code_gpk, "EventSubType", stockphoto.Burp.gpkSource, "", "" );
				/*B*/	} catch(e) { ; }
				}
			}
			if( stockphoto.gpk3.getPrice3Primary( doc_id, "", "pane1", stockphoto.gpk3.gpk3ThumbArray[ doc_id ] ) )
				bOk = true;
		}
	}
	if(   ! bOk )
//	if( ( ! bOk )&&( ( stockphoto.gpk3.gpk3_dtType & 32 ) != 0 ) )
		stockphoto.gpk3.HideWheelFromES(doc_id);
}
stockphoto.gpk3.getPrice3ByOpen=function( doc_id )
{
   if (("undefined" != typeof stockphoto.gpk3.gpk3Sys) 
        && ("undefined" != typeof stockphoto.gpk3.gpk3Sys[ doc_id ]) 
        && ("undefined" != typeof stockphoto.gpk3.gpk3Sys[ doc_id ].bprogressDialog)
        && (true == stockphoto.gpk3.gpk3Sys[ doc_id ].bprogressDialog))
        {
        	return;
        }
        
  		stockphoto.core.SendProxyCredentials(); 	

   // Start download comp of first ASP image
   var doc = stockphoto.core.findDoc( doc_id );
   if (undefined != doc)
   {
	   var ThumbArray = doc.selections; 
	   var i;
	   for( i=0; i<ThumbArray.length; i++ )
	   {
		  //If selected image is a container or is not an ASP image, then do nothing
		  if( ("undefined" == typeof ThumbArray[ i ]) || (ThumbArray[ i ].container ) || !(stockphoto.core.util.isBMImageFile(ThumbArray[ i ])))
				continue;

		  // if the image is already a comp or purchased image then do nothing.
		  if ((!stockphoto.core.util.isBMCompImage(ThumbArray[ i ])) && (!stockphoto.core.util.isBMPurchasedImage(ThumbArray[ i ])))
		  {
			  var tmpPath = stockphoto.core.util.fixPathName( ThumbArray[ i ].path );
			  if( stockphoto.DL.demandJsxLoading( stockphoto.DL.jsx_GetComp ) ) 
			  {   
				 stockphoto.getComp.GetComp_Body( tmpPath, undefined, undefined, undefined ,false, "", false, undefined, 0, true, -1);
			  }
		  }
		  break;
	   }
	}

	if( stockphoto.gpk3.setStyleSheet( doc_id ) )
	{
		stockphoto.gpk3.ShowGettingImagesFromES(doc_id);
		// Close the previous gpk
		stockphoto.gpk3.getPrice3fin( doc_id );
		app.scheduleTask( 'stockphoto.gpk3.getPrice3ByOpenSub('+doc_id+');', 1500, false );
	}
}

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

