﻿function addRemoveVideoTags(tag, link) {
	var tags = new Array();
	var tagsTextBox = document.getElementById("ctl00_cphTop_tbVideoTags");

	// Get existing tags from the textbox and put them in an array.
	if (tagsTextBox.value != "") {
		var tempTagsTextBox = tagsTextBox.value;
		tempTagsTextBox = tagsTextBox.value.replace(/\, /g, ",").replace(/\,/g, "|");
		tags = tempTagsTextBox.split("|");
	}

	// Check if tags array contains tag.
	var tagFound = -1;
	for (i = 0; i < tags.length; i++) {
		if (tags[i] == tag) {
			tagFound = i;
		}
	}

	// If the tag exists, remove it.
	if (tagFound != -1) {
		tags.splice(tagFound, 1);
		link.style.fontWeight = "normal";
	}
	else {
		tags[tags.length] = tag;
		link.style.fontWeight = "bold";
	}

	// Add the array's contents to the textbox.
	tagsTextBox.value = tags.join(", ");
}

function suggestedTagsFontStyle() {
	// Get list of tags in the textbox.
    var tagsTextBox = document.getElementById("ctl00_cphTop_tbVideoTags");
	var tempTags = tagsTextBox.value.replace(/\, /g, ",").replace(/\,/g, "|");
	var selectedTags = tempTags.split("|");
	
	// Get list of suggested tags.
	var links = document.getElementsByTagName("a");
	var suggestedTags = new Array();
	var notASuggestedTag = new Array();
	for (i = 0; i < links.length; i++) {
		if (links[i].className == "suggestedTag") {
			suggestedTags[i] = links[i];
		}
		else {
			notASuggestedTag[i] = links[i];
		}
	}

	var tags = new Array();
	for (i = notASuggestedTag.length; i < suggestedTags.length; i++) {
		tags[i] = suggestedTags[i].innerHTML;
	}
	
	// Unbold all the suggested tags.
	for (i = notASuggestedTag.length; i < tags.length; i++) {
		suggestedTags[i].style.fontWeight = "normal";
	}
	
	// Check to see if a suggested tag exists in the textbox
	// and then bold that suggested tag.
	for (i = 0; i < selectedTags.length; i++) {
		for (j = 0; j < tags.length; j++) {
			if (selectedTags[i] == tags[j]) {
				suggestedTags[j].style.fontWeight = "bold";
			}
		}
	}

	// Add the array's contents to the textbox.
	tagsTextBox.value = selectedTags.join(", ");
}

function clearSearch(e) {
    elem = document.getElementById(e);
    //elem.value = "";

    if (elem.value == "Search for a video...") {
        elem.value = "";
    }
    else if (elem.value == "") {
        elem.value = "Search for a video...";
    }
}