function change(f){
	var url = f.url.value || "#";	
	var line1 = document.getElementById('l1');
	var line2 = document.getElementById('l2');
	line1.innerHTML = '<font size=2><b><a tabindex="-1" href="' + url + '" class="tbln1" target="_blank">' + f.line1.value.replace(/</gi, "&lt;") + '</a></b></font>';
//	l2.innerHTML = '<a href="' + url + '" class="tbln2">' + f.line2.value.replace(/\n/gi, "<br>") + '</a><br />\n<a href="' + url + '" class="tbln1">' + f.line3.value + '</a>\n';
	line2.innerHTML = '<font size=2>' + f.line2.value.replace(/</gi, "&lt;")   + '<br>' + f.line4.value.replace(/</gi, "&lt;") + '<br />\n<a tabindex="-1" href="' + url + '" class="tbln1" target="_blank">' + f.line3.value + '</a></font>\n';
}

function validate_create_banner(myForm) {
	valid = 1;
	errorStr = "Please Correct The Following Errors.\n\n";
	if (myForm.line1.value == '') { valid = 0; errorStr += "· Ad Headline is blank\n"; }
	if (myForm.line2.value == '') { valid = 0; errorStr += "· Ad Description Line is blank\n"; }
	if (myForm.line3.value == '') { valid = 0; errorStr += "· Linked line is blank\n"; }
	if (myForm.url.value == '' || myForm.url == 'http://') { valid = 0; errorStr += "· URL is blank\n\n"; }
	if (valid == 1) { myForm.submit(); return true; }
	else { alert(errorStr); return false; }
}



// Set on key handler for moving using by Ctrl+arrows //
document.onkeydown = onKeyDownArrowsHandler;


function onKeyDownArrowsHandler(e) {
    e = e||window.event;
    var o = (e.srcElement||e.target);
    if (!o) return;
    if (o.tagName != "TEXTAREA" && o.tagName != "INPUT" && o.tagName != "SELECT") return;
    if (!e.ctrlKey) return;
    if (!o.id) return;

    var pos = o.id.split("_");
    if (pos[0] != "field" || typeof pos[2] == "undefined") return;

    var x = pos[2], y=pos[1];
    
    // skip non existent fields
    for (i=0; i<10; i++)
    {
        switch(e.keyCode) {
            case 38: y--; break; // up
            case 40: y++; break; // down
            case 37: x--; break; // left
            case 39: x++; break; // right
            default: return;
        }

        var id = "field_" + y + "_" + x;
        var nO = document.getElementById(id);
        if (!nO) {
            var id = "field_" + y + "_" + x + "_0";
            var nO = document.getElementById(id);
        }
        if (nO) break;
    }
    
    if (!nO) return;
    nO.focus();
    if (nO.tagName != 'SELECT') {
        nO.select();
    }
    e.returnValue = false;
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit){
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}

function findObj(n, d) {
  var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0 && parent.frames.length) {d=parent.frames[n.substring(p+1)].document;
  n=n.substring(0,p);} if(!(x=d[n]) && d.all) x=d.all[n]; for (i=0; !x && i < d.forms.length; i++) x=d.forms[i][n];
  for(i=0; !x && d.layers && i < d.layers.length; i++) x=findObj(n,d.layers[i].document); if(!x && document.getElementById)
  x=document.getElementById(n); return x;
}

function CopyClipboard(obj)
{
	obj = findObj(obj);
	if (obj) {
		window.clipboardData.setData('Text', obj.value);
	}
}


// Cookie Functions //
function addCookie(tag, value) {
	var expireDate = new Date();
	var expireString = "";
	expireDate.setTime(expireDate.getTime() + (1000 * 60 * 60 * 24 * 365));
	expireString = "expires=" + expireDate.toGMTString();
	document.cookie = tag + "=" + escape(value) + ";" + expireString + ";";
}

