function CustomF(cform){
  this.cForm_id  = cform;
  this.cForm = null;
  this.arrSelect = new Array();
  this.arrInput = new Array();
  this.selectClass = 'cust_select';
  this.curLi = null;
  this.preload = true;
  /*this.arrP2n = new Array(0,5,12,20,30,40,51,60,64,67,70);
  this.arrP2 = new Array(0,10,30,51,65,70,70,70,70,70,70);
  this.arrS3 = new Array(0,18,50,70,85,18);*/
}

CustomF.prototype.init = function(){
			this.cForm = ById(this.cForm_id);
			this.arrSelect = ByTag(this.cForm, 'select');
			if(this.arrSelect){
				for(var i=0; i<this.arrSelect.length;i++){
					if(this.arrSelect[i].className == this.selectClass){
					this.TransformSelect(this.arrSelect[i],i);
					}
				}
            }
			this.arrInput = ByTag(this.cForm, 'input');
			if(this.arrInput){
				for(var i=0; i<this.arrInput.length;i++){
					if(this.arrInput[i].className == this.selectClass && this.arrInput[i].type == 'checkbox'){
					this.TransformCheckbox(this.arrInput[i],i);
					}
				}
            }

		if(this.preload){
			var images = new Array();
			for(var i =0; i<3;i++){
				images[i] = new Image();
				}
			images[0].src = '/qdocs/images/custom_ch_n.gif';
			//images[1].src = '/images/custom_ch_s.gif';
			//images[2].src = '/images/custom_sel_bg.gif';
		}
	}


CustomF.prototype.ShowSelect = function(){
		var ul = ByTag(this.parentNode, 'ul')[0];
		var arrUl =  ByTag(CustForm.cForm, 'ul');
		var curUldisp = ul.style.display;
		for(var i=0;i<arrUl.length;i++)
			{
				arrUl[i].style.display = 'none';
			}
		ul.style.display  = (curUldisp == 'none') ? 'block' : 'none';

			var index = CustForm.ReturnSelectIndex(this.id);
			var arrLi = new Array();
			arrLi  = ByTag(ul, 'li');
			for(var i=0;i<arrLi.length;i++){
				if(i==index){
						arrLi[i].className = 'select';}
				else arrLi[i].className = '';
			}
		}

CustomF.prototype.ReturnSelectIndex = function(id){
		var id_ = id.replace(/^([a-zA-Z]*)_/,'');
		var select_ = ById(id_);
		return select_.selectedIndex;
		}

CustomF.prototype.ResetForm = function(){
	CustForm.cForm.reset();
			for(var i=0; i<CustForm.arrSelect.length;i++){
				if(CustForm.arrSelect[i].className == CustForm.selectClass){
				var el_sp = ById('sp_'+CustForm.arrSelect[i].id);
				el_sp.innerHTML = CustForm.arrSelect[i].value;
				}
			}
//			this.arrInput = ByTag(this.cForm, 'input');
			for(var i=0; i<CustForm.arrInput.length;i++){
				if(CustForm.arrInput[i].className == CustForm.selectClass && CustForm.arrInput[i].type == 'checkbox'){
				var el_sp = ById('sp_'+CustForm.arrInput[i].id);
				el_sp.className = (CustForm.arrInput[i].checked==true) ? 'custform_ch_box_s' : 'custform_ch_box_n';
				}
			}
	}



CustomF.prototype.SelectHover = function(){
		var arrLi =  ByTag(this.parentNode, 'li');
		var curLiClass = this.className;
		for(var i=0;i<arrLi.length;i++){
				arrLi[i].className = '';
			}
		this.className = 'select';
		//alert(this.parentNode.clientWidth);
		//this.style.width = this.parentNode.clientWidth + 'px';
		}

CustomF.prototype.SelectClick = function(){
		var reg  = new RegExp("([^_]+)_([0-9]{1,5})",'i');
		var res = reg.exec(this.id);
		var span_ = ById('sp_'+res[1]);
		span_.innerHTML = this.innerHTML;
		var select_ = ById(res[1]);
		var oldindex = select_.selectedIndex;
		select_.selectedIndex = res[2];
		if(select_.selectedIndex != oldindex)
			{select_.onchange();}
		this.parentNode.style.display = 'none';
		}

CustomF.prototype.CheckBoxClick = function(){
		var el_id = this.id.replace(/^([a-zA-Z]*)_/,'');
		var el = ById(el_id);
		if(el.checked==true){
				el.checked = false;
				this.className = 'custform_ch_box_n';
			}
		else{
				el.checked = true;
				this.className = 'custform_ch_box_s';
			}
		}



CustomF.prototype.TransformSelect = function(el,index){
			var issetTrans = ById('sp_'+el.id);
			if(issetTrans) {return;}
			el.style.display = 'none';
			var div_= document.createElement("span");
			var span_= document.createElement("span");
			var p_= document.createElement("p");
			ul_= document.createElement("ul");
			span_.id = 'sp_'+el.id;
			span_.style.zIndex = 0;
			div_.id = 'cust_s'+el.id;
			div_.style.zIndex  = 100- index;
			ul_.style.zIndex = 100 - index;
			ul_.style.display = 'none';

			var option = new Array();
			for(var i=0;i<el.length;i++){
				option[i] = document.createElement("li");
				//option[i].appendChild(document.createTextNode(el.options[i].text));
				var div_li =  document.createElement("p");
				div_li.appendChild(document.createTextNode(el.options[i].text));
				option[i].appendChild(div_li);
				option[i].id = ''+el.id+'_'+i;

				if(el.options[i].selected)
					{
					p_.appendChild(document.createTextNode(el.options[i].text))
					option[i].className = 'select';
					}
				ul_.appendChild(option[i]);
				option[i].onmouseover = this.SelectHover;
				var ev = el.onchange;
				option[i].onclick =this.SelectClick;
			}
			span_.appendChild(p_);
			div_.appendChild(span_);
			div_.appendChild(ul_);
			el.parentNode.insertBefore(div_, el);
			span_.className = 'sel_box';
			ul_.className = 'custform_ul';
			ul_.style.display = 'block';
			for(var i=0;i<el.length;i++)
				{				//alert(option[i].parentNode.clientWidth );
				var pwidth = option[i].parentNode.clientWidth;
				option[i].style.width = (pwidth<263) ? '261px' :option[i].parentNode.clientWidth-2 + 'px';
               // alert(option[i].style.width);
                /*
				var arrDiv_li  = ByTag(option[i],'p');
				for(var j=0;j<arrDiv_li.length;j++)
					{
					//arrDiv_li[j].style.width = '500px';
					}*/
				}

               //alert(option[0].parentNode.innerHTML);
             ul_.style.display = 'none';

			div_.className = 'custform_sel_box';
			span_.onclick = this.ShowSelect;
			//alert(div_.innerHTML);
		}


CustomF.prototype.TransformCheckbox = function(el,index){
			el.style.display = 'none';
			//var div_= document.createElement("div");
			var span_= document.createElement("span");
			if(el.checked == true){
				span_.className = 'custform_ch_box_s';
			}
			else {span_.className = 'custform_ch_box_n';}
			span_.style.zIndex = index  + 10;
			span_.id = 'sp_'+el.id;
			el.parentNode.appendChild(span_);
			span_.onclick = this.CheckBoxClick;
	}



var  CustForm = new CustomF('search_doc');
//arrEvents.push('CustForm.init()');
//window.onload = CustForm.init();