



$(document).ready(function() {

	if (IS_HOME_PAGE == 1 || IS_LOGIN_PAGE == 1) {
	  if ( 1 == 2 &&   IS_HOME_PAGE == 1) {
		setTimeout("activate_mousemove_fade_behavior()",720);
	  }
	  else if (IS_LOGIN_PAGE == 1) {
		if (IS_HOME_PAGE == 1) {
			setTimeout("activate_mousemove_fade_behavior()",7000);
		}
		else {
			setTimeout("activate_mousemove_fade_behavior()",4000);
		}
	  }
	}
	else if (  1 == 2    &&  CLIENT_ID > 1 && IS_DASHBOARD_PAGE !== 1) {
		$('#site_head').hover(
		  function() {
			$('#site_nav,#site_auth').show();
		  },
		  function() {
			$('#site_nav,#site_auth').hide();
		  }
		);
		$('#site_foot').hover(
		  function() {
			$('#site_links').show();
		  },
		  function() {
			$('#site_links').hide();
		  }
		);
	}

	jparse_controls(document.getElementById('site_jparse_controls'));

	$('#mini_so_slash_string_form').submit(function() {
		window.location = 'http://' + document.domain + '/j:' + $(this).find('#so_slash_string').val();
		return false;
	});

	

	// animate collarbone to descend to top of tabs_body, if there is a tabs_body
	$('.tabs_body:first').each(function() {

		_collarbone_height = $(this).prev().height();

		$(this).parents('div').each(function() {
			if (this.id == 'site_body') {
				return false;
			}
			_collarbone_height = _collarbone_height + $(this).position().top;
		});

		_collarbone_height = _collarbone_height + 1;

		$('#site_collarbone').hide();
		$('#site_collarbone').css('height',_collarbone_height + 'px');
		setTimeout("$('#site_collarbone').fadeIn(500)",300);
		

	});

	

	if (BROWSER_TYPE == 'IE') {
		$('#site_jparse_controls').find('select').hover(
		  function() { $(this).parents('span:first').css('border','1px solid #ccc'); },
		  function() { $(this).parents('span:first').css('border','0px solid #fff'); }
		);
	}

	activate_memoers();

});


function activate_mousemove_fade_behavior() {
	document.body.onmousemove = function() {
		if (BROWSER_TYPE == 'IE') {
			$('#site_head,#site_neck_container,#site_neck,#site_foot,#iqtpi_login_form_footer,.animate_on_mousmove_fade_behavior').show();
			$('#site_head,#site_neck_container,#site_neck,#site_foot,#iqtpi_login_form_footer,.animate_on_mousmove_fade_behavior').css('width','920px');
			$('#site_head,#site_neck_container,#site_neck,#site_foot,#iqtpi_login_form_footer,.animate_on_mousmove_fade_behavior').css('overflow','auto');
		}
		else {
			$('#site_head,#site_neck_container,#site_neck,#site_foot,#iqtpi_login_form_footer,.animate_on_mousmove_fade_behavior').animate({'opacity':'1'},360);
		}
		document.body.onmousemove = null;
	}
}








function jparse_controls(el) {

	// expects el to be a div containing jparse controls, as seen in /routine-qz_jparse_controls

	if (!el) { return false; }

	el.j_submit = function(_append) {

		if (typeof _append !== 'string') {
			var _append = '';
		}

		_do_nav_to_jav_jstr = 1;
		_nav_jstr = '';

		$(this).find('#jparse_tbl').each(function() {
			var _v = jQuery.trim($(this).val()).toLowerCase();
			if (_v !== '') {
				if (_v == '-log-me-in-') {
					window.location = 'http://' + document.domain + '/';
					_do_nav_to_jav_jstr = 0;
					return false;
				}
				else if (_v == '-customize-tables-') {
					window.location = 'http://iqtpi.com/Tables';
					_do_nav_to_jav_jstr = 0;
					return false;
				}
				else {
					_nav_jstr = _nav_jstr + '/' + _v;
				}
			}
		});
			if (_do_nav_to_jav_jstr !== 1) { return false; }

		$(this).find('#jparse_user').each(function() {
			var _v = jQuery.trim($(this).val()).toLowerCase();
			if (_v !== '') {
				if (_v == '-log-me-in-') {
					window.location = 'http://' + document.domain + '/';
					_do_nav_to_jav_jstr = 0;
					return false;
				}
				else if (_v == '-manage-contacts-') {
					window.location = 'http://iqtpi.com/People/Family';
					_do_nav_to_jav_jstr = 0;
					return false;
				}
				else {
					_nav_jstr = _nav_jstr + '@' + _v;
				}
			}
		});
			if (_do_nav_to_jav_jstr !== 1) { return false; }

		$(this).find('#jparse_site').each(function() {
			var _v = jQuery.trim($(this).val()).toLowerCase();
			if (_v !== '') {
				if (_v == '-log-me-in-') {
					window.location = 'http://' + document.domain + '/';
					_do_nav_to_jav_jstr = 0;
					return false;
				}
				else if (_v == '-site-subscriptions-') {
					window.location = 'http://iqtpi.com/Sites';
					_do_nav_to_jav_jstr = 0;
					return false;
				}
				else {
					_nav_jstr = _nav_jstr + '^' + _v;
				}
			}
		});
			if (_do_nav_to_jav_jstr !== 1) { return false; }

		$(this).find('#jparse_id').each(function() {
			var _v = jQuery.trim($(this).val()).toLowerCase();
			if (_v !== '') {
				_nav_jstr = _nav_jstr + '-' + _v;
			}
		});
			if (_do_nav_to_jav_jstr !== 1) { return false; }

		$(this).find('#jparse_str').each(function() {
			var _v = jQuery.trim($(this).val()).toLowerCase();
			if (_v !== '') {
				if (_v == '-log-me-in-') {
					window.location = 'http://' + document.domain + '/';
					_do_nav_to_jav_jstr = 0;
					return false;
				}
				else if (_v == '-customize-tables-') {
					window.location = 'http://iqtpi.com/Tables';
					_do_nav_to_jav_jstr = 0;
					return false;
				}
				else {
					// make sure _v works with url and jparse
					if (_v.indexOf('"') > -1) {
						var _v = '\'' + _v + '\'';
					}
					else {
						var _v = '"' + _v + '"';
					}
					var _v = encodeURIComponent(_v);
					_nav_jstr = _nav_jstr + ':' + _v;
				}
			}
		});
			if (_do_nav_to_jav_jstr !== 1) { return false; }

		window.location = 'http://' + document.domain + '/j:' + _nav_jstr + _append;

	}

	$(el).find('select').each(function() {

		this.that = el;

		$(this).change(function() {
			if (this.id !== 'jparse_id') {
				// prevent stupid case of filtering a single
				$(this.that).find('#jparse_id').val('');
			}
			this.that.j_submit();
		});

	});

	$(el).find('input').each(function() {

		this.that = el;

		$(this).change(function() {
			// prevent stupid case of filtering a single
			$(this.that).find('#jparse_id').val('');
			this.that.j_submit();
		});
		$(this).keydown(function(e) {
			if (e.keyCode == 13) {
				// prevent stupid case of filtering a single
				$(this.that).find('#jparse_id').val('');
				this.that.j_submit();
				return false;
			}
		});
		$(this).focus(function() {
			$(this).select();
		});

	});

}  
I_VERSION = 1.044;





