var is_ie = (navigator.userAgent.indexOf('MSIE') > -1);
function PreviewArticle(evt, obj)
{
    if (this.FCKeditorAPI && this.FCKeditorAPI.Instances.ArticleText)
    {
        var command = this.FCKeditorAPI.Instances.ArticleText.Commands.GetCommand('MyPreview');
        if (command != null)
        {
            command.Execute();
        }
    }
}

function EventStop(evt)
{
    if (evt.preventDefault)
        evt.preventDefault();

    if (evt.stopPropagation)
        evt.stopPropagation();

    evt.cancelBubble = true;
    evt.returnValue = false;

    evt.stopped = true;

}

function ChangePassword(obj)
{
    var trpassword1 = document.getElementById('trpassword1');
    var trpassword2 = document.getElementById('trpassword2');
    
    if (obj.checked)
    {
        var style = (is_ie ? 'block' : 'table-row');
        trpassword1.style.display = style;
        trpassword2.style.display = style;
    }
    else
    {
        trpassword1.style.display = 'none';
        trpassword2.style.display = 'none';
    }
    return true;
}

function CallLink(url)
{
    document.location.href = url;
    return false;
}

function GetLink(element, param)
{
  //var element = document.getElementById(obj.name);
  var link = param + element.value;
  return link;
}

function confirmDialog(obj, evt, translation)
{
    if (confirm('Are you sure you want to delete this?'))
    {
        return true;
    }
    else
    {
        EventStop(evt);
        return false;
    }
}

function SwitchOnTextPhoto(obj, evt, id)
{
 if (obj.expanded != true)
   obj.expanded = false;
    
  var newStyle = 'inline';
  if (obj.expanded == true)
  {
    newStyle = 'none';
  }
  else
  {
    obj.style.display ='none';
    var editPhotoDiv = document.getElementById('btsavephotoedit'+ id);
   
    if(editPhotoDiv != null)
    {
      editPhotoDiv.style.display = 'block';
    }
  }
  
  var elementlb = document.getElementById('lb' + id);
  var element = document.createElement('input');
  element.setAttribute('type' , 'text');
  element.setAttribute('class', 'txtbtunderphoto');
  element.style.textAlign = 'center'; 
  element.style.marginTop = '-2px';
  element.style.marginBottom = '0px';
  element.style.fontSize = '12px';
  element.style.width = '190px';
  element.style.border = '1px solid green';
  element.style.borderTop = 'none';
  element.setAttribute('value',elementlb.innerHTML);
  element.setAttribute('name','tb'+ id);
  element.setAttribute('id', 'tb'+ id);
  element.style.display = newStyle;
  
  var txtunderphoto = document.getElementById('txtunderphoto'+ id);
  txtunderphoto.style.display = 'inline';
  txtunderphoto.appendChild(element);
  element.focus();
  if(newStyle == 'none')
  {
    elementlb.style.display = 'block';
  }
  else
  {
    elementlb.style.display = 'none';
  }
  
  obj.expanded = !obj.expanded;
}

function SaveAllPhotos()
{
  var hidden = document.getElementById('typeOfAction');
  if(hidden != null)
  {
    hidden.setAttribute('value', 'saveAllPhotos'); 
  }
  document.changePhotoform.submit();
  
}



function DeletePhoto(obj, evt, id)
{
  var form = document.getElementById(obj);
  if(form != null)
  {
    var hiddenButton = document.createElement("button");
    hiddenButton.setAttribute('type', 'hidden');
    hiddenButton.setAttribute('value', id);
    form.appendChild(hiddenButton);
    document.form.submit();
  }
}


/*function SwitchOnTextPhoto(obj, evt, id)
{
 if (obj.expanded != true)
   obj.expanded = false;
    
  var newStyle = 'inline';
  if (obj.expanded == true)
  {
    newStyle = 'none';
  }
  else
  {
    obj.style.display ='none';
    var editPhotoDiv = document.getElementById('btsavephotoedit'+ id);
   
    if(editPhotoDiv != null)
    {
      editPhotoDiv.style.display = 'block';
    }
  }
  var element = document.getElementById('tb' + id);
  element.style.display = newStyle;
  var elementlb = document.getElementById('lb' + id);
  
  if(newStyle == 'none')
  {
    elementlb.style.display = 'block';
  }
  else
  {
    elementlb.style.display = 'none';
  }
  
  obj.expanded = !obj.expanded;
}*/




