var product_slide = "";
var product_status = "";
var product_toggle = "";

var Ticker = new Class({
	setOptions: function(options) {
		this.options = Object.extend({
			speed: 1500,
			delay: 5000,
			direction: 'vertical',
			onComplete: Class.empty,
			onStart: Class.empty
		}, options || {});
	},
	initialize: function(el,options){
		this.setOptions(options);
		this.el = $(el);
		this.items = this.el.getElements('li');
		var w = 0;
		var h = 0;
		if(this.options.direction.toLowerCase()=='horizontal') {
    		h = this.el.getSize().y;
			this.items.each(function(li,index) {
				w += li.getSize().x;
			});
		} else {
			w = this.el.getSize().x;
			this.items.each(function(li,index) {
   				h += li.getSize().y;
			});
   		}
		this.el.setStyles({
			position: 'absolute',
			top: 0,
			left: 0,
			width: w,
			height: h
		});
		this.fx = new Fx.Morph(this.el,{duration:this.options.speed,onComplete:function() {
			var i = (this.current==0)?this.items.length:this.current;
			this.items[i-1].injectInside(this.el);
			this.el.setStyles({
				left:0,
				top:0
			});
		}.bind(this)});
		this.current = 0;
		this.next();
	},
	next: function() {
		this.current++;
		if (this.current >= this.items.length) this.current = 0;
		var pos = this.items[this.current];
		this.fx.start({
			top: -pos.offsetTop,
			left: -pos.offsetLeft
		});
   		this.next.bind(this).delay(this.options.delay+this.options.speed);
	}
});

function scroll_to() {
    window.addEvent('domready', function() {
        var scroll = new Fx.Scroll(window, {
    	    wait: true,
        	duration: 2000,
        	transition: Fx.Transitions.Quad.easeInOut
        });
        scroll.toElement('banner');
    });
}

function roar_msg(text, i) {
    roars[i].alert(text);
    return false;
}

function alert_msg(text) {
    box.alert(text);
    return false;
}

function info_msg(text) {
    box.info(text);
    return false;
}

function error_msg(text) {
    box.error(text);
    return false;
}

function statusText() {
    var data = new Date();
	window.status='GME Music '+String.fromCharCode(169)+' 2009/'+data.getFullYear()+' by GC3 - Gradient Consulting';
	return true;
}

function check_cf(cf){
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return false;
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return false;
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		return false;
	return true;
}

function customCheck(el){
    if (!check_cf(el.value)) {
	    el.errors.push("Immetti un codice fiscale corretto!");
		return false;
	} else {
		return true;
    }
}

function login_form(referer) {
    window.addEvent('domready', function(){
    var output = $('login_output');
    var form = document.getElementById("Login_Form");
    new FormCheck('Login_Form', {
        display : {
			closeTipsButton : 0,
			flashTips : 1,
            scrollToFirst : false
        },
        submitByAjax : true,
        onAjaxRequest: function() {
            $('login_button').set('disabled',true);
            for (var i=0; i<form.elements.length; i++) form.elements[i].readOnly=true;
            output.set('html', '<img src="images/load.gif" alt="Loading..." title="Loading..." />');
        },
        onAjaxSuccess: function(response) {
            output.set('html', '');
            $('login_button').set('disabled',false);
            for (var i=0; i<form.elements.length; i++) form.elements[i].readOnly=false;
            if (response == "<!-- ERRORE_LOGIN -->") roar_msg(""+imgError+""+txtErroreLogin+"", 0);
            else if (response == "<!-- ERRORE_ACCOUNT_BLOCCATO -->") roar_msg(""+imgError+""+txtErroreAccountBloccato+"", 0);
            else if (response == "<!-- ERRORE_ACCOUNT_NON_ATTIVATO -->") roar_msg(""+imgError+""+txtErroreAccountNonAttivato+"", 0);
            else {
                $('login_button').set('disabled',true);
                for (var i=0; i<form.elements.length; i++) form.elements[i].disabled=true;
                if (referer) {
                    referer = referer.replace(/&amp;/g, "&");
                    location.href=referer;
                } else location.href='index.php';
            }
        }});
    });
}

function check_state(state, country) {
    if (document.getElementById(state).value == "Italia")
        document.getElementById(country).disabled=false;
    else {
        document.getElementById(country).value = '';
        document.getElementById(country).disabled=true;
    }
}

