function wcAddComment( sTitle )
{
//	alert(sTitle);


	var hand = function(str) { xl_GetObj('addcomments').innerHTML = str;}; 
	var ajax = new Ajax(); 
//	var rand=Math.floor(Math.random()*110000001)
//	var ajaxurl = xl_BuildURLWithFormElements('m', 'bowser.pgm?task=s&r=' + sCmd + '&rnd=' + rand);
	ajax.doGet('/wiki/Comments.php?task=AddComment&Title=' + sTitle + '&rnd=' + Math.floor(Math.random()*110000001), hand); 

//	xl_AjaxUpdate('/wiki/Comments.php?task=AddComment&Title=' + sTitle + '&rnd=' + Math.floor(Math.random()*110000001), 'addcomments', loaddiv);
}


function wcLogIn( sTitle )
{
	// Submit the Ajax login request
	var ajaxurl = xl_BuildURLWithFormElements('loginform', '/wiki/Comments.php?task=LogIn&Title=' + sTitle + '&rnd=' + Math.floor(Math.random()*110000001));	
//	alert(ajaxurl);
//	xl_AjaxUpdate(ajaxurl, 'addcomments', loaddiv);

	var hand = function(str) { xl_GetObj('addcomments').innerHTML = str;}; 
	var ajax = new Ajax(); 
	ajax.doGet(ajaxurl, hand); 
}


function wcAddActualComment( sTitle )
{
	// Submit the Ajax login request
	var ajaxurl = xl_BuildURLWithFormElements('commentform', '/wiki/Comments.php?task=AddActualComment&Title=' + sTitle + '&rnd=' + Math.floor(Math.random()*110000001));	
//	alert(ajaxurl);
	xl_AjaxUpdate(ajaxurl, 'addcomments', loaddiv);

}


// Duncan's ajax code to reload the whole page
function Ajax() { 
this.req = null; 
this.url = null;
this.method = 'GET'; 
this.asynch = true; 
this.status = null; 
this.statusText = ''; 
this.postData = null; 
this.readyState = null; 
this.responseText = null;
this.responseXML = null;
this.handleResp = null;
this.responseFormat = 'text';
this.mimeType = null; 

this.init = function() { 
 if (!this.req) { 
   try { 
      this.req = new XMLHttpRequest(); 
      return this.req; 
   } 
   catch (e) { 
     try { 
      // loops through the various versions of XMLHTTP to ensure we're using the latest
			var versions = ["Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
								"Microsoft.XMLHTTP"];
			for (var i = 0; i < versions.length ; i++)
			{
        		try 
				{
		   		  // try to create the object
		   		  // if it doesn't work, we'll try again
		   		  // if it does work, we'll save a reference to the proper one to speed up future instantiations
					this.req   = new ActiveXObject(versions[i]);
					return this.req; 
				}
				catch (e) 
				{
						// trap -  try next one
				} 
			}	
	  }		
	 catch (e)
	 { 
	   // do nothing 
	 } 
	 
   }
   // Still no HTTPRequest object- return false. 
   if (!this.req) return false; 	
  } 
};

this.setMimeType = function(mimeType) { 
 this.mimeType = mimeType; 
};  

this.doReq = function() { 


 if (!this.init()) { 
  alert('Could not create XMLHttpRequest Object.');
  return; 
 } 
   
 
 this.req.open(this.method, this.url, this.asynch); 
 if (this.mimeType) { 
   try { 
     req.overrideMimeType(this.mimeType); 
   }
   catch (e)
   { 
  	  // couldn't override mimeType- IE6 or Opera.  
   }
 }    
 var self = this;   // Fix loss of scope for callback function
 
 this.req.onreadystatechange = function() { 
 
 
  if (self.req.readyState == 4) { 
   switch (self.responseFormat) { 
    case 'text' : 
     resp = self.req.responseText;
     break;
    case 'xml': 
     resp = self.req.responseXML; 
     break; 
    case 'object': 
     resp =req; 
     break; 
   } 
   if (self.req.status >= 200 && self.req.status <= 299) { 
     self.handleResp(resp); 
    }  
   else {
     self.handleErr(resp);  
    }        
  } 
 }; 
 
 this.req.send(this.postData);     
};  
 
 
this.handleErr = function() { 
  var errorWin; 
  try { 
    errorWin = window.open('', 'errorWin'); 
    errorWin = document.body.innerHTML = this.responseText; 
  } 
  catch (e) { 
   alert('An error occurred, but the error message cannot be ' 
         + 'displayed. This is probably because of your browser\'s ' 
         + 'pop-up blocker. Blah blah. \n'
         + 'Status code: ' + this.req.status + '\n' 
         + 'Status description: ' + this.req.statusText); 
  }         
}; 

this.setHandlerErr = function(funcRef) { 
  this.handleErr = funcRef; 
}; 

this.setHandlerBoth = function(funcref) { 
  this.handleResp = funcRef; 
  this.handleErr = funcRef; 
}; 

this.abort = function() { 
 if (this.req) { 
  this.req.onreadystatechange = function() {}; 
  this.req.abort(); 
  this.req = null; 
 }
};   

this.doGet = function(url, hand, format) { 
  this.url = url; 
  this.handleResp = hand; 
  this.responseFormat = format || 'text'; 
  this.doReq(); 
};                    
}

