﻿window.addEvent('domready', function() {
    $$('img.button', 'input.button').each(function(oEl) {
        oEl.addEvents({
            'mouseover': function(){
                this.src = this.src.replace('.gif','_over.gif');
            },
            'mouseout': function(){
                this.src = this.src.replace('_over.gif','.gif');
            }        
        });
    });
    $$('img.hover').each(function(oEl) {
        oEl.addEvents({
            'mouseover': function(){
                this.src = this.src.replace('.jpg','_over.jpg');
                this.src = this.src.replace('.gif','_over.gif');
            },
            'mouseout': function(){
                this.src = this.src.replace('_over.jpg','.jpg');
                this.src = this.src.replace('_over.gif','.gif');
            }        
        });
    });    
});

function RequestDownload() 
{
    var jsonRequest = new Request.JSON({url: "/EVENT/RequestTrial.aspx", onComplete: 
        function(result){
            if (result.status=="success") {
                window.location.href="/trial-version.htm?d=" + result.serial;
            } else {
                if (result.message.length>0) 
                {
                    alert(result.message);
                } 
                else 
                {
                    alert("Sorry there was an error while trying to send you the free trial. Please try again.");
                }
                
            }
        }
    }).get({'e': $('email_Address').value  });
}

function ChooseItem(p) {
    if( $('backup-cdrom').getProperty('checked') ) {
        AddItem($('backup-cdrom').value);
    } else {
        AddItem(p)
    }
}
function AddItem(p){
    InitializeCart();
        
    var jsonRequest = new Request.JSON({url: "/EVENT/AddToBasket.aspx", onComplete: 
        function(result){
            if (result.status=="success") {
                var suffix = result.count == 1 ? '' : 's';
                $('popUpCartH3').set('html', '<strong>Thank you</strong>The ' + result.name + ' has been added to your shopping cart.');
                $('popUpCartP').set('html', 'Shopping Cart Subtotal = ' + result.subtotal);
                $('popUpCart').fade('in');
                
                if(pageTracker!=null) {pageTracker._trackPageview("Add-To-Cart-"+p );}
                
            } else {
                if (result.message.length>0) 
                {
                    alert(result.message);
                } 
                else 
                {
                    alert("Sorry there was a problem adding the product to your shopping cart");
                }
                
            }
        }
    }).get({'p':p , 'q':1 });
}

function confirmRemove() {
    var oConfirm = window.confirm("Are you sure you want to remove this item from your shopping cart?");
    if (oConfirm) { return true;}
    else {return false;}
}

function InitializeCart() {
    if (!$defined($('popUpCart'))) 
    {
        //Create HTML Elements
		cartbox = new Element('div', {
			'id': 'popUpCart',
			'styles': {
				'top': 1,
				'left': 1
			}
		});
		
		new Element('h3',{'id':'popUpCartH3'}).set('html','<strong>Thank you</strong>').inject(cartbox,'inside');
		
		new Element('p',{'id':'popUpCartP'}).inject(cartbox, 'inside');

		//Continue Shopping
		var oA1 = new Element('a').addEvent('click', function() {$('popUpCart').fade('out');}).inject(cartbox, 'inside');
		var oB1 = new Element('img', {
		    'src':'/IMAGES/button/continueshopping.gif',
		    'class':'button left',
		    'alt':'Continue Shopping'}).inject(oA1, 'inside');		
		
		
		//Proceed to Checkout
		var oA2 = new Element('a',{'href':'/Shopping-Cart.aspx'}).inject(cartbox, 'inside');
		var oB2 = new Element('img', {
		    'src':'/IMAGES/button/proceedtocheckout.gif',
		    'class':'button right',
		    'alt':'Proceed to Checkout'}).inject(oA2, 'inside');
		
		
		$(cartbox).inject(document.body, 'inside')
		$(cartbox).fade('hide');
    }
    
   
    y = $(window).getScroll().y + (($(window).getSize().y/2) - ($('popUpCart').getSize().y/2));
    x = $(window).getScroll().x + (($(window).getSize().x/2) - ($('popUpCart').getSize().x/2));
    $('popUpCart').setStyles({
        'top': y,
        'left': x
    });
    
}
