//global variables that can be used by ALL the function son this page.
var inputs;
var imgFalse = '/false.png';
var imgTrue = '/true.png';

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

function replaceChecks() {
	

	//get all the input fields on the page
	inputs = document.searchform.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');
			
			//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';
		}
	}
}

//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';
		document.getElementById('checkImage'+i).src=imgTrue;
	}

	updateOffers();

}




function replaceChecksTariff() {
	

	//get all the input fields on the page
	inputTariffs = document.searchformtariff.getElementsByTagName('input');

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

		//check if the input is a checkbox
		if(inputTariffs [i].getAttribute('type') == 'checkbox') {
			
			//create a new image
			var img = document.createElement('img');
			
			//check if the checkbox is checked
			if(inputTariffs [i].checked) {
				img.src = imgTrue;
			} else {
				img.src = imgFalse;
			}

			//set image ID and onclick action
			img.id = 'checkImageTariff'+i;
			//set image 
			img.onclick = new Function('checkChangeTariff('+i+')');
			//place image in front of the checkbox
			inputTariffs[i].parentNode.insertBefore(img, inputTariffs [i]);
			
			//hide the checkbox
			inputTariffs[i].style.display='none';
		}
	}
}

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

	if(inputTariffs[i].checked) {
		inputTariffs [i].checked = '';
		document.getElementById('checkImageTariff'+i).src=imgFalse;
	} else {
		inputTariffs[i].checked = 'checked';
		document.getElementById('checkImageTariff'+i).src=imgTrue;
	}

	updateTariffs();

}

function replaceBroadbandChecks() {
	
	//get all the input fields on the page
	inputBroadbands = document.searchformbroadband.getElementsByTagName('input');

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

		//check if the input is a checkbox
		if(inputBroadbands[i].getAttribute('type') == 'checkbox') {
			
			//create a new image
			var img = document.createElement('img');
			
			//check if the checkbox is checked
			if(inputBroadbands[i].checked) {
				img.src = imgTrue;
			} else {
				img.src = imgFalse;
			}

			//set image ID and onclick action
			img.id = 'checkImageBroadband'+i;
			//set image 
			img.onclick = new Function('checkBroadbandChange('+i+')');
			//place image in front of the checkbox
			inputBroadbands[i].parentNode.insertBefore(img, inputBroadbands[i]);
			
			//hide the checkbox
			inputBroadbands[i].style.display='none';
		}
	}
}

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

	if(inputBroadbands[i].checked) {
		inputBroadbands[i].checked = '';
		document.getElementById('checkImageBroadband'+i).src=imgFalse;
	} else {
		inputBroadbands[i].checked = 'checked';
		document.getElementById('checkImageBroadband'+i).src=imgTrue;
	}
	
	updateMobileBroadbandOffers();
}




function replaceSimCardChecks() {
	
	//get all the input fields on the page
	inputSimCard = document.simcardform.getElementsByTagName('input');

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

		//check if the input is a checkbox
		if(inputSimCard[i].getAttribute('type') == 'checkbox') {
			
			//create a new image
			var img = document.createElement('img');
			
			//check if the checkbox is checked
			if(inputSimCard[i].checked) {
				img.src = imgTrue;
			} else {
				img.src = imgFalse;
			}

			//set image ID and onclick action
			img.id = 'checkImageSimCard'+i;
			//set image 
			img.onclick = new Function('checkSimCardChange('+i+')');
			//place image in front of the checkbox
			inputSimCard[i].parentNode.insertBefore(img, inputSimCard[i]);
			
			//hide the checkbox
			inputSimCard[i].style.display='none';
		}
	}
}

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

	if(inputSimCard[i].checked) {
		inputSimCard[i].checked = '';
		document.getElementById('checkImageSimCard'+i).src=imgFalse;
	} else {
		inputSimCard[i].checked = 'checked';
		document.getElementById('checkImageSimCard'+i).src=imgTrue;
	}
	
	updateSimCardOffers();
}






function replacePAYGChecks() {
	
	//get all the input fields on the page
	inputPAYG = document.paygform.getElementsByTagName('input');

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

		//check if the input is a checkbox
		if(inputPAYG[i].getAttribute('type') == 'checkbox') {
			
			//create a new image
			var img = document.createElement('img');
			
			//check if the checkbox is checked
			if(inputPAYG[i].checked) {
				img.src = imgTrue;
			} else {
				img.src = imgFalse;
			}

			//set image ID and onclick action
			img.id = 'checkImagePAYG'+i;
			//set image 
			img.onclick = new Function('checkPAYGChange('+i+')');
			//place image in front of the checkbox
			inputPAYG[i].parentNode.insertBefore(img, inputPAYG[i]);
			
			//hide the checkbox
			inputPAYG[i].style.display='none';
		}
	}
}

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

	if(inputPAYG[i].checked) {
		inputPAYG[i].checked = '';
		document.getElementById('checkImagePAYG'+i).src=imgFalse;
	} else {
		inputPAYG[i].checked = 'checked';
		document.getElementById('checkImagePAYG'+i).src=imgTrue;
	}
	
	updatePAYGOffers();
}
