function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function isInternetExplorer(){
	var browserName=navigator.appName; 
	if (browserName=="Microsoft Internet Explorer")
		return true;
 	else
		return false;
}


function changeCaptcha(idToUpdate, pageUrl) {

	var req = new Request.HTML({url:pageUrl, 
		onSuccess: function(html) {
			$(idToUpdate).set('text', '');
			$(idToUpdate).adopt(html);
		}
	});
	
	req.send();
}

function validateOrder() {

	if ($('orderCountry').value != '' && $('orderCompany').value != '' && $('orderName').value != '' && $('orderMail').value != '' && $('orderPhone').value != '') 
		return true;
	else {
		alert("Please review your order:\nName: is required\nCompany name: is required\nCountry: is required\nEmail: is required\nPhone: is required")
		return false;
	}
}

function modOrder(pageUrl, idArticle, quantity) {

	var req = new Request.HTML({url:pageUrl+"?idArticle="+idArticle+"&quantity"+quantity, 
		onSuccess: function() {
			alert("quanty successfull update!");
		},
		onFailure: function(){
			alert("quanty NOT changed!");
		}
	});
	
	req.send();
}

num_pagine = 1;
currPage = 1;
function selected(id, n_pag){
	var sfEls = $("tabContainer").getElementsByTagName("DIV");
    for (var i = 0; i < sfEls.length; i++) {
		if (sfEls[i].id.search("textContaier")>=0){
			sfEls[i].style.display="none";
		}
	}
	$('textContaier'+id).style.display="block";
	if (window.location.search != "") {
		window.location.search = "";
		window.location.hash = "navigation"
	}
	num_pagine = n_pag;
	currPage = 1;
	displayTextImage(1,id);
}

function displayTextImage(id,container){
	if (id > 0 && id <= num_pagine) {
		var sfEls = $("details" + container).getElementsByTagName("DIV");
		for (var i = 0; i < sfEls.length; i++) {
			if (sfEls[i].id.search("textImage" + container) >= 0) {
				sfEls[i].style.display = "none";				
			}
		}
		if ($("paging" + container)) {
			var sfEls = $("paging" + container).getElementsByTagName("A");
			for (var i = 0; i < sfEls.length; i++) {
				sfEls[i].className = sfEls[i].className.replace("strong","");
			}
			$('nav' + container  + "_" + id).className = $('nav' + container  + "_" + id).className+" strong ";
		}
		$('textImage' + container + "_" + id).style.display = "block";
		currPage = id;			
	}	
}

function selectedMaterial(container,id){
	var sfEls = $(container).getElementsByTagName("DIV");
    for (var i = 0; i < sfEls.length; i++) {
		if (sfEls[i].id.search("details")>=0){
			sfEls[i].style.display="none";
		}
	}
	$('details'+id).style.display="block";
	
	var sfEls = $('navigation').getElementsByTagName("A");
    for (var i = 0; i < sfEls.length; i++) {
		sfEls[i].className="";
	}
	$('link'+id).className="selected";
}

function setBckColor(id,color) {
	$(id).style.backgroundColor=color;
}

function display(id,img){
	var duration = 1000;
	if ($(id))
	if ($(id).style.display == 'block') {
		$(img).src=$(img).src.replace('_open.png','.png')
		//$('tabContainer').style.backgroundColor='#f2f2f2';
		setBckColor('tabContainer','#f2f2f2');
		$(id).style.display = 'none';
		var myEffect = new Fx.Morph(id, {
			duration: duration,
			transition: Fx.Transitions.Sine.easeOut
		});
		myEffect.start({
			'opacity': [1, 0]
		});		
		//$(id).style.opacity = '0';
	}
	else {
		$(img).src=$(img).src.replace('.png','_open.png')
		//$('tabContainer').style.backgroundColor='#cccccc';
		setTimeout("setBckColor('tabContainer','#cccccc');",duration/2);
		$(id).style.display = 'block';
		var myEffect = new Fx.Morph(id, {
			duration: duration,
			transition: Fx.Transitions.Sine.easeOut
		});
		myEffect.start({
			'opacity': [0, 1]
		});		
		//$(id).style.opacity = '1';
	}
}

function showForm(id,img){
	var duration = 1000;
	if ($(id))
	if ($(id).style.display == 'block') {
	}
	else {
		$(img).src=$(img).src.replace('.png','_open.png')
		//$('tabContainer').style.backgroundColor='#cccccc';
		setTimeout("setBckColor('tabContainer','#cccccc');",duration/2);
		$(id).style.display = 'block';
		var myEffect = new Fx.Morph(id, {
			duration: duration,
			transition: Fx.Transitions.Sine.easeOut
		});
		myEffect.start({
			'opacity': [0, 1]
		});		
		//$(id).style.opacity = '1';
	}
}


