String.prototype.trim = function(){
        return this.replace( /(^\s*)|(\s*$)/g , "");
}
String.prototype.ltrim = function(){
        return this.replace( /(^\s*)/g, "" );
}
String.prototype.rtrim = function(){
        return this.replace( /(\s*$)/g, "" );
}

function $name( name ) { //通过Name获取对象
	if ( document.getElementsByName ) {
		var $name = function( name ){
			var tmpobj = document.getElementsByName(name);
			return tmpobj.length == 1 ? tmpobj[0] : tmpobj;
		}
		return $name(name);
	}
	alert( "Error: Lack of access to HTML object By Name, upgrade your browser to IE6 or later!" );
	var $name = function( name ) { return null; }
	return $name(name);
}

function $( key ) { // 快捷函数,默认$id
	return $id( key );
}
function $id( id ) { //通过ID获取对象
	if ( document.getElementById ){
		var $id = function( id ) { return document.getElementById( id ); }
		return $id( id );
	}
	if ( document.all ){
		var $id = function( id ) { return document.all[ id ]; }
		return $id( id );
	}
	if ( document.layers[ id ] ){
		var $id = function( id ) { return document.layers[ id ]; }
		return $id(id);
	}
	alert( "Error: Lack of access to HTML object, upgrade your browser to IE6 or later!" );
	var $id = function( id ){ return null; }
	return null;
}

function Mathr() {
	return Math.random();
}

var topAD = new Array();
var ad1Interval = 5000;
var ad1Speed = 1;
var ad1Handle = null;
var ad1MarginTop = 0;
var ad1Height = 0;
var ad1Current = 0;

//翻滚
function rollUp( id, height, interval, speed, imgPath ){
	if ( topAD.length < 1 ) {
		topAD[0] = imgPath + 'images/nopic.gif';
	}
	ad1Height = height;
	ad1Interval = interval;
	ad1Speed = speed;
	ad1MarginTop = parseInt( $(id).style.marginTop );
	var tmpStr = '';
	for ( var i = 0; i < topAD.length; i++ ) {
	   tmpStr += "<table><tr><td><a href=\"" + topAD[i] + "\" target=\"_blank\"><img src=\"" + topAD[i] + "\" onload=\"imgZoom(this, 152, 120);\" onerror=\"this.src='" + imgPath + "images/nopic.gif';\" /></a></td></tr></table>";
	}
	$('certificatepic').innerHTML = tmpStr;
	if ( topAD.length < 2 ) {
		return;
	}
	setInterval( "rollUpInterval(\"" + id + "\");", interval*1000 );
}
//间隔
function rollUpInterval( id ){
	ad1Current++;
	if ( topAD.length > ad1Current ) {
		moveElement( id, 0, ad1Current*(ad1Height-ad1Height*2), ad1Interval );
	} else {
		ad1Current = 0;
		moveElement( id, 0, 0, ad1Interval );
	}
}

//移动对象
function moveElement(elementID,final_x,final_y,interval) {
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  var elem = document.getElementById(elementID);
  if (elem.movement) {
    clearTimeout(elem.movement);
  }
  if (!elem.style.left) {
    elem.style.left = "0px";
  }
  if (!elem.style.top) {
    elem.style.top = "0px";
  }
  var xpos = parseInt(elem.style.left);
  var ypos = parseInt(elem.style.top);
  if (xpos == final_x && ypos == final_y) {
	return true;
  }
  if (xpos < final_x) {
    var dist = Math.ceil((final_x - xpos)/10);
    xpos = xpos + dist;
  }
  if (xpos > final_x) {
    var dist = Math.ceil((xpos - final_x)/10);
    xpos = xpos - dist;
  }
  if (ypos < final_y) {
    var dist = Math.ceil((final_y - ypos)/10);
    ypos = ypos + dist;
  }
  if (ypos > final_y) {
    var dist = Math.ceil((ypos - final_y)/10);
    ypos = ypos - dist;
  }
  elem.style.left = xpos + "px";
  elem.style.top = ypos + "px";
  var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
  elem.movement = setTimeout(repeat,interval);
}

function isEmpty( value ) { //检测是否为空
	return isNull( value ) || value == '' || value.length == 0;
}

function isNull( o ) { //检测是否为无效对象
	return o == null || o == 'undefined';
}

function isArray( ary ) {
	return isNull( ary ) ? false : ary.isArray;
}

function swfWrite( URL, width, height ) { //页面输出flash
	document.write( swfGetCode( URL, width, height ) );
}

