function doAction(f, a) {
	theForm = eval("document." + f);
	theForm.actionName.value = a;
	theForm.submit();
}

function wo(url,nome,w,h,s){	
	s = typeof(s)=="undefined"?"0":"1";
	return(window.open(url,nome,
					"top=" + (screen.height - h)/2 + 
					",left=" + (screen.width - w)/2 + 
					"fullscreen=1," +
					",height=" + h + 
					",width=" + w + 
					", status=0, " +
					"toolbar=no," +
					"menubar=no," +
					"location=0," +
					"statusbar=0," +
					"scrollbars=" + s).focus()
			)
}

function checkNumber(objValue) {
    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " ,+-0123456789";
	var number_format = " ,0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be + - ,  blank or a digit.
	check_char = start_format.indexOf(objValue.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
	//Remaining characters can be only , or a digit, but only one decimal.
	objValue = objValue.replace(".", ",");
	for (var i = 1; i < objValue.length; i++)
	{
		check_char = number_format.indexOf(objValue.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks
		}
	    else if (trailing_blank)
		    return false;
		else
			digits = true;
	}	

    //All tests passed, so...
    return true
}

function delay (gap) { /* gap is in millisecs */
	var then,now;
	then = new Date().getTime();
	now = then;
	while ((now-then)<gap)
		now=new Date().getTime();
}


function isInPeriod(dateFrom, dateTo) {
    var now = new Date();
    var today =  now.getYear().toString() + ((now.getMonth()+1).toString().length==1?"0":"") + (now.getMonth()+1).toString() + (now.getDate().toString().length==1?"0":"") + now.getDate().toString();
	dateFrom = dateFrom.replace("/", "").replace("/", "");
	dateTo = dateTo.replace("/", "").replace("/", "");
//alert(dateFrom + "-" + today + "-" + dateTo);
//alert(today <= dateTo);

	if (dateFrom=="" && dateTo=="") return true;
	if (dateFrom!="" && dateTo!="") {
		if (dateFrom <= today && today <= dateTo)
			return true;
		else
			return false;
	}
	if (dateFrom!="" && dateTo=="") {
		if (dateFrom.toString() <= today.toString())
			return true;
		else
			return false;	
	}
	if (dateFrom=="" && dateTo!="") {
		if (today.toString() <= dateTo.toString())
			return true;
		else
			return false;
	}
}

function ControllaCF(cf)
{
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return false;
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return false;
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return false;
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		return false;
	return true;
}


var current;
function mark(item){
	if (current) current.className = "list_off";
	if (current == item) {
		item.className = "list_off";
		current = "";
	} else {
		current = item;
		item.className = "list_on";
	}
}

function copyToList(from,to) {
	fromList = eval('document.forms[1].' + from);
	toList = eval('document.forms[1].' + to);
	if (toList.options.length > 0 && toList.options[0].value == 'temp') {
 		toList.options.length = 0;
	}
	var sel = false;
	for (i=0;i<fromList.options.length;i++) {
		var current = fromList.options[i];
		if (current.selected) {
 			sel = true;
 			if (current.value == 'temp') {
				alert ('You cannot move this text!');
 				return;
			}
			txt = current.text;
			val = current.value;
			toList.options[toList.length] = new Option(txt,val);
			fromList.options[i] = null;
			i--;
		}
	}
	if (!sel)
		alert ('You haven\'t selected any options!');
}
/*
function rolloverPrimaryLinks(item, menu) {
	if (item.className == 'primaryLinksStateOFF') {
		item.className = 'primaryLinksStateON';
		//mopen(menu);
	} else {
		item.className = 'primaryLinksStateOFF';
		//mclosetime();
	}
}


var timeout	= 200;
var closetimer	= 0;
var ddmenuitem	= 0;

// open hidden layer
function mopen(id)
{	
	// cancel close timer
	mcancelclosetime();

	// close old layer
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

	// get new layer and show it
	ddmenuitem = document.getElementById(id);
	ddmenuitem.style.visibility = 'visible';

}
// close showed layer
function mclose()
{
	if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
}

// go close timer
function mclosetime()
{
	closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime()
{
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

// close layer when click-out
document.onclick = mclose;*/

function showExplanation(e, targetDiv) {
	if(!e) e = window.event;
	if (document.getElementById) {
		el = document.getElementById(targetDiv);
		el.style.visibility = 'visible';
		el.style.top = e.clientY-60 + "px";
		el.style.left = e.clientX + "px";
	} else if (document.layers) {
		document.targetDiv.visibility = 'visible';
		el.style.top = 300;
		el.style.left = e.layerX+15;
	}	
}

function hideExplanation(targetDiv) {
	if (document.getElementById)
		document.getElementById(targetDiv).style.visibility = 'hidden';
	else if (document.layers) {
		document.targetDiv.visibility = 'hidden';
	}		
}

function echeck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var bool = true;
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID");
		   bool = false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID");
		   bool = false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		   //alert("Invalid E-mail ID");
		   bool = false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		   //alert("Invalid E-mail ID")
		   bool = false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   //alert("Invalid E-mail ID")
		   bool = false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		   //alert("Invalid E-mail ID")
		   bool = false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		   //alert("Invalid E-mail ID")
		   bool = false;
		 }

 		 return bool;					
	}
