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);
}

/*********** functions that are used by BuildRealSite.cs on page building process **********/

/*********** function that handle text encoding on page **********/

/*** handle full image popup ***/
function fnopenFullImage(obj){ 
    var popup = window.open('FullImageView.htm?image='+obj,'popup','toolbar=no,location=no,menubar=no,directories=no,scrollbars=1,resizable=0'); 
    popup.focus(); 
}
/*** encoder for client utf-8 characters ***/
function decoder(str) {
    var _string = "";
    var i = 0;
    var c = c1 = c2 = 0;
    while (i < str.length) {
        c = str.charCodeAt(i);
        if (c < 128) { _string += String.fromCharCode(c); i++; }
        else if((c > 191) && (c < 224)) {
            c2 = str.charCodeAt(i+1);
            _string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str.charCodeAt(i+1);
            c3 = str.charCodeAt(i+2);
            _string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
    return _string;
}

function encoder(str){
    //str = str.replace(/\\r\\n/g,'\\n');
    var utftext='',c;
    for (var n=0;n<str.length;n++){
       c = str.charCodeAt(n);
       if (c < 128){utftext += String.fromCharCode(c);}
       else if((c > 127) && (c < 2048)){
          utftext += '%' + ((c >> 6) | 192).toString(16);
          utftext += '%' + ((c & 63) | 128).toString(16);
       }else{
          utftext += '%' + ((c >> 12) | 224).toString(16);
          utftext += '%' + ((c >> 6) & 63).toString(16) | 128;
          utftext += '%' + ((c & 63) | 128).toString(16);
       }
    }
    return utftext;
}
// instended to distinct news links for specific handling
function isNewsLink(obj){
   try { return (obj.parentNode.previousSibling.className.indexOf('news')>-1); }
   catch(e) { return false; }
}
/*** encodes links with utf-8 characters and process target ***/
function fnConvertLinksToEncoded(){
 if(window.location.search.substring(1) == 'thankyou=true')
 { 
         document.getElementById("spMessage").innerHTML  = arrayMessages[0];
 }
    var doEncoding = new String(document.body.getAttribute('lang')) != 'false';
    var links = document.getElementsByTagName('A');
    var arrSplits;
    var linkContent;
    for(var i=0;i<links.length;i++)
    // all links that do not launch javascript fuctions
    if(links[i].href && links[i].href.indexOf('javascript')==-1) {
        // save content in case of '@' in content
       linkContent = links[i].innerHTML;
       if (doEncoding)
       {           
          if (navigator.appVersion.indexOf('MSIE 6.0')>-1)
            links[i].href = encoder(links[i].href).replace(/%c3%97%c2/ig,'%d7').replace(/%c3%83%c2/ig,'%c3').replace(/%c3%85%c2/ig,'%c5');
          else
            links[i].href = encoder(links[i].href);
       }
       else
       {
          /*if (navigator.appVersion.indexOf('MSIE 6.0')>-1)
            links[i].href = dencoder(links[i].href).replace(/%c3%97%c2/ig,'%d7').replace(/%c3%83%c2/ig,'%c3').replace(/%c3%85%c2/ig,'%c5');
          else*/
            links[i].href = dencoder(unescape(links[i].href));
       }
       if (!isNewsLink(links[i]) ||
           ((new String(links[i].getAttribute('target'))).length == 0 ||
            (new String(links[i].getAttribute('Target'))).length == 0)) {
           //if (pDomain.indexOf('localhost') == 0 || 
           if(isLinkWebPage(links[i].href) &&
			  links[i].outerHTML.indexOf('internal_link')>-1 && links[i].innerHTML.indexOf('internal_link')==-1 ||
			  (links[i].href.toLowerCase().indexOf('www' + pDomain.toLowerCase()) > -1 || links[i].href.toLowerCase().indexOf(location.protocol + '//' + pDomain.toLowerCase()) == 0))
               //links[i].href.toLowerCase().indexOf('www' + pDomain.toLowerCase()) > -1 || 
               //links[i].href.toLowerCase().indexOf(location.protocol + '//' + pDomain.toLowerCase()) == 0) && 

               links[i].target = '_self';
           else
               links[i].target = '_blank';
       }
       if (links[i].type=='file') links[i].target = '_blank';
       //fix for contact us link from item
       if (links[i].className.indexOf('linkContact')>-1) links[i].target = '_self';
       
       // fix back link content
	   try
	   {
		  if (linkContent.indexOf('@')>-1)
	          links[i].innerHTML = linkContent;
	   } catch(e){ }
    }
}

//is this link to web page ?
function isLinkWebPage(linkText)
{
    return (linkText.toLowerCase().indexOf('.htm') != -1  || 
            linkText.toLowerCase().indexOf('.html') != -1 ||
            linkText.toLowerCase().indexOf('#') != -1);
}

// for firefox js code support:
function realPreviousSibling(node) {
    var tempNode=node.previousSibling;
    while(tempNode.nodeType!=1) {
        tempNode=tempNode.previousSibling;
    }
    return tempNode;
}
function realNextSibling(node) {
    var tempNode=node.nextSibling;
    while(tempNode.nodeType!=1) {
        tempNode=tempNode.nextSibling;
    }
    return tempNode;
}
/*********** end **************************************************************************/

/*********** function that handle flash on page **********/
function fnPrintFlash(sFileURL, nWidth, nHeight,id) {
    try { document.write(fnGetFlash(sFileURL, nWidth, nHeight,id)); }
    catch (e) { alert('Error loading script:\n'+e.message); }
}  
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 fnPrintFlashAdv(sFileURL, nWidth, nHeight, id, sFVars) {    
    var fvars = new String(sFVars);    
    var fileName = new String(fvars.substring(fvars.lastIndexOf("/")+1));
    var fullFileName = new String(fvars.substring(fvars.indexOf("sMaskSWF=")+9));
    
    sFVars = fvars.replace(/%26/ig,"&");
    
    if(!isCustomFlash(fileName) || sFVars.indexOf("nMaskAlpha=100&nMaskColor=0xFFFFFF") != -1)
    {
        fnPrintFlash(fullFileName, "100%", "100%", "flash");
    }
    else
    {
        if (window.ActiveXObject)
	        document.write("<object type=\"application/x-shockwave-flash\" id=\"" + id + "\" width=\"" + nWidth + "\" height=\""+ nHeight + "\">");
        else
	        document.write("<object FlashVars=\"" + sFVars + "\" type=\"application/x-shockwave-flash\" id=\"" + id + "\" width=\"" + nWidth + "\" height=\""+ nHeight + "\" data=\"" + sFileURL + "\">");
        document.write("<param name=\"movie\" value=\"" + sFileURL + "\">");
        document.write("<param name=\"quality\" value=\"high\">");
        document.write("<param name=\"wmode\" value=\"transparent\">");
        document.write("<param name=\"FlashVars\" value=\"" + sFVars + "\">");
        document.write("</object>");
    }
}

function isCustomFlash(fileName)
{
    return fileName.indexOf(".") == fileName.lastIndexOf(".");
}

/*********** end ******************************************/
// function that simulates a virtual click 
// fixes page components the appear sliding out of place: phase 0
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;
}
//-----------------------------------------------------------------------------------------------