I_DISPLAY_SPEED = 1600;



$(document).ready(function() {

	i_init(document.body);

});



function i_init(el) {

  if (!el) { var el = document.body; }

  $(el).find('.i').each(function() {

	if (this.did_i_init && this.did_i_init == 1) { return true; }
	  this.did_i_init = 1;

	this.jstr = this.id;
			this.idstr = '';
	  if (this.jstr.indexOf('set|') == 0) {
		this.jstr = this.jstr.replace('set|','');
	  }
	  if (this.jstr.indexOf('single|') == 0) {
		this.jstr = this.jstr.replace('single|','');
		  this.idstr = this.id.split('-')[1].split('.')[0];
	  }
	this.tbl = '';
	  if (this.className.indexOf('i_tbl_') > -1) {
		var _s = this.className.split(' ');
		var x = 0;
		while (x < _s.length) {
			var _str = _s[x];
			if (_str.indexOf('i_tbl_') == 0) {
				this.tbl = _str.replace('i_tbl_','');
				break;
			}
			var x = x + 1;
		}
	  }
		if (this.tbl !== '') {
			setTimeout("i_extend('" + this.tbl + "')",20);
		}
	this.main = '';
	  if (this.className.indexOf('i_main_') > -1) {
		var _s = this.className.split(' ');
		var x = 0;
		while (x < _s.length) {
			var _str = _s[x];
			if (_str.indexOf('i_main_') == 0) {
				this.main = _str.replace('i_main_','');
				break;
			}
			var x = x + 1;
		}
	  }
	this.sub = '';
	  if (this.className.indexOf('i_sub_') > -1) {
		var _s = this.className.split(' ');
		var x = 0;
		while (x < _s.length) {
			var _str = _s[x];
			if (_str.indexOf('i_sub_') == 0) {
				this.sub = _str.replace('i_sub_','');
				break;
			}
			var x = x + 1;
		}
	  }
	this.t = '';
	  if (this.main !== '') {
		this.t = this.main;
		if (this.sub !== '') {
			this.t = this.t + '.' + this.sub;
		}
	  }
	this.maxrows = 10;
	 this.maxrows_step = this.maxrows;
	  if (this.className.indexOf('i_maxrows_') > -1) {
		var _s = this.className.split(' ');
		var x = 0;
		while (x < _s.length) {
			var _str = _s[x];
			if (_str.indexOf('i_maxrows_') == 0) {
				this.maxrows = _str.replace('i_maxrows_','');
				 this.maxrows_step = this.maxrows;
				break;
			}
			var x = x + 1;
		}
	  }
	this.tips = ',';

	this.is_busy = 0;
	this.mouse_is_over = 0;

	this.refresh_ajax_num = 1;
	this.filter_ajax_num = 1;

	var _jq = $(this).children('div.i_head').find('h4').not('.no_hover_behavior').find('a:first');
	  if (_jq.length == 1 && _jq.attr('href') !== '' && _jq.attr('href') !== '#') {
		$(this).css('cursor','pointer');
			$(_jq).css('text-decoration','none');
			$(_jq).click(function(e) {
				window.location = this.href;
				e.stopPropagation();
				return false;
			});
			$(this).click(function(e) {
				window.location = $(this).children('div.i_head').find('a:first')[0].href;
				e.stopPropagation();
				return false;
			});
			$(this).bind('mousemove', function(e) {
				this.onMouseEnter(e);
				e.stopPropagation();
			});
			$(this).bind('mouseleave', function(e) {
				this.onMouseOut(e);
				e.stopPropagation();
			});
			this.onMouseEnter = function(e) {
				if (this.mouse_is_over == 1) { return true; }
				this.mouse_is_over = 1;
				$('.mouse_is_over').each(function() {
					this.onMouseOut();
				});
				$(this).addClass('mouse_is_over');
				this.look('over');
			}
			this.onMouseOut = function(e) {
				this.mouse_is_over = 0;
				$(this).removeClass('mouse_is_over');
				this.look('out');
			}
			  var _this = this;
			  $(this).children('.i_controls').find('a').each(function() {
				this.hover_parent = _this;
				this.onMouseMove = function(e) {
					$(this).addClass('being_hovered_over');
					this.hover_parent.onMouseOut(e);
					e.stopPropagation();
				}
				$(this).bind('mousemove', function(e) {
					return this.onMouseMove(e);
				});
				this.onMouseLeave = function(e) {
					$(this).removeClass('being_hovered_over');
					if (e !== null) {
						var _class = addRandomClass(this);
						setTimeout("try{$('." + _class + "')[0].onMouseLeave(null)}catch(err){}",100);
						e.stopPropagation();
						return true;
					}
					removeRandomClass(this);
					if ($(this.hover_parent).children('.i_controls').find('a.being_hovered_over').length == 0) {
						this.hover_parent.onMouseEnter(e);
					}
				}
				$(this).bind('mouseleave', function(e) {
					return this.onMouseLeave(e);
				});
				
			  });
	  }

	this.next_look_on_not_busy = '';
	this.look = function(cmd) {
		if (cmd == 'busy' || cmd == 'busy_fading') {
			this.is_busy = 1;
			var _color = 'black';
			  if (cmd == 'busy_fading') {
				var _color = 'white';
			  }
			
			$(this).find('.i_look_overlay').remove();
			$(this).append('<div class="i_look_overlay" style="display:none; position:absolute; left:0px; top:0px; width:100%; height:100%; z-index:2;">\
				<div class="i_look_overlay_overlay" align="center" style="position:absolute; z-index:2; width:100%; left:0px; top:0px; padding-top:8px;"><img src="http://iqtpi.com/file:/image-iqtpi_loader" border="0" style="width:36px; padding:3px;"></div>\
				<div class="i_look_overlay_underlay" style="position:absolute; background:' + _color + '; opacity:0.4; filter:alpha(opacity=40); left:0px; top:0px; width:100%; height:100%; z-index:1;"></div>\
			</div>');
			$(this).find('.i_look_overlay').fadeIn(120);
		}
		else if (cmd == 'not_busy') {
			this.is_busy = 0;
			$(this).css('background','none');
			$(this).find('.i_look_overlay').remove();
			if (this.next_look_on_not_busy !== '') {
				this.look(this.next_look_on_not_busy);
				this.next_look_on_not_busy = '';
			}
		}
		else if (this.is_busy == 1) {
			this.next_look_on_not_busy = cmd;
			return true;
		}
		else if (cmd == 'good') {
			var _color = 'blue';
			$(this).find('.i_look_overlay').remove();
			$(this).append('<div class="i_look_overlay" style="display:block; position:absolute; left:0px; top:0px; width:100%; height:100%; z-index:2;">\
				<div class="i_look_overlay_overlay" align="center" style="position:absolute; z-index:2; width:100%; left:0px; top:0px; padding-top:8px;"><img src="http://iqtpi.com/file:/icon-simplistica_accept?&picwidth=64" border="0" style="width:36px; padding:3px;"></div>\
				<div class="i_look_overlay_underlay" style="position:absolute; background:' + _color + '; opacity:0.4; filter:alpha(opacity=40); left:0px; top:0px; width:100%; height:100%; z-index:1;"></div>\
			</div>');
			setTimeout("try{document.getElementById('" + this.id + "').look('not_busy')}catch(err){}",I_DISPLAY_SPEED);
		}
		else if (cmd == 'bad') {
			var _color = 'red';
			$(this).find('.i_look_overlay').remove();
			$(this).append('<div class="i_look_overlay" style="display:block; position:absolute; left:0px; top:0px; width:100%; height:100%; z-index:2;">\
				<div class="i_look_overlay_overlay" align="center" style="position:absolute; z-index:2; width:100%; left:0px; top:0px; padding-top:8px;"><img src="http://iqtpi.com/file:/icon-simplistica_delete?&picwidth=64" border="0" style="width:36px; padding:3px;"></div>\
				<div class="i_look_overlay_underlay" style="position:absolute; background:' + _color + '; opacity:0.4; filter:alpha(opacity=40); left:0px; top:0px; width:100%; height:100%; z-index:1;"></div>\
			</div>');
			setTimeout("try{document.getElementById('" + this.id + "').look('not_busy')}catch(err){}",I_DISPLAY_SPEED);
		}
		else if (cmd == 'over') {
			$(this).animate({'backgroundColor':'#f3f3f3'},120, function() {
				if (this.mouse_is_over !== 1) {
					this.look('out');
				}
			});
			$(this).css('color','#222');
		}
		else if (cmd == 'out') {
			$(this).css('background','none');
			$(this).css('color','');
		}
	}

	this.i_graph = null;
	  var _jq = $(this).children('.i_graph');
	  if (_jq.length == 1) {
		this.i_graph = _jq[0];
		this.i_graph.that = this;
	  }
		if (this.i_graph) {
			$(this.i_graph).find('a').click(function(e) {
				e.stopPropagation();
			});
		}

	this.i_head = null;
	  var _jq = $(this).children('.i_head');
	  if (_jq.length == 1) {
		this.i_head = _jq[0];
		this.i_head.that = this;
	  }
		if (this.i_head) {
			$(this.i_head).find('a').click(function(e) {
				e.stopPropagation();
			});
		}

	this.i_body = null;
	  var _jq = $(this).children('.i_body');
	  if (_jq.length == 1) {
		this.i_body = _jq[0];
		this.i_body.that = this;
	  }
		if (this.i_body) {
			$(this.i_body).find('a.eStopProp').click(function(e) {
				e.stopPropagation();
			});
		}

	this.i_foot = null;
	  var _jq = $(this).children('.i_foot');
	  if (_jq.length == 1) {
		this.i_foot = _jq[0];
		this.i_foot.that = this;
	  }
		if (this.i_foot) {
			$(this.i_foot).find('a').click(function(e) {
				e.stopPropagation();
			});
		}

	this.i_controls = null;
	  var _jq = $(this).children('.i_controls');
	  if (_jq.length == 1) {
		this.i_controls = _jq[0];
		this.i_controls.that = this;
	  }
		if (this.i_controls) {
			$(this.i_controls).find('.eStopProp').click(function(e) {
				e.stopPropagation();
			});
			$(this.i_controls).find('a').click(function(e) {
				var _f = this.id.replace('i_call_','');
				if (_f !== '') {
					that = $(this).parents('.i')[0];
					that.callFunction(_f);
					e.stopPropagation();
					return false;
				}
				e.stopPropagation();
			});
			$(this.i_controls).find('select').click(function(e) {
				e.stopPropagation();
			});
			$(this.i_controls).find('select').bind('change', function(e) {
				var _f = this.id.replace('i_call_','');
				if (_f !== '') {
					that = $(this).parents('.i')[0];
					that.callFunction(_f);
					e.stopPropagation();
				}
				e.stopPropagation();
			});
			$(this.i_controls).find('select').bind('keyup', function(e) {
				if (e.keyCode == 13) {
					// hitting "enter" equals clicking the "select_submit" link
					var _controls = $(this).parents('.i')[0];
					$(_controls).find('a.select_submit').focus();
					return false;
				}
			});
			if ($(this).hasClass('i_set')) {
				$(this.i_controls).find('.filter').each(function() {
					$(this).bind('keyup change', function(e) {
						var that = $(this).parents('.i_controls:first')[0].that;
						 var _v2 = '';
							if ( $(that.i_controls).find('.filter_body').length > 0) {
								var _v2 = $(that.i_controls).find('.filter_body').val();
							}
						that.core_functs.filter(that,$(this).val(),_v2);
					});
				});
				$(this.i_controls).find('.filter_body').each(function() {
					$(this).bind('keyup change', function(e) {
						var that = $(this).parents('.i_controls:first')[0].that;
						 var _v2 = '';
							if ( $(that.i_controls).find('.filter').length > 0) {
								var _v2 = $(that.i_controls).find('.filter').val();
							}
						that.core_functs.filter(that,_v2,$(this).val());
					});
				});
			}
		}

	this.callFunction = function(f,cb) {
		if (!cb) { var cb = function(){} }
		if (this.core_functs[f]) {
			this.core_functs[f](this,cb);
		}
		else {
			if (CLIENT_ID <= 1) {
				alert('Please log in with iqtpi to use this feature.');
				return false;
			}
			var _ok = 0;
			if (eval("typeof i_extend_" + this.tbl) == 'undefined') {
				try {
					if (typeof i_extend_iqtpi[f] == 'function') {
						var _ok = 1;
					}
					else {
						alert('There is no i_extend_iqtpi.' + f + ' function for ' + this.tbl + ' ' + this.id);
					}
				} catch(err) {
					alert('There is no i_extend_iqtpi.' + f + ' function for ' + this.tbl + ' ' + this.id);
				}
				if (_ok == 1) {
					i_extend_iqtpi[f](this,cb);
				}
			}
			else {
				try {
					if (eval("typeof i_extend_" + this.tbl + "[f]") == 'function') {
						var _ok = 1;
					}
					else {
						alert('There is no ' + f + ' function for ' + this.tbl + ' ' + this.id);
					}
				} catch(err) {
					alert('There is no ' + f + ' function for ' + this.tbl + ' ' + this.id);
				}
				if (_ok == 1) {
					eval("i_extend_" + this.tbl + "[f](this,cb)");
				}
			}
		}
	}

	this.core_functs = {

		refresh: function(that,cb) {
			that.refresh_ajax_num = that.refresh_ajax_num + 1;
			that.look('busy');
			var _pstr = '';
			  $(that).children('.i_property').each(function() {
				_pstr = _pstr + '&p_' + this.title + '=' + encodeURIComponent($(this).html());
			  });
				var _ts = new Date().getTime();
			  	var _pstr = _pstr + '&ajax_rando=' + encodeURIComponent(_ts);
			var _class = addRandomClass(that);
			that.i_callback_function_refresh = cb;
			$.get('http://' + document.domain + '/iservice?&t=' + that.t + _pstr + '&ajax_num_echo=' + that.refresh_ajax_num + '&q=' + encodeURIComponent(that.id) + '&rc_echo=' + encodeURIComponent(_class), function(data) {
				var _s = this.url.split('=');
				var _class = decodeURIComponent(_s[_s.length-1]);
				var that = $('.' + _class)[0];
					removeRandomClass(that);
				var _num = _s[_s.length-2].replace(/[^0-9]/g,'');
				$(data).insertBefore(that);
				var _new_el = $(that).prev('.i')[0];
					_new_el.i_callback_function_refresh = that.i_callback_function_refresh;
				$(that).remove();
				i_init(_new_el.parentNode);
				_new_el.look('not_busy');
				_new_el.i_callback_function_refresh(_new_el);
			});
		},

		more: function(that,cb) {
			if (that.main !== 'set') {
				alert('Function more() should not be called unless main function is "set".');
				return false;
			}
			that.look('busy_fading');
			if (that.i_body) {
				$(that.i_body).children('.i_single').each(function() {
					var _tip = this.jstr.replace('/','');
					if (that.tips.indexOf(',' + _tip + ',') == -1) {
						that.tips = that.tips + _tip + ',';
					}
				});
			}
			var _mr = that.maxrows*1 + that.maxrows_step*1;
			var _pstr = '';
			  $(that).children('.i_property').each(function() {
				if (this.title !== 'maxrows') {
					_pstr = _pstr + '&p_' + this.title + '=' + encodeURIComponent($(this).html());
				}
			  });
				var _ts = new Date().getTime();
			  	var _pstr = _pstr + '&ajax_rando=' + encodeURIComponent(_ts);
			that.i_callback_function_more = cb;
			$.get('http://' + document.domain + '/iservice?&t=' + that.t + _pstr + '&p_maxrows=' + _mr + '&exclude_these_tips=' + encodeURIComponent(that.tips) + '&no_set_wrap=1&q=' + encodeURIComponent(that.id), function(data) {
				var _s = this.url.split('=');
				var _jstr = decodeURIComponent(_s[_s.length-1]);
				var that = document.getElementById(_jstr);
				var _mr = that.maxrows*1 + that.maxrows_step*1;
				that.maxrows = _mr;
				$(that.i_body).append(data);
				i_init(that.i_body);
				that.look('not_busy');
				that.i_callback_function_more(that);
			});
		},

		filter: function(that,str,str_body) {
			if (that.main !== 'set') {
				alert('Function filter() should not be called unless main function is "set".');
				return false;
			}
			that.filter_ajax_num = that.filter_ajax_num + 1;
			//that.look('busy_fading');
			var _pstr = '';
			  $(that).children('.i_property').each(function() {
				if (this.title !== 'str' && this.title !== 'str_body') {
					_pstr = _pstr + '&p_' + this.title + '=' + encodeURIComponent($(this).html());
				}
			  });
			if (typeof str == 'string') {
				if (jQuery.trim(str) !== '') {
					var _pstr = _pstr + '&p_str=' + encodeURIComponent(str);
				}
			}
			if (typeof str_body == 'string') {
				if (jQuery.trim(str_body) !== '') {
					var _pstr = _pstr + '&p_str_body=' + encodeURIComponent(str_body);
				}
			}
			$.get('http://' + document.domain + '/iservice?&t=' + that.t + _pstr + '&no_set_wrap=1&ajax_num_echo=' + that.filter_ajax_num + '&q=' + encodeURIComponent(that.id), function(data) {
				var _s = this.url.split('=');
				var _jstr = decodeURIComponent(_s[_s.length-1]);
				var that = document.getElementById(_jstr);
				var _num = _s[_s.length-2].replace(/[^0-9]/g,'');
				if (_num*1 !== that.filter_ajax_num*1) {
					return false;
				}
				$(that.i_body).html(data);
				i_init(that.i_body);
				//that.look('not_busy');
			});
		},

		close: function(that,cb) {
			if (that.is_busy == 1) {
				alert('This ' + that.tbl + ' cannot be closed yet.\n\nPlease wait until loading completes.');
				return false;
			}
			$(that).slideUp(120, function() {
				var _tst = cb(this);
				if (_tst !== false) {
					$(this).remove();
				}
			});
		},

		delete: function(that,cb) {
			if (that.is_busy == 1) {
				alert('This ' + that.tbl + ' cannot be deleted yet.\n\nPlease wait until loading completes.');
				return false;
			}
			var _s = that.id.split('-');
			if (that.idstr == '') {
				alert('This ' + that.tbl + ' cannot be deleted because it is not a single.');
				return false;
			}
			var c = confirm('Really delete?\n\nThere is NO UNDO.');
			if (!c) {
				return false;
			}
			var _where = that.tbl + '.id = ' + that.idstr;
			  if (that.idstr.match(/[a-zA-Z_]/)) {
				var _where = that.tbl + '.gutitle = \'' + that.idstr + '\'';
			  }
			that.look('busy');
			$.post('http://' + document.domain + '/?&siteformat=xml&jstr_echo=' + encodeURIComponent(that.id), {
				"1_posttype": "delete",
				"1_orb": that.tbl,
				"1_where": _where
			}, function(data) {
				var _s = this.url.split('=');
				var that = document.getElementById(decodeURIComponent(_s[_s.length-1]));
				var _num = _s[_s.length-2].replace(/[^0-9]/g,'');
				that.look('not_busy');
				that.callFunction('close');
			});
		}

	}

			// apply filter that has initial value
			if ($(this).hasClass('i_set')) {
				$(this.i_controls).find('.filter').each(function() {
					if (jQuery.trim($(this).val()) !== '') { $(this).change(); }
				});
				$(this.i_controls).find('.filter_body').each(function() {
					if (jQuery.trim($(this).val()) !== '') { $(this).change(); }
				});
			}

			// tbl-specific init
			if (this.tbl !== '') {
				try {
					eval('i_extend_' + this.tbl + '.init_each(this)');
				} catch(err) {}
			}

  });

}


