
//f=document.forms[0]
var inps

var skins=new Array("netscape/","konqueror/","sofaking/","plain/");
var f
setSkin()	
function setSkin() {
	fcontainer=document.getElementById('formcontainer')
	//fs=document.forms
	fs=fcontainer.getElementsByTagName('FORM')
	for (ii=0;ii<fs.length;ii++) {
		f=fs[ii]
		inps=f.getElementsByTagName("INPUT")
	imgs=f.getElementsByTagName("IMG")
	for(i=0;i<imgs.length;i++) { // remove all this imgs if resize
		if(imgs[i].getAttribute("prettyCheckbox")=="1") { 	
			imgs[i].parentNode.removeChild(imgs[i]);i--;
		}
	}
	for (i=0;i<inps.length;i++) {
		inp=inps[i]
		type=inp.getAttribute("type").toLowerCase()
		if ((type!="radio") && (type!="checkbox")) continue
		im=document.createElement("IMG");	
		im.setAttribute("prettyCheckbox","1");
		if (type=="radio") im.setAttribute("name", inps[i].getAttribute("name"))
		chk=isChecked(inp)
		s=type+(chk ? 1 : 0)+".gif"; 
		im.setAttribute("src","/myResources/PrettyCheckboxes/skins/"+skins[ii]+s)	
		parElt=inp.parentNode
		setPosition(inp,im)	
		parElt.appendChild(im);
		inp.style.visibility="hidden"
		im.onmouseover=function(){this.src=this.src.replace(".gif","_over.gif")}
		im.onmouseout=function(){this.src=this.src.replace("_over.gif",".gif")}
		eval("im.onclick=function(){ setCheck("+i+",'"+type+"',this,"+ii+")}")
	}
	
	}
}
window.onresize=setSkin


function setCheck(j,t,obj,ii) {
if (t=="radio") { //uncheck all this elts
	n=f.elements[j].getAttribute("name")
	f=document.forms[ii]
	inps=f.getElementsByTagName("INPUT")
	for(i=0;i<inps.length;i++) {
		if(inps[i].getAttribute("name")==n) inps[i].removeAttribute("checked")
	}
	//replace all the image src for this name
	imgs=f.getElementsByTagName("IMG")
	for(i=0;i<imgs.length;i++) {
		if(imgs[i].getAttribute("name")==n) { 		
			imgs[i].src=imgs[i].src.replace("1.gif","0.gif")
		}
	}
	f.elements[j].setAttribute('checked','checked');
	obj.src=obj.src.replace("0_over.gif","1_over.gif")
}
if (t=="checkbox") { 
 chk=isChecked(f.elements[j])
 if (!chk) {f.elements[j].checked=true;// IE
	 f.elements[j].setAttribute('checked','checked');
	 obj.src=obj.src.replace("0_over.gif","1_over.gif")
 	}
 else {
 		f.elements[j].checked=false // IE
		b=f.elements[j].removeAttributeNode(f.elements[j].getAttributeNode("CHECKED"));//Mozilla
		obj.src=obj.src.replace("1_over.gif","0_over.gif")
	}
}
}

function isChecked (elt){
	c=elt.getAttributeNode("checked");
	try {if (c) {c.value="checked"} } catch(e){alert(e.errorText)} //for Mozilla
	chk=elt.getAttribute("checked"); 
	if(chk=="false") chk=false; //for Opera
	return chk
}

function setPosition(elt,anotherElt) {
topdiv=0;leftdiv=0; 
do {
 b=(elt.style.borderTopWidth)?(elt.style.borderTopWidth):(0)
 b=(b)?(parseInt(b.substring(0,b.length-2))):(0);
 p=(elt.style.paddingTop)?(elt.style.paddingTop):(0);
 p=(p)?(parseInt(p.substring(0,p.length-2))):(0)
 b2=(elt.style.borderLeftWidth)?(elt.style.borderLeftWidth):(0)
 b2=(b2)?(parseInt(b2.substring(0,b2.length-2))):(0);
 p2=(elt.style.paddingLeft)?(elt.style.paddingLeft):(0);
 p2=(p2)?(parseInt(p2.substring(0,p2.length-2))):(0)
 try {
 	topdiv+=elt.offsetTop+b+p; leftdiv+=elt.offsetLeft+b2+p2;  } catch(err) {alert(err)} 
 elt=elt.offsetParent; 
  } 
  while (elt.tagName!="BODY")
  
anotherElt.style.position="absolute"
topM=0;leftM=0;
if (document.body.topMargin)	topM=document.body.topMargin;
if(document.body.leftMargin)	leftM=document.body.leftMargin

//anotherElt.style.top=parseInt(topdiv)+parseInt(topM);alert(parseInt(topM))
anotherElt.style.left=parseInt(leftdiv)+parseInt(leftM/2);//alert(anotherElt.style.top)

anotherElt.style.top=parseInt(topdiv)+parseInt(topM/2)//+document.body.topMargin

}
