function translate(lang){
	var s=location.href;
	s=s.replace(/\/lang_\w*/,'/lang_'+lang);
	location.href=s;
}

function windowstop(){
	if(window.stop)window.stop();
	else if(document.execCommand) document.execCommand('Stop');
}

function winopen(url){
	window.open(url, arguments[1] ? arguments[1] : '_blank');
}

function popupopen(url){
	var name=arguments[3] ? arguments[3] : 'pwin';

	var p="toolbar=no,location=no,directories=no,status=0,menubar=no,scrollbars=yes,resizable=1";
	if(arguments[1]) p+=",width=" + arguments[1];
	if(arguments[2]) p+=",height=" + arguments[2];
	var win = window.open (url,name,  p);
	win.focus();
	return win;
}

function fitPic(p){
	window.open('picture.html?'+p,'fitWindow','height=100,width=100,top=0,left=0,z-lock=1,resizable=1');
}
function fitDialog(){
	var b=document.body;
	window.dialogWidth=parseInt(window.dialogWidth.substring(0, window.dialogWidth.length-2))+b.scrollWidth-b.clientWidth+'px';
	window.dialogHeight=parseInt(window.dialogHeight.substring(0, window.dialogHeight.length-2))+b.scrollHeight-b.clientHeight+'px';
	var x, y;
	x=(window.screen.width-parseInt(window.dialogWidth.substring(0, window.dialogWidth.length-2)))/2;
	y=(window.screen.height-parseInt(window.dialogHeight.substring(0, window.dialogHeight.length-2)))/2;
	if(x>=0)window.dialogLeft=x;
	else window.dialogLeft=0;
	if(y>=0)window.dialogTop=y;
	else window.dialogTop=0;
}
function fitWin(){
	if(navigator.appName.indexOf('Microsoft')>=0)
		window.resizeBy(document.body.scrollWidth-document.body.clientWidth, document.body.scrollHeight-document.body.clientHeight);
	else window.resizeBy(document.width-window.innerWidth, document.height-window.innerHeight);
}
function winCenter(){
	var w, h;

	if(document.body.clientWidth){
		w=document.body.clientWidth;
		h=document.body.clientHeight;
	}
	else if(window.outerWidth){
		w=window.outerWidth;
		h=window.outerHeight;
	}
	else if(window.documentElement && window.documentElement.clientWidth){
		w=window.documentElement.clientWidth;
		h=window.documentElement.clientHeight;
	}
	else return;
	var x, y;
	x=(screen.width-w)/2;
	y=(screen.height-h)/2;
//	x=(parent.width-w)/2;
//	y=(parent.height-h)/2;
	if(!(x>0))x=0;
	if(!(y>0))y=0;
	window.moveTo(x,y);

}
function modalOpen(url){
	return showModalDialog(url, window, "status:0;resizable:1;");
}
function clickwin(url){
	var w, h, n='clickwin';
	if(arguments[1]!=null)w=",width="+arguments[1];
	if(arguments[2]!=null)h=",height="+arguments[2];
	if(arguments[3]!=null)n=arguments[3];
	var win=window.open(url, n, 'toolbar=0'+w+h+',resizable=1,personalbar=0,status=0,scrollbars=1,menubar=0');
	win.focus();
}

function confirmgo(msg, url){
	if(!msg || msg=='')msg='Are you sure to delete this item?';
	if(arguments[2]) url+="&redirect="+encodeURIComponent(location.href);
	if(confirm(msg))window.location.href=url;
}
function locationgo(url){
	if(arguments[1]){
		if(arguments[1].confirm && !confirm(arguments[1].confirm))reutrn;
		if(arguments[1].prompt) url+=prompt(arguments[1].prompt, arguments[1].promptdft);
		if(arguments[1].addredir) url+="&redirect="+encodeURIComponent(location.url);
	}
	window.location.href=url;
}
function searchindex(total,perpage){
	var curpage=1;
	var pname='page';
	var max;
	var par=arguments[2] ? arguments[2] : new Object();
	if(par['pagename'])pname=par['pagename'];
	curpage=location2value(pname);
	if(!(curpage>0))curpage=1;
	var from, to;
	to=perpage*curpage;
	if(to>total)to=total;
	from=perpage*(curpage-1)+1;
	if(!(total>0))from=0;
	if(from>to)to=from;
	return {'from':from,'to':to};

}
function urlmodified(url, name, v){
	if(url==null || url=='')return '';
	var obj=new Object();
	var a=url.split('&');
	if(a==null || a.length==null)return '';
	for(var i=0; i<=a.length; i++){
		if(a[i]==null) continue;
		var a2=a[i].split('=', 2);
		if(a2[1]!=null && a2[1]!='') obj[a2[0]]=a2[1];
	}
	obj[name]=encodeURIComponent(v);
	var r='';
	for(var i in obj)r+="&"+i+'='+obj[i];
	return r.substring(1);
}
function locationmodify(name, v){
	var s=window.location.search.substr(1);
	if(arguments[2] && url2value(s, name)==v)v=arguments[2];
	window.location.search='?'+urlmodified(s, name, v);
}