var undefined; // undefined

// Browser
function Browser() {}
Browser.Agent=navigator.userAgent.toLowerCase();
Browser.Version=Browser.Agent.match(/msie ([^;]+);/);
Browser.IE=Browser.Agent.indexOf("msie")!=-1;
Browser.Moz=Browser.Agent.indexOf("gecko")!=-1;
Browser.Opera=Browser.Agent.indexOf("opera")!=-1;
//if (Browser.Opera) Browser.Moz=true;
Browser.Other=Browser.Agent.search(/(msie|mozilla)/i)==-1;
Browser.Version=Browser.Version && Browser.Version.length ? +Browser.Version[1] : null,

Browser.XML=function () {}
Browser.XML.DOM=function () {if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLDOM");else if (document.implementation && document.implementation.createDocument) return document.implementation.createDocument("","",null);}
Browser.XML.HTTP=function () {if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");else if (window.XMLHttpRequest) return new XMLHttpRequest();}

// DOM
function DOM() {}
DOM.Doc=document;

DOM.Get=function (id) {return this.Doc.getElementById(id);}
DOM.Create=function (tag,parent,className) {var el;if (Browser.Moz) el=document.mozCreateElement(tag);else el=this.Doc.createElement(tag);if (parent) parent.appendChild(el);if (className) el.className=className;return el;}
DOM.Event=function (evt,func,o) {if (!o) o=window;if (o.attachEvent) o.attachEvent("on"+evt,func);else if (o.addEventListener) o.addEventListener(evt,func,false);}
DOM.Deevent=function (evt,func,o) {if (!o) o=window;if (o.detachEvent) o.detachEvent("on"+evt,func);else if (o.removeEventListener) o.removeEventListener(evt,func,false);}
DOM.Find=function (o,tag,prop,eq) {tag=tag.toUpperCase();while (o && o!=this.Doc.documentElement && ((prop==undefined && o.tagName!=tag) || (prop && ((eq!=undefined && (o.tagName!=tag || o[prop]!=eq)) || (eq==undefined && o.tagName!=tag))))) o=o.parentNode;return o.tagName==tag ? o : null;}

// Classes
DOM.Classes={};
DOM.Classes.Add=function (el,cls) {if (el) return !this.Contains(el,cls) ? el.className+=" "+cls : el.className;}
DOM.Classes.Remove=function (el,cls) {if (el) return el.className=el.className.replace(new RegExp("\\b"+cls.ToRX()+"\\b"),"");}
DOM.Classes.Contains=function (el,cls) {if (el) return new RegExp("\\b"+cls.ToRX()+"\\b").test(el.className);}
DOM.Classes.Current=function (el,prop) {if (el) return el.currentStyle[prop];}
DOM.Classes.Toggle=function (el,cls) {cls=cls || "hidden";this[this.Contains(el,cls) ? "Remove" : "Add"](el,cls);}

// Img - Over
// DOM.ImgToggle(o);
DOM.ImgToggle=function (o,b) {var src=o.src;var toggle=b==undefined;var rxOff=/([^_])(\.\w+)$/,rxOn=/_(\.\w+)$/;if (toggle) b=rxOff.test(src);if (b) src=src.replace(rxOff,"$1_$2");else src=src.replace(rxOn,"$1");return o.src=src;}

// Positions
DOM.Pos={};
DOM.Pos.X=function (o) {for (var x=0;o;x+=o.offsetLeft,o=o.offsetParent);return x;}
DOM.Pos.Y=function (o) {for (var y=0;o;y+=o.offsetTop,o=o.offsetParent);return y;}

if (Browser.Moz) {
	var mozScript=document.createElement("script");
	mozScript.type="text/javascript";
	mozScript.defer=true;
	mozScript.src="moz._js";
	document.getElementsByTagName("head")[0].appendChild(mozScript);
}

function fnPrintFlash(sFileURL, nWidth, nHeight,id) {
    document.write(fnGetFlash(sFileURL, nWidth, nHeight,id));
}  
function fnGetFlash(sFileURL, nWidth, nHeight,id)
{
  var RetValue = "";
  if (window.ActiveXObject)
	  RetValue += '<object type="application/x-shockwave-flash"' + ((id && id!='')?' id="'+id+'"' : '') + ' width="' + nWidth + '" height="'+ nHeight + '">';
  else
	  RetValue += '<object' + ((id && id!='')?' id="'+id+'"' : '') + ' width="' + nWidth + '" height="'+ nHeight + '" data="' + sFileURL + '">';
  RetValue += '<param name="movie" value="' + sFileURL + '">';
  //document.write('<param name="quality" value="high">');
  if (id && id!='')
      RetValue += '<param name="scale" value="exactfit">';
  RetValue += '<param name="wmode" value="transparent">';
  RetValue += '<embed type="application/x-shockwave-flash" wmode="transparent" ';
  RetValue += 'width="'+nWidth+'" height="'+nHeight+'" src="'+sFileURL+'"/>';
  RetValue += '</object>';
  return RetValue;
}

function fixRendering()
{
  var sidebarMenu = document.getElementById('tdSideCategory');
  var mainMenu = (document.getElementById('divSubMenu0')) ? document.getElementById('divSubMenu0').parentNode.parentNode.parentNode.parentNode : null;
  var mainMenuAs = mainMenu.getElementsByTagName("a");
  if (mainMenuAs !=  null) 
  { mainMenuAs[0].fireEvent("onmouseover"); mainMenuAs[0].fireEvent("onmouseout"); }
  var sidebarMenuAs = sidebarMenu.getElementsByTagName("a");
  if (sidebarMenuAs !=  null) 
  { sidebarMenuAs[0].fireEvent("onmouseover"); sidebarMenuAs[0].fireEvent("onmouseout"); }
}

// handle new top menu design
// this code search particular cell in table to style all column
function findTableUp(obj)
{
    var tabObj = obj;
    var success = true;
    while (tabObj.parentNode.tagName.toLowerCase() != "table")
    {
	    if (tabObj.tagName.toLowerCase() == "body") 
	    { success = false; break; }
	    tabObj = tabObj.parentNode;	
    }
    // return tbody
    if (success) return tabObj;
    return null;
}
function findTable_2ndColumn_FirstRow(tabObj)
{
    var success = true;
    try
    {
		if(navigator.appName.indexOf('Internet Explorer') > -1) {
	    if (tabObj.firstChild.children[1].firstChild.tagName.toLowerCase() != "table")
		    success = false;
		}else{
			if (tabObj.firstChild.childNodes.item(1).firstChild.tagName.toLowerCase() != "table")
		        success = false;
		}
    } 

    catch (e) { success = false; }

    // return inner table
	if(navigator.appName.indexOf('Internet Explorer') > -1)
    { if (success) return tabObj.firstChild.children[1].firstChild; }
	else
    { if (success) return tabObj.firstChild.childNodes.item(1).firstChild; }
    
    return null;
}
function findTable_2ndColumn_LastRow(tabObj)
{
    var success = true;
    try
    {
		if(navigator.appName.indexOf('Internet Explorer') > -1) {
	    if (tabObj.children[2].children[1].firstChild.tagName.toLowerCase() != "table")
		    success = false;
		}else{
			if (tabObj.children[2].childNodes.item(1).firstChild.tagName.toLowerCase() != "table")
		        success = false;
		}
    } 
    catch (e) { success = false; }
    // return inner table
	if(navigator.appName.indexOf('Internet Explorer') > -1)	
    { if (success) return tabObj.children[2].children[1].firstChild; }
	else
    { if (success) return tabObj.children[2].childNodes.item(1).firstChild; }
    
    return null;
}
function setUnderAndAboveCenterCell(obj,cls_down,cls_up)
{
    // to find above need to go 3 levels up
    var tabObj = findTableUp(obj);
    if (tabObj == null) return;
    tabObj = findTableUp(tabObj.parentNode);
    if (tabObj == null) return;
    tabObj = findTableUp(tabObj.parentNode);
    if (tabObj == null) return;
    // now we have tabObj set to main upper table

    var index = null;
    try { index = (obj.index) ? obj.index : obj.getAttribute('index'); }catch(e){}
    if (!index) return;

    // 1st row
    try{
    var tabObj1 = findTable_2ndColumn_FirstRow(tabObj);
    var tdObj1 = findCell(tabObj1,index);
    tdObj1.className = cls_up;
    }
    catch(e){}
    // last row
    try{
    var tabObj2 = findTable_2ndColumn_LastRow(tabObj)
    var tdObj2 = findCell(tabObj2,index);
    tdObj2.className = cls_down;
}
    catch(e){}
}
function setClientWidthUnderAndAboveCenterCell(obj)
{
    var cWidth = obj.clientWidth;
    // to find above need to go 3 levels up
    var tabObj = findTableUp(obj);
    if (tabObj == null) return;
    tabObj = findTableUp(tabObj.parentNode);
    if (tabObj == null) return;
    tabObj = findTableUp(tabObj.parentNode);
    if (tabObj == null) return;
    // now we have tabObj set to main upper table

    var index = null;
    try { index = (obj.index) ? obj.index : obj.getAttribute('index'); }catch(e){}
    if (!index) return;

    // 1st row
    try{
    var tabObj1 = findTable_2ndColumn_FirstRow(tabObj);
    var tdObj1 = findCell(tabObj1,index);
    tdObj1.style.width = cWidth;
    }
    catch(e){}
    // last row
    try{
    var tabObj2 = findTable_2ndColumn_LastRow(tabObj)
    var tdObj2 = findCell(tabObj2,index);
    tdObj2.style.width = cWidth;
}
    catch(e){}
}
function findCell(tabObj, indx)
{
    for (var i=0;i< tabObj.rows.length; i++)
	    for (var j=0;j<tabObj.rows[i].cells.length ;j++ )
		    if (indx == ((tabObj.rows[i].cells[j].index)?
		                 parseInt(tabObj.rows[i].cells[j].index):
		                 parseInt(tabObj.rows[i].cells[j].getAttribute('index'))))
		    { return tabObj.rows[i].cells[j]; }
    return null;
}
function setClientWidthMenu()
{   
    var i = 0;
    var obj = null;
    do {
        obj = document.getElementById('tt' + i);
        if (obj == null) break;
        setClientWidthUnderAndAboveCenterCell(obj);
        i++;
    } while (obj != null);
}

//site "ears" code-----------------------------------------------------------------------------
var objStrip, objLeftEar, objRightEar;
var earTop, hasMenu;
function setEars(s, t, m, isPreview)
{        
    try
    {
        earTop = t;
        hasMenu = m;   
        objStrip = document.getElementById(s);        
        document.getElementById("LeftSpace").innerHTML += "<span id='LeftEar'></span>";
        document.getElementById("RightSpace").innerHTML += "<span id='RightEar'></span>";
        objLeftEar = document.getElementById("LeftEar");
        objRightEar = document.getElementById("RightEar");        
        setEarStyle(objLeftEar,isPreview);
        setEarStyle(objRightEar,isPreview);        
        adjustEars();
        setEarsResize();
    }
    catch(e){}
}

function adjustEars()
{
    try
    {
        adjustEar(objLeftEar);
        adjustEar(objRightEar);
    }
    catch(e) {}
}

function adjustEar(objEar)
{
    var totalWidth = document.body.clientWidth;
    objEar.style.visibility = setEarsVis(totalWidth, objStrip.clientWidth);
    objEar.style.height = objStrip.clientHeight;
    objEar.style.top = getEarTop();
    objEar.style.left = 0;
    objEar.style.width = (totalWidth - getStripWidth())/2;
    objEar.style.display = getDisplayStyle();    
}

function getStripWidth()
{
    if(document.getElementById("tdTopBanner") != null)
        return document.getElementById("tdTopBanner").clientWidth;
    else
        return document.getElementById("tdBottomBanner").clientWidth;
}

function getEarTop()
{    
    var retValue = earTop;
    if(objStrip.id == "tdBottomBanner" && document.getElementById("tdTopBanner") != null)     
        retValue = earTop + document.getElementById("tdTopBanner").clientHeight;    
    if(hasMenu)
        retValue += document.getElementById("topMenuBlock").clientHeight;
    return retValue;        
}

function setEarsVis(totalWidth, stripWidth)
{
    return totalWidth > stripWidth ? "visible" : "hidden";
}

function setEarStyle(objEar,isPreview)
{
    objEar.style.position = "relative";
    objEar.style.zIndex = 100;
    var imgPath = (isPreview) ? document.getElementById('earsUrl').value : "images";
    if(objEar.id == "LeftEar")
    {
        objEar.style.backgroundImage = "url("+imgPath+"/ear_left.gif)";
        objEar.style.backgroundPosition = "right";
    }
    else
    {
        objEar.style.backgroundImage = "url("+imgPath+"/ear_right.gif)";    
        objEar.style.backgroundPosition = "left";
    }
}

function getDisplayStyle()
{
    return navigator.appVersion.indexOf("MSIE") != -1 ? "inline-block" : "-moz-inline-stack";    
}

function setEarsResize()
{
    navigator.appVersion.indexOf("MSIE") != -1 ? window.attachEvent('onresize', adjustEars) : window.onresize = adjustEars;
}
//-----------------------------------------------------------------------------------------------