function swfGetCode( URL, width, height ) { //生成flash代码
	var tmpstr = isEmpty( swf_id ) ? '' : "id=\"" + swf_id + "\"";
	var tmpembedparams = '';
	tmpstr = "<object " + tmpstr + " classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"" + swf_codebase + "\" width=\"" + width + "\" height=\"" + height + "\">\n<param name=\"movie\" value=\"" + URL + "\" />\n<param name=\"quality\" value=\"" + swf_quality + "\" />\n";
	swf_params = isArray(swf_params) ? swf_params.concat( swf_globalparams ) : swf_globalparams;
	for ( var i = 0; i < swf_params.length; i += 2 ) {
  		tmpstr += "<param name=\"" + swf_params[i] + "\" value=\"" + swf_params[i+1] + "\" />\n";
		tmpembedparams += swf_params[i] + "=\"" + swf_params[i+1] + "\" "
	}
	tmpstr += "<embed src=\"" + URL+ "\" quality=\"" + swf_quality + "\" pluginspage=\"" + swf_pluginspage + "\" type=\"application/x-shockwave-flash\" width=\"" + width + "\" height=\"" + height + "\" " + tmpembedparams + "></embed></object>";
	swfInit();
	return tmpstr;
}

function swfInit() { //初始化flash局部变量
	swf_params = [], swf_id = null, swf_quality = "hign";
}

function swfVersion() { //检测flash版本
	var tmp = navigator.plugins;
	if ( !tmp || tmp.length == 0 ) {
		for ( var i = 12; i > 5; i-- ) {
			try {
				var tmp = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash." + i.toString() );
				return i.toString() + ".0";
			} catch( e ) { continue; }
		}
		return null;
	} else {
		for ( var i = 0; i < tmp.length; i++ ) {
			if ( tmp[i].name.indexOf("Shockwave Flash") == -1 ) continue;
			return tmp[i].description.substr(16, 3);
		}
		return null;
	}
}

var swf_globalparams = [ "wmode", "Transparent" ]; //flash全局通用参数
var swf_params = []; //flash参数变量
var swf_id = null; //flash的ID
var swf_quality = "hign"; //flash播放品质
var swf_codebase = "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"; //flash安装插件地址
var swf_pluginspage = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash"; //flash安装插件地址
var swf; //是否支持flash
swf = swfVersion(); //初始化浏览器是否支持flas

//获取浏览器的版本
function getOs( key, count ) {
	tmpstr = navigator.userAgent.toLowerCase().trim();
	key = key.toLowerCase().trim();
    if ( tmpstr.indexOf(key) > -1 ) {
	    return tmpstr.substr(  tmpstr.indexOf(key) + key.length + 1, count );
	} else {
	    return false;
	}
}

var IE, firefox, opera; //浏览器变量

//初始化浏览器版本变量
IE = getOs( "msie", 3 );
firefox = getOs( "firefox", 8 );
opera = getOs( "opera", 4 );

function toBreakWord( o, len ){
	if (document.getElementById  && !document.all) {
		var obj = document.getElementById(o);
		var strContent = obj.innerHTML;  
		var strTemp = "";
		while( strContent.length > len ){
			strTemp += strContent.substr( 0, len ) + "<br>";  
			strContent = strContent.substr( len, strContent.length );  
		}
		strTemp += "<br>" + strContent;
		obj.innerHTML = strTemp;
	}
}

// [CN] 连接URL
var pageurl;
// [CN] 总页数
var pagecount = 0;
// [CN] 当前页
var currpage = 0;
// [CN] 页数循环开始数
var startpage = 0;
// [CN] 页数循环结束数
var endpage = 0;
// [CN] 总记录
var recount = 0;
// [CN] 分页表格位置
var listablepoint = 'right';
// [CN] 记录头
var currpageheader = 0;
// [CN] 记录尾
var currpagetail = 0;
// [CN] 每页大小
var pagesize = 0;

function tofirst() {
	if( currpage == 1 ) {
		alert( "To the top page." );
	} else {
		window.location.href = pagereplace(1);
	}
}

function totail() {
	if( currpage == pagecount ) {
		alert( "To the last page." );
	} else {
		window.location.href = pagereplace(pagecount);
	}
}

function seltopage( page ) {
	if( !isNaN(page) ) {
		if( page < 1 || page > pagecount ) {
			alert( "Sorry,the page can’t be found,please make sure the page range." );
			return false;
		} else {
			window.location.href = pagereplace(page);
		}
	} else {
		alert( "Sorry,the page can’t be found,please make sure the page range." );
		return false;
	}
}

function lastpage() {
	var page = currpage - 1;
	if( page < 1 ) {
		alert( "No more pages forward" );
	} else {
		window.location.href = pagereplace(page);
	}
}

