var timeRedirect = 20;
var iTimerID = null;

function doAutoRedirect(){
	if(timeRedirect<0){return false;}
	--timeRedirect;
	var obj = $("timeLeft");
	if(obj)obj.innerHTML = timeRedirect;
	if(timeRedirect==0){
		timeRedirect = -1;
		window.location.href = '/';
		return false;
	}
}

function getBrowser(){
	var Browser = navigator.userAgent.toLowerCase();
	if(Browser.indexOf('maxthon')!= -1){					//Maxthon
		return 'maxthon';
	}else if(Browser.indexOf('msie')!= -1){				//MSIE
		return 'msie';
	}else if(Browser.indexOf('safari')!= -1){			//Safari
		return 'safari';
	}else if(Browser.indexOf('opera')!= -1){			//Opera
		return 'opera';
	}else if(Browser.indexOf('flock')!= -1){			//Flock
		return 'flock';
	}else if(Browser.indexOf('chrome')!= -1){			//Google Chrome
		return 'chrome';
	}else if(Browser.indexOf('netscape')!= -1||Browser.indexOf('navigator')!= -1){						
		return 'netscape';
	}else if(Browser.indexOf('firefox')!= -1){
		return 'firefox';
	}else{
		return 'others';
	}
}

var browser = getBrowser();

function $(id){
	return document.getElementById(id);
}

function $n(id){
	return document.getElementsByName(id);
}

function $t(id){
	return document.getElementsByTagName(id);
}

String.prototype.trim = function(){ 
	return this.replace(/(^\s*)|(\s*$)/g,"");
}

function clearThis(obj,init){
	var re = new RegExp(init,'gi');
	var _text = obj.value.replace(re,"").trim();
	obj.value = _text;
}

function check1stWord(inText){
	var fw = inText.substring(0,1);
	var result = false;
	if(fw=="."||fw=="-"||fw=="0")result = true;
	return result;
}

function checkString(dataType,string){
	var re = "";
	switch(dataType){
		case "Int":
			re = /^[1-9]\d*$/;
			break;
		case "Num":
			re = /^[\d]*$/;
			break;
		case "Price":
			re = /^([1-9]\d*|[0])(\.[0-9]+)?$/;
			break;
		case "Email":
			re = /^(\w+([-+.]\w+)*)+@([0-9a-z][\w-]+\.)+[a-z]{2,4}$/i;
			break;
		case "UserID":
			re = /^[\w\@\_\-\.]{6,20}$/;
			break;
		case "Domain":
			re = /^[0-9a-z\-\_]{4,36}$/i;
			break;
		case "URL":
			re = /^https?:\/\/.+$/i;
			break;
		case "MailTo":
			re = /^mailto:(\w+([-+.]\w+)*)+@([0-9a-z][\w-]+\.)+[a-z]{2,4}$/i;
			break;
		case "Unique":
			re = /^[0-9a-f]{8}([-][0-9a-f]{4}){3}[-][0-9a-f]{12}$/i;
			break;
		case "PWD":
			re = /^[\S]{6,20}$/;
			break;
		case "Date":								//Format:mm-dd-yyyy
			re = /^(((0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01])-((1[6-9]|[2-9]\d)\d{2}))|((0?[13456789]|1[012])-(0?[1-9]|[12]\d|30)-((1[6-9]|[2-9]\d)\d{2}))|(0?2-(0[1-9]|1\d|2[0-8])-((1[6-9]|[2-9]\d)\d{2}))|(0?2-29-((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))))$/;
			break;
		default:
			//Nothing...
	}
	if(re!=""){
		return re.test(string);
	}else{
		return false;
	}
}

function btnOver(obj){
	obj.src = obj.src.substring(0,obj.src.length-7) + "_on.gif";
}

function btnOut(obj){
	obj.src = obj.src.substring(0,obj.src.length-7) + "_of.gif";
}

function doCheckLogin(form){
	var re = new RegExp('UserID or Email Address','i');
	if(re.test(form.inpUserID.value)){
		alert("Please input your User ID or Email Address!");
		form.inpUserID.value = '';
		form.inpUserID.focus();
		return false;
	}
	
	if(form.inpUserID.value.trim()==""){
		alert("Please input your User ID or Email Address!");
		form.inpUserID.focus();
		return false;
	}
	
	if(form.inpPassword.value.trim()==""){
		alert("Please input your Passwords!");
		form.inpPassword.focus();
		return false;
	}
	
	return true;
}

function initInput(obj,val){
	obj.focus();
	obj.select();
	if(window.addEventListener){ // Mozilla, Netscape, Firefox
		obj.addEventListener('click',function(){if(obj.value.toLowerCase()==val.toLowerCase())clearThis(obj,val);},false);
		obj.addEventListener('mouseout',function(){if(obj.value.trim()=='')obj.value=val;},false);
	}else{ // IE
		obj.attachEvent('onclick',function(){if(obj.value.toLowerCase()==val.toLowerCase())clearThis(obj,val);});
		obj.attachEvent('onmouseout',function(){if(obj.value.trim()=='')obj.value=val;});
	}
}

