function debugObj(obj)
{
	var count = 0;
	var str = "";

	for(prop in obj)
	{
		count++;
		str += prop + "," + obj[prop] + "\n";

		if(count>19)
		{
			alert(str);
			count = 0;
			str = "";
		}
	}
	alert(str);
}
/**
 * Ajax calls
 * @todo Clean up js at the top before // ---- NON AJAX
 */
var orig_rating = new Object();

function get_el(el_id)
{
	return document.getElementById(el_id);
}

// Do rating
function r(rating,content_id)
{
	//get_el('rating_'+content_id).innerHTML = 'Loading...';
	do_ajax('rate_content',rating+','+content_id);
}

// Rating result
function r_result(id,str)
{
	get_el(id).innerHTML = str;
}

// Rating highlight
function r_h(content_id,star)
{
	// This caches the original rating before rollover change
	if ( typeof orig_rating[content_id] == 'undefined' )
	{
		orig_rating[content_id] = get_el('rating_'+content_id).innerHTML;
	}

	//var desc = new Array ('rubbish','not great','ok','good','excellent');
	//get_el('rating_txt_'+content_id).innerHTML = "It's "+desc[star-1]+':';
	for ( var i=1; i <= 5 ; i ++ )
	{
		get_el('img_'+content_id+'_'+i).src = template_root+'/gfx/star_'+(i<=star?'red':'grey')+'.gif';
	}
}

// Rating reset
function r_r(content_id)
{
	//get_el('rating_txt_'+content_id).innerHTML = 'Rating:';
	get_el('rating_'+content_id).innerHTML = orig_rating[content_id];
}

// ------------------ NON AJAX -------------------
/**
 * toggles the input size for a tiny mce editor
 * @param {int} width
 * @param {int} height
 */
function toggle_input_size(width,height)
{
 	editor = document.getElementById("mce_editor_0");
    if (editor) 
    {
    	editor.style.width = width+'px';
        editor.style.height = height+'px';
    }
}


/**
 * Add multiple onload event functions
 */
function add_load_event(function_name) 
{
	var current_onload = window.onload;
	if (typeof window.onload != 'function') 
	{
		window.onload = function_name;
	}
	else 
	{
		window.onload = function() 
		{
			current_onload();
			function_name();
		}
	}
}


/**
 * Show/hide divs
 * @param {string} ids - a string of , seperated element ids
 */
function show_hide(ids)
{
	var list_of_ids = new Array;
	
	// check for , in id
	if( ids.indexOf(',') )
	{
		list_of_ids = ids.split(',');
	}
	
	// do show/hide based on css display = none
	// it will assume that the element is showing if no css is found
	if( list_of_ids.length > 0 )
	{
		for(i=0; i < list_of_ids.length; i++)
		{
			// show hide ele
			show_hide_ele(list_of_ids[i]);
		}
	}
	else // one id
	{
		// show hide ele
		show_hide_ele(ids);
	}
}

/**
 * Subset of show_hide
 * @param {id} element id
 * @todo add swap attribute etc
 */
function show_hide_ele(id)
{
		var ele = document.getElementById(id);
		
		if(ele.style.display != 'none')
		{
			ele.style.display = 'none';
		} 
		else
		{
			ele.style.display = 'block';
		}
}

function force_show_hide(id, action)
{	
	var ele = document.getElementById(id);
	
	if(ele.style.display != 'none' && action == 'hide')
	{
		ele.style.display = 'none';
	} 
	else if(ele.style.display != 'block' && action == 'show')
	{
		ele.style.display = 'block';
	}
}

function force_timed_show_hide(id, action)
{
	setTimeout("force_show_hide('"+id+"', '"+action+"')", 80 );
}

/**
 * show_timed_ele - shows an element for a amount of time 
 * @param {Object} ele_id
 * @param {Object} time
 */
function show_timed_ele(ele_id, time)
{
	var ele = document.getElementById(ele_id);
	
	if( ele.style.display != 'block')
	{
		ele.style.display = 'block';
		setTimeout("force_show_hide('"+ele_id+"','hide')", time);
	}
}

/**
 * Swaps innerHTML by id
 * @param {id} element id
 */