function wcShowFeedbackForm()
{
	var str;

	str = "<form method=\"post\" action=\"/contactme.php\" enctype=\"multipart/form-data\">" + 
   "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">" + 
      "<tr>" + 
         "<td align=\"right\">Your Name:</td>" + 
         "<td><input name=\"Name\" style=\"width: 400\"></td>" + 
      "</tr>" + 
      "<tr>" + 
         "<td align=\"right\">Your E-Mail:</td>" + 
         "<td><input name=\"Email\" style=\"width: 400\"></td>" + 
      "</tr>" + 
      "<tr>" + 
         "<td align=\"right\" valign=\"top\">Message:</td>" + 
         "<td><textarea name=\"Message\" rows=\"5\" cols=\"30\" style=\"width: 400\"></textarea></td>" + 
      "</tr>" + 
//      "<tr>" + 
//         "<td align=\"right\">Security Code:</td>" + 
//         "<td valign=\"middle\"><input name=\"SecurityCode\" size=\"4\">" + 
//            "<img src=\"/contactme.php?captcha\" align=\"absmiddle\" " + 
//            "style=\"cursor: pointer; border: 1px solid #000000;\" " + 
//            "onclick=\"this.src='/contactme.php?captcha'+(new Date()).getTime();\" " + 
//            "alt=\"Code\" title=\"Click to generate a new code\"> " + 

//            "<span id=\"speech\"></span> " + 
//         "</td> " + 
//      "</tr> " + 
      "<tr> " + 
         "<td></td> " + 
         "<td><br><input type=\"submit\" value=\"Send Message\"></td> " + 
      "</tr></table></form>";

	xl_GetObj('feedbackform').innerHTML = str;
}

function wcLoadDiv(mydiv, response)
{
  xl_GetObj(mydiv).innerHTML = response;
}


function wcVerseRollover( oSpan )
{
	// turn on the focus property for this 
	// span
	oSpan.bFocus = 1;

	// If the verse div does not exist,
	// then create it and launch the Ajax to load it
	wcCreateDiv('testdiv', 'blah', 200, 200, oSpan.offsetLeft, oSpan.offsetTop);

//	alert(oSpan.offsetLeft);

	// Now launch the timeout function which checks to
	// see if the focus is still on this div and if 
	// so it will show the div.
}

function wcVerseRollout( oSpan )
{
	// turn off the focus property
	oSpan.bFocus = 0;
}


function wcCreateDiv(id,html,width,height,left,top) 
{
 var newdiv = document.createElement('div');
 newdiv.setAttribute('id',id);
 if(width)
 {
   newdiv.style.width = 300;
 }
 if(height)
 {
   newdiv.style.height = 300;
 }
 if((left || top)||(left && top))
 {
 newdiv.style.position = "absolute";
   if(left)
   {
     newdiv.style.left = left;
   }
   if(top)
   {
     newdiv.style.top = top;
   }
 }
 newdiv.style.background = "#00C";
 newdiv.style.border = "4px solid #000";
 if(html)
 {
   newdiv.innerHTML = html;
 } else {
   newdiv.innerHTML = "nothing"
 }
 document.body.appendChild(newdiv);
} 