function loadTab(act,tab){				//act define: T;X;L;R;S(Save or Set)
	var error = false;
	var tabFile = '';
	var Selected = nSelected = getCookie('Tabber','Selected');
	var Shown = nShown = getCookie('Tabber','Shown');
	var Focus = nFocus = getCookie('Tabber','Focus');
	//var nSelected,nShown,nFocus;
	var ary,len,tabPos;
	var sHL = cHL = sC = cC = slBtn = srBtn = null;
	if(Selected!=null && Selected!=""){
		ary = Selected.split('|');
		len = ary.length;
	}
	
	switch(act){
		case 'T':
			if(tab=='Headlines'){
				tabFile = 'Headlines';
				sHL = 'Headlines';
				cHL = 'focus';
				sC = '<span onmouseover="showTip(this,\'Click to view news in this headlines selection\',true,262,6,3);" onclick="loadTab(\'T\',\'' + Shown + '\');">' + Shown + '</span>';
				cC = '';
				nFocus = '';
			}else{
				tabFile = Shown;
				sHL = '<span onmouseover="showTip(this,\'Click to view news in this headlines selection\',true,262,6,3);" onclick="loadTab(\'T\',\'Headlines\');">Headlines</span>';
				cHL = '';
				sC = Shown + '<div class="x"><div onclick="loadTab(\'X\',\'' + Shown + '\');" title="Close Tab"></div></div>';
				cC = 'focus';
				nFocus = nShown;
			}
			hideTip();
			break;
		case 'X':
			for(var i=0;i<len;i++){if(ary[i]==Shown)tabPos = i;}
			if(len<3){
				slBtn = '<div></div>';
				srBtn = '<div></div>';
			}else if(tabPos>len-3){
				srBtn = '<div></div>';
			}
			if(len<2){
				tabFile = 'Headlines';
				sHL = 'Headlines';
				cHL = 'focus';
				sC = '';
				cC = 'hidden';
				nSelected = nShown = nFocus = '';
			}else{
				nSelected = '';
				for(var i=0;i<len;i++){
					if(ary[i]==Shown){
						tabPos = i;
					}else{
						if(nSelected!='')nSelected += '|';
						nSelected += ary[i];
					}
				}
				if(tabPos<len-1){
					nShown = ary[tabPos+1];
				}else{
					nShown = ary[tabPos-1];
				}
				if($('li_customize').className=='focus'){
					nFocus = nShown;
					tabFile = nShown;
					sC = nShown + '<div class="x"><div onclick="loadTab(\'X\',\'' + nShown + '\');" title="Close Tab"></div></div>';
				}else{
					sC = '<span onmouseover="showTip(this,\'Click to view news in this headlines selection\',true,262,6,3);" onclick="loadTab(\'T\',\'' + nShown + '\');">' + nShown + '</span>';
				}
			}
			break;
		case 'L':
			for(var i=0;i<len;i++){if(ary[i]==Shown)tabPos = i;}
			if(tabPos==1)slBtn = '<div></div>';
			if(len>1)srBtn = '<div class="on" onmouseover="showTip(this,\'Click to view next headlines selection\',true,222,7,0);" onclick="loadTab(\'R\');"></div>';
			nShown = ary[tabPos-1];
			if($('li_customize').className=='focus'){
				nFocus = nShown;
				tabFile = nShown;
				sC = nShown + '<div class="x"><div onclick="loadTab(\'X\',\'' + nShown + '\');" title="Close Tab"></div></div>';
			}else{
				sC = '<span onmouseover="showTip(this,\'Click to view news in this headlines selection\',true,262,6,3);" onclick="loadTab(\'T\',\'' + nShown + '\');">' + nShown + '</span>';
			}
			break;
		case 'R':
			for(var i=0;i<len;i++){if(ary[i]==Shown)tabPos = i;}
			if(len>1)slBtn = '<div class="on" onmouseover="showTip(this,\'Click to view previous headlines selection\',true,248,7,0);" onclick="loadTab(\'L\');"></div>';
			if(tabPos==len-2)srBtn = '<div></div>';
			nShown = ary[tabPos+1];
			if($('li_customize').className=='focus'){
				nFocus = nShown;
				tabFile = nShown;
				sC = nShown + '<div class="x"><div onclick="loadTab(\'X\',\'' + nShown + '\');" title="Close Tab"></div></div>';
			}else{
				sC = '<span onmouseover="showTip(this,\'Click to view news in this headlines selection\',true,262,6,3);" onclick="loadTab(\'T\',\'' + nShown + '\');">' + nShown + '</span>';
			}
			break;
		case 'S':
			//var ti = $n('divTabItem');								//all Tab Item		- in msie error
			var ti = $('dlgBox').getElementsByTagName('div');
			var tl = ti.length;											//Tab Length
			var tv;																	//Single Tab Value
			nSelected = '';
			var j = 0;
			tabPos = 0;
			for(var i=0;i<tl;i++){
				if(ti[i].className=='checked'||ti[i].className=='selected'){
					if(nSelected!='')nSelected += '|';
					tv = ti[i].getAttribute("value");
					nSelected += tv;
					if(tv==Shown)tabPos = j;
					j++;
				}
			}
			
			if($('li_customize').className=='hidden'&&nSelected!=''){
				nShown = nSelected.split('|')[0];
				sC = '<span onmouseover="showTip(this,\'Click to view news in this headlines selection\',true,262,6,3);" onclick="loadTab(\'T\',\'' + nShown + '\');">' + nShown + '</span>';
				cC = '';
			}
			
			hideDiv('dlg');
			if(j>0){
				if(tabPos==0){
					slBtn = '<div></div>';
				}else{
					slBtn = '<div class="on" onmouseover="showTip(this,\'Click to view previous headlines selection\',true,248,7,0);" onclick="loadTab(\'L\');"></div>';
				}
				if(tabPos==j-1){
					srBtn = '<div></div>';
				}else{
					srBtn = '<div class="on" onmouseover="showTip(this,\'Click to view next headlines selection\',true,222,7,0);" onclick="loadTab(\'R\');"></div>';
				}
			}
			break;
		default:
			error = true;
	}
	if(error)return;
	setCookie('Tabber','Selected',nSelected,90);
	setCookie('Tabber','Shown',nShown,90);
	setCookie('Tabber','Focus',nFocus,90);
	if(sHL!=null)$('li_headlines').innerHTML = sHL;
	if(cHL!=null)$('li_headlines').className = cHL;
	if(sC!=null)$('li_customize').innerHTML = sC;
	if(cC!=null)$('li_customize').className = cC;
	if(slBtn!=null)$('hptablft').innerHTML = slBtn;
	if(srBtn!=null)$('hptabrgt').innerHTML = srBtn;
	if(tabFile!='')showTabBody('/tabber/',tabFile,'htm');
}

