<!--//

var menulist_status = new Array();
var gallerytimer = '' ;

function ShowHideSubMenu(theid){
  if (document.getElementById) {
    var switch_id = document.getElementById(theid);
    var switch_menu_id = document.getElementById(theid + '_Entry' );
    if(menulist_status[theid] != 'show') {
      if ( switch_id.className != 'show' ) {
	    switch_id.className = 'show';
	    menulist_status[theid] = 'show';
	    if( switch_menu_id.className.indexOf( "_active" ) < 0 ) {
	      switch_menu_id.className = switch_menu_id.className + '_active' ;	
	    } 
      } else {
        switch_id.className = 'hide';
        menulist_status[theid] = 'hide';
        if( switch_menu_id.className.indexOf( "_active" ) >= 0 ) {
      	  switch_menu_id.className = switch_menu_id.className.replace('_active', '' ) ;	
        }	
      }
    }else{
      switch_id.className = 'hide';
      menulist_status[theid] = 'hide';
      if( switch_menu_id.className.indexOf( "_active" ) >= 0 ) {
      	switch_menu_id.className = switch_menu_id.className.replace('_active', '' ) ;	
      }
    }    
  }
}

function DivSetVisible(dropDownId, state) {
  var DivRef = document.getElementById(dropDownId);
  if (state) {
	DivRef.style.display = "block";
  }
  else {
	DivRef.style.display = "none";
  }
}

function menuSwapOn(id,image){
	$(id).style.background = "url(" + image + ")";
}

function menuSwapOff(id,image){
	$(id).style.background = "url(" + image + ")";
}

// Check that the number of characters in a string is between a max and a min
function isValidLength(string, min, max) {
        if (string.length < min || string.length > max) return false;
        else return true;
}

// Check that an email address is valid based on RFC 821 (?)
function isValidEmail(address) {
        if (address.indexOf('@') < 3) return false;
        var name = address.substring(0, address.indexOf('@'));
        var domain = address.substring(address.indexOf('@') + 1);
        if (name.indexOf('(') != -1 || name.indexOf(')') != -1 || name.indexOf('<') != -1 || name.indexOf('>') != -1 || name.indexOf(',') != -1 || name.indexOf(';') != -1 || name.indexOf(':') != -1 || name.indexOf('\\') != -1 || name.indexOf('"') != -1 || name.indexOf('[') != -1 || name.indexOf(']') != -1 || name.indexOf(' ') != -1) return false;
        if (domain.indexOf('(') != -1 || domain.indexOf(')') != -1 || domain.indexOf('<') != -1 || domain.indexOf('>') != -1 || domain.indexOf(',') != -1 || domain.indexOf(';') != -1 || domain.indexOf(':') != -1 || domain.indexOf('\\') != -1 || domain.indexOf('"') != -1 || domain.indexOf('[') != -1 || domain.indexOf(']') != -1 || domain.indexOf(' ') != -1) return false;
        return true;
}

function isFirstItem(select_obj) {
	return ( select_obj.selectedIndex <= 0 ) ;	
}

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];}
}
	
function StopGalleryMoving() {
	if (gallerytimer) clearTimeout(gallerytimer);	
}

function StartGalleryMoving( direction, boxId, bigboxId, listId ) {
	var increment = 15 ;
	// leggo valori
	content_width 	= document.getElementById( listId ).offsetWidth;
    container_width = document.getElementById( boxId ).offsetWidth;
    pos	= document.getElementById( bigboxId ).style.left ;
    // pulisco 
    pos	= parseInt( pos ) ;
    if ( isFinite( pos ) == false ) pos = 0 ;
    content_width   = parseInt( content_width ) ;
    container_width = parseInt( container_width ) ;
    // Se il contenuto è più grande del contenitore... 
    if ( content_width > container_width ) {
	    newpos = ( direction == 'left' ) ? (pos+increment) : (pos-increment) ;
	    if ( isFinite( newpos ) == false ) newpos = 0 ;    
	    // converto ad intero
	    min	= 0 ;
	    max	= ( container_width - content_width ) ;
		// se è sotto zero lo riposiziono
		if ( newpos > min ) {
			StopGalleryMoving() ;
			document.getElementById( bigboxId ).style.left = '0px' ;	
		} else if ( newpos < max ) {
			StopGalleryMoving() ;
			document.getElementById( bigboxId ).style.left = ( max ) + 'px' ;	 	
		} else {
			if ( direction == 'left' ) {
				new Effect.MoveBy(bigboxId, 0, +increment , {duration: 0});
	    		gallerytimer = setTimeout('StartGalleryMoving("'+direction+'", "'+boxId+'", "'+bigboxId+'", "'+listId+'")',50);	
			} else {
				new Effect.MoveBy(bigboxId, 0, -increment , {duration: 0});
	    		gallerytimer = setTimeout('StartGalleryMoving("'+direction+'", "'+boxId+'", "'+bigboxId+'", "'+listId+'")',50);
			}
		} 
    }
} 

function ProductSearchChange( url, selectId ) {
	// prendo l'oggetto "SELECT"
	select_obj = document.getElementById( selectId ) ;
	// se non ho l'URL, la costruisco
	url = ( url == '') ? location.href + '?' : url ;
	// determino se devo aggiungere il '?' oppre il '&' 
	if ( url.indexOf( '?' ) == -1 ) url = url + '?' + select_obj.name + '=' + select_obj.options[ select_obj.selectedIndex ].value ;
	else url = url + '&' + select_obj.name + '=' + select_obj.options[ select_obj.selectedIndex ].value ;
	// salto all'URL
	location.href= url + '#products_search_engine' ;
}

function ProductSearchSubmit( url, inputId ) {
	// prendo l'oggetto "INPUT"
	input_obj = document.getElementById( inputId ) ;
	// se non ho l'URL, la costruisco
	url = ( url == '') ? location.href + '?' : url ;
	// determino se devo aggiungere il '?' oppre il '&' 
	if ( url.indexOf( '?' ) == -1 ) url = url + '?' + input_obj.name + '=' + escape( input_obj.value ) ;
	else url = url + '&' + input_obj.name + '=' + escape( input_obj.value ) ;
	// salto all'URL
	location.href=url ;
}

function CheckGoogleSearchForm( form ) {
	if ( form.q.value != '' ) return true;
	else return false;
}

function GoogleSearchSubmit( formId, inputId ) {
	// prendo l'oggetto "INPUT"
	input_obj = document.getElementById( inputId ) ;
	form_obj  = document.getElementById( formId ) ;
	if ( input_obj.value != '' ) form_obj.submit();
}

function GoogleSearchSubmit( formId, inputId ) {
	// prendo l'oggetto "INPUT"
	input_obj = document.getElementById( inputId ) ;
	form_obj  = document.getElementById( formId ) ;
	if ( input_obj.value != '' ) form_obj.submit();
}

function CheckSearchGoogle( form ) {
	if ( form.q.value != '' ) return true;
	else return false;
}

function SearchGoogle( formId ) {
	form_obj  = document.getElementById( formId ) ;
	form_obj.submit();
}

function menuSwapOn(id,image){
	$(id).style.background = "url(" + image + ")";
}

function menuSwapOff(id,image){
	$(id).style.background = "url(" + image + ")";
}

function buildmailaddress( email, domain ) { 
	location.href = 'mailto:' + email + "@" + domain;
}

function mailaddress( email, domain ) { 
	return ( email + "@" + domain ) ;
} 

function ShowHideCommands( whichLayer ) {
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichLayer );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichLayer];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichLayer];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
    vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
  vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
