function sendEmail(sUser, sDomain, sSubject)
{
	location.href = 'mailto:' + sUser + '@' + sDomain + '?subject=' + sSubject;
}

function NewWindow(mypage, myname, w, h) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=no,resizable=no,directories=no,status=no,location=no,toolbar=no';
	win = window.open(mypage, myname, winprops);
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function privacy() {
        priv = window.open("privacy.asp",'privacy','scrollbars=yes,resizable=yes,directories=no,width=490,height=400,status=no,location=no,toolbar=no');
}

function cambia_pic(immagine) {
	document.big.src = "pict/hi/"+immagine+".jpg";
}

function cont() {
		p1 = "cont";
		p2 = "attis";
		window.location = p1 + p2 + ".asp";
}

function regrivend() {
	document.location.href="regrivend.asp";
}

function validate_form() {
  var validity = true; // assume valid
  var msg = "Verificare i seguenti dati:\n\n";
  if (!check_empty(document.form.Nome.value))
  	{ validity = false; msg=msg+'Inserire Nome\n'; }
  if (!check_empty(document.form.Cognome.value))
  	{ validity = false; msg=msg+'Inserire Cognome\n'; }
  if (!check_empty(document.form.Indirizzo.value))
  	{ validity = false; msg=msg+'Inserire Indirizzo\n'; }
  if (!check_empty(document.form.Citta.value))
  	{ validity = false; msg=msg+'Inserire Citta\'\n'; }
  if (!check_empty(document.form.Telefono.value))
  	{ validity = false; msg=msg+'Inserire Telefono\n'; }
  if (!check_empty(document.form.email.value) || !check_email(document.form.email.value))
  	{ validity = false; msg=msg+'Email non corretta\n'; }
   if (!check_accetto())
  	{ validity = false; msg=msg+'Accettare condizioni privacy\n'; }
  if (!validity) {
  	alert (msg);
  } else {
	document.form.action="sendmail.asp";
  }
  return validity;
}

function validate_form_riv() {
  var validity = true; // assume valid
  var msg = "Verificare i seguenti dati:\n\n";
  if (!check_empty(document.form.Azienda.value))
  	{ validity = false; msg=msg+'Inserire Azienda\n'; }
  if (!check_empty(document.form.Nome.value))
  	{ validity = false; msg=msg+'Inserire Nome\n'; }
  if (!check_empty(document.form.Cognome.value))
  	{ validity = false; msg=msg+'Inserire Cognome\n'; }
  if (!check_empty(document.form.Indirizzo.value))
  	{ validity = false; msg=msg+'Inserire Indirizzo\n'; }
  if (!check_empty(document.form.Citta.value))
  	{ validity = false; msg=msg+'Inserire Citta\'\n'; }
  if (!check_empty(document.form.Provincia.value))
  	{ validity = false; msg=msg+'Inserire Provincia\'\n'; }
   if (!check_empty(document.form.Cap.value))
  	{ validity = false; msg=msg+'Inserire Cap\n'; }
  if (!check_empty(document.form.Telefono.value))
  	{ validity = false; msg=msg+'Inserire Telefono\n'; }
  if (!check_empty(document.form.Fax.value))
  	{ validity = false; msg=msg+'Inserire Fax\n'; }
  if (!check_empty(document.form.PartIva.value))
  	{ validity = false; msg=msg+'Inserire Partita IVA\n'; }
  if (!check_empty(document.form.CodFisc.value))
  	{ validity = false; msg=msg+'Inserire Codice fiscale\n'; }
  if (!check_empty(document.form.email.value) || !check_email(document.form.email.value))
  	{ validity = false; msg=msg+'Email non corretta\n'; }
  if (!check_empty(document.form.pass1.value) || document.form.pass1.value != document.form.pass2.value)
  	{ validity = false; msg=msg+'Password e controllo password devono essere uguali\n'; }
   if (!check_accetto())
  	{ validity = false; msg=msg+'Accettare regole sulla privacy\ne condizioni di vendita\n'; }
  if (!validity) {
  	alert (msg);
  } else {
	document.form.action="sendmailriv.asp";
  }
  return validity;
}


function validate_form_cli() {
  var validity = true; // assume valid
  var msg = "Verificare i seguenti dati:\n\n";
  if (!check_empty(document.form.Nome.value))
  	{ validity = false; msg=msg+'Inserire Nome\n'; }
  if (!check_empty(document.form.Cognome.value))
  	{ validity = false; msg=msg+'Inserire Cognome\n'; }
  if (!check_empty(document.form.Indirizzo.value))
  	{ validity = false; msg=msg+'Inserire Indirizzo\n'; }
  if (!check_empty(document.form.Citta.value))
  	{ validity = false; msg=msg+'Inserire Citta\'\n'; }
  if (!check_empty(document.form.Provincia.value))
  	{ validity = false; msg=msg+'Inserire Provincia\'\n'; }
   if (!check_empty(document.form.Cap.value))
  	{ validity = false; msg=msg+'Inserire Cap\n'; }
  if (!check_empty(document.form.Telefono.value))
  	{ validity = false; msg=msg+'Inserire Telefono\n'; }
  if (!check_empty(document.form.CodFisc.value))
  	{ validity = false; msg=msg+'Inserire Codice fiscale\n'; }
  if (!check_empty(document.form.email.value) || !check_email(document.form.email.value))
  	{ validity = false; msg=msg+'Email non corretta\n'; }
  if (!check_empty(document.form.pass1.value) || document.form.pass1.value != document.form.pass2.value)
  	{ validity = false; msg=msg+'Password e controllo password devono essere uguali\n'; }
  if (!check_empty(document.form.Nazione.value))
  	{ validity = false; msg=msg+'Inserire Nazione\n'; }
	
  if (!check_accetto())
  	{ validity = false; msg=msg+'Accettare condizioni di vendita\n'; }
  if (!validity) {
  	alert (msg);
  } else {
	document.form.action="checkout.asp";
  }
  return validity;
}


