/*** Global ****/

var IE4 = document.all;
var NS6 = document.getElementById && !document.all;
var disappearDelay = 500; // miliseconds

function DynamicHide (node, e) {
if ((IE4 && !node.contains(e.toElement)) ||
(NS6 && e.currentTarget != e.relatedTarget && !NS6_Contains( e.currentTarget, e.relatedTarget ))) 
{
InitTimer( node );
} 
}	

function HideObject (nodeID) {		
var node = document.getElementById( nodeID );

if (typeof node != "undefined") {
if (IE4 || NS6) {
node.style.visibility = "hidden";
node.style.display = 'none';
}
}
}

function ReleaseTimer (node) {		
if (typeof node != "undefined") {
if (typeof node.HideTimer != "undefined") {
clearTimeout( node.HideTimer );
}
}
}

function InitTimer (node) {
if (typeof node != "undefined") {
var callBack = 'HideObject( "' + node.getAttribute( 'id' ) + '" )';			
node.HideTimer = setTimeout( callBack, disappearDelay );
}
}

function NS6_Contains (a, b) {
while (b.parentNode) {
if ((b = b.parentNode) == a)
return true;
}

return false;
}

/*******/

function ToggleSendToFriend() {
sendToFriendForm = document.getElementById('SendToFriendForm');
sendToFriendButton = document.getElementById('SendToFriendButton');

if (sendToFriendForm.style.visibility == "hidden") {
sendToFriendForm.style.visibility = "visible";
sendToFriendForm.style.display = 'block';
} else {
sendToFriendForm.style.visibility = "hidden";
sendToFriendForm.style.display = 'none';
}

//sendToFriendForm.style.left = getposOffset(sendToFriendButton, "left") - sendToFriendForm.offsetWidth + sendToFriendButton.offsetWidth;
sendToFriendForm.style.left = getposOffset(sendToFriendButton, "left") - (sendToFriendForm.offsetWidth / 2) + (sendToFriendButton.offsetWidth / 2);
sendToFriendForm.style.top = getposOffset(sendToFriendButton, "top") + sendToFriendButton.offsetHeight;
}

function ToggleAddComment() {
commentMenu = document.getElementById('CommentMenu');
commentButton = document.getElementById('CommentButton');

commentMenu.style.left = getposOffset(commentButton, "left");
commentMenu.style.top = getposOffset(commentButton, "top") + commentButton.offsetHeight;

if (commentMenu.style.visibility == "hidden") {
commentMenu.style.visibility = "visible";
commentMenu.style.display = 'block';
} else {
commentMenu.style.visibility = "hidden";
commentMenu.style.display = 'none';
}
}

function ToggleGalleryThumbnail(pictureID) {
largeThumbDiv = document.getElementById('SecondaryThumbDiv' + pictureID);
smallThumb = document.getElementById('SmallThumb' + pictureID);

if (largeThumbDiv.className == "secondaryThumbnailHidden") {
largeThumbDiv.className = "secondaryThumbnailPopup";
largeThumbDiv.style.left = getposOffset(smallThumb, "left") - ((largeThumbDiv.offsetWidth - smallThumb.offsetWidth) / 2) + "px";
largeThumbDiv.style.top = getposOffset(smallThumb, "top")	- ((largeThumbDiv.offsetHeight - smallThumb.offsetHeight) / 2) + "px";
setTimeout(function() { largeThumbDiv.style.visibility = "visible"; }, 5);
} else {
largeThumbDiv.className = "secondaryThumbnailHidden";
}
}

function ToggleRateMenu() {
rateMenu = document.getElementById('RateMenu');
rateButton = document.getElementById('RateButton');

rateMenu.style.left = getposOffset(rateButton, "left");
rateMenu.style.top = getposOffset(rateButton, "top") + rateButton.offsetHeight;

if (rateMenu.style.visibility == "hidden") {
rateMenu.style.visibility = "visible";
rateMenu.style.display = 'block';
} else {
rateMenu.style.visibility = "hidden";
rateMenu.style.display = 'none';
}

// Init autohide
if (window.event) {
event.cancelBubble = true;
}

ReleaseTimer( rateMenu );
}

function ToggleRatePostMenu(control) {
rateButton = control.parentNode;
rateMenu = rateButton.nextSibling.nextSibling;

if ((rateButton.id != "RateButton") || (rateMenu.id != "RateMenu"))
return;

rateMenu.style.left = getposOffset(rateButton, "left");
rateMenu.style.top = getposOffset(rateButton, "top") + rateButton.offsetHeight;

if (rateMenu.style.visibility == "hidden") {
rateMenu.style.visibility = "visible";
rateMenu.style.display = 'block';
} else {
rateMenu.style.visibility = "hidden";
rateMenu.style.display = 'none';
}

// Init autohide
if (window.event) {
event.cancelBubble = true;
}

ReleaseTimer( rateMenu );
}