var headermenu = function() 
{
    var t = 15,
    z = 50,
    s = 6,
    a;
    function dd(n) 
    {
        this.n = n;
        this.h = [];
        this.c = []
    };
    dd.prototype.init = function(p, c) 
    {
        a = c;
        var w = document.getElementById(p),
        s = w.getElementsByTagName('ul');
        l = s.length;
        i = 0;
        for (i; i < l; i++) 
        {
            var h = s[i].parentNode;
            this.h[i] = h;
            this.c[i] = s[i];
            h.onmouseover = new Function(this.n + '.st(' + i + ',true)');
            if (is_ie)
            {
                h.onmouseleave = new Function(this.n + '.st(' + i + ')');
            }
            else h.onmouseout = new Function(this.n + '.st(' + i + ')');
        }
    };
    dd.prototype.st = function(x, f) 
    {
        var c = this.c[x];
        changeDisplayTopMenuItem(x, f, c);        
        h = this.h[x];
        p = h.getElementsByTagName('a')[0];
        clearInterval(c.t);
        c.style.overflow = 'hidden';
        if (f) 
        {
            p.className += ' ' + a;
            if (!c.mh) 
            {
                c.style.display = 'block';
                c.style.height = '';
                c.mh = c.offsetHeight;
                c.style.height = '0px';
            }
            if (c.mh == c.offsetHeight) 
            {
                c.style.overflow = 'visible';
            }
            else 
            {
                c.style.zIndex = z;
                z++;
                c.t = setInterval(function() 
                  {
                      sl(c, 1);
                  },
                  t);
            }
        } 
        else 
        {
            p.className = p.className.replace(a, '');
            c.t = setInterval(function() 
              {
                  sl(c, -1);
              },
              t);
        }
    };
    function sl(c, f) 
    {
        var h = c.offsetHeight;
        if ((h <= 1 && f != 1) || (h >= c.mh && f == 1)) 
        {
            if (f == 1) 
            {
                c.style.filter = '';
                c.style.opacity = 1;
                c.style.overflow = 'visible';
            }
            clearInterval(c.t);
            return;
        }
        var d = (f == 1) ? Math.ceil((c.mh - h) / s) : Math.ceil(h / s);
        o = h / c.mh;
        c.style.opacity = o;
        c.style.filter = 'alpha(opacity=' + (o * 100) + ')';
        c.style.height = h + (d * f) + 'px';
    };
    return    {
        dd: dd
    }
} ();


var isIe = false;

function getNewXMLHttpRequest()
{
    var request;
    if (typeof(XMLHttpRequest) != "undefined")
	    request = new XMLHttpRequest();
	else if (typeof(ActiveXObject) != "undefined")
	{
	    isIe = true;
	    try
	    {
	        if(request == null)
	        { 
	            request = new ActiveXObject("Msxml2.XMLHTTP.4.0"); 
	        }
	    }
	    catch(e)
	    {
	        request = new ActiveXObject("Microsoft.XMLHTTP"); 
	    }
	}
    
	return request;
}

/**Scroller*/
 
function jsScroller (o, w, h) 
{
	var self = this;
	var list = o.getElementsByTagName("div");
	for (var i = 0; i < list.length; i++) 
  {
		if (list[i].className.indexOf("Scroller-Container") > -1) 
    {
			o = list[i];
		}
	}
	
	//Private methods
	this._setPos = function (x, y) 
  {
		if (x < this.viewableWidth - this.totalWidth) 
			x = this.viewableWidth - this.totalWidth;
		if (x > 0) x = 0;
		if (y < this.viewableHeight - this.totalHeight) 
			y = this.viewableHeight - this.totalHeight;
		if (y > 0) y = 0;
		this._x = x;
		this._y = y;
		
		with (o.style) 
    {
			left = this._x +"px";
			top  = this._y +"px";
		}
	};
	
	//Public Methods
	this.reset = function () 
  {
		this.content = o;
		this.totalHeight = o.offsetHeight;
		this.totalWidth	 = o.offsetWidth;
		this._x = 0;
		this._y = 0;
		with (o.style) {
			left = "0px";
			top  = "0px";
		}
	};
	this.scrollBy = function (x, y) 
  {
		this._setPos(this._x + x, this._y + y);
	};
	this.scrollTo = function (x, y) 
  {
		this._setPos(-x, -y);
	};
	this.stopScroll = function () 
  {
		if (this.scrollTimer) window.clearInterval(this.scrollTimer);
	};
	this.startScroll = function (x, y) 
  {
		this.stopScroll();
		this.scrollTimer = window.setInterval(
			function(){ self.scrollBy(x, y); }, 40
		);
	};
	this.swapContent = function (c, w, h) 
  {
		o = c;
		var list = o.getElementsByTagName("div");
		for (var i = 0; i < list.length; i++) {
			if (list[i].className.indexOf("Scroller-Container") > -1) {
				o = list[i];
			}
		}
		if (w) this.viewableWidth  = w;
		if (h) this.viewableHeight = h;
		this.reset();
	};
	
	//variables
	this.content = o;
	this.viewableWidth  = w;
	this.viewableHeight = h;
	this.totalWidth	 = o.offsetWidth;
	this.totalHeight = o.offsetHeight;
	this.scrollTimer = null;
	this.reset();
};

