/*
	CHECKBOX.JS
	Displays a cart symbol in place of every checkbox on the page.
	
	-------------------------------------------------------------------------------------
	Used with permission of the author and modified by Website Expressions Pty Ltd (2005)
	-------------------------------------------------------------------------------------
	
	ABN:	  87 108 587 131
	Internet: www.websiteexpressions.com
	Email:	  mail@websiteexpressions.com
	Phone:	  +61 2 4948 1555
	Fax:	  +61 2 4948 1666

	Version 1.0		Used with permission http://brainerror.net/scripts_js_checkbox2.php,
	29/06/2005		i.e. "... can be copied, used and altered as you please." 
					
*/	


//global variables that can be used by ALL the functions on this page. 
var inputs; 
var imgFalse = './special/cart_no.gif'; 
var imgTrue = './special/cart_yes.gif'; 

//this function runs when the page is loaded, put all your other onload stuff in here too. 
function init() { 
    replaceChecks(); 
} 

function replaceChecks() { 
     
    //get all the input fields on the page 
    inputs = document.getElementsByTagName('input'); 

    //cycle trough the input fields 
    for(var i=0; i < inputs.length; i++) { 

        //check if the input is a checkbox 
        if(inputs[i].getAttribute('type') == 'checkbox') { 
             
            //create a new image 
            var img = document.createElement('img'); 
             img.style.cursor = "hand";

            //check if the checkbox is checked 
            if(inputs[i].checked) { 
                img.src = imgTrue; 
                img.alt = 'Item is in the cart'
            } else { 
                img.src = imgFalse; 
                img.alt = 'Click to add item to the cart'
            } 

            //set image ID and onclick action 
            img.id = 'checkImage'+i; 
            
            //set image 
	if (!(inputs[i].disabled)) {		
            
            img.onclick = new Function('checkChange('+i+')'); }
            //place image in front of the checkbox 
            inputs[i].parentNode.insertBefore(img, inputs[i]); 
             
            //hide the checkbox 
            inputs[i].style.display='none'; 
        } 
    } 
} 

//change the checkbox status and the replacement image 
function checkChange(i) { 

    if(inputs[i].checked) { 
        inputs[i].checked = ''; 
        document.getElementById('checkImage'+i).src=imgFalse; 
        document.getElementById('checkImage'+i).alt = 'Click to add item to the cart'; 
    } else { 
        inputs[i].checked = 'checked'; 
        document.getElementById('checkImage'+i).src=imgTrue; 
        document.getElementById('checkImage'+i).alt = 'Item is in the cart'; 
    } 
} 

window.onload = init;
