function doBlink() {
	var blink = document.all.tags("BLINK")
	for (var i=0; i<blink.length; i++)
		blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

function getExpirationDate(nbDays){
	var r = null;
	var today 			= new Date();
	today.setTime(today.getTime());
	var expires 		= nbDays * 1000 * 60 * 60 * 24;
	var r 	= new Date( today.getTime() + (expires) );
	return r;
}

function startBlink() {
	if (document.all) setInterval("doBlink()",500)
}
window.onload = startBlink;
/*
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, days, path, domain, secure) {
	var expires = "";
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires=" + date.toGMTString();
	}
	document.cookie= name + "=" + escape(value) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) {
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function isEmailValid(email)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	//var filter  = /\b[A-Z0-9._%-]+@[A-Z0-9-]+\.[A-Z]{2,4}\b/i;
	return filter.test(email);
}

function verifyEmail(control, mandatory){
	var email = control.value;
	if (mandatory==true && !isEmailValid(email)){
		alert("Please, enter a valid email address!")
		control.focus();
		control.select();
		return false;
	}
	return true;
}

function verifyMandatoryControl(control, name){
	var value = control.value;
	if (value==null || value==""){
		alert("Please, enter "+name+"!")
		control.focus();
		control.select();
		return false;
	}
	return true;
}

var attTo = new Array();

function addTimeOut(inStrName, inStrFunc, inTime){
	var i = searchTimeOut(inStrName);
	//alert('addTimeOut:'+inStrName+" in array "+attTo.length);
	if (i>=0 && attTo.length){
		attTo[i][0] = inStrName;
		attTo[i][1] = window.setTimeout(inStrFunc,inTime);			
	}else{
		i = attTo.length;
		attTo[i] = new Array(2);
		attTo[i][0] = inStrName;
		attTo[i][1] = window.setTimeout(inStrFunc,inTime);
	}
}

function searchTimeOut(inStrName){
	var i = 0;
	var found = false;
	while (!found && i<attTo.length){
		var name 	= attTo[i][0];
		var to 		= attTo[i][1];
		
		if (inStrName == name){
			found = true;
			window.clearTimeout(to);
			to = null;
		}else{
			i++;
		}
	}
	if (found) return i;
	else return -1;
}

function clearTimeOut(inStrName){
	var i = 0;
	
	i = searchTimeOut(inStrName);
	if (i>=0){
		var name 	= attTo[i][0];
		var to 		= attTo[i][1];
		window.clearTimeout(to);
	}
}

function displayMenu(inStrName){
	var name='Menu'+inStrName;
	//alert('displayMenu '+name);
	showHide(name,true);
	clearTimeOut(name);	
}

function hideMenu(inStrName){
	var name='Menu'+inStrName;
	//alert('hideMenu '+name);
	addTimeOut(name,'showHide(\"'+name+'\",false)',300);
}

/* ==============================================================================
	fnShowDiv / fnHideDiv
============================================================================== */
function fnShowDiv(inName){document.all[inName].style.display="";}
function fnHideDiv(inName){document.all[inName].style.display="none";}
function showHide(inStrV,b){
	if (document.all[inStrV]){
		o = document.all[inStrV];
		if (!b) {
			if (o.style.visibility=='') o.style.visibility='hidden';
		}else{
			if (o.style.visibility=='hidden') o.style.visibility='';
		}
	}else{
		alert("showHide ["+inStrV+"] does not exist.");
	}
}

function getControl(name){
	control = null;
	var type = 0;
	if (document.getElementById){
		type = 1;
		control = document.getElementById(name);
	}else if (document.layers){
		type = 2;
		control = document.layers[name];
	}else if (document.all){
		type = 3;
		control = document.all[name];
	}
	//alert(name + "/" + type + "/" + control);
	return control;	
}

function hideControl(control)
{
	if (document.layers)					control.visibility		 = 'hide';
	else if (document.all)					control.style.visibility = 'hidden';
	else if (document.getElementById)		control.style.visibility = 'hidden';
}

function showControl(control)
{
	if (document.layers)					control.visibility		 = 'show';
	else if (document.all)					control.style.visibility = 'visible';
	else if (document.getElementById)		control.style.visibility = 'visible';
}

function showHideControl(control)
{
	if (document.layers)					control.visibility		 = ((control.visibility == 'hide') ? 'show' : 'hide');
	else if (document.all)					control.style.visibility = ((control.style.visibility == 'hidden') ? 'visible'	: 'hidden');
	else if (document.getElementById)		control.style.visibility = ((control.style.visibility == 'hidden') ? 'visible' : 'hidden');
}

function showBlockControl(control)
{
	if (document.layers)					control.display			= 'block';
	else if (document.all)					control.style.display	= 'block';
	else if (document.getElementById)		control.style.display	= 'block';
}
function hideBlockControl(control)
{
	if (document.layers)					control.display			= 'none';
	else if (document.all)					control.style.display	= 'none';
	else if (document.getElementById)		control.style.display	= 'none';
}
function showHideBlockControl(control)
{
	if (document.layers)					control.display			= ((control.display == 'none') ? 'block' : 'none');
	else if (document.all)					control.style.display	= ((control.style.display == 'none') ? 'block' : 'none');
	else if (document.getElementById)		control.style.display	= ((control.style.display == 'none') ? 'block' : 'none');
}
