///////////////////////////////////////////////////////////////////////////////////
///                                                                             ///
///                  name: NHPedia                                              ///
///                   ver: 1.0                                                  ///
///            powered by: Arilo System ver 2.0b                                ///
///                 autor: NEGON S.C. Pavlo Khmara, Dmitriy Vaskovskiy          ///
///                 autor: Dmitriy Vaskovskiy                                   ///
///                 email: info@negon.pl                                        ///
///                 email: dima@negon.pl                                        ///
///                                                                             ///
///                       copyright C 2010 by NEGON                             ///
///                                                                             ///
///////////////////////////////////////////////////////////////////////////////////
// JavaScript Form Costumize

var num=0;

function createSelectNew(element){
  if(element.parentNode.className=="select4k") return false; 
  var divTag = document.createElement("div");
  var divWithText = document.createElement("div");
  var divWithColor = document.createElement("div");
  var textSel = document.createTextNode("");
  if(element.disabled) divTag.className = 'select4kBW';
  else divTag.className = 'select4k';
  divWithText.className = 'select4kText';
  divWithColor.className = 'select4kColor'
  divWithText.id = 'select4kText'+element.name;
  divWithColor.id = 'select4kColor'+element.name;
  element.parentNode.insertBefore(divTag,element);
  divWithText.appendChild(textSel);
  divTag.appendChild(divWithColor);
  divTag.appendChild(divWithText);
  divTag.appendChild(element);
  selectFirstStart(element);
  if(element.disabled){
     divWithText.style.cursor="default";
     element.style.display="none";
  }else{
     //element.onchange = FC4K.selectClick;
  }
}