function ToggleSearchMenu() {
searchMenu = document.getElementById('SearchMenu');
searchButton = document.getElementById('SearchButton');

searchMenu.style.left = getposOffset(searchButton, "left");
searchMenu.style.top = getposOffset(searchButton, "top") + searchButton.offsetHeight;

if (searchMenu.style.visibility == "hidden") {
searchMenu.style.visibility = "visible";
searchMenu.style.display = 'block';
} else {
searchMenu.style.visibility = "hidden";
searchMenu.style.display = 'none';
}
}

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function ToggleMenuOnOff (menuName) {
var menu = document.getElementById(menuName);

if (menu.style.display == 'none') {
menu.style.display = 'block';
} else {
menu.style.display = 'none';
}
}

function OpenWindow (target) { 
window.open(target, "_Child", "toolbar=no,scrollbars=yes,resizable=yes,width=400,height=400"); 
}

function OpenPostWindow (target) { 
window.open(target, "_Child", "resizable=yes,width=500,height=700"); 
}

function ShowEditBlock(block) {
block.className = "CommonContentPartBorderOn";
}
function HideEditBlock(block) {
block.className = "CommonContentPartBorderOff";
}

function getCookie(sName) {
var cookie = "" + document.cookie;
var start = cookie.indexOf(sName);
if (cookie == "" || start == -1) 
return "";
var end = cookie.indexOf(';',start);
if (end == -1)
end = cookie.length;
return unescape(cookie.substring(start+sName.length + 1,end));
}
function setCookie(sName, value) {
document.cookie = sName + "=" + escape(value) + ";path=/;";
}
function setCookieForever(sName, value) {
document.cookie = sName + "=" + escape(value) + ";path=/;expires=Fri, 1 Jan 2010 00:00:00 GMT;";
}

function inLineEditOn(control)
{
control.className = "CommonInlineEditOn";
}

function inLineEditOff(control)
{
control.className = "CommonInlineEditOff";
}

//Ajax Start

function Ajax_GetXMLHttpRequest() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else {
if (window.Ajax_XMLHttpRequestProgID) {
return new ActiveXObject(window.Ajax_XMLHttpRequestProgID);
} else {
var progIDs = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
for (var i = 0; i < progIDs.length; ++i) {
var progID = progIDs[i];
try {
var x = new ActiveXObject(progID);
window.Ajax_XMLHttpRequestProgID = progID;
return x;
} catch (e) {
}
}
}
}
return null;
}
function Ajax_CallBack(type, id, method, args, clientCallBack, debugRequestText, debugResponseText, debugErrors, includeControlValuesWithCallBack, url) {
if (!url)
{
url = window.location.href;
url = url.replace(/\#.*$/, '');
if (url.indexOf('?') > -1)
url += "&Ajax_CallBack=true";
else
{
if (url.substr(url.length - 1, 1) == "/")
url += "default.aspx";

url += "?Ajax_CallBack=true";
}
}

var x = Ajax_GetXMLHttpRequest();
var result = null;
if (!x) {
result = { "value":null, "error": "NOXMLHTTP"};
if (debugErrors) {
alert("error: " + result.error);
}
if (clientCallBack) {
clientCallBack(result);
}
return result;
}

x.open("POST", url, clientCallBack ? true : false);
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
if (clientCallBack) {
x.onreadystatechange = function() {
var result = null;

if (x.readyState != 4) {
return;
}

if (debugResponseText) {
alert(x.responseText);
}

try
{
var result = eval("(" + x.responseText + ")");
if (debugErrors && result.error) {
alert("error: " + result.error);
}
}
catch (err)
{
if (window.confirm('The following error occured while processing an AJAX request: ' + err.message + '\n\nWould you like to see the response?'))
{
var w = window.open();
w.document.open('text/plain');
w.document.write(x.responseText);
w.document.close();
}

result = new Object();
result.error = 'An AJAX error occured.	The response is invalid.';
}

clientCallBack(result);
}
}
var encodedData = "Ajax_CallBackType=" + type;
if (id) {
encodedData += "&Ajax_CallBackID=" + id.split("$").join(":");
}
encodedData += "&Ajax_CallBackMethod=" + method;
if (args) {
for (var i in args) {
encodedData += "&Ajax_CallBackArgument" + i + "=" + encodeURIComponent(args[i]);
}
}

if (includeControlValuesWithCallBack && document.forms.length > 0) {
var form = document.forms[0];
for (var i = 0; i < form.length; ++i) {
var element = form.elements[i];
if (element.name) {
var elementValue = null;
if (element.nodeName == "INPUT") {
var inputType = element.getAttribute("TYPE").toUpperCase();
if (inputType == "TEXT" || inputType == "PASSWORD" || inputType == "HIDDEN") {
elementValue = element.value;
} else if (inputType == "CHECKBOX" || inputType == "RADIO") {
if (element.checked) {
	elementValue = element.value;
}
}
} else if (element.nodeName == "SELECT") {
elementValue = element.value;
} else if (element.nodeName == "TEXTAREA") {
elementValue = element.value;
}
if (elementValue) {
encodedData += "&" + element.name + "=" + encodeURIComponent(elementValue);
}
}
}
}
if (debugRequestText) {
alert(encodedData);
}
x.send(encodedData);
if (!clientCallBack) {
if (debugResponseText) {
alert(x.responseText);
}
result = eval("(" + x.responseText + ")");
if (debugErrors && result.error) {
alert("error: " + result.error);
}
}
delete x;
return result;
}

//Ajax End

//Element Items Borrowed From Prototype

function $() {
var elements = new Array();

for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);

if (arguments.length == 1) 
return element;

elements.push(element);
}

