﻿
var xmlhttp
var gp_iCnt = 0
var gp_iMouseDownX = 0
var gp_iMouseDownY = 0
var gp_bMouseDown = false
var gp_iNotifierWndStartX
var gp_iNotifierWndStartY

// ShowNotifierWindowWebPhoto
// Shows the notifier window with a regular photo in the source
function ShowNotifierWindowWebPhoto(szTitle,szSource)
{
	// Show the notifier window
	ShowNotifierWindow();
	
	// Set the notifier window title
	SetNotifierWindowTitle(szTitle);
	
	// Set the content of the notifier window
	document.getElementById("notifier_window_content").innerHTML = "<img src='"+szSource+"'>";
}


// ShowNotifierWindowMessage
// Shows the notifier window with choosen content
function ShowNotifierWindowMessage(szTitle,szContent)
{
	// Show the notifier window
	ShowNotifierWindow();
	
	// Set the notifier window title
	SetNotifierWindowTitle(szTitle);
	
	// Set the content of the notifier window
	document.getElementById("notifier_window_content").innerHTML = szContent;
}

// NotifierWindowMessage
// Outputs data in the notifier window
function NotifierWindowMessage(szTitle,szMessage)
{
	// Show notifier
	ShowNotifierWindow();
	
	// Set title
	SetNotifierWindowTitle(szTitle);

	// Let them know upload starting
	document.getElementById("notifier_window_content").innerHTML = szMessage;

}

// StartUpload
// Starts the processing of upload
function StartUpload()
{
	// Get AJAX ready
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}

	// Get the uploding page
	//url = url + "?tempfile=" + szTmpFileName;
	//url=url+"&sid="+Math.random();
	//document.getElementById("ajax_output").style.visibility = 'visible';
	lp_szUrl = "uploading_please_wait.php";
	xmlhttp.onreadystatechange=Uploading;
	xmlhttp.open("GET",lp_szUrl,true);
	xmlhttp.send(null);

	// Show notifier
	ShowNotifierWindow();
	
	// Set title
	SetNotifierWindowTitle("Uploading...");
	
	// Let them know upload starting
	document.getElementById("notifier_window_content").innerHTML = "Upload in progress!<br/>Do not close this window until upload completes.";
}

// Uploading
// Shows uploading page
function Uploading()
{
	// Show notifier
	ShowNotifierWindow();
	
	// Set title
	SetNotifierWindowTitle("Uploading...");

	// Check if page is ready
	if (xmlhttp.readyState == 4)
	{
		document.getElementById("notifier_window_content").innerHTML = xmlhttp.responseText;
	}
}

// CompleteUpload
// Lets the user know the upload is complete
function CompleteUpload()
{
	// Let them know upload starting
	document.getElementById("notifier_window_content").innerHTML = "Upload completed successfully!";
}


// ShowNotifierWindow
// Shows the notifier window
function ShowNotifierWindow()
{
	document.getElementById("notifier_window").style.visibility = "visible";
}

// SetNotifierWindowTitle
// Sets the notifier windows title
function SetNotifierWindowTitle(szNewTitle)
{
	document.getElementById("notifier_window_title").innerHTML = szNewTitle;
}

// OnMouseDownNotifierWindow()
// Gets the down hitpoint
function OnMouseDownNotifierWindow()
{
	// Set the mouse down flag
	gp_bMouseDown = true;
	
	// Capture the coords
	gp_iMouseDownX = event.clientX;
	gp_iMouseDownY = event.clientY;
	
	// Get where the window was to start from
	gp_iNotifierWndStartX = parseInt(document.getElementById("notifier_window").style.left);
	gp_iNotifierWndStartY = parseInt(document.getElementById("notifier_window").style.top);
}

// OnMouseUpNotifierWindow()
// Gets the down hitpoint
function OnMouseUpNotifierWindow()
{
	// Set the mouse down flag
	gp_bMouseDown = false;
}