function registration_form() {
    window.addEvent('domready', function(){
    new DatePicker('.date_birthday', {
    	pickerClass: 'datepicker_dashboard',
    	days: [txtSunday, txtMonday, txtTuesday, txtWensday, txtThursday, txtFriday, txtSaturday],
    	months: [txtJanuary, txtFebruary, txtMarch, txtApril, txtMay, txtJune, txtJuly, txtAugust, txtSeptember, txtOctober, txtNovember, txtDecember],
    	allowEmpty: true,
    	toggleElements: '.birthday',
        format: 'd F Y',
        inputOutputFormat: 'Y-m-d'
   	});
    var output = $('registration_output');
    var activation = $('activation_output');
    var form = document.getElementById("Registration_Form");
    new FormCheck('Registration_Form', {
        display : {
			closeTipsButton : 0,
			flashTips : 1,
            scrollToFirst : true
        },
        submitByAjax : true,
        onAjaxRequest: function() {
            $('registration_button').set('disabled',true);
            for (var i=0; i<form.elements.length; i++) form.elements[i].readOnly=true;
            output.set('html', '<img src="images/load.gif" alt="Loading..." title="Loading..." />');
        },
        onAjaxSuccess: function(response) {
            output.set('html', '');
            $('registration_button').set('disabled',false);
            for (var i=0; i<form.elements.length; i++) form.elements[i].readOnly=false;
            if (response == "<!-- ERRORE_EMAIL -->") roar_msg(""+imgError+""+txtErroreEmail+"", 0);
            else if (response == "<!-- ERRORE_CF -->") roar_msg(""+imgError+""+txtErroreCF+"", 0);
            else if (response == "<!-- ERRORE_GENERICO -->") roar_msg(""+imgError+""+txtErroreGenerico+"", 0);
            else if (response == "<!-- SUCCESSO_REGISTRAZIONE -->") {
                $('registration_button').set('disabled',true);
                for (var i=0; i<form.elements.length; i++) form.elements[i].disabled=true;
                roar_msg(""+imgSuccess+""+txtSuccessoRegistrazione+"", 0);
                activation.set('html', ""+txtLinkAttivazione+"");
            }
        }});
    });
}

function edit_form() {
    window.addEvent('domready', function(){
    new DatePicker('.date_birthday', {
    	pickerClass: 'datepicker_dashboard',
    	days: [txtSunday, txtMonday, txtTuesday, txtWensday, txtThursday, txtFriday, txtSaturday],
    	months: [txtJanuary, txtFebruary, txtMarch, txtApril, txtMay, txtJune, txtJuly, txtAugust, txtSeptember, txtOctober, txtNovember, txtDecember],
    	allowEmpty: true,
    	toggleElements: '.birthday',
        format: 'd F Y',
        inputOutputFormat: 'Y-m-d'
   	});
    var output = $('edit_output');
    var form = document.getElementById("Edit_Form");
    new FormCheck('Edit_Form', {
        display : {
			closeTipsButton : 0,
			flashTips : 1,
            scrollToFirst : true
        },
        submitByAjax : true,
        onAjaxRequest: function() {
            $('edit_button').set('disabled',true);
            for (var i=0; i<form.elements.length; i++) form.elements[i].readOnly=true;
            output.set('html', '<img src="images/load.gif" alt="Loading..." title="Loading..." />');
        },
        onAjaxSuccess: function(response) {
            output.set('html', '');
            $('edit_button').set('disabled',false);
            for (var i=0; i<form.elements.length; i++) form.elements[i].readOnly=false;
            if (response == "<!-- ERRORE_CF -->") roar_msg(""+imgError+""+txtErroreCF+"", 0);
            else if (response == "<!-- ERRORE_GENERICO -->") roar_msg(""+imgError+""+txtErroreGenerico+"", 0);
            else if (response == "<!-- SUCCESSO_MODIFICA -->") {
                roar_msg(""+imgSuccess+""+txtSuccessoModifica+"", 0);
            }
        }});
    });
}