I_EXTEND_TBL_LIST = '|';
function i_extend(tbl) {
	if (I_EXTEND_TBL_LIST.indexOf('|' + tbl + '|') == -1) {
		I_EXTEND_TBL_LIST = I_EXTEND_TBL_LIST + tbl + '|';
		var _tst = eval("typeof i_extend_" + tbl);
		if (_tst !== 'object') {
			$.getScript('http://' + document.domain + '/iservice?&version=' + I_VERSION + '&t=script&q=/' + tbl, function() {
				var _s = this.url.split('/');
				var _tbl = _s[_s.length-1];
				try {
					eval('i_extend_' + _tbl + '.init()');
				} catch(err) {}
				try {
					// tbl-specific init
					$('.i_tbl_' + _tbl).each(function() {
						eval('i_extend_' + _tbl + '.init_each(this)');
					});
				} catch(err) {}
			});
		}
	}
}








function makeGutitleField(el) { // el is an input that should force gutitle format
	if (el.is_gutitle_field == 1) { return false; }
	el.is_gutitle_field = 1;
	$(el).keyup(function(e) {
		var _orig = $(this).val();
		var _v = jQuery.trim($(this).val()).toLowerCase();
		if (_v.length == 0) {
			return true;
		}
		var _v = _v.replace(/[^a-z_]/gi,'');
		var _v = _v.replace(/(_)+/g,'_');
		if (_v.indexOf('_') == 0) {
			var _v = _v.replace('_','');
		}
		if (_v !== _orig) {
			$(this).val(_v);
		}
	});
}
function isValidEmail(str) {
	var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	if (!filter.test(str)) {
		return false;
	}
	else {
		return true;
	}
}



