var xmlHttp;
var whichButton = null;

function verifyParentID(theForm)
{  
	
	if(theForm.parentType.value == "Photos"){
		return true;
	}
	//alert(theForm.parentID.value);
	else if(theForm.parentID.value <= 0){
		alert("You must select a " + theForm.parentType.value.substr(0,theForm.parentType.value.length-1) + " to save the photo against, you may need to add a new " + theForm.parentType.value.substr(0,theForm.parentType.value.length-1) + " from the Admin homepage.");
		return false;
	}
	return true;
}

function verifyDelete()
{  
	if(whichButton.value=="Del")
		return confirm ("Are you sure you wish to delete, all related photos will also be deleted!");
		
		return true;
}

function getParents(selectedParentType)
{  
 
  if(selectedParentType=="Photos"){

		document.getElementById("parentID").style.display = "none";
		document.getElementById("parentID2").style.display = "none";
		document.getElementById("parentID3").style.display = "none";
		document.getElementById("parentID4").style.display = "none";
		return;
   }
   else if(selectedParentType=="Groups"){
	  	document.getElementById("parentID").style.display = "";
		document.getElementById("parentID2").style.display = "";
	  	document.getElementById("parentID3").style.display = "none";
		document.getElementById("parentID4").style.display = "none";
		document.getElementById("parentID").innerHTML = selectedParentType.substr(0,selectedParentType.length-1);
   }
   else{
	  	document.getElementById("parentID").style.display = "";
		document.getElementById("parentID2").style.display = "";
	  	document.getElementById("parentID3").style.display = "";
		document.getElementById("parentID4").style.display = "";
		document.getElementById("parentID").innerHTML = selectedParentType.substr(0,selectedParentType.length-1);

   }
  
  try
  {    // Firefox, Opera 8.0+, Safari    
  	xmlHttp=new XMLHttpRequest();    
  }
  catch (e)
  {    // Internet Explorer    
  
	  try
	  {      
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      
	  }
	  catch (e) 
	  {      
		try
		{        
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        
		}
		catch (e)
		{        
			alert("Your browser does not support AJAX!");        
			return false;        
		}      
	  }    
   }  
  
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET","ajaxParents.asp?parentType=" + selectedParentType + "&time=" + new Date().getTime(),true);
  xmlHttp.send(null);

}
function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		updateParents(xmlHttp.responseText);
	}
} 

function updateParents(dbListString){

	var parentList=document.MyForm.parentID;
	parentList.options.length=0;
	
	var parentDBList=new Array();
	parentDBList = dbListString.split("*");

	
		for (i=0; i<parentDBList.length; i++)
			parentList.options[parentList.options.length]=new Option(parentDBList[i].split("|")[1], parentDBList[i].split("|")[0])
}

