

/***********

	Custom Checkbox

	v1.0

	last revision: 03.30.2005

	S.G. Chipman

	slayeroffice.com



	please leave this notice in tact!



	should you modify or improve upon this

	code please let me know so that I can

	update the version hosted at slayeroffice



*************/



/*

window.onload = init;

var d=document;

function init() {

	so_checkCanCreate();

}



function so_checkCanCreate() {

	// make sure the browser has images turned on. If they are, so_createCustomCheckBoxes will

	// fire when this small test image loads. otherwise, the user will get the hard-coded checkboxes

	testImage = d.body.appendChild(d.createElement("img"));

	// MSIE will cache the test image, causing it to not fire the onload event the next time the

	// page is hit. The parameter on the end will prevent this.

	testImage.src = "/_img/blank.gif?" + new Date().valueOf();

	testImage.id = "so_testImage";

	testImage.onload = so_createCustomCheckBoxes;

}





function so_createCustomCheckBoxes() {

	// bail out is this is an older browser

	if(!d.getElementById)return;

	// bail out if this is MacIE

	if(navigator.userAgent.indexOf("Mac")>-1 && d.all) return;

	// remove our test image from the DOM

	d.body.removeChild(d.getElementById("so_testImage"));

	// an array of applicable events that we'll need to carry over to our custom select

	events = new Array("onfocus", "onblur", "onselect", "onchange", "onclick", "ondblclick", "onmousedown", "onmouseup", "onmouseover", "onmousemove", "onmouseout", "onkeypress", "onkeydown", "onkeyup");

	// a reference var to all the forms in the document

	frm = d.getElementsByTagName("form");

	// loop over the length of the forms in the document

	for(i=0;i<frm.length;i++) {

		// reference to the elements of the form

		c = frm[i].elements;

		// loop over the length of those elements

		for(j=0;j<c.length;j++) {

			// if this element is a checkbox, do our thing

			if(c[j].getAttribute("type") == "checkbox") {

				// hide the original checkbox

				//c[j].style.display = "none";

				c[j].style.position = "absolute";

				c[j].style.left = "-9000px";

				// create the replacement image

				n = d.createElement("img");

				n.setAttribute("class","chk");

				// check if the corresponding checkbox is checked or not. set the 

				// status of the image accordingly

				if(c[j].checked == false) {

					n.setAttribute("src","/_img/checkbox_0.png");

					n.setAttribute("title","click here to select this option.");

					n.setAttribute("alt","click here to select this option.");

				} else {

					n.setAttribute("src","/_img/checkbox_1.png");

					n.setAttribute("title","click here to deselect this option.");

					n.setAttribute("alt","click here to deselect this option.");

				}

				// there are several pieces of data we'll need to know later.

				// assign them as attributes of the image we've created

				// first - the name of the corresponding checkbox

				n.xid = c[j].getAttribute("name");

				// next, the index of the FORM element so we'll know which form object to access later

				n.frmIndex = i;

				// assign the onclick event to the image

				n.onclick = function() { so_toggleCheckBox(this,0);return false; }

				// insert the image into the DOM

				c[j].parentNode.insertBefore(n,c[j].nextSibling)

				// this attribute is a bit of a hack - we need to know in the event of a label click (for browsers that support it)

				// which image we need turn on or off. So, we set the image as an attribute!

				c[j].objRef = n;

				// assign the checkbox objects event handlers to its replacement image

				for(e=0;e<events.length;e++) if(eval('c[j].' +events[e])) eval('n.' + events[e] + '= c[j].' + events[e]);

				// append our onchange event handler to any existing ones.

				fn = c[j].onchange;

				if(typeof(fn) == "function") {

					c[j].onchange = function() { fn(); so_toggleCheckBox(this.objRef,1); return false; }

				} else {

					c[j].onchange = function () { so_toggleCheckBox(this.objRef,1); return false; }

				}

			}

		}

	}

}





function so_toggleCheckBox(imgObj,caller) {

	// if caller is 1, this method has been called from the onchange event of the checkbox, which means

	// the user has clicked the label element. Dont change the checked status of the checkbox in this instance

	// or we'll set it to the opposite of what the user wants. caller is 0 if coming from the onclick event of the image

	

	// reference to the form object

	formObj = d.forms[imgObj.frmIndex];

	// the name of the checkbox we're changing

	objName = imgObj.xid;

	/// change the checked status of the checkbox if coming from the onclick of the image

	if(!caller)formObj.elements[objName].checked = !formObj.elements[objName].checked?true:false;

	// finally, update the image to reflect the current state of the checkbox.

	if(imgObj.src.indexOf("/_img/checkbox_1.png")>-1) {

		imgObj.setAttribute("src","/_img/checkbox_0.png");

		imgObj.setAttribute("title","click here to select this option.");

		imgObj.setAttribute("alt","click here to select this option.");

	} else {

		imgObj.setAttribute("src","/_img/checkbox_1.png");

		imgObj.setAttribute("title","click here to deselect this option.");

		imgObj.setAttribute("alt","click here to deselect this option.");

	}

}

*/













