
// ---------------------------------------------------------
// Fancybox

$(document).ready(function() {
	$("a#fancybox").fancybox({
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic'
	});
});


// ---------------------------------------------------------
// Enable a table row to change color and work as a link
//
//function ChangeColor(tableRow, highlight) {
//    if (highlight)	{ tableRow.style.backgroundColor = '#ddddff'; }
//	else			{ tableRow.style.backgroundColor = 'white'; }
//}
//function DoNav(url) { document.location.href = url; }
//
//Usage: Inside a <table>
//	<tr valign='top'	onmouseover="ChangeColor(this, true);" 
//						onmouseout="ChangeColor(this, false);" 
//						onclick="DoNav('/{{ s.class_name }}/{{ s.key }}');">


// ---------------------------------------------------------
// AJAX functions

function downloadUrl(url, type, data, callback) {
	var status = -1;
	var request = createXmlHttpRequest();
	if (!request) { return false; }
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
			try { status = request.status; } 
			catch (e) {}
			if (status == 200) {
				callback(request.responseText);
				request.onreadystatechange = function() {};
			}
		}
	}
	request.open(type, url, true);
	if (type == "POST") {
		request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		request.setRequestHeader("Content-length", data.length);
		request.setRequestHeader("Connection", "close"); 
	}
	try { request.send(data); } 
	catch (e) { changeStatus(e); }
}


function downloadScript(url) {
	var script = document.createElement('script');
	script.src = url;
	document.body.appendChild(script);
}


function createXmlHttpRequest() {
	try {
		if (typeof ActiveXObject != 'undefined') {
			return new ActiveXObject('Microsoft.XMLHTTP');
		} else if (window["XMLHttpRequest"]) {
			return new XMLHttpRequest();
		}
	} catch (e) {
		changeStatus(e);
	}
	return null;
}


// ---------------------------------------------------------
// Runs a javascript function when the user presses enter on the input field

function checkEnter(e, func){ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable
	if(e && e.which) { //if which property of event object is supported (NN4)
		e = e
		characterCode = e.which //character code is contained in NN4's which property
	} else {
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	if(characterCode == 13) { //if generated character code is equal to ascii 13 (if enter key)
		func() //submit the form
		return
	} else {
		return
	}
}