/*Scrollbar*/
 function jsScrollbar (o, s, a, ev) {
	var self = this;
	
	this.reset = function () {
		//Arguments that were passed
		this._parent = o;
		this._src    = s;
		this.auto    = a ? a : false;
		this.eventHandler = ev ? ev : function () {};
		//Component Objects
		this._up   = this._findComponent("Scrollbar-Up", this._parent);
		this._down = this._findComponent("Scrollbar-Down", this._parent);
		this._yTrack  = this._findComponent("Scrollbar-Track", this._parent);
		this._yHandle = this._findComponent("Scrollbar-Handle", this._yTrack);
		//Height and position properties
		this._trackTop = findOffsetTop(this._yTrack);
		this._trackHeight  = this._yTrack.offsetHeight;
		this._handleHeight = this._yHandle.offsetHeight;
		this._x = 0;
		this._y = 0;
		//Misc. variables
		this._scrollDist  = 5;
		this._scrollTimer = null;
		this._selectFunc  = null;
		this._grabPoint   = null;
		this._tempTarget  = null;
		this._tempDistX   = 0;
		this._tempDistY   = 0;
		this._disabled    = false;
		this._ratio = (this._src.totalHeight - this._src.viewableHeight)/(this._trackHeight - this._handleHeight);
		
		this._yHandle.ondragstart  = function () {return false;};
		this._yHandle.onmousedown = function () {return false;};
		this._addEvent(this._src.content, "mousewheel", this._scrollbarWheel);
		this._removeEvent(this._parent, "mousedown", this._scrollbarClick);
		this._addEvent(this._parent, "mousedown", this._scrollbarClick);
		this._addEvent(document, "DOMMouseScroll", this._domScrollBarWheel);
		
		this._src.reset();
		with (this._yHandle.style) {
			top  = "0px";
			left = "0px";
		}
		this._moveContent();
		
		if (this._src.totalHeight < this._src.viewableHeight) {
			this._disabled = true;
			this._yHandle.style.visibility = "hidden";
			if (this.auto) this._parent.style.visibility = "hidden";
		} else {
			this._disabled = false;
			this._yHandle.style.visibility = "visible";
			this._parent.style.visibility  = "visible";
		}
	};
	
	this._domScrollBarWheel = function(e)
	{
	   if (findParent(e.originalTarget, document.getElementById(scrollbarContainer)))
     {  
        //var dummyEvent = new Object();
        //dummyEvent.target = document.getElementById(scrollbarId);
        self._scrollbarWheel(e);
        return false;
     }
     return true;
  }
  
  this._getDelta = function(evt) 
  { 
    var delta = 0; 
    if (evt.wheelDelta) 
    { 
      delta = evt.wheelDelta / 120; 
    } 
    else if (evt.detail) 
    {
       delta = -evt.detail / 3; 
      
    } 
    
    if (delta > 0) return -1;
    else return 1;
    //return -delta; 
  }
	
	this._addEvent = function (o, t, f) {
		if (o.addEventListener) 
    {
      o.addEventListener(t, f, false);
    }
		else if (o.attachEvent) o.attachEvent('on'+ t, f);
		else o['on'+ t] = f;
	};
	this._removeEvent = function (o, t, f) {
		if (o.removeEventListener) o.removeEventListener(t, f, false);
		else if (o.detachEvent) o.detachEvent('on'+ t, f);
		else o['on'+ t] = null;
	};
	this._findComponent = function (c, o) {
		var kids = o.childNodes;
		for (var i = 0; i < kids.length; i++) {
			if (kids[i].className && kids[i].className == c) {
				return kids[i];
			}
		}
	};
	//Thank you, Quirksmode
	function findOffsetTop (o) {
		var t = 0;
		if (o.offsetParent) {
			while (o.offsetParent) {
				t += o.offsetTop;
				o  = o.offsetParent;
			}
		}
		return t;
	};
	this._scrollbarClick = function (e) {
		if (self._disabled) return false;
		
		e = e ? e : event;
		if (!e.target) e.target = e.srcElement;
		
		if (e.target.className.indexOf("Scrollbar-Up") > -1) self._scrollUp(e);
		else if (e.target.className.indexOf("Scrollbar-Down") > -1) self._scrollDown(e);
		else if (e.target.className.indexOf("Scrollbar-Track") > -1) self._scrollTrack(e);
		else if (e.target.className.indexOf("Scrollbar-Handle") > -1) self._scrollHandle(e);
		
		self._tempTarget = e.target;
		self._selectFunc = document.onselectstart;
		document.onselectstart = function () {return false;};
		
		self.eventHandler(e.target, "mousedown");
		self._addEvent(document, "mouseup", self._stopScroll, false);
		
		return false;
	};
	this._scrollbarDrag = function (e) {
		e = e ? e : event;
		var t = parseInt(self._yHandle.style.top);
		var v = e.clientY + document.body.scrollTop - self._trackTop;
		with (self._yHandle.style) {
			if (v >= self._trackHeight - self._handleHeight + self._grabPoint)
				top = self._trackHeight - self._handleHeight +"px";
			else if (v <= self._grabPoint) top = "0px";
			else top = v - self._grabPoint +"px";
			self._y = parseInt(top);
		}
		
		self._moveContent();
	};
	this._scrollbarWheel = function (e) {
		e = e ? e : event;
		var dir = self._getDelta(e);
		//if (e.wheelDelta >= 120) dir = -1;
		//if (e.wheelDelta <= -120) dir = 1;
		
		self.scrollBy(0, dir * 20);
		e.returnValue = false;
		if(e.preventDefault)
			e.preventDefault();
		return false;
	};
	this._startScroll = function (x, y) {
		this._tempDistX = x;
		this._tempDistY = y;
		this._scrollTimer = window.setInterval(function () {
			self.scrollBy(self._tempDistX, self._tempDistY); 
		}, 40);
	};
	this._stopScroll = function () {
		self._removeEvent(document, "mousemove", self._scrollbarDrag, false);
		self._removeEvent(document, "mouseup", self._stopScroll, false);
		
		if (self._selectFunc) document.onselectstart = self._selectFunc;
		else document.onselectstart = function () { return true; };
		
		if (self._scrollTimer) window.clearInterval(self._scrollTimer);
		self.eventHandler (self._tempTarget, "mouseup");
	};
	this._scrollUp = function (e) {this._startScroll(0, -this._scrollDist);};
	this._scrollDown = function (e) {this._startScroll(0, this._scrollDist);};
	this._scrollTrack = function (e) {
		var curY = e.clientY + document.body.scrollTop;
		this._scroll(0, curY - this._trackTop - this._handleHeight/2);
	};
	this._scrollHandle = function (e) {
		var curY = e.clientY + document.body.scrollTop;
		this._grabPoint = curY - findOffsetTop(this._yHandle);
		this._addEvent(document, "mousemove", this._scrollbarDrag, false);
	};
	this._scroll = function (x, y) {
		if (y > this._trackHeight - this._handleHeight) 
			y = this._trackHeight - this._handleHeight;
		if (y < 0) y = 0;
		
		this._yHandle.style.top = y +"px";
		this._y = y;
		
		this._moveContent();
	};
	this._moveContent = function () {
		this._src.scrollTo(0, Math.round(this._y * this._ratio));
	};
	
	this.scrollBy = function (x, y) {
		this._scroll(0, (-this._src._y + y)/this._ratio);
	};
	this.scrollTo = function (x, y) {
		this._scroll(0, y/this._ratio);
	};
	this.swapContent = function (o, w, h) {
		this._removeEvent(this._src.content, "mousewheel", this._scrollbarWheel, false);
		this._src.swapContent(o, w, h);
		this.reset();
	};
	
	this.reset();
};

