try
{
	var test = jQuery;
}
catch(e)
{
	//Include jQuery library JS
	document.write('<script type="text/javascript" src="/opencms/opencms/js/jquery.js"></script>');
}

//Include jQuery plugins 
document.write('<script type="text/javascript" src="/opencms/opencms/js/jquery.dump.js"></script>');

//Include Page initialization JS
document.write('<script type="text/javascript" src="/opencms/opencms/js/pageInit.js"></script>');

//---------------------Alan: Common functions for different browsers---------------------------------

var browserIsIE = document.all ? true : false;

function getIEVersion()
{
    return parseFloat(window.navigator.appVersion.split("MSIE")[1]);
}

function getSrc(ent)
{
    return (browserIsIE ? ent.srcElement : ent.target);
}

function getEventCode(ent)
{
    return (browserIsIE ? ent.keyCode : ent.which);
}

function getPar(src, dist)
{
    if (dist <= 0)
    {
        return null;
    }

    if (browserIsIE)
    {
        for (var i = 0; i < dist; i++)
        {
            src = src.parentElement;
        }
    }
    else
    {
        for (var i = 0; i < dist; i++)
        {
            src = src.parentNode;
        }
    }
    
    return src;
}

function getChild(index)
{
    return browserIsIE ? index : (index * 2 + 1);
}

function custAttachEvent(obj, ent, func)
{
    if (browserIsIE)
    {
        obj.attachEvent("on" + ent, func);
    }
    else
    {
        obj.addEventListener(ent, func, false);
    }
}

function custDetachEvent(obj, ent, func)
{
    if (browserIsIE)
    {
        obj.detachEvent("on" + ent, func);
    }
    else
    {
        obj.removeEventListener(ent, func, false);
    }
}

//-------------------------------------------------------------------------------------------

//---------------------------Alan: Ajax functions--------------------------------------------

var xmlHttp;
var sResult="";

function createXMLHttpRequest()
{
   if (!xmlHttp)
	{
	    if(window.XMLHttpRequest)
	    {
		    xmlHttp = new XMLHttpRequest();
	    }
	    else if(window.ActiveXObject)
	    {
		    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	    }
	} 
}

function xmlHttpPost(sUrl, sParameter)
{
	sResult="";
	
	createXMLHttpRequest();
		
	try
	{
		xmlHttp.open("POST", sUrl, false);
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlHttp.send(sParameter);
		sResult = xmlHttp.responseText;
	}
	catch(e)
	{
	    alert(e.message);
	}
	
	return sResult;
}

//-------------------------------------------------------------------------------------------

//--------------------------Alan: Get coordinates--------------------------------------------

function Coordinate(el)
{
    this.source = el;
    
    this.x = 0;
    this.y = 0;
    
    while (true)
    {
        this.x += el.offsetLeft;
        this.y += el.offsetTop;
        
        el = el.offsetParent;
        
        if (!el)
        {
            break;
        }
    }
}

//-------------------------------------------------------------------------------------------

//--------------------------Alan: Window size------------------------------------------------

function WindowSize()
{
    var doc = document.documentElement;
    this.width = window.innerWidth || self.innerWidth || (doc&&doc.clientWidth) || document.body.clientWidth;
    this.height = window.innerHeight || self.innerHeight || (doc&&doc.clientHeight) || document.body.clientHeight
}

//-------------------------------------------------------------------------------------------

//--------------------------Alan: Resize page width automatically----------------------------

function getMainDiv()
{
    var items = window.document.forms[0].childNodes;
    var len = items.length;
    
    for (var i = 0; i < len; i++)
    {
        if (('DIV' == items[i].tagName) && ('Main' == items[i].className))
        {
            return items[i];
        }
    }
    
    return null;
}

function getResolution()
{
    try
    {
        xmlHttpPost('../AjaxPost.aspx', 'type=Resolution&w=' + window.screen.width + '&h=' + window.screen.height);
    }
    catch(e)
    {}
}

var rightWidth;
var scrollWidth = 20;
var mainBody;

function resetBodySize(resize)
{
    mainBody = getMainDiv();
    
    if (null == mainBody)
    {
        return;
    }
    
    var minwidth = 777;
    var width = (new WindowSize()).width;
    
    if (width <= minwidth)
    {
        if (mainBody.offsetWidth != minwidth)
        {
            mainBody.style.width = minwidth + 'px';
        }
        
        width = minwidth;
    }
    else
    {
        if (browserIsIE)
        {
            if (mainBody.offsetWidth == minwidth)
            {
                mainBody.style.width = '100%';
            }
        }
        else
        {
            width -= scrollWidth;
            mainBody.style.width = width + 'px';
        }
    }
    
    rightWidth = width - 277;   /*217 + 20 + 20 + 20 = 277*/
    document.getElementById('TopFrame').style.width = (width - (browserIsIE ? 5 * 2 : 5)) + 'px';
    
    if (!resize)
    {
        return;
    }
    
    resetRightWidth();
}

