function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//old code
function loginFocus(oname, focused){
    var obj = document.getElementById(oname);
    
    if (focused) {
        obj.style.backgroundColor = '#D7EDF4';
    }
    else
    {
        obj.style.backgroundColor = '#FFFFFF';
    }
}

function swapURL(thisLang,toLang) 
{
	var temp = parent.location.href;
	var tmp0 = "";
	var tmp1 = "";
	var thisURL1 = "";
	
	if (thisLang == "en")
	{
		if (toLang == "tc")
		{
			if (temp == "http://www.2456.com/chinaplas")
				tmp0 = temp.replace("/chinaplas","/chinaplas/tc/general/info1/eid/3101/order/102/");
			else if (temp == "http://www.2456.com/chinaplas/")
				tmp0 = temp.replace("/chinaplas/","/chinaplas/tc/general/info1/eid/3101/order/102/");
			else
				tmp0 = temp.replace("/chinaplas/index.asp","/chinaplas/tc/general/info1/eid/3101/order/102/");
				
			tmp1 = tmp0.replace("/en/","/tc/");
			thisURL = tmp1.replace("3095","3101");			
		}
		else if (toLang == "sc")
		{
			if (temp == "http://www.2456.com/chinaplas")
				tmp0 = temp.replace("/chinaplas","/chinaplas/sc/general/info1/eid/3148/order/102/");
			else if (temp == "http://www.2456.com/chinaplas/")
				tmp0 = temp.replace("/chinaplas/","/chinaplas/sc/general/info1/eid/3148/order/102/");
			else
				tmp0 = temp.replace("/chinaplas/index.asp","/chinaplas/sc/general/info1/eid/3148/order/102/");
				
			tmp1 = tmp0.replace("/en/","/sc/");	
			thisURL = tmp1.replace("3095","3148");			
		}
	}	
	else if (thisLang == "tc")
	{
		if (toLang == "en")
		{
			tmp1 = temp.replace("/tc/","/en/");
			thisURL = tmp1.replace("3101","3095");			
		}
		else if (toLang == "sc")
		{
			tmp1 = temp.replace("/tc/","/sc/");
			thisURL = tmp1.replace("3101","3148");			
		}
	}	
	else if (thisLang == "sc")
	{
		if (toLang == "en")
		{
			tmp1 = temp.replace("/sc/","/en/");
			thisURL = tmp1.replace("3148","3095");			
		}
		else if (toLang == "tc")
		{
			tmp1 = temp.replace("/sc/","/tc/");
			thisURL = tmp1.replace("3148","3101");			
		}
	}
	
	parent.location.href = thisURL;
}

function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function mail() {
 
	var t = new Date(); at = "@"; subject = "Adsale enquiry (" + t.getYear() +
"/" + (t.getMonth()+1) + "/" + t.getDate() + " "+ t.getHours() + ":" +
t.getMinutes() + ":" + t.getSeconds() + ")";
 window.location = "mailto:info06" + at + "EventTrip.com?subject=" +
escape(subject);

}


/*
===========================
LTrim(string):remove space in the left
===========================
*/
 
function LTrim(str)
{
var whitespace = new String(" tnr");
var s = new String(str);
 
if (whitespace.indexOf(s.charAt(0)) != -1)
{
var j=0, i = s.length;
while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
{
j++;
}
s = s.substring(j, i);
}
return s;
}
/*
===========================
RTrim(string):remove space in the right
===========================
*/
function RTrim(str)
{
var whitespace = new String(" tnr");
var s = new String(str);
 
if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
{
var i = s.length - 1;
while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
{
i--;
}
s = s.substring(0, i+1);
}
return s;
}
 
