var field_defaults = new Array();
field_defaults['email'] = "Email";
field_defaults['password'] = "Password";
field_defaults['q'] = "Search this blog";

function clearField(field)
{
	if (field_defaults[field.name] == field.value)
	{
		field.value = '';
	}
	
} // End function clearField

function populateField(field)
{
	if (field.value == '')
	{
		field.value = field_defaults[field.name];
	}
}


function confirm_delete()
{
	var ret = window.confirm("Please confirm removal.");

	if(ret)
	{
		return true;
	}
	else
	{
		return false;
	}
}

function is_email(email)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email))
		return true;
	else
		return false;
}

function is_numeric(num)
{
	var regexp = new RegExp('[0-9]+');
	return regexp.test(num);
}

/*********************************************************
cookie test
*********************************************************/
function _cookiesAreEnabled() {
  SetCookie( "foo", "bar" );
  if ( GetCookie( "foo" ) ) {
    DeleteCookie( "foo" );
    return true;
  } else {
    return false;
  }
}

navigator.cookiesAreEnabled = _cookiesAreEnabled;

function _getHVCCAuthID() {
  return GetCookie( "HVCCAuthID" );
}
document.getHVCCAuthID = _getHVCCAuthID;

function GetCookie( name ) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while ( i < clen ) {
    var j = i + alen;
    if ( document.cookie.substring(i, j) == arg ) return getCookieVal(j);
    i = document.cookie.indexOf( " ", i ) + 1;
    if ( i == 0 ) break;
  }
  return null;
}

function DeleteCookie( name, path, domain ) {
  if ( GetCookie( name ) ) {
    document.cookie = name + "=" +
    ( ( path ) ? "; path=" + path : "" ) +
    ( ( domain ) ? "; domain=" + domain : "" ) +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function SetCookie( name, value, expires, path, domain, secure ) {
  document.cookie = name + "=" + escape (value) +
  ( ( expires ) ? "; expires=" + expires.toGMTString() : "" ) +
  ( ( path ) ? "; path=" + path : "" ) +
  ( ( domain ) ? "; domain=" + domain : "" ) +
  ( ( secure ) ? "; secure" : "" );
}

/**
 *   Helper function for GetCookie()
 */
function getCookieVal( offset ) {
  var endstr = document.cookie.indexOf ( ";", offset );
  if ( endstr == -1 ) endstr = document.cookie.length;
  return unescape( document.cookie.substring( offset, endstr ) );
}



function doJavaScriptTest() {
window.alert( "JavaScript is enabled!" );
}


function doCookieTest() {
var msg;

if ( navigator.cookiesAreEnabled() ) {
  msg = "Cookies are enabled on this browser! ";
} else {
  msg = "Cookies are not enabled on this browser! ";
  msg += "Please enable cookies in your browser in order to login to AIIM.org. You will not be able to access systems requiring authentication if your cookies are disabled.";
}
window.alert( msg );
}

function do_cookie_test()
{
	var msg;

	if (!navigator.cookiesAreEnabled())
	{
		msg = "Cookies are not enabled on this browser! Please enable cookies in your browser.";
		alert(msg);
		return false;
	}
	else
		return true;
}

/*********************************************************
facebook share
*********************************************************/
function fbs_click(url)
{
	if(!url)
		url = location.href;
	u=url;
	t=document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');

	return false;
}

function wopen(url, name, w, h)
{
	// Fudge factors for window decoration space.
	// In my tests these work well on all platforms & browsers.
	w += 32;
	h += 96;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	// IE5 and other old browsers might allow a window that is
	// partially offscreen or wider than the screen. Fix that.
	// (Newer browsers fix this for us, but let's be thorough.)
	if (wleft < 0) 
	{
		w = screen.width;
		wleft = 0;
	}
	if (wtop < 0) 
	{
		h = screen.height;
		wtop = 0;
	}
	
	var win = window.open(url,
	name,
	'width=' + w + ', height=' + h + ', ' +
	'left=' + wleft + ', top=' + wtop + ', ' +
	'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=no, resizable=no');
	// Just in case width and height are ignored
	win.resizeTo(w, h);
	// Just in case left and top are ignored
	win.moveTo(wleft, wtop);
	win.focus();
}
/*********************************************************
misc
*********************************************************/
function show_tip_frm(element)
{
	element = $(element);
	new Effect.Appear(element);
}
function hide_tip_frm(element)
{
	element = $(element);
	new Effect.Fade(element);
}

function showMiniShare(index){
	var dLink = document.getElementById("url"+index);
	var dEmail = document.getElementById("email"+index);
	var stat;

	stat  = (dLink.style.display=="none" || dLink.style.display=="") ? "block" : "none";

	dLink.style.display = stat;
	dEmail.style.display = stat;
}

function insert_image(id, content)
{
	var oEditor = FCKeditorAPI.GetInstance(id);
	oEditor.InsertHtml('<img src="'+ content + '" />');
}   
