

var keyCode;
document.onkeydown = keyDown;
function keyDown(e) {
    if (e) { keyCode = e.which; } else { keyCode = event.keyCode; }
}

//var slide_left=0;
//var slide_width=0;
/*Initializes the page effects - specifically the slider*/
function initPage(id){
	/*var header_coords=$('header').getCoordinates();
	if(id){
	    var el_coords=$('plat_'+id).getCoordinates();
	    $('slider').style.marginLeft=el_coords.left-header_coords.left+"px";
	    $('slider').style.width=(el_coords.width-1)+"px";
	    slide_left=el_coords.left-header_coords.left;
	    slide_width=el_coords.width-1;
	}
	var tabs = $$('.tab');
	var fx = new Fx.Styles('slider', {duration:600, wait:false, transition: Fx.Transitions.Quart.easeOut});
	tabs.each(function(element) {
		var coords=element.getCoordinates();				
		element.addEvent('mouseenter', function(){
			fx.stop()
			fx.start({
				'margin-left': coords.left-header_coords.left,
				'width':coords.width-1
			});
		});			 
		element.addEvent('mouseleave', function(){
			fx.stop();
			fx.start({
				'margin-left': slide_left,
				'width':slide_width
			});
		});
	 
	});	*/
}

/*Submits the input form*/
function go(frm){
    $(frm).submit();
}
/*Submits the input form*/
function pay(frm){
    $(frm).send({
        method: 'post',
        onComplete:function(){
            var x=this.transport.responseText;
            if(x.indexOf("Success")!=-1){
                var resp=x.split(":");
                window.location="thankyou.aspx?orderid="+resp[1]+"&orderkey="+resp[2];
                emailReceipt(resp[1],resp[2])
            }else{
                alert(x);
            }
            $('info').style.visibility="hidden";
        },
        onError:function(){
            var x=this.transport.responseText;
            alert("An Error Occured: "+x);
            $('info').style.visibility="hidden";
        },
        onFailure:function(){
            var x=this.transport.responseText;
            alert("A Failure Occured: "+x);
            $('info').style.visibility="hidden";
        }
    });
}
/*Populates the shipping fields from the billing fields*/
function sameShipping(){
    if($('same_shipping').checked==true){
        $('ship_fname').value=$('bill_fname').value;
        $('ship_lname').value=$('bill_lname').value;
        $('ship_address1').value=$('bill_address1').value;
        $('ship_address2').value=$('bill_address2').value;
        $('ship_city').value=$('bill_city').value;
        $('ship_state').value=$('bill_state').value;
        $('ship_zip').value=$('bill_zip').value;
        $('ship_phone').value=$('bill_phone').value;
    }
}
/*Hides the generic 'Info' box*/
function closeInfo(){
    $('info').style.visibility="hidden"
}
/*Returns the products ordered - edit_account.aspx*/
function showProducts(orderid,orderkey){
    $('info').style.visibility="hidden";
    var temp=$('order_'+orderid).getCoordinates();
    $('info').style.top=(temp.top+22)+"px";
    $('info').style.left=(temp.left)+"px";
    new Ajax('aspxf/order_products.aspx?orderid='+orderid+'&orderkey='+orderkey+'&random='+$random(0,99999), {
		method: 'get',
		update: 'info_content',
		onComplete: function(){
		    $('info').style.visibility="visible";
		}
	}).request();
}
/*Opts the email in to the newsletter */
function optIn(){
    var email=$('news_email').value;
    new Ajax('aspxf/opt_in.aspx?news_email='+email, {
		method: 'post',
		onComplete: function(){
		    alert("Your email has been submitted.  Thank you.");
		    $('news_email').value="";
		},
		onError: function(){
		    alert("Unable to save this email address.");
		}
	}).request();
}
/*Email the reciept to the order email address */
function emailReceipt(orderid,orderkey){
    new Ajax('aspxf/email_receipt.aspx?orderid='+orderid+'&orderkey='+orderkey, {
		method: 'get',
		onComplete: function(){
		    var resp=this.transport.responseText;
		    if(trim(resp)!="success"){
		        //alert(resp);
		    }
		},
		onError: function(){
		    //alert("An error occured while attempting to send the email.");
		}
	}).request();
}