return elements;
}


var Element = {

toggle: function() {
for (var i = 0; i < arguments.length; i++) {
			var element = document.getElementById(arguments[i]);
element.style.display = 
(element.style.display == 'none' ? '' : 'none');
}
},

hide: function() {
for (var i = 0; i < arguments.length; i++) {
			var element = document.getElementById(arguments[i]);
element.style.display = 'none';
}
},

show: function() {
for (var i = 0; i < arguments.length; i++) {
			var element = document.getElementById(arguments[i]);
element.style.display = '';
}
},

remove: function(element) {
		element = document.getElementById(element);
element.parentNode.removeChild(element);
},

getHeight: function(element) {
		element = document.getElementById(element);
return element.offsetHeight; 
}
}


//End Element Items

//----- Awelan

var req;
var dropDowns;
var hideGray = false;
var URIPage;
var categories = "categories.aspx";
var regions = "regions.aspx";
var cities = "cities.aspx";
var subjects = "subjects.aspx";
var flipPageAddress;
var flipPageUri = "flipPage.aspx";
var categoriesWhere, categoriesBuffer;

var w3cDOM = (typeof document.getElementById != "undefined" && typeof document.createElement != "undefined") ? true : false;

try {
document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

/* Events */
var pageLoaded = function() {};
function listenEvent (target, type, listener) {
if( target==window && type=='load' ) {
var tmp = pageLoaded;
pageLoaded = function() {tmp();listener();};
} else if (typeof target.addEventListener != "undefined") {
target.addEventListener (type, listener, false);
} else if (typeof target.attachEvent != "undefined") {
target.attachEvent ("on" + type, listener);
}
}
function unlistenEvent (target, type, listener) {
if (typeof target.removeEventListener != "undefined") {
target.removeEventListener (type, listener, false);
} else if (typeof target.detachEvent != "undefined") {
target.detachEvent ("on" + type, listener);
}
}

/* Call to server */
function callToServer(ctrl, url) {
	dropDowns = ctrl;
	for (i in dropDowns){
		dropDowns[i].disabled=true;
	}
if (typeof XMLHttpRequest != "undefined") {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
req.open("GET", url, true);
req.onreadystatechange = clientCallback;
req.send(null);
}

function clientCallback() {
if (req.readyState == 4 && req.status == 200) {
fillClientDropDown();
}
}
 
function fillClientDropDown() {
var ar = req.responseXML.getElementsByTagName("ddItem");
	for (j in dropDowns){
		var dropDown = dropDowns[j];
		dropDown.disabled=false;
dropDown.length = 0;
for (i=0; i < ar.length; ++i) {
newOption = new Option(ar[i].childNodes[0].nodeValue, ar[i].attributes[0].nodeValue);
if (true == hideGray) {
if ("0" == ar[i].attributes[1].nodeValue)
newOption.className = 'kw';
}
			if (ar[i].attributes.length > 2 && j==0){
				if (ar[i].attributes[2].nodeValue == "True")
					newOption.selected = true;
			}
dropDown.options[dropDown.length] = newOption;
}
}
	dropDowns[0].focus();
}

function UpdateRegionsFromServer(id1, id2, id3, id4, mg)
{
    ctrl1 = document.getElementById(id1);
    ctrl2 = document.getElementById(id2);
    if (id3 != ''){
        ctrl3 = document.getElementById(id3);
        if (ctrl3)
            ctrl3.options.length = 0;
        ctrl3 = document.getElementById(id3+"2");
        if (ctrl3)
            ctrl3.options.length = 0;
        ctrl3 = document.getElementById(id3+"3");
        if (ctrl3)
            ctrl3.options.length = 0;        
    }
    if (id4 != ''){
        ctrl4 = document.getElementById(id4);
        if (ctrl4)
            ctrl4.style.display = "none";
        ctrl4 = document.getElementById(id4+"2");
        if (ctrl4)
            ctrl4.style.display = "none";
        ctrl4 = document.getElementById(id4+"3");
        if (ctrl4)
            ctrl4.style.display = "none";                        
    }
hideGray = mg;
var Url = mainURL + regions + "?countryId=" + ctrl2.value;
	callToServer(new Array(ctrl1), Url);
}
function UpdateCitiesFromServer(id1, id2, id3, mg)
{
    ctrl1 = document.getElementById(id1);
    ctrl2 = document.getElementById(id2);
    
    if (id3 != ''){
        ctrl3 = document.getElementById(id3);
        if (ctrl3)
            ctrl3.style.display = "none";
        ctrl3 = document.getElementById(id3+"2");
        if (ctrl3)
            ctrl3.style.display = "none";
        ctrl3 = document.getElementById(id3+"3");
        if (ctrl3)
            ctrl3.style.display = "none";        
}
    var ar = new Array(ctrl1);
    
    ctrl = document.getElementById(id1+"2");
    if (ctrl)
        ar[ar.length] = ctrl;
    ctrl = document.getElementById(id1+"3");
    if (ctrl)
        ar[ar.length] = ctrl;

	hideGray = mg;
	var Url = mainURL + cities + "?regionId=" + ctrl2.value;
	Url = URISetParameter (Url, "lang", lang);
	callToServer(ar, Url);
}
function CityChanged(id1, id2)
{
    ctrl1 = document.getElementById(id1);
    ctrl2 = document.getElementById(id2);
    if (ctrl2.value == "0")
	    ctrl1.style.display = "inline";
	else
	    ctrl1.style.display = "none";
}
function UpdateSubjectsFromServer(ctrl1, ctrl2)
{
var Url = mainURL + subjects + "?lineId=" + ctrl2.value;
	callToServer(new Array(ctrl1), Url);
}

/* Limit length of the input string */
function limitLength(obj, max)
{
if (obj.value.length > max)
obj.value = obj.value.substring(0, max);
}

function cutString(obj, max, message)
{
if (obj.value.length > max)
{
obj.value = obj.value.substring(0, max);
alert(message);
}
}

/* Favourites */
var itemsCount=0;
function checkBoxClick()
{
var list = getCookie( 'clipboard' );
if( list==null ) { list = '' }
else { list = list.replace( /^\*/, '' ); }
if( this.className=='clipboard' ) {
if( clipbordMaxSize && itemsCount >= clipbordMaxSize ) {
var removeElement = list.substr( 0, list.indexOf( '|' ) );
var removeSelectionCheckbox = document.getElementById( 'clipboard'+removeElement );
if( removeSelectionCheckbox ) {
removeSelectionCheckbox.className = 'clipboard';
removeSelectionCheckbox.src = this.src.replace(/star_on/g, 'star_off');
removeSelectionCheckbox.alt = addToFav;
removeSelectionCheckbox.title = addToFav;
}
list = list.replace( /^\w+\W/, '' );
itemsCount--;
}
list += this.value + '|';
itemsCount++;
this.className = 'clipboardIn';
this.src = this.src.replace(/star_off/g, 'star_on');
this.alt = delFromFav;
this.title = delFromFav;
} else if( list.length>0 ) {
list = '|' + list;
		var patern = new RegExp( '\\W+'+this.value+'\\W+', 'g' );
list = list.replace( patern, '|' );
		list = list.replace( /^\W+/g, '' );

itemsCount--;
this.className = 'clipboard';
this.src = this.src.replace(/star_on/g, 'star_off');
this.alt = addToFav;
this.title = addToFav;
}
list = '*' + list; /* this adds additional * as sign that this cookie is from JS*/
setCookie( 'clipboard', list);
if( document.getElementById('favCount') ) {
document.getElementById('favCount').innerHTML = "("+itemsCount+")";
}
}

function clipboard() {
var container;
var clipboardList = getCookie( 'clipboard' );
if( clipboardList ) {
clipboardList = clipboardList.replace( /^\*/, '' );
itemsCount = 0;
for( var i=0; i<clipboardList.length; i++ ) {
if(clipboardList.charAt(i) == '|') itemsCount++;
}
clipboardList = '|' + clipboardList;
} else {
clipboardList = '';
}

if( document.getElementById('favCount') ) {
document.getElementById('favCount').innerHTML = "("+itemsCount+")";
}

if( !(container = document.getElementById('favList')) ) {
return false;
}

var images = container.getElementsByTagName( 'img' );
for( var i = 0; i<images.length; i++ ) {
if( images.item(i).className=='clipboard' ) {
var checkbox = images.item(i);

checkbox.value = checkbox.id.replace( /clipboard/, '' );
if( clipboardList.indexOf( '|' + checkbox.value + '|' )>-1 ) {
checkbox.className = 'clipboardIn';
checkbox.src = checkbox.src.replace(/star_off/g, 'star_on');
checkbox.alt = delFromFav;
checkbox.title = delFromFav;
} else {
checkbox.alt = addToFav;
checkbox.title = addToFav;
}
checkbox.onclick = checkBoxClick;
}
}
}

function initFav()
{
if (w3cDOM) {
clipboard();
}
}

listenEvent(window, 'load', initFav);

/* Gallery */
function SetImageSrc(imgSrc, imgHref, imgAlt)
{
var _img = document.getElementById('demoImg');
if( _img ) {
_img.src = imgSrc;
_img.style.cursor = 'hand';
_img.style.border = '4px solid white';
_img.alt = imgAlt;
}
var _a = document.getElementById('demoA');
if (_a)
_a.href = imgHref;
var _div = document.getElementById('demoDiv');
if (_div)
_div.style.border = 'solid 1px #CDDEEE';
var _span = document.getElementById('demoSpan');
if (_span)
_span.innerHTML = imgAlt;
return false;
}

var _viewPlanExpanded = false;
function ViewPlanExpandCollapse(obj, targetCtrlId, parentDivId, imgSrc)
{
_viewPlanExpanded = !_viewPlanExpanded;
var _img = document.getElementById(targetCtrlId);
var _div = document.getElementById(parentDivId);
var _divPlan = document.getElementById('trPlan');
if( _img ) {
if (_viewPlanExpanded){
_divPlan.style.display = 'block';
obj.innerHTML = hidePlanStr;
_div.style.border = 'solid 1px #C0C0C0';
_img.src = imgSrc;
_img.alt = showPlanStr;
}
else{
_divPlan.style.display = 'none';
obj.innerHTML = showPlanStr;
_div.style.border = 'none';
}
}

}

/* Mutiple category select */

document.getUniqueId = function () {
var prefix = "random";
var suffix;
do {
suffix = Math.round (Math.random () * 1000000000000000000);
} while (typeof document.getElementById (prefix + suffix) == "undefined" && document.getElementById (prefix + suffix) == null);
return prefix + suffix;
}

function shrinkAmpCharEntRefs (string) {
return string.replace (/&amp;/g, "&")
}

function classNameGetId (className) {
return className.replace (/^[^0-9]*/, "");
}

function replaceLastCid(cidStr, newCid)
{
var index = cidStr.lastIndexOf(';');
if (index != -1)
cidStr = cidStr.substring(0, index)
cidStr += ";" + newCid;
return cidStr;
}

function URISetParameter (URI, name, value) {
if (URI.indexOf (name + "=") != -1) {
var re = new RegExp ("(" + name + ")=[^&]*", "");
return URI.replace (re, "$1=" + value);
} else if (URI.indexOf ("?") != -1) {
return URI += ("&" + name + "=" + value);
} else {
return URI += ("?" + name + "=" + value);
}
}

function setCategoriesEventHandling () {
var as = categoriesWhere.getElementsByTagName ("a");
if (as.length == 0) {
cid = 0;
var cidVal = document.getElementById(cidValueField);
cidVal.value += ";0";
}

for (loop = 0; loop < as.length; loop ++) {

if (/^drop[0-9]*$/.test (as.item (loop).className)) {
as.item(loop).style.cursor = 'hand';
as.item (loop).onmouseover = function () {
window.status = this.title;
return true;
}
as.item (loop).onmouseout = function () {
window.status = "";
return true;
}
as.item (loop).onclick = function () {
cid = classNameGetId (this.className);
var cidVal = document.getElementById(cidValueField);
cidVal.value = replaceLastCid(cidVal.value, cid);
URICategories = URISetParameter (URICategories, "cid", cidVal.value);
URICategories = URISetParameter (URICategories, "lang", lang);

categoriesWhere.innerHTML = loading;
window.status = "";
categoriesBuffer.loadData(URICategories);
return false;
}
}
}

if (categoriesWhere.getElementsByTagName ("select").length > 0) {
var select = categoriesWhere.getElementsByTagName ("select").item (0);

select.onchange = function () {

cid = this.options[this.selectedIndex].value;

if (this.selectedIndex != 0) {
var cidVal = document.getElementById(cidValueField);

cidVal.value = replaceLastCid(cidVal.value, cid);
URICategories = URISetParameter (URICategories, "cid", cidVal.value);
URICategories = URISetParameter (URICategories, "lang", lang);
categoriesBuffer.loadData(URICategories);
} 
}
}
}

function rewrite (action) {
switch (action) {
case categories :
categoriesWhere.innerHTML = flush (categoriesBuffer);
setCategoriesEventHandling ();
break;
case flipPageUri:
case flipPageAddress:
case naviAddress:
pagePanel.innerHTML = flush(pageBuffer);
initFav();
break;
}
}

function contextAction(url) {
url = url.replace(/\?.*$/, '');
url = url.replace(mainURL, '');
url = url.replace(mainURL.replace('www', 'referat'), '');
return url;
}

function createBuffer (get) {

var buffer = new Object();
buffer.xml = false;
buffer.iframe = false;
if( get ) {
buffer.loadData = function(url) 
{
var url = URISetParameter(url, 'XMLHttpRequest', 'true');
buffer.xml.open('GET', url, true);

buffer.xml.onreadystatechange = function() {
if (buffer.xml.readyState==4) {
var action = contextAction(url);
var content = buffer.xml.responseText;
if( content.indexOf(action)>-1 ) {
rewrite(action);
} else {
content = content.replace(/\n/g, '');
content = content.replace(/.*<meta http-equiv="Refresh" content="/i, '');
content = content.replace(/".*/i, '');
var delay = Math.ceil(content);
if( delay!='NaN' && delay>0 ) { delay = delay*1000; }
else { delay = 5000; }
setTimeout(function(){buffer.loadData(url);}, delay);
}
}
}

if(document.cookie != '') {
buffer.xml.setRequestHeader('Cookie', document.cookie);
}
buffer.xml.send(null);
}

if (!buffer.xml && typeof XMLHttpRequest!='undefined') {
buffer.xml = new XMLHttpRequest();
}
}

if (!buffer.xml) {
var name = document.getUniqueId ();
try {
var iframe = document.createElement ("iframe");
iframe.style.width = 0;
iframe.style.height = 0;
iframe.style.border = 0;

document.getElementsByTagName ("body").item (0).appendChild (iframe);
buffer.iframe = iframe;
buffer.iframe.setAttribute ("name", name);
buffer.iframe.setAttribute ("id", name);

if (typeof buffer.iframe.location == "undefined") {
buffer.iframe = frames[frames.length - 1];
buffer.iframe.name = name;
buffer.iframe.id = name;
}
} catch (exception) {
/* intended to be IE5-only section - the browser that cannot append an iframe*/
var iframeHTML = '<iframe name="'+name+'" id="'+name+'" style="width:0;height:0;border:0"></iframe>';
document.getElementsByTagName ("body").item (0).insertAdjacentHTML ("beforeEnd", iframeHTML);
buffer.iframe = frames[name];
}

buffer.loadData = function(url) {
buffer.iframe.location = url;
}
}
return buffer;
}


function flush (buffer) {
var content = "";

if(buffer.xml) {
content = buffer.xml.responseText;
} else if (typeof buffer.iframe.contentDocument != "undefined") {
content = buffer.iframe.contentDocument.body.innerHTML;
content = content.replace( /\\"/g, "&quot;" )
buffer.iframe.contentDocument.body.innerHTML = "";
} else if (typeof buffer.iframe.contentWindow != "undefined") {
content = buffer.iframe.contentWindow.document.body.innerHTML;
buffer.iframe.contentWindow.document.body.innerHTML = "";
} else if (typeof buffer.iframe.document!="undefined") {
content = buffer.iframe.document.body.innerHTML;
buffer.iframe.document.body.innerHTML = "";
}
var patern = new RegExp( '<!-- .+ -->', 'g' );
content = content.replace( patern, '' );
return content;
}

function flipPage(obj, panel_id, page){
if (obj)
obj.disabled=true;
pagePanel = document.getElementById(panel_id);
pageBuffer = createBuffer (true);
if (page)
URIPage = URISetParameter (URIPage, "page", page);
pageBuffer.loadData(URIPage);
	return false;
}

function initCategories()
{
categoriesWhere = document.getElementById ("chCat");
categoriesWhere.innerHTML = loading;
categoriesBuffer = createBuffer (true);
URICategories = URISetParameter( URICategories, 'cid', cid );
URICategories = URISetParameter (URICategories, "lang", lang);
categoriesBuffer.loadData(URICategories);
}

function initPos()
{
	posContent = document.getElementById ("posContent");
	setTimeout(tree + '.GenerateHoverPopups()',1000);
}

function clearAll()
{
var cidVal = document.getElementById(cidValueField);
cidVal.value = "";
cid = 0;
URICategories = URISetParameter( URICategories, 'cid', cid );
initCategories();
}

function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}

/* Posluga splitter */
var MIN_WIDTH = 100;
var MAX_WIDTH = 350;
var OFFSET_X=7;

var startX;

var pos_browser_agt=(navigator==null||navigator.userAgent==null)?'':navigator.userAgent.toLowerCase();
var pos_browser_app=(navigator==null||navigator.appVersion==null)?'':navigator.appVersion;
var pos_browser_major=parseInt(pos_browser_app);
var pos_browser_opera=pos_browser_agt.indexOf('opera')!=-1;
var pos_browser_ie=!pos_browser_opera&&(pos_browser_agt.indexOf('msie')!=-1);

function qzAfw(qzgx){return 100;};
function qzAfx(qzgx){return 100;};		

var resizingOffset=0;
var resizingObj;
var resizeDragObject;
	

function qzff(qzbc){
	if(qzbc){
		if(cart_browser_ie){
			qzbc.removeNode(true);
		}else{
			qzbc.parentNode.removeChild(qzbc);
		};
	};
};

function nodeSelect(node){
	var adv=document.getElementById("adv");
	if (adv)
		adv.style.display='none';
	replaceContent(node.GetProperty('Value'));
	setTimeout(tree + '.GenerateHoverPopups()',1000);
}

function curX(qzim){return pos_browser_ie?event.clientX+(document.documentElement&&document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft):qzim.pageX;}

function startResize(qzim,qzgx,id){
	ComponentArt_CancelEvent(qzim);
	resizingObj=document.getElementById(id);
	
//	resizingObj = domObj;
	startX = curX(qzim);
	
	resizeDragObject=document.createElement('table');
	resizeDragObject.cellSpacing=0;
	var tb=document.createElement('tbody');
	resizeDragObject.appendChild(tb);
	var tr=document.createElement('tr');
	tb.appendChild(tr);
	var td=document.createElement('td');
	tr.appendChild(td);
	var div=document.createElement('div');
	div.className="ActiveSplitterBar";
	div.style.width=qzgx.offsetWidth+'px';
	div.style.height=qzgx.offsetHeight+'px';
	div.style.overflow='hidden';
	td.appendChild(div);
	resizeDragObject.style.position='absolute';
	resizeDragObject.style.cursor=qzgx.style.cursor;
	resizeDragObject.style.top=qzAfw(qzgx)+'px';
	resizeDragObject.style.left=qzAfx(qzgx)+'px';

	document.body.insertBefore(resizeDragObject,document.body.firstChild);		
	
	document.onmousemove=resizeHandler;
	document.onmouseup=resizeDone;
	return false;
}

function resizeHandler(qzim){
	ComponentArt_CancelEvent(qzim);
	var off = getposOffset(treeHolder, "left")+OFFSET_X;
	var qzp=curX(qzim)-off;
	if(qzp<MIN_WIDTH){
		qzp=MIN_WIDTH;
	}else if(qzp>MAX_WIDTH){
		qzp=MAX_WIDTH;
	};
	if (resizeDragObject){
		resizeDragObject.style.left=qzp+off-OFFSET_X+'px';
	}
}

function resizeDone(qzim,qzgx){
	var qzp=curX(qzim)- getposOffset(treeHolder, "left")-OFFSET_X ;
	if(qzp<MIN_WIDTH){
		qzp=MIN_WIDTH;
	}else if(qzp>MAX_WIDTH){
		qzp=MAX_WIDTH;
	};
	resizingObj.style.width = qzp+ 'px';
	qzff(resizeDragObject);
	resizeDragObject=null;
	document.onmousemove=null;
	document.onmouseup=null;
	
	return false;	
}

/* encodeToURI
** encodes text to URI standard
*/
function utf8(wide) {
var c, s;
var enc = '';
var i = 0;
while( i<wide.length ) {
c= wide.charCodeAt(i++);
/* handle UTF-16 surrogates*/
if( c>=0xDC00 && c<0xE000 ) { continue;
}
if( c>=0xD800 && c<0xDC00 ) {
if( i>=wide.length ) { continue;
}
s = wide.charCodeAt(i++);
if( s<0xDC00 || c>=0xDE00 ) { continue;
}
c = ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
}
/* output value*/
if( c<0x80 ) { enc += String.fromCharCode(c);
} else if( c<0x800 ) { enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
} else if( c<0x10000 ) { enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
} else { enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
}
}
return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
var s = utf8(s);
var c;
var enc = '';
for (var i= 0; i<s.length; i++) {
if (okURIchars.indexOf(s.charAt(i))==-1) {
enc += '%'+toHex(s.charCodeAt(i));
} else {
enc += s.charAt(i);
}
}
return enc;
}
function encodeToURI(text) {
if( text=='' ) { 
return text;
}
var encodedText = '';
if( typeof encodeURIComponent!='undefined' && encodeURIComponent!=null ) {
encodedText = encodeURIComponent(text);
} else if( typeof encodeURI!='undefined' && encodeURI!=null ) {
encodedText = encodeURI(text);
} else {
/* Need to mimic the JavaScript version
 Netscape 4 and IE 4 and IE 5.0*/
encodedText = encodeURIComponentNew(text);
}
return encodedText;
}
/* encodeToURI
** END
*/
/* Search */
function searchRedirectTo(obj, searchCtrl, whereCtrl, logicCtrl) {
	if (null == searchCtrl)
		return false;
	var keywords = trim(searchCtrl.value).toLowerCase();
	keywords = keywords.replace( /[^a-z0-9_à-ÿ¸³º¿´ ]+/ig, ' ' );
	//keywords = keywords.replace( /\s[^\s]{1,2}\s/ig, ' ' );
	keywords = keywords.replace( /(\s+)/ig, '-' );
	if (keywords.length > 0){
		obj.disabled=true;
		var newUrl = mainURL + "search/" + encodeToURI(keywords) + ".aspx";
		if (whereCtrl){
			
			if (whereCtrl.value != "")
				newUrl = URISetParameter (newUrl, "app", whereCtrl.value);
		}
		if (logicCtrl){
			if (logicCtrl.checked)
				newUrl = URISetParameter (newUrl, "logic", "and");
//			else
//			{
//				var logicOr = document.getElementById("searchLogicOr");
//				if (logicOr != null && logicOr.checked)
//					newUrl = URISetParameter (newUrl, "logic", "or");
//			}
		}
		window.location.href = newUrl;
	}
	return false;
}
function redirectTo(obj, searchCtrl, where, logic) {
obj.disabled=true;
if (null == searchCtrl)
return;
var keywords = trim(searchCtrl.value).toLowerCase();
keywords = keywords.replace( /[^a-z0-9_à-ÿ¸³º¿´ ]+/ig, ' ' );
//keywords = keywords.replace( /\s[^\s]{1,2}\s/ig, ' ' );
keywords = keywords.replace( /(\s+)/ig, ' ' );

if (keywords.length > 0){
var newUrl = mainURL + "search/" + encodeToURI(keywords) + ".aspx";
if (!where){
var app = document.getElementById("appsearch");
if (app != null && app.value != "")
newUrl = URISetParameter (newUrl, "app", app.value);
}else{
newUrl = URISetParameter (newUrl, "app", where);
}
if (!logic){
var logicAnd = document.getElementById("searchLogicAnd");
if (logicAnd != null && logicAnd.checked)
newUrl = URISetParameter (newUrl, "logic", "and");
else
{
var logicOr = document.getElementById("searchLogicOr");
if (logicOr != null && logicOr.checked)
newUrl = URISetParameter (newUrl, "logic", "or");
}
}else{
newUrl = URISetParameter (newUrl, "logic", logic);
}
window.location.href = newUrl;
}
return false;
}
function keyDownDefaultBtn(event, btnCtrl){
if (event.keyCode == 13){
event.returnValue = false;
event.cancel = true;
if (btnCtrl)
btnCtrl.click();
}
}

var extendedVisible = false;
function hideShowExt(){
extendedVisible = !extendedVisible;
if (extendedVisible){
document.getElementById('hideShowBtn').innerHTML = searchBrief;
document.getElementById('hideShowBtn').className = "searchHide";
document.getElementById('extended').style.display = 'block';
}
else{
document.getElementById('hideShowBtn').innerHTML = searchDetailed;
document.getElementById('hideShowBtn').className = "searchShow";
document.getElementById('extended').style.display = 'none';
}
}

/* Shop */
function shopCategorySelect(node){
replaceShopContent(node.GetProperty('Value'));
}
function replaceShopContent(categoryId)
{
pageBuffer = createBuffer (true);
pagePanel = shopContent;
URIShopContent = URISetParameter (URIShopContent, "c", categoryId);
URIShopContent = URISetParameter (URIShopContent, "lang", lang);
URIPage = URISetParameter (URIPage, "c", categoryId);
	
shopContent.innerHTML = loading;
window.status = "";
	
pageBuffer.loadData(URIShopContent);
}