function CheckSelect(variable,msg)
{
  for (i=0; ;i++)
  {
    thisVar = variable + '_' + i;
    obj = document.getElementById(thisVar);
    if (obj)
    {
      if (obj.checked)
        return true;
    }
    else
      break;
  }
  window.alert(msg);
  return false;
}

function CheckSearch(formObj,msg)
{
 if (document.forms[formObj].elements['keywords'].value == '')
 {
   window.alert(msg);
   document.forms[formObj].elements['keywords'].focus();
   return false;
 }
 else
  return true;
}

function CheckAll(element)
{
  for(i=0;;i++)
  {
  	var thisObj = document.getElementById(element+i);
  	if (!thisObj)
  	  break;
  	thisObj.checked=true; 
  }
  return;
}

function UncheckAll(element)
{
  var allObj = document.getElementById('all_'+element);
  var allVal = true;	
  for (i=0;;i++)
  {
  	var thisObj = document.getElementById(element+i);
  	if (!thisObj)
  	  break; 
  	else if(!thisObj.checked)
  	{
  	  allVal = false;	
  	  break;	
  	}
  }
  allObj.checked = allVal;
}

//Form Validation

function eCheckEMail(sn){
    s= sn.value;
    if (s.indexOf("@") == -1) return false;
    if (s.indexOf(".") == -1) return false;
    at=false;
    dot=false;
    for (var i = 0; i < s.length; i++) {
        ch = s.substring(i, i + 1);
        if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z")
                || (ch == "@") || (ch == ".") || (ch == "_")
                || (ch == "-") || (ch >= "0" && ch <= "9")) {
                if (ch == "@"){
                  if (at) return false;
                  else at=true;
                }
                if ((ch==".") && at)
                   dot=true;
        }
        else return false;
    }
   return dot;
}

function CheckEMail(theForm,theEmailFields,theMsg){
   for(var i=0; i<theEmailFields.length; i++)
         if (!eCheckEMail(theForm.elements[theEmailFields[i]])){
            alert(theMsg);
            theForm.elements[theEmailFields[i]].focus();
            return false;
        }
   return true;
}


function CheckRequiredFields(theForm,theRequiredFields,theMsg)
{
   for(i=0; i<theRequiredFields.length; i++)
        if (theForm.elements[theRequiredFields[i]].type=="radio")
        {
          var radioName = theForm.elements[theRequiredFields[i]].name;	
          var radioLength = theForm.elements[radioName].length;	
          
          for (n=0; n<radioLength; n++)	
          {
          	if (theForm.elements[radioName][n].checked)
          	  return true;
          }
          alert(theMsg);
          theForm.elements[theRequiredFields[i]].focus();
          return false;
        }
        else if(theForm.elements[theRequiredFields[i]].value==""){
            alert(theMsg);
            theForm.elements[theRequiredFields[i]].focus();
            return false;
        }
   return true;
}

function CheckForm(theForm,theEmailFields,theRequiredFields,theEmailMsg,theGlobalMsg){
     if(CheckRequiredFields(theForm,theRequiredFields,theGlobalMsg))
     if(CheckEMail(theForm,theEmailFields,theEmailMsg))
          return true;
  return false;
}

//End

function changeLang()
{
  var obj = $('chlang');
  var selectedVal = obj.options[obj.selectedIndex].value;
  
  if (selectedVal == "")
    return;
  
  location.href = selectedVal;  
}

/*  Prototype JavaScript framework, version 1.4.0
 *  (c) 2005 Sam Stephenson <sam@conio.net>
 *
 *  Prototype is freely distributable under the terms of an MIT-style license.
 *  For details, see the Prototype web site: http://prototype.conio.net/
 *
/*--------------------------------------------------------------------------*/

//note: stripped down version of prototype, to be used with moo.fx by mad4milk (http://moofx.mad4milk.net).

var Class = {
	create: function() {
		return function() {
			this.initialize.apply(this, arguments);
		}
	}
};

Object.extend = function(destination, source) {
	for (var property in source) destination[property] = source[property];
	return destination;
};

Function.prototype.bind = function(object) {
	var __method = this;
	return function() {
		return __method.apply(object, arguments);
	}
};

if (!Array.prototype.forEach){
	Array.prototype.forEach = function(fn, bind){
		for(var i = 0; i < this.length ; i++) fn.call(bind, this[i], i);
	};
}

Array.prototype.each = Array.prototype.forEach;

