/* Java script file */

function initForm(formId)
{
	var elements = $(formId).getElements();
	elements.map(
	    function(el){
	      var val = el.value.strip();
	      if(el.title != undefined && val == '')
	        {
	            el.value = el.title;
	        }
	    }
	);
}

function processForm(form_id, additionalCheck)
{
  var elements = $(form_id).getElements();
  var required = [];
  var invalids = [];
  var message = []; 
  elements.map(
    function(el){
      var val = el.value.strip();
      if(el.readAttribute('require')=='true')
      {
        if(el.title == val || val == '')
        {
          required.push(el.title.replace(' *',''));
          return;
        }
      }
      if(el.readAttribute('validation') != null)
      {
        var method = el.readAttribute('validation');
        var bool = false;
        eval('bool = '+ method +'("'+ val +'");');
        if(!bool)
        {
          invalids.push(el.readAttribute('error_message'));
        }
      }
    }
  );
  if(required.length > 0)
  {
    message.push('The field(s) ' + required.join(', ') + ' must be populated!')
  }
  if(invalids.length > 0)
  {
    message.push(invalids.join('\n'));
  }
  if(message.length > 0)
  {
    alert(message.join('\n'));
    return false;
  }
  elements.map(
    function(el){
      if(el.title == el.value)
			{
				el.value = '';
			}
    }
  );
  if(typeof additionalCheck == 'function')
  {
		if(!additionalCheck.apply(this))
		{
			return false;
		}
	}
	$(form_id).submit();
}
function changeValue(el, ev)
{
	if(ev.type == 'blur' && el.title != el.value && el.value == '')
	{
		el.value = el.title;
	}
	if(ev.type == 'focus' && el.title == el.value)
	{
		el.value = '';
	}
}

function isMail(str)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return filter.test(str);
}
function addSeparatorsNF(nStr, inD, outD, sep)
{
	nStr += '';
	var dpos = nStr.indexOf(inD);
	var nStrEnd = '';
	if (dpos != -1) {
		nStrEnd = outD + nStr.substring(dpos + 1, nStr.length);
		nStr = nStr.substring(0, dpos);
	}
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(nStr)) {
		nStr = nStr.replace(rgx, '$1' + sep + '$2');
	}
	return nStr + nStrEnd;
}
function showpage(page, holder)
{
	$A($(holder).childNodes).map(
    function(el){
      if(el.id)
      {
        el[(el.id == 'paging' + page)?'show':'hide']();
      }
    }
	);
}
/*

function selectReplacement(obj) {
      // append a class to the select
      obj.className += ' replaced';
      // create list for styling
      var ul = document.createElement('ul');
      ul.className = 'selectReplacement';
      var opts = obj.options;
      for (var i=0; i<opts.length; i++) {
        var selectedOpt;
        if (opts[i].selected) {
          selectedOpt = i;
          break;
        } else {
          selectedOpt = 0;
        }
      }
      for (var i=0; i<opts.length; i++) {
        var li = document.createElement('li');
        var txt = document.createTextNode(opts[i].text);
        li.appendChild(txt);
        li.selIndex = opts[i].index;
        li.selectID = obj.id;
        li.onclick = function() {
          selectMe(this);
        }
        if (i == selectedOpt) {
          li.className = 'selected';
          li.onclick = function() {
            this.parentNode.className += ' selectOpen';
            this.onclick = function() {
              selectMe(this);
            }
          }
        }
        if (window.attachEvent) {
          li.onmouseover = function() {
            this.className += ' hover';
          }
          li.onmouseout = function() {
            this.className = 
              this.className.replace(new RegExp(" hover\\b"), '');
          }
        }
        ul.appendChild(li);
      }
      // add the input and the ul
      obj.parentNode.appendChild(ul);
    }
    function selectMe(obj) {
      var lis = obj.parentNode.getElementsByTagName('li');
      for (var i=0; i<lis.length; i++) {
        if (lis[i] != obj) { // not the selected list item
          lis[i].className='';
          lis[i].onclick = function() {
            selectMe(this);
          }
       } else {
          setVal(obj.selectID, obj.selIndex);
          obj.className='selected';
          obj.parentNode.className = 
            obj.parentNode.className.replace(new RegExp(" selectOpen\\b"), '');
          obj.onclick = function() {
            obj.parentNode.className += ' selectOpen';
            this.onclick = function() {
              selectMe(this);
            }
          }
        }
      }
    }
    function setVal(objID, selIndex) {
      var obj = document.getElementById(objID);
      obj.selectedIndex = selIndex;
    }
    function setForm() {
      var s = document.getElementsByTagName('select');
      for (var i=0; i<s.length; i++) {
        selectReplacement(s[i]);
      }
    }
    function closeSel(obj) {
      // close the ul
    } */
/*    window.onload = function() {
      (document.all && !window.print) ? null : setForm();
    }
*/
// funkcia zaradi padashtoto menu v Explorer 
sfHover = function() {
            	var sfEls = document.getElementById("menu").getElementsByTagName("li");
            	for (var i=0; i<sfEls.length; i++) {
            		sfEls[i].onmouseover=function() {
            			this.className+=" sfhover";
            		}
            		sfEls[i].onmouseout=function() {
            			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
            		}
            	}
            }
            if (window.attachEvent)window.attachEvent("onload", sfHover);

// Show Hide function fron Euro audit site for Interior design divs        
function showMe(num)
{
	for (var i=1; i>0; i++) {
		var curElement = document.getElementById('sublist_' + i);
		if (curElement) {
			var parElement = curElement.parentNode;
			if (num == i) {
			
				curElement.style.display = 'block';
				parElement.className = 'gold_in_tab';
			}
			else {
				curElement.style.display = 'none';
				parElement.className = '';
			}
		}
		else {
			var lastID = i-1;
			var last = document.getElementById('sublist_' + lastID);
			last.parentNode.className = 'padding_gold';
			break;
		}
	}
}
