// Input revolve
function check_input_focus(node,def)	{ if(node.value==def) node.value=''; return; }
function check_input_blur(node,def)	{ if(node.value=='') node.value=def; return; }

// Other
var winWidth=0;
var winHeight=0;
function findDimensions(){
	if(window.innerWidth) winWidth=window.innerWidth;
	else if((document.body) && (document.body.clientWidth)) winWidth=document.body.clientWidth;
	if(window.innerHeight) winHeight=window.innerHeight;
	else if ((document.body) && (document.body.clientHeight)) winHeight=document.body.clientHeight;
	/* nasty hack to deal with doctype switch in IE */
	if(document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth){
		winHeight=document.documentElement.clientHeight;
		winWidth=document.documentElement.clientWidth;
	}
}
findDimensions();
window.onresize=findDimensions;

String.prototype.valid=function(type){
	var valid_regex={
		num_nat:/^([0-9]+)$/,
		email:/^([a-z0-9_\-\.]+)@(([a-z0-9_\-]{2,})\.)+([a-z]{2,4})$/i
	};
	return typeof(regex=valid_regex[type])!="undefined" && regex.test(this);
}
	
// Pop-up
function user_popup(href){
	return general_popup(href,'user_profile','auto',450,300);
}
function event_reg_popup(id){
	return general_popup('/events/reg/'+id,'events_reg','auto',640,400);
}
function general_popup(href,wname,wini,width,height){
	if(href.href) href=href.href;
	if(wini=='auto') wini="status=0,toolbar=0,menubar=0,resizable=0,scrollbars=no";
	var whost=window;
	while(whost!=top) whost=whost.parent;
	whost=whost.document;
	windowimg=whost.open(href,wname,((wini.length?(wini+','):'')+'width='+width+',height='+height));
	windowimg.moveTo((winWidth-width)/2,250);
	return false;
}
function author_digest_popup(lnk){
	return general_popup(lnk,'author_digest','status=0,toolbar=0,menubar=0,resizable=0,scrollbars=yes',980,700);
}

// Roll Menu
// ---------
var rollmenu={
	setup:{
		fontMin:1.0,
		fontMax:1.5,
		fontStep:0.1,
		tmrInterval:40
	},
	act:{
		u:{
			fontStep:function(a){return ((a-rollmenu.setup.fontStep)<rollmenu.setup.fontMin)?rollmenu.setup.fontMin:(a-rollmenu.setup.fontStep);},
			isFin:function(a){return a==rollmenu.setup.fontMin;}
		},
		d:{
			fontStep:function(a){return ((a+rollmenu.setup.fontStep)>rollmenu.setup.fontMax)?rollmenu.setup.fontMax:(a+rollmenu.setup.fontStep);},
			isFin:function(a){return a==rollmenu.setup.fontMax;}
		}
	},
	list:[]
};
rollmenu.cbStep=function(id){
	this.list[id].rollStep();
}
rollmenu.init=function(wrp_id){
	wrp=document.getElementById(wrp_id);
	if(!wrp) return;
	items=wrp.getElementsByTagName('div');
	for(i in items){
		item_tmp=items[i];
		if(item_tmp.className!=='item') continue;
		capt_hnd=(item_tmp.getElementsByTagName('h3'))[0];
		roll_hnd=(item_tmp.getElementsByTagName('div'))[0];
		capt_hnd['roll_hnd']=roll_hnd;
		capt_hnd['parentHnd']=item_tmp;
		this.capt_ptt(capt_hnd);
	}
}
rollmenu.capt_ptt=function(hnd){
	id_tmp=this.list.length;
	hnd['list_id']=id_tmp;
	this.list[id_tmp]=hnd;
	hnd['fs']=this.setup.fontMin;
	hnd['rdir']='u';
	hnd['msg']=document.createElement('span');
	hnd.appendChild(hnd.msg);
	hnd.msg.style.fontSize='1em';
	hnd.msg.innerHTML=hnd.innerHTML;
	hnd.removeChild(hnd.firstChild);
	hnd.onmouseover=function(){
		if(this.rdir=='d') return;
		this.rdir='d';
		this.loadTmr(id_tmp);
		return;
	}
	hnd.onmouseout=function(){
		if(this.rdir=='u') return;
		this.rdir='u';
		this.loadTmr();
		return;
	}
	hnd.loadTmr=function(){
		setTimeout('rollmenu.cbStep('+this.list_id+');',rollmenu.setup.tmrInterval);
	}
	hnd.rollStep=function(){
		this.fs=rollmenu.act[this.rdir].fontStep(this.fs);
		if(!rollmenu.act[this.rdir].isFin(this.fs)) this.loadTmr();
		this.msg.style.fontSize=this.fs+'em';
		rollHeight=this.parentHnd.clientHeight*((this.fs-rollmenu.setup.fontMin)/(rollmenu.setup.fontMax-rollmenu.setup.fontMin));
		this.roll_hnd.style.height=rollHeight+'px';
		//this.roll_hnd.style.display=rollHeight>0?'block':'none';
		return;
	}
}