function FC4KselectClick(element){
    option = element.getElementsByTagName("option");
    countOpt = option.length;
      for(d = 0; d < countOpt; d++) {
  			if(option[d].selected == true) {
  				document.getElementById("select4kText" + element.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
  				if(option[d].value==1) document.getElementById("select4kColor" + element.name).style.background='#abffde';
  				else if(option[d].value==2) document.getElementById("select4kColor" + element.name).style.background='#1dffab';
  				else if(option[d].value==3) document.getElementById("select4kColor" + element.name).style.background='#4cff1d';
  				else if(option[d].value==4) document.getElementById("select4kColor" + element.name).style.background='#b7ff3d';
  				else if(option[d].value==5) document.getElementById("select4kColor" + element.name).style.background='#ffa01d';
  				else if(option[d].value==6) document.getElementById("select4kColor" + element.name).style.background='#ff4000';
  				else if(option[d].value==7) document.getElementById("select4kColor" + element.name).style.background='#df0050';
  				else if(option[d].value==8) document.getElementById("select4kColor" + element.name).style.background='#c51fff';
  				else if(option[d].value==9) document.getElementById("select4kColor" + element.name).style.background='#1800ff';
  				else if(option[d].value==10) document.getElementById("select4kColor" + element.name).style.background='#1f7aff';
  				else if(option[d].value==11) document.getElementById("select4kColor" + element.name).style.background='#1fe2ff';
  				else if(option[d].value==12) document.getElementById("select4kColor" + element.name).style.background='#bce0f8';
  			}
  		}
}

function selectFirstStart(element){
      option = element.getElementsByTagName("option");
      countOpt = option.length;
      for(d = 0; d < countOpt; d++) {
  			if(option[d].selected == true) {
  				document.getElementById("select4kText" + element.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
  				if(option[d].value==1) document.getElementById("select4kColor" + element.name).style.background='#abffde';
  				else if(option[d].value==2) document.getElementById("select4kColor" + element.name).style.background='#1dffab';
  				else if(option[d].value==3) document.getElementById("select4kColor" + element.name).style.background='#4cff1d';
  				else if(option[d].value==4) document.getElementById("select4kColor" + element.name).style.background='#b7ff3d';
  				else if(option[d].value==5) document.getElementById("select4kColor" + element.name).style.background='#ffa01d';
  				else if(option[d].value==6) document.getElementById("select4kColor" + element.name).style.background='#ff4000';
  				else if(option[d].value==7) document.getElementById("select4kColor" + element.name).style.background='#df0050';
  				else if(option[d].value==8) document.getElementById("select4kColor" + element.name).style.background='#c51fff';
  				else if(option[d].value==9) document.getElementById("select4kColor" + element.name).style.background='#1800ff';
  				else if(option[d].value==10) document.getElementById("select4kColor" + element.name).style.background='#1f7aff';
  				else if(option[d].value==11) document.getElementById("select4kColor" + element.name).style.background='#1fe2ff';
  				else if(option[d].value==12) document.getElementById("select4kColor" + element.name).style.background='#bce0f8';
  			}
  		}
}

function createCheckboxNew(element){
  if(element.parentNode.className=="checkbox4k") return false; 
  var divTag = document.createElement("div");
  if(element.disabled) divTag.className = 'checkbox4kBW';
  else divTag.className = 'checkbox4k';
  element.parentNode.insertBefore(divTag,element);
  divTag.appendChild(element);
  element.style.display='none';
  if(element.checked) divTag.style.backgroundPosition="0 -50px";
  if(!element.disabled){
      divTag.onclick = element.onchange;
      element.onchange = FC4K.checkboxClear;
			divTag.onmousedown = FC4K.checkboxClick;
			divTag.onmouseup = FC4K.checkboxSelect;
			document.onmouseup = FC4K.checkboxClear;
			 
  }
}

function createRadioNew(element){
  if(element.parentNode.className=="radio4kBW") return false; 
  var divTag = document.createElement("div");
  if(element.disabled) divTag.className = 'radio4kBW';
  else divTag.className = 'radio4k';
  element.parentNode.insertBefore(divTag,element);
  divTag.appendChild(element);
  element.style.display='none';
  if(element.checked) divTag.style.backgroundPosition="0 -50px";
  if(!element.disabled){
      element.onchange = FC4K.radioClear;
			divTag.onmousedown = FC4K.radioClick;
			divTag.onmouseup = FC4K.radioSelect;
			document.onmouseup = FC4K.radioClear;
  }
}

function createFileNew(element){
   var divTag = document.createElement("div");
   var divWithText = document.createElement("div");
   var textSel = document.createTextNode(' ');
   if(element.disabled) divTag.className = 'file4kBW';
   else divTag.className = 'file4k';
   divWithText.className = 'file4kText';
   divWithText.id = 'file4kText'+element.name;
   element.parentNode.insertBefore(divTag,element);
   divWithText.appendChild(textSel);
   divTag.appendChild(divWithText);
   if(!element.disabled){
       var divWithText2 = document.createElement("div");
       divWithText2.className = 'file4kText2';
       divWithText2.id = 'file4kText2'+element.name;
       divTag.appendChild(divWithText2);   
   }
   divTag.appendChild(element);
   if(element.disabled){
      divWithText.style.cursor="default";
      element.style.display="none";
   }else{
      divWithText.style.cursor="default";
      element.onchange = FC4K.changeFile;
   }
}

var FC4K = {
	init: function(){
	  if(document.getElementsByClassName) {
      var elements = document.getElementsByClassName('style4k');
    }else{
      /*For IE*/
      var elements = [], a=0;
      inputy = document.getElementsByTagName("input");
      countInputy = inputy.length;
      selecty = document.getElementsByTagName("select");
      countSelecty = selecty.length;
      for(i=0;i<countInputy;i++){
        if(inputy[i].className == "style4k"){
           elements[a] = inputy[i];
           a++;
        }
      }
      for(i=0;i<countSelecty;i++){
        if(selecty[i].className == "style4k"){
           elements[a] = selecty[i];
           a++;
        }
      }
    }
    var countEl = elements.length;
    if(countEl) for(i=0;i<countEl;i++){
       if(elements[i]) switch (elements[i].nodeName)
       {
          case 'SELECT':   createSelectNew(elements[i]);
                           break;
          case 'INPUT':    switch (elements[i].type){
                              case 'checkbox':  createCheckboxNew(elements[i]);
                                                break;
                              case 'radio':     createRadioNew(elements[i]);
                                                break;
                              case 'file':      createFileNew(elements[i]);
                                                break;
                              //default: alert(element.type)
                           }
                           break; 
          //default: alert(element.nodeName) 
       }
    }
	},
	selectClick: function() {
      option = this.getElementsByTagName("option");
      countOpt = option.length;
      for(d = 0; d < countOpt; d++) {
  			if(option[d].selected == true) {
  				document.getElementById("select4kText" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
  			}
  		}
  },
  checkboxClick: function() {
		element = this.firstChild;
		if(element.checked == true) {
			this.style.backgroundPosition = "0 -75px";
		} else {
      this.style.backgroundPosition = "0 -25px";
		}
	},
  radioClick: function() {
		element = this.firstChild;
		if(element.checked == true) {
			this.style.backgroundPosition = "0 -75px";
		} else {
			this.style.backgroundPosition = "0 -25px";
		}
	},
	checkboxSelect: function() {
		element = this.firstChild;
		if(element.checked == true) {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			this.style.backgroundPosition = "0 -50px";
			element.checked = true;
		}
	},
  radioSelect: function() {
		element = this.firstChild;
		  	this.style.backgroundPosition = "0 -50px";
				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;
	}, 
	checkboxClear: 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 == "style4k") {
				inputs[b].parentNode.style.backgroundPosition = "0 -50px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "style4k") {
				inputs[b].parentNode.style.backgroundPosition = "0 0";
			}
		}
	},
  radioClear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "style4k") {
				inputs[b].parentNode.style.backgroundPosition = "0 -50px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "style4k") {
				inputs[b].parentNode.style.backgroundPosition = "0 0";
			}
		}
	},
  changeFile: function() {
     document.getElementById("file4kText2" + this.name).innerHTML = this.value;
  }
}

window.onload=FC4K.init;

