// Hack to add startsWith to a string
String.prototype.startsWith = function(sStart)
{
    return (this.substr(0,sStart.length)==sStart);
}

// Hack to add endsWith to a string
String.prototype.endsWith = function(sStart)
{
    return (this.substr(this.length-sStart.length,this.length)==sStart);
}

/**
Verifiy an email
@param email The E-Mail to verify
*/
function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email))
		return true;
	// alert("O E-Mail introduzido não é válido!")
	return false;
}

/**
Alternate between 2 different images
@param imgId The id of the <img>
@param img1 One Image
@param img2 Another Image
*/
function switchImage( imgId, img1, img2 ) {
	var img = document.getElementById( imgId );
// 	alert(img.src);
	if( img ) {
		if( img.src.endsWith(img2) ) {
			img.src = img1;
		} else {
			img.src = img2;
		}
	}
}

// Dumb function
function foo() {}
/**
 Hide/Show the layer specified in ID
 @param id The layer ID
*/
function toggle( id ) {

	var div = document.getElementById( id );

	if( !div ) return;
	
// 	alert( div.style.visibility );
		
	if( div.style.visibility == 'hidden' /* || div.style.visibility == '' */ ) {
		div.style.visibility = 'visible';
		div.style.display = 'block';
	} else {
		div.style.visibility = 'hidden';
		div.style.display = 'none';
	}
	
}

/**
Close a layer
*/
function closeDiv( id ) {
	var div = document.getElementById( id );
	div.style.visibility = 'hidden';
	div.style.display = 'none';
}

/**
Show a layer
*/
function openDiv( id ) {
	var div = document.getElementById( id );
	div.style.visibility = 'visible';
	div.style.display = 'block';
}

/**
Open a Window for printing
*/
function printWindow( href ) {
	var opener = document;
	/*
	Features:
	status  	The status bar at the bottom of the window.
	toolbar 	The standard browser toolbar, with buttons such as Back and Forward.
	location 	The Location entry field where you enter the URL.
	menubar 	The menu bar of the window
	directories 	The standard browser directory buttons, such as What's New and What's Cool
	resizable 	Allow/Disallow the user to resize the window.
	scrollbars 	Enable the scrollbars if the document is bigger than the window
	height 	Specifies the height of the window in pixels. (example: height='350')
	width 	Specifies the width of the window in pixels.
	*/
	var title = 'print';
	var features = 'scrollbars=1, toolbar=false, menubar=false, status=false, width=800, height=600';
	var w = window.open( href, title, features );
	w.focus();
	if( w.confirm( 'Do you wish to print this document?' ) ) {
		w.print();
	}
}

/**
Open a Window
*/
function newWindow( url, width, height ) {
	var opener = document;
	/*
	Features:
	status  	The status bar at the bottom of the window.
	toolbar 	The standard browser toolbar, with buttons such as Back and Forward.
	location 	The Location entry field where you enter the URL.
	menubar 	The menu bar of the window
	directories 	The standard browser directory buttons, such as What's New and What's Cool
	resizable 	Allow/Disallow the user to resize the window.
	scrollbars 	Enable the scrollbars if the document is bigger than the window
	height 	Specifies the height of the window in pixels. (example: height='350')
	width 	Specifies the width of the window in pixels.
	*/
	var title = 'newWindow';
	var features = 'scrollbars=1, toolbar=false, menubar=false, status=false, width='+width+', height='+height;
	var w = window.open( url, title, features );
	w.focus();
}
