function getHTTPObject() {
   /*
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }*/
  var xmlhttp = window.XMLHttpRequest ?
      new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");
  return xmlhttp;
}

function handleHttpResponse() {
	if (http.readyState == 4) {
//	 var newImageSrc = rXML.getElementsByTagName('imageURL').
		var TheResponse = http.responseText.split('#');
		var i;
		for (i=0; i<TheResponse.length; i++) {
			var r=TheResponse[i].split(';');  
			var TheObj = document.getElementById(r[1]); // r[1] is element ID
			switch (r[0]){ // r[0] is type of the element
				case ('IMG'): {
					TheObj.src = r[2];
					//alert(r[2]);
					break;
				}
				case ('DIV'): {
					TheObj.innerHTML = r[2];
					//alert(r[2]);
					break;
				}
				default: alert ('Unknown element type '+r[0]);
			}
		}
	}
}

function sendRequest(url) {
	http.open('GET',url,true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}

/*function changeVis(DivId) {
	if      (DivId == 'A'){
		document.getElementById('B').className = 'rectVisible';
		document.getElementById('A').className = 'rectInVisible';
	}
	else if (DivId == 'B'){
		document.getElementById('A').className = 'rectVisible';
		document.getElementById('B').className = 'rectInVisible';
	}
}
*/
function toggleSessionVar(theIMG,src_1,src_2,sessionVar,sessionVarValue) {

//	theIMG.src = src_2;
	if (theIMG.src.indexOf(src_1)>0) {
//		alert ('src_1'+theIMG.src.indexOf(src_1));
		theIMG.src = src_2;
		//http.open('GET','toggleSessionVar.php?sessionVar='+sessionVar+'&sessionVarValue='+sessionVarValue,true);
	}
	else if (theIMG.src.indexOf(src_2)>0) {
//		alert ('src_2'+theIMG.src.indexOf(src_2));
		theIMG.src = src_1;
		//http.open('GET','toggleSessionVar.php?sessionVar='+sessionVar+'&sessionVarValue='+sessionVarValue,true);
	}
}

function changeVis(DivId) {
	if      (DivId == 'A'){
//		alert('A');
		document.getElementById('B').style.display = 'block';
		document.getElementById('A').style.display = 'none';
	}
	else if (DivId == 'B'){
//		alert('B');
		document.getElementById('A').style.display = 'block';
		document.getElementById('B').style.display = 'none';
	}
}
function showBigCell(photoID){
	document.getElementById('StockBigImage').src = 'showPhoto.php?table=images&photoID='+photoID;
	document.getElementById('StockRoomBigCell').style.display = 'block';
	document.getElementById('StockRoomPaletteCell').style.display = 'none';
	sendRequest('makePhotoInfo.php?photoID='+photoID)
//	sendRequest('makePhotoInfo.php?lmnt=DIV&id=divPhotoInfo&photoID='+photoID)
}

function showBigCellDiskImage(img){
	document.getElementById('StockBigImage').src = img;
	document.getElementById('StockRoomBigCell').style.display = 'block';
	document.getElementById('StockRoomPaletteCell').style.display = 'none';
}

function showPaletteCell(){
	document.getElementById('StockBigImage').src = 'ImagesIntro/loadInProgress.gif';
	document.getElementById('StockRoomBigCell').style.display = 'none';
	document.getElementById('StockRoomPaletteCell').style.display = 'block';
	document.getElementById('divVariants').innerHTML = '';
	document.getElementById('divPhotoInfo').innerHTML = '';
//	document.getElementById('divPhotoInfo').innerHTML = '';
}


if( !window.XMLHttpRequest ) XMLHttpRequest = function()
{
  try{ return new ActiveXObject("Msxml2.XMLHTTP.6.0") }catch(e){}
  try{ return new ActiveXObject("Msxml2.XMLHTTP.3.0") }catch(e){}
  try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
  try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
  throw new Error("Could not find an XMLHttpRequest alternative.")
};

var http = getHTTPObject(); // We create the HTTP Object
