// JavaScript Document
window.setInterval(control_cart, 300); 

$(document).ready(function() {
$('#user_connect').html('<img src=http://www.edyte.it/image/loading_d.gif align=absmiddle > Loading...');	
$('#user_connect').load("http://www.edyte.it/include/navigator_out_connect.php");
//control_cart(); 
});

function DoLogin(){
$('#topnavigation').animate({'height':'60px'},400);
$("#user_connect").fadeOut(150,function() { 
$('#user_connect').html('');
$("#user_connect").html('<b>Username:</b> <input type="text" name="user" id="user" class="inputLogin" size="15" /> <b>Password:</b> <input type="password" name="pass" id="pass" class="inputLogin" size="15"/> <input type="button" name="login" id="login" value="Login" onclick="Process_Login();" onfocus="this.blur();" /> | <input type="button" name="nologin" id="nologin" onclick="NoLogin();" onfocus="this.blur();" value="Annulla" /><div id="log_initial"></div>');	
$('#user_connect').fadeIn(300);
$('#user').focus();
});
}

function DoLogin_cart(){
$('html, body').animate({scrollTop: $("#topnavigation").offset().top}, 600, function(){ DoLogin(); }); 
}

function NoLogin(){
$('#user_connect').html('<img src=http://www.edyte.it/image/loading_d.gif align=absmiddle > Loading...');
$('#topnavigation').animate({'height':'25px'},400, function(){
$('#user_connect').load("http://www.edyte.it/include/navigator_out_connect.php").fadeIn(300); });
}

function Process_Login(){
$("#log_initial").html('<br><img src=http://www.edyte.it/image/loading_d.gif align=absmiddle > Attendere Prego...');
document.getElementById("nologin").disabled = true;
document.getElementById("login").disabled = true;
document.getElementById("user").disabled = true;
document.getElementById("pass").disabled = true;

var user = document.getElementById('user').value; 
var pass = document.getElementById('pass').value; 

$.ajax({
method: 'get',
url : "http://www.edyte.it/secure/function_login.php?action=login&user="+user+"&pass="+pass+"",
dataType : 'text',
cache: false, 
success: function (text) {
window.setTimeout('nexte("'+text+'")', 2500);	
},
error: function()
{
$('#log_initial').html('<img src=http://www.edyte.it/image/alert_red.png align=absmiddle > <b>ERRORE</b> Impossibile eseguire questa operazione.');
}
});
return true;

}

function nexte(text){

 var sp = text.split(","); 
 var a = sp[0];
 var b = sp[1];

if( a == 'no'){ $('#log_initial').html('<br><img src=http://www.edyte.it/image/alert_red.png align=absmiddle > Accesso Negato! / Le credenziali non sono valide.'); window.setTimeout('del_msg()', 1200); }
if( a == 'si'){ 

if( b == 'Administrator'){ document.location.href = 'http://www.edyte.it/admin/index.php'; } else {

NoLogin();  var state = $('#state').val(); var inCart  = $('#ord-totale').val();
if ( state == 'cart' && inCart != '0.00'  ){  goProcess2();  }  } }
}

function del_msg(){
$('#log_initial').html('');
document.getElementById("nologin").disabled = false;
document.getElementById("login").disabled = false;
document.getElementById("user").disabled = false;
document.getElementById("pass").disabled = false;
 
}

function LogOff(){
$.ajax({
method: 'get',
url : "http://www.edyte.it/secure/function_login.php?action=logoff",
dataType : 'text',
cache: false, 
success: function (text) {
NoLogin();
var state = $('#state').val();
if ( state == 'cart' ){  exit_cart();  }
},
error: function()
{
alert('ERRORE');
}
});
return true;
	
}