function findParent(element, potentialParent)
{
  try
  {
     while(element.parentNode != null && element.parentNode.tagName != null && element.parentNode.tagName.toLowerCase() != 'body')
     {
         if (element == potentialParent)
           return true;
         element = element.parentNode;
     }
   }
   catch(e)
   {
    
   }
   return false;
};



/**/

function changeDisplayTopMenuItem(i, displayed, obj)
{  
  var topmenuitemhover = document.getElementById('topmenuitemhover' + i);
  var beforeWidth = topmenuitemhover.scrollWidth;
  if (beforeWidth == 0)
  {
    beforeWidth = topmenuitemhover.offsetWidth;
  }
      
  topmenuitemhover.className = (displayed ? "active" : "inactive");
  
  var headersubmenuactiv = document.getElementById('headersubmenuactiv'+ i);
  var headersubmenutopend = document.getElementById('headersubmenutopend'+ i);
  var headermenutoprightend = document.getElementById('headermenutoprightend' + i);
  var headermenutopright = document.getElementById('headermenutopright' + i);
  var innerheadermenucontainer = document.getElementById('innerheadermenucontainer' + i); 
  var headermenutopcenteritem = document.getElementById('headermenutopcenteritem' + i);
    
  if(headersubmenuactiv != null)
  {
    if (displayed)
    {
       if (!topmenuitemhover.isDisplayed)
       {
          topmenuitemhover.isDisplayed = true;
          innerheadermenucontainer.style.display = 'block';
          
          var tempWidth = headermenutopcenteritem.scrollWidth;
          if (tempWidth == 0)
          {
            tempWidth = headermenutopcenteritem.offsetWidth;
          }
          
          headersubmenuactiv.style.width = (beforeWidth - 4) + 'px';
                
          headermenutopcenteritem.style.width =  headersubmenuactiv.style.width;
          headersubmenutopend.style.width = (169 - tempWidth) + 'px';
          headersubmenutopend.style.background = 'url(style/headermenutopinvisible2.gif) no-repeat -' + tempWidth + 'px 0px ';
          headersubmenutopend.style.left = (tempWidth + 5) + 'px';
          headermenutopright.style.left = (tempWidth + 4) + 'px';
      }
    }
    else 
    {
      topmenuitemhover.isDisplayed = false;
      headersubmenutopend.style.width = '10px';
      innerheadermenucontainer.style.display = 'none';
      setTimeout(function(){RemoveHeight(innerheadermenucontainer);}, 100);
    }
  }
}