function countFillingHeight()
{
    var diff = (new WindowSize()).height - 132 - 53 - 19 - (browserIsIE ? 0 : 2);
    diff -= document.getElementById('TheMainFrame').offsetHeight;
    diff = (diff > 0) ? diff : 0;
    return diff;
}

function addScrollWidthForFireFox()
{
    with (mainBody)
    {
        style.width = (offsetWidth + 20) + 'px';
    }

    with (document.getElementById('TopFrame'))
    {
        style.width = (offsetWidth + 20) + 'px';
    }
}

function resetRightWidth()
{
    if ((!browserIsIE) && (countFillingHeight() > 0))
    {
        rightWidth += scrollWidth;
        addScrollWidthForFireFox();
    }

    with (document.getElementById('TheMainFrame'))
    {
        style.width = (rightWidth + 217 + 20) + 'px';
    }
    
    try
    {
        with (document.getElementById('TheRightFrame'))
        {
            style.width = rightWidth + 'px';
        }
    }
    catch(e)
    {
        resetBodyHeight();
        return;
    }

    var silverlight = document.getElementById('SilverlightControlHost');
    
    if (!silverlight)
    {
        resetBodyHeight();
        return;
    }
    
    var silverlightBar = document.getElementById('SilverlightBar');
    var breakingNews = document.getElementById('divPanelBreakingNews');
    var featuredPanel = document.getElementById('TodayFeaturedPanel');
    
    var width = rightWidth;
    var width2 = width - 1 * 2;
    
    silverlight.style.width = width + 'px';
    silverlight.style.height = ((width + 277) / 777 * 244) + 'px';
    
    silverlightBar.style.width = width2 + 'px';
    breakingNews.style.width = width2 + 'px';
    featuredPanel.style.width = width + 'px';
    
    i++;
    
    if ((!browserIsIE) || (2 < i))
    {
        ResetPosition();
    }
    
    resetBodyHeight();
}

function resetBodyHeight()
{
    document.getElementById('divBodyDiffbar').style.height = countFillingHeight() + 'px';
}

//-------------------------------------------------------------------------------------------

function preLoading(msg)
{
    if (document.getElementById('loaddiv'))
    {
        return false;
    }

    // Loading...
    var div1 = document.createElement('DIV');
    var div2 = document.createElement('DIV');
    
    div1.id = 'loaddiv';
    div1.style.height = window.document.body.offsetHeight + 'px';
    
    var pagesize = new WindowSize();
    var arrayPageScroll = getPageScroll();
    
    popId = 'loaddivMsg';
    
    with (div2)
    {
        id = popId;
        className = 'NormalFont';
        innerHTML = "<img src='../IMG/progress.gif' />&nbsp;<span>" +
            (((msg) && (msg != '')) ? msg : "Please wait while loading...</span>");
    }
    
    document.forms[0].appendChild(div1);
    div1.appendChild(div2);
    doScroll();
    
    custAttachEvent(window, "scroll", doScroll);
    
    return true;
}


// 添加收藏
function myAddBookmark(title,url) 
{ 
    if ((typeof(window.sidebar) == 'object') && (typeof(window.sidebar.addPanel) == 'function'))
    {
        window.sidebar.addPanel(title,url,""); 
    } 
    else
    { 
        window.external.AddFavorite(url,title); 
    } 
}

function openWin(lnk)
{
	window.open(lnk, "_blank", "");
}


//-----------------Auto Columns Layout----------------
/**
 * Make sure the left column has the same height as content column
 */
function performColumnsLayout()
{

var leftColumn = document.getElementById('col1');
var leftColumnPole = document.getElementById('divLeftM');

if ((!leftColumn) || (!leftColumnPole))
{
  return;
}

var mainColumnHeight = document.getElementById('col2')? document.getElementById('col2').offsetHeight : 0;
var rightColumnHeight = document.getElementById('col3')? document.getElementById('col3').offsetHeight : 0;

var contentHeight = Math.max(mainColumnHeight, rightColumnHeight);

//store original height of the left column
if(!leftColumn.originalHeight)
	leftColumn.originalHeight = leftColumn.offsetHeight;

if (leftColumn.originalHeight < contentHeight)
{
   //increase to content height
   leftColumnPole.style.height = contentHeight + "px";
}
else
{

  //shrink to default height
  leftColumnPole.style.height = leftColumn.originalHeight;
}
 

}
//---------------------------------------------



//-----------------Content Control-------------
function displayListBoxTitles()
{
	
var col1 = document.getElementById('title');

if (!col1)
{
  return;
}

var col2 = document.getElementById('showtitle');

//trip <p> element
var titleListStr = col1.innerHTML.replace(/(<p>)|(<\/p>)/gi, "");

col2.innerHTML = titleListStr;

}
//--------------------------------------------

function openPdf()
{
	var href = window.location.href;
	window.location.href = href.substr(0, href.lastIndexOf('.'));
}

function building()
{
	window.location.href = '/opencms/opencms/shouye/building.html';
}
