function openwin(url,name,features)	{
	window.open(url,name,features);
}



function iCheckAll(obj, b, d)	{
	if(!obj)	return;
	b= b?true:false;
	d= d?true:false;
	if(isNaN(obj.length))
		obj.checked= (d?!obj.disabled:true)&b;
	else
		for(var i= 0; i<obj.length; i++)
			obj[i].checked= (d?!obj[i].disabled:true)&b;
}
function iJoinChecked(obj, c)	{
	if(!obj)	return '';
	c= c?c:',';
	if(isNaN(obj.length))	return obj.checked?obj.value:'';
	
	var str= '';
	for(var i= 0; i<obj.length; i++)
		if(obj[i].checked)
			str+= (str==''?'':c)+ obj[i].value;
	return str;
}
function iCheckEmail(str)	{
	return /^[0-9a-zA-Z][0-9a-zA-Z\_\.\-]+@[0-9a-zA-Z][0-9a-zA-Z\_\.\-]+\.[0-9a-zA-Z][0-9a-zA-Z\_\.\-]+$/.test(str);
}
function iCheckPhone(str)	{
	return /^[0-9]+(\-[0-9]+)*(#[0-9]+)?$/.test(str);
}
function iCheckAccount(str)	{
	return /^[0-9a-zA-Z]{3,10}$/.test(str);
}
function iCheckPassword(str, acc)	{
	return /^[0-9a-zA-Z]{6,10}$/.test(str)
		&& str.toLowerCase().indexOf(acc.toLowerCase())==-1;
}



function iPrint()	{
	if(window.print)
		window.print();
	else	{
		var wb = '<OBJECT ID="wb1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
		document.body.insertAdjacentHTML('beforeEnd', wb);
		wb1.ExecWB(6, 2);
	}
}
function iBookmark(title, url)	{
	if(window.sidebar)
		window.sidebar.addPanel(title, url, "");
	else if(window.external)
		window.external.AddFavorite(url, title);
}
function iBookmarkMy()	{
	iBookmark(MSG.siteName, MSG.siteUrl);
}
function iBookmarkMyEng()	{
	iBookmark(MSG.siteNameEng, MSG.siteUrl);
}

function iCharCount(txta, div)	{
	if(!div)	return;
	div.innerText= (txta && txta.value && !isNaN(txta.value.length))?txta.value.length:0;
}
function iCharCountSetTo(div, c)	{
	if(div)	div.innerText= isNaN(c)?0:c;
}


function iLogout()	{
	HidFrm.location.href= '/member/login.act.php?logout=T';
}
function iOpenRecommend()	{
	window.open('/recommend.php','','width=569,height=590');
}
function iOpenSearchTip()	{
	window.open('/popup/search-tip.htm','','scrollbars=yes,width=590,height=600');
}
function iOpenPic(img, title, w, h, it, iw, ih, c)	{
	window.open('/picview.php?pic='+ img
		+ (it?('&t='+ it):'')+ (iw?('&w='+ iw):'')+ (ih?('&h='+ ih):'')
		+ (title?('&title='+ escape(title)):'')
		, '_blank', 'width='+ w+ ',height='+ h
		+ (c?(',left='+ ((screen.availWidth-w)/2)+ ',top='+ ((screen.availHeight-h)/2)):'') );
}
function iOpenIntima(u, w, h)	{
	window.open(u, '_blank'
		, 'left='+ ((screen.availWidth-w)/2)
		+ ',top='+ ((screen.availHeight-h)/2)
		+ ',width='+ w+ ',height='+ h).focus();
}
function iOpenOldEpaper(u)	{
	if(!u)	return false;
	window.open(u, '_blank');
	return true;
}
function iHrefOldEpaper(u)	{
	if(!u)	return false;
	location.href= u;
	return true;
}



var iQSearch_defaultText= '';
function iQSearch_init()	{
	iQSearch_defaultText= document.qSearch.keyword.value;
}
function iQSearch_onFocusBlur(tf)	{
	var obj= document.qSearch.keyword;
	if(tf)	{
		if(obj.value==iQSearch_defaultText)	obj.value='';
	}
	else	{
		if(obj.value=='')	obj.value=iQSearch_defaultText;
	}
}
function iQSearch_onSubmit()	{
	var obj= document.qSearch;
	obj.keyword.value= obj.keyword.value.replace(/^\s+|\s+$/, '');
	if(obj.keyword.value=='' || obj.keyword.value==iQSearch_defaultText)	{
		alert(MSG.plzKeyword);
		obj.keyword.focus();
		return false;
	}
	obj.action= (!obj.qsType.length || obj.qsType[1].checked)?'/product.php':'/events.php';
	return true;
}
function iQSearch(str)	{
	var obj= document.qSearch;
	obj.keyword.value= str;
	if(iQSearch_onSubmit())	obj.submit();
}

var iREpaper_defaultText= '';
function iREpaper_init()	{
	iREpaper_defaultText= document.rEpaper.email.value;
}
function iREpaper_reset()	{
	var obj= document.rEpaper;
	obj.enabl.value= 'A';
	obj.email.value= iREpaper_defaultText;
}
function iREpaper_onFocusBlur(tf)	{
	var obj= document.rEpaper.email;
	if(tf)	{
		if(obj.value==iREpaper_defaultText)	obj.value='';
	}
	else	{
		if(obj.value=='')	obj.value=iREpaper_defaultText;
	}
}
function iREpaper_onSubmit()	{
	var obj= document.rEpaper;
	if(iCheckEmail(obj.email.value))
		return true;
	else	{
		obj.email.focus();
		alert(MSG.plzEmail);
		return false;
	}
}
function iREpaper_submit(m)	{
	var obj= document.rEpaper;
	obj.enabl.value= m;
	if(iREpaper_onSubmit())	obj.submit();
}
function iREpaper_onOutside(email)	{
	document.rEpaper.email.value= email;
	iREpaper_submit('Ar');
}

function iReloadImg(id)	{
	if(id= document.getElementById(id))	id.src= id.src;
}

function iChangeLang(lang)	{
	var url= top.location.href;
	url= url.replace(/^http:\/\/[^\/]+(.*)/, '$1').replace(/#.*$/, '');
	if(/.*\.htm$/.test(url))
		url= url.replace(/(\/[a-z]{2,2}\-[A-Z]{2,2})?(\/.*)/, '/'+ lang+ '$2');
	else	{
		url= url.replace(/((\?|&)ln=)[^&]*(&|$)/, '$1'+ lang+ '$3');
		if(url.indexOf('?')==-1)
			url+= '?ln='+ lang;
		else if(!/(\?|&)ln=[^&]*(&|$)/.test(url))
			url+= '&ln='+ lang;
	}
	top.location.href= url;
}



function Zip_getPath(zip)	{
	var NOTFOUND= ['zh-CN', '2', null];
	if(!zip)	return NOTFOUND;
	for(var i1= 2, a1= Zip_AREA; i1<a1.length; i1++)
	for(var i2= 2, a2= a1[i1]; i2<a2.length; i2++)
	for(var i3= 2, a3= a2[i2]; i3<a3.length; i3++)
	if(a3[i3][1]==zip)	return [a1[i1][1], ''+ i2, zip];
	return NOTFOUND;
}
function Zip_setSelectTag(obj, sel)	{
	for(var i= 0, obj= obj.options; i<obj.length; i++)
		if(obj[i].value==sel)	return obj[i].selected= true;
}
function Zip_initSelectTag(obj, ary, sel, fv, ft)	{
	obj= obj.options;
	obj.length= 0;
	for(var i= 2, opt; i<ary.length; i++)	{
		obj.add(opt= document.createElement('option'));
		opt.value= fv?fv(ary[i]):i;
		opt.text= ft?ft(ary[i]):ary[i][0];
		opt.selected= opt.value==sel;
	}
}
function Zip_init(objs, f2, zip)	{
	objs[2].onchange= f2;
	objs[1].onchange= function()	{
		Zip_initSelectTag(objs[2], Zip_AREA[objs[0].selectedIndex+2][this.selectedIndex+2], this.value
			, function(ary){return ary[1];}
			, function(ary){return ary[1]+ ' '+ ary[0];}
		);
		objs[2].onchange();
	}
	objs[0].onchange= function()	{
		Zip_initSelectTag(objs[1], Zip_AREA[this.selectedIndex+2], this.value);
		objs[1].onchange();
	}
	
	Zip_initSelectTag(objs[0], Zip_AREA, '', function(ary){return ary[1];} );
	if(!zip)
		objs[0].onchange();
	else	{
		zip= Zip_getPath(zip);
		for(var i= 0; i<3; i++)	{
			Zip_setSelectTag(objs[i], zip[i]);
			objs[i].onchange();
		}
	}
}
function Zip_initAddr(objs, oArea, oZip, oAddr, zip, addr)	{
	Zip_init(objs
		, function()	{
			var addr1= objs[1].options[objs[1].selectedIndex].text;
			var addr2= objs[2].options[objs[2].selectedIndex].text;
			addr2= addr2.replace(/^\d+\s+/g, '');
			oArea.value= objs[0].value;
			oAddr.value= addr1==addr2?addr1:(addr1+ addr2);
			oZip.value= objs[2].options[objs[2].selectedIndex].value;
		}
		, zip);
	if(addr)	oAddr.value= addr;
}



function Date_format(d)	{
	var t;
	return ''+ d.getFullYear()
		+'/'+ ((t= d.getMonth()+1)<10?('0'+ t):t)
		+'/'+ ((t= d.getDate())<10?('0'+ t):t);
}
function Date_initSelectTag(obj, min, max)	{
	obj= obj.options;
	obj.length= 0;
	for(var i= min, opt; i<=max; i++)	{
		obj.add(opt= document.createElement('option'));
		opt.value= i;
		opt.text= i<10?('0'+i):i;
	}
}
function Date_init(objs, yMin, yMax, f, def)	{
	Date_initSelectTag(objs[0], yMin, yMax);
	Date_initSelectTag(objs[1], 1, 12);
	Date_initSelectTag(objs[2], 1, 31);
	
	if(def)	{
		def= new Date(def);
		var y= def.getFullYear();
		if(y<yMin)	def.setYear(yMin);
		if(y>yMax)	def.setYear(yMax);
		objs[0].options[def.getFullYear()-yMin].selected= true;
		objs[1].options[def.getMonth()].selected= true;
		objs[2].options[def.getDate()-1].selected= true;
	}
	if(f)	{
		for(var i=0; i<3; i++)
			objs[i].onchange= f;
		f();
	}
}
function Date_initBirth(objs, oBirth, birth)	{
	if(!birth)	{
		birth= new Date();
		birth.setYear(birth.getFullYear()-40);
		birth.setMonth(0);
		birth.setDate(1);
		birth= Date_format(birth);
	}
	Date_init(objs, 1920, new Date().getFullYear()
		, function()	{
			var d= new Date(objs[0].value+ '/'+ objs[1].value+ '/'+ objs[2].value);
			if(d.getMonth()!=objs[1].selectedIndex)	{
				d= new Date(objs[0].value+ '/'+ (objs[1].selectedIndex+2)+ '/0');
				objs[2].options[d.getDate()-1].selected= true;
			}
			oBirth.value= Date_format(d);
		}
		, birth);
}
function Date_initSingle(p, oH, sD)	{
	if(!sD)	sD= Date_format(new Date());
	var dy= new Date(sD).getFullYear();
	var o= [];
	for(var i= 0; i<3; i++)	o[i]= document.getElementById(p+i);
	Date_init(o, dy-2, dy
		, function ()	{
			var d= new Date(o[0].value+ '/'+ o[1].value+ '/'+ o[2].value);
			if(d.getMonth()!=o[1].selectedIndex)	{
				d= new Date(o[0].value+ '/'+ (o[1].selectedIndex+2)+ '/0');
				o[2].options[d.getDate()-1].selected= true;
			}
			oH.value= Date_format(d);
		}
		, sD);
}
function Date_initRange(p1, p2, oH1, oH2, d1, d2)	{
	if(!d1)	{
		d1= new Date();
		d1.setYear(d1.getFullYear()-2);
		d1.setMonth(0);
		d1.setDate(1);
		d1= Date_format(d1);
	}
	Date_initSingle(p1, oH1, d1);
	Date_initSingle(p2, oH2, d2);
}


function Powma(obj, mi, md, ms, h)	{
	obj= document.getElementById(obj);
	if(!obj)	return;
	var objCs= obj.childNodes, objCh= 0, objCl= 0;
	for(var i=0, o; i<objCs.length;)	{
		o= objCs[i];
		if(o.nodeType!=1)	{
			if(o.removeNode)
				o.removeNode(true);
			else
				o.parentNode.removeChild(o);
			continue;
		}
		o.style.marginTop= 
		o.style.marginBottom= '0px';
		objCl++;
		objCh+= o.offsetHeight;
		i++;
	}
	if(objCl<=0)	return;
	var x= Math.ceil(obj.offsetHeight/objCh);
	x= x<=2?1:(x-1);
	for(var i=0; i<=x; i++)
		for(var j=0; j<objCl; j++)
			obj.appendChild(objCs[j].cloneNode(true));
	
	var move, MOVE= move= function()	{
		while( (mi-md+objCs[0].offsetHeight)<=0 )	{
			objCs[0].style.marginTop= '0px';
			mi+= objCs[0].offsetHeight;
			obj.appendChild(obj.removeChild(objCs[0]));
		}
		mi= mi-md;
		objCs[0].style.marginTop= mi+ 'px';
	}
	obj.style.height= h+ 'px';
	obj.style.margin=
	obj.style.borderWidth= '0px';
	obj.style.overflow= 'hidden';
	obj.onmouseout= function()	{	move= MOVE;	}
	obj.onmouseover= function()	{	move= null;	}
	var walk= function()	{
		if(move)	move();
		setTimeout(walk, ms);
	}
	walk();
}

function Thuna(objs, max, num, urls)	{
	if(!objs || (objs= (''+ objs).split('|')).length<3)	return;
	for(var i= 0; i<3; i++)	objs[i]= objs[i]?document.getElementById(objs[i]):null;
	if(isNaN(max= parseInt(max)))	max= 0;
	if(isNaN(num= parseInt(num)))	num= 0;
	
	var x= [-1, -1, -1, -1, -1], xb= null, xf= [];
	if(objs[0])
		for(var i= 0, oc= objs[0].childNodes, oci; i<oc.length && (x[0]<0 || x[1]<0 || x[2]<0); i++)	{
			oci= oc[i];
			if(oci.nodeType!=1)	continue;
			if(x[0]==-1 && oci.tagName=='A' && (x[0]= i)>=0)	continue;
			if(x[1]==-1 && oci.tagName=='INPUT' && oci.type=='button' && (x[1]= i)>=0)	continue;
			if(x[2]==-1 && oci.tagName=='INPUT' && oci.type=='hidden' && (x[2]= i)>=0)	{
				xf[0]= oci.form;
				xf[1]= oci.name;
				continue;
			}
		}
	if(objs[1])
		for(var i= 0, oc= objs[1].childNodes, oci; i<oc.length && (x[3]<0 || x[4]<0); i++)	{
			oci= oc[i];
			if(oci.nodeType!=1)	continue;
			if(x[3]==-1 && oci.tagName=='INPUT' && oci.type=='button' && (x[3]= i)>=0)	continue;
			if(x[4]==-1 && oci.tagName=='INPUT' && oci.type=='file' && (x[4]= i)>=0)	{
				xf[2]= oci.form;
				xf[3]= oci.name;
				continue;
			}
		}
	if(objs[2])
		for(var i= 0, oc= objs[2].childNodes, oci; i<oc.length && !xb; i++)	{
			oci= oc[i];
			if(oci.nodeType!=1)	continue;
			if(oci.tagName=='INPUT' && oci.type=='button')	xb= oci;
		}
		
	var sum= function()	{
		if(max==0)	return 0;
		var o, sum= 0;
		if(xf[0] && xf[1] && (o= xf[0].elements[xf[1]]))
			if(isNaN(o.length))	sum+= o.value!=''?0:1;
			else	for(var i= 0; i<o.length; i++)	sum+= o[i].value!=''?0:1;
		if(xf[2] && xf[3] && (o= xf[2].elements[xf[3]]))
			sum+= isNaN(o.length)?1:o.length;
		return sum;
	};
	var bug= function()	{
		if(document.all || !xf[0])	return;
		for(var i= xf[0].childNodes.length-1; i>=0; i--)
			xf[0].appendChild(xf[0].removeChild(xf[0].childNodes[i]));
	}
	
	if(urls && objs[0] && x[0]>=0 && x[1]>=0 && x[2]>=0)	{
		urls= (''+ urls).split('|');
		var f= function(cnc, x, urls, i)	{
			cnc= cnc.childNodes;
			cnc[x[0]].href= urls[i-2];
			cnc[x[0]].innerHTML= urls[i-1];
			cnc[x[1]].onclick= function(e)	{
				if(!e)	e= window.event;
				if(cnc[x[2]].value=='')	{
					cnc[x[2]].value= urls[i];
					cnc[x[0]].style.textDecoration= 'line-through';
				}
				else	{
					if(max!=0 && sum()>=max)	{
						alert(MSG.thunaMaxReset.replace('%0', max));
						return;
					}
					cnc[x[2]].value= '';
					cnc[x[0]].style.textDecoration= '';
				}
			}
		}
		for(var i=2, cn, cnc; i<urls.length; i+= 3)	{
			if(urls[i]=='')	continue;
			f(cn= objs[0].cloneNode(true), x, urls, i);
			objs[0].parentNode.insertBefore(cn, objs[0]);
		}
		bug();
	}
	if(objs[0])	objs[0].parentNode.removeChild(objs[0]);
	
	if(objs[1])	(objs[1]= objs[1].parentNode.removeChild(objs[1])).id= '';
	if(xb && objs[1] && objs[2] && x[3]>=0)	{
		xb.onclick= function(e)	{
			if(e!=0 && max!=0 && sum()>=max)	{
				alert(MSG.thunaMax.replace('%0', max));
				return;
			}
			var of= objs[1].cloneNode(true);
			of.childNodes[x[3]].onclick= function(e)	{
				e= e?e.target:window.event.srcElement;
				e.parentNode.parentNode.removeChild(e.parentNode);
			}
			objs[2].parentNode.insertBefore(of, objs[2]);
			bug();
		}
		for(var i= sum(); i<num && i<max; i++)	xb.onclick(0);
	}
	else
		objs[2].parentNode.removeChild(objs[2]);
}



// product
function dyImgInit()	{
	var obj= dyImgMeta;
	obj.oBig= document.getElementById("big");
	obj.oZoom= document.getElementById("dyImgLb");
	obj.oIwin= document.getElementById("dyImg");
	obj.oBwin= obj.oBig.parentNode;
	obj.oLwin= createLwin();
	obj.oLarge= obj.oLwin.childNodes[0];
	obj.oSwin= createSwin();
	function createLwin()	{
		var t, o= document.createElement("div");
		o.style.width=
		o.style.height= "250px";
		o.style.padding= "0px";
		o.style.overflow= "hidden";
		o.style.backgroundColor= "gray";
		o.appendChild(t= document.createElement("img"));
		t.style.width=
		t.style.height= "500px";
		return o;
	}
	function createSwin()	{
		var o= document.createElement("div");
		o.style.position= "absolute";
		o.style.border= "1px solid green";
		return o;
	}
	function hideSwin()	{
		if(obj.oIwin.childNodes[0]==obj.oLwin)	{
			obj.oIwin.removeChild(obj.oLwin);
			obj.oIwin.appendChild(obj.oBwin);
			
			obj.oSwin.style.display= "none";
			document.body.removeChild(obj.oSwin);
			
			document.onmousemove= null;
		}
	}
	var biw= 500, bih= 500, bww= 250, bwh= 250;
	var siw= 80, sih= 80, sww= Math.floor(siw*bww/biw), swh= Math.floor(sih*bwh/bih);
	obj.oSwin.style.width= (sww<=0? 1: sww)+ 'px';
	obj.oSwin.style.height= (swh<=0? 1: swh)+ 'px';
	function showSwin(o, e, i)	{
		if(obj.oIwin.childNodes[0]!=obj.oLwin)	{
			obj.oIwin.removeChild(obj.oBwin);
			obj.oIwin.appendChild(obj.oLwin);
			
			document.body.appendChild(obj.oSwin);
			obj.oSwin.style.display= "";
			document.onmousemove= function(e)	{
				showSwin(o, (window.event || e), i);
			}
		}
		obj.oLarge.src= obj.array[i-1][0];
		obj.oLarge.alt= obj.array[i-1][1];
		
		var sil= o.clientLeft, sit= o.clientTop;
		for(var x= o; x; x= x.offsetParent)	{
			sil+= x.offsetLeft? x.offsetLeft: 0;
			sit+= x.offsetTop? x.offsetTop: 0;
		}
		var	pdl= (document.all? document.body.parentNode.scrollLeft: window.scrollX)+ e.clientX- sil,
			pdt= (document.all? document.body.parentNode.scrollTop: window.scrollY)+ e.clientY- sit;
		if(pdl<0 || pdt<0 || pdl>=siw || pdt>=sih)	{
			hideSwin();
			return;
		}
		var	swdl= pdl- Math.floor(sww/2),
			swdt= pdt- Math.floor(swh/2);
		if(swdl<=0)	swdl= 0;
		if(swdt<=0)	swdt= 0;
		if(swdl>sww)	swdl= sww;
		if(swdt>swh)	swdt= swh;
		obj.oSwin.style.left= (swdl+ sil)+ 'px';
		obj.oSwin.style.top= (swdt+ sit)+ 'px';
		obj.oLarge.style.marginLeft= (-swdl*biw/siw)+ 'px';
		obj.oLarge.style.marginTop= (-swdt*bih/sih)+ 'px';
		
		obj.oSwin.onmouseout= function(e)	{
			hideSwin();
		}
		obj.oSwin.onclick= function()	{
			dyImgChange(i);
		}
	}
	function attach(o, i)	{
		o.onmousemove= function(e)	{
			showSwin(o, (window.event || e), i);
		}
	}
	for(var i= 1, o; i<=6; i++)
		if(o= document.getElementById("small_"+ i))	{
			attach(o, i);
			new Image().src= obj.array[i-1][0];
		}
}
function dyImgChange(no)	{
	var obj= dyImgMeta;
	obj.oBig.src= obj.array[no-1][2];
	obj.oBig.alt= obj.array[no-1][1];
	obj.oBig.parentNode.href= 
	obj.oZoom.href= "javascript: dyImgLightbox("+ no+ ");";
}
function dyImgLightbox(no)	{
	var obj= dyImgMeta;
	try{	LIGHTBOX_INSTANCE.start({array: obj.array, href: obj.array[no-1][0]});	}catch(e){}
}
function prodTemp(pid)	{
	if(!pid)	return;
	HidFrm.location.href= '/member/mytemporary.act.php?pids='+ pid;
}