function GetXMLHttpRequest() {
	// Set up the lightweigtht AJAX
	// http://www.jibbering.com/2002/4/httprequest.html
	var xmlhttp = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	 // JScript gives us Conditional compilation, we can cope with old IE versions.
	 // and security blocked creation of the objects.
	 try {
	 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	 try {
	 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	 } catch (E) {
	 xmlhttp = false;
	 }
	 }
	 @end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	if (!xmlhttp && window.createRequest) {
		try {
			xmlhttp = window.createRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}

	return xmlhttp;
}

function readCookie(NameOfCookie) {
	if (document.cookie.length > 0) {
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) {
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1)
				end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		}
	}
	return null;
}

function InitializeUpload() {
	document.getElementById("uploadprogress").innerHTML = '<b>Starting the upload process...</b><br>';
	return true;
}

function updateimage (customerid, widgetid, formatpix, assetid, thumbnailid, selectedkey, token) {
	// updated ================================
	var user = readCookie('u');
	var newimage = '<img src="'+'http://cdn.liveclicker.net/thumbnails/'+customerid+'/'+assetid+'_1_Flv_'+formatpix+'_thumb_'+thumbnailid+'.jpg'+'" height="48" width="64">';
	var uploadstatusURL = 'ajax/updatethumbnail.php?customerid='+customerid+'&token='+token+'&w='+widgetid+'&t='+thumbnailid;
	var xmlhttp = GetXMLHttpRequest();

	xmlhttp.open("GET", uploadstatusURL, false);
	xmlhttp.send(null);
	if (xmlhttp.readyState==4) {
		if ((xmlhttp.status==200) && (xmlhttp.responseText != null)) {
			document.getElementById('selected'+selectedkey).innerHTML=newimage;
			document.getElementById('title'+selectedkey).innerHTML=document.getElementById('title'+selectedkey).innerHTML+'<br><br><b>UPDATED</b>';
		}
	}
	return true;
}

function updatetitle (customerid, widgetid, selectedkey, token) {
	// updated ================================
	var title = $("#newtext"+selectedkey).val();
	//var encodedTitle = escape(title);
	encodedTitle = title;
	//var uploadstatusURL = 'ajax/updatetitle.php?c='+customerid+'&token='+token+'&w='+widgetid+'&t='+encodedTitle+'&escaped=1';
	var uploadstatusURL = 'ajax/updatetitle.php';
	$.get(uploadstatusURL, {
		c: customerid,
		token: token,
		w: widgetid,
		t: encodedTitle,
		escaped: 1
	}, function (data) {
		$('#title'+selectedkey).html(title+' <b>Updated</b>');
	});
	return true;
}

function updatepinnedurl (customerid, widgetid, selectedkey, token) {
	// updated ================================
	var element = $("#actionlink"+selectedkey);
	var newUrl = $("#newurl"+selectedkey).val();
	var pinned = element.attr("pinned");
	if (pinned == "0") {

		var uploadstatusURL = 'ajax/updateprimaryurl.php?c='+customerid+'&token='+token+'&w='+widgetid+'&pin=1&url='+escape(newUrl);
		$.get(uploadstatusURL, function (data) {
			$('#chars'+selectedkey).html('<b>Your URL had been pinned and will not change.</b>');
			$('#save'+selectedkey).removeClass("saveicon").addClass("pinnedicon");
			element.attr("pinned", "1");
			element.attr("title", "Unpin URL - Click to let Liveclicker automatically update the URL");
		});
	} else {
		$("#newurl"+selectedkey).val("");
		var uploadstatusURL = 'ajax/updateprimaryurl.php?c='+customerid+'&token='+token+'&w='+widgetid+'&pin=0&url='+escape(newUrl);
		$.get(uploadstatusURL, function (data) {
			$('#chars'+selectedkey).html('<b>URL deleted. Liveclicker will automatically determine the primary URL.</b>');
			$('#save'+selectedkey).removeClass("pinnedicon").addClass("saveicon");
			element.attr("pinned", "0");
			element.attr("title", "Pin URL - Click to manually set this URL for this widget");
		});
	}
	return true;
}

function updatemeta (customerid, widgetid, selectedkey, token) {
	// updated ================================
	var meta = document.getElementById('myform'+selectedkey).myname.value;

	var uploadstatusURL = 'ajax/updatemeta.php?c='+customerid+'&w='+widgetid+'&m='+meta+'&token='+token;
	// alert(uploadstatusURL);
	var xmlhttp = GetXMLHttpRequest();

	xmlhttp.open("GET", uploadstatusURL, false);
	xmlhttp.send(null);
	if (xmlhttp.readyState==4) {
		if ((xmlhttp.status==200) && (xmlhttp.responseText != null)) {
			if (xmlhttp.responseText.indexOf('error') < 0) {
				var currenttitle = document.getElementById('title'+selectedkey).innerHTML;
				document.getElementById('title'+selectedkey).innerHTML=currenttitle+'<br><b>Updated</b>';
			}
		}
	}
	return true;
}

function updatetextlink (widgetid, selectedkey,link_id) {
	// updated ================================
	var customerid = readCookie('c');
	var title = document.getElementById('myform'+selectedkey).myname.value;

	var mytime= '&ms='+new Date().getTime();

	var uploadstatusURL = 'ajax/updatetextlink.php?c='+customerid+'&w='+widgetid+'&lid='+link_id+'&t='+title+mytime;
	// alert(uploadstatusURL);
	var xmlhttp = GetXMLHttpRequest();

	xmlhttp.open("GET", uploadstatusURL, false);
	xmlhttp.send(null);
	if (xmlhttp.readyState==4) {
		if ((xmlhttp.status==200) && (xmlhttp.responseText != null)) {
			if (xmlhttp.responseText.indexOf('error') < 0) {
				document.getElementById('title'+selectedkey).innerHTML=title+'<br><b>Updated</b>';
			}
		}
	}
	return true;
}

