
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'  && inputs[i].className.indexOf("styled") == -1) {
            //create a new image
            var img = document.createElement('img');

            //check if the checkbox is checked
            if(inputs[i].checked) {
                img.src = imgTrue;
            } else {
                img.src = imgFalse;
            }

            //set image ID and onclick action
            img.id = 'checkImage'+i;
            //set image
            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';
        }
		// check if imout type is radio
		if(inputs[i].getAttribute('type') == 'radio' && inputs[i].className.indexOf("styled") == -1 && inputs[i].className.indexOf("radiopayment") == -1 ) {
            //create a new image
            var img = document.createElement('img');

            //check if the radio is checked
            if(inputs[i].checked) {
                img.src = imgRadioTrue;
            } else {
                img.src = imgRadioFalse;
            }
            //set image ID and onclick action
            img.id = 'radioImage'+i;
            
            //set image
            img.onclick = new Function('radioChange('+i+')');
            //place image in front of the radio button
            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;
    } else {
		inputs[i].checked = 'checked';
		var fillbilling = new Shipping('co-shipping-form');
		fillbilling.syncWithBilling();
        document.getElementById('checkImage'+i).src=imgTrue;
    }
}

//change the radio status and the replacement image
function radioChange(i) {
    // radio buttons
    var arrRadios = new Array();
    
    // take all input types
    inputs = document.getElementsByTagName('input');

    for(var j=0; j < inputs.length; j++) {
	    // only radios
		if(inputs[j].getAttribute('type') == 'radio' && inputs[j].className.indexOf("styled") == -1 ) {
	    	// Id
		    var itemId = 'radioImage'+j;
	            arrRadios.push(itemId);
		}
    }
    
    var url;
    url = document.getElementById('url').value;
    
    if(!inputs[i].checked) {
		inputs[i].checked = 'checked';
	        var selectedId = 'radioImage'+i;
		for(var k=0; k < arrRadios.length; k++) {
	            if(arrRadios[k] != selectedId){
	               document.getElementById(arrRadios[k]).src=imgRadioFalse;
		    }else{
		       document.getElementById('radioImage'+i).src=imgRadioTrue;
		    }
		}
		location.href= url;
    }
}