function swap_html(id,content_1,content_2)
{
	var ele = document.getElementById(id);
	if(ele.innerHTML ==  content_1)
	{
		ele.innerHTML = content_2;
	}
	else
	{
		ele.innerHTML = content_1;
	}
	
}

/**
 * Woyano_pop_up
 * @param {string} window_target = path to file
 * @param {string} window_name
 * @param {int} int window_width
 * @param {int} int window_height
 */
var pop_win; 
function pop_up_window(window_target, window_width, window_height)
{
	
	// check for ? to make sure the url is correct
	var op = '?';
	if( window_target.indexOf('?') )
	{
		op = '&';
	}

	if ( pop_win )
	{
		pop_win.focus();	
	}

	//open window
	pop_win = window.open(window_target+op+'pop_up=true', 'pop_win', 'width='+window_width+',height='+window_height+'no,menubar=no,status=no,resizable=yes,scrollbars=yes');

}

/**
 * To be called from pop_ups to fill in a element on the 'window.opener' window
 * to make life easy
 * @param {string} id the element id to be filled
 * @param {string} html the content filler
 */
function update_ele_content(id,html)
{
	// alert(window.opener.document.getElementById(id) + ' '+id); // <-- for Checking if an element exists 
	window.opener.document.getElementById(id).innerHTML = html;
}

// ------------------ AJAX -------------------

/**
 * Flag as adult
 * @param {Object} content_id
 */
function flag_as_adult(content_id)
{
	do_ajax('flag_as_adult',content_id);
}

/**
 * Flag as bad
 * @param {Object} content_id
 */
function flag_as_bad(content_id)
{
	do_ajax('flag_as_bad',content_id);
}

// ------

// Mark as featured
function f(content_id,nudge)
{
	do_ajax('feature_this',content_id+','+nudge);
}

// Mark as Unfeatured
function uf(content_id)
{
	do_ajax('unfeature_this',content_id);
}

// COMMENTS related functions:

/**
 * Clears the add comments details
 * @deprecated
 */
function clear_add_comments()
{
	c = get_el('add_comment');
	c.innerHTML = '';
	
	pid = get_el('parent_comment_id');
	pid.value = '';
	
	return true;
}

/**
 * 
 * @param {integer} comment_id
 */
function comment_up(comment_id)
{
	//do ajax
	do_ajax('comment_increase_rating', comment_id);
}

/**
 * 
 * @param {integer} comment_id
 */
function comment_down(comment_id)
{
	//do ajax
	do_ajax('comment_decrease_rating', comment_id);
}

/**
 * Subits the asset form to upload photos!
 */
function submit_asset_content()
{
	
	// get all forms elements
	var form_ele = get_el('asset_form');
	var form_elements = '';
	var error = '';
	var ele = '';
	
	for (var i=0; i<form_ele.length; i++)
	{
		ele = form_ele.elements[i];
		
		if( ele.getAttribute("name") == 'subject'&& ele.value.length == 0 )
		{
			error += "Title cannot be empty!\n";
		}
		if( ele.getAttribute("name") == 'upload'&& ele.value.length == 0 )
		{
			error += "File location is empty! Please choose an asset to upload.\n";
		}
		if( ele.getAttribute("name") == 'body'&& ele.value.length == 0 )
		{
			error += "Description cannot be empty! \n";
		}
		
		
		form_elements += ele.value+',';
	}
	
	if( error.length > 0 )
	{
		alert(error);
		return;
	}
	/*
	do_ajax('upload_asset_photo', form_elements);
	*/
	form_ele.submit();
}

// Globals for comment editing
var ORIG_C = "";
var REPLY_ID = "";

function edit_comment(comment_id)
{
	var comment_input = cancel_comment_action();
	add_title(0);
	reply_title(0);
	
	var comment = get_el('comment_'+comment_id);
	ORIG_C = trim( comment.innerHTML.replace(/<br( *?)\/?>/gi, "") );
	comment.innerHTML = comment_input.innerHTML;
	comment_input.innerHTML = '';

	make_edit_form(comment_id, ORIG_C);
}

