function openCloseCategory(id) {
	if ((opened_div!=null)&&(opened_div!=id))
		$(opened_div).toggle();
	$(id).toggle();
	if (!$(id).visible()) {
		opened_div=null;
	} else {
		opened_div=id;
	}
}
function changeProduct(pid,table,bg_title) {
	var url='ajax_site_manager.php';
	var pars="action=change_product&pid="+pid+"&table="+table;
	var myAjax=new Ajax.Request(
		url,
		{
		method: 'get',
		parameters: pars,
		onComplete: function(originalRequest) {
						if( originalRequest.responseXml )
					        node = originalRequest.responseXml;
					    else
					        node = originalRequest.responseXML;
					    
					    var itemNode=node.getElementsByTagName('change_product')[0];
					    
					    h2=document.createElement("h2");
					    h2.className="prod_title";
					    h2.id="prod_title";
					    h2.style.fontSize="24px"
					    
					    title=document.createTextNode(itemNode.getAttribute('name'));
					    h2.appendChild(title);
					    
					    $('prod_title').remove();
					    $('title_div').appendChild(h2);
					    							    
					    $('div_prod_link').hide();
					    
					    Effect.Fade('prod_img',{duration:.5,afterFinish:function(e){
					    										changeProperties('prod_img','prod_link',itemNode);
					    									}
					    						}
					    			);

					    sIFR.replaceElement(named({sSelector:"h2", sFlashSrc:"sifr/franklin.swf", 
								sColor:"#ffffff",sLinkColor:"#477BBA",
								sBgColor:bg_title, sHoverColor:"#FF6600", nPaddingTop:0, 
								nPaddingBottom:0, sFlashVars:"textalign=left&offsetTop=3&offsetLeft=5"})); 
					}
		}
	);
	
}
function changeProperties(img,link,node) {
	var itemNode=node.getElementsByTagName('change_product')[0];
	var parent=$(img).parentNode;
	$(img).remove();
	var imgObj=document.createElement("img");
	imgObj.style.display="none";
	
	imgObj.src=node.getAttribute('img');
	imgObj.id="prod_img";
	
	parent.appendChild(imgObj);
	$('loader').show();
	
	
	imgPreload = new Image();
	imgPreload.onload=function(){
		$('loader').hide();
		
		Effect.Appear(imgObj, {duration:.5});
		//$(img).show();
		$(link).href="product.cfm?pid="+node.getAttribute('id');
		Effect.Appear($(link).parentNode, {duration:.5});
		
		
	}
	
	imgPreload.src = node.getAttribute('img');
	
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function showCloseMenu(s_menu,h_menu) {
	if (!($(s_menu).visible())) {
		opened_menu=s_menu;
		Effect.Appear(s_menu, {duration:.5});
	}
	if ($(h_menu)&&($(h_menu).visible()))
		Effect.Fade(h_menu, {duration:.5});
}

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_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];}
}
// (30/01/2009) valerio (per questionario dopo invio form contatti)
function checkContactForm(form_id) {
	
	if (($F('nome')=='')||($F('nome')==mandatory_field)) {
		$('nome').style.color="#ff0000";
		$('nome').value=mandatory_field;
		return 0;
	}
	if (($F('cognome')=='')||($F('cognome')==mandatory_field)) {
		$('cognome').style.color="#ff0000";
		$('cognome').value=mandatory_field;
		return 0;
	}
	if (($F('email')=='')||($F('email')==mandatory_field)) {
		$('email').style.color="#ff0000";
		$('email').value=mandatory_field;
		return 0;
	}
	if (!checkEmail($F('email'))) {
		$('email').style.color="#ff0000";
		$('email').value=bad_format;
		return 0;
	}
	
	$(form_id).submit();

}
function sendForm(form_id) {
	var str=Form.serialize($(form_id));
	
	//console.log(str)
	
	
	
	if (($F('nome')=='')||($F('nome')==mandatory_field)) {
		$('nome').style.color="#ff0000";
		$('nome').value=mandatory_field;
		return 0;
	}
	if (($F('cognome')=='')||($F('cognome')==mandatory_field)) {
		$('cognome').style.color="#ff0000";
		$('cognome').value=mandatory_field;
		return 0;
	}
	if (($F('email')=='')||($F('email')==mandatory_field)) {
		$('email').style.color="#ff0000";
		$('email').value=mandatory_field;
		return 0;
	}
	if (!checkEmail($F('email'))) {
		$('email').style.color="#ff0000";
		$('email').value=bad_format;
		return 0;
	}
	
	$('loader').toggle();
	$('SubmitContatti').disabled=true;
	
	var url='http://www.bellelli.com/admin/include/ajax_mail_manager.php';
	var pars="action=send_contacts&"+str;
	
	//alert(pars);
	
	var myAjax=new Ajax.Request(
		url,
		{
		method: 'post',
		parameters: pars,
		onComplete: function(originalRequest) {
				if( originalRequest.responseXml )
					node = originalRequest.responseXml;
				else
					node = originalRequest.responseXML;
				//console.log(originalRequest.responseText);
				
				var itemNode=node.getElementsByTagName('mail')[0];
				$('loader').toggle();
				$('SubmitContatti').disabled=false;
				if (itemNode.firstChild.nodeValue==1) {
					//alert("yep");
					appearDisappear('yep')
				} else {
					//alert("nope");
					//$('nope').show();
					appearDisappear('nope')
				}
				
			}
		}
	);
	
}
function sendPassword(form_id){
	var str=Form.serialize($(form_id));
	
	if (($F('req_email')=='')||($F('req_email')==mandatory_field)) {
		$('req_email').style.color="#ff0000";
		$('req_email').value=mandatory_field;
		return 0;
	}
	if (!checkEmail($F('req_email'))) {
		$('req_email').style.color="#ff0000";
		$('req_email').value=bad_format;
		return 0;
	}
	
	var url='http://www.bellelli.com/admin/include/ajax_mail_manager.php';
	var pars="action=request_password&"+str;
	
	//alert(pars);
	$('loader').toggle();
	$('Submit').disabled=true;
	
	var myAjax=new Ajax.Request(
		url,
		{
		method: 'post',
		parameters: pars,
		onComplete: function(originalRequest) {
				if( originalRequest.responseXml )
					node = originalRequest.responseXml;
				else
					node = originalRequest.responseXML;
				//console.log(originalRequest.responseText);
				
				$('loader').toggle();
				$('Submit').disabled=false;
				
				var itemNode=node.getElementsByTagName('send_password')[0];
				if (itemNode.firstChild.nodeValue==1) {
					//alert("yep");
					appearDisappear('ok_password',1)
				} else {
					//alert("nope");
					//$('nope').show();
					appearDisappear('no_password',1)
				}
				
			}
		}
	);
}
function subscribeReservedArea(form_id) {
	var str=Form.serialize($(form_id));
	
	if (($F('nome')=='')||($F('nome')==mandatory_field)) {
		$('nome').style.color="#ff0000";
		$('nome').value=mandatory_field;
		return 0;
	}
	if (($F('cognome')=='')||($F('cognome')==mandatory_field)) {
		$('cognome').style.color="#ff0000";
		$('cognome').value=mandatory_field;
		return 0;
	}
	if (($F('email')=='')||($F('email')==mandatory_field)) {
		$('email').style.color="#ff0000";
		$('email').value=mandatory_field;
		return 0;
	}
	if (!checkEmail($F('email'))) {
		$('email').style.color="#ff0000";
		$('email').value=bad_format;
		return 0;
	}
	
	var url='http://www.bellelli.com/admin/include/ajax_mail_manager.php';
	var pars="action=subscribe&"+str;
	
	$('loader_subscribe').toggle();
	$('areaSubmit').disabled=true;
	
	//alert(pars);
	
	var myAjax=new Ajax.Request(
		url,
		{
		method: 'post',
		parameters: pars,
		onComplete: function(originalRequest) {
				if( originalRequest.responseXml )
					node = originalRequest.responseXml;
				else
					node = originalRequest.responseXML;
				//console.log(originalRequest.responseText);
				
				$('loader_subscribe').toggle();
				$('areaSubmit').disabled=false;
				
				var itemNode=node.getElementsByTagName('subscribe')[0];
				if (itemNode.firstChild.nodeValue==1) {
					//alert("yep");
					appearDisappear('ok',1)
				} else {
					//alert("nope");
					//$('nope').show();
					appearDisappear('already',1)
				}
				
			}
		}
	);
}
function checkEmail(str){
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		testresults=true
	else{
		testresults=false
	}
	return (testresults)
}
function getWindowSize() {
	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 {'width':myWidth,'height':myHeight};
}
function appearDisappear(id,opacity,center) {
	var obj=$(id);
	var size=getWindowSize();
	//alert(size.width+","+size.height);
	if (center) {
		obj.setStyle({left:(size.width/2-160)+"px",top:(size.height/2-100)+"px"});
	}
	
	if ((!opacity)||(opacity==undefined))
		opacity=100;
	if (!obj.visible()) {
		Effect.Appear(id,{from:0,to:opacity,queue:'end'});
	} else {
		Effect.Fade(id,{from:opacity,to:0,queue:'end'});
	}	
}