function recovering_form() {
    window.addEvent('domready', function(){
    var output = $('recovering_output');
    var form = document.getElementById("Recovering_Form");
    new FormCheck('Recovering_Form', {
        display : {
			closeTipsButton : 0,
			flashTips : 1,
            scrollToFirst : true
        },
        submitByAjax : true,
        onAjaxRequest: function() {
            $('recovering_button').set('disabled',true);
            for (var i=0; i<form.elements.length; i++) form.elements[i].readOnly=true;
            output.set('html', '<img src="images/load.gif" alt="Loading..." title="Loading..." />');
        },
        onAjaxSuccess: function(response) {
            output.set('html', '');
            $('recovering_button').set('disabled',false);
            for (var i=0; i<form.elements.length; i++) form.elements[i].readOnly=false;
            if (response == "<!-- ERRORE_CODICE_ANTISPAM -->") roar_msg(""+imgError+""+txtErroreCodiceAntispam+"", 0);
            else if (response == "<!-- ERRORE_RECUPERO_EMAIL -->") roar_msg(""+imgError+""+txtErroreRecuperoEmail+"", 0);
            else if (response == "<!-- ERRORE_UTENTE_BLOCCATO -->") roar_msg(""+imgError+""+txtErroreUtenteBloccato+"", 0);
            else if (response == "<!-- ERRORE_RECUPERO_ATTIVAZIONE -->") roar_msg(""+imgError+""+txtErroreRecuperoAttivazione+"", 0);
            else if (response == "<!-- ERRORE_GENERICO -->") roar_msg(""+imgError+""+txtErroreGenerico+"", 0);
            else if (response == "<!-- SUCCESSO_RECUPERO_PASSWORD -->") {
                roar_msg(""+imgSuccess+""+txtSuccessoRecuperoPassword+"", 0);
                $('recovering_button').set('disabled',true);
                for (var i=0; i<form.elements.length; i++) form.elements[i].disabled=true;
            } else if (response == "<!-- SUCCESSO_RECUPERO_ATTIVAZIONE -->") {
                roar_msg(""+imgSuccess+""+txtSuccessoRecuperoAttivazione+"", 0);
                $('recovering_button').set('disabled',true);
                for (var i=0; i<form.elements.length; i++) form.elements[i].disabled=true;
            }
        }});
    });
}

function contacts_form() {
    window.addEvent('domready', function(){
    var output = $('contacts_output');
    var form = document.getElementById("Contacts_Form");
    new FormCheck('Contacts_Form', {
        display : {
			closeTipsButton : 0,
			flashTips : 1,
            scrollToFirst : true
        },
        submitByAjax : true,
        onAjaxRequest: function() {
            $('contacts_button').set('disabled',true);
            for (var i=0; i<form.elements.length; i++) form.elements[i].readOnly=true;
            output.set('html', '<img src="images/load.gif" alt="Loading..." title="Loading..." />');
        },
        onAjaxSuccess: function(response) {
            output.set('html', '');
            $('contacts_button').set('disabled',false);
            for (var i=0; i<form.elements.length; i++) form.elements[i].readOnly=false;
            if (response == "<!-- ERRORE_CODICE_ANTISPAM -->") roar_msg(""+imgError+""+txtErroreCodiceAntispam+"", 0);
            else if (response == "<!-- ERRORE -->") roar_msg(""+imgError+""+txtErroreGenerico+"", 0);
            else if (response == "<!-- SUCCESSO -->") {
                roar_msg(""+imgSuccess+""+txtSuccessoInvioMessaggio+"", 0);
                $('contacts_button').set('disabled',true);
                for (var i=0; i<form.elements.length; i++) form.elements[i].disabled=true;
            }
        }});
    });
}

function get_description(page, id) {
    var request = new Request({
    	url: 'ajax.php?actions=Get_Description&page='+page+'&id='+id+'',
    	method: 'post',
        evalScripts: true,
        onRequest: function() {
            var h = $('description').getStyle('height').toInt()+10;
    		$('description').set('html','<div style="height: '+h+'px;"><img src="images/load.gif" alt="Loading..." title="Loading..." /></div>');
        },
    	onComplete: function(response) {
    		$('description').set('html', response);
    	}
    }).send();
}

function add_cart_form(id, load) {
    window.addEvent('domready', function(){
    var output = $('cart_output');
    var works_output = $('Output_'+id);
    var forms = document.getElementById("Add_Cart_"+id);
    new FormCheck('Add_Cart_'+id, {
        display : {
			closeTipsButton : 0,
			flashTips : 1,
            scrollToFirst : true
        },
        submitByAjax : true,
        onAjaxRequest: function() {
            $('Button_'+id).set('disabled',true);
            for (var i=0; i<forms.elements.length; i++) forms.elements[i].readOnly=true;
            if (load) works_output.set('html', '<img src="images/black_small_load.gif" alt="Loading..." title="Loading..." />');
            else works_output.set('html', '<img src="images/gray_small_load.gif" alt="Loading..." title="Loading..." />');
        },
        onAjaxSuccess: function(response) {
            works_output.set('html', '');
            $('Button_'+id).set('disabled',false);
            for (var i=0; i<forms.elements.length; i++) forms.elements[i].readOnly=false;
            var responseArray = response.split("<!-- SPLIT -->");
            if (response == "<!-- ERRORE_GENERICO -->") roar_msg(""+imgError+""+txtErroreGenerico+"", 0);
            if (responseArray[0] == "<!-- ERRORE_DISPONIBILITA -->") {
                for (var i=0; i<forms.elements.length; i++) forms.elements[i].disabled=true;
                if ($('Edit_'+id)) {
                    works_output.set('html', responseArray[1]);
                   	$('Edit_'+id).set('html', responseArray[2]);
                }
                roar_msg(""+imgError+""+txtErroreDisponibilita+"", 0);
            }
            else if (responseArray[0] == "<!-- AGGIUNTO -->") {
                roar_msg(""+imgSuccess+""+txtCarrelloAggiunto+"", 0);
                output.set('html', responseArray[1]);
            } else if (responseArray[0] == "<!-- EDIT -->") {
                for (var i=0; i<forms.elements.length; i++) forms.elements[i].disabled=true;
                roar_msg(""+imgSuccess+""+txtCarrelloModificato+"", 0);
                output.set('html', responseArray[1]);
                $('total_price').set('html','&euro; '+responseArray[2]);
                works_output.set('html',responseArray[3]);
               	$('Edit_'+id).set('html',responseArray[4]);
            }
        }});
    });
}