String.prototype.camelize = function(){
	return this.replace(/-\D/gi, function(match){
		return match.charAt(match.length - 1).toUpperCase();
	});
};

var $A = function(iterable) {
	var nArray = [];
	for (var i = 0; i < iterable.length; i++) nArray.push(iterable[i]);
	return nArray;
};

function $() {
	if (arguments.length == 1) return get$(arguments[0]);
	var elements = [];
	$c(arguments).each(function(el){
		elements.push(get$(el));
	});
	return elements;

	function get$(el){
		if (typeof el == 'string') el = document.getElementById(el);
		return el;
	}
};

if (!window.Element) var Element = {};

Object.extend(Element, {

	remove: function(element) {
		element = $(element);
		element.parentNode.removeChild(element);
	},

	hasClassName: function(element, className) {
		element = $(element);
		return !!element.className.match(new RegExp("\\b"+className+"\\b"));
	},

	addClassName: function(element, className) {
		element = $(element);
		if (!Element.hasClassName(element, className)) element.className = (element.className+' '+className);
	},

	removeClassName: function(element, className) {
		element = $(element);
		if (Element.hasClassName(element, className)) element.className = element.className.replace(className, '');
	}

});

document.getElementsByClassName = function(className){
	var elements = [];
	var all = document.getElementsByTagName('*');
	$A(all).each(function(el){
		if (Element.hasClassName(el, className)) elements.push(el);
	});
	return elements;
};

//(c) 2006 Valerio Proietti (http://mad4milk.net). MIT-style license.
//moo.fx.js - depends on prototype.js OR prototype.lite.js
//version 2.0

var Fx = fx = {};

Fx.Base = function(){};
Fx.Base.prototype = {

	setOptions: function(options){
		this.options = Object.extend({
			onStart: function(){},
			onComplete: function(){},
			transition: Fx.Transitions.sineInOut,
			duration: 500,
			unit: 'px',
			wait: true,
			fps: 50
		}, options || {});
	},

	step: function(){
		var time = new Date().getTime();
		if (time < this.time + this.options.duration){
			this.cTime = time - this.time;
			this.setNow();
		} else {
			setTimeout(this.options.onComplete.bind(this, this.element), 10);
			this.clearTimer();
			this.now = this.to;
		}
		this.increase();
	},

	setNow: function(){
		this.now = this.compute(this.from, this.to);
	},

	compute: function(from, to){
		var change = to - from;
		return this.options.transition(this.cTime, from, change, this.options.duration);
	},

	clearTimer: function(){
		clearInterval(this.timer);
		this.timer = null;
		return this;
	},

	_start: function(from, to){
		if (!this.options.wait) this.clearTimer();
		if (this.timer) return;
		setTimeout(this.options.onStart.bind(this, this.element), 10);
		this.from = from;
		this.to = to;
		this.time = new Date().getTime();
		this.timer = setInterval(this.step.bind(this), Math.round(1000/this.options.fps));
		return this;
	},

	custom: function(from, to){
		return this._start(from, to);
	},

	set: function(to){
		this.now = to;
		this.increase();
		return this;
	},

	hide: function(){
		return this.set(0);
	},

	setStyle: function(e, p, v){
		if (p == 'opacity'){
			if (v == 0 && e.style.visibility != "hidden") e.style.visibility = "hidden";
			else if (e.style.visibility != "visible") e.style.visibility = "visible";
			if (window.ActiveXObject) e.style.filter = "alpha(opacity=" + v*100 + ")";
			e.style.opacity = v;
		} else e.style[p] = v+this.options.unit;
	}

};

Fx.Style = Class.create();
Fx.Style.prototype = Object.extend(new Fx.Base(), {

	initialize: function(el, property, options){
		this.element = $(el);
		this.setOptions(options);
		this.property = property.camelize();
	},

	increase: function(){
		this.setStyle(this.element, this.property, this.now);
	}

});

Fx.Styles = Class.create();
Fx.Styles.prototype = Object.extend(new Fx.Base(), {

	initialize: function(el, options){
		this.element = $(el);
		this.setOptions(options);
		this.now = {};
	},

	setNow: function(){
		for (p in this.from) this.now[p] = this.compute(this.from[p], this.to[p]);
	},

	custom: function(obj){
		if (this.timer && this.options.wait) return;
		var from = {};
		var to = {};
		for (p in obj){
			from[p] = obj[p][0];
			to[p] = obj[p][1];
		}
		return this._start(from, to);
	},

	increase: function(){
		for (var p in this.now) this.setStyle(this.element, p, this.now[p]);
	}

});

