function subscribe() {
	var f = document.forms[0];
	if(f.txtEmail.value.length==0)
		alert("Enter an email first");
	else if(!isEmail(f.txtEmail.value))
		alert("The email entered is invalid");
    else
    	f.submit();
}

function isEmail(email) { 
	var regex = /^[a-z0-9][-._a-z0-9]*@[a-z0-9]+([-.][a-z0-9]+)*[.][a-z]{2,7}$/i;
	return regex.test(email);
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

var preloadFlag = false;
function preloadImages() {
	if (document.images) {
	    logo1 = newImage("ui/background.jpg");
		logo1 = newImage("ui/logo.jpg");
		logo2 = newImage("ui/logo-over.jpg");
		preloadFlag = true;
	}
}

function addToLightbox(workId) {
    var f = document.forms[0];
    f.hidWorkId.value = workId;
    f.submit();
}

function removeFromLightbox(workId) {
    var f = document.forms[0];
    f.hidWorkId.value = workId;
    f.submit();
}

// ------------------------- STRINGS ------------------------- //

function isEmpty(str) {
  return str.trim().length == 0;
}

function strltrim() {
	return this.replace(/^\s+/,'');
}
function strrtrim() {
	return this.replace(/\s+$/,'');
}
function strtrim() {
	return this.replace(/^\s+/,'').replace(/\s+$/,'');
}
function endsWith(str) {
    str = str.replace("\\", "\\\\");
    return this.match("^.+" + str + "$")
}

function startsWith(str) {
    str = str.replace("\\", "\\\\");
    return this.match("^" + str + ".+$")
}

String.prototype.startsWith = startsWith;
String.prototype.endsWith = endsWith;
String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim = strtrim;

// -------------------------------------------------- //
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
var tip = null;

function getMouseXY(e) {
    if (IE) { // grab the x-y pos.s if browser is IE
        tempX = event.clientX;
        if(document.body != null) tempX = tempX + document.body.scrollLeft;
        tempY = event.clientY;
        if(document.body != null) tempY = tempY + document.body.scrollTop;
    } else {  // grab the x-y pos.s if browser is NS
        tempX = e.pageX;
        tempY = e.pageY;
    }  
    if (tempX < 0){tempX = 0;}
    if (tempY < 0){tempY = 0;}  
    return true;
}

function displayTip() {
    if(tip == null) return;
    tip.style.display = "block";
    tip.style.left = (tempX+25) + "px";;
    tip.style.top = tempY + "px";;
}

function hideTip() {
    if(tip == null) return;
    tip.style.display = "none";        
}

function loadTip() {
    tip = document.getElementById("tip");
}

window.onload = function init() {
    loadTip();
    preloadImages();
}