browserName = navigator.appName;
browserVer = parseInt(navigator.appVersion);
var ver = false;
if (browserName == "Microsoft Internet Explorer" && browserVer >= 4) ver = true;
if (browserName == "Netscape" && browserVer >= 3) ver = true;

var errorfound = false;
var invioavviato = false;
var lingua = 'ted';
var ultimoIDArticolo = 0;
var leftConvBoxShift = 220;

if (ver){
	freccia_dx_acc = new Image();
	freccia_dx_acc.src = 'images/freccia_dx_accesa.gif';
	freccia_sx_acc = new Image();
	freccia_sx_acc.src = 'images/freccia_sx_accesa.gif';
	loadfreccie = true;
}

function ON_freccia(NomeImg, Numero) {
	if (ver && loadfreccie) {
		eval("document." + NomeImg + Numero + ".src = " + NomeImg + "_acc.src");
	}
}

function OFF_freccia(NomeImg, Numero) {
	if (ver && loadfreccie) {
		eval("document." + NomeImg + Numero + ".src = 'images/" + NomeImg + "_scura.gif'"); 
	}
}

function validemail(item)
{	
	if(!validlength(item, 5)) return false;
	if(item.indexOf('\'', 0) > -1) return false;
	if(item.indexOf('@', 0) == -1) return false;
	if(item.indexOf('.', 0) == -1) return false;
	if(item.indexOf(',', 0) > 0) return false;
	return true;
}

function validlength(item, len) 
{
	return(trim(item).length >= len);
}

function error(elem, text)
{
	if (errorfound) return;
	window.alert(text)
	elem.focus();
	errorfound = true;
}

function radioValue(rObj)
{
	if (rObj.length==undefined) return rObj.value;
	for (var i=0; i<rObj.length; i++) if (rObj[i].checked) return rObj[i].value;
	return false;
}

function apriCCV(Lingua)
{
	nuovafinestra = window.open("ccv_" + Lingua + ".html", "CCV", "menubar=no, width=410, height=580, left=10, top=10, resizable=yes, scrollbars=no");
	nuovafinestra.focus();
}

function trim(StrToTrim)
{
    if (typeof StrToTrim != "string")
    {
        return StrToTrim;
    }
    var StrBlank = StrToTrim.substring(0, 1);
    while (StrBlank == " ")
    {
        StrToTrim = StrToTrim.substring(1, StrToTrim.length);
        StrBlank = StrToTrim.substring(0, 1);
    }
    StrBlank = StrToTrim.substring(StrToTrim.length - 1, StrToTrim.length);
    while (StrBlank == " ")
    {
        StrToTrim = StrToTrim.substring(0, StrToTrim.length-1);
        StrBlank = StrToTrim.substring(StrToTrim.length-1, StrToTrim.length);
    }
    while (StrToTrim.indexOf("  ") != -1)
    {
        StrToTrim = StrToTrim.substring(0, StrToTrim.indexOf("  "));
        StrToTrim += StrToTrim.substring(StrToTrim.indexOf("  ") + 1, StrToTrim.length);
    }
    return StrToTrim;
}

function are_cookies_enabled() {
	var cookieEnabled = (navigator.cookieEnabled) ? true : false;
	if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled) { 
		document.cookie="testcookie";
		cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
	}
	return (cookieEnabled);
}

function isnumeric (str) {
	for (var i = 0; i < str.length; i++) {
		var ch = str.substring(i, i+1);
		if (ch < "0" || ch > "9") {
			return false;
		}
	}
	return true;
}

function ControllaRicerca() {
	if (document.formricerca.testoricerca.value == "") {
		alert(iifLingua('Perfavore inserire il testo da cercare.', 'Bitte den zusuchenden Text eingeben.', 'Please insert the text to search.'));
		document.formricerca.testoricerca.focus();
		return false;
	}
	if (document.formricerca.testoricerca.value.length > 25)
		document.formricerca.testoricerca.value = document.formricerca.testoricerca.value.substring(0, 25);
}

function Over(el) {
	el.style.backgroundColor = '#ffffff';
	el.style.cursor = 'pointer'
}

function Out(el) {
	el.style.backgroundColor = ''; 
	el.style.cursor = 'default';
}

function sOver(el) {
	el.style.backgroundColor='#0b246b';
	el.style.color = '#ffffff';
	el.style.cursor = 'pointer';
}

function sOut(el) {
	el.style.backgroundColor = '';
	el.style.color = '';
	el.style.cursor = 'default';
}

