doAjax = function(){
	
	$('formajax').request({
		onComplete: function(transport) {
	    var responseText = transport.responseText;
				if(responseText.match(/index.php/))
				{
					window.location.href = transport.responseText;
				}
				else
				{
					//alert(responseText);
					DisplayAlert('AlertBox', responseText);
				}
	}});
	return false;
}

function DisplayAlert(id, message) {
	dim = Element.getDimensions(id);
	var popup_width = 300;
  var popup_height = 200;
		
	var pagesize = getPageSize();
	var viewport_width = pagesize[2];
	var viewport_height = pagesize[3];
	
	//alert(popup_width);
	//alert(popup_height);
	//alert(viewport_width);
	//alert(viewport_height);
	
	var x;
	if (popup_width >= viewport_width) {
		x = 0;
	}
	else {
		x = (viewport_width - popup_width)/2;
	}

	var y;
	if (popup_height >= viewport_height) {
		y = 0;
	}
	else {
		y = (viewport_height - popup_height)/2;
	}
	//alert(x + ','+ y);
	
	var newdiv = document.createElement("div");
	var container = document.getElementById('alertMsg');
	container.innerHTML = '';
	newdiv.innerHTML = message;
	
	container.appendChild(newdiv);

	document.getElementById(id).style.left=x+'px';
	document.getElementById(id).style.top=y+'px';
	document.getElementById(id).style.display='block';
}


getPageSize = function(){
	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}






var wordLimit = 100;
var holdText;
var disabledBox = false;

function countEm()
{
 var text1 = document.forms['form1'].elements['data'].value;
 var numberOfWords = doCount(text1);

 if(numberOfWords == wordLimit)
 {
  holdText = text1;
 }//end if

 document.forms['form1'].elements['wordcount'].value = wordLimit - numberOfWords;
 document.forms['form1'].elements['wordcount_hidden'].value = wordLimit - numberOfWords;

 //if(numberOfWords >= wordLimit)
 // disabledBox = true;
 //else
 // disabledBox = false;
 
}//end function

function doCount(textParam)
{
 //replace all instances of one-or-more spaces with a single space
 var text2 = textParam.replace(/\s+/g, ' ');

 //trim leading and tailing spaces
 while(text2.substring(0, 1) == ' ')
  text2 = text2.substring(1);
 while(text2.substring(text2.length-2, text2.length-1) == ' ')
  text2 = text2.substring(0,text2.length-1);

 var text3 = text2.split(' ');

 return text3.length;
}//end function

function maybeReset()
{
 if(disabledBox)
 {
  var currText = document.forms['form1'].elements['data'].value;
  var newLength = doCount(currText);

  //prevent user from adding words, but not taking them away
  if(newLength > wordLimit)
  {
   document.forms['form1'].elements['data'].value = holdText;
  }//end if
 }//end if
}//end function


function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*1*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}