function nextpage() {
	var page = currpage + 1;
	if( page > pagecount ) {
		alert( "No more pages backward" );
	} else {
		window.location.href = pagereplace(page);
	}
}

function listpage() {
	var liststr = '';
	for( i = startpage; i <= endpage; i++  ) {
		if( i != currpage ) {
			liststr += "    <a title=\"" + i + "\" href=\"javascript:seltopage(" + i + ");\" class=\"num\">" + i + "<\/a>";
		} else {
			liststr += "    <a title=\"" + i + "\" class=\"num current\">" + i + "<\/a>";
		}
	}
	return liststr;
}

function pagereplace( page ) {
	return pageurl.replace( '{i}', page );
}

function enterpage( page ) {
	if( window.event.keyCode==13 ) {
			seltopage( page );
			return false;
	}
	return false;
}

function showpageinfo( img_path ) {
	var tmpheader = 0;
	tmpheader = currpageheader + 1;
	
	document.writeln("<div style=\"float: right; clear: both;\" class=\"page_bar\">");
	//document.writeln("    <a title=\"每页 " + pagesize + " 条\" class=\"page_pages\">" + pagesize + "<\/a>");
	document.writeln("    <a title=\"" + pagesize + " pcs each page\" class=\"page_pages\">" + pagesize + "<\/a>");
	//document.writeln("    <a title=\"总记录数\" class=\"page_total\">" + recount + "</a>");
	document.writeln("    <a title=\"the total records\" class=\"page_total\">" + recount + "</a>");
	//document.writeln("    <a title=\"当前页\/总页数\" class=\"page_pages\">" + currpage + "\/" + pagecount + "</a>");
	document.writeln("    <a title=\"the current page\/total pages\" class=\"page_pages\">" + currpage + "\/" + pagecount + "</a>");
	//document.writeln("    <a href=\"javascript:tofirst();\" title=\"回到首页\"><img border=\"0\" src=\"" + img_path + "images/pagination/first.gif\" alt=\"回到首页\"/></a>");
	document.writeln("    <a href=\"javascript:tofirst();\" title=\"First\"><img border=\"0\" src=\"" + img_path + "images/pagination/first.gif\" alt=\"First\"/></a>");
	//document.writeln("    <a href=\"javascript:lastpage();\" title=\"Previous\"><img border=\"0\" src=\"" + img_path + "images/pagination/previous.gif\" alt=\"Previous\"/></a> ");
	document.writeln("    <a href=\"javascript:lastpage();\" title=\"Previous\"><img border=\"0\" src=\"" + img_path + "images/pagination/previous.gif\" alt=\"Previous\"/></a> ");
	document.writeln("    " + listpage() );
	//document.writeln("    <a href=\"javascript:nextpage();\" title=\"下一页\"><img border=\"0\" src=\"" + img_path + "images/pagination/next.gif\" alt=\"下一页\"/></a>");
	document.writeln("    <a href=\"javascript:nextpage();\" title=\"Next\"><img border=\"0\" src=\"" + img_path + "images/pagination/next.gif\" alt=\"Next\"/></a>");
	//document.writeln("    <a href=\"javascript:totail();\" title=\"最后一页\"><img border=\"0\" src=\"" + img_path + "images/pagination/last.gif\" alt=\"最后一页\"/></a>");
	document.writeln("    <a href=\"javascript:totail();\" title=\"Last\"><img border=\"0\" src=\"" + img_path + "images/pagination/last.gif\" alt=\"Last\"/></a>");
	//document.writeln("    <input type=\"text\" value=\"1\" onfocus=\"this.focus();this.select();\" onmousemove=\"this.focus();this.select();\" style=\"text-align: center;\" onkeydown=\"if(event.keyCode==13){ seltopage( parseInt(this.value) ); }\" name=\"page\" size=\"2\" class=\"page_input\" title=\"Please enter the page number and press “enter” to skip directly\"/>");
	document.writeln("    <input type=\"text\" value=\"1\" onfocus=\"this.focus();this.select();\" onmousemove=\"this.focus();this.select();\" style=\"text-align: center;\" onkeydown=\"if(event.keyCode==13){ seltopage( parseInt(this.value) ); }\" name=\"page\" size=\"2\" class=\"page_input\" title=\"输入页面，回车直接跳转\"/>");
	document.writeln("<\/div>");
}

//显示已有的所在地区
function nowaddress( value ) {
	tmpary = value.split('@@');
	tmpstr = '';
	for ( var i = 0; i < tmpary.length; i++ ) {
		if ( i + 1 < tmpary.length ) {
			tmpstr += tmpary[i] + "&nbsp;&nbsp;&nbsp;&nbsp; &gt; &nbsp;&nbsp;";
		} else {
			tmpstr += tmpary[i];
		}
	}
	document.write( tmpstr );
}

