function onDomLoad() {
	var startButton = document.getElementById('url_start_button');
	startButton.onmouseover = startButtonMouseOver;
	startButton.onmouseout = startButtonMouseOut;
	startButton.onmousedown = startButtonMouseDown;
	startButton.onmouseup = startButtonMouseUp;
	new Image().src="/editor/img/button_hover1.jpeg"; //preload image
}

function selectUrlBox() {
	var urlBox = document.getElementById("url_text_box");
	if ( urlBox.value.match(/\(ex:.*/i) ) {
		urlBox.value = "";
		urlBox.style.color = 'black';
		urlBox.style.fontStyle = 'normal';
		urlBox.style.paddingTop = '7px';
		urlBox.style.paddingBottom = '7px';
		urlBox.style.fontSize = '13pt';
		//url text box name set here
		//otherwise if user clicks start with only default text in url box, app will try to process default text as url
		urlBox.name = "url";
	}
}

/* Start Button */
function startButtonMouseOver() {
	YAHOO.util.Dom.addClass(this, 'start_button_onhover');
}
function startButtonMouseOut() {
	YAHOO.util.Dom.removeClass(this, 'start_button_onhover');
	YAHOO.util.Dom.removeClass(this, 'start_button_onclick')
}
function startButtonMouseDown() {
	YAHOO.util.Dom.addClass(this, 'start_button_onclick');
}
function startButtonMouseUp() {
	YAHOO.util.Dom.removeClass(this, 'start_button_onclick')
}

/* Bookmarklet info */
function showBookmarkletInfo() {
	displayForBrowser('bookmarklet_more_info_install_ie', 'bookmarklet_more_info_install_ie8', 'bookmarklet_more_info_install_ie9', 'bookmarklet_more_info_install_ff', 'bookmarklet_more_info_install_safari', 'bookmarklet_more_info_install_ipad');
}

/* Utilities */
function displayForBrowser(ie, ie8, ie9, ff, safari, ipad) {
	document.getElementById(ie).style.display = 'none';
	document.getElementById(ie8).style.display = 'none';
	document.getElementById(ie9).style.display = 'none';
	document.getElementById(ff).style.display = 'none';
	document.getElementById(safari).style.display = 'none';
	document.getElementById(ipad).style.display = 'none';
	
	if (YAHOO.env.ua.ie >= 9) {
		document.getElementById(ie9).style.display = 'inline';
	} else if (YAHOO.env.ua.ie >= 8) {
		document.getElementById(ie8).style.display = 'inline';
	} else if (YAHOO.env.ua.ie > 0) {
		document.getElementById(ie).style.display = 'inline';
	} else if ((navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPhone/i))) {
		document.getElementById(ipad).style.display = 'inline';
	}else if (YAHOO.env.ua.webkit > 0) {
		document.getElementById(safari).style.display = 'inline';
	} else {
		document.getElementById(ff).style.display = 'inline';
	}
}

function trimUrl(idOfUrl) {
	var elem = document.getElementById(idOfUrl);

	//trim the url
	elem.value = elem.value.replace(/^\s+/, '').replace(/\s+$/, '');

	//make sure a url has been entered
	if (elem.value.search(/^\(ex\:/) >= 0 || elem.value.length == 0) {
		alert("Please enter a url (ex. http://www.google.com)");
		return false;
	}

	return true;
}

function setClipListWidth(clipsList) {
	var clips = clipsList.getElementsByTagName("li");
	if (clips.length > 0) {
		var w = clips.length * 165;
		clipsList.style.width = w + 'px';
	}
}

/*-------- Bookmarklet Loader ------------*/
function generateBookmarkletLink(loaderFunctionId, linkId) {
	var loader = document.getElementById(loaderFunctionId).innerHTML;
	loader = loader.replace(/function.*\(\)/, "function()");
	loader = loader.replace(/\s/g, "");
	loader = loader.replace(/\"/g, "\\\"");
	loader = "javascript:(" + loader + ")();";
	if (linkId == 'bkmklt_link_ipad') {
		document.getElementById(linkId).value = loader;
	} else {
		document.getElementById(linkId).href = loader;
	}
}

/*-------- Delete ------------*/
function showDeletePanel(url, panel_body_id, panel_id, dash_box_id, update_clips_width) {
	window.deletePanel = new IFramePanel(url, panel_body_id, panel_id);
	window.deletePanel.dash_box_id = dash_box_id;
	window.deletePanel.update_clips_width = update_clips_width;
	window.scroll(0,0); //if user is scrolled down, window will appear scrolled off the top
	window.deletePanel.show();
}

function updateAfterDelete(response) {
	// Update dashboard page
	var dash_box = parent.document.getElementById( parent.deletePanel.dash_box_id )
	dash_box.innerHTML = response;
	
	if (parent.deletePanel.update_clips_width) {
		setClipListWidth( parent.document.getElementById("clips_list") );
	}

	// Close delete clips panel
	parent.deletePanel.hide();
}
