var strUserAgent = new String(navigator.userAgent);

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

function destroycatfish()
{
	var catfish = document.getElementById('catfish');
	writeCookie(showname);
	document.body.removeChild(catfish); /* clip catfish off the tree */
	document.getElementsByTagName('html')[0].style.padding= '0'; /* reset the padding at the bottom */
	return false;
}

function closeme()
{   var closelink = document.getElementById('closeme');
	closelink.onclick = destroycatfish;
}

function IEwrapFish() {
	var catfish = document.getElementById('catfish');
	var subelements = [];
	for (var i = 0; i < document.body.childNodes.length; i++) {
 		subelements[i] = document.body.childNodes[i];
	}

	var zip = document.createElement('div');    // Create the outer-most div (zip)
	zip.id = 'zip';                      // call it zip

	for (var i = 0; i < subelements.length; i++) {
		zip.appendChild(subelements[i]); 
	}
	document.body.appendChild(zip); // add the major div
	document.body.appendChild(catfish); // add the catfish after the zip
}

function writeCookie(showname) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate() + 1);
	//document.cookie = showname + '=1;expires=' + exdate.toGMTString() + '; path=/; domain=tradeshow.globalsources.com;';
	document.cookie = showname + '=CatFish cookie;expires=' + exdate.toGMTString();
}

function getCookie(showname) {
	if (document.cookie.length>0) {
		cookie_start = document.cookie.indexOf(showname + "=");
		if (cookie_start != -1) {
			cookie_start = cookie_start + showname.length+1;
			cookie_end = document.cookie.indexOf(";",cookie_start);
	
			if (cookie_end == -1) cookie_end = document.cookie.length;
			return unescape( document.cookie.substring(cookie_start, cookie_end) );
		}
	}
	return "";
}

function checkCookie(showname) {
	showInfo = getCookie(showname);
	if (showInfo != null && showInfo != "") {}
	else { document.getElementById('catfish').style.display = ""; }
}

function checkDirectory() {
	var URL = document.URL;
	
	if ( URL.match("/HONGKONG-BABY-CHILDREN-PRODUCTS") || URL.match("/GB-HONGKONG-BABY-CHILDREN-PRODUCTS") || URL.match("/BIG5-HONGKONG-BABY-CHILDREN-PRODUCTS") )
	{ showname="HK_BCP"; }
	else if ( URL.match("/HONGKONG-ELECTRONICS") || URL.match("/GB-HONGKONG-ELECTRONICS") || URL.match("/BIG5-HONGKONG-ELECTRONICS") )
	{ showname="HK_EC"; }
	else if ( URL.match("/HONGKONG-FASHION") || URL.match("/GB-HONGKONG-FASHION") || URL.match("/BIG5-HONGKONG-FASHION") )
	{ showname="HK_FA"; }
	else if ( URL.match("/HONGKONG-GIFTSPREMIUMS") || URL.match("/GB-HONGKONG-GIFTSPREMIUMS") || URL.match("/BIG5-HONGKONG-GIFTSPREMIUMS") )
	{ showname="HK_GP"; }
	else if ( URL.match("/HONGKONG-HOME-PRODUCTS") || URL.match("/GB-HONGKONG-HOME-PRODUCTS") || URL.match("/BIG5-HONGKONG-HOME-PRODUCTS") )
	{ showname="HK_HP"; }
	else if ( URL.match("/HONGKONG-SECURITY-PRODUCTS") || URL.match("/GB-HONGKONG-SECURITY-PRODUCTS") || URL.match("/BIG5-HONGKONG-SECURITY-PRODUCTS") )
	{ showname="HK_SP"; }
	else if ( URL.match("/HONGKONG-UNDERWEAR-SWIMWEAR") || URL.match("/GB-HONGKONG-UNDERWEAR-SWIMWEAR") || URL.match("/BIG5-HONGKONG-UNDERWEAR-SWIMWEAR") )
	{ showname="HK_US"; }
	else if ( URL.match("/HONGKONG-INDIA-SOURCING-FAIR-HOMEPRODUCTS") || URL.match("/GB-HONGKONG-INDIA-SOURCING-FAIR-HOMEPRODUCTS") || URL.match("/BIG5-HONGKONG-INDIA-SOURCING-FAIR-HOMEPRODUCTS") )
	{ showname="HK_ISF"; }
}

addLoadEvent(function() {
	checkDirectory();
	checkCookie(showname);
	closeme();
});

function allCatfish() {
	if(strUserAgent.match("MSIE")) { IEwrapFish(); }
	checkDirectory();
	checkCookie(showname);
	closeme();
}

