function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function getElementLeft(Elem) {
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	xPos = elem.offsetLeft;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		xPos += tempEl.offsetLeft;
		tempEl = tempEl.offsetParent;
	}
	return xPos;
}

function getElementTop(Elem) {
	if(document.getElementById) {	
		var elem = document.getElementById(Elem);
	} else if (document.all) {
		var elem = document.all[Elem];
	}
	yPos = elem.offsetTop;
	tempEl = elem.offsetParent;
	while (tempEl != null) {
		yPos += tempEl.offsetTop;
		tempEl = tempEl.offsetParent;
	}
	return yPos;
}

function SetCookie(cookieName, cookieValue, nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString();
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) { 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}
function checkKeyword( field, lang, defValue )
{
	if ( field.value == "" || field.value == defValue )
	{
		if( lang == 'en' )
			alert( 'Insert your search keywords' );
		else
			alert( 'Inserisci il termine di ricerca' );

		field.focus();
		return false;
	}
	else if( field.value.length < 4 )
	{
		if( lang == 'en' )
			alert( 'The keywords lenght must be min 4 chars' );
		else
			alert( 'Il termine di ricercaLa deve essere di almeno 4 caratteri!' );

		field.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function rolloverCat(obj)
{
	obj.style.backgroundColor = '#EEEEEE';
}

function rolloutCat(obj)
{
	obj.style.backgroundColor = '';
}

function printObj( obj, dbPrefix, docRoot, siteName )
{
	var currentDate = new Date();
	var header = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><title>'+siteName+'</title><link href="'+docRoot+'styles/template.css" rel="stylesheet" type="text/css"><link href="'+docRoot+'styles/template_print.css" rel="stylesheet" type="text/css" media="screen,print"></head><body><div id="'+obj+'" align="left"><table width="600" border="0" cellpadding="0" cellspacing="0"><tr><td><img src="'+docRoot+'media/layout_images/topbar_print.jpg"></td></tr><tr><td height="20"></td></tr><tr><td>';
	
	if( document.getElementById('footer_print') )
		var footer = '</td></tr></table></div><div id="footer_print">' + document.getElementById('footer_print').innerHTML + '</div></body></html>';
	else
		var footer = '</td></tr></table></div></body></html>';

	var content = document.getElementById(obj).innerHTML;
	var data = header + content + footer;
	var ident_window = window.open('','ident_window','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=0,height=0,left=0,top=0,screenX=0,screenY=0');
	ident_window.resizeBy(-100,-100);
	ident_window.status = "";
	ident_window.blur();
	window.focus();
	ident_window.document.open();
	ident_window.document.write(data);
	for (var x = 0; x <= 1000; x++) {
		if (ident_window.document.getElementById('noprint'+x)) {
			ident_window.document.getElementById('noprint'+x).style.display = 'none';
		}
	}
	ident_window.document.close();
	ident_window.print();
	ident_window.close();
}

function sendEmail2Friend( theForm, lang )
{
	//*** Var loading
	var loadingImg = new Image();
	loadingImg.src = '/media/layout_images/sendFriend/loading.gif';
	var loadingTxt = ( lang == 'en' ) ? 'Please wait, send in progress...' : 'Attendere invio in corso...';
	var loadingObj = '<img src="' + loadingImg.src + '" align="absmiddle" />&nbsp;&nbsp;&nbsp;&nbsp;' + loadingTxt;

	//*** Var Message
	var theMessageOK = ( lang == 'en' ) ? 'Your message is be sent!' : 'Il messaggio è stato inviato correttamente!';
	var theMessageKO = ( lang == 'en' ) ? 'Some errors occurs, please try again!' : 'Il messaggio NON è stato inviato!';

	//*** Var object
	var theContent = document.getElementById( 'sendFriend_return' );
	var theButton  = document.getElementById( 'sendFriend_button' );
	var theFirst   = theForm.elements[0];

	//*** Var check
	var arrayCheck   = new Array( 'sendFriend_userName', 'sendFriend_userEmail', 'sendFriend_friendName', 'sendFriend_friendEmail', 'sendFriend_message' );
	var arrayName_it = new Array( 'Il tuo nome', 'La tua email', 'Il nome del tuo amico', 'La mail del tuo amico', 'Messaggio di testo' );
	var arrayName_en = new Array( 'Your Name', 'Your Email', 'Friend Name', 'Friend Email', 'Messagge' );

	//*** Ajax Agent Var
	var theXmlHttp        = getXmlHttp();
	var theXmlHttp_link   = '/modules/sendEmail.php';
	var theXmlHttp_params = 'type=sendFriend&random=' + ( new Date().getTime() );

	//*** Check field
	for( i = 0; i < theForm.elements.length; i++ )
	{
		if( i == 0 )
			theFirst = theForm.elements[ i ];

		for( j = 0; j < arrayCheck.length; j++ )
		{
			if( theForm.elements[ i ].name == arrayCheck[ j ] && theForm.elements[ i ].value.length < 4 )
			{
				if( lang == 'en' )
					alert( 'The field "' + arrayName_en[ j ] + '" lenght must be min 4 chars!' );
				else
					alert( 'Il campo "' + arrayName_it[ j ] + '" deve essere lungo almeno 4 caretteri!' );

				theForm.elements[i].focus();
				return false;
			}
		}

		theXmlHttp_params += "&" + theForm.elements[ i ].name + "=" + theForm.elements[ i ].value;
	}

	//*** Display Div Loading
	theContent.innerHTML     = loadingObj
	theContent.style.display = 'block';

	//*** CALLBACK FUNCTION
	theXmlHttp.onreadystatechange = function()
	{
		if( theXmlHttp.readyState == 4 )
		{
			//*** IF NO ERROR
			if( theXmlHttp.status == 200 )
			{
				if( theXmlHttp.responseText == 'OK' )
					theContent.innerHTML = '<div class="success">' + theMessageOK + '</div>';
				else
					theContent.innerHTML = '<div class="error">' + theMessageKO + '</div>';
			}
			//*** OTHER ERROR
			else
			{
				theContent.innerHTML = '<div class="error">' + theMessageKO + '</div>';
			}
		}
	}

	//*** SEND DATA
	theXmlHttp.open( 'POST', theXmlHttp_link, true );
	theXmlHttp.setRequestHeader( 'Cache-Control', 'no-cache' );
	theXmlHttp.setRequestHeader( 'Pragma', 'no-cache' );
	theXmlHttp.setRequestHeader( 'Content-type', 'application/x-www-form-urlencoded' );
	theXmlHttp.setRequestHeader( 'Content-length', theXmlHttp_params.length );
	theXmlHttp.setRequestHeader( 'connection', 'close' );
	theXmlHttp.send( theXmlHttp_params );

	//*** Reset Form
	theForm.reset();
	theFirst.focus();

	return false;
}

function closesendEmail2Friend()
{
	document.getElementById( 'sendFriend_return' ).innerHTML = '';
	document.getElementById( 'sendFriend_return' ).style.display = 'none';

	popUp('sendFriend');
}

function getXmlHttp()
{
	var xmlHttp;

	//*** Firefox, Opera 8.0+, Safari
	if( window.XMLHttpRequest )
	{
		xmlHttp = new XMLHttpRequest();

		if( xmlHttp.overrideMimeType )
			xmlHttp.overrideMimeType( 'text/xml' );
	}
	//*** Internet Explorer
	else if( window.ActiveXObject )
	{
		//*** Internet Explorer 5+
		try
		{
			xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" );
		}
		catch( e )
		{
			//*** Internet Explorer 7
			try
			{
				xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
			}
			catch( e )
			{
				alert( "Your browser does not support AJAX!" );
				return false;
			}
		}
	}

	return xmlHttp;
}