// -----------------------------------------------------------------------------------
//
//	Lightbox v2.04 extension
//	by Derrick Russell - http://www.ldmailmasters.com
//	Last Modification: 2008-09-04
//
//  Functions
//    sendImageName(strImgName, strPHPPage, objLB, strCurrDesc)
//
// -----------------------------------------------------------------------------------

var doUseAjax = true;

if(!document.getElementById) {
	doUseAjax = false;
}

var tmpObj = null;
var tmpCurrDesc = '';

function createXMLRequestObject() {
	// No point if we can't get elements by id
	var req;
	req = false;
	if(document.getElementById) {
		try {
			if(window.XMLHttpRequest){
				req = new XMLHttpRequest();
			} else if(window.ActiveXObject) {
				// Internet Explorer 5+
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} else {
				req = false;
			}
		} catch (e) {
			req = false;
		}
	}
	return req;
}
if(!sinhttp) {
var sinhttp = createXMLRequestObject();
}

function sendImageName(strImgName, strPHPPage, objLB, strCurrDesc) {
  tmpObj = null;
  tmpCurrDesc = '';
	// Ajax request - updates on the fly
	var strCurrState = '';

	if(doUseAjax == true && document.getElementById) {
    objLB.caption.update('').show();
    if(strImgName != '' && strPHPPage != '') { 
  			// Open PHP script for description
  			try {
          var tmpReqString = strPHPPage + '?useval=getDesc&iName=' + escape(strImgName);
          tmpObj = objLB;
          tmpCurrDesc = strCurrDesc;
          sinhttp.open('get', tmpReqString);
          sinhttp.onreadystatechange = hSINResponse;
          sinhttp.send(null);
  			} catch (e) {
          // Do nothing
        }
    } else {
			objLB.caption.update('').show();
		}
  } else {
			objLB.caption.update('').show();
	}
}

//function handleSendImageNameResponse(objLB, strCurrDesc) {
function hSINResponse() {
	// When getting a response from the ajax request
	if(sinhttp.readyState == 4 && sinhttp.status == 200){
		// Text returned FROM the PHP script
		var descResponse = sinhttp.responseText;
		descResponse = descResponse.replace(/^\s+|\s+$/g, '');
    var strCurrDesc = "";
		if(descResponse) {
		  if(tmpObj) {
        if (tmpCurrDesc != ""){
          tmpObj.caption.update(tmpCurrDesc + "<br />" + descResponse).show();
        } else {
          tmpObj.caption.update(descResponse).show();
        }
      }
		} else {
		  errorSendImageName1();
		}
	} else if(sinhttp.readyState == 4 && sinhttp.status != 200) {
		// Didn't get an OK response
		errorSendImageName1();
	}
}

function errorSendImageName1 () {
  // Do nothing
}