function reply_comment(username, comment_id)
{
	var comment_input = cancel_comment_action();

	add_title(0);
	reply_title(1, username);
	
	REPLY_ID = comment_id;
	reply_box(0, REPLY_ID);
	
	var reply_input = get_el('reply_input_'+comment_id);
	reply_input.innerHTML = comment_input.innerHTML;
	comment_input.innerHTML = '';
	
	make_reply_form(reply_input, comment_id);
}

function add_title(x)
{
	var add_title = get_el('add_comment_title');
	if (x==1)
	{
		add_title.style.display = 'block';
	}
	else
	{
		add_title.style.display = 'none';
	}
}

function reply_title(x, username)
{
	var username = (username == null) ? "" : username;
	
	var reply_title = get_el('replying_to_title');
	var un = get_el('replying_to_username');
	un.innerHTML = username;
	
	if (x==1)
	{
		reply_title.style.display = 'block';
	}
	else
	{
		reply_title.style.display = 'none';
	}
}

function reply_box(x, comment_id)
{
	var comment_id = (comment_id == null) ? "" : comment_id;
	var reply_box = get_el('reply_'+comment_id);
	
	if (x==1)
	{
		reply_box.style.display = 'block';
	}
	else
	{
		reply_box.style.display = 'none';
	}
}

function cancel_comment_action()
{
	var comment_input = get_el('comment_input');
	if ( comment_input.innerHTML == '' )
	{
		var comment_form = get_el('add_comment_form');
		var comment_div = comment_form.parentNode;
		reset_form(comment_input, comment_form);
		
		if ( ORIG_C != '' )
		{
			comment_div.innerHTML = ORIG_C.replace(/\n/g, "<br>\n");
			ORIG_C = '';
		}
		
		if ( REPLY_ID != '' )
		{
			reply_box(1, REPLY_ID);
			REPLY_ID = '';
		}
	}
	return comment_input;
}

function reset_form(comment_input, comment_form)
{
	comment_input.innerHTML = comment_form.parentNode.innerHTML;
	comment_form.parentNode.innerHTML = '';
	add_title(1);
	reply_title(0);
	make_add_form(comment_input);
}


function make_add_form(comment_input)
{
	var comment_form = get_el('comment_form');
	
	// if comment_id node exists remove it
	var c_id_input = get_el('comment_id');
	if ( c_id_input != null )
	{
		c_id_input.parentNode.removeChild(c_id_input);
	}
	
	// if parent_comment_id node doesn't exist then append it and clear its value
	var p_c_id_input = get_el('parent_comment_id');
	if ( p_c_id_input == null )
	{
		p_c_id_input = document.createElement('input');
		p_c_id_input.setAttribute('id', 'parent_comment_id');
		p_c_id_input.setAttribute('name', 'parent_comment_id');
		p_c_id_input.setAttribute('type', 'hidden');
		comment_form.appendChild(p_c_id_input);
	}
	p_c_id_input.setAttribute('value', '');
	
	var sub_but = get_el('add_comment_submit');
	sub_but.value = 'Add Comment';
	
	var text_area = get_el('add_comment');
	text_area.innerHTML = '';
	
	var cancel = get_el('cancel_edit');
	cancel.innerHTML = '';

	var action = get_el('do_add_comment');
	if ( action == null )
	{
		action = document.createElement('input');
		action.setAttribute('id', 'do_add_comment');
		action.setAttribute('name', 'do_add_comment');
		action.setAttribute('type', 'hidden');
		action.setAttribute('value', 'true');
		comment_form.appendChild(action);
	}
	
	action = get_el('do_edit_comment');
	if ( action != null )
	{
		comment_form.removeChild(action);
	}
}