function CheckUserName(username)
{
   var request = getNewXMLHttpRequest();        
                                
  var url = 'index.php?checkUserName=true&userName=' + username;
  request.open("GET", url, false);
  request.send(null);          
  return request.responseText;                     
}

function checkUser(evt, obj)
{
    
    evt.returnValue = true;
    var changePasswordElement = document.getElementById('changePassword');
    if (changePasswordElement == null || changePasswordElement.checked)
    {
        var password1Element = document.getElementById('password1');
        var password2Element = document.getElementById('password2');
        var passwordErrorElement = document.getElementById('passwordError');        
        if (password1Element != null && password2Element != null && passwordErrorElement != null)
        {
            if (password1Element.value != password2Element.value || password1Element.value == '')
            {
                passwordErrorElement.style.display = '';
                evt.returnValue = false;
            }
            else 
            {
                passwordErrorElement.style.display = 'none';
            }
        }
    }
    
    var firstNameElement = document.getElementById('firstName');
    var firstNameErrorElement = document.getElementById('firstNameError');
    if (firstNameElement != null && firstNameErrorElement != null)
    {
        if (firstNameElement.value == '')
        {
            firstNameErrorElement.style.display = '';
            evt.returnValue = false;
        }
        else 
        {
            firstNameErrorElement.style.display = 'none';
        }
    }
    var lastNameElement = document.getElementById('lastName');
    var lastNameErrorElement = document.getElementById('lastNameError');
    if (lastNameElement != null && lastNameErrorElement != null)
    {
        if (lastNameElement.value == '')
        {
            lastNameErrorElement.style.display = '';
            evt.returnValue = false;
        }
        else 
        {
            lastNameErrorElement.style.display = 'none';
        }
    }
    
    var emailElement = document.getElementById('email');
    var emailErrorElement = document.getElementById('emailError');
    var emailError2Element = document.getElementById('emailError2');
    if (emailElement != null && emailErrorElement != null && emailError2Element != null)
    {
        if (/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(emailElement.value))
        {
            emailError2Element.style.display = 'none';
        }
        else
        {
            evt.returnValue = false;
            emailError2Element.style.display = '';
        }
        if (emailElement.value == '')
        {
            emailErrorElement.style.display = '';
            evt.returnValue = false;
        }
        else 
        {
            emailErrorElement.style.display = 'none';
        }
    }
    
    var loginElement = document.getElementById('login');
    var loginErrorElement = document.getElementById('loginError');
    var loginError2Element = document.getElementById('loginError2');
    if (loginElement != null && loginErrorElement != null && loginError2Element != null)
    {
        if (loginElement.value == '')
        {
            loginErrorElement.style.display = '';
            evt.returnValue = false;
        }
        else 
        {
            loginErrorElement.style.display = 'none';
            
            if (CheckUserName(loginElement.value) == "true")
            {
                loginError2Element.style.display = 'none';
            }
            else 
            {
                loginError2Element.style.display = '';
                evt.returnValue = false;
            }
        }
    }

    return evt.returnValue;

}

