function
redirect(url)
	{
	opener.location.href = url;
	opener.location.reload(true);
	} 
function 
checkEmail(this_field) 
	{
	indirizzo = this_field.value;
	if(indirizzo == "")
		return;
	if(window.RegExp) 
		{
		var nonvalido = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var valido = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$";
		var regnv = new RegExp(nonvalido);
		var regv = new RegExp(valido);
		if(!regnv.test(indirizzo) && regv.test(indirizzo))
			return true;
		else
			{
			this_field.focus();
//			alert("Insert a valid email");
			return false;
			}
		}
  else 
		{
		if(indirizzo.indexOf("@") > 0)
			return true;
		else
			{
			this_field.focus();
//			alert("Insert a valid email");
			return false;
			}
  		}
	}
function
confirmSingleDelete(href)
	{
	if(confirm("Are you sure you want to delete the selected record?"))
		location.href = href;
	} // confirmSingleDelete
function 
CheckAll(checkflag) 
	{
	elem = document.getElementsByTagName("input");
	for(var i = 0; i < elem.length; i++) 
		{
	    var e = elem[i];
		if(e.type == 'checkbox' && !e.disabled && e.name == "entries[]") 
			{
			e.checked = checkflag;
			}
		}
	}
function
checkRecord()
	{
	local_checked = false;
	k = 0;
	elem = document.getElementsByTagName("input");
	for(var i = 0; i < elem.length; i++) 
		{
	    var e = elem[i];
		if(e.type=='checkbox' && !e.disabled) 
			{
			if(e.checked)
				{
				local_checked = true;
				k++;
				}
			}
		}
	if(!local_checked)
		alert("No records selected !");
	return local_checked;
	} // checkRecord
function
confirmDelete(msg)
	{
	k = 0;
	elem = document.getElementsByTagName("input");
	for(var i = 0; i < elem.length; i++) 
		{
	    var e = elem[i];
		if(e.type=='checkbox' && !e.disabled) 
			{
			if(e.checked)
				{
				k++;
				}
			}
		}
	if(k == 0)
		alert("No records selected !");
	else
	if(confirm(msg + " Are you sure to delete the " + k + " selected records ?"))
		{
		document.getElementById("hiddens_for_submit").innerHTML = "<input type='hidden' name='action' value='Elimina'>";
		document.manage_rec.submit();
		}
	} // confirmDelete

function
confirmClone()
	{
	k = 0;
	hidden_elements = "";
	elem = document.getElementsByTagName("input");
	for(var i = 0; i < elem.length; i++) 
		{
	    var e = elem[i];
		if(e.type=='checkbox' && !e.disabled && e.name == "entries[]") 
			{
			if(e.checked)
				{
				hidden_elements += "<input type=hidden name='entries[]' value='" + e.value + "'>";
				k++;
				}
			}
		}
	if(k == 0)
		alert("No records selected !");
	else
	if(confirm(" Are you sure to clone the " + k + " selected records ?"))
		{
		// set the lang to clone to
		hidden_elements += "<input type=hidden name='id_lang' value='" + document.getElementById("id_lang_clone").value + "'>";
		document.getElementById("hiddens").innerHTML = hidden_elements;
		document.forms['clone_form'].submit();
		}
	} // confirmClone

function
selezionaTab(selected, total)
	{
	for(i = 0; i < total; i++)
		{
		if(i == selected)
			{
			document.getElementById("the_tab" + i).style.display = 'block';
			}
		else
			{
			document.getElementById("the_tab" + i).style.display = 'none';
			}
		}
	} // selezionaTab
function
setInvisible(total)
	{
	for(i = 0; i < total; i++)
		document.getElementById("the_tab" + i).style.display = 'none';
	} // setInvisible
function 
visualizza(id)
	{
	if(document.getElementById)
		{
		if(document.getElementById(id).style.display == 'none')
			document.getElementById(id).style.display = 'block';
		else
			document.getElementById(id).style.display = 'none';
		}
	} // visualizza
/*--------------------------------------------------------------------*/
/*------------------------ MANAGE THE DIV ----------------------------*/
/*--------------------------------------------------------------------*/
/*-------------------------- center ----------------------------------*/
function 
center(onlyDivName,divWidth, divHeight)
   {
   if(document.getElementById(onlyDivName).style.display != 'none')
      centerTheDiv(onlyDivName, divWidth, divHeight);
   } // center
