// JavaScript Document
function showbox(id){
	visi=document.getElementById(id).style.display;
	if(visi=="none" || visi==""){
		document.getElementById(id).style.display="block";
	}else{
		document.getElementById(id).style.display="none";
	}
}

function selitem(obj,objhold){
	holder=document.getElementById(objhold);
	
	oldnode=document.getElementById(objhold).childNodes[0];
	newnode=obj.cloneNode(true);
	holder.replaceChild(newnode,oldnode);
	val=obj.getAttribute("value");
	frmfield=obj.parentNode.parentNode.id;
	frmfield=frmfield.substring(0,frmfield.length-1);
	document.getElementById(frmfield).value=val;
	obj.parentNode.style.display="none";
}

function makebox(id,parent,height,width,optlist,cont_type,value,defaultval){
	newarr=optlist.split(":");
	//alert(height+ ',' +width);
	if(!value){
		value='';
	}	
	parnode=document.getElementById(parent);
	newnode=document.createElement("div");
	newnode.setAttribute("id",id+"a");
	if((((newarr.length/2)+1)*height)<90){
		intbox='height:'+((newarr.length/2)*height)+'px;';
	}else{
		intbox='height:90px;';
	}
	newnode.style.height=height+"px";
	newnode.style.width=(width+20)+"px";
	newnode.style.border='#666666 1px solid';
	newnode.style.zindex='1';
	newarrow='<div class="downarrow" style="height:'+(height-2)+'px;left:'+width+'px" id="'+id+'downarr" onclick="showbox(\''+id+'optbox\')"></div>';
	newoptholder='<div class="optholder" id="'+id+'optholder" style="width:'+width+'px;height:'+height+'px" onclick="showbox(\''+id+'optbox\')"><div></div></div>';
	opt_trigger='';
	if(cont_type=="color"){
		//alert(newarr);
		opt='<div id="'+id+'optbox" class="optbox" style="width:58px" onblur="showbox(\''+id+'optbox\')">';
		for(a=0;a<newarr.length;a=a+2){
			if(value==newarr[a+1]){
				opt_trigger=id+'opt'+a;
			}
			opt=opt+'<div id="'+id+'opt'+a+'" value="'+newarr[a+1]+'" class="option" style="background-color:#'+newarr[a]+';width:18px;height:18px;border:#000000 1px solid;" onclick="selitem(this,\''+id+'optholder\')"></div>'+"\n";
			//alert(opt);
		}
	}else if(cont_type=="image"){
		opt='<div id="'+id+'optbox" class="optbox" style="'+intbox+'width:'+(width+18)+'px">';
		for(a=0;a<newarr.length;a=a+2){
			if(value==newarr[a+1]){
				opt_trigger=id+'opt'+a;
			}
			opt=opt+'<div id="'+id+'opt'+a+'" value="'+newarr[a+1]+'" class="option" style="background-image:url('+path_to_pics+newarr[a]+');height:'+height+'px;width:'+width+'px" onclick="selitem(this,\''+id+'optholder\')"></div>'+"\n";
			//alert(opt);
		}
	}	
	opt=opt+"</div>";
	newnode.innerHTML='<input type="hidden" name="'+id+'" value="'+defaultval+'" id="'+id+'">'+newoptholder+newarrow+opt;	
	parnode.appendChild(newnode);
	if(opt_trigger>''){
		document.getElementById(opt_trigger).onclick();
	}
	//document.body.appendChild(newnode);
}