function RemoveHeight(container)
{
    if (container.style.display == 'none')
        container.style.height = '0px';
}

function getElementsByAttribute(parentElement, searchedTagNames, searchedAttributeName, onlyDescendents , searchedAttributeValue)
{
  var correspodingTagNameElements = null;
  if (onlyDescendents == false)
  {
    correspodingTagNameElements = (searchedTagNames == "*" && parentElement.all) ? parentElement.all : parentElement.getElementsByTagName(searchedTagNames);
  }
  else
  {
    if (searchedTagNames == "*")
    {
      if (parentElement.all)
      {
        correspodingTagNameElements = parentElement.all;
      }
      
      if (correspodingTagNameElements == null)
      {
        correspodingTagNameElements = parentElement.getElementsByTagName("*");
      }
    }
    else
    {
      correspodingTagNameElements = new Array();
      for (var i = 0; i < parentElement.childNodes.length; i++)
      {
        var currentElement = parentElement.childNodes[i];
        if (currentElement.tagName != null 
          && currentElement.tagName.toLowerCase() == searchedTagNames.toLowerCase())
          correspodingTagNameElements.push(currentElement);
      }
    }
  }
  
  var result = new Array();
  var attributeValue = (typeof(searchedAttributeValue) != "undefined") ? new RegExp("(^|\\s)" + searchedAttributeValue + "(\\s|$)", "i") : null;
  
  var currentElement;
  var attribute;
  
  for(var i = 0; i < correspodingTagNameElements.length; i++)
  {
    currentElement = correspodingTagNameElements[i];
    attribute = currentElement.getAttribute && currentElement.getAttribute(searchedAttributeName);
    if(typeof(attribute) == "string" && attribute.length > 0)
    {
      if(typeof(searchedAttributeValue) == "undefined" || (attributeValue && attributeValue.test(attribute)))
      {
        result.push(currentElement);
      }
    }
  }
  return result;
}


function Mouseouttop(obj)
{
   obj.style.background = 'url(style/menu.gif) no-repeat  0px 0px';
}

function Mouseovertop(obj)
{
  obj.style.background = 'url(style/menu.gif) no-repeat  0px -33px';
}

function Mouseoversubmenuli(obj)
{
  //obj.style.width = (obj.clientWidth+10) +'px';
  obj.style.border = '2px solid #34980d';
  obj.style.background = '#7e3909';
}
      
function Mouseoutsubmenuli(obj)
{
  obj.style.border = '2px solid transparent';
  obj.style.background = 'transparent';
}
      
function FireImageRefresh()
{
   var request = getNewXMLHttpRequest();
  
  request.onreadystatechange = function()
	                             {
	                                try
	                                {
	                                    if(request.readyState == 4)
	                                    {
	                                        showNewImage(request.responseText); 
	                                        if(isIe)
	                                        {
	                                            request.abort(); 
	                                            request = null;
	                                        }
	                                    }
	                                 }
	                                 catch(e)
	                                 {
	                                 } 
	                              };
  request.open("GET", "index.php?getNewImage=true");
	request.send(null);                              
}
      