function updateassettitle (assetid, selectedkey, token) {

	// updated ================================
	var customerid = readCookie('c');
	var title = document.getElementById('myform'+selectedkey).myname.value;

	var uploadstatusURL = 'ajax/updateassettitle.php?c='+customerid+'&a='+assetid+'&t='+title+'&token='+token;
	// alert(uploadstatusURL);
	var xmlhttp = GetXMLHttpRequest();

	xmlhttp.open("GET", uploadstatusURL, false);
	xmlhttp.send(null);
	if (xmlhttp.readyState==4) {
		if ((xmlhttp.status==200) && (xmlhttp.responseText != null)) {
			if (xmlhttp.responseText.indexOf('error') < 0) {
				document.getElementById('title'+selectedkey).innerHTML=title+' <b>Updated</b>';
			}
		}
	}
	return true;
}

function previewwidget_bak(customerid,widgetid) {
	// obsolete
	var actualwidgetid;
	var media_type;

	if (widgetid < 0) {
		actualwidgetid = - widgetid;
		media_type = 1;
	} else {
		actualwidgetid = widgetid;
		media_type = 0;
	}
	var getembedURL = 'ajax/previewwidget.php?w='+actualwidgetid+'&media_type='+media_type+'&aid='+customerid;
	// alert(uploadstatusURL);
	var xmlhttp = GetXMLHttpRequest();

	xmlhttp.open("GET", getembedURL, false);
	xmlhttp.send(null);
	if (xmlhttp.readyState==4) {
		if ((xmlhttp.status==200) && (xmlhttp.responseText != null)) {
			if (xmlhttp.responseText.indexOf('error') < 0) {
				document.getElementById('video_preview').innerHTML=xmlhttp.responseText;
				document.getElementById('preview_link_label').innerHTML='Click to hide the widget';
				document.getElementById('video_preview').style.visibility='visible';
				document.getElementById('video_preview').style.height='300px';
			}
		}
	}
	return true;
}

function previewwidget(customerid,widgetid) {
	// obsolete
}

function togglepreview(customerid,widgetid) {
	if (document.getElementById('video_preview').innerHTML == '') {
		previewwidget(customerid,widgetid);
	} else {
		if (document.getElementById('preview_link_label').innerHTML == 'Click to view') {
			document.getElementById('preview_link_label').innerHTML='Click to hide';
			document.getElementById('video_preview').style.visibility='visible';
			document.getElementById('video_preview').style.height='300px';
		} else {
			document.getElementById('preview_link_label').innerHTML='Click to view';
			document.getElementById('video_preview').style.visibility='hidden';
			document.getElementById('video_preview').style.height='0px';
		}
	}
	return true;
}

function copyvalue(spot,new_value) {
	document.getElementById('ac_me_assignment'+spot).value=new_value;
	document.getElementById('ac_me_assignment'+spot).style.color='red';
	document.getElementById('ac_me_assignment'+spot).style.fontWeight='bold';
	return true;
}

