var xmlHttp;
var thisAlbum;
var thisImage;

function albumUpdate() {
document.getElementById('imageChangeHere').innerHTML = "<p><p><p><center><p><p><p><img src=/forum/resource/graphics/loader.gif>";
if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
		document.getElementById('imageChangeHere').innerHTML = xmlHttp.responseText;
         } else {
            alert("There was a problem with the request");
         }
      }   
   } 
   
   function albumUpdateAdd() {
document.getElementById('imageChangeHere').innerHTML = "<p><p><p><center><p><p><p><img src=/forum/resource/graphics/loader.gif>";
if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
		//albumHome();
imageHome();
         } else {
            alert("There was a problem with the request");
         }
      }   
   } 
   
      function albumUpdateAdd2() {
document.getElementById('imageChangeHere').innerHTML = "<p><p><p><center><p><p><p><img src=/forum/resource/graphics/loader.gif>";
if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
		goBack();
         } else {
            alert("There was a problem with the request");
         }
      }   
   } 

function albumHome(){
var thisLot="1";
var url="/photos/resource/working/albumHome.asp";
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
  //document.location.href=url;
xmlHttp.onreadystatechange = albumUpdate;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function imageHome(){
var thisLot="1";
var url="/photos/resource/working/imageHome.asp";
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
  //document.location.href=url;
xmlHttp.onreadystatechange = albumUpdate;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function imageHome2(){
var thisLot="1";
var url="/photos/resource/working/imageHome.asp";
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
  //document.location.href=url;
xmlHttp.onreadystatechange = pFriendUpdate;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function albumNew(){
var thisLot="1";
var url="/photos/resource/working/albumNew.asp";
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
  //document.location.href=url;
xmlHttp.onreadystatechange = albumUpdate;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function albumOpen(obj){
thisAlbum=obj;
var thisLot="id=" + obj;
var url="/photos/resource/working/albumOpen.asp";
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
  //document.location.href=url;
xmlHttp.onreadystatechange = albumUpdate;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function goBack(){
albumOpen(thisAlbum);
}

function addAlbum(){

var iChars = "@<>";

for (var i = 0; i < document.formPhoto.aName.value.length; i++) {
  	if (iChars.indexOf(document.formPhoto.aName.value.charAt(i)) != -1) 
  	{
openAlert('Alert','Album Name contains invalid characters: @ < >');
return;
}
}
for (var i = 0; i < document.formPhoto.aDescription.value.length; i++) {
  	if (iChars.indexOf(document.formPhoto.aDescription.value.charAt(i)) != -1) 
  	{
openAlert('Alert','Album Description contains invalid characters: @ < >');
return;
}
}

var thisLot;
thisLot = "aName=" + encodeURIComponent(document.formPhoto.aName.value);
thisLot = thisLot + "&aDescription=" + encodeURIComponent(document.formPhoto.aDescription.value);
thisLot = thisLot + "&aGroup=" + encodeURIComponent(document.formPhoto.selectGroup.value);

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
//alert(thisLot);
var url="/photos/resource/working/albumNewDo.asp";
//document.location.href=url+"?"+thisLot; 
xmlHttp.onreadystatechange = albumUpdateAdd;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function albumEdit(obj){
var thisLot="id=" + obj;
var url="/photos/resource/working/albumEdit.asp";
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
  //document.location.href=url;
xmlHttp.onreadystatechange = albumUpdate;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function editAlbum(){

var iChars = "@<>";

for (var i = 0; i < document.formPhoto.aName.value.length; i++) {
  	if (iChars.indexOf(document.formPhoto.aName.value.charAt(i)) != -1) 
  	{
openAlert('Alert','Album Name contains invalid characters: @ < >');
return;
}
}
for (var i = 0; i < document.formPhoto.aDescription.value.length; i++) {
  	if (iChars.indexOf(document.formPhoto.aDescription.value.charAt(i)) != -1) 
  	{
openAlert('Alert','Album Description contains invalid characters: @ < >');
return;
}
}

var thisLot;
thisLot = "aName=" + encodeURIComponent(document.formPhoto.aName.value);
thisLot = thisLot + "&aDescription=" + encodeURIComponent(document.formPhoto.aDescription.value);
thisLot = thisLot + "&id=" + encodeURIComponent(document.formPhoto.id.value);

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
//alert(thisLot);
var url="/photos/resource/working/albumEditDo.asp";
//document.location.href=url+"?"+thisLot; 
xmlHttp.onreadystatechange = albumUpdateAdd;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function deleteAlbum(obj){
if (confirm('Are you sure you want to DELETE this album and all its content?\n\nThis action cannot be undone!')) {
var url="/photos/resource/working/albumDeleteDo.asp";
var thisLot="id=" + obj;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
//document.location.href=url+"?"+thisLot;
xmlHttp.onreadystatechange = albumUpdateAdd;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}else{
//return;
}
}

function imageEdit(obj){
var thisLot="id=" + obj;
var url="/photos/resource/working/imageEdit.asp";
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
  //document.location.href=url;
xmlHttp.onreadystatechange = albumUpdate;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}



function editImage(){

var iChars = "@<>";

for (var i = 0; i < document.formPhoto.pCaption.value.length; i++) {
  	if (iChars.indexOf(document.formPhoto.pCaption.value.charAt(i)) != -1) 
  	{
openAlert('Alert','Image Caption contains invalid characters: @ < >');
return;
}
}

var thisLot;
thisLot = "pCaption=" + encodeURIComponent(document.formPhoto.pCaption.value);
thisLot = thisLot + "&pProfilePic=" + encodeURIComponent(document.formPhoto.pProfilePic.value);
thisLot = thisLot + "&pAlbumId=" + encodeURIComponent(document.formPhoto.pAlbumId.value);
thisLot = thisLot + "&id=" + encodeURIComponent(document.formPhoto.id.value);
thisLot = thisLot + "&pAlbumPic=" + encodeURIComponent(document.formPhoto.pAlbumPic.value);

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  } 
//alert(thisLot);
var url="/photos/resource/working/imageEditDo.asp";
//document.location.href=url+"?"+thisLot; 
xmlHttp.onreadystatechange = albumUpdateAdd2;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function deleteImage(obj){
if (confirm('Are you sure you want to DELETE this image?\n\nThis action cannot be undone!')) {
var url="/photos/resource/working/imageDeleteDo.asp";
var thisLot="id=" + obj;
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
//document.location.href=url+"?"+thisLot;
xmlHttp.onreadystatechange = albumUpdateAdd2;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}else{
//return;
}
}

function imageNew(obj){
var thisLot="id=" + obj;
var url="/photos/resource/working/imageNew.asp";
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
  //document.location.href=url;
xmlHttp.onreadystatechange = albumUpdate;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function imageAdd(){
if(document.imup.filesent.value==""){
openAlert('Alert','There is no file selected for upload');
return;
}
document.getElementById('imageUploadInfo').innerHTML = "<img src=/community/resource/graphics/loader.gif>&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=red>Loading ... Depending on file size, this may take a few minutes</font></b>";
document.imup.submit();
//setTimeout("imageChange")
}

function imageFail(){
document.imup.reset();
document.getElementById('imageUploadInfo').innerHTML = "<b>Image failed to upload</b>";
setTimeout("imageAdd3()",5000);
}

function imageChange(obj){
document.getElementById('imageUploadInfo').innerHTML = "<img src=/community/resource/graphics/loader.gif>&nbsp;&nbsp;&nbsp;&nbsp;<b><font color=orange>Saving </font></b>...";
var thisLot="filename=" + encodeURIComponent(obj);
thisLot = thisLot + "&album=" + encodeURIComponent(document.imup.selectAlbum.value);
var url="/photos/resource/working/imageChangeName.asp";
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null) {
  alert ("Your browser does not support AJAX!");
  return;
  }
  //alert(thisLot);
  //document.location.href=url + "?" + thisLot;
xmlHttp.onreadystatechange = imageFinish;
xmlHttp.open("POST",url,true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", thisLot.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.send(thisLot);
}

function imageFinish() {
if (xmlHttp.readyState == 4) {
         if (xmlHttp.status == 200) {
		imageComplete();
         } else {
            alert("There was a problem with the request");
         }
      }   
   } 
   
function imageComplete(){
document.imup.reset();
document.getElementById('imageUploadInfo').innerHTML = "<p><b><font color=green>Finished... please wait</font></b>";
setTimeout("imageAdd3()",2000);
}

function imageAdd3(){
document.getElementById('imageUploadInfo').innerHTML = "<p>By clicking the [ Upload Now ] button you acknowledge and agree that either:</p><ul><li>You own the rights to the image (usually meaning that you created the image yourself)</li><li>You can prove that the copyright holder has licensed the image under an acceptable free license</li><li>You can prove that the image is in the public domain</li></ul>";
}