function showNewImage(innerText)
{
  var jsonObj = eval('(' + innerText + ')');
  var bottomImageElement = document.getElementById('bottomImage');
  var bottomImageHref = document.getElementById('bottomImageHref');
  var bottomImageTextElement = document.getElementById('bottomImageText');
  if (bottomImageElement != null && bottomImageTextElement != null && bottomImageHref != null)
  {
      if (jsonObj.src != 'null' && jsonObj.src != null)
      {
        bottomImageElement.src = jsonObj.src;
        bottomImageTextElement.innerHTML = jsonObj.text;
        bottomImageHref.href = jsonObj.href;
      }
  }
}


function scrollbarEvent (o, type) 
{
	if (type == "mousedown") 
  {
    if (o.className == "Scrollbar-Up")
    {
      o.className = 'Scrollbar-Up-Active';
    }
    else if (o.className == "Scrollbar-Down")
    {
      o.className = 'Scrollbar-Down-Active';
    }
    else if (o.className == "Scrollbar-Handle")
    {
      o.className = 'Scrollbar-Handle-Active';
    }
  }
  else if (type == "mouseup") 
  {
    if (o.className == "Scrollbar-Up-Active")
    {
      o.className = 'Scrollbar-Up';
    }
    else if (o.className == "Scrollbar-Down-Active")
    {
      o.className = 'Scrollbar-Down';
    }
    else if (o.className == "Scrollbar-Handle-Active")
    {
      o.className = 'Scrollbar-Handle';
    }
  }

}

function swapIt(o) 
{
	o.blur();
	if (o.className == "current") return false;
  
	//var list = document.getElementById("Navigation").getElementsByTagName("a");
	//for (var i = 0; i < list.length; i++) {
//		if (list[i].className == "current") {
//			list[i].className = "";
//			document.getElementById(list[i].title).y = -scroller._y;
//		}
//		if (list[i].title == o.title) o.className = "current";
//	}
  
	list = document.getElementById("Container").childNodes;
	for (var i = 0; i < list.length; i++) 
  {
		if (list[i].tagName == "DIV") 
      list[i].style.display = "none";
	}
  
	var top = document.getElementById(o.title);
	top.style.display = "block";
	scrollbar.swapContent(top);
	if (top.y) scrollbar.scrollTo(0, top.y);
  
	return false;
}

function FireLoggingInRefresh(logout)
{
   var request = getNewXMLHttpRequest();
  
  request.onreadystatechange = function()
	                             {
	                                try
	                                {
	                                    if(request.readyState == 4)
	                                    {
	                                        HandleUserLogin(request.responseText);
	                                        if(isIe)
	                                        {
	                                            request.abort(); 
	                                            request = null;
	                                        }
	                                    }
	                                 }
	                                 catch(e)
	                                 {
	                                 } 
	                              };                
                                
  var url = 'index.php?logmein=true';
  if (typeof(logout) != "undefined" && logout == true)
  {
    url = 'index.php?logmeout=true';
  }           
  request.open("GET", url, true);
	request.send(null);                              
}

function AppendOpenFile()
{
  //num_of_lines ++; 
  if(document.getElementById('oldphotocategory').style.display == 'none')
  {
    tbfoto = document.getElementById('tbfotonew');
  }
  else
  {
    tbfoto = document.getElementById('tbfotoold');
  }
  var num_of_lines =  tbfoto.rows.length;

  //create row table
  var newTr = document.createElement('tr');
  var newTd = document.createElement('td');
  var newTd2 = document.createElement('td');
  var newTd3 = document.createElement('td');
  var newTd4 = document.createElement('td');
  newTd4.style.width = 350 + "px";
  var txt = document.createTextNode("Photo: ");  
  
  var input = document.createElement('input');  
  input.setAttribute('name', 'fupload' + num_of_lines);  
  input.setAttribute('type' , 'file');
  
  var inputphoto= document.createElement('input');
  inputphoto.setAttribute('name','photolabel' + num_of_lines);
  inputphoto.setAttribute('id','photolabel' + num_of_lines);
  inputphoto.setAttribute('type','text');
  //inputphoto.style.width = 350 + 'px';
  inputphoto.style.width = 100 + "%";

  var lblphoto = document.createElement('label');
  lblphoto.setAttribute('for', 'photolabel' + num_of_lines);  
  //lblphoto.style.marginLeft = 20 + 'px';
  lblphoto.style.textAlign = "left";

  var txtphoto = document.createTextNode(" Description: ");
  lblphoto.appendChild(txtphoto);

  tbfoto.appendChild(newTr); 
  newTr.appendChild(newTd);
  newTd.appendChild(txt); 
  newTd2.appendChild(input); 
  newTd3.appendChild(lblphoto);
  newTd4.appendChild(inputphoto);
  
  newTr.appendChild(newTd2);
  newTr.appendChild(newTd3);
  newTr.appendChild(newTd4);

  initScroller();  

}