/*



CUSTOM FORM ELEMENTS



Created by Ryan Fait

www.ryanfait.com



The only thing you need to change in this file is the following

variables: checkboxHeight, radioHeight and selectWidth.



Replace the first two numbers with the height of the checkbox and

radio button. The actual height of both the checkbox and radio

images should be 4 times the height of these two variables. The

selectWidth value should be the width of your select list image.



You may need to adjust your images a bit if there is a slight

vertical movement during the different stages of the button

activation.



Visit http://ryanfait.com/ for more information.



*/



var checkboxHeight = "18";

var radioHeight = "18";

var selectWidth = "113";



/* No need to change anything after this */



document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; z-index: 5; }</style>');



var Custom = {

	init: function() {

		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;

		for(a = 0; a < inputs.length; a++) {

			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {

				span[a] = document.createElement("span");

				span[a].className = inputs[a].type;



				if(inputs[a].checked == true) {

					if(inputs[a].type == "checkbox") {

						position = "0 -" + (checkboxHeight*2) + "px";

						span[a].style.backgroundPosition = position;

					} else {

						position = "0 -" + (radioHeight*2) + "px";

						span[a].style.backgroundPosition = position;

					}

				}

				inputs[a].parentNode.insertBefore(span[a], inputs[a]);

				inputs[a].onchange = Custom.clear;

				span[a].onmousedown = Custom.pushed;

				span[a].onmouseup = Custom.check;

				document.onmouseup = Custom.clear;

			}

		}

		inputs = document.getElementsByTagName("select");

		for(a = 0; a < inputs.length; a++) {

			if(inputs[a].className == "styled") {

				option = inputs[a].getElementsByTagName("option");

				active = option[0].childNodes[0].nodeValue;

				textnode = document.createTextNode(active);

				for(b = 0; b < option.length; b++) {

					if(option[b].selected == true) {

						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);

					}

				}

				span[a] = document.createElement("span");

				span[a].className = "select";

				span[a].id = "select" + inputs[a].name;

				span[a].appendChild(textnode);

				inputs[a].parentNode.insertBefore(span[a], inputs[a]);

				inputs[a].onchange = Custom.choose;

			}

		}

	},

	pushed: function() {

		element = this.nextSibling;

		if(element.checked == true && element.type == "checkbox") {

			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";

		} else if(element.checked == true && element.type == "radio") {

			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";

		} else if(element.checked != true && element.type == "checkbox") {

			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";

		} else {

			this.style.backgroundPosition = "0 -" + radioHeight + "px";

		}

	},

	check: function() {

		element = this.nextSibling;

		if(element.checked == true && element.type == "checkbox") {

			this.style.backgroundPosition = "0 0";

			element.checked = false;

		} else {

			if(element.type == "checkbox") {

				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";

			} else {

				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";

				group = this.nextSibling.name;

				inputs = document.getElementsByTagName("input");

				for(a = 0; a < inputs.length; a++) {

					if(inputs[a].name == group && inputs[a] != this.nextSibling) {

						inputs[a].previousSibling.style.backgroundPosition = "0 0";

					}

				}

			}

			element.checked = true;

		}

	},

	clear: function() {

		inputs = document.getElementsByTagName("input");

		for(var b = 0; b < inputs.length; b++) {

			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {

				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";

			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {

				inputs[b].previousSibling.style.backgroundPosition = "0 0";

			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {

				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";

			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {

				inputs[b].previousSibling.style.backgroundPosition = "0 0";

			}

		}

	},

	choose: function() {

		option = this.getElementsByTagName("option");

		for(d = 0; d < option.length; d++) {

			if(option[d].selected == true) {

				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;

			}

		}

	}

}

window.onload = Custom.init;













/*

window.onload = init;

var d=document;

function init() {

	so_createCustomCheckBoxes();

}



function so_createCustomCheckBoxes(imgObj,caller) {

	// Ta reda på om detta är en äldre webbläsare

	if(!d.getElementById)return;

	// Ta reda på om detta är en MacIE

	if(navigator.userAgent.indexOf("Mac")>-1 && d.all) return;

	// En samling med tillämpliga händelser som vi behöver för att överföra till våra egna select

	events = new Array("onfocus", "onblur", "onselect", "onchange", "onclick", "ondblclick", "onmousedown", "onmouseup", "onmouseover", "onmousemove", "onmouseout", "onkeypress", "onkeydown", "onkeyup");

	// En hänvisning var att alla formulär i dokumentet

	frm = d.getElementsByTagName("form");

	// Loop över längden på de formulärer i dokumentet

	for(i=0;i<frm.length;i++) {

		// Hänvisning till elementen i formuläret

		c = frm[i].elements;

		// Loop över längden av dessa element

		for(j=0;j<c.length;j++) {

			// Om detta inslag är en kryssruta, gör vår sak

			if(c[j].getAttribute("type") == "checkbox") {

				// hide the original checkbox

				//c[j].style.display = "none";

				c[j].style.position = "absolute";

				c[j].style.left = "-9000px";

				// Skapa ersättande bild

				n = d.createElement("img");

				n.setAttribute("class","chk");

				// kontrollera om motsvarande kryssruta är markerad eller inte. ställer in 

				// status av bilden i enlighet

				if(c[j].checked == false) {

					n.setAttribute("src","/_img/checkbox_0.gif");

					n.setAttribute("title","click here to select this option.");

					n.setAttribute("alt","click here to select this option.");

				} else {

					n.setAttribute("src","/_img/small_checkbox_1.gif");

					n.setAttribute("title","click here to deselect this option.");

					n.setAttribute("alt","click here to deselect this option.");

				}

				// det finns flera bitar av data vi behöver veta senare.

				// tilldela dem som attribut för den bild vi har skapat

				// första - namnet på motsvarande kryssruta

				n.xid = c[j].getAttribute("name");

				// nästa, för form element så vi vet vilka utgör föremålet för att få tillgång till senare

				n.frmIndex = i;

				// tilldela onclick händelse till bilden

				n.onclick = function() { so_createCustomCheckBoxes(this,1);return false; }

				// bifogar bilden i DOM

				c[j].parentNode.insertBefore(n,c[j].nextSibling)

				// detta attribut är lite av en hacka - vi behöver känna till i händelse av en etikett på (för webbläsare som stöder det)

				// vilken bild vi måste slå på eller av. Så vi ställa in bilden som ett attribut!

				c[j].objRef = n;

				// Tilldela kryssrutan objekt händelsehanterare till dess ersättande bild

				for(e=0;e<events.length;e++) if(eval('c[j].' +events[e])) eval('n.' + events[e] + '= c[j].' + events[e]);

				// append våra onchange händelsehanterare till alla befintliga.

				fn = c[j].onchange;

				if(typeof(fn) == "function") {

					c[j].onchange = function() { fn(); so_toggleCheckBox(this.objRef,1); return false; }

				} else {

					c[j].onchange = function () { so_toggleCheckBox(this.objRef,1); return false; }

				}

			}

		}

	}

}

*/











/* Detta script finns att hämta på http://www.jojoxx.net och

   får användas fritt så länge som dessa rader står kvar. */



function gfxSCheckboxToggle(checkboxobj,imgobj,offSrc,onSrc)

{

	if (!offSrc)

	{

	var offSrc = '/_img/small_checkbox_0.gif';

	}

	if (!onSrc)

	{

	var onSrc = '/_img/small_checkbox_1.gif';

	}

	if (document.images)

	{

	imgobj.src = (checkboxobj.checked==false) ? onSrc:offSrc;

	checkboxobj.checked = (checkboxobj.checked==true) ? false:true;

	}

}



function gfxCheckboxToggle(checkboxobj,imgobj,offSrc,onSrc)

{

	if (!offSrc)

	{

	var offSrc = '/_img/checkbox_0.gif';

	}

	if (!onSrc)

	{

	var onSrc = '/_img/checkbox_1.gif';

	}

	if (document.images)

	{

	imgobj.src = (checkboxobj.checked==false) ? onSrc:offSrc;

	checkboxobj.checked = (checkboxobj.checked==true) ? false:true;

	}

}



function PopUp(url, name, width, height)

{

window.open(url, name, "channelmode=no, directories=no, fullscreen=no,"+" height="+height+", location=no, menubar=no,"+" resizable=no, scrollbars=yes, status=no, width="+width+", left= "+(((screen.width-width)/2)-15)+", top= "+(screen.height-height)/3);

return false

}



function showImage(ImageName)

{

var imgMain = document.getElementById("ImgMain");

	if(ImageName)

	{

	imgMain.src = ImageName;	

	}	

}

function markText(id)
{
var myField = document.getElementById(id);
	if (myField.value == myField.defaultValue)
	{
	myField.focus();
	var valueLenght = myField.value.length;
		//IE support
		if (document.selection)
		{
		var sel = document.selection.createRange();
			if (myField.createTextRange)
			{
			var range = myField.createTextRange();
			/*alert(valueLenght);*/
			range.collapse(true);
			range.moveStart('character',0); 
			range.moveEnd('character',(valueLenght)); 
			range.select(); 
			}
		}
		//MOZILLA/NETSCAPE support
		else if (myField.selectionStart || myField.selectionStart == '0')
		{
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.setSelectionRange(0,valueLenght);
		}
	}
}