function createXMLHttpRequest() {
	try {
		return new XMLHttpRequest();
	} catch(e) {
	}
	try {
		return new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	}
	try {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {
	}
	alert("XMLHttpRequest not supported");
	return null;
}

function popupwindow(url) {
	newwindow=window.open(url,'name','height=320,width=360');
	if (window.focus) {
		newwindow.focus()
	}
	return false;
}

function mediumpopupwindow(url) {
	newwindow=window.open(url,'name','height=480,width=640');
	if (window.focus) {
		newwindow.focus()
	}
	return false;
}

function largepopupwindow(url) {
	newwindow=window.open(url,'name','height=520,width=660');
	if (window.focus) {
		newwindow.focus()
	}
	return false;
}

function largerpopupwindow(url) {
	newwindow=window.open(url,'name','height=700,width=800');
	if (window.focus) {
		newwindow.focus()
	}
	return false;
}

function launchtutorial(url) {
	return largepopupwindow(url);
}

function getcontextualhelp (words) {
	if (document.getElementById('related-posts')) {
		var mytime= '&ms='+new Date().getTime();
		var xmlhttp = GetXMLHttpRequest();

		var embedurl = '../wp/wp-content/custom-api/related-posts.php?w='+encodeURI(words)+mytime;
		//alert(embedurl);
		xmlhttp.open("GET", embedurl, false);
		xmlhttp.send(null);
		if (xmlhttp.readyState==4) {
			if ((xmlhttp.status==200) && (xmlhttp.responseText != null)) {
				if (xmlhttp.responseText.indexOf('error') < 0) {
					document.getElementById('related-posts').innerHTML=xmlhttp.responseText;
				}
			}
		}
	}

	return true;

}

function verify(msgtype) {
	msg_delete_site = "PLEASE READ!! Deleting a site will erase all records associated with it. This operation cannot be undone. Are you sure you want to continue?";
	msg_connection_exchange = "ARE YOU SURE? This operation cannot be undone. Are you sure you want to continue? (Recommended: Click Cancel)";
	msg_generic = "This operation cannot be undone. Are you sure you want to continue?";
	if (msgtype=='deletesite') {
		return confirm(msg_delete_site);
	} else if (msgtype=='exchangedeleteconnection') {
		return confirm(msg_connection_exchange);
	} else {
		return confirm(msg_generic);
	}
}

function select_all() {
	var text_val=eval("document.form1.type");
	text_val.focus();
	text_val.select();
}

// ============================================================================================================================================================
// ============================================================================================================================================================
// utils!!! ===================================================================================================================================================
// ============================================================================================================================================================
// ============================================================================================================================================================

/*!
 * jQuery blockUI plugin
 * Version 2.31 (06-JAN-2010)
 * @requires jQuery v1.2.3 or later
 *
 * Examples at: http://malsup.com/jquery/block/
 * Copyright (c) 2007-2008 M. Alsup
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 * Thanks to Amir-Hossein Sobhi for some excellent contributions!
 */

;
(function($) {

	if (/1\.(0|1|2)\.(0|1|2)/.test($.fn.jquery) || /^1.1/.test($.fn.jquery)) {
		alert('blockUI requires jQuery v1.2.3 or later!  You are using v' + $.fn.jquery);
		return;
	}

	$.fn._fadeIn = $.fn.fadeIn;

	var noOp = function() {
	};
	// this bit is to ensure we don't call setExpression when we shouldn't (with extra muscle to handle
	// retarded userAgent strings on Vista)
	var mode = document.documentMode || 0;
	var setExpr = $.browser.msie && (($.browser.version < 8 && !mode) || mode < 8);
	var ie6 = $.browser.msie && /MSIE 6.0/.test(navigator.userAgent) && !mode;

	// global $ methods for blocking/unblocking the entire page
	$.blockUI   = function(opts) {
		install(window, opts);
	};
	$.unblockUI = function(opts) {
		remove(window, opts);
	};
	// convenience method for quick growl-like notifications  (http://www.google.com/search?q=growl)
	$.growlUI = function(title, message, timeout, onClose) {
		var $m = $('<div class="growlUI"></div>');
		if (title)
			$m.append('<h1>'+title+'</h1>');
		if (message)
			$m.append('<h2>'+message+'</h2>');
		if (timeout == undefined)
			timeout = 3000;
		$.blockUI({
			message: $m,
			fadeIn: 700,
			fadeOut: 1000,
			centerY: false,
			timeout: timeout,
			showOverlay: false,
			onUnblock: onClose,
			css: $.blockUI.defaults.growlCSS
		});
	};
	// plugin method for blocking element content
	$.fn.block = function(opts) {
		return this.unblock({
			fadeOut: 0
		}).each( function() {
			if ($.css(this,'position') == 'static')
				this.style.position = 'relative';
			if ($.browser.msie)
				this.style.zoom = 1; // force 'hasLayout'
			install(this, opts);
		});
	};
	// plugin method for unblocking element content
	$.fn.unblock = function(opts) {
		return this.each( function() {
			remove(this, opts);
		});
	};
	$.blockUI.version = 2.31; // 2nd generation blocking at no extra cost!

	// override these in your code to change the default behavior and style
	$.blockUI.defaults = {
		// message displayed when blocking (use null for no message)
		message:  '<h1>Please wait...</h1>',

		title: null,	  // title string; only used when theme == true
		draggable: true,  // only used when theme == true (requires jquery-ui.js to be loaded)

		theme: false, // set to true to use with jQuery UI themes

		// styles for the message when blocking; if you wish to disable
		// these and use an external stylesheet then do this in your code:
		// $.blockUI.defaults.css = {};

		// top:		'40%',
		// ==> top:		'400px',
		// in the iFrame
		css: {
			padding:	'3px',
			margin:		0,
			width:		'30%',
			top:		'200px',
			left:		'35%',
			textAlign:	'center',
			color:		'#000',
			border:		'3px solid #000',
			backgroundColor:'#fff',
			cursor:		'wait'
		},

		// minimal style set used when themes are used
		themedCSS: {
			width:	'30%',
			top:	'40%',
			left:	'35%'
		},

		// styles for the overlay
		overlayCSS: {
			backgroundColor: '#FFF',
			opacity:	  	 0.6,
			cursor:		  	 'wait'
		},

		// styles applied when using $.growlUI
		growlCSS: {
			width:  	'350px',
			top:		'10px',
			left:   	'',
			right:  	'10px',
			border: 	'none',
			padding:	'5px',
			opacity:	0.6,
			cursor: 	'default',
			color:		'#fff',
			backgroundColor: '#000',
			'-webkit-border-radius': '10px',
			'-moz-border-radius':	 '10px'
		},

		// IE issues: 'about:blank' fails on HTTPS and javascript:false is s-l-o-w
		// (hat tip to Jorge H. N. de Vasconcelos)
		iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank',

		// force usage of iframe in non-IE browsers (handy for blocking applets)
		forceIframe: false,

		// z-index for the blocking overlay
		baseZ: 1000,

		// set these to true to have the message automatically centered
		centerX: true, // <-- only effects element blocking (page block controlled via css above)
		centerY: true,

		// allow body element to be stetched in ie6; this makes blocking look better
		// on "short" pages.  disable if you wish to prevent changes to the body height
		allowBodyStretch: true,

		// enable if you want key and mouse events to be disabled for content that is blocked
		bindEvents: true,

		// be default blockUI will supress tab navigation from leaving blocking content
		// (if bindEvents is true)
		constrainTabKey: true,

		// fadeIn time in millis; set to 0 to disable fadeIn on block
		fadeIn:  200,

		// fadeOut time in millis; set to 0 to disable fadeOut on unblock
		fadeOut:  400,

		// time in millis to wait before auto-unblocking; set to 0 to disable auto-unblock
		timeout: 0,

		// disable if you don't want to show the overlay
		showOverlay: true,

		// if true, focus will be placed in the first available input field when
		// page blocking
		focusInput: true,

		// suppresses the use of overlay styles on FF/Linux (due to performance issues with opacity)
		applyPlatformOpacityRules: true,

		// callback method invoked when fadeIn has completed and blocking message is visible
		onBlock: null,

		// callback method invoked when unblocking has completed; the callback is
		// passed the element that has been unblocked (which is the window object for page
		// blocks) and the options that were passed to the unblock call:
		//	 onUnblock(element, options)
		onUnblock: null,

		// don't ask; if you really must know: http://groups.google.com/group/jquery-en/browse_thread/thread/36640a8730503595/2f6a79a77a78e493#2f6a79a77a78e493
		quirksmodeOffsetHack: 4
	};

	// private data and functions follow...

	var pageBlock = null;
	var pageBlockEls = [];

	function install(el, opts) {
		var full = (el == window);
		var msg = opts && opts.message !== undefined ? opts.message : undefined;
		opts = $.extend({}, $.blockUI.defaults, opts || {});
		opts.overlayCSS = $.extend({}, $.blockUI.defaults.overlayCSS, opts.overlayCSS || {});
		var css = $.extend({}, $.blockUI.defaults.css, opts.css || {});
		var themedCSS = $.extend({}, $.blockUI.defaults.themedCSS, opts.themedCSS || {});
		msg = msg === undefined ? opts.message : msg;

		// remove the current block (if there is one)
		if (full && pageBlock)
			remove(window, {
				fadeOut:0
			});

		// if an existing element is being used as the blocking content then we capture
		// its current place in the DOM (and current display style) so we can restore
		// it when we unblock
		if (msg && typeof msg != 'string' && (msg.parentNode || msg.jquery)) {
			var node = msg.jquery ? msg[0] : msg;
			var data = {};
			$(el).data('blockUI.history', data);
			data.el = node;
			data.parent = node.parentNode;
			data.display = node.style.display;
			data.position = node.style.position;
			if (data.parent)
				data.parent.removeChild(node);
		}

		var z = opts.baseZ;

		// blockUI uses 3 layers for blocking, for simplicity they are all used on every platform;
		// layer1 is the iframe layer which is used to supress bleed through of underlying content
		// layer2 is the overlay layer which has opacity and a wait cursor (by default)
		// layer3 is the message content that is displayed while blocking

		var lyr1 = ($.browser.msie || opts.forceIframe)
		? $('<iframe class="blockUI" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;position:absolute;width:100%;height:100%;top:0;left:0" src="'+opts.iframeSrc+'"></iframe>')
		: $('<div class="blockUI" style="display:none"></div>');
		var lyr2 = $('<div class="blockUI blockOverlay" style="z-index:'+ (z++) +';display:none;border:none;margin:0;padding:0;width:100%;height:100%;top:0;left:0"></div>');

		var lyr3;
		if (opts.theme && full) {
			var s = '<div class="blockUI blockMsg blockPage ui-dialog ui-widget ui-corner-all" style="z-index:'+z+';display:none;position:fixed">' +
			'<div class="ui-widget-header ui-dialog-titlebar blockTitle">'+(opts.title || '&nbsp;')+'</div>' +
			'<div class="ui-widget-content ui-dialog-content"></div>' +
			'</div>';
			lyr3 = $(s);
		} else {
			lyr3 = full ? $('<div class="blockUI blockMsg blockPage" style="z-index:'+z+';display:none;position:fixed"></div>')
			: $('<div class="blockUI blockMsg blockElement" style="z-index:'+z+';display:none;position:absolute"></div>');
		}

		// if we have a message, style it
		if (msg) {
			if (opts.theme) {
				lyr3.css(themedCSS);
				lyr3.addClass('ui-widget-content');
			} else
				lyr3.css(css);
		}

		// style the overlay
		if (!opts.applyPlatformOpacityRules || !($.browser.mozilla && /Linux/.test(navigator.platform)))
			lyr2.css(opts.overlayCSS);
		lyr2.css('position', full ? 'fixed' : 'absolute');

		// make iframe layer transparent in IE
		if ($.browser.msie || opts.forceIframe)
			lyr1.css('opacity',0.0);

		//$([lyr1[0],lyr2[0],lyr3[0]]).appendTo(full ? 'body' : el);
		var layers = [lyr1,lyr2,lyr3], $par = full ? $('body') : $(el);
		$.each(layers, function() {
			this.appendTo($par);
		});
		if (opts.theme && opts.draggable && $.fn.draggable) {
			lyr3.draggable({
				handle: '.ui-dialog-titlebar',
				cancel: 'li'
			});
		}

		// ie7 must use absolute positioning in quirks mode and to account for activex issues (when scrolling)
		var expr = setExpr && (!$.boxModel || $('object,embed', full ? null : el).length > 0);
		if (ie6 || expr) {
			// give body 100% height
			if (full && opts.allowBodyStretch && $.boxModel)
				$('html,body').css('height','100%');

			// fix ie6 issue when blocked element has a border width
			if ((ie6 || !$.boxModel) && !full) {
				var t = sz(el,'borderTopWidth'), l = sz(el,'borderLeftWidth');
				var fixT = t ? '(0 - '+t+')' : 0;
				var fixL = l ? '(0 - '+l+')' : 0;
			}

			// simulate fixed position
			$.each([lyr1,lyr2,lyr3], function(i,o) {
				var s = o[0].style;
				s.position = 'absolute';
				if (i < 2) {
					full ? s.setExpression('height','Math.max(document.body.scrollHeight, document.body.offsetHeight) - (jQuery.boxModel?0:'+opts.quirksmodeOffsetHack+') + "px"')
					: s.setExpression('height','this.parentNode.offsetHeight + "px"');
					full ? s.setExpression('width','jQuery.boxModel && document.documentElement.clientWidth || document.body.clientWidth + "px"')
					: s.setExpression('width','this.parentNode.offsetWidth + "px"');
					if (fixL)
						s.setExpression('left', fixL);
					if (fixT)
						s.setExpression('top', fixT);
				} else if (opts.centerY) {
					if (full)
						s.setExpression('top','(document.documentElement.clientHeight || document.body.clientHeight) / 2 - (this.offsetHeight / 2) + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + "px"');
					s.marginTop = 0;
				} else if (!opts.centerY && full) {
					var top = (opts.css && opts.css.top) ? parseInt(opts.css.top) : 0;
					var expression = '((document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) + '+top+') + "px"';
					s.setExpression('top',expression);
				}
			});
		}

		// show the message
		if (msg) {
			if (opts.theme)
				lyr3.find('.ui-widget-content').append(msg);
			else
				lyr3.append(msg);
			if (msg.jquery || msg.nodeType)
				$(msg).show();
		}

		if (($.browser.msie || opts.forceIframe) && opts.showOverlay)
			lyr1.show(); // opacity is zero
		if (opts.fadeIn) {
			var cb = opts.onBlock ? opts.onBlock : noOp;
			var cb1 = (opts.showOverlay && !msg) ? cb : noOp;
			var cb2 = msg ? cb : noOp;
			if (opts.showOverlay)
				lyr2._fadeIn(opts.fadeIn, cb1);
			if (msg)
				lyr3._fadeIn(opts.fadeIn, cb2);
		} else {
			if (opts.showOverlay)
				lyr2.show();
			if (msg)
				lyr3.show();
			if (opts.onBlock)
				opts.onBlock();
		}

		// bind key and mouse events
		bind(1, el, opts);

		if (full) {
			pageBlock = lyr3[0];
			pageBlockEls = $(':input:enabled:visible',pageBlock);
			if (opts.focusInput)
				setTimeout(focus, 20);
		} else
			center(lyr3[0], opts.centerX, opts.centerY);

		if (opts.timeout) {
			// auto-unblock
			var to = setTimeout( function() {
				full ? $.unblockUI(opts) : $(el).unblock(opts);
			}, opts.timeout);
			$(el).data('blockUI.timeout', to);
		}
	};

	// remove the block
	function remove(el, opts) {
		var full = (el == window);
		var $el = $(el);
		var data = $el.data('blockUI.history');
		var to = $el.data('blockUI.timeout');
		if (to) {
			clearTimeout(to);
			$el.removeData('blockUI.timeout');
		}
		opts = $.extend({}, $.blockUI.defaults, opts || {});
		bind(0, el, opts); // unbind events

		var els;
		if (full) // crazy selector to handle odd field errors in ie6/7
			els = $('body').children().filter('.blockUI').add('body > .blockUI');
		else
			els = $('.blockUI', el);

		if (full)
			pageBlock = pageBlockEls = null;

		if (opts.fadeOut) {
			els.fadeOut(opts.fadeOut);
			setTimeout( function() {
				reset(els,data,opts,el);
			}, opts.fadeOut);
		} else
			reset(els, data, opts, el);
	};

	// move blocking element back into the DOM where it started
	function reset(els,data,opts,el) {
		els.each( function(i,o) {
			// remove via DOM calls so we don't lose event handlers
			if (this.parentNode)
				this.parentNode.removeChild(this);
		});
		if (data && data.el) {
			data.el.style.display = data.display;
			data.el.style.position = data.position;
			if (data.parent)
				data.parent.appendChild(data.el);
			$(el).removeData('blockUI.history');
		}

		if (typeof opts.onUnblock == 'function')
			opts.onUnblock(el,opts);
	};

	// bind/unbind the handler
	function bind(b, el, opts) {
		var full = el == window, $el = $(el);

		// don't bother unbinding if there is nothing to unbind
		if (!b && (full && !pageBlock || !full && !$el.data('blockUI.isBlocked')))
			return;
		if (!full)
			$el.data('blockUI.isBlocked', b);

		// don't bind events when overlay is not in use or if bindEvents is false
		if (!opts.bindEvents || (b && !opts.showOverlay))
			return;

		// bind anchors and inputs for mouse and key events
		var events = 'mousedown mouseup keydown keypress';
		b ? $(document).bind(events, opts, handler) : $(document).unbind(events, handler);

		// former impl...
		//	   var $e = $('a,:input');
		//	   b ? $e.bind(events, opts, handler) : $e.unbind(events, handler);
	};

	// event handler to suppress keyboard/mouse events when blocking
	function handler(e) {
		// allow tab navigation (conditionally)
		if (e.keyCode && e.keyCode == 9) {
			if (pageBlock && e.data.constrainTabKey) {
				var els = pageBlockEls;
				var fwd = !e.shiftKey && e.target == els[els.length-1];
				var back = e.shiftKey && e.target == els[0];
				if (fwd || back) {
					setTimeout( function() {
						focus(back)
					},10);
					return false;
				}
			}
		}
		// allow events within the message content
		if ($(e.target).parents('div.blockMsg').length > 0)
			return true;

		// allow events for content that is not being blocked
		return $(e.target).parents().children().filter('div.blockUI').length == 0;
	};

	function focus(back) {
		if (!pageBlockEls)
			return;
		var e = pageBlockEls[back===true ? pageBlockEls.length-1 : 0];
		if (e)
			e.focus();
	};

	function center(el, x, y) {
		var p = el.parentNode, s = el.style;
		var l = ((p.offsetWidth - el.offsetWidth)/2) - sz(p,'borderLeftWidth');
		var t = ((p.offsetHeight - el.offsetHeight)/2) - sz(p,'borderTopWidth');
		if (x)
			s.left = l > 0 ? (l+'px') : '0';
		if (y)
			s.top  = t > 0 ? (t+'px') : '0';
	};

	function sz(el, p) {
		return parseInt($.css(el,p))||0;
	};

})(jQuery);
savedParameters = new Object();
var lastParameterName;
var lastParameterValue;
var newParameterName;
var newParameterValue;

function delaySubmission(element, callback) {
	lastParameterName = element.attr("name");
	lastParameterValue = element.val();
	setTimeout( function() {
		newParameterName = element.attr("name");
		newParameterValue = element.val();
		if ((newParameterName == lastParameterName) && (lastParameterValue == newParameterValue) && (savedParameters.lastParameterName != lastParameterValue)) {
			callback(element);
			savedParameters.lastParameterName = lastParameterValue;
		}
	}, 800);
}

function blockUI(scenario) {
	switch(scenario) {
		case "addtags":
			$.blockUI({
				message: '<h1><img src="/vms/images/busy.gif" />Updating Tags. Please wait...<br>Tip: Did you know you can use commas in your submissions to create multiple tags at once?</h1>'
			});
			break;

		case "deleteasset":
			$.blockUI({
				message: '<h1><img src="/vms/images/busy.gif" />Deleting asset</h1>This should be quick.'
			});
			break;

		case "createwidget":
			$.blockUI({
				message: '<h1><img src="/vms/images/busy.gif" />Create a new Widget</h1>This should be quick.'
			});
			break;

		case "emailexpress":
			$.blockUI({
				message: '<img src="/vms/images/busy.gif" /><b>Well that\'s a cool video!</b> Liveclicker is now encoding it. When complete, you will be taken to the video email builder page. Please be patient!'
			});
			break;
			
		case "failedcreatewidget":
			var messageWidth = 530;
			var StageWidth = $(window).width();
			var leftMargin = (StageWidth - messageWidth) / 2;
			$.blockUI({
				message: "<h1>Oops.. Something bizarre happened.</h1> Looks like we weren't able to create a widget. Can you please try again?<br><br><br><a href='javascript:void(0);' onclick='unblockUI();'><span id='closethisblockui' class='blockUINegative'>Okay!</span></a>" ,
				css: {
					padding: '15px',
					width: messageWidth+'px',
					left: leftMargin+'px',
					height: '70px'
				}
			});
			break;

		case "unapprovedwidget":
			var messageWidth = 530;
			var StageWidth = $(window).width();
			var leftMargin = (StageWidth - messageWidth) / 2;
			$.blockUI({
				message: "<h1>You need to approve the asset first</h1> Before creating a widget you need to approve the asset.<br><br><br><a href='javascript:void(0);' onclick='unblockUI();'><span id='closethisblockui' class='blockUINegative'>Okay, let me approve it and try again!</span></a>" ,
				css: {
					padding: '15px',
					width: messageWidth+'px',
					left: leftMargin+'px',
					height: '70px'
				}
			});
			break;

		case "faileddeleteasset":
			var messageWidth = 530;
			var StageWidth = $(window).width();
			var leftMargin = (StageWidth - messageWidth) / 2;
			$.blockUI({
				message: "<h1>Oops.. Something bizarre happened.</h1> Looks like we weren't able to delete this asset. Can you please try again?<br><br><br><a href='javascript:void(0);' onclick='unblockUI();'><span id='closethisblockui' class='blockUINegative'>Okay!</span></a>" ,
				css: {
					padding: '15px',
					width: messageWidth+'px',
					left: leftMargin+'px',
					height: '70px'
				}
			});
			break;

		case "uploaddone":
			var messageWidth = 530;
			var StageWidth = $(window).width();
			var leftMargin = (StageWidth - messageWidth) / 2;
			$.blockUI({
				message: "<h1>Upload successful</h1> Your upload was successful. You can either upload a new video or access the asset list to see the status of your upload.<br><br><br><a href='javascript:void(0);' onclick='unblockUI();'><span id='closethisblockui' class='blockUINegative'>Upload another video</span></a>&nbsp;&nbsp;<a href='listasset.php'><span id='closethisblockui' class='blockUIPositive'>Take me to the asset list</span></a>" ,
				css: {
					padding: '15px',
					width: messageWidth+'px',
					left: leftMargin+'px',
					height: '70px'
				}
			});
			break;
		case "newuploadversiondone":
			var messageWidth = 530;
			var StageWidth = $(window).width();
			var leftMargin = (StageWidth - messageWidth) / 2;
			$.blockUI({
				message: "<h1>Upload successful</h1> Your upload was successful. You can either upload a new video or access the asset list to see the status of your upload.<br><br><br><a href='javascript:void(0);' onclick='unblockUI();'><span id='closethisblockui' class='blockUINegative'>Okay!</span></a>" ,
				css: {
					padding: '15px',
					width: messageWidth+'px',
					left: leftMargin+'px',
					height: '70px'
				}
			});
			break;
		case "faileddeletewidget":
			var messageWidth = 530;
			var StageWidth = $(window).width();
			var leftMargin = (StageWidth - messageWidth) / 2;
			$.blockUI({
				message: "<h1>Oops.. Something bizarre happened.</h1> Looks like we weren't able to delete this. Can you please try again?<br><br><br><a href='javascript:void(0);' onclick='unblockUI();'><span id='closethisblockui' class='blockUINegative'>Okay!</span></a>" ,
				css: {
					padding: '15px',
					width: messageWidth+'px',
					left: leftMargin+'px',
					height: '70px'
				}
			});
			break;

		case "deletewidget":
			$.blockUI({
				message: '<h1><img src="/vms/images/busy.gif" />Deleting the widget</h1>This should be quick.'
			});
			break;

		case "createwidget":
			$.blockUI({
				message: '<h1><img src="/vms/images/busy.gif" />Create a new Widget</h1>This should be quick.'
			});
			break;

		case "publish":
			$.blockUI({
				message: '<h1><img src="/vms/images/busy.gif" />Updating distribution options...</h1>'
			});
			break;
		case "listofwidgets":
			$.blockUI({
				message: '<h1><img src="/vms/images/busy.gif" />Updating the list of widgets...</h1> Please wait... should be pretty quick!'
			});
			break;
		case "listofassets":
			$.blockUI({
				message: '<h1><img src="/vms/images/busy.gif" />Updating the list of assets...</h1> Please wait... should be pretty quick!'
			});
			break;
		case "updateassignment":
			var messageWidth = 530;
			var StageWidth = $(window).width();
			var leftMargin = (StageWidth - messageWidth) / 2;
			$.blockUI({
				message: "<h1>Sorry to bother, but are you sure?</h1> Changing the original asset is a big deal and cannot be undone.<br>Do you want to continue?<br><br><span id='thatsokupdateassignment' class='blockUINegative'>Yes, let's go make the update!</span>&nbsp;&nbsp;<span id='thatsnotokupdateassignment' class='blockUIPositive'>No, let me check one last time.</span>" ,
				css: {
					padding: '15px',
					width: messageWidth+'px',
					left: leftMargin+'px',
					height: '70px'
				}
			});
			break;
		case "missinglinks":
			var messageWidth = 530;
			var StageWidth = $(window).width();
			var leftMargin = (StageWidth - messageWidth) / 2;
			$.blockUI({
				message: "<h1>Really? You didn't attach any links.</h1> Without your help Liveclicker can't link this great video to any product.<br><br><span id='thatsoklinks' class='blockUINegative'>That's fine, this widget has no products.</span>&nbsp;&nbsp;<span id='iforgotlinks' class='blockUIPositive'>Good catch! let me add a link now.</span>" ,
				css: {
					padding: '15px',
					width: messageWidth+'px',
					left: leftMargin+'px',
					height: '70px'
				}
			});
			break;
		default:
			$.blockUI({
				message: '<h1><img src="/vms/images/busy.gif" />Please wait...</h1>'
			});
			break;
	}
}

function unblockUI() {
	$.unblockUI();
	return false;
}

function addCommas(nStr) {
	nStr += '';
	x = nStr.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;
}

// tooltip

/*
 * TipTip
 * Copyright 2010 Drew Wilson
 * www.drewwilson.com
 * code.drewwilson.com/entry/tiptip-jquery-plugin
 *
 * Version 1.3   -   Updated: Mar. 23, 2010
 *
 * This Plug-In will create a custom tooltip to replace the default
 * browser tooltip. It is extremely lightweight and very smart in
 * that it detects the edges of the browser window and will make sure
 * the tooltip stays within the current window size. As a result the
 * tooltip will adjust itself to be displayed above, below, to the left
 * or to the right depending on what is necessary to stay within the
 * browser window. It is completely customizable as well via CSS.
 *
 * This TipTip jQuery plug-in is dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

(function($) {
	$.fn.tipTip = function(options) {
		var defaults = {
			activation: "hover",
			keepAlive: false,
			maxWidth: "270px",
			edgeOffset: 3,
			defaultPosition: "top",
			delay: 700,
			fadeIn: 200,
			fadeOut: 200,
			attribute: "title",
			content: false, // HTML or String to fill TipTIp with
			enter: function() {
			},
			exit: function() {
			}
		};
		var opts = $.extend(defaults, options);

		// Setup tip tip elements and render them to the DOM
		if($("#tiptip_holder").length <= 0) {
			var tiptip_holder = $('<div id="tiptip_holder" style="max-width:'+ opts.maxWidth +';"></div>');
			var tiptip_content = $('<div id="tiptip_content"></div>');
			var tiptip_arrow = $('<div id="tiptip_arrow"></div>');
			$("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>')));
		} else {
			var tiptip_holder = $("#tiptip_holder");
			var tiptip_content = $("#tiptip_content");
			var tiptip_arrow = $("#tiptip_arrow");
		}

		return this.each( function() {
			var org_elem = $(this);
			if(opts.content) {
				var org_title = opts.content;
			} else {
				var org_title = org_elem.attr(opts.attribute);
			}
			if(org_title != "") {
				if(!opts.content) {
					org_elem.removeAttr(opts.attribute); //remove original Attribute
				}
				var timeout = false;

				if(opts.activation == "hover") {
					org_elem.hover( function() {
						active_tiptip();
					}, function() {
						if(!opts.keepAlive) {
							deactive_tiptip();
						}
					});
					if(opts.keepAlive) {
						tiptip_holder.hover( function() {
						}, function() {
							deactive_tiptip();
						});
					}
				} else if(opts.activation == "focus") {
					org_elem.focus( function() {
						active_tiptip();
					}).blur( function() {
						deactive_tiptip();
					});
				} else if(opts.activation == "click") {
					org_elem.click( function() {
						active_tiptip();
						return false;
					}).hover( function() {
					}, function() {
						if(!opts.keepAlive) {
							deactive_tiptip();
						}
					});
					if(opts.keepAlive) {
						tiptip_holder.hover( function() {
						}, function() {
							deactive_tiptip();
						});
					}
				}

				function active_tiptip() {
					opts.enter.call(this);
					tiptip_content.html(org_title);
					tiptip_holder.hide().removeAttr("class").css("margin","0");
					tiptip_arrow.removeAttr("style");

					var top = parseInt(org_elem.offset()['top']);
					var left = parseInt(org_elem.offset()['left']);
					var org_width = parseInt(org_elem.outerWidth());
					var org_height = parseInt(org_elem.outerHeight());
					var tip_w = tiptip_holder.outerWidth();
					var tip_h = tiptip_holder.outerHeight();
					var w_compare = Math.round((org_width - tip_w) / 2);
					var h_compare = Math.round((org_height - tip_h) / 2);
					var marg_left = Math.round(left + w_compare);
					var marg_top = Math.round(top + org_height + opts.edgeOffset);
					var t_class = "";
					var arrow_top = "";
					var arrow_left = Math.round(tip_w - 12) / 2;

					if(opts.defaultPosition == "bottom") {
						t_class = "_bottom";
					} else if(opts.defaultPosition == "top") {
						t_class = "_top";
					} else if(opts.defaultPosition == "left") {
						t_class = "_left";
					} else if(opts.defaultPosition == "right") {
						t_class = "_right";
					}

					var right_compare = (w_compare + left) < parseInt($(window).scrollLeft());
					var left_compare = (tip_w + left) > parseInt($(window).width());

					if((right_compare && w_compare < 0) || (t_class == "_right" && !left_compare) || (t_class == "_left" && left < (tip_w + opts.edgeOffset + 5))) {
						t_class = "_right";
						arrow_top = Math.round(tip_h - 13) / 2;
						arrow_left = -12;
						marg_left = Math.round(left + org_width + opts.edgeOffset);
						marg_top = Math.round(top + h_compare);
					} else if((left_compare && w_compare < 0) || (t_class == "_left" && !right_compare)) {
						t_class = "_left";
						arrow_top = Math.round(tip_h - 13) / 2;
						arrow_left =  Math.round(tip_w);
						marg_left = Math.round(left - (tip_w + opts.edgeOffset + 5));
						marg_top = Math.round(top + h_compare);
					}

					var top_compare = (top + org_height + opts.edgeOffset + tip_h + 8) > parseInt($(window).height() + $(window).scrollTop());
					var bottom_compare = ((top + org_height) - (opts.edgeOffset + tip_h + 8)) < 0;

					if(top_compare || (t_class == "_bottom" && top_compare) || (t_class == "_top" && !bottom_compare)) {
						if(t_class == "_top" || t_class == "_bottom") {
							t_class = "_top";
						} else {
							t_class = t_class+"_top";
						}
						arrow_top = tip_h;
						marg_top = Math.round(top - (tip_h + 5 + opts.edgeOffset));
					} else if(bottom_compare | (t_class == "_top" && bottom_compare) || (t_class == "_bottom" && !top_compare)) {
						if(t_class == "_top" || t_class == "_bottom") {
							t_class = "_bottom";
						} else {
							t_class = t_class+"_bottom";
						}
						arrow_top = -12;
						marg_top = Math.round(top + org_height + opts.edgeOffset);
					}

					if(t_class == "_right_top" || t_class == "_left_top") {
						marg_top = marg_top + 5;
					} else if(t_class == "_right_bottom" || t_class == "_left_bottom") {
						marg_top = marg_top - 5;
					}
					if(t_class == "_left_top" || t_class == "_left_bottom") {
						marg_left = marg_left + 5;
					}
					tiptip_arrow.css({
						"margin-left": arrow_left+"px",
						"margin-top": arrow_top+"px"
					});
					tiptip_holder.css({
						"margin-left": marg_left+"px",
						"margin-top": marg_top+"px"
					}).attr("class","tip"+t_class);

					if (timeout) {
						clearTimeout(timeout);
					}
					timeout = setTimeout( function() {
						tiptip_holder.stop(true,true).fadeIn(opts.fadeIn);
					}, opts.delay);
				}

				function deactive_tiptip() {
					opts.exit.call(this);
					if (timeout) {
						clearTimeout(timeout);
					}
					tiptip_holder.fadeOut(opts.fadeOut);
				}

			}
		});
	}
})(jQuery);
jQuery(document).ready( function() {
	jQuery(".fadeoutafter5seconds").fadeOut(5000);	
	jQuery(".fadeoutafter2seconds").fadeOut(2000);	
	try {
		jQuery(".tiptip").tipTip();
	} catch (err) {

	}

	jQuery(".videotutorialclosebtn").click( function() {
		// close the video
		jQuery("#LiveclickerVideoDiv").empty();
		jQuery(".insertvideo").slideUp(300, function() {
			$("#blackveil").fadeOut(300);
		});
	});
	jQuery(".videotutoriallink").hover( function() {
		var thisWidgetId = jQuery(this).attr('widget_id');
		jQuery("#playbtn"+thisWidgetId).css("opacity", 1);
	}, function() {
		var thisWidgetId = jQuery(this).attr('widget_id');
		jQuery("#playbtn"+thisWidgetId).css("opacity", 0.4);
	})
	.click( function() {
		var playerW = 10+jQuery(".reportingtable").width();
		var thisWidgetId = jQuery(this).attr('widget_id');
		var thisAid = jQuery(this).attr('aid');
		var ajustedLeft = (-667  + $(window).width()) / 2;
		jQuery(".insertvideo").css("left", ajustedLeft+"px").slideDown(300, function() {
			$('head').append('<script type="text/javascript" src="http://sv.liveclicker.net/service/getEmbed?autoplay=true&cdn_prefix=http://cdn.liveclicker.net&account_id='+thisAid+'&player_custom_id=1&width=640&height=360&widget_id='+thisWidgetId+'&div_id=LiveclickerVideoDiv"></script>');
			$("#blackveil").fadeIn(300);
		});
	});
})