function ChangeEditCategory(evt, obj, elementId, disabledObjects)
{
  var element = document.getElementById(elementId);
  var hiddenElement = document.getElementById('typeOfAction');
  var oldAction =  hiddenElement.value;
  if (element != null)
  {
      hiddenElement.value = element.id;
  }
  var result = DisplayElement(evt, obj, elementId, disabledObjects);
  
  if(element.id == "oldphotocategory" || element.id=="newphotocategory")  
  {
    //delete tr
    var table;
    var disableElement = document.getElementById("newphotocategory");
    var visualElement = document.getElementById("oldphotocategory");
    if(element.id == "newphotocategory")
    {
      disableElement = document.getElementById("oldphotocategory");
      visualElement = document.getElementById("newphotocategory");
    }
    
    for(var i=0;i < disableElement.childNodes.length; i++)
    {
      if(disableElement.childNodes[i].tagName == 'TABLE')
      {
        table = disableElement.childNodes[i];
        var numberOfRows = table.rows.length;
        for(var j=numberOfRows-1; j > 0; j--)
        {
          //I must delete, this is open folder in disable part
          table.deleteRow(j);
        }
        if(oldAction != element.id && oldAction != "")
        {
          AppendOpenFile();
        }
        break;
      }
    }
  }

  return result;
}

function DisplayElement(evt, obj, elementId, disabledObjects, callFunction)
{
  var element = document.getElementById(elementId);
  
  if (element != null)
  {
      element.style.display = 'block';
  }
  if (disabledObjects != null)
  {
      for (var i = 0; i < disabledObjects.length; i++)
      {
          var elementX = document.getElementById(disabledObjects[i]);
          if (elementX != null)
          {
              elementX.style.display = 'none';
          }
      }
  }
  
  if (typeof(callFunction) != "undefined" && callFunction != null)
    callFunction;
  
  initScroller();  
}

function CheckedPermission(obj)
{
  var men = document.getElementById('man');
  var woman = document.getElementById('woman');
  var junior = document.getElementById('junior');
  var admin = document.getElementById('admin');
  var publicElement = document.getElementById('public');
  
  if(obj.value == 0)
  {
    men.checked = false;
    woman.checked = false;
    junior.checked = false;
    if (admin != null)
        admin.checked = false;
  }
  else
  {
    publicElement.checked = false;
  }
  
  return true;
}

function CheckFillForm(nameobj)
{
  var element = document.getElementById(nameobj);
  if(element != null)
  {
    if(element.value != null && element.value != "")
    {
      return true;
    }
    else
    {
      alert('The name of category is not fill');
      return false;
    } 
  }
  return true;
}

function changeMenuPosition(evt, obj)
{    
    var parentId = document.getElementById('parentId');
    var itemType = document.getElementById('itemType');
    
    if (parentId != null && itemType != null)
    {
        if (itemType.options[itemType.selectedIndex].value == '0')
        {    
            parentId.options[0].selected = true;
            parentId.disabled = true;
        }
        else parentId.disabled = false;
            
    }
    return true;
}

function changeMenuType(evt, obj)
{
    var linkUrlTypeArticleLink = document.getElementById('linkUrlTypeArticleLink');
    var linkUrlTypeExternalLink = document.getElementById('linkUrlTypeExternalLink');
    var linkUrlTypeInternalSpecialLink = document.getElementById('linkUrlTypeInternalSpecialLink');
    var articleUrl = document.getElementById('articleUrl');
    var externalLink = document.getElementById('externalLink');  
    var internalLink = document.getElementById('internalLink');  
    
    if (linkUrlTypeArticleLink.checked)
    {
        articleUrl.disabled = false;                
        externalLink.disabled = true;
        internalLink.disabled = true;
    }
    else if (linkUrlTypeInternalSpecialLink.checked)
    {
        articleUrl.options[0].selected = true;
        articleUrl.disabled = true;                
        externalLink.disabled = true;
        internalLink.disabled = false;       
    }
    else
    {
        articleUrl.disabled = true;
        articleUrl.options[0].selected = true;
        externalLink.disabled = false;
        internalLink.disabled = true;
    }

    return true;
}


var scriptLoaded = true;