//Transitions (c) 2003 Robert Penner (http://www.robertpenner.com/easing/), BSD License.

Fx.Transitions = {
	linear: function(t, b, c, d) { 
		return c*t/d + b; 
	},
	sineIn: function(t, b, c, d){
		return -c * Math.cos(t/d * (Math.PI/2)) + c + b;
	},

	sineOut: function(t, b, c, d){
		return c * Math.sin(t/d * (Math.PI/2)) + b;
	},
	sineInOut: function(t, b, c, d) { 
		return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; 
	}
};


//by Valerio Proietti (http://mad4milk.net). MIT-style license.
//moo.fx.pack.js - depends on prototype.js or prototype.lite.js + moo.fx.js
//version 2.0

Fx.Scroll = Class.create();
Fx.Scroll.prototype = Object.extend(new Fx.Base(), {

	initialize: function(el, options) {
		this.element = $(el);
		this.setOptions(options);
		this.element.style.overflow = 'hidden';
	},
	
	down: function(){
		return this.custom(this.element.scrollTop, this.element.scrollHeight-this.element.offsetHeight);
	},
	
	up: function(){
		return this.custom(this.element.scrollTop, 0);
	},

	increase: function(){
		this.element.scrollTop = this.now;
	}

});

//fx.Color, originally by Tom Jensen (http://neuemusic.com) MIT-style LICENSE.

Fx.Color = Class.create();
Fx.Color.prototype = Object.extend(new Fx.Base(), {
	
	initialize: function(el, property, options){
		this.element = $(el);
		this.setOptions(options);
		this.property = property.camelize();
		this.now = [];
	},

	custom: function(from, to){
		return this._start(from.hexToRgb(true), to.hexToRgb(true));
	},

	setNow: function(){
		[0,1,2].each(function(i){
			this.now[i] = Math.round(this.compute(this.from[i], this.to[i]));
		}.bind(this));
	},

	increase: function(){
		this.element.style[this.property] = "rgb("+this.now[0]+","+this.now[1]+","+this.now[2]+")";
	}

});

Object.extend(String.prototype, {

	rgbToHex: function(array){
		var rgb = this.match(new RegExp('([\\d]{1,3})', 'g'));
		if (rgb[3] == 0) return 'transparent';
		var hex = [];
		for (var i = 0; i < 3; i++){
			var bit = (rgb[i]-0).toString(16);
			hex.push(bit.length == 1 ? '0'+bit : bit);
		}
		var hexText = '#'+hex.join('');
		if (array) return hex;
		else return hexText;
	},

	hexToRgb: function(array){
		var hex = this.match(new RegExp('^[#]{0,1}([\\w]{1,2})([\\w]{1,2})([\\w]{1,2})$'));
		var rgb = [];
		for (var i = 1; i < hex.length; i++){
			if (hex[i].length == 1) hex[i] += hex[i];
			rgb.push(parseInt(hex[i], 16));
		}
		var rgbText = 'rgb('+rgb.join(',')+')';
		if (array) return rgb;
		else return rgbText;
	}	

});

//by Valerio Proietti (http://mad4milk.net). MIT-style license.
//moo.fx.utils.js - depends on prototype.js OR prototype.lite.js + moo.fx.js
//version 2.0

Fx.Height = Class.create();
Fx.Height.prototype = Object.extend(new Fx.Base(), {

	initialize: function(el, options){
		this.element = $(el);
		this.setOptions(options);
		this.element.style.overflow = 'hidden';
	},

	toggle: function(){
		if (this.element.offsetHeight > 0) return this.custom(this.element.offsetHeight, 0);
		else return this.custom(0, this.element.scrollHeight);
	},

	show: function(){
		return this.set(this.element.scrollHeight);
	},

	increase: function(){
		this.setStyle(this.element, 'height', this.now);
	}

});

Fx.Width = Class.create();
Fx.Width.prototype = Object.extend(new Fx.Base(), {

	initialize: function(el, options){
		this.element = $(el);
		this.setOptions(options);
		this.element.style.overflow = 'hidden';
		this.iniWidth = this.element.offsetWidth;
	},

	toggle: function(){
		if (this.element.offsetWidth > 0) return this.custom(this.element.offsetWidth, 0);
		else return this.custom(0, this.iniWidth);
	},

	show: function(){
		return this.set(this.iniWidth);
	},

	increase: function(){
		this.setStyle(this.element, 'width', this.now);
	}

});

