//********************************************************
//general ajax functions
//********************************************************



function AJAXInteraction(url, callback) {

    var req = init();
    req.onreadystatechange = processRequest;
        
    function init() {
	  var xmlHttp=null;
	  try
	    {
	    // Firefox, Opera 8.0+, Safari
	    xmlHttp=new XMLHttpRequest();
	    }
	  catch (e)
	    {
	    // Internet Explorer
	    try
	      {
	      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	      }
	    catch (e)
	      {
	      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	      }
	    }
	  return xmlHttp;
     }
    
    function processRequest () {
      if (req.readyState == 4) {
        if (req.status == 200) {
          if (callback) callback(req.responseText);
        }
      }
    }

    this.doGet = function() {
      req.open("GET", url, true);
      req.send(null);
    }
    
    this.doPost = function(body) {
      req.open("POST", url, true);
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
      req.send(body);
    }
}


//********************************************************
//function needs structure with element 'data' that have two subelements
//  - array selvalues -> will be used as select options values
//  - array seltext -> will be used as select options text
// You can create easy such struct using cfcJSon.encode(data=qGetLightbox) 
// where qGetLightbox is query with 2 columns : selvalues and seltext
//********************************************************
function updateSelectBox (lightboxSelectBoxId,xmlHttp) {
	if (xmlHttp.readyState==4)
	{ 
		lightboxSelectBox=document.getElementById(lightboxSelectBoxId);
		objLightboxes=eval('(' + xmlHttp.responseText + ')');
		
		//clear all curent options
		lightboxSelectBox.options.length = 0;
		//add new options
		for (i=0;i<objLightboxes.data.selvalues.length;i++){
			lightboxSelectBox.options[i] = new Option(objLightboxes.data.seltext[i],objLightboxes.data.selvalues[i]);
		}
	}	
}
//********************************************************
