// JavaScript Document

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function swapMenu(id){
	if($(id)) $(id).toggleClass("active");
}

function swapTab(id,id2){
	if($("Tab_"+id)) $("Tab_"+id).toggleClass("active");
	if($("Tab_"+id2)) $("Tab_"+id2).toggleClass("active");
	if($("Sk_"+id)) $("Sk_"+id).toggleClass("active");
	if($("Sk_"+id2)) $("Sk_"+id2).toggleClass("active");
}

function cleanText(object){
	object.value="";
	object.style.color = "#000";
}
function resetText(object){
	if (object.value==""){
		object.value = object.title;
		object.style.color = "#CCC";
	}
}

function addProduct(VAR_ID){
	if(VAR_ID!=""){
		$("VAR_ID").value 		= VAR_ID;
		$("VAR_Quantita").value = $("prd_"+VAR_ID+"_Qta").value;
		$("formVarianti").submit();
	}
	return false;
}
function ValidateSearch(){
	if (($("QS_PRD_Codice").value != $("QS_PRD_Codice").title)||($("QS_PRD_Descrizione").value != $("QS_PRD_Descrizione").title)){
		if(($("QS_PRD_Codice").value == $("QS_PRD_Codice").title)) $("QS_PRD_Codice").value = ""
		if(($("QS_PRD_Descrizione").value == $("QS_PRD_Descrizione").title)) $("QS_PRD_Descrizione").value = ""
		return true;
	}else{
		return false;
	}
}
function SendForm(idForm, idField, sValue){
	if($(idForm)){
		$(idField).value = sValue;
		//alert(idField + " : " + $(idField).value);
		//alert(idForm + " : " + $(idForm));
		$(idForm).submit();

		//alert($(idForm) + " : " + idForm);
	}
	return false;
}
// Funzioni custom...
window.addEvent('domready', function() {
	
	//Scheda prodotto
	if ($('Image')) {
		$('Image_Big').set('opacity', 0);
		$('Image_Big').toggleClass('active');
		var oLink = $('Image').getChildren('a');
		oLink.addEvent('click', function(event){
				event.stop();
				$('Image_Big').fade('toggle');
			});	
		
		var oLink = $('Image_Big').getChildren('a');
		oLink.addEvent('click', function(event){
				event.stop();
				$('Image_Big').fade('toggle');
			});	
	};
	
	if ($('Text_more')){
		
		var sClass = 'open';
		var sizeTo = $('Text_inner').getSize().y;
		var sizeFrom = $('Text').getSize().y;
				
		var myFx = new Fx.Morph('Text', {duration : 1000, transition : Fx.Transitions.Pow.easeOut});
		
		var oLink = $('Text_more').getChildren('a');
		oLink.addEvent('click', function(e){
			e.stop();
			var isize = (sClass=='close') ? sizeFrom : sizeTo;
			myFx.start({height: isize});
			(sClass=='close') ? sClass = 'open' : sClass = 'close';
			oLink.toggleClass('close');
		});			
	}
	
	if( $('pagamentoritiro_help') ){
		$('boxPagamentoRitiro_inner').slide('hide');
		$('boxPagamentoRitiro').setStyle('display', 'block');
		$('pagamentoritiro_help').addEvent('click', function(event){
				event.stop();
				$('boxPagamentoRitiro_inner').slide('toggle');
		});	
		$('pagamentoritiro_help_close').addEvent('click', function(event){
			   event.stop();
			   $('boxPagamentoRitiro_inner').slide('toggle');
		});	
	}
	
});