//holds an instance of XMLHttpRequest
var xmlHttp = createXmlHttpRequestObject();
// creates an XMLHttpRequest instance
function createXmlHttpRequestObject(){
	// will store the reference to the XMLHttpRequest object
	var xmlHttp;
	// this should work for all browsers except IE6 and older
	try{
		// try to create XMLHttpRequest object
		xmlHttp = new XMLHttpRequest();
	}
	catch(e){
		// assume IE6 or older
		var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
		"MSXML2.XMLHTTP.5.0",
		"MSXML2.XMLHTTP.4.0",
		"MSXML2.XMLHTTP.3.0",
		"MSXML2.XMLHTTP",
		"Microsoft.XMLHTTP");
		// try every prog id until one works
		for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++)
		{
			try
			{
				// try to create XMLHttpRequest object
				xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
			}
			catch (e) {}
		}
	}
	// return the created object or display an error message
	if (!xmlHttp){
	alert("Error creating the XMLHttpRequest object.");
	}
	return xmlHttp;
}
function next_forward_picture_page(pic_id,hide){	
	if(document.getElementById("show_picture_edit_view_"+hide) != null){
		document.getElementById("show_picture_edit_view_"+hide).style.display = 'none';		
	}
	if(document.getElementById("show_picture_edit_view_"+pic_id) != null){
		document.getElementById("show_picture_edit_view_"+pic_id).style.display = '';		
	}
	else{
		
		var serverPage = "functions/next_picture_page.php?picture_id="+pic_id
		xmlHttp.open("GET",serverPage);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=utf-8");	
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4 && xmlHttp.status == 200){			
			    var id_name = "show_picture_edit_view_"+pic_id;
			
				if(document.getElementById(id_name)==null){
					var newdiv = document.createElement('div');
					newdiv.setAttribute('id', id_name);
	                
					newdiv.innerHTML = xmlHttp.responseText;
					document.getElementById('picture_edit_div').appendChild(newdiv);
					var obj = document.getElementById(id_name);
					                							
					Drag.init(obj);
				}			
			}
		}
		xmlHttp.send(null)
	}
}
