/*********************************************/
/*AJAX FUNCTIONS
**********************************************/

function GetXmlHttpObject()
	{
	var xmlHttp=null;
	try
  		{
  		// Firefox, Opera 8.0+, Safari
 		 xmlHttp=new XMLHttpRequest();
 		 }
	catch (e)
  		{
  		// Internet Explorer
 		try
    		{
    		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    		}
  		catch (e)
    		{
    		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    		}
  		}
	return xmlHttp;
	}


/*********************************************/
/*CONFIRM DELETE FUNCTION
**********************************************/	
function confirmDelete(delUrl) {
  if (confirm("Are you sure you want to delete?")) {
    document.location = delUrl;
  }
}

/*********************************************/
/*POPUP WINDOW FUNCTIONS
**********************************************/

function windowSize()
	{
	var h = window.innerHeight; 
	var w = window.innerWidth; 
		
	if(h == null || w == null) 
		{
		var h = document.body.clientHeight; 
		var w = document.body.clientWidth; 
		}
		
	document.getElementById("backdrop").style.width = w +'px'; 
	document.getElementById("backdrop").style.height = h + 'px'; 
	}
	
function windowFix()
	{
	document.getElementById("window").style.width = 450 + 'px';
	document.getElementById("shadow").style.width = 450 + 'px';
	}
	
function windowOpen()
	{
	windowSize();
	document.getElementById("backdrop").style.visibility = 'visible'; 
	}
	
function windowClose()
	{
	document.getElementById("backdrop").style.visibility = 'hidden'; 
	/*window.location.reload(true);*/
	}
	
function viewImage(image)
	{
	document.getElementById("window").style.width = '700px';
	document.getElementById("shadow").style.width = '700px';
	
	uploadImage = '<img src="/gallery/photos/'+image+'.jpg" />'; 
	document.getElementById("display").innerHTML=uploadImage;
	
	windowOpen();
	}
	
function keyStroke(e)
	{
	if(e) //TO WORK WITH IE
		{
		var keynum = e.which;
		}
	else	
		{
		var keynum = window.event.keyCode;
		}
	 
	if(keynum == 27)
		{
		windowClose(); 
		}
	}
	
/*********************************************/
/*ADDING A NEW USER FUNCTIONS
**********************************************/
function addUser()
	{	
	window.location = '/gallery/pro/adduser.php'; 
	}
	
function submitUser()
	{
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  	{
  	alert ("Your browser does not support AJAX!");
  	return false;
  	} 
  	  	
  var u = document.adduser.u.value; 
  if(u == '')
  	{
  	alert("Please insert a user name."); 
  	return false; 
  	}
  	
  var fn = document.adduser.fn.value; 
  if(fn == '')
  	{
  	alert("Please insert a first name."); 
  	return false; 
  	}
  	
  var ln = document.adduser.ln.value; 
  if(ln == '')
  	{
  	alert("Please insert a last name."); 
  	return false; 
  	}
  	
  var p1 = document.adduser.p1.value; 
  ch = /^\w{6,20}/
  if(p1 == '')
  	{
  	alert("Please insert a password."); 
  	return false; 
  	}
 	
 	if(ch.test(document.adduser.p1.value))
  	{
  	var p2 = document.adduser.p2.value; 
  	if(p1 == p2)
  		{
  		return true; 
			}
		else
			{
			alert("Passwords do not match."); 
			return false; 
			}
		}
	else
		{
		alert("You have not entered a valid password"); 
		return false; 
		}
	}
	
function windowStatus() 
	{
	if (xmlHttp.readyState==4)
		{
		windowSize(); 
		windowFix(); 
		windowOpen(); 
		document.getElementById("display").innerHTML=xmlHttp.responseText;
		}
	}
	
function messageStatus() 
	{		
	if (xmlHttp.readyState==1)
		{
		document.getElementById("status2").style.visibility = 'visible';
		}
	
	if (xmlHttp.readyState==4)
		{
		document.getElementById("status2").style.visibility = 'hidden'; 
		document.getElementById("message").innerHTML=xmlHttp.responseText;
		}
	}
	
/*********************************************/
/*ACCEPT/DENY PHOTOS FUNCTIONS
**********************************************/
function deny(id)
	{	
	var ans = confirm("Deny this photo?"); 
		
		if(ans)
			{
			window.location = "/gallery/pro/deny.php?id="+id;
			}

	}

	
function acpt(id)
	{	
	var ans = confirm("Accept this photo?"); 
		
	if(ans)
		{
		window.location = "/gallery/pro/accept.php?id="+id; 
		}

	}
/*********************************************/
/*PHOTO UPLOAD FUNCTIONS 
**********************************************/

/*USE TO REDIRECT TO THE UPLOAD.PHP. */ 
function upload()
	{
	window.location = '/gallery/basic/upload.php'; 
	}
	
	
/*********************************************/
/*EDIT IMAGE FUNCTION  
**********************************************/
function editImage(id)
	{	
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
  		{
  		alert ("Your browser does not support AJAX!");
  		return;
  		} 
  		
  windowFix();
  			
	var url="/gallery/basic/edit.php?id="+id;
	xmlHttp.onreadystatechange=windowStatus;
	xmlHttp.open("GET",url);
	xmlHttp.send(null);
	}
	
/*********************************************/
/*LOGOUT FUNCTION 
**********************************************/
function logout()
	{
	window.location = "/gallery/logout.php"; 
	}