/*
===========================
Trim(string):remove all space
===========================
*/
function Trim(str)
{
//return RTrim(LTrim(str));
return trim( str );
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
  
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function Upper(obj) {
    obj.value = obj.value.toUpperCase();
}

function goGb(){
	var url = location.href;
	var lang = 'lang-simp/';
	var re = new RegExp('\/lang-[a-z]+\/', 'ig');
	
	if (url.match( re ) )
	{
		url = url.replace( re, '/' + lang);
	}
	else
	{
		re = new RegExp('\/(ExhibitorDB|DB09)\/', 'ig');
		rel = re.exec(url);
		url = url.replace( re, rel[0] + lang);
	}
	
	window.location = url;
}

function goEng(){
	var url = location.href;
	var lang = 'lang-eng/';
	var re = new RegExp('\/lang-[a-z]+\/', 'ig');
	
	if (url.match( re ) )
	{
		url = url.replace( re, '/' + lang);
	}
	else
	{
		re = new RegExp('\/(ExhibitorDB|DB09)\/', 'ig');
		rel = re.exec(url);
		url = url.replace( re, rel[0] + lang);
	}
	
	window.location = url;
}

function goBig5(){
	var url = location.href;
	var lang = 'lang-trad/';
	var re = new RegExp('\/lang-[a-z]+\/', 'ig');
	
	if (url.match( re ) )
	{
		url = url.replace( re, '/' + lang);
	}
	else
	{
		re = new RegExp('\/(ExhibitorDB|DB09)\/', 'ig');
		rel = re.exec(url);
		url = url.replace( re, rel[0] + lang);
	}
	
	window.location = url;
}

function OEShowHideLayers( objId, dummy, state ) {
	var obj
	
	obj = document.getElementById( objId );
	if (state == 'show' ) {
		obj.style.display = 'block';
	}
	if (state == 'hide' ) {
		obj.style.display = 'none';
	}
}



function checkNumber(field)
{
    var check = true;
    var value = field.value; //get characters
    //check that all characters are digits, ., -, or ""
    for(var i=0;i < field.value.length; ++i)
    {
        var new_key = value.charAt(i); //cycle through characters
        if(((new_key < "0") || (new_key > "9")) && !(trim(new_key) == ""))
        {
            check = false;
            break;
        }
    }
    return check;
          
}

function ValidatorEmail(email) {
		var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		return filter.test(email);
}

function popVideo(url, src)
{
    var obj = window.open(url, 'GalleryVideo', 'toolbar=0,location=0,statusbar=0,menubar=0,resizable=0,width=690,height=525');
    obj.focus();
}

function popWindow(lnk)
{
	var temp = window.open(lnk, '', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=640,height=525');
	temp.focus();
}

function popGeneral(lnk, name, width, height, scrollbars)
{
	var temp = window.open(lnk, name, 'toolbar=0,scrollbars=' + scrollbars + ',location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height);
	temp.focus();
}

function popGeneralWithSize(name, width, height, scrollbars)
{
	var temp = window.open('', name, 'toolbar=0,scrollbars=' + scrollbars + ',location=0,statusbar=0,menubar=0,resizable=0,width=' + width + ',height=' + height);
	temp.focus();
}

function LoadVideo(videoPath, videoHeight, videoWidth, 
                   transparentAtStart, autoStart, animationStart, 
                   showControls, showStatusBar, enableContextMenu, autoSize, displaySize)
{
    var embed;
    embed  = "<object ID='MediaPlayer' classid='CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95' CODEBASE='http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,5,715'";
    embed += "standby='Loading Microsoft Windows Media Player components...' type='application/x-oleobject' width='" + videoWidth + "' height='" + videoHeight + "'>";
    embed += "<param NAME='FileName' Value='" + videoPath + "'>";
    embed += "<param NAME='Loop' Value='true'>";
    embed += "<param NAME='TransparentAtStart' Value='" + transparentAtStart + "'>";
    embed += "<param NAME='AutoStart' Value='" + autoStart + "'>";
    embed += "<param NAME='AnimationatStart' Value='" + animationStart + "'>";
    embed += "<param NAME='ShowControls' Value='" + showControls + "'>";
    embed += "<PARAM NAME='ShowStatusBar' VALUE='" + showStatusBar + "'>";
    embed += "<param NAME='EnableContextMenu' value='" + enableContextMenu + "'>";
    embed += "<param NAME='autoSize' Value='" + autoSize + "'>";
    embed += "<param NAME='displaySize' Value='" + displaySize + "'>";
    embed += "<embed type='application/x-mplayer2' pluginspage='http://www.microsoft.com/isapi/redir.dll?prd=windows&sbp=mediaplayer&ar=media&sba=plugin&'";
    embed += " src='" + videoPath + "' Name='MediaPlayer' Width='" + videoWidth + "' Height='" + videoHeight + "'";
    embed += " transparentAtStart='" + ((transparentAtStart == true) ? "1" : "0") + "'";
    embed += " Loop='1'";
    embed += " AutoStart='" + ((autoStart == true) ? "1" : "0") + "'";
    embed += " animationAtStart='" + ((animationStart == true) ? "1" : "0") + "'";
    embed += " showcontrols='" + ((showControls == true) ? "1" : "0") + "'";
    embed += " showpositioncontrols='" + ((showControls == true) ? "1" : "0") + "'";
    embed += " showaudiocontrols='" + ((showControls == true) ? "1" : "0") + "'";
    embed += " showtracker='" + ((showControls == true) ? "1" : "0") + "'";
    embed += " showdisplay='" + ((showControls == true) ? "1" : "0") + "'";
    embed += " showgotobar='0' showcaptioning='0' autostart='0' autorewind='1'";
    embed += " ShowStatusBar='" + showStatusBar + "'";
    embed += " EnableContextMenu='" + enableContextMenu + "'";
    embed += " autoSize='" + ((autoSize == true) ? "1" : "0") + "'";
    embed += " displaySize='" + ((displaySize == true) ? "1" : "0") + "'>";
    embed += " </embed></object>";

    //document.write(embed);
	return embed;
}

function GetWidth()
{
    var x = 0;
    if (screen.width)
    {
    	x = screen.width;
    }
    else if (self.innerHeight)
    {
        x = self.innerWidth;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
        x = document.documentElement.clientWidth;
    }
    else if (document.body)
    {
        x = document.body.clientWidth;
    }
    return x;
}

function GetHeight()
{
    var y = 0;
    if (screen.height)
    {
    	y = screen.height;
    }
    else if (self.innerHeight)
    {
        y = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
    {
        y = document.documentElement.clientHeight;
    }
    else if (document.body)
    {
        y = document.body.clientHeight;
    }
    return y;
}

function resizeHeight(height)
{
	var width = GetWidth();
	if (document.all) 
	{
	   	try
	   	{
	   		top.window.resizeTo( width , height);
	   	}
	   	catch (ex)
	   	{
	   		//
	   	}
	} 
	else if (document.layers || document.getElementById) 
	{
	    try
	    {
	        if (top.window.outerHeight < height)
            {
                top.window.outerHeight = height;
            } 
        }
        catch (ex)
        {
       	    //
        }
	}
}

function resizeWidth(width)
{
	var height = GetHeight();
	if (document.all) 
	{
	   	try
	   	{
	   		top.window.resizeTo( width , height);
	   	}
	   	catch (ex)
	   	{
	   		//
	   	}
	} 
	else if (document.layers || document.getElementById) 
	{
	    try
	    {
	        if (top.window.outerWidth <  width)
            {
                top.window.outerWidth = width;
            } 
        }
        catch (ex)
        {
       	    //
        }
	}
}


function resizeBrowser(width, height)
{
	if (document.all) 
	{
	    try
	    {
	        top.window.resizeTo(width,height);
	   	} catch (ex)
	   	{
	   		//
	   	}
	}
	else if (document.layers || document.getElementById)
	{  
	    try
	    {
	        if (top.window.outerHeight < height || top.window.outerWidth <  width)
	        {
	            top.window.outerHeight = height;
	            top.window.outerWidth = width;
	        } 
	    } catch (ex)
	    {
	       	//
	    }
	}
}

function ExhiPopUp()
{
    var obj = window.open('', 'exhiPopup', 'toolbar=0,location=0,statusbar=0,menubar=0,resizable=0,scrollbars=1,width=350,height=300');
    obj.focus();
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function getY( oElement )
{
    var iReturnValue = 0;
    while( oElement != null )
    {
        iReturnValue += oElement.offsetTop;
        //alert(oElement.offsetTop );
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function getYPlus( oElement )
{
    var iReturnValue = 0;
    while( oElement != null )
    {
        iReturnValue += oElement.offsetTop;
        if (oElement.pageYOffset)
        {
            iReturnValue += oElement.pageYOffset;
        }
        else
        {
            iReturnValue += oElement.scrollTop;
        }
        //alert(oElement.offsetTop );
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function getX( oElement )
{
    var iReturnValue = 0;
    while( oElement != null )
    {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

function rollAdButton(curAd, maxAd, did, maxDisplay)
{
    for (var lpg = curAd; lpg < curAd + maxDisplay; lpg++)
    {
        var obj = document.getElementById('Ad_' + did + '_' + lpg);
        obj.style.display = 'none';
    }
    
    curAd += maxDisplay;
    curAd = curAd % maxAd;

    for (var lpg = curAd; lpg < curAd + maxDisplay; lpg++)
    {
        var obj = document.getElementById('Ad_' + did + '_' + lpg);
        obj.style.display = '';
    }
    
    setTimeout('rollAdButton(' + curAd + ', ' + maxAd + ', ' + did + ', ' + maxDisplay + ')', 5000);
}

function PopUpFlipBook()
{
    var width = screen.width;
    var height = screen.height;
    var obj = window.open('', 'flipbook', 'toolbar=0,location=0,statusbar=0,menubar=0,resizable=0,scrollbars=1,top=0,left=0,width=' + width + ',height=' + height);
    obj.focus();
}

function PopUpAd() {
	var pageH = GetHeight();
	var pageW = GetWidth();
	var winWidth = 790;
	var winHeight = 600;
	var winLeft = (pageW - winWidth) / 2;
	var winTop = (pageH - winHeight) / 2;
	
	window.open('', 'popupAd', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + winWidth + ',height=' + winHeight + ',left = ' + winLeft + ',top = ' + winTop);
}

function PopUpVideoAd(grp) {
	var pageH = GetHeight();
	var pageW = GetWidth();
	var winWidth = 640 + 30;
	var winHeight = 600;
	
	if (grp == 5)
	{
	    winWidth = 320 + 30;
	    winHeight = 400;
	}
	
	var winLeft = (pageW - winWidth) / 2;
	var winTop = (pageH - winHeight) / 2;
	
	window.open('', 'popupVideoAd', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=' + winWidth + ',height=' + winHeight + ',left = ' + winLeft + ',top = ' + winTop);
}

function PopupForward()
{
    var width = screen.width;
    var height = screen.height;
    var popWidth = 500;
    var popHeight = 400;
    var top = ( height - popHeight ) / 2;
    var left = ( width - popWidth ) / 2;
    var obj = window.open('', 'forward', 'toolbar=0,location=0,statusbar=0,menubar=0,resizable=0,scrollbars=0,top=' + top + ',left=' + left + ',width=' + popWidth + ',height=' + popHeight);
    obj.focus();
}

function runrun(ademo1,ademo11,ademo12)
{
	var demo1 = document.getElementById(ademo1);
	var demo11 = document.getElementById(ademo11);
	var demo12 = document.getElementById(ademo12);
	var speed=40
	demo12.innerHTML=demo11.innerHTML
	function Marquee1(){
	if(demo12.offsetTop-demo1.scrollTop<=0)
	demo1.scrollTop-=demo11.offsetHeight
	else{
	demo1.scrollTop++
	}
	}
	var MyMar1=setInterval(Marquee1,speed)
	demo1.onmouseover=function() {clearInterval(MyMar1)}
	demo1.onmouseout=function() {MyMar1=setInterval(Marquee1,speed)}
}


/*
=====
Functions for Rss Popup
=====
*/
function RssShowDetail_Toggle(value, panel, align)
{   
    if(!state && value == 1){
        RssShowDetail_ClearTimer();
        RssShowDetail_Cur = !RssShowDetail_Cur;
        RssShowDetail(RssShowDetail_Cur, panel, align);
        RssShowDetail_Timer = setTimeout(function(){RssShowDetail_Hide(panel, align)}, 500 * 5);
    }
}

function RssShowDetail(isShow, panel, align)
{
    var obj = document.getElementById('WRssIcon_' + panel);
    var top = getY(obj) + 23;
    var left = getX(obj);
    obj = document.getElementById('WRssPopup_' + panel);
   
    if(isShow)
    {
        obj.style.top = top + 'px';
        if(align == 1){
            obj.style.left = left  - 325 + 'px';
        }
        else obj.style.left = left + 'px';
        state = true;
    }
    else
    {
        obj.style.top = '-300px';
        state = false;
    }
    RssShowDetail_Cur = isShow;
}

function RssShowDetail_Hide(panel, align)
{
    RssShowDetail(false, panel);
}

function RssShowDetail_HideTimer(panel, align)
{
    RssShowDetail_Timer = setTimeout(function(){RssShowDetail_Hide(panel, align)}, 500);
}

function RssShowDetail_ClearTimer()
{
    clearTimeout(RssShowDetail_Timer);
}
/*
=====
End Rss Popup Functions
=====
*/

function ValidatePassword(value, min, max)
{
	var filter = new RegExp('^([a-zA-Z0-9]{' + min + ',' + max + '})+$');
	return filter.test(value);
}

function AlertField(obj)
{
    obj.style.backgroundColor = '#FF8888';
    obj.focus();
}

function ResetField(obj)
{
    obj.style.backgroundColor = '';
}

function ValidateNumber(value, isContact)
{
	var filter;
	
	if (isContact)
	{
	    filter = /^[\*|0-9|-]+$/;
	}
	else
	{
	    filter = /^[0-9]+$/;
	}
	
	return filter.test(value);
}

function ClickListing(ele, idx)
{
    var obj;
    
    if (idx == -1)
    {
        obj = document.getElementById( ele );
    }
    else
    {
        obj = document.getElementById( ele + '_' + idx);
    }
    obj.click();
}

function rollAdBanner(curAd, maxAd, did, maxDisplay)
{
    for (var lpg = curAd; lpg < curAd + maxDisplay; lpg++)
    {
        var obj = document.getElementById('Ad_' + did + '_' + lpg);
        obj.style.display = 'none';
    }
    
    var obj = document.getElementById('Ad_' + did + '_999');
    obj.style.display = '';
    setTimeout('rollAdBannerVis(' + curAd + ', ' + maxAd + ', ' + did + ', ' + maxDisplay + ')', 1500);
}

function rollAdBannerVis(curAd, maxAd, did, maxDisplay)
{
    var obj = document.getElementById('Ad_' + did + '_999');
    obj.style.display = 'none';
    
    curAd += maxDisplay;
    curAd = curAd % maxAd;

    for (var lpg = curAd; lpg < curAd + maxDisplay; lpg++)
    {
        var obj = document.getElementById('Ad_' + did + '_' + lpg);
        obj.style.display = '';
    }
    
    setTimeout('rollAdBanner(' + curAd + ', ' + maxAd + ', ' + did + ', ' + maxDisplay + ')', 5000);
}