function getXmlhttp(){
	var http_request;
	if(window.XMLHttpRequest){																																				// if Mozilla, IE7, Safari etc
		http_request = new XMLHttpRequest();
	}else if(window.ActiveXObject){																																		// if IE6 or below
		try{http_request = new ActiveXObject("MSXML2.XMLHTTP");}
			catch(e){
		try{http_request = new ActiveXObject("Microsoft.XMLHTTP");}
			catch(e){}
		}
	}
	if(!http_request){ 
		window.alert("can't create XMLHttpRequest object.");
		return null;
	}	
	return http_request;
}

function showTabBody(path,file,ext){
	var re = / /gi;
	file = file.replace(re,"_");
	var url = path + file + '.' + ext;
	var xHttp = getXmlhttp();
	xHttp.onreadystatechange = function(){
		if(xHttp.readyState==4 && xHttp.status==200){
			$('tab_body').innerHTML = xHttp.responseText;
		}
	}
	url = url + "?Rand=" + (new Date()).getTime();
	xHttp.open("GET",url,true);
	xHttp.send(null);
}
//------------------------------------------- Tip -------------------------------------------
function getObjPos(obj){
	var _left = 0;
	var _top = 0;
	if(obj.offsetParent){
		_left = obj.offsetLeft;
		_top = obj.offsetTop;
		while(obj=obj.offsetParent){
			_left += obj.offsetLeft
			_top += obj.offsetTop
		}
	}
	return{x:_left,y:_top};
}

function hideTip(){
	var tipObj = $('divTip');
	if(tipObj){
		if(tipObj.style.display=="block"){
			tipObj.style.display = "none";
			$('tipPointer').style.display = "none";
		}
	}
}

function showTip(obj,_text,_auto,_width,_offset,offY,_color){
	if(obj){
		var pos = getObjPos(obj);
		var _offsetX;
		var _offsetY = 16 + offY;
		var divTip = $('divTip');
		var tipImg = $('tipPointer');
		divTip.style.top = pos.y + 30 + offY + "px";
		if(typeof(_offset)!="undefined"){
			_offsetX = _offset;
			divTip.style.left = pos.x + _offset - 16 + "px";
		}else{
			_offsetX = 8;
			divTip.style.left = pos.x - 8 + "px";
		}
		
		if(typeof(_width)!="undefined")divTip.style.width = _width + "px";
		if(typeof(_color)!="undefined" && _color!="")divTip.style.backgroundColor = _color;
		
		tipImg.style.left = pos.x + _offsetX + "px";
		tipImg.style.top = pos.y + _offsetY + "px";
		
		divTip.innerHTML = _text;
		tipImg.style.display = "block";
		divTip.style.display = "block";
		if(_auto){
			if(window.addEventListener){ // Mozilla, Netscape, Firefox
				obj.addEventListener('mouseout',hideTip,false);
			}else{ // IE
				obj.attachEvent('onmouseout',hideTip);
			}
		}
	}
}
//------------------------------------------ /Tip -------------------------------------------
//--------------------------------------------------- Cookie ----------------------------------------------------------
function setCookie(group, name, value, expires){
	var now = new Date();
	if(expires)expires = expires * 1000 * 60 * 60 * 24;
	var _expires = new Date(now.getTime() + (expires));
	var str = group + '=';
	if(value==null)value = '';
	if(name==''){
		str += escape(value);
	}else{
		//-------------------------------- get org cookie ---------------------------------
		var prefix = group + "=";
		var cookieStartIndex = document.cookie.indexOf(prefix);
		if(cookieStartIndex == -1){
			ostr = '';
		}else{
			var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
			if(cookieEndIndex == -1)cookieEndIndex = document.cookie.length;
			var ostr = document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex);
		}
		//------------------------------- /get org cookie ---------------------------------
		var oCookie = '';
		var ary = ostr.split('&');
		var len = ary.length;
		var ln = name.length;
		var isCookieExist = false;
		for(var i=0;i<len;i++){
			if(ary[i].substring(0,ln+1)==name+'='){
				isCookieExist = true;
				break;
			}
		}
		if(isCookieExist){
			for(var j=0;j<len;j++){
				if(j==i){
					str += name + '=' + escape(value);
				}else{
					str += ary[j];
				}
				if(j<len-1)str += '&';
			}
		}else{
			if(ostr!='')ostr += '&';
			str += ostr + name + '=' + escape(value);
		}
	}
	str += ((expires)? ';expires=' + _expires.toGMTString() : '' ) + ';path=/;domain=efeedlink.com';
	document.cookie = str;
}
	
function deleteCookie(name, path, domain){
	if(getCookie(name))document.cookie = name + '=' +
	((path)? ';path=' + path : '') +
	((domain)? ';domain=' + domain : '' ) +	';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}

function getCookie(group,name){
	var prefix = group + "=";
	var cookieStartIndex = document.cookie.indexOf(prefix);
	if(cookieStartIndex == -1)return null;
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length);
	if(cookieEndIndex == -1)cookieEndIndex = document.cookie.length;
	var str = document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex);
	if(typeof(name)!="undefined"&&name!=""){
		var ary = str.split('&');
		var ln = name.length;
		for(var i=0;i<ary.length;i++){
			if(ary[i].substring(0,ln)==name){
				str = ary[i].substring(ln+1,ary[i].length);
				break;
			}
		}
	}
	str = unescape(str);
	if(str!='')str = str.replace(/\+/gi,' ');
	return str;
}
//--------------------------------------------------- /Cookie ----------------------------------------------------------
function hideDiv(id){
	iTimerID = null;
	var div = $(id);
	if($('div_layer_background'))$('div_layer_background').style.display = 'none';
	if(div)div.style.display = 'none';
}