function del_cart(id) {
    var request = new Request({
    	url: 'ajax.php?actions=Del_Cart&id='+id+'',
    	method: 'post',
        onRequest: function() {
    		$('del_cart_'+id).set('html','<img src="images/load.gif" style="margin-top: 34px;" alt="Loading..." title="Loading..." />');
        },
    	onComplete: function(response) {
            roar_msg(""+imgSuccess+""+txtCarrelloRimosso+"", 0);
            var slide = new Fx.Slide('del_cart_'+id, {mode: 'vertical'});
            slide.toggle();
      		$('del_cart_'+id).set('html','');
            var responseArray = response.split("<!-- SPLIT -->");
            if (responseArray[0] != "0.00")
          		$('total_price').set('html','&euro; '+responseArray[0]);
            else {
          		$('cart').set('html',responseArray[2]);
            }
      		$('cart_output').set('html',responseArray[1]);
    	}
    }).send();
}

function set_search() {
    window.addEvent('domready', function() {
        new DatePicker('.date_search_1', {
            pickerClass: 'datepicker_dashboard',
        	days: [txtSunday, txtMonday, txtTuesday, txtWensday, txtThursday, txtFriday, txtSaturday],
        	months: [txtJanuary, txtFebruary, txtMarch, txtApril, txtMay, txtJune, txtJuly, txtAugust, txtSeptember, txtOctober, txtNovember, txtDecember],
       		allowEmpty: true,
      		toggleElements: '.date_a',
            format: 'd F Y',
            inputOutputFormat: 'Y-m-d'
      	});
        new DatePicker('.date_search_2', {
     		pickerClass: 'datepicker_dashboard',
        	days: [txtSunday, txtMonday, txtTuesday, txtWensday, txtThursday, txtFriday, txtSaturday],
        	months: [txtJanuary, txtFebruary, txtMarch, txtApril, txtMay, txtJune, txtJuly, txtAugust, txtSeptember, txtOctober, txtNovember, txtDecember],
       		allowEmpty: true,
       		toggleElements: '.date_b',
            format: 'd F Y',
            inputOutputFormat: 'Y-m-d'
      	});
    });
}

function set_observer() {
    document.addEvent('domready', function() {
    	var inputWord = $('key');
        var indicator = document.getElementById('indicator');
    	new Autocompleter.Request.JSON(inputWord, 'ajax.php?actions=Get_Search', {
            'postVar': 'key',
    		'indicator': indicator,
    		'width': 250,
		    'forceSelect': false,
    		'cache': false,
    		'minLength': 3
    	});
    });
}

function check_privacy(id, reference) {
    if (id == "true")
        document.getElementById(reference).disabled=false;
    else
        document.getElementById(reference).disabled=true;
}

function check_form(id) {
    document.getElementById("Qty_"+id).disabled=false;
   	$('Edit_Button_'+id).set('html','<input type="image" src="images/'+txtCartella+'/gme_ok.png" class="img_button" id="Button_'+id+'" alt="'+txtConferma+'" title="'+txtConferma+'" />');
}

function request_confirm(text, form) {
    box.confirm(text, {
        textBoxBtnOk: txtConferma,
        textBoxBtnCancel: txtAnnulla,
        onComplete: function(returnvalue) {
            if (returnvalue) form.submit();
        }
    });
}