Fx.Opacity = Class.create();
Fx.Opacity.prototype = Object.extend(new Fx.Base(), {

	initialize: function(el, options){
		this.element = $(el);
		this.setOptions(options);
		this.now = 1;
	},

	toggle: function(){
		if (this.now > 0) return this.custom(1, 0);
		else return this.custom(0, 1);
	},

	show: function(){
		return this.set(1);
	},
	
	increase: function(){
		this.setStyle(this.element, 'opacity', this.now);
	}

});

//Ticker

var currentNews = 0;
var intTickSpeed = 5000;

function buttonDown(obj) {
  if (!arrNewsItems.length)
    return;
    	
  obj.style.cssText = "margin: 7px 5px 0px 2px;";
}

function buttonUp(obj) {
  if (!arrNewsItems.length)
    return;	
	
  obj.style.cssText = "";
}

function nextNews() {
  setNews(currentNews);
}

function prevNews() {
  setNews(currentNews-2);
}

function initTicker() {
  if (!arrNewsItems.length)
    return;
    
  $("ticker").onmouseover = stopTicker;
  $("ticker").onmouseout = resumeTicker;
  $("back").onclick = prevNews;
  $("next").onclick = nextNews;
  $("back").onmouseover = stopTicker;
  $("next").onmouseover = stopTicker;
  $("next").onmouseout = resumeTicker;
  $("back").onmouseout = resumeTicker;
  
  playTicker();
}

function stopTicker() {
  clearTimeout(autoTimerID);
}

function resumeTicker() {
  clearTimeout(autoTimerID);
  autoTimerID = self.setTimeout("playTicker()", intTickSpeed);
}

function playTicker() {
  setNews(currentNews);	
  autoTimerID = self.setTimeout("playTicker()", intTickSpeed);
}

function setNews(intPos)
{	
  if (arrNewsItems.length < intPos+1)
    intPos = 0;	
  else if (intPos < 0)
    intPos = arrNewsItems.length - 1;  
    
  strResults = '';
  strResults += '<div id="typer"><img src="/images/typer.gif" width="8" height="10" class="typerimg"></div><table border="0" cellpadding="0" cellspacing="0"><tr><td class="tickContent"><a class="tickerlnk" href="' + arrNewsItems[intPos][1] + '" target="_top">';
  strResults += arrNewsItems[intPos][0] + '</a></td></tr></table>';
  $("ticker").innerHTML = strResults;
  efekt = new Fx.Style('typer','width',{duration:700,onComplete:function(){
  	$('typer').style.visibility = "hidden";
  }
  });
  efekt._start($('typer').offsetWidth,0); /* efekt._start($('typer').offsetWidth,0); */
  currentNews = intPos+1;
}

function printThis()
{
  document.styleSheets[0].disabled=true;	
  document.styleSheets[1].disabled=false;
  window.print();
  setTimeout('printDone()', 700);
}

function printDone()
{
  document.styleSheets[1].disabled=true;	
  document.styleSheets[0].disabled=false;
}

//End

function CheckLogin(formObj,msg1,msg2,msg3)
{
  var usrVal = document.forms[formObj].elements['cuser'].value;
  var pasVal = document.forms[formObj].elements['cpass'].value;
  
  if (usrVal == "" && pasVal == "")
  {
    window.alert(msg1);	
    document.forms[formObj].elements['cuser'].focus();
  	return false;
  }
  else if (usrVal == "")
  {
  	window.alert(msg2);	
  	document.forms[formObj].elements['cuser'].focus();
  	return false;
  }
  else if (pasVal == "")
  {
  	window.alert(msg3);
  	document.forms[formObj].elements['cpass'].focus();	
  	return false;
  }
  else
    return true;
}

//Menu Functions

function menuOver(obj)
{
  obj.style.cssText = "color:#cd9e40;background:#e2dddb;cursor:pointer;";
}

function menuOut(obj)
{
  obj.style.cssText = "color:white;background:none;cursor:none;";
}

function menuClick(url)
{
  location.href = url;	
}

//End

//Doc switcher

var currentDoc = -1;
//var maxDoc = 3;
//var timerSpeed = 8000; //milsec
//var normalBG = '#eceff0';
//var selectedBG = '#d1d3d4';
  
