
var errfound=false;
var now=new Date();
var nowYear=now.getYear(); //this year
var nowMonth=now.getMonth()+1; //this month
var nowDate=now.getDate(); //today

function JB_doExit() {
  	window.onerror=null;
  	return true;
}

function JB_isErr(){
	errfound=true;
}

function JB_doConfirm(msg){
	var resure=confirm(msg);
	if(resure) errfound=true;
}

function JB_doPager(theBlock,dataPerPage,totData){
	var pagestr='';
	var theBlockObj=eval(theBlock);
	if(theBlockObj[0]){
		for(var i=0;i<theBlockObj.length;i++){
			pagestr+='[';
			pagestr+='<a name="page" href="javascript:JB_goToPage('+theBlock+','+(i+1)+')" onclick="JB_doFocusPage(this)">&nbsp;';
			pagestr+=(i*dataPerPage+1);
			pagestr+=' - ';
			pagestr+=(i==theBlockObj.length-1)?totData:((i+1)*dataPerPage);
			pagestr+='&nbsp;</a>';
			pagestr+=']';
		}
	}

	document.write(pagestr);	
	var defaultPage=(!(JB_getCookie('page of vipSelfManage')==null))?JB_getCookie('page of vipSelfManage'):1;
	JB_goToPage(theBlock,defaultPage);

}


function JB_goToPage(theBlock,pageNo){
	var theBlock=eval(theBlock);
	if(!theBlock[0])
		theBlock.style.display='block';
	else{
		for(var i=0;i<theBlock.length;i++){
			theBlock[i].style.display='none';
		}
		theBlock[pageNo-1].style.display='block';
	}

	JB_doSetCookie('page of vipSelfManage',pageNo);

	if(document.anchors('page')==null) return;
	if(page[0]){
		JB_doFocusPage(page[pageNo-1]);
	}
	else{
		JB_doFocusPage(page);
	}
}


function JB_doFocusPage(obj){
	var ancName=obj.name;
	var ancObj=document.anchors(ancName);
	var len=ancObj.length;
	if(ancObj[0]){
		for(var i=0;i<len;i++){
			ancObj[i].style.color='#009900';
			ancObj[i].style.backgroundColor='';
		}
	}
	obj.style.color='#002200';
	obj.style.backgroundColor='#CCEE66';
}

function JB_doPrint(ID){//v2.0--[ID] is optional
	if(document.images('memsmallLogo')){
		var memsmallLogoImg=new Image();
		memsmallLogoImg.src=document.images('memsmallLogo').src;
	}
	
	var ID=(ID!=null)?ID:'JB_doPrintTemplate';
	var myDiv=document.getElementById(ID);
	var footID=document.getElementById('foot');
	var NFW=JB_doPopupWindow('PrintWin');
	
	var imgObj = null;
	if (document.images('friendlyPrintBtn')) {
		imgObj = document.images('friendlyPrintBtn');
	}
	else if (event) { // when onclick occurs in IMG or A
		if (event.srcElement.tagName == 'IMG') {
			imgObj = event.srcElement;
		}
		else if (event.srcElement.tagName == 'A') {
			imgObj = event.srcElement.childNodes[0];
		}
	}
	else {
		for (var i = 0; i < document.links.length; i++ ) {
			if (document.links[i].href.indexOf('JB_doPrint') != -1) {
				imgObj = document.links[i].childNodes[0];
				break;
			}
		}
	}

	var friendlyPrintBtnImg = new Image();
	friendlyPrintBtnImg.src = imgObj.src;

	
	var str='';

	str+='<html>';
	str+=headstr;
	str+='<body bgcolor="#FFFFFF" valign="top">';
	str+='	<table align="center" valign="top" border="0" width="688">';//here, height of the table equals to A4 paper height

	if(document.images('memsmallLogo')){
		str+='		<tr>';
		str+='			<td>';
		str+='				'+'<img src="'+memsmallLogoImg.src+'">';
		str+='<hr>';
		str+='			</td>';
		str+='		</tr>';
	}

	str+='		<tr>';
	str+='			<td valign="top">';
	str+='				'+myDiv.innerHTML;
	str+='			</td>';
	str+='		</tr>';

	str+='		<tr id="friendlyPrintBtnBlock">';
	str+='			<td align="center">';
	str+='				'+'<a href="javascript:friendlyPrintBtnBlock.style.display=\'none\';window.print();"><img src="'+friendlyPrintBtnImg.src+'" border="0"></a>';
	str+='			</td>';
	str+='		</tr>';

	str+='		<tr>';
	str+='			<td id="pagefoot">';
	//str+='<hr>';
	str+=(footID)?footID.innerHTML:'';
	str+='			</td>';
	str+='		</tr>';

	str+='	</table>';
	str+='</body>';
	str+='</html>';

	NFW.document.open();
	NFW.document.write(str);
	NFW.document.close();
}