function make_edit_form(comment_id, orig_c)
{
	var comment_form = get_el('comment_form');
	
	// if comment_id node doesn't exist then append it and set it
	var c_id_input = get_el('comment_id');

	var add_node_comment_id = false;
	if ( navigator.appName == 'Microsoft Internet Explorer' )
	{
		if ( c_id_input == null || c_id_input.getAttribute('id') == null || c_id_input.getAttribute('id') == "" )
		{
			add_node_comment_id = true;
		}
	}
	else
	{
		if ( c_id_input == null )
		{
			add_node_comment_id = true;
		}
	}
	
	if (add_node_comment_id)
	{
		c_id_input = document.createElement('input');
		c_id_input.setAttribute('id', 'comment_id');
		c_id_input.setAttribute('name', 'comment_id');
		c_id_input.setAttribute('type', 'hidden');
		comment_form.appendChild(c_id_input);
	}
	
	c_id_input.setAttribute('value', comment_id);

	// if parent_comment_id node exists then remove
	var p_c_id_input = get_el('parent_comment_id');

	if ( p_c_id_input != null )
	{
		p_c_id_input.parentNode.removeChild(p_c_id_input);
	}
	
	var sub_but = get_el('add_comment_submit');
	sub_but.value = 'Submit Comment';
	
	var text_area = get_el('add_comment');
	text_area.innerHTML = orig_c;
	text_area.focus();
	
	var cancel = get_el('cancel_edit');
	cancel.innerHTML = '<input type="button" onclick="cancel_comment_action()" value="Cancel" />';

	var action = get_el('do_add_comment');
	if ( action != null )
	{
		action.parentNode.removeChild(action);
	}
	
	action = get_el('do_edit_comment');
	if ( action == null )
	{
		action = document.createElement('input');
		action.setAttribute('id', 'do_edit_comment');
		action.setAttribute('name', 'do_edit_comment');
		action.setAttribute('type', 'hidden');
		action.setAttribute('value', 'true');
		comment_form.appendChild(action);
	}
	
	
}


function make_reply_form(reply_input, comment_id)
{
	var comment_form = get_el('comment_form');
	
	// if comment_id node exists then remove
	var c_id_input = get_el('comment_id');
	if ( c_id_input != null )
	{
		c_id_input.parentNode.removeChild(c_id_input);
	}
	
	// if parent_comment_id node doesn't exist then append it and set it
	var p_c_id_input = get_el('parent_comment_id');
	if ( p_c_id_input == null )
	{
		p_c_id_input = document.createElement('input');
		p_c_id_input.setAttribute('id', 'parent_comment_id');
		p_c_id_input.setAttribute('name', 'parent_comment_id');
		p_c_id_input.setAttribute('type', 'hidden');
		comment_form.appendChild(p_c_id_input);
	}
	p_c_id_input.setAttribute('value', comment_id);
	
	var sub_but = get_el('add_comment_submit');
	sub_but.value = 'Reply to Comment';
	
	var text_area = get_el('add_comment');
	text_area.innerHTML = '';
	text_area.focus();
	
	var cancel = get_el('cancel_edit');
	cancel.innerHTML = '<input type="button" onclick="cancel_comment_action()" value="Cancel" />';

	var action = get_el('do_add_comment');
	if ( action == null )
	{
		action = document.createElement('input');
		action.setAttribute('id', 'do_add_comment');
		action.setAttribute('name', 'do_add_comment');
		action.setAttribute('type', 'hidden');
		action.setAttribute('value', 'true');
		comment_form.appendChild(action);
	}
	
	action = get_el('do_edit_comment');
	if ( action != null )
	{
		comment_form.removeChild(action);
	}
}


/**
 * 
 * @param {integer} comment_id
 * @param {integer} time
 */
function edit_comment_countdown(comment_id, time)
{
	var el = get_el('time_left_'+comment_id);
	
	if (time > 0)
	{
		el.innerHTML = time;
		time--;
		setTimeout("edit_comment_countdown("+comment_id+", "+time+")", 1000);
	}
	else
	{
		var el = get_el('edit_'+comment_id);
		el.className = 'edit';
		
		var comment = get_el('comment_id')
		if ( comment != null )
		{
			cancel_comment_action();			
		}
	}
}


/* 
 * Javascript Trim, LTrim and RTrim Functions (http://www.somacon.com/p355.php)
 */