function switchDoc(obj,val)
{
    for(i=0;i<maxDoc; i++)
    {
      if($('first_doc_bg'+i))
    	$('first_doc_bg'+i).className='first_doc_slides';
      
      $('first_doc_sc'+i).style.display='none';
    }
    $('first_doc_sc'+obj).style.display=val;
    
    if($('first_doc_bg'+obj))
      $('first_doc_bg'+obj).className='slides_selected';
}
  
function nextDoc()
{
    if (currentDoc < maxDoc-1)
      currentDoc++;    
    else
      currentDoc = 0;
      
    switchDoc(currentDoc,'block');
}
  
function preDoc()
{
    if (currentDoc == 0)
      currentDoc = maxDoc - 1;    
    else
      currentDoc--;
    
    switchDoc(currentDoc,'block');
}
  
function playDocs() {
    nextDoc();
    
    if (maxDoc > 1)	
      autoTimerID = window.setTimeout("playDocs()", timerSpeed);
}
  
function stopDocs() {
	
	if (maxDoc <= 1)
	  return;
	  
    clearTimeout(autoTimerID);
}

function resumeDocs() {
	
	if (maxDoc <= 1)
	  return;
	
    clearTimeout(autoTimerID);
    autoTimerID = window.setTimeout("playDocs()", timerSpeed);
}
function getMaxHeight(divName,divNumber) {
	if (divNumber <= 1)
	  return;
	  
	var maxHeight=0;
    for(i=0;i<divNumber; i++)
    {
    	if ($(divName + i).style.display == "none")
    	{
	      $(divName + i).style.display = "block";	
	      if ($(divName + i).offsetHeight > maxHeight)
	      	maxHeight = $(divName +i).offsetHeight;
	      $(divName + i).style.display = "none";
    	}
    	else
    	{
	      if ($(divName + i).offsetHeight > maxHeight)
	      	maxHeight = $(divName +i).offsetHeight;
    	}
    }
    
    for(i=0;i<divNumber; i++)
    {
      $(divName + i).style.height = maxHeight;
    }
}
//End

//Tab Script

function SwitchDiv(CurrentSel,tabPrefix)
{
  var buttonObj = $(tabPrefix+'_tab_button'+CurrentSel);	
  var ContentObj = $(tabPrefix+'_tab_content'+CurrentSel);
  buttonObj.className = "tab_button_sel";
  ContentObj.style.display='block';
  
  var tabCounter = eval(tabPrefix+'TabCounter');
  
  for (i=0; i<tabCounter; i++)
  {
  	if (i == CurrentSel)
  	  continue;
  	var buttonObj = $(tabPrefix+'_tab_button'+i);	
    var ContentObj = $(tabPrefix+'_tab_content'+i);
    
    if (!buttonObj || !ContentObj)
      continue;
      
    buttonObj.className = "tab_button";
    ContentObj.style.display='none';
  }
}

function switchMyTab(CurrentSel,tabPrefix)
{
  var buttonObjRight = $(tabPrefix+'tab_bt_right'+CurrentSel);
  var buttonObj = $(tabPrefix+'tab_bt'+CurrentSel);
  var buttonObjLeft = $(tabPrefix+'tab_bt_left'+CurrentSel);

  var ContentObj = $(tabPrefix+'tab_content'+CurrentSel);
  
  buttonObjRight.className = "sidetab_title_selected_right";
  buttonObj.className = "sidetab_title_selected";
  buttonObjLeft.className = "sidetab_title_selected_left";
  
  ContentObj.style.display='block';
  
  //var tabCounter = eval(tabPrefix+'TabCounter');
  var tabCounter = 4;
  
  for (i=0; i<tabCounter; i++)
  {
  	if (i == CurrentSel)
  	  continue;

	var buttonObjRight = $(tabPrefix+'tab_bt_right'+i);
  	var buttonObj = $(tabPrefix+'tab_bt'+i);
	var buttonObjLeft = $(tabPrefix+'tab_bt_left'+i);
    var ContentObj = $(tabPrefix+'tab_content'+i);
    
    if (!buttonObj || !ContentObj)
      continue;

	buttonObjRight.className = "sidetab_title_right";
	buttonObj.className = "sidetab_title";
	buttonObjLeft.className = "sidetab_title_left";
    ContentObj.style.display='none';
  }
}
//End