function JB_doDownload(file){
	var theURL=file;
	var winName='JB_doDownloadWin';
	var winW=250;
	var winH=250;
	var winPos=JB_doCenterWindow(winW,winH);
	var features='width='+winW+',height='+winH+','+winPos+',toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes';
	var popup=window.open(theURL,winName,features);
	popup.focus();
}


function JB_openSuccessWin(){
	window.open('/web66/askr/Merchandise?command=delCache&page=manager&control=md&http=/web66/product/html/delCacheSuccessForm.htm','messageWindow','scrollbars=no,width=450, height=275');
}

function JB_doPopupWindow(winName){
	var theURL='';
	var winW=600;
	var winH=400;
	var winPos=JB_doCenterWindow(winW,winH);
	var features='width='+winW+',height='+winH+','+winPos+',toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes';
	var popup=window.open(theURL,winName,features);
	return popup;
}


function JB_doPopupDesc(URL) {
	var windowprops = "location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=yes,left=100,top=100,width=300,height=150";
	popup = window.open(URL,"DescPopup",windowprops);
}


function JB_doCenterWindow(w,h) {
	var winl=(screen.width-w)/2;
	var wint=(screen.height-h)/2;
	var winpos='top='+wint+',left='+winl;
	return winpos;
}



function JB_isLengthLimit(field,theMinBytes,theMaxBytes){
	if(!JB_isFilled(field.value,theMinBytes)) return false;
	else{
		var len=field.value.length;
		if(len*3 <= theMaxBytes) return true;
		else if(len > theMaxBytes) return false;
		else return (JB_getTheRestBytes(field,theMaxBytes) >= 0);
	}
}



function JB_showTheRestBytes(str,maxbytes,divIDToShow){
	var a=JB_getTheRestBytes(str,maxbytes);
	if(typeof(divIDToShow)!='undefined') divIDToShow.innerText=a;
	return (a);
}


function JB_getTheRestBytes(str,maxbytes){
	var totbytes=0;
	var maxlen=0;
	for(var i=0;i<str.value.length;i++){
   		var c=str.value.substring(i,i+1);
   		totbytes+=(c>'~')?3:1;
   		maxlen++;
	}
    return (maxbytes-totbytes);//return the rest bytes
}

function JB_doTrimString(field,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
}

function JB_isChecked(r) {
	if(r.checked!=true){
    	for (var i=0; i<r.length; i++) {
        	if (r[i].checked==true)	return true;
        }
        return false;
    }
    else{
    	return true;
    }
}


function JB_doCheckAll(field) {
	var chkflag=true;
	JB_doCheckAllFields(field,chkflag);
}


function JB_doUncheckAll(field) {
	var chkflag=false;
	JB_doCheckAllFields(field,chkflag);
}


function JB_doCheckAllFields(field,checkflag){
	if(field[0]){
		for (i = 0; i < field.length; i++) {
			field[i].checked=checkflag;
		}
	}
	else {
		field.checked=checkflag;
	}
}

/*
	define time pulldown menu object
*/
function JB_selTimeObj(selType,selName,selStart,selEnd,selectedOpt){
	this.selType=selType;
	/* selType is 'year' or 'month' or 'date' */
	this.selName=selName;
	this.selStart=selStart;
	this.selEnd=selEnd;
	this.selectedOpt=selectedOpt;
	this.JB_selOutput=new JB_selOutput(this);
}


/*
	time pulldown menu html output
*/
function JB_selOutput(JB_selTimeObj){
	var selectedOpt;
	if(JB_selTimeObj.selectedOpt==''){
		switch(JB_selTimeObj.selType) {
			case 'year':
				selectedOpt = nowYear;
				break;
			case 'month':
				selectedOpt = nowMonth;
				break;
			case 'date':
				selectedOpt = nowDate;
				break;
		}
	}
	else{
		selectedOpt=JB_selTimeObj.selectedOpt;
	}
	document.write('<select name="'+JB_selTimeObj.selName+'">');
	for(var i=JB_selTimeObj.selStart;i<=JB_selTimeObj.selEnd;i++){
		if(i==selectedOpt)
			document.write('<option value="'+i+'" selected="">'+i+'</option>');
		else
			document.write('<option value="'+i+'">'+i+'</option>');
	}
	document.write('</select>');
}


