
var thePrompt;

var notie = false;
// is defined in top.php


function IEprompt(innertxt,def,callback) {
	var _dialogPromptID=null;
	var _blackoutPromptID=null;

  thePrompt = this;
  
  if (!def) def = '';
  
  // wrapupPrompt is called when the user enters or cancels the simulated prompt box.
  this.wrapupPrompt = function (canceled) {

    if ($.browser.msie && $.browser.version>=7.0) {
      
			// Get the value written by the user:
			val = $('#iepromptfield').val();

			// Remove the created elements
	 		$(_dialogPromptID).remove();
	 		$(_blackoutPromptID).remove();

      if (canceled) val = '';

 		 	callback(val);
    }
    return false;
  }

  // If we are in MSIE7+:
  if ($.browser.msie && $.browser.version>=7.0) {

		// First, create the two elements that comprise the dialog box and the page-covering transparent background:
		
    // Get the body tag in the dom
    var tbody = document.getElementsByTagName("body")[0];
    // create a new division
    tnode = document.createElement('div');
    // name it
    tnode.id='IEPromptBox';
    // attach the new division to the body tag
    tbody.appendChild(tnode);
    // and save the element reference in a global variable
    _dialogPromptID=document.getElementById('IEPromptBox');
    // Create a new division (blackout)
    tnode = document.createElement('div');
    // name it.
    tnode.id='promptBlackout';
    // attach it to body.
    tbody.appendChild(tnode);
    // And get the element reference
    _blackoutPromptID=document.getElementById('promptBlackout');
    // assign the styles to the blackout division.
    _blackoutPromptID.className='IEprompt_blackout';
    _blackoutPromptID.style.opacity='.9';
    _blackoutPromptID.style.filter='alpha(opacity=90)';
    _blackoutPromptID.style.height=(document.body.offsetHeight<screen.height) ? screen.height+'px' : document.body.offsetHeight+20+'px'; 
    
    // assign the styles to the dialog box
	 	_dialogPromptID.className='IEprompt_dialog whitebox';



    // This is the HTML which makes up the dialog box, it will be inserted into
    // innerHTML later. We insert into a temporary variable because
    // it's very, very slow doing multiple innerHTML injections, it's much
    // more efficient to use a variable and then do one LARGE injection.
    var tmp = '';
    tmp += '<form onSubmit="return thePrompt.wrapupPrompt()" class="body">';
	 	tmp += '<div class="message">'+innertxt+'</div>';
    tmp += '<input id="iepromptfield" name="iepromptdata" type="text" class="text" value="'+def+'">';
    tmp += '<input type="submit" class="button" value="OK">';
    tmp += '<input type="button" class="button" onClick="thePrompt.wrapupPrompt(true)" value="Cancel">';
    tmp += '</form>';
    
    // Stretch the blackout division to fill the entire document
    // and make it visible.  Because it has a high z-index it should
    // make all other elements on the page unclickable.
    _blackoutPromptID.style.height=(document.body.offsetHeight<screen.height) ? screen.height+'px' : document.body.offsetHeight+20+'px'; 
    _blackoutPromptID.style.width='100%';
    _blackoutPromptID.style.display='block';

    // Insert the tmp HTML string into the dialog box.
    // Then position the dialog box on the screen and make it visible.
    _dialogPromptID.innerHTML=tmp;
    _dialogPromptID.style.top = 
	 	 			parseInt(document.documentElement.scrollTop+(screen.height/3))+'px';
    _dialogPromptID.style.left=parseInt((document.body.offsetWidth-330)/2)+'px';
    _dialogPromptID.style.display='block';

    // Give the dialog box's input field the focus.
    document.getElementById('iepromptfield').focus();

  } else {
    // we are not using MSIE so do things "normally"
    callback(prompt(innertxt,def));
  }
}

