﻿
function initCheckout(){
    // Recycle Checkbox
    if($('chkrecycle')){
        $('chkrecycle').onclick = function(){
            updateSession('recycle',this.value,this.checked);
        }
    }
    
    // Payment Fields
	if($("paymentmethod")){
		$("paymentmethod").onchange = function(){
		    doCall();
		};
	}
	
	// Confirm form submit
	if($('frmConfirm')){
	   	$('frmConfirm').onsubmit = function(){
			/*
			var allLinks = document.getElementsByTagName("a");
			for(var i = 0; i < allLinks.length; i++){
				allLinks[i].onclick = function(){return false;}	
			}
		   	var spanCreate = document.createElement("span");
			spanCreate.id = "paymentLoading";
			createLoadingImage = document.createElement("img");
			createLoadingImage.setAttribute("src", "/images/dyBox/loading.gif");
			createLoadingImage.setAttribute("id", "paymentLoading_Image");
			spanCreate.appendChild(createLoadingImage);
			$("content").appendChild(spanCreate);
			*/
			SubmitOnce();
			
			
	   }
}
    try {
        $('taxCloseBtn').onclick = function() {
            $('taxFail').fade({duration:0.3});
            return (false);
        }
    }
    catch (err) { }
	
 	// Basket updated messaging
	checkUpdate();
   
}

function checkUpdate() {
	// Set the position of the Update Div
    var win = window.windowDimensions()
    // var scrollValue = window.scrollOffset();
		  
    
	if($("updated")) { 
	    //alert((parseInt(win[0])-970)/2+150+"px")
	   //$('updated').style.left = "200px" //parseInt((parseInt(win[0])-970)/2+150)+"px"
        $("updated").removeClassName("hidden")
	    window.setTimeout('fadeItOut("updated")',2000);
	}
}

function fadeItOut(ele) { 
    if($(ele)) new Effect.Fade($("updated"),{duration:0.2});
}

function doCall() {
	var data = "paymentmethod=" + $("paymentmethod").value;
	var ajaxResults = new Ajax.Updater ("payment", "paymentfields_ajax.asp", {parameters: data, onComplete: focusCursor});
}
function focusCursor() {
	if($("paymentMethodErr")) $("paymentMethodErr").hide();
	if($("ccno")) $("ccno").focus();
}

document.observe("dom:loaded",function() {initCheckout();});