RANDOM_CLASS_NUM = 1;
function addRandomClass(el) {
	RANDOM_CLASS_NUM = RANDOM_CLASS_NUM + 1;
	var _class = 'iRandomClass_' + RANDOM_CLASS_NUM;
	$(el).addClass(_class);
	return _class;
}
function removeRandomClass(el) {
	var _s = el.className.split(' ');
	var x = 0;
	while (x < _s.length) {
		var c = _s[x];
		if (c.indexOf('iRandomClass_') == 0) {
			$(el).removeClass(c);
		}
		var x = x + 1;
	}
}








/*

 Fentriss AC, take two
 
 (C) Fentriss

*/
QAC_AJAX_NUM = 1;
RETURNED_QAC_AJAX_NUM = 1;
function fentriss_AC(imp,jstr,pEl) {
	imp.locator_class = addRandomClass(imp);
	imp.jstr = jstr;
	  if (typeof jstr !== 'string') {
		imp.jstr = '/answer';
	  }
	imp.pEl = pEl;
	  if (typeof pEl == 'undefined') {
		imp.pEl = imp.parentNode;
	  }
	imp.last_selected_val = $(imp).val();
	$(imp).keyup(function(e) {
		if (e.keyCode == 38 || e.keyCode == 40 || e.keyCode == 13) { return false; }
		var _v = jQuery.trim($(this).val());
		if (_v == this.last_selected_val) { return false; }
		_v_space_split_len = _v.split(' ').length;
		if (_v == '') {  //  || (this.jstr == '/question' && _v_space_split_len <= 1)
			if (_v == '') {
				$(this).val('');
				this.last_selected_val = '';
			}
			$(this).next('.i_main_set').remove();
			return true;
		}
		else {
			var _pstr = '';
			  $(this.pEl).children('.i_property').each(function() {
				_pstr = _pstr + '&p_' + this.title + '=' + encodeURIComponent($(this).html());
			  });
			if (jstr == '/question') {
				var _pstr = _pstr + '&function=question_ac';
			}
			this.last_selected_val = _v;
			QAC_AJAX_NUM = QAC_AJAX_NUM + 1;
			$.get('http://' + document.domain + '/iservice?&t=set.results_ac' + _pstr + '&q=' + this.jstr + '&p_str=' + encodeURIComponent(_v) + '&ajax_num_echo=' + QAC_AJAX_NUM + '&locator_class_echo=' + this.locator_class, function(data) {
				var _s = this.url.split('=');
				  var _num = _s[_s.length-2];
				  var _class = _s[_s.length-1];
				var imp = $('.' + _class)[0];
				if (_num*1 < RETURNED_QAC_AJAX_NUM*1) { return false; }
				RETURNED_QAC_AJAX_NUM = _num;
				$(imp).next().remove();
				$(imp).after(data);
				if (jQuery.trim($(imp).val()) == '') {
					$(imp).val('');
					imp.last_selected_val = '';
					$(imp).next('.i_main_set').remove();
				}
				else {
					$(imp).next('.i_main_set').find('.i_sub_result_ac').each(function() {
						$(this).hover(
							function() { $(this).parents('.i_main_set').prev()[0].makeDivLookFocused(this,0); },
							function() { $(this).parents('.i_main_set').prev()[0].makeDivLookUnfocused(this,0); }
						);
						$(this).css('cursor','pointer');
						$(this).click(function() {
							var imp = $(this).parents('.i_main_set').prev()[0];
							imp.makeDivLookFocused(this,1);
							imp.finishSelectingAnswer();
							return false;
						});
					});
				}
			});
		}
	});
	$(imp).keydown(function(e) {
		if (e.keyCode == 40) { // down arrow
			var _jq = $(this).next().find('.ac_focused');
			if (_jq.length == 0) {
				var _jq2 = $(this).next().find('.i_sub_result_ac:first');
				if (_jq2.length == 1) {
					this.makeDivLookFocused(_jq2[0]);
					_jq2[0].parentNode.scrollTop = _jq2.position().top;
				}
				else {
					$(this).val(this.last_selected_val);
					try {
						$(this).next()[0].scrollTop = 0;
					} catch(err) {}
				}
			}
			else {
				var _jq2 = _jq.next();
				if (_jq2.length == 1) {
					this.makeDivLookFocused(_jq2[0]);
					_jq2[0].parentNode.scrollTop = _jq2.position().top;
				}
				else {
					this.makeDivLookUnfocused(_jq[0]);
					$(this).val(this.last_selected_val);
					$(this).next()[0].scrollTop = 0;
				}
			}
			return false;
		}
		else if (e.keyCode == 38) { // up arrow
			var _jq = $(this).next().find('.ac_focused');
			if (_jq.length == 0) {
				var _jq2 = $(this).next().find('.i_sub_result_ac:last');
				if (_jq2.length == 1) {
					this.makeDivLookFocused(_jq2[0]);
					_jq2[0].parentNode.scrollTop = _jq2.position().top;
				}
				else {
					$(this).val(this.last_selected_val);
					try {
						$(this).next()[0].scrollTop = 0;
					} catch(err) {}
				}
			}
			else {
				var _jq2 = _jq.prev();
				if (_jq2.length == 1) {
					this.makeDivLookFocused(_jq2[0]);
					_jq2[0].parentNode.scrollTop = _jq2.position().top;
				}
				else {
					this.makeDivLookUnfocused(_jq[0]);
					$(this).val(this.last_selected_val);
					$(this).next()[0].scrollTop = 0;
				}
			}
			return false;
		}
		else if (e.keyCode == 13) {
			try {
				this.finishSelectingAnswer();
			} catch(err) {}
			return false;
		}
	});
	imp.makeDivLookFocused = function(el,changeVal) {
		if (typeof changeVal !== 'number') { var changeVal = 1; }
		var imp = $(el).parents('.i_main_set').prev()[0];
		$(el).siblings('.i_sub_result_ac').each(function() {
			imp.makeDivLookUnfocused(this);
		});
		$(el).addClass('ac_focused');
		$(el).css('background','#e0e5ff');
		if (changeVal == 1) {
			$(imp).val(jQuery.trim($(el).find('.i_head').text()));
			$(imp).focus();
		}
	}
	imp.makeDivLookUnfocused = function(el) {
		$(el).removeClass('ac_focused');
		$(el).css('background','none');
	}
	imp.finishSelectingAnswer = function() {
		if ($(this).next('.i_sub_results_ac').length > 0) {
			$(this).focus();
			$(this).siblings('.i_main_set').slideUp(240, function() {
				var imp = $(this).siblings('input')[0];
				$(imp.pEl).find('input,select,textarea').not('.' + imp.locator_class).focus();
				$(this).remove();
			});
		}
		else {
			$(this.pEl).find('input,select,textarea').not('.' + this.locator_class).focus();
		}
	}
}