function ltrim(str)
{ 
 for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
 return str.substring(k, str.length);
}
function rtrim(str)
{
	for (var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str)
{
 return ltrim(rtrim(str));
}

function isWhitespace(charToCheck)
{
 var whitespaceChars = " \t\n\r\f";
 return (whitespaceChars.indexOf(charToCheck) != -1);
}
/* End of Javascript Trim, LTrim and RTrim Functions */

/**
 * 
 * @param {string} name
 */
function jump_to_anchor(name)
{
	window.location.hash = name;
}

/**
 * Load a content template in the editor
 * @param {string} template_id
 */
var have_set_thumb = false;
function insert_asset(id,type,cat,title)
{
	if (typeof title == 'undefined') 
	{
		title = '';
	}
	setTimeout("do_ajax('insert_asset','"+id+","+type+","+cat+","+title+"')",1);
	
	if ( cat != 'pdf' && ! have_set_thumb )
	{
		set_as_thumb(id,true);
	}
	
	if ( cat == 'image' )
	{
		toggle_input_size(725,400);	
	}
}

function map_thump_path(id)
{
	var els = id.split('');
	var dirs = '';
	for ( i=0; i<3; i++ )
	{
		dirs += els[i] + '/';
	}
	return '/sites/woyano/data/thumbnails/'+dirs+id+'-thumb.png';
}

function set_as_thumb(id,no_alert)
{
	get_el('internal_thumb').value = id;
	get_el('thumb_preview').innerHTML = '<img src="'+map_thump_path(id)+'" width="70" height="70" class="std_image">';
	if ( ! no_alert )
	{
		//alert('Set image as thumbnail! Save content to see changes.');
		close_popup();
	}
}

function close_popup()
{
	$('#'+lastPopup).TransferTo(
		{
			to:lastPopup+'-opener',
			className:'transferer2', 
			duration: 200
		}
	).hide();
	toggle_selects('show');
}

function update_tinymce(html_str)
{
	tinyMCE.setContent(tinyMCE.getContent()+html_str+'<br /><br />');
	tinyMCE.execCommand('mceFocus',true,'mce_editor_0');
	
	close_popup();

	// One day we would like this to work :(
	//tinyMCE.execInstanceCommand('mce_editor_0','mceInsertContent', false, html_str+'<br />');
}

/* ~~~~ BLOGROLL EDITING ~~~~~ */

/**
 * 
 * @param {string} link_id
 */
function edit_blog_link(link_id)
{
	// change link to input text
	var edit_title_box = get_el('edit_title_box_'+link_id);
	var edit_title_input_box = get_el('edit_title_input_box_'+link_id);
	
	edit_title_box.style.display = 'none';
	edit_title_input_box.style.display = 'block';	

	// change title to input text
	var edit_link_box = get_el('edit_link_box_'+link_id);
	var edit_link_input_box = get_el('edit_link_input_box_'+link_id);
	
	edit_link_box.style.display = 'none';
	edit_link_input_box.style.display = 'block';
	
	// change edit button to save edit form
	var edit_button_box = get_el('edit_button_box_'+link_id);
	var save_edit_box = get_el('save_edit_box_'+link_id);
	
	edit_button_box.style.display = 'none';
	save_edit_box.style.display = 'block';
	
	// change delete button to cancel button
	var del_button_box = get_el('del_button_box_'+link_id);
	var cancel_edit_box = get_el('cancel_edit_box_'+link_id);
	
	del_button_box.style.display = 'none';
	cancel_edit_box.style.display = 'block';
}

/**
 * 
 * @param {string} link_id
 */
function cancel_edit_link(link_id)
{
	var edit_title_box = get_el('edit_title_box_'+link_id);
	var edit_title_input_box = get_el('edit_title_input_box_'+link_id);
	
	edit_title_box.style.display = 'block';
	edit_title_input_box.style.display = 'none';	
	
	// change title to input text
	var edit_link_box = get_el('edit_link_box_'+link_id);
	var edit_link_input_box = get_el('edit_link_input_box_'+link_id);
	
	edit_link_box.style.display = 'block';
	edit_link_input_box.style.display = 'none';
	
	// change edit button to save edit form
	var edit_button_box = get_el('edit_button_box_'+link_id);
	var save_edit_box = get_el('save_edit_box_'+link_id);
	
	edit_button_box.style.display = 'block';
	save_edit_box.style.display = 'none';
	
	// change delete button to cancel button
	var del_button_box = get_el('del_button_box_'+link_id);
	var cancel_edit_box = get_el('cancel_edit_box_'+link_id);
	
	del_button_box.style.display = 'block';
	cancel_edit_box.style.display = 'none';
}


/* ~~~~ AUTO LOOK UPS ~~~~~ */

/**
 * SEARCH autocomplete_lookup
 * @param {Object} search_input
 */
function search_autocomplete_lookup(search_input)
{
	//vars
	if( search_input.length >= 1)
	{
		// slight lag on showing auto complete
		setTimeout("do_ajax('search_autocomplete', '"+search_input+"');", 500);
	}
	else
	{
		force_show_hide('search_autocomplete','hide');
	}
}


/**
 * USERNAME autocomplete_lookup
 * @param {Object} search_input
 */
function username_autocomplete_lookup(search_input)
{
	var submit_value = '';

	if( search_input.length >= 1)
	{
			// split by , and just submit the last value
			if( search_input.indexOf(",") > 0)
			{
				submit_value = search_input.split(",");
				submit_value = submit_value[(submit_value.length-1)];
			}
			else
			{
				submit_value = search_input;
			}

		if( submit_value.length > 0 && submit_value != ' ') // just check you don't search for nothing
		{
			// slight lag on showing auto complete
			setTimeout("do_ajax('username_autocomplete', '"+submit_value+"');", 500);
		}
	}
	else
	{
		force_show_hide('username_autocomplete','hide');
	}
}

/**
 * TAGS autocomplete_lookup
 * @param {Object} search_input
 */
function tags_autocomplete_lookup(search_input)
{
	var submit_value = '';

	//vars
	if( search_input.length >= 1)
	{
			// split by , and just submit the last value
			if( search_input.indexOf(",") > 0)
			{
				
				submit_value = search_input.split(",");
				submit_value = submit_value[(submit_value.length-1)];
			}
			else
			{
				submit_value = search_input;
			}

		if( submit_value.length > 0 && submit_value != ' ') // just check you don't search for nothing
		{
			// slight lag on showing auto complete
			setTimeout("do_ajax('tags_autocomplete', '"+submit_value+"');", 500);
		}
	}
	else
	{
		force_show_hide('tags_autocomplete','hide');
	}
}

/**
 * GEO TAGS autocomplete_lookup
 * @param {Object} search_input
 */
function geo_tags_autocomplete_lookup(search_input)
{

	var submit_value = '';

	//vars
	if( search_input.length >= 1)
	{
			// split by , and just submit the last value
			if( search_input.indexOf(",") > 0)
			{
				
				submit_value = search_input.split(",");
				submit_value = submit_value[(submit_value.length-1)];
			}
			else
			{
				submit_value = search_input;
			}

		if( submit_value.length > 0 && submit_value != ' ') // just check you don't search for nothing
		{
			// slight lag on showing auto complete
			setTimeout("do_ajax('geo_tags_autocomplete', '"+submit_value+"');", 500);
		}
	}
	else
	{
		force_show_hide('geo_tags_autocomplete','hide');
	}
}


/**
 * Fills a element with content from the auto complete drop down menu 
 * used by all dropdown "menus"
 * @param {Object} ele
 * @param {Object} hide_ele
 * @param {Object} content
 * @param {bool} prepend
 */
function fill_form_from_ac(ele, hide_ele, content, prepend)
{
	fill_ele(ele, content, prepend);
	
	force_show_hide(hide_ele,'hide');
	document.getElementById(ele).focus();
}

/**
 * Fills an element with content
 * @param {string} ele - name of element
 * @param {string} content
 */
function fill_ele(ele, content, prepend)
{
	// get var
	var ele = get_el(ele);
	var prepend_value = '';
	var comma = '';
	
	// fill element by type
	if( ele.tag == 'textarea' )
	{
		if( prepend == 'true')
		{
			prepend_value = ele.innerHTML;
		}
		
		if(prepend_value.length > 0)
		{
			comma = ',';
		}
		
		ele.innerHTML = prepend_value+' '+content+comma;
	}
	else
	{
		if( prepend == 'true' && ele.value.length > 1)
		{
			prepend_value = ele.value;
		}
		
		if(prepend_value.length > 0)
		{
			comma = ',';
		}
		
		// do check for 1st char in a search and strip it before adding the seach results on
		if( prepend_value.indexOf(",") > 0 )
		{
			last_search = prepend_value.split(",");
			//if( last_search[(last_search.length-1)].length <= 3 ) // dump last value
			//{
				last_search.pop(); // drop last entry
			//}
			
			// rejoin this way because .join ain't doing what i want it to X(
			prepend_value = '';
			for(i=0; i<last_search.length; i++ )
			{
					prepend_value += last_search[i]+',';		
			}
		}
		else
		{
			prepend_value = '';
		}

		// fill the element
		ele.value = prepend_value+content+comma;
	}
}

function login_alert()
{
	alert('Oops! You need to login to do that.');	
}

/**
 * MAIL TO!
 * populates the "to" field when your messaging
 * @param {string} name
 */
function pop_from_address_book(name)
{
	fill_ele('to_field', name, true);
}

/**
 * Get version of IE user is using
 */
function getIEVersionNumber()
{
	var ua = navigator.userAgent;
	var MSIEOffset = ua.indexOf("MSIE ");
	if (MSIEOffset == -1)
	{
		return 0;
	}
	else
	{
		return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));	
	}
}