//图片缩略
function imgZoom( imageDest_i, W, H ) {
    // 显示框宽度W,高度H
    var image = new Image();
    var imageDest = {};
    image = imageDest_i;
    if(image.width>0 && image.height>0)
    {
        // 比较纵横比
        if(image.width/image.height >= W/H) // 相对显示框：宽>高
        {
            if(image.width > W) // 宽度大于显示框宽度W，应压缩高度
            {
                imageDest.width = W;
                imageDest.height = (image.height*W)/image.width;
            }else{ // 宽度少于或等于显示框宽度W，图片完全显示
                imageDest.width = W;
                imageDest.height = (image.height*W)/image.width;
            }
        }else{ // 同理
            if(image.height > H)
            {
                imageDest.height = H;
                imageDest.width = (image.width*H)/image.height;
            }else{
                imageDest.height = H;
                imageDest.width = (image.width*H)/image.height;
            }
        }

		imageDest_i.style.width = Math.round(imageDest.width) + 'px';
		imageDest_i.style.height = Math.round(imageDest.height) + 'px';
    }
	imageDest = null;
	return;
}

var slideMain = 
{
  files : '',
  links : '',
  texts : '',
  
  width : 100,
  height : 100,
  objURL : '',
  
  loopslide : function()
  {
	  var f = slideMain.files.split('|');
	  var l = slideMain.links.split('|');
	  var t = slideMain.texts.split('|');
	  var s = '';
	  
	  s = '<data><channel>';
	  for(var i = 0; i < f.length; i++)
	  {
		  s += '<item><link>' + f[i] + '</link><image>' + l[i] + '</image><title>' + t[i] + '</title></item>';
	  }
	  s += '</channel><config><roundCorner>2</roundCorner><autoPlayTime>3</autoPlayTime><isHeightQuality>false</isHeightQuality><blendMode>normal</blendMode><transDuration>1</transDuration><windowOpen>_self</windowOpen><btnSetMargin>auto 5 5 auto</btnSetMargin><btnDistance>20</btnDistance><titleBgColor>0xff6600</titleBgColor><titleTextColor>0xffffff</titleTextColor><titleBgAlpha>.75</titleBgAlpha><titleMoveDuration>1</titleMoveDuration><btnAlpha>.7</btnAlpha><btnTextColor>0xffffff</btnTextColor><btnDefaultColor>0x1B3433</btnDefaultColor><btnHoverColor>0xff9900</btnHoverColor><btnFocusColor>0xff6600</btnFocusColor><changImageMode>click</changImageMode><isShowBtn>false</isShowBtn><isShowTitle>false</isShowTitle><scaleMode>noBorder</scaleMode><transform>breathe</transform><isShowAbout>false</isShowAbout></config></data>';
	  s = escape(s);
	  document.write('<div class="companyimage"><object type="application/x-shockwave-flash" data="' + slideMain.objURL + 'bcastr.swf?xml=' + s + '"  width="' + slideMain.width + '" height="' + slideMain.height + '" id="vcastr3"><param name="movie" value="' + slideMain.objURL + 'bcastr.swf?xml=' + s + '" /></object></div>');
  }
}

//显示侧栏菜单搜索框
function showSearchBox() {
	document.write('<form action="/search.php" method="post" target="_blank">');
	document.write('<select name="target"><option value="_self">Site</option><option value="arbsoso">Arbsoso</option></select>');
	document.write('<select name="channel"><option value="product">Product</option><option value="supply">Supply and Demand</option><option value="news">News</option></select>');
	document.write('<input type="text" name="keyword" class="searchinput" value="Please enter keywords..." onfocus="this.value=\'\';" />');
	document.write('<input type="hidden" name="lang" value="en" /><input type="submit" class="btn1" value="Search" /></form>');
}

//添加收藏夹
function addFavorite( sTitle, sURL )
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            //alert("加入收藏失败，请使用Ctrl+D进行添加");
			alert("Fails to add to Favorite, Press (Ctrl + D) to add");
        }
    }
}

// 设为首页
function setHome(obj, vrl)
{
	try
	{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
	}
	catch(e)
	{
		if(window.netscape) 
		{
			try 
			{
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
			}  
			catch (e)  
			{ 
			//alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入\"about:config\"并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'");
			alert("This action refused by the browser! \nPlease type: 'about:config' in your address bar then press Enter \n and set the value of [signed.applets.codebase_principal_support] to 'true'");
			return false;
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',vrl);
		}
	}
}