/*----------------------------- centerTheDiv -------------------------*/
function
centerTheDiv(onlyDivName, divWidth, divHeight)
	{
	divtocenter = onlyDivName + ".style";
	
	// get the size of the browser
	var dim = getSize();

	// get the scroll offsets
	var scr = getScrollXY();

	// set the position
	comando = divtocenter + ".left=" + (((dim[0] / 2) - (parseInt(divWidth) / 2)) + scr[0]) + ";";
   
	//special case for top, if div is greater then browser
	if (divHeight > dim[1])
		comando += divtocenter + ".top= 10" + ";";
	else
		comando += divtocenter + ".top=" + (((dim[1] / 2) - (parseInt(divHeight) / 2)) + scr[1]) + ";";

	// center
	eval(comando);

	// show up the select and applet element of the form
	showElement('SELECT');
	showElement('APPLET');

	// hide the select and applet element under the divtocenter
	hideElement('SELECT', document.getElementById(onlyDivName));
	hideElement('APPLET', document.getElementById(onlyDivName));			
	} // centerTheDiv
/*------------------------------ closeDiv ----------------------------*/
function 
closeDiv(onlyDivName)
   {
   // put back the elements
   showElement('SELECT');
   showElement('APPLET');

	// hide the div
   document.getElementById(onlyDivName).style.display='none';
   } // closeDiv
/*------------------------------ getSize -----------------------------*/
function 
getSize()
   {
   var myWidth = 0, myHeight = 0;
   if(typeof(window.innerWidth) == 'number')
      {
      // Non-IE
      myWidth = window.innerWidth;
      myHeight = window.innerHeight;
      } 
   else 
      {
      if(document.documentElement && (document.documentElement.
	   clientWidth || document.documentElement.clientHeight)) 
	      {
         // IE 6+ in 'standards compliant mode'
         myWidth = document.documentElement.clientWidth;
         myHeight = document.documentElement.clientHeight;
         } 
      else 
         {
         if(document.body && (document.body.clientWidth || document.
			body.clientHeight)) 
	         {
            // IE 4 compatible
            myWidth = document.body.clientWidth;
            myHeight = document.body.clientHeight;
            }
         }
      }
   return [myWidth, myHeight];
   } // getSize
/*------------------------------ getScrollXY -------------------------*/
function 
getScrollXY()
   {
   var scrOfX = 0, scrOfY = 0;
   if(typeof(window.pageYOffset) == 'number') 
      {
      // Netscape compliant
      scrOfY = window.pageYOffset;
      scrOfX = window.pageXOffset;
      } 
   else 
      {
      if(document.body && (document.body.scrollLeft || document.body.
	   scrollTop)) 
         {
         // DOM compliant
         scrOfY = document.body.scrollTop;
         scrOfX = document.body.scrollLeft;
         } 
	  else 
	      {
         if(document.documentElement && (document.documentElement.
		   scrollLeft || document.documentElement.scrollTop)) 
		      {
            // IE6 standards compliant mode
            scrOfY = document.documentElement.scrollTop;
            scrOfX = document.documentElement.scrollLeft;
            }
         }
      }
   return [scrOfX, scrOfY];
   } // getScrollXY
/*------------------------------ hideElement -------------------------*/
function 
hideElement(elmID, overDiv)
   {
	// if ie
	if(document.all)
	   {
		for(i = 0; i < document.all.tags(elmID).length; i++)
         {
			obj = document.all.tags(elmID)[i];
			if(!obj || !obj.offsetParent)
				continue;

			objLeft = obj.offsetLeft;
			objTop = obj.offsetTop;
			objParent = obj.offsetParent;

			// if is not the body
			while(objParent.tagName.toUpperCase() != "BODY")
			   {
				objLeft += objParent.offsetLeft;
				objTop += objParent.offsetTop;
				objParent = objParent.offsetParent;
			   }

         objHeight = obj.offsetHeight;
			objWidth = obj.offsetWidth;

         // hide if is the case
/*			if((overDiv.offsetLeft + overDiv.offsetWidth) <= objLeft)
            ;
			else 
			if((overDiv.offsetTop + overDiv.offsetHeight) <= objTop)
			   ;
			else 
			if(overDiv.offsetTop >= (objTop + objHeight))
			   ;
			else
			if(overDiv.offsetLeft >= (objLeft + objWidth))
			   ;
			else
*/				obj.style.visibility = "hidden";
         }
	   }
   } // hideElement
