function preload(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()')
		eval(imgObj+'.src = "'+imgSrc+'"')
	}
}

function changeImage(layer,imgName,imgObj) {
	if (document.images) {
		if (document.layers && layer!=null) eval('document.'+layer+'.document.images["'+imgName+'"].src = '+imgObj+'.src')
		else document.images[imgName].src = eval(imgObj+".src")
	}
}

// lets allow using images to replace html checkboxes

preload('checkbox0','images/checkbox0.gif')
preload('checkbox1','images/checkbox1.gif')

preload('radio0','images/radio0.gif')
preload('radio1','images/radio1.gif')

// CheckBox object

function CheckBox(layer,imgName,trueValue,falseValue,defaultToTrue) {
	this.layer = layer
	this.imgName = imgName
	this.trueValue = trueValue
	this.falseValue = falseValue
	this.state = (defaultToTrue) ? 1 : 0
	this.value = (this.state) ? this.trueValue : this.falseValue
	this.change = CheckBoxChange
}

function CheckBoxChange(formname,formelement) {
	this.state = (this.state) ? 0 : 1
	this.value = (this.state) ? this.trueValue : this.falseValue
	eval('document.'+formname+'.'+formelement+'.value = "'+this.value+'"');
	changeImage(this.layer,this.imgName,'checkbox'+this.state)
}

// Radio object

function Radio(layer,imgNames,length,defaultValue) {
	this.layer = layer
	this.imgNames = imgNames
	this.length = length
	this.change = RadioChange
	this.value = (defaultValue)? defaultValue : "undefined"
}

function RadioChange(formname,formelement,index,value) {
	this.value = value
	for (var i=0; i<this.length; i++) changeImage(this.layer,this.imgNames+i,'radio0')
	eval('document.'+formname+'.'+formelement+'.value = "'+this.value+'"');
	changeImage(this.layer,this.imgNames+index,'radio1')
}

