// JavaScript Document

//==============================================================================
//		doStuff()
//==============================================================================
function doStuff() {
	}

//==============================================================================
//		ShowInWindow(theURL,winName,features)
//==============================================================================
function ShowInWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
	}

//==============================================================================
//		popupConfirmMsg(Message)
//	$PopupMessage = 'Are you sure you want to disable this account?';
//	$LinkString = "<a href=\"user_disable.php?user=5\" onclick=\"popupConfirmMsg('".$PopupMessage."');return document.MM_returnValue\">disable</a></td>\n";
//==============================================================================
function popupConfirmMsg(Message) {
        document.MM_returnValue = confirm(Message);
        return document.MM_returnValue;
        }

//==============================================================================
//		HandleDropdown(FormName)
//==============================================================================
function HandleDropdown(MenuName,baseURL) {
    var myIndex  = MenuName.selectedIndex
    var SelectedValue = MenuName.options[myIndex].value
    var redirectURL  = baseURL + SelectedValue
    window.location.href = redirectURL;
    return true;
        }

//==============================================================================
function selectionSearch() {
//==============================================================================
	selection = getSelText();
	var message = "Do you want to search Spotlight Online for " + selection + "?";
	var response = prompt(message,selection);
	if (response) {
		window.location = "search_main.php?searchtext=" + response;
		}
	}

//==============================================================================
function getSelText() {
//==============================================================================
    var txt = '';
     if (window.getSelection) {
        txt = window.getSelection();
        }
    else if (document.getSelection) {
        txt = document.getSelection();
        }
    else if (document.selection) {
        txt = document.selection.createRange().text;
        }
    else return;
	return txt;
	}

//==============================================================================
function checkVideoExtension() {
//==============================================================================
	var fileTypes = new Array('.avi','.AVI');
	var fileName = document.getElementById('video').value;
	var extension = fileName.substr(fileName.lastIndexOf('.'),fileName.length);
	var valid = 0;
	for (var i in fileTypes) {
		if (fileTypes[i] == extension) {
			valid = 1;
			break;
			}
		}
	if (valid != 1) {
		alert('Video files must be in .avi format.\n\n' +
			'Please choose an appropriate file to upload');
		return false;
		} else {
		return true;
		}
	}

// =============================================================================
// INPUT TEXT LENGTH COUNTER
// =============================================================================
function initJuNo() {
	setMaxLength();
	}

function setMaxLength() {
	var x = document.getElementsByTagName('input');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength') < 2000) {      // IE seems to set this high if it isn't set explicitly in the form.
			if (x[i].getAttribute('maxlength') != null) { // whereas FF sets it to null.
				var counterClone = counter.cloneNode(true);
				counterClone.relatedElement = x[i];
				counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
				x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
				x[i].relatedElement = counterClone.getElementsByTagName('span')[0];
				x[i].onkeyup = x[i].onchange = checkMaxLength;
				x[i].onkeyup();
				}
			}
		}
	}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var warningLength = maxLength-5;
	var currentLength = this.value.length;
	if (currentLength > warningLength) {
		this.relatedElement.className = 'almost-too-long';
		} else {
		this.relatedElement.className = '';
		}
	if (currentLength == maxLength) {
		this.relatedElement.className = 'too-long';
		}
	this.relatedElement.firstChild.nodeValue = currentLength;
	}