function numFormat(str) {
	str += '';
	x = str.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}





i_extend_iqtpi = {

	sayHello: function(that) {
		alert('Hello from ' + that.id);
	},

	play: function(that) {
		var _idstr = that.id.split('-')[1];
		window.open('http://' + document.domain + '/file:/' + that.tbl + '-' + _idstr);
	},

	del: function(that) {
		var c = confirm('Really delete?\n\nThere is NO UNDO.');
		if (c == true) {
			that.look('busy_fading');
			$.get('http://' + document.domain + '/iservice?&t=post.delete&q=' + encodeURIComponent(that.id), function(data) {
				var _s = this.url.split('=');
				var that = document.getElementById(decodeURIComponent(_s[_s.length-1]));
				that.look('not_busy');
				that.look('bad');
				var _class = addRandomClass(that);
				setTimeout("$('." + _class + "').slideUp(240, function() {\
					$(this).remove();\
				})",1000);
			});
		}
	}

} 



/* thank you to http://blogs.sitepointstatic.com/examples/tech/json-serialization/json-serialization.js */
var JSON = JSON || {};

// implement JSON.stringify serialization
JSON.stringify = JSON.stringify || function (obj) {

	var t = typeof (obj);
	if (t != "object" || obj === null) {

		// simple data type
		if (t == "string") obj = '"'+obj+'"';
		return String(obj);

	}
	else {

		// recurse array or object
		var n, v, json = [], arr = (obj && obj.constructor == Array);

		for (n in obj) {
			v = obj[n]; t = typeof(v);

			if (t == "string") v = '"'+v+'"';
			else if (t == "object" && v !== null) v = JSON.stringify(v);

			json.push((arr ? "" : '"' + n + '":') + String(v));
		}

		return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
	}
};


