//function cl_dialog(dialog, buttons)
//dialog = array(<text>, array(<id>, <classname>), array(array(<style>, <value>), ...))
//  <text> - Text displayed in dialog box
//  <id> - Id assigned to the dialog box div
//  <classname> - Classname assigned to the dialog box div
//  <style> - Style property
//  <value> - Value the style property should be set to
//buttons = array(<buttonholder>, array(<text>, <id>, <classname>, <handler>), ...)
//  <buttonholder> - Class name of the div holding the buttons
//  <text> - Text on the button
//  <id> - Id of the button
//  <classname> - Classname assigned to the button
//  <handler> - Onclick assigned to the button
//  <style> - Style property
//  <value> - Value to which the style property should be set
function cl_dialog(dialog, buttons)
{
  // Create the div containing the 'dialog'
  dialogDiv  = top.document.createElement('div');
  dialogDiv.style.position   = 'absolute';
//  dialogDiv.style.top        = '100px';
//  dialogDiv.style.left       = '100px';
  dialogDiv.style.zIndex     = '5000';
  dialogDiv.style.background = '#eee';
  dialogDiv.id               = dialog[1][0];
  dialogDiv.className        = dialog[1][1];
  ddTextHolder               = top.document.createElement('div');
  ddText                     = top.document.createElement('div');
  ddText.innerHTML = dialog[0];
  for (i = 0; i < dialog[2].length; i++)
  {
    prop = dialog[2][i][0];
    value = dialog[2][i][1];
    eval('dialogDiv.style.' + prop + ' = "' + value + '";');
  }
  // Deal with the buttons
  ddButHolder = top.document.createElement('div');
  ddButHolder.className  = buttons[0];
  for (i = 1; i < buttons.length; i++)
  {
    ddBut                      = top.document.createElement('button');
    ddBut.id                   = buttons[i][1];
    ddBut.onclick              = buttons[i][2]
    ddButText                    = top.document.createTextNode(buttons[i][0]);
    ddBut.appendChild(ddButText);
    ddButHolder.appendChild(ddBut);
  }


  // Finish associating the objects
  ddTextHolder.appendChild(ddText);
  dialogDiv.appendChild(ddTextHolder);
  dialogDiv.appendChild(ddButHolder);
  top.document.body.appendChild(dialogDiv);

}

function wwAck2(wwType, wwURI, wwFrame, wwText, wwBut1Text, wwBut2Text, wwClass, wwQuery, wwHandler) {
	if (wwType == '')     { wwType     = 1; }
	if (wwText  == '')    { wwText     = 'Please confirm action.'; }
	if (wwClass == '')    { wwClass    = 'wwClass'; }
	if (wwFrame == '')    { wwFrame    = top.document; }
	if (wwBut1Text == '') { wwBut1Text = 'Yes'; }
	if (wwBut2Text == '') { wwBut2Text = 'No'; }


	wwURIglob   = wwURI;
	wwFrameglob = wwFrame;
        wwQueryglob = wwQuery;
        wwHandlerglob = wwHandler;        
	if (document.getElementById) {
		if (document.getElementById('wwDialog')) { wwCloseAck2(); }
		dialogDiv                  = top.document.createElement('div');
		dialogDiv.style.position   = 'absolute';
		dialogDiv.style.top        = '100px';
		dialogDiv.style.left       = '100px';
		dialogDiv.style.zIndex     = '5000';
		dialogDiv.style.background = '#eee';
		dialogDiv.id               = 'wwDialog';
		dialogDiv.className        = wwClass;
		ddTextHolder               = top.document.createElement('div');
		ddText                     = top.document.createTextNode(wwText);
		ddButHolder                = top.document.createElement('div');
		ddButHolder.className      = 'wwClassButton';
		ddBut1                     = top.document.createElement('button');
		ddBut1.id                  = 'wwButton1';
		ddText1                    = top.document.createTextNode(wwBut1Text);
		ddBut1.appendChild(ddText1);
		ddButHolder.appendChild(ddBut1);
		ddBut1.onclick = wwConfirmAck2;
		if (wwType == 2) {
			ddBut2    = top.document.createElement('button');
			ddText2   = top.document.createTextNode(wwBut2Text);
			ddBut2.id = 'wwButton2';
			ddBut2.appendChild(ddText2);
			ddButHolder.appendChild(ddBut2);
			ddBut2.onclick = wwCloseAck2;
		}
//		ddTextHolder.appendChild(ddText);
		dialogDiv.appendChild(ddTextHolder);
		dialogDiv.appendChild(ddButHolder);
		top.document.body.appendChild(dialogDiv);
	}
	return false;
}

//function cl_xmlPost(<uri>, <data>, <handler>)
//<uri> - URI of script (/script/php/somescript.php)
//<data> - Data to send (id=blah&when=now)
//<handler> - (String) name of a handler, which is called with two
//            arguments upon completion of request;
//            1 - String - The data returned
//            2 - Obj - The request object
function cl_xmlPost(uri, data, handler)
{
  var postObj = false;

  if (window.XMLHttpRequest){
    postObj = new XMLHttpRequest();
    if (postObj.overrideMimeType) { postObj.overrideMimeType('text/xml'); }
  } else if (window.ActiveXObject) {
    postObj = new ActiveXObject('Microsoft.XMLHTTP')
  } else {
    return false;
  }

  postObj.open('POST', uri, true);
  postObj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  postObj.onreadystatechange = function()
  {
    if (postObj.readyState == 4) {
      if (handler != null) {
        response = postObj.responseText;
        eval(handler + '(response, postObj);');
      }
    }
  }
  postObj.send(data);
}