function clear_search_box(search_box)
{
	if ( search_box.value == 'search woyano' || search_box.value == 'search my site' || search_box.value == 'your email' )
	{
		search_box.value = '';
		search_box.style.color = '#000000';
	}
}

function mt(content_id,my_taste,training,no_session)
{	
	if ( no_session )
	{
		alert('Oops! Please login to use MyTaste');
		return;	
	}
	
	if ( training )
	{
		var my_text = 'Training';
	}
	else
	{
		var my_text = 'Loading';
	}
	
	get_el('my_taste_'+content_id).innerHTML = my_text + ' <img src="/sites/woyano/template/uk/gfx/ajax-loader.gif" class="va_c">';
	do_ajax('my_taste',content_id+','+my_taste+','+training);

}

function load_iframe(iframe_id,url)
{
    $('#'+iframe_id).attr('src',url);
    $('#'+iframe_id).attr('width',560);
    $('#'+iframe_id).attr('height',260);
}

function toggle_selects(hide_show)
{
	var collection = document.getElementsByTagName('select');
	for ( var i=0; i< collection.length; i++ )
	{
		collection[i].style.display = (hide_show == 'hide' ? 'none' : 'inline');
	}
}

// Fixes bug that was affecting add content screen
function go_hash(my_hash)
{
	setTimeout("location.hash = '"+my_hash+"';",100);
}