// implement JSON.parse de-serialization
JSON.parse = JSON.parse || function (str) {
	if (str === "") str = '""';
	eval("var p=" + str + ";");
	return p;
}; 




function activate_radio_containers() {
	$('.radio_container').each(function() {
		style_radio_container(this);
		$(this).find('input.radio').bind('change blur click', function(e) {
			if (e.type == 'change') {
				return true;
			}
			else if (e.type == 'click') {
				this.checked = true;
				e.stopPropagation();
				$(this).change();
			}
			$($(this).parents('.radio_container')[0]).siblings('.radio_container').each(function() {
				style_radio_container(this);
			});
			style_radio_container($(this).parents('.radio_container')[0]);
		});
		$(this).click(function() {
			$(this).find('input.radio').click();
		});
		$(this).css('cursor','pointer');
	});
}
function style_radio_container(el) {
	if ($(el).find('input.radio')[0].checked == true) {
		$(el).css('background','#ffb');
		$(el).css('color','#222');
	}
	else {
		$(el).css('background','#fff');
		$(el).css('color','#222');
	}
}













function activate_memoers() {

	$('.memoer').each(function() {

		this.refresh_el = null;
		  try {
			this.refresh_el = document.getElementById($(this).find('.memoer_refresh_elId').text());
		  } catch(err) {}

		$(this).find('textarea').focus(function() {
			$(this).animate({'height':'86px'},360);
		});
		$(this).find('textarea').blur(function() {
			if ( jQuery.trim($(this).val()) == '') {
				$(this).animate({'height':'40px'},360);
			}
		});

		$(this).find('form:first').submit(function() {

			if (CLIENT_ID <= 1) {
				alert('Please log in to post comments and updates.');
			}

			if (jQuery.trim($(this).find('#1_body').val()) == '') {
				alert('Type something first!');
				return false;
			}

			var that = $(this).parents('.memoer:first')[0];

			var _pdata = {
				"1_posttype": $(this).find('#1_posttype').val(),
				"1_orb": $(this).find('#1_orb').val(),
				"1_body": $(this).find('#1_body').val(),
				"1_name": $(this).find('#1_name').val(),
				"1_title": $(this).find('#1_title').val(),
				"1_uname": $(this).find('#1_uname').val(),
				"1_iqtpi_age_num_double": $(this).find('#1_iqtpi_age_num_double').val(),
				"1_user_key_id": $(this).find('#1_user_key_id').val()
			}

			if (that.refresh_el) {
				$(that).append('<div class="memoer_loader" align="center" style="position:absolute; display:none; z-index:1000; width:100%; height:100%; left:0px; top:0px;">\
				  <div class="memoer_loader_bg" style="position:absolute; z-index:1; width:100%; height:100%; left:0px; top:0px; background:#00a6ff; opacity:0.4; filter:alpha(opacity=40);"></div>\
				  <div class="memoer_loader_content" style="position:relative; z-index:2; width:10em; padding:1em; margin-top:0.72em; background:#fff;"> <img src="http://iqtpi.com/?&o=612&f=routine-2134" border="0" style="height:1em;; ">  Posting...</div>\
				</div>');
				$(that).find('.memoer_loader').fadeIn(360);
				$.post('http://' + document.domain + '/?&siteformat=xml&elId_echo=' + encodeURIComponent(that.id), _pdata, function(data) {
					var _s = this.url.split('=');
					var that = document.getElementById(decodeURIComponent(_s[_s.length-1]));
					$(that).find('.memoer_loader_bg').css('background','#8b2');
					$(that).find('.memoer_loader_content').html(' <img src="http://iqtpi.com/get_7o_file.cfm?&path=icons/Fugue/icons/tick.png" border="0" style="" class="" id="" align="">  Posted');
					$(that).find('textarea').val('');
					$(that).find('textarea').blur();
					$(that).find('.memoer_loader').fadeOut(2000, function() {
						var that = $(this).parents('.memoer:first')[0];
							try {
								that.refresh_el.callFunction('refresh');
							} catch(err) {
								alert('Developer: element ' + that.refresh_el.id + ' does not have a refresh function.');
							}
						$(this).remove();
					});
				});
				return false;
			}
			else  {
				$(that).append('<div class="memoer_loader" align="center" style="position:absolute; display:none; z-index:1000; width:100%; height:100%; left:0px; top:0px;">\
				  <div class="memoer_loader_bg" style="position:absolute; z-index:1; width:100%; height:100%; left:0px; top:0px; background:#00a6ff; opacity:0.4; filter:alpha(opacity=40);"></div>\
				  <div class="memoer_loader_content" style="position:relative; z-index:2; width:10em; padding:1em; margin-top:0.72em; background:#fff;">  <img src="http://iqtpi.com/?&o=612&f=routine-2134" border="0" style="height:1em;; ">  Posting...</div>\
				</div>');
				$(that).find('.memoer_loader').fadeIn(360);
				$.post('http://' + document.domain + '/?&siteformat=xml&elId_echo=' + encodeURIComponent(that.id), _pdata, function(data) {
					var _s = this.url.split('=');
					var that = document.getElementById(decodeURIComponent(_s[_s.length-1]));
					$(that).find('.memoer_loader_bg').css('background','#8b2');
					$(that).find('.memoer_loader_content').html('  <img src="http://iqtpi.com/get_7o_file.cfm?&path=icons/Fugue/icons/tick.png" border="0" style="" class="" id="" align="">  Posted...');
					$(that).find('textarea').val('');
					$(that).find('textarea').blur();
					window.location = 'http://iqtpi.com/';
				});
				return false;
			}

		});

	});

} 