/*
	check pulldown menu
*/
function JB_isSelected(item) {
    if(item.options == null) return false;
    if(item.selectedIndex == -1) return false;
    if(item.options[item.selectedIndex].value == "") return false;
    return true;
}


/*
	check time in pulldown menus
	time1 must be after time2
*/
function JB_isTime1AfterTime2(yy1,mm1,dd1,yy2,mm2,dd2){
	var y1,m1,d1,y2,m2,d2;
	y1=eval(yy1);
	m1=eval(mm1);
	d1=eval(dd1);
	y2=eval(yy2);
	m2=eval(mm2);
	d2=eval(dd2);
	if(y1>y2) return true;
	else if(y1<y2) return false;
	else{//y1=y2
		if(m1>m2) return true;
		else if(m1<m2) return false;
		else{//m1=m2
			if(d1>=d2) return true;
			else if(d1<d2) return false;
		}
	}
	return true;
}

function JB_isNum(argvalue){
	argvalue=argvalue.toString();
	if(argvalue.length==0) return false;
	for(var n=0;n < argvalue.length;n++){
		var x = argvalue.substring(n,n+1);
		if(x < "0" || x > "9" || x == "."){
			return false;
		}
	}
	return true;
}

function JB_isEmail (emailStr) {

   var emailPat=/^(.+)@(.+)$/;
   var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
   var validChars="\[^\\s" + specialChars + "\]";
   var quotedUser="(\"[^\"]*\")";
   var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
   var atom=validChars + '+';
   var word="(" + atom + "|" + quotedUser + ")";
   var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
   var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
   var matchArray=emailStr.match(emailPat);

   if (matchArray==null) return false;

   var user=matchArray[1];
   var domain=matchArray[2];

   if (user.match(userPat)==null) return false;

   var IPArray=domain.match(ipDomainPat)
   if (IPArray!=null) {
	for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) return false;
      }
      return true
   }

   var domainArray=domain.match(domainPat)
   if (domainArray==null) return false;
   var atomPat=new RegExp(atom,"g");

   var domArr=domain.match(atomPat);
   var len=domArr.length;
   if (domArr[domArr.length-1].length<2 ||
      domArr[domArr.length-1].length>3) {
      return false;
   }

   if (len<2) return false;

   return true;
}


function JB_isTelAreacode(num) {
	var flag = (JB_isFilled(num,2) && !JB_isFilled(num,4) && JB_isNum(num));
	return flag;
}

function JB_isTelephone(num) {
	var flag = (JB_isFilled(num,5) && !JB_isFilled(num,11) && JB_isNum(num));
	return flag;
}

function JB_isTelExt(num) {
	var flag = (JB_isFilled(num,2) && !JB_isFilled(num,7) && JB_isNum(num));
	return flag;
}

/*
	check cellphone numbers
*/
function JB_isCellphone(cphone){
	if(!cphone) return false;
	if(cphone.value.length < 9 || cphone.value.length > 10) return false;
	if(!JB_isNum(cphone.value)) return false;
	return true;
}
/*
	check cellphone numbers allow empty
*/
function JB_isCellphoneoknull(cphone){
	if(cphone.value=="") return true;
	if(cphone.value.length < 9 || cphone.value.length > 10) return false;
	if(!JB_isNum(cphone.value)) return false;
	return true;
}

function JB_doUnderConstructionImg(inWidth,inHeight,properties){
	var oriWidth=180,oriHeight=127;
	var outWidth,outHeight,Percentage;
	Percentage=(oriWidth/inWidth - oriHeight/inHeight>0)?(inWidth/oriWidth):(inHeight/oriHeight);
	outWidth=Math.round(oriWidth * Percentage);
	outHeight=Math.round(oriHeight * Percentage);
	document.write('<img src="/web66/image/viplogin/underconstruction.gif" width="' + outWidth + '" height="' + outHeight+'" '+ properties + '"/>');
}