function check_avaibility(form) {
    var request = new Request({
      	url: 'ajax.php?actions=Check_Avaibility',
       	method: 'post',
        onRequest: function() {
            $('td_1').setStyle('background','#58585A');
            $('td_2').setStyle('background','#58585A');
      		$('Check_Avaibility').set('html','<img src="images/gray_small_load.gif" alt="Loading..." title="Loading..." /><span style="font-family: verdana; font-size: 10px; margin-left: 10px;"><b>'+txtVerificaDisponibilita+'</b></span>');
        },
      	onComplete: function(response) {
            if (response == "<!-- OK -->") {
                $('td_1').setStyle('background','#00B600');
                $('td_2').setStyle('background','#00B600');
          		$('Check_Avaibility').set('html','<img src="images/gme_right.png" alt="" title="" /><span style="font-family: verdana; font-size: 10px; margin-left: 10px;"><b>'+txtVerificaDisponibilitaCompletata+'</b></span>');
                request_confirm(txtConfermaTesto, form);
                return false;
            } else {
                $('td_1').setStyle('background','#FF0000');
                $('td_2').setStyle('background','#FF0000');
        		$('Check_Avaibility').set('html','<img src="images/gme_wrong.png" alt="" title="" /><span style="font-family: verdana; font-size: 10px; margin-left: 10px;"><b>'+txtErroreVerificaDisponibilita+'</b></span>');
                var responseArray = response.split("<!-- SPLIT -->");
                for (var i=0; i<responseArray.length; i++) {
                    var newArray = responseArray[i].split("#");
                    $('notes').set('html',txtNoteDisponibilita);
                    $('Product_'+newArray[0]).set('html','<div style="text-align: center; font-size: 12px; font-weight: bold; margin-bottom: 13px; padding-top: 2px; background: url(images/gme_bullet.png) top center no-repeat; height: 21px;">'+newArray[1]+'</div>'+txtDisp+': '+newArray[2]+'');
                }
                return false;
            }
        }
    }).send();
}

function check_shippay(form) {
    if (form.pay_type.value == "" || form.ship_type.value == "") {
        roar_msg(""+imgError+""+txtErroreSelezione+"", 0);
        return false;
    } else {
        check_avaibility(form);
        return false;
    }
}

function set_notes(code) {
    var request = new Request({
    	url: 'ajax.php?actions=Set_Notes&code='+code+'',
    	method: 'post',
        onRequest: function() {
    		$('notes').set('html','<img src="images/black_small_load.gif" alt="Loading..." title="Loading..." />');
        },
    	onComplete: function(response) {
    		$('notes').set('html',response);
    	}
    }).send();
}

function update_shipping(id, price) {
    var request = new Request({
    	url: 'ajax.php?actions=Update_Shipping&id='+id+'&price='+price+'',
    	method: 'post',
        onRequest: function() {
    		$('ship').set('html','<img src="images/black_small_load.gif" alt="Loading..." title="Loading..." />');
        },
    	onComplete: function(response) {
            var responseArray = response.split("<!-- SPLIT -->");
    		$('ship').set('html', responseArray[0]);
    		$('total_price').set('html','&euro; '+responseArray[1]);
    	}
    }).send();
}

function update_payment(id, price) {
    var request = new Request({
    	url: 'ajax.php?actions=Update_Payment&id='+id+'&price='+price+'',
    	method: 'post',
        onRequest: function() {
    		$('pay').set('html','<img src="images/black_small_load.gif" alt="Loading..." title="Loading..." />');
        },
    	onComplete: function(response) {
            var responseArray = response.split("<!-- SPLIT -->");
    		$('pay').set('html', responseArray[0]);
    		$('total_price').set('html','&euro; '+responseArray[1]);
    	}
    }).send();
    set_notes(id);
}

function set_notify(id) {
    var request = new Request({
    	url: 'ajax.php?actions=Set_Notify&id='+id+'',
    	method: 'post',
        onRequest: function() {
    		$('notify_output_'+id).set('html','<img src="images/load.gif" alt="Loading..." title="Loading..." />');
        },
    	onComplete: function(response) {
    		$('notify_output_'+id).set('html',response);
    	}
    }).send();
}

function order_cancel(id, color) {
    box.confirm(txtSeiSicuro, {
        textBoxBtnOk: txtConferma,
        textBoxBtnCancel: txtAnnulla,
        onComplete: function(returnvalue) {
            if (returnvalue) {
    var request = new Request({
    	url: 'ajax.php?actions=Order_Cancel&id='+id+'',
    	method: 'post',
        onRequest: function() {
    		$('button_output_'+id).set('html','<img src="images/'+color+'_small_load.gif" alt="Loading..." title="Loading..." />');
        },
    	onComplete: function(response) {
    		$('button_output_'+id).set('html','<img src="images/gme_button_x_off.png" alt="'+txtAnnullato+'" title="'+txtAnnullato+'" />');
    		if ($('paypal_'+id)) $('paypal_'+id).set('disabled', true);
    		$('status_output_'+id).set('html', response);
    	}
    }).send();

            }
        }
    });
}

function update_total_price(product_slide, product_status, product_toggle, type, value, total_price) {
    var request = new Request({
    	url: 'ajax.php?actions=Update_Total_Price&type='+type+'&value='+value+'&total_price='+total_price+'',
    	method: 'post',
        onRequest: function() {
            if (product_status[product_slide.open] == "open") product_slide.toggle();
    		$('free_product').set('html','');
    		$('total_price').set('html','<img src="images/gray_small_load.gif" alt="Loading..." title="Loading..." />');
        },
    	onComplete: function(response) {
    		$('total_price').set('html','&euro; '+response);
    	}
    }).send();
}

