//------------------------------------------------------------------------------
// Class:  ManagePhotos
//------------------------------------------------------------------------------
// Author:  CL
// Date:  2008/01/30
// Description:  This class defines the functions used by the Manage Photos section.
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function ManagePhotos()
{
	// Variables:
	//var maxCheckedPhoto = 5;
	//var currentCheckedPhoto = 0;
	
	//--------------------------------------------------------------------------

	// Methods:
	this.popupWindow = popupWindow;
	//this.getChecked = getChecked;
	//this.selectPhoto = selectPhoto;
	this.getCheckedPhotoValues = getCheckedPhotoValues;
	this.changeManagePhotoView = changeManagePhotoView;
	this.editPhotoInfo = editPhotoInfo;
	this.editPhotoInfoSave = editPhotoInfoSave;
	this.editPhotoInfoClose = editPhotoInfoClose;
	this.addTagToInput = addTagToInput;
	this.deletePhotos = deletePhotos;
	this.deletePhotosConfirm = deletePhotosConfirm;
	this.deletePhotosConfirmClose = deletePhotosConfirmClose;
	this.openEditPhotoWin = openEditPhotoWin;
	this.rotateLeft = rotateLeft;
	this.rotateRight = rotateRight;
	this.popupSortPhoto = popupSortPhoto;
	this.updateLabelSettingConfirm = updateLabelSettingConfirm;
	this.updatePhotoLabelSetting = updatePhotoLabelSetting;
	this.manageComment = manageComment;
	this.closeManageCommentWindow = closeManageCommentWindow;
	
	//--------------------------------------------------------------------------
	
	function popupWindow(URL,sTitle,iHeight)
	{
		var sStyle = "width=750px,height="+ iHeight + ",top=50px,left=150px,resize=1,scrolling=1,center=0";
		window.popUp = dhtmlwindow.open("galleryadmin", "iframe", URL, sTitle, sStyle, "recal");
		window.popUp.onclose=function(){
			window.frames["_iframe-galleryadmin"].location.replace('about:blank');
			return true;
		}
	}
	
	//--------------------------------------------------------------------------
	/*
	function selectPhoto(thePhoto)
	{
		if(document.getElementById(thePhoto).checked == true)
		{
			currentCheckedPhoto ++;
		
			if(currentCheckedPhoto > maxCheckedPhoto)
			{
				alert('You must select only ' + maxCheckedPhoto + ' photos at a time. ');
				document.getElementById(thePhoto).checked = false;
				currentCheckedPhoto = currentCheckedPhoto - 1;
			}
			else
			{
				var strSelectedPhotoIds = document.frmManagePhotos.intSelectedPhotoIDs.value;

				if(strSelectedPhotoIds.length == 0)
				{
					document.frmManagePhotos.intSelectedPhotoIDs.value = document.getElementById(thePhoto).value;
				}
				else
				{
					document.frmManagePhotos.intSelectedPhotoIDs.value = strSelectedPhotoIds + ',' + document.getElementById(thePhoto).value;
				}
			}
		}
		else
		{
			currentCheckedPhoto --;
		}
		
	}
	*/
	//--------------------------------------------------------------------------
	/*
	function getChecked()
	{
		var thePhotos = document.frmManagePhotos.photo;
		var numChecked = 0;
		
		for(i=0; i<thePhotos.length; ++i)
		{
			if(thePhotos[i].checked)
			{
				numChecked = numChecked + 1;
			}
		}
		currentCheckedPhoto = numChecked;
	}
	*/
	//--------------------------------------------------------------------------
	
	function getCheckedPhotoValues()
	{
		var thePhotos = document.frmManagePhotos.photo;
		
		for(i=0; i<thePhotos.length; ++i)
		{
			if(thePhotos[i].checked)
			{
				var strSelectedPhotoIds = document.frmManagePhotos.intSelectedPhotoIDs.value;
				
				if(strSelectedPhotoIds.length == 0)
				{
					document.frmManagePhotos.intSelectedPhotoIDs.value = thePhotos[i].value;
				}
				else
				{
					document.frmManagePhotos.intSelectedPhotoIDs.value = strSelectedPhotoIds + ',' + thePhotos[i];
				}
			}
		}
	}
	
	//--------------------------------------------------------------------------
	
	function changeManagePhotoView(URL)
	{
		//window.location = URL + "&s=" + document.getElementById("intSortType").value;
		window.location = URL;
	}	
	
	//--------------------------------------------------------------------------
	
	function editPhotoInfo(URL,sTitle,iHeight)
	{
		
		document.getElementById("overlay").style.height = YAHOO.util.Dom.getDocumentHeight()+"px";
		document.getElementById("overlay").style.width = YAHOO.util.Dom.getDocumentWidth()+"px";
		document.getElementById("overlay").style.display ="block";
		var iframeWName = "_iframe-" + editPhotoInfoWin;
		var sStyle = "width=810px,height="+ iHeight + ",resize=1,scrolling=1,center=1";
		window.editPhotoInfoWin = dhtmlwindow.open("editPhotoInfoWin", "iframe", URL, sTitle, sStyle, "recal");
		window.editPhotoInfoWin.onclose=function(){
			document.getElementById("overlay").style.display="none";
			window.frames["_iframe-editPhotoInfoWin"].location.replace('about:blank');
			return true;
		}
		
		//document.frmManagePhotos.target = "_iframe-galleryadmin";
		//document.frmManagePhotos.action = URL;
		//document.frmManagePhotos.submit();
	}
	
	//--------------------------------------------------------------------------
	
	function editPhotoInfoSave()
	{	
		document.frmEditPhotoInfo.target = "managePhotoMain";
		document.frmEditPhotoInfo.submit();
	}
	
	//--------------------------------------------------------------------------
	
	function editPhotoInfoClose()
	{
		//var ifr = parent.document.getElementById("_iframe-editPhotoInfoWin");
		//ifr.parentNode.removeChild(ifr);
		parent.document.getElementById("overlay").style.display ="none";
		parent.window.editPhotoInfoWin.hide();
		parent.window.frames["_iframe-editPhotoInfoWin"].location.replace('about:blank');
	}
	
	//--------------------------------------------------------------------------
	
	function addTagToInput(sNewTag)
	{
		theTagInput = document.getElementById("tags").value;
		theNewTag = document.getElementById(sNewTag).value;
		
		if(!((theTagInput.length == 0) || (theTagInput.match(/^\s+$/))))
		{
			theNewTag = ", " + theNewTag;
		}
		
		document.getElementById("tags").value = theTagInput + theNewTag;
		
	}
	
	//--------------------------------------------------------------------------
	
	function deletePhotos()
	{
		document.frmManagePhotos.isDelete.value = 1;
		document.frmManagePhotos.isUpdateLabelSettings.value = 0;
		document.frmManagePhotos.submit();
	}
	
	//--------------------------------------------------------------------------

	function deletePhotosConfirm(idString)
	{
		//this.getCheckedPhotoValues();
		
		document.getElementById("overlay").style.height = YAHOO.util.Dom.getDocumentHeight()+"px";
		document.getElementById("overlay").style.width = YAHOO.util.Dom.getDocumentWidth()+"px";
		document.getElementById("overlay").style.display ="block";
		
		theElement = document.getElementById(idString);
		if (theElement.style.display == "none")
		{
			theElement.style.display = "block";
		}
		
		function hideDeletePhotos()
		{
			document.getElementById("overlay").style.display ="none";
			YAHOO.deletePhoto.container.deletePhoto.hide();
		}
			
		YAHOO.deletePhoto.container.deletePhoto = new YAHOO.widget.ResizePanel('deletePhoto', { width:'350px', close:false, draggable:false, fixedcenter:true, visible:true, constraintoviewport:false, zIndex:100 } );
		YAHOO.deletePhoto.container.deletePhoto.render();
		YAHOO.util.Event.addListener("closeDeletePhoto", "click", hideDeletePhotos, YAHOO.deletePhoto.container.deletePhoto, true);
		//document.frmManagePhotos.deletePhotoIDs.value = document.frmManagePhotos.intSelectedPhotoIDs.value;
	}
	
	//--------------------------------------------------------------------------
	
	function deletePhotosConfirmClose()
	{
		//document.frmManagePhotos.deletePhotoIDs.value = "";
	}

	//--------------------------------------------------------------------------

	function openEditPhotoWin(URL)
	{
		window.open(URL, "editPhotoMain", "resizable=yes, scrollbars=yes, toolbar=no, location=no, directories=no, status=no,menubar=no");
	}
	
	//--------------------------------------------------------------------------

	function rotateLeft(aID, pID, strID, thumbWidth, thumbHeight)
	{
			var overlayDiv = strID + '_overlay';
			var overlayContent = strID + '_content';
			var overlayContentCell = strID + '_contentcell';
			var rotateError = strID + '_rotateError';
			//originalMouseOver = document.getElementById(overlayDiv).onmouseover;
			//originalMouseOut = document.getElementById(overlayDiv).onmouseout;
			document.getElementById(overlayDiv).className="overlayManagePhoto";
			document.getElementById(overlayContent).style.visibility = "hidden";
			document.getElementById(overlayDiv).onmouseover = "";
			document.getElementById(overlayDiv).onmouseout = "";
			$.ajax({
				type: "POST",
				url: "/gallery/_var/inc_rotatePhoto.cfm?a=" + aID + "&pID=" + pID,
				data: "isRotateLeft=1",
				dataType: "xml",
				success: function(xml){
					var blnRotateStatus = jQuery('rotateStatus', xml).text();
					var thumbPath = jQuery('thumbnailPath', xml).text();
					setTimeout(
						function(){
						if(blnRotateStatus == 'true')
						{
							//var strIDContent = '<img src="' + thumbPath + '?' + Math.floor(Math.random()*10000) + '" width="' + thumbWidth +'" height="' + thumbHeight +'">';
							var strIDContent = '<img src="' + thumbPath + '" width="' + thumbWidth +'" height="' + thumbHeight +'">';
							document.getElementById(strID).innerHTML = strIDContent;
							//alert(Math.floor(Math.random()*10000));
							//document.getElementById("photo"+strID).src= thumbPath + '?' + Math.floor(Math.random()*10000);
							document.getElementById(overlayDiv).className="";
							//document.getElementById(overlayDiv).className="managePhotoSuccess";
							document.getElementById(overlayContent).style.visibility = "visible";
							document.getElementById(overlayContentCell).className="managePhotoSuccess";
							document.getElementById(rotateError).innerHTML = "<span style='color:#00aa00;font-weight:bold;'>Rotate Left 90&ordm; Successful.</span>";
						}
						else
						{
							document.getElementById(overlayDiv).className="";
							//document.getElementById(overlayDiv).className="managePhotoError";
							document.getElementById(overlayContent).style.visibility = "visible";
							document.getElementById(overlayContentCell).className="managePhotoError";
							document.getElementById(rotateError).innerHTML = "<span style='color:#aa0000;font-weight:bold;'>Rotate Left 90&ordm; Unsuccessful.</span>";
						}
						}, 300
					);
				},
				error: function(){
					setTimeout(
						function(){
							document.getElementById(overlayDiv).className="";
							document.getElementById(overlayContent).style.visibility = "visible";
							document.getElementById(overlayContentCell).className="managePhotoError";
							document.getElementById(rotateError).innerHTML = "<span style='color:#aa0000;font-weight:bold;'>Rotate Left 90&ordm; Unsuccessful.</span>";
						}, 300
					);
				}
			});
	}
	
	//--------------------------------------------------------------------------

	function rotateRight(aID, pID, strID, thumbWidth, thumbHeight)
	{
			var overlayDiv = strID + '_overlay';
			var overlayContent = strID + '_content';
			var overlayContentCell = strID + '_contentcell';
			var rotateError = strID + '_rotateError';
			//originalMouseOver = document.getElementById(overlayDiv).onmouseover;
			//originalMouseOut = document.getElementById(overlayDiv).onmouseout;
			document.getElementById(overlayDiv).className="overlayManagePhoto";
			document.getElementById(overlayContent).style.visibility = "hidden";
			document.getElementById(overlayDiv).onmouseover = "";
			document.getElementById(overlayDiv).onmouseout = "";
			$.ajax({
				type: "POST",
				url: "/gallery/_var/inc_rotatePhoto.cfm?a=" + aID + "&pID=" + pID,
				data: "isRotateRight=1",
				dataType: "xml",
				success: function(xml){
					var blnRotateStatus = jQuery('rotateStatus', xml).text();
					var thumbPath = jQuery('thumbnailPath', xml).text();
					setTimeout(
						function(){
						if(blnRotateStatus == 'true')
						{
							var strIDContent = '<img src="' + thumbPath + '" width="' + thumbWidth +'" height="' + thumbHeight +'">';
							document.getElementById(strID).innerHTML = strIDContent;
							//document.getElementById(overlayDiv).className="managePhotoSuccess";
							document.getElementById(overlayDiv).className="";
							document.getElementById(overlayContent).style.visibility = "visible";
							document.getElementById(overlayContentCell).className="managePhotoSuccess";
							document.getElementById(rotateError).innerHTML = "<span style='color:#00aa00;font-weight:bold;'>Rotate Right 90&ordm; Successful.</span>";
						}
						else
						{
							//document.getElementById(overlayDiv).className="managePhotoError";
							document.getElementById(overlayDiv).className="";
							document.getElementById(overlayContent).style.visibility = "visible";
							document.getElementById(overlayContentCell).className="managePhotoError";
							document.getElementById(rotateError).innerHTML = "<span style='color:#aa0000;font-weight:bold;'>Rotate Right 90&ordm; Unsuccessful.</span>";
						}
						}, 300
					);
				},
				error: function(){
					setTimeout(
						function(){
							document.getElementById(overlayDiv).className="";
							document.getElementById(overlayContent).style.visibility = "visible";
							document.getElementById(overlayContentCell).className="managePhotoError";
							document.getElementById(rotateError).innerHTML = "<span style='color:#aa0000;font-weight:bold;'>Rotate Right 90&ordm; Unsuccessful.</span>";
						}, 300
					);
				}
			});
	}
	
	
	//--------------------------------------------------------------------------
	
	function popupSortPhoto(URL,sTitle,iWidth,iHeight,wName,wType)
	{
		document.getElementById("overlay").style.height = YAHOO.util.Dom.getDocumentHeight()+"px";
		document.getElementById("overlay").style.width = YAHOO.util.Dom.getDocumentWidth()+"px";
		document.getElementById("overlay").style.display ="block";
		var sStyle = "width=" + iWidth + ",height="+ iHeight + ",top=50px,left=150px,resize=0,scrolling=0,center=0";
		var popUp = dhtmlwindow.open(wName, wType, URL, sTitle, sStyle);
		var iframeWName = "_iframe_" + wName;
		popUp.onclose=function(){
			document.getElementById("overlay").style.display="none";
			window.frames[iframeWName].location.replace('about:blank');
			return true;
		}
	}
	
	//--------------------------------------------------------------------------

	function updateLabelSettingConfirm(idString)
	{
		document.getElementById("overlay").style.height = YAHOO.util.Dom.getDocumentHeight()+"px";
		document.getElementById("overlay").style.width = YAHOO.util.Dom.getDocumentWidth()+"px";
		document.getElementById("overlay").style.display ="block";
		
		theElement = document.getElementById(idString);
		if (theElement.style.display == "none")
		{
			theElement.style.display = "block";
		}
		
		function hideLabelSettingPopup()
		{
			document.getElementById("overlay").style.display ="none";
			YAHOO.updateLabelSetting.container.updateLabelSetting.hide();
		}
			
		YAHOO.updateLabelSetting.container.updateLabelSetting = new YAHOO.widget.ResizePanel('updateLabelSetting', { width:'350px', close:false, draggable:false, fixedcenter:true, visible:true, constraintoviewport:false, zIndex:100 } );
		YAHOO.updateLabelSetting.container.updateLabelSetting.render();
		YAHOO.util.Event.addListener("closeUpdateLabelSetting", "click", hideLabelSettingPopup, YAHOO.updateLabelSetting.container.updateLabelSetting, true);
	}
	
	//--------------------------------------------------------------------------
	
	function updatePhotoLabelSetting()
	{
		document.frmManagePhotos.isDelete.value = 0;
		document.frmManagePhotos.isUpdateLabelSettings.value = 1;
		document.frmManagePhotos.submit();
	}
	
	//--------------------------------------------------------------------------
	
	function manageComment(URL,sTitle,iHeight)
	{
		document.getElementById("overlay").style.height = YAHOO.util.Dom.getDocumentHeight()+"px";
		document.getElementById("overlay").style.width = YAHOO.util.Dom.getDocumentWidth()+"px";
		document.getElementById("overlay").style.display ="block";
		var iframeWName = "_iframe-editPhotoInfoWin" ;
		var sStyle = "width=810px,height="+ iHeight + ",resize=1,scrolling=1,center=1";
		var popup = dhtmlwindow.open("editPhotoInfoWin", "iframe", URL, sTitle, sStyle, "recal");
		popup.onclose=function(){
			document.getElementById("overlay").style.display="none";
			window.frames[iframeWName].location.replace('about:blank');
			return true;
		}
	}
	
	//--------------------------------------------------------------------------
	
	function closeManageCommentWindow()
	{
			parent.document.getElementById('overlay').style.display = "none";
			parent.document.getElementById('editPhotoInfoWin').style.display = "none";
			parent.window.frames["_iframe-editPhotoInfoWin"].location.replace('about:blank');
	}
	
	
}

// Create Object
oManagePhotos = new ManagePhotos();

//--------------------------------------------------------------------------