var srcImg;
function JB_imageViewer(myImg) {
	srcImg = myImg;
	window.open('/web66/md/html/imageViewer.html','messageWindow','width=150,height=150,toolbar=no,scrollbars=yes,resizable=yes');
	void(0);
}

/*	HUfunction(Ω # ɹw #  # eXeɪˬd #)һ
	JB_doCheckImageDimensions,JB_showImageDimensions,JB_doCheckImgSize***/
var fileNameY;
var maxImgSizeY;
var maxImgWidthY;
var maxImgHeightY;
var previewImgY;
var defaultImgY;

function JB_doCheckImageDimensions (fileNameX,maxImgSizeX,maxImgWidthX,maxImgHeightX,previewImgX,defaultImgX) {
 
  	var imgURL=fileNameX.value;


  	fileNameY=fileNameX;
  	maxImgSizeY=maxImgSizeX;
  	maxImgWidthY=maxImgWidthX;
  	maxImgHeightY=maxImgHeightX;
  	previewImgY=previewImgX;
  	defaultImgY=defaultImgX;
  	thisImgSize=0;

  	JB_getImageDimension(imgURL, JB_showImageDimensions);
}


function JB_getImageDimension (imgURL, loadHandler) {
	var img = new Image();
  	img.onload = loadHandler;
  	if (document.layers
      	&& location.protocol.toLowerCase() != 'file:'
      	&& navigator.javaEnabled())
    	netscape.security.PrivilegeManager.enablePrivilege(
      	'UniversalFileRead'
    );
  	img.src = imgURL;
}


function JB_showImageDimensions () {
  	previewImgY.src=fileNameY.value;
  	var thisImgSize=Math.floor(previewImgY.fileSize/1024*10)/10;
  	var thisImgWidth=this.width;
  	var thisImgHeight=this.height;
  	if(!JB_doCheckImgSize(maxImgSizeY,maxImgWidthY,maxImgHeightY,thisImgSize,thisImgWidth,thisImgHeight)){
  		previewImgY.src=defaultImgY;
  	}
	else{
		errfound=false;
	}
	this.onload=null;
}

function JB_enableUpload(e){
	var f=document.forms;
	for(var i=0;i<f.length;i++){
		var elem=f[i].elements;
		for(var j=0;j<elem.length;j++){
			if(elem[j].type=='file' && event.srcElement==elem[j]){
				var canUpload=(opener)?opener.JB_canUpload:JB_canUpload;
				if(!canUpload) alert('No enough space');
				//alert(canUpload);
				return canUpload;
			}
		}
	}
}


function JB_emptyOptions(selectObj) {
	for (var i = selectObj.options.length - 1 ; i >= 0; i--) {
		selectObj.options[i] = null;
	}
	if (myCtrl == ctrlObj && myGroup.items){
	        JB_swapOptions(null,beCtrledObj,myGroup.items[0]);
	}
	
}

var opVal=0;

if (document.all) var IE4=true;
else if (document.layers) var NN4=true;
else var OTHER=true;

function JB_toShowLayer(layID) {
	if (IE4) document.all(layID).style.visibility = "visible";
	if (NN4) document.layers[layID].visibility = "show";
}

function JB_toHideLayer(layID) {
	if (IE4) document.all(layID).style.visibility = "hidden";
	if (NN4) document.layers[layID].visibility = "hidden";
}

function JB_toFadeout(el) {
	if(IE4) {
		var fadeTarget=el;
		if (opVal==100) {
			clearTimeout(fadeTarget);
		}
		if (opVal>=0) {
			opVal-=25;
			document.all(el).style.filter="Alpha(Opacity="+ opVal +")";
			fadeoutId=setTimeout("JB_toFadeout('"+ fadeTarget +"')",0);
		}
		else {
			clearTimeout(fadeTarget);
			document.all(el).style.filter="";
			JB_toHideLayer(el);
			opVal=0;
  	}
}
	else JB_toHideLayer(el);
}

function JB_toFadein(el) {
	if(IE4) {
		var fadeTarget=el;
		if (opVal==0) {
			clearTimeout(fadeTarget);
			document.all(el).style.filter="Alpha(Opacity=0)";
			JB_toShowLayer(el);
		}
		if (opVal<=100) {
			opVal+=15;
			document.all(el).style.filter="Alpha(Opacity="+ opVal +")";
			fadeinId=setTimeout("JB_toFadein('" + fadeTarget + "')",0);
		}
		else {
			clearTimeout(fadeTarget);
			document.all(el).style.filter="";
			opVal=100;
		}
	}
	else JB_toShowLayer(el);
}