/* ADSENSE FUNCTIONS */
var adsense_default = 'null';
function adsense_set_default(id)
{
	adsense_default = id;
}

function adsense_save_default()
{
	if (adsense_default != 'null')
	{
		do_ajax('adsense_save_default', adsense_default);
		adsense_default = 'null';
	}
}

/* Alex: some form field validation functions */
function isEmailAddr(elem, msg)
{
	var str = elem.value;
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if (!str.match(re))
	{
		alert(msg);
		return false;
	}
	else
	{
		return true;
	}
}

function isNotEmpty(elem, msg)
{
	var str = elem.value;
	var re = /.+/;
	if (!str.match(re))
	{
		alert(msg);
		return false;
	}else{
		return true;
	}
}

function oneIsNotEmpty(elem1, elem2, msg)
{
	var str1 = elem1.value;
	var str2 = elem2.value;
	var re = /.+/;
	if (!str1.match(re) && !str2.match(re))
	{
		alert(msg);
		return false;
	}else{
		return true;
	}
}

function isLength(elem, len, msg)
{
	var str = elem.value;
	if (str.length != len)
	{
		alert(msg);
		return false;	
	}
	return true;
}

function isChecked(elem, msg)
{
	checked = elem.checked;
	if (!elem.checked)
	{
		alert(msg);
		return false;
	}else{
		return true;
	}
}

function confirm_action(question,url)
{
	if (confirm(question))
	{
		go(url);
	}
}

function go(url)
{
	location.href = url;
}

function confirm_form_action(question)
{
	if (confirm(question))
	{
		return true;
	}
	return false;
}

function do_ajax_loader(action, args, id)
{
	get_el(id).innerHTML = '<img src="/sites/woyano/template/uk/gfx/ajax-loader.gif\"/>';
	do_ajax(action, args);
}