function getCookie(tag) {
	var value = null;
	var myCookie = document.cookie + ";";
	var findTag = tag + "=";
	var endPos;
	if (myCookie.length > 0) {
		var beginPos = myCookie.indexOf(findTag);
	if (beginPos != -1) {
		beginPos = beginPos + findTag.length;
		endPos = myCookie.indexOf(";",beginPos);
		if (endPos == -1)
			endPos = myCookie.length;
			value = unescape(myCookie.substring(beginPos,endPos));
		}
	}
	return value;
}

function deleteCookie(cookie) {
	var yesterday = 24 * 60 * 60 * 1000;
	var expireDate = new Date();
	expireDate.setTime (expireDate.getTime() - yesterday);
	document.cookie = cookie + "=" + escape("nothing") + ";" + "expires"+ "=" + expireDate.toGMTString();
}

	function createSelectorCheckbox(selectorName, destinationTitle, idPrefix, notificationFunction)
	{
		var selectorInstance = new Object();
		
		selectorInstance.destinationTitle = destinationTitle;
		selectorInstance.idPrefix = idPrefix;
		selectorInstance.boxes = new Array();
		selectorInstance.notificationFunction = false;
		
		if (notificationFunction)
		{
			selectorInstance.notificationFunction = notificationFunction;			
		}
		
		selectorCheckboxInstanceList[selectorName] = selectorInstance;
	}
	
	function addSelectorCheckboxItem(selectorName, id, active, title, description, exclusive, isParent)
	{
		var selectorInstance = getSelectorCheckboxInstance(selectorName);
		if (selectorInstance == null)
		{
			return;	
		}
		
		selectorCheckbox = new Object();
		
		selectorCheckbox.id = id;
		selectorCheckbox.title = title;
		selectorCheckbox.description = description;
		selectorCheckbox.exclusive = exclusive;
		selectorCheckbox.isParent = isParent;
		selectorCheckbox.active = active;
		
		selectorInstance.boxes[selectorInstance.boxes.length] = selectorCheckbox;
	}
	
	function getSelectorCheckboxInstance(selectorName)
	{
		if (selectorCheckboxInstanceList[selectorName] != null)
		{
			return selectorCheckboxInstanceList[selectorName];
		}
		if (!selectorCheckboxErrorOccurred)
		{
			alert("Failed to find the checkbox definition: " + selectorName);
			selectorCheckboxErrorOccurred = true;
		}
		return null;
	}
	
	function updateAllSelectorCheckboxItemsState(selectorName, checked)
	{
		var selectorInstance= getSelectorCheckboxInstance(selectorName);
		if (selectorInstance == null)
		{
			return;
		}

		for (x = 0; x < selectorInstance.boxes.length; x++)
		{
			selectorInstance.boxes[x].active = checked;
			var tempBox = document.getElementById(selectorInstance.idPrefix + x);
			if (tempBox)
			{
				tempBox.checked = checked;
			}
		}
		sendSelectorCheckboxNotification(selectorInstance);
	}
	
	function updateSelectorCheckboxItemStateByID(selectorName, checkboxID, checked)
	{
		var selectorInstance= getSelectorCheckboxInstance(selectorName);
		if (selectorInstance == null)
		{
			return;
		}

		for (x = 0; x < selectorInstance.boxes.length; x++)
		{
			if (selectorInstance.boxes[x].id == checkboxID)
			{
				selectorInstance.boxes[x].active = checked;
				var tempBox = document.getElementById(selectorInstance.idPrefix + x);
				if (tempBox)
				{
					tempBox.checked = checked;
				}
			}
		}		
		sendSelectorCheckboxNotification(selectorInstance);				
	}
	
	function updateSelectorCheckboxItemState(selectorName, checkbox)
	{
		var selectorInstance= getSelectorCheckboxInstance(selectorName);
		if (selectorInstance == null)
		{
			return;
		}
		var idString = checkbox.id;
		var boxIndex = idString.substr(selectorInstance.idPrefix.length);
		boxIndex = parseInt(boxIndex);

		if (checkbox.checked)
		{
			if (selectorInstance.boxes[boxIndex].exclusive)
			{
				firstExclusive = true;
				for (x = 0; x < selectorInstance.boxes.length; x++)
				{
					if (selectorInstance.boxes[x].active)
					{
						if (firstExclusive)
						{
							if (!confirm('The selected item is an exclusive option and cannot be combined with any other option.  Choosing it will deselect the other items you have selected.\n\nAre you sure you want to do this?'))
							{
								checkbox.checked = false;
								return;
							}
						}
						firstExclusive = false;
						
						selectorInstance.boxes[x].active = false;
						if (x != boxIndex)
						{
							var tempBox = document.getElementById(selectorInstance.idPrefix + x);
							if (tempBox)
							{
								tempBox.checked = false;
							}
						}
					}
				}
			}
			else
			{
				//Uncheck any exclusives
				for (x = 0; x < selectorInstance.boxes.length; x++)
				{
					if (selectorInstance.boxes[x].exclusive && selectorInstance.boxes[x].active)
					{
						selectorInstance.boxes[x].active = false;
						var tempBox = document.getElementById(selectorInstance.idPrefix + x);
						if (tempBox)
						{
							tempBox.checked = false;
						}
					}
				}
				
			}
			selectorInstance.boxes[boxIndex].active = true;
		}
		else
		{
			selectorInstance.boxes[boxIndex].active = false;
		}
		sendSelectorCheckboxNotification(selectorInstance);				
	}
	
	function updateSelectorCheckboxDestinationList(selectorName, destinationID)
	{
		var selectorInstance = getSelectorCheckboxInstance(selectorName);
		if (!selectorInstance)
		{
			return false;
		}
		
		var destinationList = document.getElementById(destinationID)
		var activeCount = 0;
				
		for (x = 0; x < selectorInstance.boxes.length; x++)
		{
			if (selectorInstance.boxes[x].active)
			{
				activeCount++;
			}
		}
		
		var htmlString = '';
		var removeAllURL = "<div style=\"margin: 0px; padding: 0px; float: right\"><a href=\"#\" onclick=\"updateAllSelectorCheckboxItemsState('" + selectorName + "', false); updateSelectorCheckboxDestinationList('" + selectorName + "', '" + destinationID + "'); return false;\">remove all</a></div>";
		if (activeCount > 0)
		{
			htmlString += removeAllURL;
		}
		
		if (selectorInstance.destinationTitle != "")
		{
			htmlString += '<h4>' + selectorInstance.destinationTitle + '</h4>';
		}
		
		htmlString += "<ul>"
		
		for (x = 0; x < selectorInstance.boxes.length; x++)
		{
			if (selectorInstance.boxes[x].active)
			{
				if (selectorInstance.boxes[x].isParent)
				{
					boxClassString = "selector_parent";
				}
				else
				{
					boxClassString = "selector_child";
				}
				htmlString += "<li class=\"" + boxClassString + "\"><input checked=\"true\" type=\"checkbox\" onclick=\"updateSelectorCheckboxItemStateByID('" + selectorName + "', '" + selectorInstance.boxes[x].id + "', false); updateSelectorCheckboxDestinationList('" + selectorName + "', '" + destinationID + "');\"/>" + selectorInstance.boxes[x].title;
				if (selectorInstance.boxes[x].description)
				{
					 htmlString += "<br/>" + selectorInstance.boxes[x].description;
				}
				+ '</li>';				
			}
		}
		htmlString += "</ul>";
		destinationList.innerHTML = htmlString;
	}
	
	function sendSelectorCheckboxNotification(selectorInstance)
	{
		if (selectorInstance.notificationFunction)
		{			
			var selectedCount = 0;
			var x;
			
			for (x = 0; x < selectorInstance.boxes.length; x++)
			{
				if (selectorInstance.boxes[x].active)
				{
					selectedCount++;
				}
			}
			eval(selectorInstance.notificationFunction + "(" + selectedCount + ")");
		}
	}
	var selectorCheckboxInstanceList = new Array();
	var selectorCheckboxErrorOccurred = false;

