//////////////////////////////////////////////////////////////
//    
// Miscellaneous JavaScript functions - 2004-05-11
//
//	© Enki Technologies
//	info@enki-tech.com
//
//////////////////////////////////////////////////////////////


/////////////////////
// BrowserCheck
/////////////////////
function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.v = parseInt(navigator.appVersion)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v==5)
	this.ns6 = (this.b=="ns" && this.v==6)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (navigator.userAgent.indexOf('MSIE 4')>0)
	this.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0)
	if (this.ie5) this.v = 5
	this.ie6 = (navigator.userAgent.indexOf('MSIE 6')>0)
	if (this.ie6) this.v = 6
	this.min = (this.ns||this.ie)
	this.mac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
}


/////////////////////
// getObject
/////////////////////
function getObject(objectId) {
	var obj;
	if (document.getElementById) {
		// DOM
		obj = document.getElementById(objectId);
	}
	else if (document.all) {
		// ie4
		obj = eval("document.all." + objectId);
	}
	else {
		// nn4
		obj = getObjectNN4(document,objectId);
	}
	return obj;
}
function getObjectNN4(container,objectId)
{
	var x = container.layers;
	var obj;
	for (var i=0;i<x.length;i++)
	{
		if (x[i].id == objectId) { obj = x[i]; }
		else {
			if (x[i].layers.length) {
				var tmp = getObjectNN4(x[i],objectId);
				if (tmp) { obj = tmp; }
			}
		}
	}
	return obj;
}



/////////////////////
// hideObject
/////////////////////
function hideObject(obj) {
	if (obj) {
		if (document.getElementById) {
			// DOM
			obj.style.visibility="hidden";
			obj.style.display="none";
		}
		else if (document.all) {
			// ie4
			obj.style.visibility="hidden";
			obj.style.display="none";
		}
		else {
			// nn4
			obj.visibility="hide";
		}
	}
}


/////////////////////
// showObject
/////////////////////
function showObject(obj) {
	if (obj) {
		if (document.getElementById) {
			// DOM
			obj.style.visibility="visible";
			obj.style.display="block";
		}
		else if (document.all) {
			// ie4
			obj.style.visibility="visible";
			obj.style.display="block";
		}
		else {
			// nn4
			obj.visibility="show";
		}
	}
}


/////////////////////
// getObjectPositionX
/////////////////////
function getObjectPositionX(obj) {
	var is = new BrowserCheck();
	if (is.ns && is.v<5) {
		return obj.x;
	}
	else {
		x = 0;
		if (is.v>=5) {
			while (obj.tagName != 'BODY') {
				x += obj.offsetLeft;
				obj = obj.offsetParent;
			}
		}
		else {
			while (obj.tagName != 'BODY') {
				if (obj.tagName == 'TABLE' || obj.tagName == 'TD') {
					x += obj.offsetLeft;
				}
				obj = obj.parentElement;
			}
		}
		
		return x;
	}
}


/////////////////////
// getObjectPositionY
/////////////////////
function getObjectPositionY(obj) {
	var is = new BrowserCheck();
	if (is.ns && is.v<5) {
		return obj.y;
	}       
	else {
		y = 0;
		if (is.v>=5) {
			while (obj.tagName != 'BODY') {
				y = obj.offsetTop + y;
				obj = obj.offsetParent;
			}
		}
		else {
			while (obj.tagName != 'BODY') {
				if (obj.tagName == 'TABLE' || obj.tagName == 'TD') {
					y += obj.offsetTop;
				}
				obj = obj.parentElement;
			}
		}
		
		//if (is.ns) y -= 14;
		return y;
	}
}


/////////////////////
// setObjectPositionX
/////////////////////
function setObjectPositionX(obj,X) {
	if (document.layers) {
		// nn
		obj.left = X;
	}
	else {
		// ie
		obj.style.left = X;
	}
}

/////////////////////
// setObjectPositionY
/////////////////////
function setObjectPositionY(obj,Y) {
	if (document.layers) {
		// nn
		obj.top = Y;
	}
	else {
		// ie
		obj.style.top = Y;
	}
}

/////////////////////
// FormFunctions
/////////////////////

function isValidEmail(s) {
	if (isEmpty(s)) { return false; }
	//return (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);
	return (s.search(/^[\w-]+(\.[\w-]+)*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1);
}
function isValidDate(s,f) {
	if (isEmpty(s)) { return false; }
	var rExp = /(\d{1,4})-(\d{1,2})-(\d{1,2})/;
	var posYear = 1;
	var posMonth = 2;
	var posDay = 3;
	if (!isEmpty(f)) { 
		if (f == 'dd/mm/yyyy') {
			rExp = /(\d{1,2})\/(\d{1,2})\/(\d{1,4})/;
			posYear = 3;
			posMonth = 2;
			posDay = 1;
		}
	}
	var d = s.match(rExp);
	if (d != null) {
		d[posMonth]--;
		var dd= new Date(d[posYear], d[posMonth], d[posDay]);
		return ( dd.getDate()==d[posDay] && dd.getMonth()==d[posMonth] );
	}
	return false
}
function isEmpty(s) {
	if (s == null || s == "") {
		return true;
	}
	return false;
}
function isInteger(s) {
	i = stringToInteger(s);
	return (i == s);
}
function stringToInteger(s) {
	if (s == null || s == "") { i = 0; }
	else { i = parseInt(s); }
	if (isNaN(i)) { i = 0; }
	return i;
}
function radioIsSelected(r) {
	var radioChoice = false;
	if (r) {
		for (counter = 0; counter < r.length; counter++) {
			if (r[counter].checked) {
				radioChoice = true;
			}
		}
	}
	return radioChoice;
}

/////////////////////
// Preload Images
/////////////////////

var preloadImagesArray = new Array();
function preloadImages() {
	for (var i=0; i <preloadImages.arguments.length;i++){
		var index = preloadImagesArray.length;
		preloadImagesArray[index]=new Image();
		preloadImagesArray[index].src=preloadImages.arguments[i];
	}
}