/*------------------------ showElement -------------------------------*/
function 
showElement(elmID)
   {
	// if ie
	if(document.all)
		{
      for(i = 0; i < document.all.tags(elmID).length; i++)
		   {
			obj = document.all.tags(elmID)[i];
			if(!obj || !obj.offsetParent)
				continue;
			obj.style.visibility = "";
			}
		}
	} // showElement
/*--------------------------------------------------------------------*/
/*----------------------------- AJAX ---------------------------------*/
/*--------------------------------------------------------------------*/
var myRequest = null;
var myDiv = null;
var myElement = null;

function 
CreateXmlHttpReq2(handler) 
	{
	var xmlhttp = null;
	try 
		{
		xmlhttp = new XMLHttpRequest();
		} 
	catch(e) 
		{
		try 
			{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
			} 
		catch(e) 
			{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}
		}
	xmlhttp.onreadystatechange = handler;
	return xmlhttp;
	} // CreateXmlHttpReq2
function 
myHandler2(the_div) 
	{
    if(myRequest.readyState == 4 && myRequest.status == 200) 
		{
        e = document.getElementById(myDiv);
//alert(myRequest.responseText);
        e.innerHTML = myRequest.responseText;
		//alert(myReload);
		if (myReload)
			{
				document.location.reload(true);	
			}
		}
	}
function 
myHandler1() 
	{
    if(myRequest.readyState == 4 && myRequest.status == 200) 
		{
        e = document.getElementById(myElement);
        e.value = myRequest.responseText;
		}
	}
function 
get_cont(url, the_div, doLocationReload) 
	{
//alert(url);
	myDiv = the_div;
	myReload = doLocationReload;
	myRequest = CreateXmlHttpReq2(myHandler2);
	myRequest.open("GET", url);
	myRequest.send(null);
	}
function 
get_value(url, the_element) 
	{
	myElement = the_element;
	myRequest = CreateXmlHttpReq2(myHandler1);
//alert(url);
	myRequest.open("GET", url);
	myRequest.send(null);
	}
/*--------------------------------------------------------------------*/
/*------------------------- COOKIE -----------------------------------*/
/*--------------------------------------------------------------------*/
function 
setCookie(name, value, expires, path, domain, secure) 
	{
    var curCookie = name + "=" + escape(value) + 
	(expires ? "; expires=" + expires : "") +
	(path ? "; path=" + path : "") + 
	(domain ? "; domain=" + domain : "") + 
	(secure ? "secure" : "");
    document.cookie = curCookie;
	}

function 
getCookie(name) 
	{
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;

    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
    return unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
	}
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 
fixDate(date) 
	{
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
	}
function 
rememberMe(f) 
	{
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
    now = now.toGMTString();
    if (f.username != undefined)
       setCookie('username', f.username.value, now, '/', '', '');
    if (f.password != undefined)
       setCookie('password', f.password.value, now, '/', '', '');
	}
function 
forgetMe(f) 
	{
    deleteCookie('username', '/', '');
    deleteCookie('password', '/', '');
	}


// Ottieni la base url
//url = document.location.href;
//xend = url.lastIndexOf("/") + 1;
//var base_url = url.substring(0, xend);

function setNew(url) 
{
		urlF = document.location.href;
		xend = urlF.lastIndexOf("/") + 1;
		var base_url = urlF.substring(0, xend);
        //Inizia l'url con http?
        if (url.substring(0, 4) != 'http') {
                url = base_url + url;
        }

        // Crea un nuovo elemento JS
        var jsel = document.createElement('SCRIPT');
        jsel.type = 'text/javascript';
        jsel.src = url;

        //Appende l'elemento JS e quindi esegue la 'chiamata AJAX')
        document.body.appendChild (jsel);
}

// --------------------------- contatti
function
confirmEventoAssocia()
	{
	k = 0;
	elem = document.getElementsByTagName("input");
	for(var i = 0; i < elem.length; i++) 
		{
	    var e = elem[i];
		if(e.type=='checkbox' && !e.disabled) 
			{
			if(e.checked)
				{
				k++;
				}
			}
		}
	if(k == 0)
		alert("None selected!");
	else
	if(confirm("Are you sure to link " + k + " selected records to the event/attribute ?"))
		{
		document.getElementById("hiddens_for_submit").innerHTML = "<input type='hidden' name='action' value='Associa'>";
		document.manage_rec.submit();
		}
	} // confirmEventoAssocia

