//'@Project: WebSite	@Type: Libreria
//'Tab - © 2005 - 2009 KinderSoft
//'v.1.4.r.29.03.03

function trim(s){
	while (s.substring(0,1) == ' ')
		s = s.substring(1, s.length);
	while (s.substring(s.length-1,s.length) == ' ')
		s = s.substring(0, s.length-1);
	return s;
}

function fsubmitSearch(){document.forms[0].p.value = ''; document.forms[0].submit();}

function restartPage(){if (event.keyCode==13) document.forms[0].p.value = '';}

function changePage(){document.forms[0].p.value = '';}

function azzera()
	{document.forms[0].f.value = '';document.forms[0].f.focus();}

function reload() 
	{document.forms[0].p.value=1;document.forms[0].submit();}

function resort(v) 
	{document.forms[0].p.value=1;document.forms[0].d.value=v;document.forms[0].submit();}

function move(n) {
		if (document.forms[0].p.value=='') document.forms[0].p.value=1;	else document.forms[0].p.value=n;
		document.forms[0].submit();
}

function doaction(n,f,a) {	
	document.forms[0].nrec.value=n;
	document.forms[0].action=f;
	document.forms[0].azione.value=a;
	document.forms[0].submit();
}

function rdelete() {	
	if (confirm("Eliminare questo record?")) {
		if (confirm("Conferma eliminazione definitiva?")) {
			document.forms[0].azione.value="delete";
			document.forms[0].submit();
		}
	}
}

function emailsend(m) {	
	var e = trim(document.forms[0].Email.value)
	if (e=='') {
		alert("L'indirizzo email è vuoto")
	}
	else {
		if (KSemailAlert(e,"L'indirizzo e-mail inserito non è corretto"))	{
			if (confirm(m)) {
				document.forms[0].azione.value="email";
				document.forms[0].submit();
			}
		}
	}
}

function thisemailsend(m) {	
	var ok = -1;

	var e = trim(document.forms[0].sFrom.value);

	if (e=='') { alert("Indicare l'indirizzo del mittente") }
	else { if (KSemailAlert(e,"L'indirizzo del mittente non è corretto")) { ok = 1 } }

	if (ok == 1)
	{
	ok = 0
	e = trim(document.forms[0].sTo.value);
	if (e=='') { alert("Indicare l'indirizzo del destinatario") }
	else { if (CheckMulti(e,"L'indirizzo del destinatario non è corretto")) { ok = 1} } 
	}
	
	if (ok == 1)
	{
	ok = 0
	e = trim(document.forms[0].sCc.value);
	if (e=='') { ok = 1 }
	else { if (CheckMulti(e,"L'indirizzo del secondo destinatario non è corretto")) { ok = 1 } }
	}

	if (ok == 1)
	{
	ok = 0
	e = trim(document.forms[0].sSubject.value);
	if (e=='') { alert("Indicare l'oggetto del messaggio") }
	else { ok = 1 }
	}

	if (ok == 1)
	{
		if (confirm(m)) { document.forms[0].submit() }
	}
}

function CheckMulti(e,m)
{
	var s = e.split(",");
	var n = s.length;
	var ok = 1;
		for (i = 0; ((i < n) && (ok == 1)); i++ )
		{
			if (!KSemailAlert(s[i],m)) { ok = 0 }
		}
	return ok;
}

function SelectWind(u,v)
{
	u = u + "&IDsel=" + v
	sw = window.open(u,'wsel','location=0,border=0,resizable=yes,status=0,scrollbars=yes,toolbar=0,menubar=0,width=500,height=350,left=10,top=50;');
	sw.focus();
}

function IncM(f)
{
	var fId = document.getElementsByName(f)[0];
	var x = fId.value;
	x = Math.abs(x);
	if (x > 0) { fId.value = String(x - 1) }
	else { fId.value = String(0) }
}

function IncP(f)
{
	var fId = document.getElementsByName(f)[0];
	var x = fId.value;
	x = Math.abs(x);
	if (x >= 0) { fId.value = String(x + 1) }
	else { fId.value = String(0) }
}

function Dettaglio(m,f)
{
	var fId = document.getElementById(f);
	var x = fId.value;
	if (x.length==0 ||  x=='0') return;
	PopUpXCenterBar(m+'?id='+x,640,480);
}

function kMultiCheck(f) {
	var p1 = document.getElementById(f);
	var p2 = document.getElementById(f+'Img');
	var p3 = document.getElementById(f+'Status');
	var Status = p1.style.display;
	if (Status == "none") {
		p1.style.display = "block";
		p2.src = "../img/Minus.gif";
		p3.value = "block";
	}
	else {
		p1.style.display = "none";
		p2.src = "../img/Plus.gif";
		p3.value = "none";
	}
}

function kMultiCheckOnOff(f,k,v) {
	var p;
	for (var i=0;i<=k;i++)
	{	p = document.getElementById(f+i);
		p.checked = (v==1);
	}	
}

function Advanced(s) {
	var p1 = document.getElementById(s + 'DivPlus');
	var p2 = document.getElementById(s + 'DivMinus');
	var p3 = document.getElementById(s + 'Param');
	var Stato = p1.style.display;
	if (Stato == "none") {
		p1.style.display = "block";
		p2.style.display = "none";
	}
	else {
		p1.style.display = "none";
		p2.style.display = "block";
	}
	p3.value = Stato;
}