function chkTab(Selected,each){
	var bResult = false;
	if(Selected!=null && Selected!=""){
		var ary = Selected.split('|');
		len = ary.length;
		for(var i=0;i<len;i++){
			if(ary[i]==each){
				bResult = true;
				break;
			}
		}
	}
	return bResult;
}

function checkUsed(t,form){							//UserID;Email
	var obj,id,em,sTrue,sFalse,url;
	if(t=='U'){
		obj = form.inpUserID;
		id = obj.value;
		if(id.trim()==""){
			alert("Please specify your User ID.");
			obj.focus();
			return;
		}
		
		if(check1stWord(id)){
			alert("The first character of User ID can not accept\n\".\"\t\"-\"\t\"0\"");
			obj.focus();
			return;
		}
		
		if(!checkString('UserID',id)){
			alert("The User ID must be 6 to 20 alpha-numeric characters and no spacing.");
			obj.focus();
			return;
		}
		url = '/xml/chkUserID.html?id=' + id + '&em=';
		sFalse = 'Your chosen User ID has been used.<br />Please input another User ID.';
		sTrue = 'You can use the User ID indicated.';
	}else{
		obj = form.inpEmail;
		id = form.inpUserID.value;
		em = obj.value;
		if(em.trim()==""){
			alert("Please specify your email address.");
			obj.focus();
			return;
		}
	
		if(!checkString('Email',em)){
			alert("You have entered a wrong Email format.\nPlease enter again.");
			obj.focus();
			return;
		}
		if(t=='E'){
			url = '/xml/chkEmail.html?id=&em=' + em;
		}else{
			url = '/xml/chkEmail.html?id=' + id + '&em=' + em;
		}
		sFalse = 'The email address you indicated has already been used.<br />Please use a different email address of yours.';
		sTrue = 'You can use the Email Address indicated.';
	}
	var xmlHttp = getXmlhttp();
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status==200){
			var row = xmlHttp.responseXML.getElementsByTagName("Row");
			var exist = row[0].childNodes[0].nodeValue;
			if(exist=="True"){
				obj.focus();
				EFLMessage('alert',sFalse,380,98,true);
				return;
			}else{
				EFLMessage('info',sTrue,380,98,true);
				return;
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function EFLMessage(t,txt,_width,_height,auto){
	var div,sh,doc,_left,_top;
	var sTitle = 'System Alert';
	if(t=='info')sTitle = 'System Information';
	if(!$('msg')){
		div = document.createElement('div');
		div.id = 'msg';
		div.style.position = 'absolute';
		div.style.display = 'none';
		div.style.zIndex = 999;
		document.body.appendChild(div);
	}
	/*1st:0-120px;2nd:130px-330px;3rd:340px-560px;4th:570px-970px;5th:980px-1580px;6th:1590px-2590px*/
	if(_height > 600){
		sh = 1590;
	}else if(_height > 400){
		sh = 980;
	}else if(_height > 220){
		sh = 570;
	}else if(_height > 200){
		sh = 340;
	}else if(_height > 120){
		sh = 130;
	}else{
		sh = 0;
	}
	var sHTML = '<iframe frameborder="0" src="about:blank"></iframe>';
	sHTML += '<b class="b1"></b><b class="b2 d1" style="background-position:0 -' + sh + 'px;"></b><b class="b3 d1" style="background-position:0 -' + (sh+1) + 'px;"></b><b class="b4 d1" style="background-position:0 -' + (sh+2) + 'px;"></b>';
	sHTML += '<div class="msgbox" style="background-position:0 -' + (sh+5) + 'px;height:' + (_height-10) + 'px;">';
	sHTML += '  <div class="topBar"><div class="' + t + 'ico"></div><span class="title ' + t + '">' + sTitle + '</span><div class="btnclose" onclick="hideDiv(\'msg\');"></div></div>';
	sHTML += '  <div class="txt ' + t + '">' + txt + '</div>';
	sHTML += '</div>';
	sHTML += '<b class="b4 d1" style="background-position:0 -' + (_height+sh-5) + 'px;"></b><b class="b3 d1" style="background-position:0 -' + (_height+sh-4) + 'px;"></b><b class="b2 d1" style="background-position:0 -' + (_height+sh-2) + 'px;"></b><b class="b1b"></b>';
	
	div = $('msg');
	div.style.width = _width + "px";
	div.style.height = _height + "px";
	
	doc = document.documentElement;
	if(doc.clientWidth<_width){
		_left = (10 + D.scrollLeft) + 'px';
	}else{
		_left = ((doc.clientWidth-_width)/2+doc.scrollLeft) + 'px';
	}

	if(doc.clientHeight<_height){
		_top = (10 + doc.scrollTop) + 'px';
	}else{
		_top = ((doc.clientHeight-_height)/2+doc.scrollTop) + 'px';
	}
	div.style.left = _left;
	div.style.top = _top;
	div.innerHTML = sHTML;
	div.style.display = 'block';
	
	if(auto)iTimerID = window.setTimeout(function (){hideDiv('msg');},8000);
}

function showPayment(dialog){
	var obj = $n('chkboxAgreement')[0];
	if(dialog=='Enets')obj = $n('chkboxAgreement')[1];
	if(!obj.checked){
		alert("Please confirm your acceptance of the Terms & Conditions of Use.");
		obj.focus();
		return;
	}
	EFLDialog(dialog);
}

function EFLDialog(dialog,obj,evt,arg){				//arg define:dialog Type; click Obj; click event;Other arg sep by '|'
	var error = false;
	var b_center = false;
	var b_mask = false;
	var url = '';
	var _left,_top,_offsetX,_offsetY,_width,_height,_line,_bgcolor,_bdcolor;
	var sInner = '';
	switch(dialog){
		case 'howTo':
			_width = 450;_height = 300;_line = '';_offsetX = -429;_offsetY = 26;_bgcolor = '#f6f6f6';_bdcolor = '#ffccaa';
			sInner += '<div style="margin:0 5px;border-bottom:1px solid #979797;"><img src="/images/img_logo_268x90.gif" alt="eFeedLink Logo" /></div>';
			sInner += '<div class="icon" style="margin:5px;line-height:15px;padding-left:10px;background-position:0 -944px;font-weight:bold;">How to use "Customize"</div>';
			sInner += '<div style="margin:5px;line-height:15px;">Customize the "Headlines" menu bar to display channels for easy access from the homepage to top stories in the industry sections related to your work.</div>';
			sInner += '<div style="margin:0 5px;line-height:15px;">Click the "Customize" button, and then put a tick in the boxes next to the channels of interest to you. The tabs representing the channels will appear on the "Headlines" menu bar. You can put in as many tabs as you want.</div>';
			sInner += '<div style="margin:5px;line-height:15px;">Click on the tab to read the top story of the channel. If you have placed more than one tab, use the left and right arrows to select the top story of the channel you want to view.</div>';
			sInner += '<div style="margin:0 5px;line-height:15px;">To remove a channel from the menu bar, uncheck on the top right corner of the tab.</div>';
			break;
		case 'selTab':
			_width = 320;_height = '';_line = '';_offsetX = -235;_offsetY = 26;_bgcolor = '#f6f6f6';_bdcolor = '#ffccaa';
			if(browser=='netscape'||browser=='flock'){
				_offsetX = -230;
			}else if(browser=='maxthon'){
				_offsetX = -236;
			}
			var ary = new Array('Feed Grain','Protein Meal','Feed Supplement','Feed Manufacturing','Poultry & Egg','Swine','Ruminant','Aquaculture','Animal Health','Meat Processing','Asia','China','Americas','World','Industry');
			var Selected = getCookie('Tabber','Selected');
			
			var len = ary.length;
			var each,sClass,sClick;
			sInner += '<ul class="tabber">';
			for(var i=0;i<len;i++){
				each = ary[i];
      	sClass = '';
      	sClick = '';
      	if(chkTab(Selected,each)){
      		sClass = ' class="selected"';
      	}else{
      		sClick = ' onclick="setClass(this);"';
      	}
      	sInner += '<li' + sClass + '><div name="divTabItem" value="' + each + '"' + sClass + sClick + '></div>'+ each + '</li>';
			}
			sInner += '<li>&nbsp;</li>';
			sInner += '</ul>';
			sInner += '<div class="tabact"><div class="close" onclick="hideDiv(\'dlg\');"></div><div class="submit" onclick="loadTab(\'S\');"></div></div>';
			break;
		case 'PayPal':
			b_center = true;
			b_mask = true;
			var UniqueID = (new Date()).getTime() % 1000000000;
			url = dialog + '.html?' + UniqueID;
			_width = 420;_height = 320;_line = '';_bgcolor = '#f6f6f6';_bdcolor = '#ffccaa';
			sInner += '<div style="margin-top:144px;height:16px;line-height:16px;text-align:center;color:#f00;"><img src="/images/loading.gif" width="16" height="16" alt="Loading" /><br />Loading...</div>';
			break;
		case 'Forwards':			//Forwards Sign In
		case 'Comments':			//Comments Sign In
			b_center = true;
			b_mask = true;
			var UniqueID = (new Date()).getTime() % 1000000000;
			url = dialog + '.html?' + UniqueID + '&id=' + arg;
			_width = 620;_height = 320;_line = '';_bgcolor = '#f6f6f6';_bdcolor = '#ffccaa';
			break;
		case 'EditComm':
			b_center = true;
			b_mask = true;
			var UniqueID = (new Date()).getTime() % 1000000000;
			url = 'comments.html?' + UniqueID + '&op=edit&id=';
			if(arg.indexOf("|")!= -1){
				var ary = arg.split('|');
				url += ary[0] + '&ph=' + ary[1];
			}else{
				url += arg;
			}
			_width = 620;_height = 320;_line = '';_bgcolor = '#f6f6f6';_bdcolor = '#ffccaa';
			break;
		case 'DelComm':
			b_center = true;
			b_mask = true;
			var UniqueID = (new Date()).getTime() % 1000000000;
			url = 'comments.html?' + UniqueID + '&op=del&id=';
			if(arg.indexOf("|")!= -1){
				var ary = arg.split('|');
				url += ary[0] + '&ph=' + ary[1];
			}else{
				url += arg;
			}
			_width = 620;_height = 320;_line = '';_bgcolor = '#f6f6f6';_bdcolor = '#ffccaa';
			break;
		case 'Print':					//Print Sign In
			b_center = true;
			b_mask = true;
			_width = 420;_height = 320;_line = '';_bgcolor = '#f6f6f6';_bdcolor = '#ffccaa';
			sInner = arg;
			break;
		default:
			error = true;
	}
	if(error)return;
	if($('dlg') && $('dlg').style.display=='block'){
		$('dlg').style.display = 'none';
		return;
	}
	
	createMask(b_mask);
	buildDiv(_width,_height,_line,_bgcolor,_bdcolor);
	$('dlgBox').innerHTML = sInner;
	var div = $('dlg');
	if(b_center){
		var doc = document.documentElement;
		if(doc.clientWidth<_width){
			_left = (10 + D.scrollLeft);
		}else{
			_left = ((doc.clientWidth-_width)/2+doc.scrollLeft);
		}
		if(doc.clientHeight<_height){
			_top = (10 + doc.scrollTop);
		}else{
			_top = ((doc.clientHeight-_height)/2+doc.scrollTop);
		}
	}else{
		var pos = getObjPos(obj);
		_left = pos.x + _offsetX;
		_top = pos.y + _offsetY;
	}
	
	div.style.left = _left + 'px';
	div.style.top = _top + 'px';
	div.style.display = 'block';
	
	if(url!=''){
		var xmlHttp = getXmlhttp();
		xmlHttp.onreadystatechange = function(){
			if(xmlHttp.readyState == 4 && xmlHttp.status==200){
				var dochtml = xmlHttp.responseText;
				if(dochtml=='Session Expired'){
					window.location = 'status.html?login';
				}else{
					$('dlgBox').innerHTML = xmlHttp.responseText;
				}
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function stepMask(c){
	var opacity = c * 5;
	$('div_layer_background').style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity + ',finishOpacity=100,style=0)';
	$('div_layer_background').style.opacity = opacity / 100;
	c++;
	if(c <= 10){
		iTimerID = window.setTimeout('stepMask(' + c + ')', 5);
	}else{
		iTimerID = null;
	}
}

function createMask(b){																			//createDiv(obj){
	if(b){
		if($('div_layer_background')){
			var div = $('div_layer_background');
			div.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0,finishOpacity=100,style=0)';
			div.style.opacity = 0;
		}else{
			div = document.createElement('div');
			div.id = 'div_layer_background';
			div.style.position = 'absolute';
			div.style.left = div.style.top = '0px';
			div.style.width = document.body.scrollWidth + 'px';
			div.style.height = document.body.scrollHeight + 'px';
			div.style.backgroundColor = '#000000';
			div.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=0,finishOpacity=100,style=0)';
			div.style.opacity = 0;
			div.style.zIndex = 0;
			document.body.appendChild(div);
		}
		$('div_layer_background').style.display = 'block';
		iTimerID = window.setTimeout(function (){stepMask(1);},5);
	}else{
		return;
	}
}

function buildDiv(_width,_height,_line,_bgcolor,_bdcolor){
	var sHTML = '';
	var _style = '';
	if(!$('dlg')){
		div = document.createElement('div');
		div.id = 'dlg';
		div.style.position = 'absolute';
		div.style.display = 'none';
		document.body.appendChild(div);
	}

	if(typeof(_width)=="number")_style += 'width:' + _width + 'px;';
	if(typeof(_height)=="number")_style += 'height:' + _height + 'px;';
	if(typeof(_line)=="number")_style += 'line-height:' + _line + 'px;';
	if(typeof(_bgcolor)!="undefined")_style += 'background-color:' + _bgcolor + ';';
	if(typeof(_bdcolor)!="undefined"){
		_style += 'border:1px solid ' + _bdcolor + ';';
	}else{
		_style += 'border:1px solid #9d9da1;';
	}
	
	sHTML = '<div id="dlgBox" style="' + _style + '"></div>'
	
	$('dlg').innerHTML = sHTML;
}

function setClass(obj,txt){
	if(typeof(txt)!="undefined"){
		obj.className = txt;
	}else{
		if(obj.className=='checked'){
			obj.className = '';
		}else{
			obj.className = 'checked';
		}
	}
}

function doFilter(base,ps,dps,ph){
	var form = document.forms["FormFilter"];
	var month = form.inpFilterMonth.value;
	var year = form.inpFilterYear.value;
	if(month==''){
		alert("Please specify the Filer Month!");
		form.inpFilterMonth.focus();
		return;
	}
	if(year==''){
		alert("Please specify the Filer Year!");
		form.inpFilterYear.focus();
		return;
	}
	var url = base + '_m' + month + '_y' + year;
	if(ps!=dps)url += '_ps' + ps;
	if(ph>1)url += '_p' + ph;
	url += '.html';
	window.location.href = url;
}

function doListAll(base){
	window.location.href = base + '.html';
}

function gotoPage(base,totalpage){
	var page = $('gotopage').value;
	if(!checkString('Int',page)||page>totalpage){
		alert("Please specify valid number of Page!");
		return;
	}
	var url;
	if(page>1){
		url = base + '_p' + page + '.html';
	}else{
		url = base + '.html';
	}
	window.location.href = url;
}

function jumpPage(base,totalpage){
	var page = $('gotopage').value;
	if(!checkString('Int',page)||page>totalpage){
		alert("Please specify valid number of Page!");
		return;
	}
	var url;
	if(page>1){
		url = base + '&ph=' + page;
	}else{
		url = base;
	}
	window.location.href = url;
}

function popDefWin(_url,_name,features){ //v2.0
	var win = window.open(_url,_name,features);
	win.focus();
}

function doChangeRegion(form,sel){
	var _name = sel.options[sel.selectedIndex].text;
	var xmlHttp = getXmlhttp();
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status==200)showRegion(form,_name,xmlHttp.responseXML);
	}
	xmlHttp.open("GET","/xml/regions.xml",true);
	xmlHttp.send(null);
}

function showRegion(form,sel,xmlDoc){
	var row = xmlDoc.getElementsByTagName("country");
	var node,country,regions,region,_selected;
	var _input = form.inpState.value;
	var _width = "340px";
	var sHTML = "";
	for(var i=0;i<row.length;i++){
		node = row[i];
		country = node.getAttribute("name");
		if(sel==country){
			_width = "200px";
			regions = node.getElementsByTagName("region");
			sHTML = '<select size="1" name="inpRegion" style="width:190px;margin-right:5px;" onChange="setRegion(' + form.name + ',this);">';
			for(var j=0;j<regions.length;j++){
				region = regions[j].getAttribute("name");
				_selected = "";
				if(region==_input)_selected = " selected";
				sHTML += '<option value="' + j + '"' + _selected + '>' + region + '</option>';
			}
			sHTML += '</select>';
			break;
		}
	}
	form.inpState.style.width = _width;
	$('spanRegion').innerHTML = sHTML;
}

function setRegion(form,sel){
	var _index = sel.selectedIndex;
	if(_index>0)form.inpState.value = sel.options[_index].text;
}

function doCheckInfo(form){
	var _form = form.name;
	var xmlHttp,row;
	if(_form=="FormRegister"){
		if(form.inpUserID.value.trim()==""){
			alert("Please specify your User ID.");
			form.inpUserID.focus();
			return false;
		}
		
		if(check1stWord(form.inpUserID.value)){
			alert("The first character of User ID can not accept\n\".\"\t\"-\"\t\"0\"");
			form.inpUserID.focus();
			return false;
		}
		
		if(!checkString('UserID',form.inpUserID.value)){
			alert("The User ID must be 6 to 20 alpha-numeric characters and no spacing.");
			form.inpUserID.focus();
			return false;
		}
	}
	
	if(_form=="FormProfile"){
		var str = form.inpPassword.value.trim();
		if(str==""){
			alert("Please specify your password.");
			form.inpPassword.focus();
			return false;
		}
		
		if(!checkString('PWD',str)){
			alert("Your chosen password must at lease 6 characters and no spacing.");
			form.inpPassword.focus();
			return false;
		}
	}
	
	if(form.inpFirstName.value.trim()==""){
		alert("Please specify your First Name.");
		form.inpFirstName.focus();
		return false;
	}
		
	if(form.inpLastName.value.trim()==""){
		alert("Please specify your Last Name.");
		form.inpLastName.focus();
		return false;
	}
	
	if(form.inpScreenName.value.trim()==""){
		alert("Please specify your Screen Name.");
		form.inpScreenName.focus();
		return false;
	}
	
	var bd = form.inpBirthMonth.value + '-' + form.inpBirthDay.value + '-' + form.inpBirthYear.value;
	if(!checkString('Date',bd)){
		alert("You have entered a wrong Birthday format.");
		form.inpBirthMonth.focus();
		return false;
	}
	
	if(form.inpQualification.value==""){
		alert("Please specify Minimum Education.");
		form.inpQualification.focus();
		return false;
	}
	
	if(form.inpQualification.value==""){
		alert("Please specify Minimum Education.");
		form.inpQualification.focus();
		return false;
	}
	
	if(form.inpJobFunction.value==""){
		alert("Please specify the nature of your job.");
		form.inpJobFunction.focus();
		return false;
	}
	
	if(form.inpJobTitle.value.trim()==""){
		alert("Please specify your job title.");
		form.inpJobTitle.focus();
		return false;
	}
	
	if(form.inpEmail.value.trim()==""){
		alert("Please specify your email address.");
		form.inpEmail.focus();
		return false;
	}

	if(!checkString('Email',form.inpEmail.value)){
		alert("You have entered a wrong Email format.\nPlease enter again.");
		form.inpEmail.focus();
		return false;
	}
	
	if(form.inpBizCategories.value==""){
		alert("Please specify the Business Category of your company.");
		form.inpBizCategories.focus();
		return false;
	}
	
	if(form.inpCountry.value==""){
		alert("Please specify your Country of Residence.");
		form.inpCountry.focus();
		return false;
	}
	
	if(form.inpState.value.trim()==""){
		alert("Please specify the State or Province you reside in.");
		form.inpState.focus();
		return false;
	}
	
	if(form.inpCity.value.trim()==""){
		alert("Please specify Town or City of address entered.");
		form.inpCity.focus();
		return false;
	}
	
	if(form.inpZip.value.trim()==""){
		alert("Please specify Zip or Postal Code for your place of residence.");
		form.inpZip.focus();
		return false;
	}
	
	if(form.inpAddress.value.trim()==""){
		alert("Please specify your Address.");
		form.inpAddress.focus();
		return false;
	}
	
	if(form.inpTelCCode.value.trim()==""){
		alert("Please specify Country Code of telephone number you have indicated.");
		form.inpTelCCode.focus();
		return false;
	}
	
	if(!checkString('Num',form.inpTelCCode.value)){
		alert("Please indicate a numeric value for the Country Code of your telephone number.");
		form.inpTelCCode.focus();
		return false;
	}
	
	if(form.inpTelACode.value.trim()!=""){
		if(!checkString('Num',form.inpTelACode.value)){
			alert("Please indicate a numeric value for the Area Code of your telephone number.");
			form.inpTelACode.focus();
			return false;
		}
	}
	
	if(form.inpTelNo.value.trim()==""){
		alert("Please specify Telephone Number.");
		form.inpTelNo.focus();
		return false;
	}
	
	if(!checkString('Int',form.inpTelNo.value)){
		alert("Please indicate a numeric value for your telephone number.");
		form.inpTelNo.focus();
		return false;
	}
	
	if(form.inpTelEXT.value.trim()!=""){
		if(!checkString('Num',form.inpTelEXT.value)){
			alert("Please indicate a numeric value for the Extension of your telephone number.");
			form.inpTelEXT.focus();
			return false;
		}
	}
	
	if(form.inpFaxCCode.value.trim()!=""){
		if(!checkString('Num',form.inpFaxCCode.value)){
			alert("Please indicate a numeric value for the Country Code of your fax number.");
			form.inpFaxCCode.focus();
			return false;
		}
	}
	
	if(form.inpFaxACode.value.trim()!=""){
		if(!checkString('Num',form.inpFaxACode.value)){
			alert("Please indicate a numeric value for the Area Code of your fax number.");
			form.inpFaxACode.focus();
			return false;
		}
	}
	
	if(form.inpFaxNo.value.trim()!=""){
		if(!checkString('Int',form.inpFaxNo.value)){
			alert("Please indicate a numeric value for your fax number.");
			form.inpFaxNo.focus();
			return false;
		}
	}
	
	if(form.inpMobileCCode.value.trim()!=""){
		if(!checkString('Num',form.inpMobileCCode.value)){
			alert("Please indicate a numeric value for the Country Code of your mobile number.");
			form.inpMobileCCode.focus();
			return false;
		}
	}
	
	if(form.inpMobileACode.value.trim()!=""){
		if(!checkString('Num',form.inpMobileACode.value)){
			alert("Please indicate a numeric value for the Area Code of your mobile number.");
			form.inpMobileACode.focus();
			return false;
		}
	}
	
	if(form.inpMobileNo.value.trim()!=""){
		if(!checkString('Int',form.inpMobileNo.value)){
			alert("Please indicate a numeric value for your mobile number.");
			form.inpMobileNo.focus();
			return false;
		}
	}
	
	var obj = form.inpKeywords;
	var keywords = obj.value.trim();
	if(keywords!=""){
		if(!CheckKeyword(keywords)){
			alert("You have entered a wrong Keyword format.\nPlease correct it first.");
			obj.focus();
			return false;
		}
	}
	return true;
}

function doCheckPayment(form){
	if(!form.chkAgreement.checked){
		alert("Please confirm your acceptance of the Terms & Conditions of Use.");
		form.chkAgreement.focus();
		return false;
	}
}

function doCheckPwd(form){
	var obj = form.inpUserID;
	var string = obj.value.trim();
	if(strimg==''){
		alert("Please specify your User ID or Email Address.");
		obj.focus();
		return false;
	}
	if(!checkString('UserID',string)&&!checkString('Email',string)){
		alert("Please specify valid User ID or Email Address.");
		obj.focus();
		return false;
	}
	return true;
}

function processPrint(logo){
	if(!$('printArea'))return;
	var html = '';
	if(logo)html += '<div><img src="/images/img_logo_183x58.gif" width="183" height="58" alt="eFeedLink Logo"></div>';
	html += $('printArea').innerHTML;
	if(!$('printHTML')){
		div = document.createElement('div');
		div.id = 'printHTML';
		div.style.position = 'absolute';
		document.body.appendChild(div);
	}
	$('printHTML').innerHTML = html;
	window.print();
}

function printNews(obj,evt,id){
	var UniqueID = (new Date()).getTime() % 1000000000;
	url = 'print.html?' + UniqueID + '&id=' + id;
	var xmlHttp = getXmlhttp();
	xmlHttp.onreadystatechange = function(){
		if(xmlHttp.readyState == 4 && xmlHttp.status==200){
			var dochtml = xmlHttp.responseText;
			if(dochtml=='Print OK'){
				processPrint(true);
			}else{
				EFLDialog('Print',obj,evt,dochtml);
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function summCount(num,obj,show){
	var summ = obj.value.trim().replace(/[^\x00-\xff]/g,"aa");
	if(summ.length <= num){
		if(show!='')$(show).innerHTML = num - summ.length;
	} else {
		obj.value = obj.value.trim().toString().substr(0,num);
	}
}

function frmReset(form,idObj,txt){
	if(form){
		form.reset();
		$(idObj).innerHTML = txt;
	}
}

function doCheckComments(form){
	var obj = form.inpText;
	var str = obj.value.replace(/((<p>)|(<\/p>)|(\&nbsp\;)|(\&lt\;p\&gt\;)|(\&lt\;\/p\&gt\;)|(\s))/gi,"");
	if(str==''){
		alert("Please input your comments.");
		return false;
	}
	
	return true;
}

function doCheckForwards(form){
	if(form.inpMailToName.value.trim()==""){
		alert("Please specify mail to name.");
		form.inpMailToName.focus();
		return false;
	}
	
	if(form.inpMailToAddress.value.trim()==""){
		alert("Please specify mail to email address.");
		form.inpMailToAddress.focus();
		return false;
	}
	
	if(!checkString('Email',form.inpMailToAddress.value.trim())){
		alert("You have entered a wrong Email format.\nPlease enter again.");
		form.inpMailToAddress.focus();
		return false;
	}
	
	if(form.inpMailFromName.value.trim()==""){
		alert("Please specify mail from name.");
		form.inpMailFromName.focus();
		return false;
	}
		
	//check email
	if(form.inpMailFromAddress.value.trim()==""){
		alert("Please specify mail from email address.");
		form.inpMailFromAddress.focus();
		return false;
	}
		
	if(!checkString('Email',form.inpMailFromAddress.value.trim())){
		alert("You have entered a wrong Email format.\nPlease enter again.");
		form.inpMailFromAddress.focus();
		return false;
	}
	
	return true;
}

function doCheckSubscribe(form){
	var obj = form.inpEmail;
	
	var re = new RegExp('Email Address Here','i');
	if(re.test(obj.value.trim())){
		alert("Please specify your email address.");
		obj.value = '';
		obj.focus();
		return false;
	}
	
	if(obj.value.trim()==""){
		alert("Please specify your email address.");
		obj.focus();
		return false;
	}
	
	if(!checkString('Email',obj.value.trim())){
		alert("You have entered a wrong Email format.\nPlease enter again.");
		obj.focus();
		return false;
	}
	
	return true;
}

function doCheckSearch(form){
	var obj = form.ky;
	var vl = obj.value.trim();
	var re = new RegExp('Search eFeedLink','i');
	if(vl==""||re.test(vl)){
		alert("Please enter a keyword for the search!");
		obj.value = '';
		obj.focus();
		return false;
	}
	
	return true;
}