function update_product_free(product_slide, product_status, product_toggle, id, total_price) {
    var request = new Request({
    	url: 'ajax.php?actions=Update_Product_Free&id='+id+'',
    	method: 'post',
        onRequest: function() {
            if (product_status[product_slide.open] == "close") product_slide.toggle();
    		$('free_product').set('html','<img src="images/load.gif" style="margin-top: 30px;" alt="Loading..." title="Loading..." />');
    		$('total_price').set('html','<img src="images/gray_small_load.gif" alt="Loading..." title="Loading..." />');
        },
    	onComplete: function(response) {
    		$('free_product').set('html', response);
            var gme_shipping = parseFloat(getCookie('gme_shipping'));
            if (!gme_shipping) gme_shipping = "0.00";
            var gme_payment = parseFloat(getCookie('gme_payment'));
            if (!gme_payment) gme_payment = "0.00";
            var new_price = parseFloat(total_price)+parseFloat(gme_shipping)+parseFloat(gme_payment);
            new_price = parseFloat(new_price).toFixed(2);
    		$('total_price').set('html','&euro; '+new_price);
            window.addEvent('domready', function() {
            	var initMultiBox = new multiBox({
            		mbClass: '.free_product',
               		contentColor: '#000',
            		container: $(document.body),
            		descClassName: 'multiBoxDesc',
            		path: './files/',
            		useOverlay: true,
            		addDownload: false,
            		pathToDownloadScript: '',
            		addRollover: true,
            		addOverlayIcon: false,
            		addChain: false,
            		recalcTop: false,
            		addTips: false
            	});
            });
    	}
    }).send();
}

function get_fidelity(product_slide, product_status, product_toggle, page, total_price) {
    var request = new Request({
    	url: 'ajax.php?actions=Get_Fidelity&page='+page+'&total_price='+total_price+'',
    	method: 'post',
        evalScripts: true,
        onRequest: function() {
            if (product_status[product_slide.open] == "open") product_slide.toggle();
    		$('free_product').set('html','');
    		$('total_price').set('html','<img src="images/gray_small_load.gif" alt="Loading..." title="Loading..." />');
    		$('fidelity').set('html','<img src="images/load.gif" alt="Loading..." title="Loading..." />');
        },
    	onComplete: function(response) {
    		$('free_product').set('html', '');
            var gme_shipping = parseFloat(getCookie('gme_shipping'));
            if (!gme_shipping) gme_shipping = "0.00";
            var gme_payment = parseFloat(getCookie('gme_payment'));
            if (!gme_payment) gme_payment = "0.00";
            var new_price = parseFloat(total_price)+parseFloat(gme_shipping)+parseFloat(gme_payment);
            new_price = parseFloat(new_price).toFixed(2);
    		$('total_price').set('html','&euro; '+new_price);
    		$('fidelity').set('html', response);
            window.addEvent('domready', function() {
            	var initMultiBox = new multiBox({
            		mbClass: '.list_free',
               		contentColor: '#000',
            		container: $(document.body),
            		descClassName: 'multiBoxDesc',
            		path: './files/',
            		useOverlay: true,
            		addDownload: false,
            		pathToDownloadScript: '',
            		addRollover: true,
            		addOverlayIcon: false,
            		addChain: false,
            		recalcTop: false,
            		addTips: false
            	});
        	});
    	}
    }).send();
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
  	    begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function disable_autocomplete(form){
    document.getElementById(form).setAttribute('autocomplete', 'off');
}

function uppercase(text){
	var phrase = text.toUpperCase();
	return phrase;
}

function lowercase(text){
	var phrase = text.toLowerCase();
	return phrase;
}

function disable_allbox(form) {
	for (var i=0;i<document.getElementById(form).elements.length;i++) {
    	var e = document.getElementById(form).elements[i];
	    if (e.type == 'checkbox')
	    	e.disabled=true;
	}
}

function enable_allbox(form) {
	for (var i=0;i<document.getElementById(form).elements.length;i++) {
    	var e = document.getElementById(form).elements[i];
	    if (e.type == 'checkbox')
	    	e.disabled=false;
	}
}

function uncheck_only_allbox(form){
    document.getElementById(form).allbox.checked=false;
}

function check_all(form) {
	for (var i=0;i<document.getElementById(form).elements.length;i++) {
    	var e = document.getElementById(form).elements[i];
	    if ((e.name != 'allbox') && (e.type == 'checkbox'))
	    	e.checked = document.getElementById(form).allbox.checked;
	}
}

function uncheck_all(form) {
	var TotalBoxes = 0;
	var TotalOn = 0;
	for (var i=0;i<document.getElementById(form).elements.length;i++) {
	    var e = document.getElementById(form).elements[i];
	    if ((e.name != 'allbox') && (e.type=='checkbox')) {
			TotalBoxes++; if (e.checked) TotalOn++;
		}
	}
	if (TotalBoxes == TotalOn) {
		document.getElementById(form).allbox.checked=true;
	} else {
		document.getElementById(form).allbox.checked=false;
	}
}

function cloacking(who, domain, view) {
    email = who + '@' + domain;
    if (view != "")
        output = '<a href="mailto:'+email+'"><span style="font-size: 10px;">'+view+'</span></a>';
    else
        output = '<a href="mailto:'+email+'"><span style="font-size: 10px;">'+email+'</span></a>';
    document.write(output);
}

function images_preload() {
    var immagini=new Array()
    for (cont=0;cont<images_preload.arguments.length;cont++) {
        immagini[cont]=new Image()
        immagini[cont].src=images_preload.arguments[cont]
    }
}
images_preload ("images/load.gif", "images/tl.png", "images/t.png", "images/tr.png", "images/l.png", "images/r.png", "images/bullet.png",
                "images/bl.png", "images/b.png", "images/br.png", "images/c.png", "images/close.png", "images/black_small_load.gif", "images/gray_small_load.gif",
                "images/"+txtCartella+"/gme_ok.png", "images/gme_right.png", "images/gme_wrong.png", "images/cl/frame.png", "images/cl/buttons.png");

function addBookmark(title, url) {
    if (window.sidebar && window.sidebar.addPanel) {
        if (navigator.userAgent.lastIndexOf("Netscape") != -1) {
            document.write('<a href="javascript:window.sidebar.addPanel(\''+title+'\', \''+url+'\', \'\');">'+txtAggiungiAiPreferiti+'</a>');
        } else {
            document.write('<a href="javascript:window.sidebar.addPanel(\''+title+'\', \''+url+'\', \'\');">'+txtAggiungiAiPreferiti+'</a>');
        }
    } else if (window.opera && window.print) {
        document.write('<a href="'+url+'" rel="sidebar" title="'+title+'">'+txtAggiungiAiPreferiti+'</a>');
    } else if (navigator.userAgent.lastIndexOf("WebKit") != -1) {
     	document.write('<a href="javascript:alert(\''+txtCtrlD+'\');">'+txtAggiungiAiPreferiti+'</a>' );
    } else if (window.external && ( navigator.platform == 'Win32' || ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1))) {
    	document.write('<a href="javascript:window.external.AddFavorite(\''+url+'\', \''+title+'\');">'+txtAggiungiAiPreferiti+'</a>' );
    }
}