/*
	Get Set Del Cookie
*/
function JB_doSetCookie(name,value,expires){
	document.cookie = name + "=" + escape(value) + "; path=/" +
	((expires == null) ? " " : "; expires =" + expires.toGMTString());
}

function JB_getCookie(name) {
	var cname = name + "=";
	var dc = document.cookie;

	if(dc.length > 0) {
		begin = dc.indexOf(cname);

		if(begin != -1) {
			begin += cname.length;
		end = dc.indexOf(";",begin);

		if(end == -1) end = dc.length;
			return unescape(dc.substring(begin,end));
		}
	}
	return null;
}


function JB_doDelCookie(name){
	document.cookie = name + "=; expires=Thu,01-Jan-70 00:00:01 GMT" + "; path=/";
}



function JB_toAddFCMForm(redirURL,fcmSource){
	var formStr='';

	var elem=new Array(8);
	elem[0]=new Array('command','new');
	elem[1]=new Array('id','');
	elem[2]=new Array('redirectURL',redirURL);
	elem[3]=new Array('name','');
	elem[4]=new Array('URL','');
	elem[5]=new Array('fcmSource',fcmSource);
	elem[6]=new Array('type','origin');
	elem[7]=new Array('mode','normal');

	var elemType='hidden';
	formStr+='<form method="post" name="addToFCMListForm" action="/web/FCMSetup">';

	for(var i=0;i<elem.length;i++){
		formStr+='<input type="'+elemType+'" name="'+elem[i][0]+'" value="'+elem[i][1]+'">';
	}

	formStr+='</form>';

	document.write(formStr);
}

function JB_toAdd2FCM(cmd,funcID,funcName,funcURL,funcfcmSource){
	var f=document.addToFCMListForm;
	f.command.value=cmd;/*command:new|delete*/
	f.id.value=funcID;
	//f.redirectURL.value='MemSBack';
	f.name.value=funcName;
	f.URL.value=funcURL;
	if(funcfcmSource != null) f.fcmSource.value=funcfcmSource;
	//f.type.value='origin';
	//f.mode.value='normal';
	return false;
}

function JB_importScript(srcScript) {
	var head = document.getElementsByTagName('head').item(0);
	script = document.createElement('script');
	script.src = srcScript;
	script.type = 'text/javascript';
	script.defer = true;
	void(head.appendChild(script));
	//void(document.body.appendChild(script));
	//document.write('<scr' + 'ipt src="' + srcScript + '" defer><\/script>');
}

function md(type,id,title,content,listprice,sellprice,items) {
	this.type = type;
	this.id = id;
	this.title = title;
	this.content = content;
	this.listprice = listprice;
	this.sellprice = sellprice;
	this.items = items || [];	
}

function mb(type,gid,gtitle,id,title,content,sdate,edate,items) {
	this.type = type;
	this.gid = gid;
	this.gtitle = gtitle;
	this.id = id;
	this.title = title;
	this.content = content;
	this.sdate = sdate;
	this.edate = edate;
	this.items = items || [];	
}

function faq(gid,gtitle,id,forq,fora,items) {	
	this.gid = gid;
	this.gtitle = gtitle;
	this.id = id;	
	this.forq = forq;
	this.fora = fora;	
	this.items = items || [];	
}

function msgroup(id,title,content,deca,right,items) {	
	this.id = id;
	this.title = title;
	this.content = content;	
	this.deca = deca;
	this.right = right;	
	this.items = items || [];	
}

function mdclassify_List(name,id,count,items) {
	this.name = name;
	this.id = id;
	this.count = count;
	this.serial = -1;
	this.items = items || [];	
}

function cmd(id,title,content,listprice,sellprice,bonus,items) {	
	this.id = id;
	this.title = title;
	this.content = content;
	this.listprice = listprice;
	this.sellprice = sellprice;
	this.bonus = bonus;
	this.items = items || [];	
}

function callServer_(MID) {
	var  ima  = new Image();
	ima.src="/web/Comp?command=setHit&amp;MID="+MID;
}

document.write('<scr' + 'ipt src="/web66/js/theme.js"><\/script>');
document.write('<scr' + 'ipt src="/web66/js/MM_lib.js"><\/script>');
document.write('<scr' + 'ipt src="/web66/js/JB_ObjLib.js"><\/script>');