// param
var queryStr=document.location.search.substring(1);
var pairs=queryStr.split("&"); //split the queryStr with "&" ..as "&" is the usual delimiters for parameters in URL
var sourceParam="";
for (var i=0;i<pairs.length;i++) {
	if (pairs[i].indexOf("source")>-1) {//locate source
		sourceParam=pairs[i];
		break;// need to put break so that it will stop looping when it finds the first occurence of source
	}	
}
var invalidChars="'\"<>'\\/&% ";
var sourcevalue="";
if (sourceParam.indexOf("=")>0)
	sourcevalue=sourceParam.substring((sourceParam.indexOf("=")+1),sourceParam.length);
if (sourceParam!="" && sourcevalue.length>0) {
	hasInvalid=false;
	for (var j=0;j<sourcevalue.length;j++){
		for (var k=0;k<invalidChars.length;k++) {
			if (sourcevalue.charAt(j)==invalidChars.charAt(k)) {
				hasInvalid=true;
				break;
			}
		}
		if (hasInvalid)
			break;
	}
	if (hasInvalid==true) 
		sourceParam = "";
}
else
	sourceParam="";				
//end param	

dynamicLink = "";
staticLink = "";

function dynamictrackURL(tsid,dtc)
{
	//Keep appending it
	if (sourceParam != "")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&"+sourceParam;
	
	//Final here
	if(dynamicLink=="" && dtc!="")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&source="+dtc;
		
	window.location=dynamicLink;
}

function statictrackURL(URLlink,dtc)
{
	//Keep appending it
	if (sourceParam != "")
	 	staticLink = URLlink+"?"+sourceParam;
	
	//Final here
	if(staticLink=="" && dtc!="")
		staticLink = URLlink+"?source="+dtc;
	
	window.location=staticLink;
}

function GB_dynamictrackURL(tsid,dtc)
{
	//Keep appending it
	if (sourceParam != "")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&ruleset=ONLINEVREGCN&language=zh&country=CN&"+sourceParam;
	
	//Final here
	if(dynamicLink=="" && dtc!="")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&ruleset=ONLINEVREGCN&language=zh&country=CN&source="+dtc;
		
	window.location=dynamicLink;
}

function GB_statictrackURL(URLlink,dtc)
{
	//Keep appending it
	if (sourceParam != "")
	 	staticLink = URLlink+"?"+sourceParam;
	
	//Final here
	if(staticLink=="" && dtc!="")
		staticLink = URLlink+"?source="+dtc;
	
	window.location=staticLink;
}

function B5_dynamictrackURL(tsid,dtc)
{
	//Keep appending it
	if (sourceParam != "")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&ruleset=ONLINEVREGCN&language=zh&country=TW&"+sourceParam;
	
	//Final here
	if(dynamicLink=="" && dtc!="")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&ruleset=ONLINEVREGCN&language=zh&country=TW&source="+dtc;
		
	window.location=dynamicLink;
}

function B5_statictrackURL(URLlink,dtc)
{
	//Keep appending it
	if (sourceParam != "")
	 	staticLink = URLlink+"?"+sourceParam;
	
	//Final here
	if(staticLink=="" && dtc!="")
		staticLink = URLlink+"?source="+dtc;
	
	window.location=staticLink;
}

function Russian_dynamictrackURL(tsid,dtc)
{
	//Keep appending it
	if (sourceParam != "")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&plang=RUSSIAN&"+sourceParam;
	
	//Final here
	if(dynamicLink=="" && dtc!="")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&plang=RUSSIAN&source="+dtc;
		
	window.location=dynamicLink;
}

function Russian_statictrackURL(URLlink,dtc)
{
	//Keep appending it
	if (sourceParam != "")
	 	staticLink = URLlink+"?"+sourceParam;
	
	//Final here
	if(staticLink=="" && dtc!="")
		staticLink = URLlink+"?source="+dtc;
	
	window.location=staticLink;
}

function Spanish_dynamictrackURL(tsid,dtc)
{
	//Keep appending it
	if (sourceParam != "")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&plang=SPANISH&"+sourceParam;
	
	//Final here
	if(dynamicLink=="" && dtc!="")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&plang=SPANISH&source="+dtc;
		
	window.location=dynamicLink;
}

function Spanish_statictrackURL(URLlink,dtc)
{
	//Keep appending it
	if (sourceParam != "")
	 	staticLink = URLlink+"?"+sourceParam;
	
	//Final here
	if(staticLink=="" && dtc!="")
		staticLink = URLlink+"?source="+dtc;
	
	window.location=staticLink;
}

function Japanese_dynamictrackURL(tsid,dtc)
{
	//Keep appending it
	if (sourceParam != "")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&plang=JAPANESE&"+sourceParam;
	
	//Final here
	if(dynamicLink=="" && dtc!="")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&plang=JAPANESE&source="+dtc;
		
	window.location=dynamicLink;
}

function Japanese_statictrackURL(URLlink,dtc)
{
	//Keep appending it
	if (sourceParam != "")
	 	staticLink = URLlink+"?"+sourceParam;
	
	//Final here
	if(staticLink=="" && dtc!="")
		staticLink = URLlink+"?source="+dtc;
	
	window.location=staticLink;
}

function Korean_dynamictrackURL(tsid,dtc)
{
	//Keep appending it
	if (sourceParam != "")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&plang=KOREAN&"+sourceParam;
	
	//Final here
	if(dynamicLink=="" && dtc!="")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&plang=KOREAN&source="+dtc;
		
	window.location=dynamicLink;
}

function Korean_statictrackURL(URLlink,dtc)
{
	//Keep appending it
	if (sourceParam != "")
	 	staticLink = URLlink+"?"+sourceParam;
	
	//Final here
	if(staticLink=="" && dtc!="")
		staticLink = URLlink+"?source="+dtc;
	
	window.location=staticLink;
}

function Arabic_dynamictrackURL(tsid,dtc)
{
	//Keep appending it
	if (sourceParam != "")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&arabic=true&"+sourceParam;
	
	//Final here
	if(dynamicLink=="" && dtc!="")
		dynamicLink = "http://tradeshow.globalsources.com/trdshw/gsol/pex/en/bondat/jsp/common/visreg.jsp?tsid="+tsid+"&arabic=true&source="+dtc;
		
	window.location=dynamicLink;
}

function Arabic_statictrackURL(URLlink,dtc)
{
	//Keep appending it
	if (sourceParam != "")
	 	staticLink = URLlink+"?"+sourceParam;
	
	//Final here
	if(staticLink=="" && dtc!="")
		staticLink = URLlink+"?source="+dtc;
	
	window.location=staticLink;
}