/*
var reparti=[	"CHITARRE---BASSI.1.16.5.sp.uw.aspx",
			"RECORDING.1.16.12.sp.uw.aspx",
			"AUDIO.1.16.3.sp.uw.aspx",
			"BATTERIE.1.16.4.sp.uw.aspx",
			"PERCUSSIONI.1.16.10.sp.uw.aspx",
			"TASTIERE.1.16.13.sp.uw.aspx",
			"ARCHI.1.16.2.sp.uw.aspx",
			"FIATI.1.16.8.sp.uw.aspx"];
var repOfferList=["Offerte Chitarre e Bassi",
			"Offerte Recording",
			"Offerte Audio",
			"Offerte Batterie e Percussioni",
			"Offerte Batterie e Percussioni",
			"Offerte Tastiere",
			"Offerte Archi",
			"Offerte Fiati"];
*/


function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}
function check_email(str){
		if(str==null)return false;
		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstat=str.lastIndexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		var lstdot=str.lastIndexOf(dot);
		if (lat==-1){
		   return false;
		}

		if (lat==-1 || lat==0 || lstat==(lstr-1)){
		   return false
		}

		if (ldot==-1 || ldot==0 || lstdot==(lstr-1)){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
}
// end CHECKEMAIL
function check_contacts(form){
	var fields = "";
	var tel_str = form.find("#tel").attr("value").replace(' ','');
	var nan_tel = isNaN(parseInt(tel_str) );
	var mail = trim(form.find("#email").attr("value"));
	if(mail == "" && tel_str == ""){
		fields = fields + " - Inserire almeno un contatto (email/telefono)\n\n";
	}else{
			if(mail != ""){
			 	if(!check_email(mail)){
					fields = fields + " - email non valida\n\n";
				}
			}
			if(tel_str != "" && nan_tel){
				fields = fields + " - Telefono non valido\n\n";				
			}
	}
	return fields;
}

function check_form_usato(frm){
	var form = $(frm);
	var marca = form.find("#marca").attr("value");
	var modello = form.find("#modello").attr("value")
	var fields = "";
	if(form.find("#tipo_str").attr("value") == "NON-IMMESSO") fields = fields + " - Tipo Strumento\n\n";
	if(marca == null || trim(marca) == "") fields = fields + " - Marca\n\n";
	if(modello == null || trim(modello) == "") fields = fields + " - Modello\n\n";
	fields = fields + check_contacts(form);
	if (fields == ""){
		return true;
	}else{
		alert("Attenzione alcuni campi obbligatori non corretti:\n\n"+fields);
		return false;
	}
}

function regFormUpper(){
	$("#regForm form").submit(function(){$("#regForm input[type='text']:lt(6)").each(function(){
												this.value=this.value.toUpperCase();
												});
						});
};


function msgDiscDett(){
/*
	becca le marche su liste(resultBox)
	$(".resultBox").each(function(i){
			alert($(this).find("dd").eq(2).html())
		}
	)
	*/
	/*
	becca le marche su dettaglio(detailsBox)
	$(".detailsBox").each(function(i){
			alert($(this).find("td").eq(2).html())
		}
	)
	*/
	$(".detailsBox").after("<div style='margin: 0pt 0pt 10px 310px;' id='disclPrice' class='servicesBox'><h2>Attenzione:</h2><p>Grazie ai minori costi di gestione i prezzi online possono essere pi&ugrave; vantaggiosi rispetto a quelli proposti in negozio e sono quindi validi esclusivamente per acquisti effettuati online</p></div>");
};

function slideBox(){
	var indRnd=Math.floor(Math.random()*5)
	$('#slidecx').slideshow({
				index:indRnd,
				panel:false,
				playframe:false,
				play:true,
				titleshow:true,
				imgajax:true,
				imglink:true,
				width:620,
				height:146,
				effect:'random',
				help:'Marpamusica Strumenti Musicali'});
	$('#slidecx').css("visibility","visible");
	$('#slidecx').css("z-index","-1");
};

function animateMenu(){

     $("#categories>ul>li:has('ul')>a").removeAttr("onclick");
     $("#categories>ul>li:has('ul')>a").click(function(){
        var th = $(this).parent();
/*
        var ur = $(this).attr("href");
	  var offList = getRepList(ur);
	  var reloc = (th.find("ul:visible").size() == 0  && location.href.indexOf(ur)==-1 && th.find("ul li a strong").size() == 0);
*/      
        th.siblings("li").find("ul").hide("slow");
        th.find("ul").toggle("slow");
/*
        if(reloc){
			if(offList == null && ur != null)Location.replace(ur);
			else if(offList != null )offerList(offList);
		}
*/
        return false;
  });
};
function getRepList(repUrl){
	for(var i=0;i<reparti.length;i++){
		if(repUrl == reparti[i]){
			return repOfferList[i]
		}
	}
	return null;
};

function spostaSearch(){
	$("#mainSearchFormBox a").css({backgroundPosition : "0 -16px"});
	$("#mainSearchFormBox").css({width:"180px"});
	$("#mainSearchFormBox fieldset label").after("<br/>");
	$("#mainSearchFormBox fieldset").hide();
	$("#colSx").prepend($("#mainSearchFormBox"));
	$("#mainSearchFormBox").css("visibility","visible");
	$("#search_currentArea").click();
	$("#search_currentArea").parent().find("*").css("display","none");
	$("#mainSearchForm_cmdString").focus();
};

function nascondiMiniBox(){
	$(".miniBox").hide();
};

function offerList(offId){
	$("#mainSearchForm_cmdString").val(offId);
	$("#mainSearchFormBox_frm").submit();
};