function setHomePage(url) {
    if (window.sidebar) {
        if(window.netscape) {
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        } catch(e) {
            alert(''+txtWarningAboutConfig+'');
        }
    }
    var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
    prefs.setCharPref('browser.startup.homepage',''+url+'');
 }
}

function setHome(url) {
    if (window.sidebar && window.sidebar.addPanel) {
        if (navigator.userAgent.lastIndexOf("Netscape") != -1) {
            document.write('<a href="javascript:setHomePage(\''+url+'\');">'+txtPaginaIniziale+'</a>');
        } else {
            document.write('<a href="javascript:setHomePage(\''+url+'\');">'+txtPaginaIniziale+'</a>');
        }
    } else if (window.opera && window.print) {
        document.write('<span style="text-decoration: line-through;">'+txtPaginaIniziale+'</span>');
    } else if (navigator.userAgent.lastIndexOf("WebKit") != -1) {
        document.write('<span style="text-decoration: line-through;">'+txtPaginaIniziale+'</span>');
    } else if (window.external && ( navigator.platform == 'Win32' || ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1))) {
        document.write('<a href="javascript:void(0);" onclick="this.style.behavior=\'url(#default#homepage)\'; this.setHomePage(\''+url+'\');">'+txtPaginaIniziale+'</a>');
    }
}

function enable_form(what) {
    var type_1 = $('type_1');
    var type_2 = $('type_2');
    var status = {
    	'true': 'open',
    	'false': 'close'
    };
    if (what == "open") {
        var slide_1 = new Fx.Slide('slide_1', {mode: 'vertical'});
        var slide_2 = new Fx.Slide('slide_2', {mode: 'vertical'});
    } else {
        var slide_1 = new Fx.Slide('slide_1', {mode: 'vertical'}).hide();
        var slide_2 = new Fx.Slide('slide_2', {mode: 'vertical'}).hide();
    }
    type_1.addEvent('change', function(e){
    	e.stop();
        if (type_1.checked == true && status[slide_1.open] == "close") {
            slide_1.toggle();
            slide_2.toggle();
            $('company').set('disabled',false);
            $('piva').set('disabled',false);
        }
    });
    type_2.addEvent('change', function(e){
    	e.stop();
        if (type_1.checked == false && status[slide_1.open] == "open") {
            slide_1.toggle();
            slide_2.toggle();
            $('company').set('disabled',true);
            $('piva').set('disabled',true);
        }
    });
}

