var popupActive = false;
var popupNeedReloadOnClose = false;
var photoDivID = -1;

function SetPrimaryPhoto( index )
{
	document.updateForm.primaryPhotoID[ index ].checked = true;
}

function ConfirmDeletePhoto( photoID )
{
	if ( confirm( "Do you really want to delete this photo?" ) )
	{
		document.updateForm.deletePhotoID.value = photoID;
		document.updateForm.submit();
	}
}

/// generic functions
function ClosePopup( reloadMainWin )
{
	popupActive = false;
	popupNeedReloadOnClose = false;
	UnTip();

	if ( reloadMainWin )
	{
		window.location.reload();
	}
}

/// functions to activate the photo window
function ViewPhotoClickHandler( modelID, photoID, _photoDivID, viewPhotoQueryStr, size )
{
	if ( popupActive )
	{
		ClosePopup( false );
	}

	popupActive = true;
	photoDivID = _photoDivID;
	var myRequest = new oAjax( "/index.php", ViewPhotoCallback, "", "" );
	myRequest.update( viewPhotoQueryStr + "&modelID=" + modelID + "&photoID=" + photoID + "&size=" + size, "GET" );
}

function ViewPhotoCallback( responseText, responseStatus )
{
	if ( responseStatus != 200 )
	{
		alert( "Failure to load photo window" );
		return;
	}

	coord = findAbsPos( photoDivID );

	//coord[ 0 ] -= 50;
	//coord[ 1 ] -= 50;

	Tip( responseText, 
	     BGCOLOR, "#EFEFEF",
	     BORDERSTYLE, 'solid',
	     BORDERCOLOR, "#000000",
	     OPACITY, 100,
	     FADEIN, 100,
	     FADEOUT, 100,
	     SHADOW, true,
	     SHADOWWIDTH, 7,
	     FOLLOWMOUSE, false,
	     FIX, coord,
	     PADDING, 0,
	     DELAY, 0
	   );
}