function sizeToggle(IDArticolo) {
	if (document.getElementById('convBox' + IDArticolo).style.display == 'block')
		jQ('#convBox' + IDArticolo).hide('fast');
	else 
		sizeShow(IDArticolo);
}

function sizeShow(IDArticolo) {
	var heightWin = jQ(window).height();
	var scrollWin = jQ(window).scrollTop()
	var offsetTable = jQ('#table' + IDArticolo).offset();
	var topTable = offsetTable.top;
	var heightTable = jQ('#table' + IDArticolo).height();
	leftConvBox = offsetTable.left + leftConvBoxShift;

	//alert('heightWin: ' + heightWin);
	//alert('scrollWin: ' + scrollWin);
	//alert('topTable: ' + topTable);

	if (topTable + heightTable + jQ('#convBox' + IDArticolo).height() - scrollWin > heightWin) {
		jQ('.col1').css('border-left', '1px solid #fff');
		jQ('#convTab' + IDArticolo).css('margin', '2px 2px 0px');
		jQ('#convBox' + IDArticolo).css('top', '');
		if (jQ.browser.msie)
			if (parseInt(jQ.browser.version) == 6)
				heightWin += scrollWin;
		jQ('#convBox' + IDArticolo).css({left:leftConvBox, bottom:(heightWin - topTable)}).show('fast');
	}
	else {
		jQ('.col1').css('border-left', '1px solid #b2b2b2');
		jQ('#convTab' + IDArticolo).css('margin', '0px 2px 2px');
		jQ('#convBox' + IDArticolo).css('bottom', '');
		jQ('#convBox' + IDArticolo).css({left:leftConvBox, top:(topTable + heightTable)}).show('fast');
	}
	jQ('.convBox:not(#convBox' + IDArticolo + ')').hide('fast');
}

function sizeClick(IDArticolo, IDArticoloMisura, misura, qmax) {
	document.getElementById('add_size_value' + IDArticolo).innerHTML = misura;
	document.forms['formadd' + IDArticolo].IDArticoloMisura.value = IDArticoloMisura;
	document.forms['formadd' + IDArticolo].qmax.value = qmax;
	sizeToggle(IDArticolo);
}

function iifLingua(txtIta, txtTed, txtEng) {
	switch (lingua) {
		case 'ita': 
			return txtIta;
		case 'eng':
			return txtEng;
		default:
			return txtTed;
	}
}

function iif(test, a, b) {
	if (test)
		return a;
	else
		return b;
}

function addCart(IDArticolo) {
	if (document.forms['formadd' + IDArticolo].IDArticoloMisura.value == 0) {
		alert(iifLingua('Perfavore scegliere la misura.', 'Bitte die Größe aussuchen.', 'Please choose a size.'));
		sizeShow(IDArticolo);
		return false;
	}
	if (!isnumeric(document.forms['formadd' + IDArticolo].quant.value)) {
		alert('Quantità non valida.', 'Die Menge ist nicht gültig.', 'The quantity is not correct.');
		return false;
	}
	if ((document.forms['formadd' + IDArticolo].quant.value) < 1) {
		alert('Quantità non valida.', 'Die Menge ist nicht gültig.', 'The quantity is not correct.');
		return false;
	}
	var qmax = parseInt(document.forms['formadd' + IDArticolo].qmax.value);
	if (parseInt(document.forms['formadd' + IDArticolo].quant.value) > qmax) {
		switch (lingua) {
			case 'ita': 
				alert('Ci dispiace, abbiamo disponibil' + iif(qmax==1, 'e solo un paio.', 'i solo ' + qmax + ' paia.'));
				break;
			case 'eng':
				alert('Sorry, we have only ' + qmax + ' pair' + iif(qmax==1, '.', 's.'));
				break;
			default:
				alert('Es tut uns leid, wir haben nur ' + qmax + ' Stück auf Lager.');
		}
		document.forms['formadd' + IDArticolo].quant.value = qmax;
		return false;
	}
}

function addSizeOver(element)
{
	element.style.cursor='pointer';
}

function addSizeOverSeven(element)
{
	addSizeOver(element);
	element.style.backgroundImage=imgOver;
}

function addSizeOut(element)
{
	element.style.cursor='default';
}

function addSizeOutSeven(element)
{
	addSizeOut(element);
	element.style.backgroundImage="url(images/popup_Seven.gif)";
}
