// ################################################
// ################################################

version = ""
browserName = navigator.appName;
browserVer  = parseInt(navigator.appVersion);
bPlatform = navigator.platform;

if ( browserName == "Netscape" && browserVer >= 3 )
	version = "n3+";
else
if ( browserName == "Microsoft Internet Explorer" && browserVer >= 4 )
	version = "ie4+";

	
browserPlat  = "win";
if ( navigator.platform.indexOf("Mac") != -1 )
	browserPlat = "mac";
else
if ( bPlatform.indexOf("Win") != -1 )
	browserPlat = "win";



// ################################################

function NuovaFinestra (content, wName, width, height, status, resizable, toolbar, menubar, scrollbars, location, directories)
{
if (version == "ie4+" )
	if (browserPlat == "mac")
		{
		width -= 16;
		height -= 16;
		}
	else
		{
		}
else
if (version == "n3+" )
	if (browserPlat == "mac")
		{
		}
	else
		{
		}
	
params = ""
params += "width=" + width;
params += ",";

params += "height=" + height;
params += ",";

status ? params += "status=1" : "status=0" ;
params += ",";

resizable ? params += "resizable=1" : "resizable=0" ;
params += ",";

toolbar ? params += "toolbar=1" : "toolbar=0" ;
params += ",";

menubar ? params += "menubar=1" : "menubar=0" ;
params += ",";

scrollbars ? params += "scrollbars=1" : "scrollbars=0" ;
params += ",";

location ? params += "location=1" : "location=0" ;
params += ",";

directories ? params += "directories=1" : "directories=0" ;
params += ",";

//params += "location=0, directories=0";

aWind = window.open(content, wName, params);

aWind.blur(); //necessario per chorme (bucato)
aWind.focus();
return aWind;
}

// ##########################################################

function cambiaimg(x,pulsante)
{

compat = false;
if(parseInt(navigator.appVersion)>=4) { compat = true; }

if(compat)
{
document.images[x].src=pulsante; 
}

}

// ################################################

function CambiaProdotto( href, img )
{

for (i=0; i < document.links.length; i++ )
	{

	if ( document.links[ i ].name == 'prodottolink' )
		{
		//alert( i );
		
		prodottoLinkID = i;
		}
	}

document.images.prodotto.src = img;
document.images.prodottobott.src = '../img/prod-freccia.gif';

if ( prodottoLinkID >= 0 )
	{
	document.links[ prodottoLinkID ].href = href;
	}
}

// ################################################

function CheckNumber( aField, typeInt )
{ 
var		nr1; 
var		i;
var		cmp;
var		tst;
var		err = 0;

nr1 = aField.value; 

if (nr1 == "") 
	{
	err = 1;
	}
		
if ( typeInt == 0 )
	cmp = "0123456789";
else
	cmp = "0123456789,.";

for ( i = 0; i < nr1.length; i++ )
	{
	tst = nr1.substring( i ,i + 1 )
	if ( cmp.indexOf( tst ) < 0 )
		{
		err = 2;
		}
	}

if ( err )
	{
	if ( err == 1 )
		aField.value = '0';
		
	return false;
	}
	
return true;

}

// ################################################

function CheckEmail( aField )
{
var		i = 1;
var		len = aField.value.length;


while ((i < len) && (aField.value.charAt(i) != "@"))
	i++

if ((i >= len) || (aField.value.charAt(i) != "@"))
	return false;

i += 2;
	
while ((i < len) && (aField.value.charAt(i) != "."))
	i++

if ( (i >= len - 1) || (aField.value.charAt(i) != "."))
	return false;

return true;
}

function OpenTransactionList(vIdCliente) {
    var Url = "ASPTOASPX.asp?maschiocards_transactions.aspx&id="+vIdCliente;
    var theWin = NuovaFinestra(Url, 'maschiocards_transactions', 800, 400, false, true, false, false, false, false, false);    
    return theWin;
}


//onkeypress='return isNumberKey(event)'
function isNumberKey(evt,bAllowDecimals) {
    evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt) {
        var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
        if (elem) {
            var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
            if ((charCode < 32) ||
               ((charCode > 44 && charCode < 47) && bAllowDecimals) ||
               (charCode > 47 && charCode < 58)) 
            {
                return true;
            }
            else {
                return false;
            }
        }
    }
}

function WinPopup(url, w, h, Name) {
    var l = Math.floor((screen.width - w) / 2);
    var t = Math.floor((screen.height - h) / 2);
    hwnd = window.open(url, Name, "width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
    hwnd.blur(); //necessario per chorme (bucato)
    hwnd.focus();
}

function HtmlEncode(text) {

    // Lettere accentate ------------- 
    text = text.replace(/à/g, "&agrave;");
    text = text.replace(/è/g, "&egrave;");
    text = text.replace(/é/g, "&eacute;");
    text = text.replace(/ì/g, "&igrave;");
    text = text.replace(/ù/g, "&ugrave;");
    text = text.replace(/ò/g, "&ograve;");
    text = text.replace(' ', "&nbsp;");
    
    //--------------------------------
    //-------Fix Safari problem-------
    text = text.replace(/</g, "&lt;");
    text = text.replace(/>/g, "&gt;");

    //alert(text);
    return text;
}



// ***********************************************
// ***********************************************