function validate_ordine_riv() {
  var validity = true; // assume valid
  var msg = "Verificare i seguenti dati:\n\n";

  var pag = false;
  var riba = false;
  for (i=0; i<document.form.Pagamento.length; i++){
	if (document.form.Pagamento[i].checked) {
		pag = true;
		if (i==3) riba=true;
	}
  }
  if (!pag){
	validity = false; msg=msg+'Selezionare pagamento\n';
  }
  if (riba){
	if (!check_empty(document.form.abi.value))
	{ validity = false; msg=msg+'Inserire codice ABI\n'; }
	if (!check_empty(document.form.cab.value))
	{ validity = false; msg=msg+'Inserire codice CAB\n'; }
	if (!check_empty(document.form.banca.value))
	{ validity = false; msg=msg+'Inserire Banca\n'; }
  }

  if (!check_accetto())
  	{ validity = false; msg=msg+'Accettare condizioni di vendita\n'; }

  if (!validity) {
  	alert (msg);
  } else {
	document.form.action="order.asp";
  }
  return validity;
}

function validate_ordine() {
  var validity = true; // assume valid
  var msg = "Verificare i seguenti dati:\n\n";

  var pag = false;
  var riba = false;
  for (i=0; i<document.form.Pagamento.length; i++){
	if (document.form.Pagamento[i].checked) {
		pag = true;
		if (i==3) riba=true;
	}
  }
  if (!pag){
	validity = false; msg=msg+'Selezionare pagamento\n';
  }
  if (riba){
	if (!check_empty(document.form.abi.value))
	{ validity = false; msg=msg+'Inserire codice ABI\n'; }
	if (!check_empty(document.form.cab.value))
	{ validity = false; msg=msg+'Inserire codice CAB\n'; }
	if (!check_empty(document.form.banca.value))
	{ validity = false; msg=msg+'Inserire Banca\n'; }
  }

  if (!check_accetto())
  	{ validity = false; msg=msg+'Accettare condizioni di vendita\n'; }

  if (!validity) {
  	alert (msg);
  } else {
	document.form.action="order.asp";
  }
  return validity;
}

function check_empty(text) {
  return (text.length > 0); // returns false if empty
}
function check_email(Email) {
  if ((Email == "")
    || (Email.indexOf ('@') == -1)
    || (Email.indexOf ('.') == -1))
      return false;
  return true;
}

function checkEmail(toCheck) {
	if (/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/.test(toCheck)) return true; else return false;
}

function check_accetto() {
	if (!document.form.accetto.checked)
		return false;
	return true;
}

function RunFla(var1,var2,var3,var4)
{
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+var3+'" height="'+var4+'">\n');
    document.write('<param name="movie" value="'+var1+'">\n');
	document.write('<param name="quality" value="high">\n');
	document.write('<param name="wmode" value="transparent">\n');
	document.write('<param name="bgcolor" value="'+var2+'">\n');
	document.write('<embed src="'+var1+'" quality="high" bgcolor="'+var2+'" width="'+var3+'" height="'+var4+'" name="lay" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">\n');
    document.write('</object>\n');
}


function euroval2(s) {
	var strTot = replaceChars( s ,".",",");
	if (strTot.indexOf(",") > 0) {
		//strTot += "0";
	} else {
		strTot += ",00";
	}
	return strTot;
}

/*
var x = 3.14159;
alert( x.roundTo(2) );    // 3.14
alert( x.roundTo(4) );    // 3.1416 
*/

function roundTo(decimalpositions)
{
    var i = this * Math.pow(10,decimalpositions);
    i = Math.round(i);
    return i / Math.pow(10,decimalpositions);
}
Number.prototype.roundTo = roundTo;

function euroval(s) {
	var strTot = replaceChars( FormatNumber(s,2,false,false,false) ,".",",");
	if (strTot.indexOf(",") > 0) {
		//strTot += "0";
	} else {
		strTot += ",00";
	}
	return strTot;
}

function replaceChars(entry,what,withs) {
	temp = "" + entry; // temporary holder

	while (temp.indexOf(what)>-1) {
		pos= temp.indexOf(what);
		temp = "" + (temp.substring(0, pos) + withs + 
		temp.substring((pos + what.length), temp.length));
	}
	return temp;
}


function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
    if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}