function
confirmEventoTogli()
	{
	k = 0;
	elem = document.getElementsByTagName("input");
	for(var i = 0; i < elem.length; i++) 
		{
	    var e = elem[i];
		if(e.type=='checkbox' && !e.disabled) 
			{
			if(e.checked)
				{
				k++;
				}
			}
		}
	if(k == 0)
		alert("None selected!");
	else
	if(confirm("Are you sure to unlink from the event " + k + " selected records ?"))
		{
		document.getElementById("hiddens_for_submit").innerHTML = "<input type='hidden' name='action' value='Togli'>";
		document.manage_rec.submit();
		}
	} // confirmEventoTogli

function
confirmAttributoAssocia()
	{
	k = 0;
	elem = document.getElementsByTagName("input");
	for(var i = 0; i < elem.length; i++) 
		{
	    var e = elem[i];
		if(e.type=='checkbox' && !e.disabled) 
			{
			if(e.checked)
				{
				k++;
				}
			}
		}
	if(k == 0)
		alert("None selected!");
	else
	if(confirm("Are you sure to link " + k + " selected contacts to the attribute ?"))
		{
		document.getElementById("hiddens_for_submit").innerHTML = "<input type='hidden' name='action' value='AssociaAttributo'>";
		document.manage_rec.submit();
		}
	} // confirmAttributoAssocia

function
confirmAttributoTogli()
	{
	k = 0;
	elem = document.getElementsByTagName("input");
	for(var i = 0; i < elem.length; i++) 
		{
	    var e = elem[i];
		if(e.type=='checkbox' && !e.disabled) 
			{
			if(e.checked)
				{
				k++;
				}
			}
		}
	if(k == 0)
		alert("None selected!");
	else
	if(confirm("Are you sure to unlink " + k + " selected records from the attribute ?"))
		{
		document.getElementById("hiddens_for_submit").innerHTML = "<input type='hidden' name='action' value='TogliAttributo'>";
		document.manage_rec.submit();
		}
	} // confirmAttributoTogli

function
confirmAttributoChange(from, to)
	{
	if(from == to)
		{
		alert("The internal status to be change in, is the same selected!");
		return;
		}
	k = 0;
	elem = document.getElementsByTagName("input");
	for(var i = 0; i < elem.length; i++) 
		{
	    var e = elem[i];
		if(e.type=='checkbox' && !e.disabled) 
			{
			if(e.checked)
				{
				k++;
				}
			}
		}
	if(k == 0)
		alert("None selected!");
	else
	if(confirm("Are you sure to change " + k + " selected contacts to the field attribute ?"))
		{
		document.getElementById("hiddens_for_submit").innerHTML = 
		"<input type='hidden' name='action' value='ChangeAttributo'>" + 
		"<input type='hidden' name='from' value='" + from + "'>" + 
		"<input type='hidden' name='to' value='" + to + "'>";
		document.manage_rec.submit();
		}
	} // confirmAttributoChange

var arSelected = new Array();
function getMultiple(ob)
	{
    while (ob.selectedIndex != -1)
		{
        if (ob.selectedIndex != 0) arSelected.push(ob.options[ob.selectedIndex].value);
        ob.options[ob.selectedIndex].selected = false;
		//alert(arSelected);
	    }
    // You can use the arSelected array for further processing.
	}

function 
set_content_attribute_fields_internal_status(id, div_name, div_name_1, from)
	{
	content = "";
	content_1 = 
	'<img src="../includes/images/page_down.png" alt="Link" align="top"/>' + 
	'<input type="button" name="action" value="Link" onclick="return confirmAttributoAssocia();" />' + 
	'<img src="../includes/images/page_up.png" alt="Unlink" align="top"/>' + 
	'<input type="button" name="action" value="Unlink" onclick="return confirmAttributoTogli();" />';
	if(id == 61)
		{
		content = 
		"<select name='internal_status' id='internal_status'>" +
		"<option value=1>Request inserted</option>" +
		"<option value=4>Substitution in progress</option>" +
		"<option value=2>Substitution done</option>" +
		"<option value=3>Substitution refused</option>" +
		"</select>";

		content_1 =
		'<img src="../includes/images/page_down.png" alt="Change" align="top"/>' + 
		'<input type="button" name="action" value="Change" onclick="return confirmAttributoChange(\'' + from + '\', document.forms[\'manage_rec\'].internal_status.value);" />';
		}

	document.getElementById(div_name).innerHTML = content;
	document.getElementById(div_name_1).innerHTML = content_1;
	} // set_content_attribute_fields