function addCart_msg(idart,articolo,prezzo,quantita,variante,cancellabile)
{
	
$.msgbox('Inserire l\'articolo:<br>&laquo; <strong>'+articolo+'</strong> &raquo;<br>nel carrello?', {
type : 'confirm',
buttons : [
    {type: 'submit', value:'Aggiungi'},
    {type: 'cancel', value:'Annulla'}
  ]
},  function(e1, e2) {

if (e1){
	
//ESEGUO ADDIZIONE PER IL TOTALE DELL'PRODOTTO MOLTIPLICATO PER LA QUANTITA
var g = quantita;
var si = prezzo;
var i=parseFloat(si);
var tot=i*g;
tot = String(Math.round(tot*100)/100);
tot = (tot.indexOf(".")>=0)?tot+"0":tot+".00";
tot = tot.substr(0,tot.indexOf(".")+3);
tot=tot.replace(/\./g , "."); // output sempre con punto
var importo = tot;

$('#notifica').jGrowl("<img src=http://www.edyte.it/image/success.gif align=absmiddle > Articolo aggiunto al carrello.");

$.ajax({
method: 'get',
url : "http://www.edyte.it/ordini/cart_control.php?action=add&idart="+idart+"&articolo="+articolo+"&prezzo="+prezzo+"&quantita="+quantita+"&importo="+importo+"&variante="+variante+"&cancellabile="+cancellabile+"",
dataType : 'text',
cache: false, 
success: function (text) {
$('#updateQTCART').html(text);
},
error: function()
{
alert('ERRORE');
}
});
return true;

}

});
}

function addCart(idart,articolo,prezzo,quantita,variante,cancellabile)
{
	
//ESEGUO ADDIZIONE PER IL TOTALE DELL'PRODOTTO MOLTIPLICATO PER LA QUANTITA
var g = quantita;
var si = prezzo;
var i=parseFloat(si);
var tot=i*g;
tot = String(Math.round(tot*100)/100);
tot = (tot.indexOf(".")>=0)?tot+"0":tot+".00";
tot = tot.substr(0,tot.indexOf(".")+3);
tot=tot.replace(/\./g , "."); // output sempre con punto
var importo = tot;

$('#notifica').jGrowl("<img src=http://www.edyte.it/image/success.gif align=absmiddle > Articolo aggiunto al carrello.");

$.ajax({
method: 'get',
url : "http://www.edyte.it/ordini/cart_control.php?action=add&idart="+idart+"&articolo="+articolo+"&prezzo="+prezzo+"&quantita="+quantita+"&importo="+importo+"&variante="+variante+"&cancellabile="+cancellabile+"",
dataType : 'text',
cache: false, 
success: function (text) {
$('#updateQTCART').html(text);
},
error: function()
{
alert('ERRORE');
}
});
return true;

}


function control_cart(){

$.ajax({
method: 'get',
url : "http://www.edyte.it/ordini/cart_control.php?action=control",
dataType : 'text',
cache: false, 
success: function (text) {
$('#updateQTCART').html(text);
},
error: function()
{
alert("ERRORE");
}
});
return true;
	
}


function kb(puntamento){
var w = 800;
var h = 400;
var l = Math.floor((screen.width-w)/2);
var t = Math.floor((screen.height-h)/2);
window.open("http://www.edyte.it/assistenza/kb/"+puntamento+"","_blank","width=" + w + ",height=" + h + ",scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes,status=yes,top=" + t + ",left=" + l);
}

function iLink(punta){
var w = 800;
var h = 400;
var l = Math.floor((screen.width-w)/2);
var t = Math.floor((screen.height-h)/2);
window.open(""+punta+"","_blank","width=" + w + ",height=" + h + ",scrollbars=yes,resizable=yes,menubar=yes,toolbar=yes,location=yes,status=yes,top=" + t + ",left=" + l);
}

function ticket(){
window.location.href = "http://www.edyte.it/membership/assistance/help_center.php";	
}

function outPage(locator){
$.fancybox({
				'width'				: 650,
				'height'			: 450,
				'href'			    : ""+locator+"",
				'autoScale'			: false,
				'transitionIn'	    : 'fade',
				'transitionOut'		: 'fade',
				'overlayColor'		: '#000',
				'overlayOpacity'	: 0.7,
				'type'				: 'iframe'
			});	
}