function init_maps() {
    var latlng = new google.maps.LatLng(39.337567,16.241879);
    var myOptions = {
        zoom: 16,
        center: latlng,
        disableDefaultUI: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    var contentString = "<span style=\"color: #000;\"><b>GME Music<br />G.M. Elettronica SRL<\/b><br />"+
                        "Via Don Minzoni, 35/41<br />"+
                        "87036 - Rende (CS)<br />"+
                        "Tel/Fax: 0984/461846<br /><br />"+
                        "http://www.gmemusic.it<br />"+
                        "info@gmemusic.it<\/span>";
    var infowindow = new google.maps.InfoWindow({ content: contentString });
    var marker = new google.maps.Marker({ position: latlng, map: map, title: "GME Music - G.M. Elettronica SRL" });
    google.maps.event.addListener(marker, 'click', function() {
        infowindow.open(map, marker);
    });
}

function fidelity() {
    var toggle = $('toggle');
    var status = {
    	'true': 'open',
    	'false': 'close'
    };
    var slide = new Fx.Slide('fidelity', {mode: 'vertical'}).hide();
    toggle.addEvent('click', function(e){
    	e.stop();
        slide.toggle();
    });
}

function sliders(id) {
    var toggle = $('toggle_'+id);
    var status = {
    	'true': 'open',
    	'false': 'close'
    };
    var slide = new Fx.Slide('details_'+id, {mode: 'vertical'}).hide();
    toggle.addEvent('click', function(e){
    	e.stop();
        if (status[slide.open] == "close") {
            $('image_'+id).set('src','images/gme_close.png');
            $('image_'+id).set('alt','Chiudi');
            $('image_'+id).set('title','Chiudi');
        } else {
            $('image_'+id).set('src','images/gme_open.png');
            $('image_'+id).set('alt','Apri');
            $('image_'+id).set('title','Apri');
        }
        slide.toggle();
    });
}

function init_ticker() {
	var vertical = new Ticker('TickerVertical',{speed:1000,delay:2000,direction:'vertical'});
}

function menu_accordion() {
	var accordion = new Accordion($$('.toggler'),$$('.element'), {
  	    display: -1,
       	opacity: true,
        alwaysHide: true,
        transition: Fx.Transitions.Bounce.easeOut,
		onActive: function(toggler, element) {
        	var bullet = "bullet_"+toggler.get('id');
            $(''+bullet+'').set('html', '<img src="images/bullet.png" alt="" title="" />');
        },
		onBackground: function(toggler, element) {
            var bullet = "bullet_"+toggler.get('id');
            $(''+bullet+'').set('html', '');
            $(toggler.get('id')).addEvent('mouseenter', function(e){
                e.stop();
                $(''+bullet+'').set('html', '<img src="images/bullet.png" alt="" title="" />');
       	    });
            $(toggler.get('id')).addEvent('mouseleave', function(e){
                e.stop();
                if (element.offsetHeight == 0) $(''+bullet+'').set('html', '');
       	    });
        }
    }, $('accordion'));
}

if (document.layers) document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
document.onmouseover=statusText
document.onmouseout=statusText

window.addEvent('domready', function() {
    box = new SexyAlertBox();
    roars = [new Roar(),new Roar({position: 'upperRight'}),new Roar({position: 'lowerLeft'}),new Roar({position: 'lowerRight'})];
	initMultiBox = new multiBox({
		mbClass: '.mb',
   		contentColor: '#000',
		container: $(document.body),
		descClassName: 'multiBoxDesc',
		path: './files/',
		useOverlay: true,
		addDownload: false,
		pathToDownloadScript: '',
		addRollover: true,
		addOverlayIcon: false,
		addChain: false,
		recalcTop: false,
		addTips: false
	});
    document.body.style.overflowX="hidden";
    document.body.style.overflowY="auto";
    $(document.body).setStyle('-moz-user-select','none');
    $(document.body).setStyle('-khtml-user-select','none');
    $$('fieldset').setStyle('-moz-border-radius','5px');
    $$('fieldset').setStyle('-webkit-border-radius','5px');
});

Event.Keys.f5 = 116;
window.addEvent('keydown', function(event){
    rapid_box = new SexyAlertBox();
    if (event.key == "f5") {
        rapid_box.alert(txtNoPressF5);
        return false;
    }
});