// OnMouseMoveNotifierWindow()
// Moves the notifier window around as the mouse moves
function OnMouseMoveNotifierWindow()
{
// Locals
var lp_iDeltaX;
var lp_iDeltaY;
	
	// Set the mouse down flag
	if (gp_bMouseDown == true)
	{
		// Calculate how much to move
		lp_iDeltaX = gp_iMouseDownX - event.clientX;
		lp_iDeltaY = gp_iMouseDownY - event.clientY;
		
		// Move the notifier window
		document.getElementById("notifier_window").style.left = gp_iNotifierWndStartX - lp_iDeltaX + "px";
		document.getElementById("notifier_window").style.top = gp_iNotifierWndStartY - lp_iDeltaY + "px";
	}
}



// Hides the output of the Ajax div
function HideAjaxOutput()
{
	document.getElementById("ajax_output").style.visibility = 'hidden';
}

// Shows the output of the Ajax div
function ShowAjaxOutput()
{
	document.getElementById("ajax_output").style.visibility = 'visible';
}

// Writes output in the ajax div
function AjaxOutput(szNewHtml)
{
	document.getElementById("ajax_output").innerHTML = szNewHtml;
}


function UpdateUpload()
{
	setInterval("UploadStatus()",1000);

}

// Pulls the status on an upload
function UploadStatus()
{
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}

	var url="PullUploadStats.php";
	//url = url + "?tempfile=" + szTmpFileName;
	//url=url+"&sid="+Math.random();
	//document.getElementById("ajax_output").style.visibility = 'visible';
	xmlhttp.onreadystatechange=UploadRefresh;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	// Show the div and write output
	//var lp_szHttp;
	//lp_szHttp = "<div style='position: absolute; left: 10px; top: 5px;'><img onclick='HideAjaxOutput()' src='images/icon_delete.png'><br/></div>"
	//lp_szHttp = lp_szHttp + "<div style='position: absolute; left: 10px; top: 30px;'><img width= 780 height=560 src='GetFile.php?file="+str+"'>";
	//document.getElementById("ajax_output").style.visibility = 'visible';
	//document.getElementById("ajax_output").innerHTML = lp_szHttp;

}

function ShowImage(str)
{
	// Show the notifier window
	document.getElementById("notifier_window").style.visibility = "visible";

  	// Test
	xmlhttp=GetXmlHttpObject();
	
	if (xmlhttp==null)
	{
	  alert ("Your browser does not support AJAX!");
	  return;
	}
	
	/*var url="GetFile.php";
	url=url+"?file="+str;
	//url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=stateChanged;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);*/
	
	// Show the div and write output
	/*var lp_szHttp;
	lp_szHttp = "<div style='position: absolute; left: 10px; top: 5px;'><img onclick='HideAjaxOutput()' src='images/icon_delete.png'><br/></div>"
	lp_szHttp = lp_szHttp + "<div style='position: absolute; left: 10px; top: 30px;'><img width= 780 height=560 src='GetFile.php?file="+str+"'>";*/
	
	// Put the image content into the notifier
	document.getElementById("notifier_window_content").innerHTML = "<img width=622 height=409 src='GetImageThumb.php?file="+str+"&width=640&height=480'>";

}
function UploadRefresh()
{
	setTimeout('UploadStatus()',1000);
	if (xmlhttp.readyState==4)
	{
		//gp_iCnt += 1;
		// Show the div and write output
		document.getElementById("ajax_output").style.visibility = 'visible';
		document.getElementById("ajax_output").innerHTML = xmlhttp.responseText;
		//setTimeout('UploadRefresh()',500);
	}

}

// Write the output to the ajax output div
function stateChanged()
{
	if (xmlhttp.readyState==4)
	{
		// Show the div and write output
		document.getElementById("ajax_output").style.visibility = 'visible';
		document.getElementById("ajax_output").innerHTML = "Time: " + gp_sDate.getMilliseconds() + xmlhttp.responseText;
		//setTimeout('UploadRefresh()',500);
	}
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
