/**
* Standard Javascript routines for 44I CMS
*
* Copyright (c)2008 44 Interactive. All Rights Reserved.
*
* SVN File: $Id: ffi.js 271 2008-08-26 14:37:56Z Mike Neugebauer $
* @author $Author: Mike Neugebauer $
* @version $Revision: 271 $
* @lastrevision $Date: 2008-08-26 09:37:56 -0500 (Tue, 26 Aug 2008) $
* @modifiedby $LastChangedBy: Mike Neugebauer $
* @lastmodified $LastChangedDate: 2008-08-26 09:37:56 -0500 (Tue, 26 Aug 2008) $
* @filesource $URL: svn+ssh://miken@svnhost.44i-dev.com/svnhome/base/branches/dakotadrafting/js/ffi.js $
*/

var dayNames = [ 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday' ];
var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July',
	'August', 'September', 'October', 'November', 'December' ];

function ffiConfirmAndGo( msgIn, locIn ) {
	if ( confirm( msgIn ) ) {
	window.location = locIn;
	}
	return;
}

function ffiGetDayName( xd )
{	// accepts date object
	calc = xd.getDay();
	return ( ( calc >=0 && calc < 7 ) ? dayNames[ calc ] : '' );
}

function ffiGetMonthName( xd )
{	// accepts date object
	calc = xd.getMonth();
	return ( ( calc >=0 && calc < 12 ) ? monthNames[ calc ] : '' );
}

function ffiShow( domObj )
	{
		if ( ( typeof domObj ) != 'object' )
			{
				domObj = document.getElementById( domObj );
			}

		domObj.style.visibility = 'visible';
		domObj.style.display = 'block';

	}

function ffiHide( domObj )
	{
		if ( ( typeof domObj ) != 'object' )
			{
				domObj = document.getElementById( domObj );
			}

		domObj.style.visibility = 'hidden';
		domObj.style.display = 'none;';

	}

function ffiSwap( domObj, newContent )
	{
		if ( ( typeof domObj ) != 'object' )
			{
				domObj = document.getElementById( domObj );
			}

		domObj.innerHTML = newContent;

	}

function ffiPageTop() {
	var chk = "" + window.location;
	if ( chk.split( "#" ).length == 2 )
	{
		window.location = window.location;
	}
	else
	{
		window.location = window.location + "#page_top";
	}

}

function ffiInvokeAjax ( div_id, url, complete_js )
{
	var load =
		new Ajax.Updater(
			div_id,
			url,
			{ onComplete:eval( complete_js )  }
			 );
}

function ffiCaptchaRegen( form_in ) {
	form_in.word_check.value = '';
	window.captcha_win.location = window.captcha_win.location;
}

String.prototype.trim = function () {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}
