function f_navigator() {
	var browser=navigator['userAgent'].toLowerCase();



	if (browser.indexOf('firefox')!=-1) { return 'Firefox'; }
	if (browser.indexOf('msie')!=-1) { return 'Internet Explorer'; }
	if (browser.indexOf('chrome')!=-1) { return 'Chrome'; }
	if (browser.indexOf('opera')!=-1) { return 'Opera'; }
	if (browser.indexOf('safari')!=-1) { return 'Safari'; }
	return '';
}



function f_var(variable,type) {
	if (typeof(type)!='string') { return; }



	if (type=='S') { return ('undefinedbooleanobjectfunction'.indexOf(typeof(variable))!=-1)?'':''+variable; }
	if (type=='n') { return ('undefinedbooleanobjectfunction'.indexOf(typeof(variable))!=-1)?0:Math.round(0+variable); }
	if (type=='N') { return ('undefinedbooleanobjectfunction'.indexOf(typeof(variable))!=-1)?0:Math.max(0,Math.round(0+variable)); }
	if (type=='d') { return ('undefinedbooleanobjectfunction'.indexOf(typeof(variable))!=-1)?0:0+variable; }
	if (type=='D') { return ('undefinedbooleanobjectfunction'.indexOf(typeof(variable))!=-1)?0:Math.max(0,0+variable); }
	if (type=='O') { return (typeof(variable)!='object')?undefined:variable; }
	if (type=='F') { return (typeof(variable)!='function')?undefined:variable; }
}



function f_rand(number1,number2) {
	number1=f_var(number1,'n');
	number2=f_var(number2,'n');
	return (number1==number2)?number1:Math.round(Math.random()*(number2-number1))+number1;
}



function f_unique() {
	var id='uni_'+f_rand(10000,99999);



	while (document.getElementById(id)) { id='uni_'+f_rand(10000,99999); }
	return id;
}



function f_load(hyper,parameter) {
	hyper=f_var(hyper,'S');
	parameter=f_var(parameter,'O');
	if (!hyper) { return ''; }



	var connection=(window['XMLHttpRequest'])?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
	connection.open('POST',hyper,false);



	var variable='';
	for (var i in parameter) { variable+='&'+i+'='+encodeURIComponent(parameter[i]).replace(/~/g,'%7E').replace(/%20/g,'+'); }



	connection.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	connection.send(variable);
	return (connection['status']==200)?f_trim(connection['responseText']):'';
}



function f_day(year,month) {
	year=f_var(year,'N');
	month=f_var(month,'N');
	if ((!year) || (!month) || (month>12)) { return 0; }



	if ((month==1) || (month==3) || (month==5) || (month==7) || (month==8) || (month==10) || (month==12)) { return 31; }
	else if ((month==4) || (month==6) || (month==9) || (month==11)) { return 30; }
	else if (year/4-Math.floor(year/4)) { return 28; }
	return 29;
}



function f_date(data) {
	data=f_var(data,'S');



	if (!data) {
		var date=new Date();
		return date.getFullYear()+'-'+(1+date.getMonth())+'-'+date.getDate();
	}



	data=data.replace(/\-0/g,'-')+' ';
	return data.substr(0,data.indexOf(' '));
}



function f_trim(data,limit) {
	data=f_var(data,'S');
	limit=f_var(limit,'N');
	if (!data) { return ''; }



	data=data.replace(/\r/g,'').replace(/ *\n */g,'\n').replace(/^\n+|\n+$|^ +| +$/g,'').replace(/ +/g,' ');
	return ((!limit) || (data.length<=limit))?data:f_trim(data.substr(0,limit-3))+'...';
}



function f_capitalize(data) {
	data=f_var(data,'S');
	if (!data) { return ''; }



	data=data.replace(/\_/g,' ');
	return data.substr(0,1).toUpperCase()+data.substr(1).toLowerCase();
}



function f_grab(object) {
	object=f_var(object,'O');
	if (!object) { return; }



	var x=0;
	var y=0;



	while (object) {
		x+=object['offsetLeft'];
		y+=object['offsetTop'];
		object=object['offsetParent'];
	}
	return [x,y];
}



function f_child(id,object) {
	id=f_var(id,'S');
	object=f_var(object,'O');
	if ((!id) && (!object)) { return -1; }



	if (id) { object=document.getElementById(id); }
	if (!object) { return -1; }



	for (var i=0; i<object['parentNode']['children'].length; i++) {
		if (object['parentNode']['children'][i]==object) { return i; }
	}
	return -1;
}



function f_new(parent,type,attribute,before,reference) {
	parent=f_var(parent,'O');
	type=f_var(type,'S');
	attribute=f_var(attribute,'O');
	before=f_var(before,'O');
	reference=f_var(reference,'O');
	if ((!parent) || (!type)) { return; }



	var object=document.createElement(type);
	for (var i in attribute) {
		if (i=='id') { f_free(attribute[i]); }
		(i.substr(0,6)=='style_')?object['style'][i.substr(6)]=attribute[i]:object[i]=attribute[i];
	}



	if (typeof(object['innerHTML'])=='undefined') { object['innerHTML']=''; }
	if (typeof(object['value'])=='undefined') { object['value']=''; }



	if (reference) {
		var coordinate=f_grab(reference);
		object['style']['top']=coordinate[1]+'px';
		object['style']['left']=coordinate[0]+'px';
	}



	(before)?parent.insertBefore(object,before):parent.appendChild(object);



	if ((type=='select') && (object['multiple']) && (f_navigator()=='Internet Explorer')) { object.focus(); }
	return object;
}



function f_free(id,object) {
	id=f_var(id,'S');
	object=f_var(object,'O');
	if ((!id) && (!object)) { return; }



	if (id) { object=document.getElementById(id); }
	if (object) { object['parentNode'].removeChild(object); }
}



function f_inc(begin,end,current) {
	begin=f_var(begin,'n');
	end=f_var(end,'n');
	current=f_var(current,'d');
	if (begin==end) { return 0; }



	var way=Math.abs(begin-end);
	if (!way) { return 0; }



	var ratio=0;
	var portion=1;



	current=Math.abs(begin-current);
	if (!current) { ratio=1; }
	else { (current<way/2)?current=way-current:portion=2; }



	if (!ratio) { ratio=Math.max(1,Math.round((way-current)*0.25)); }
	if ((portion==2) && (current+ratio>=way-1)) { return 0; }
	return (begin>end)?0-ratio:ratio;
}



function f_morph(id,attribute,trigger) {
	id=f_var(id,'S');
	attribute=f_var(attribute,'O');
	if (!id) { return; }



	var object=document.getElementById(id);
	if (!object) { return; }



	if (!attribute) {
		if (!object['~attribute']) { return; }
		attribute=object['~attribute'];
		if (object['~trigger']) { trigger=object['~trigger']; }
	}



	clearTimeout(object['~f_morph']);
	if ((typeof(attribute['hmove'])!='undefined') && (typeof(attribute['~hmove_c'])=='undefined')) {
		attribute['hmove']=f_var(attribute['hmove'],'n');
		attribute['~hmove_b']=attribute['~hmove_c']=f_grab(object)[0];
		attribute['~hmove_e']=(attribute['~hmove_w'])?attribute['hmove']:attribute['~hmove_b']+attribute['hmove'];
	}
	if ((typeof(attribute['vmove'])!='undefined') && (typeof(attribute['~vmove_c'])=='undefined')) {
		attribute['vmove']=f_var(attribute['vmove'],'n');
		attribute['~vmove_b']=attribute['~vmove_c']=f_grab(object)[1];
		attribute['~vmove_e']=(attribute['~vmove_w'])?attribute['vmove']:attribute['~vmove_b']+attribute['vmove'];
	}



	if ((typeof(attribute['hscale'])!='undefined') && (typeof(attribute['~hscale_c'])=='undefined')) {
		attribute['hscale']=f_var(attribute['hscale'],'n');
		attribute['~hscale_b']=attribute['~hscale_c']=object['offsetWidth'];
		attribute['~hscale_e']=(attribute['~hscale_w'])?attribute['hscale']:attribute['~hscale_b']+attribute['hscale'];
	}
	if ((typeof(attribute['vscale'])!='undefined') && (typeof(attribute['~vscale_c'])=='undefined')) {
		attribute['vscale']=f_var(attribute['vscale'],'n');
		attribute['~vscale_b']=attribute['~vscale_c']=object['offsetHeight'];
		attribute['~vscale_e']=(attribute['~vscale_w'])?attribute['vscale']:attribute['~vscale_b']+attribute['vscale'];
	}



	if ((typeof(attribute['hscroll'])!='undefined') && (typeof(attribute['~hscroll_c'])=='undefined')) {
		attribute['hscroll']=f_var(attribute['hscroll'],'n');
		attribute['~hscroll_b']=attribute['~hscroll_c']=object['scrollLeft'];
		attribute['~hscroll_e']=(attribute['~hscroll_w'])?attribute['hscroll']:attribute['~hscroll_b']+attribute['hscroll'];



		var range=object['scrollWidth']-object['clientWidth'];
		if ((!attribute['~hscroll_b']) && (attribute['~hscroll_e']<0)) { attribute['~hscroll_e']=range; }
		else if ((attribute['~hscroll_b']==range) && (attribute['~hscroll_e']>range)) { attribute['~hscroll_e']=0; }
		else { attribute['~hscroll_e']=Math.min(range,attribute['~hscroll_e']); }
	}
	if ((typeof(attribute['vscroll'])!='undefined') && (typeof(attribute['~vscroll_c'])=='undefined')) {
		attribute['vscroll']=f_var(attribute['vscroll'],'n');
		attribute['~vscroll_b']=attribute['~vscroll_c']=object['scrollTop'];
		attribute['~vscroll_e']=(attribute['~vscroll_w'])?attribute['vscroll']:attribute['~vscroll_b']+attribute['vscroll'];



		var range=object['scrollHeight']-object['clientHeight'];
		if ((!attribute['~vscroll_b']) && (attribute['~vscroll_e']<0)) { attribute['~vscroll_e']=range; }
		else if ((attribute['~vscroll_b']==range) && (attribute['~vscroll_e']>range)) { attribute['~vscroll_e']=0; }
		else { attribute['~vscroll_e']=Math.min(range,attribute['~vscroll_e']); }
	}



	if ((attribute['color']) && (!attribute['~color_c'])) {
		if (object['_COLOR']) { attribute['~color_b']=object['_COLOR']; }
		else if (!attribute['~color_b']) { return; }
		attribute['~color_c']=attribute['~color_b'];
		attribute['~color_e']=attribute['color'];
		object['_COLOR']=attribute['~color_b'];
	}
	if ((attribute['background']) && (!attribute['~background_c'])) {
		if (object['_BACKGROUND']) { attribute['~background_b']=object['_BACKGROUND']; }
		else if (!attribute['~background_b']) { return; }
		attribute['~background_c']=attribute['~background_b'];
		attribute['~background_e']=attribute['background'];
		object['_BACKGROUND']=attribute['~background_b'];
	}
	if ((attribute['border']) && (!attribute['~border_c'])) {
		if (object['_BORDER']) { attribute['~border_b']=object['_BORDER']; }
		else if (!attribute['~border_b']) { return; }
		attribute['~border_c']=attribute['~border_b'];
		attribute['~border_e']=attribute['border'];
		object['_BORDER']=attribute['~border_b'];
	}
	if ((typeof(attribute['opacity'])!='undefined') && (typeof(attribute['~opacity_c'])=='undefined')) {
		if (typeof(object['_OPACITY'])!='undefined') { attribute['~opacity_b']=object['_OPACITY']; }
		else if (typeof(attribute['~opacity_b'])=='undefined') { return; }
		attribute['opacity']=Math.min(100,f_var(attribute['opacity'],'N'));
		attribute['~opacity_b']=Math.min(100,f_var(attribute['~opacity_b'],'N'));
		attribute['~opacity_c']=attribute['~opacity_b'];
		attribute['~opacity_e']=attribute['opacity'];
		object['_OPACITY']=attribute['~opacity_b'];
	}



	var ratio=0;
	var paint='';
	var more=0;
	for (var i in attribute) {
		if ((i.substr(0,1)=='~') || (typeof(attribute['~'+i+'_c'])=='undefined')) { continue; }



		paint='';
		if ('colorbackgroundborder'.indexOf(i)!=-1) {
			paint=f_color(attribute['~'+i+'_c'],attribute['~'+i+'_e'],1);
			ratio=(paint)?1:0;
		}
		else if (i!='opacity') { ratio=f_inc(attribute['~'+i+'_b'],attribute['~'+i+'_e'],attribute['~'+i+'_c']); }
		else if (attribute['~'+i+'_e']>attribute['~'+i+'_c']) { ratio=(attribute['~'+i+'_c']+2>=attribute['~'+i+'_e'])?0:2; }
		else { ratio=(attribute['~'+i+'_c']-2<=attribute['~'+i+'_e'])?0:-2; }



		if (!ratio) { attribute['~'+i+'_c']=attribute['~'+i+'_e']; }
		else { attribute['~'+i+'_c']=(paint)?paint:attribute['~'+i+'_c']+ratio; }



		switch (i) {
			case 'hmove':object['style']['left']=attribute['~'+i+'_c']+'px'; break;
			case 'vmove':object['style']['top']=attribute['~'+i+'_c']+'px'; break;
			case 'hscale':object['style']['width']=attribute['~'+i+'_c']+'px'; break;
			case 'vscale':object['style']['height']=attribute['~'+i+'_c']+'px'; break;
			case 'hscroll':object['scrollLeft']=attribute['~'+i+'_c']; break;
			case 'vscroll':object['scrollTop']=attribute['~'+i+'_c']; break;
			case 'color':object['style']['color']=object['_COLOR']=attribute['~'+i+'_c']; break;
			case 'background':object['style']['backgroundColor']=object['_BACKGROUND']=attribute['~'+i+'_c']; break;
			case 'border':object['style']['borderColor']=object['_BORDER']=attribute['~'+i+'_c']; break;
			default:
				object['style']['opacity']=attribute['~'+i+'_c']/100;
				object['style']['filter']='alpha(opacity='+attribute['~'+i+'_c']+')';
				object['_OPACITY']=f_var(attribute['~'+i+'_c'],'S');
		}



		if (ratio) { more++; }
		else {
			delete attribute[i];
			delete attribute['~'+i+'_b'];
			delete attribute['~'+i+'_c'];
			delete attribute['~'+i+'_e'];
		}
	}



	if (more) {
		object['~attribute']=attribute;
		if (trigger) { object['~trigger']=trigger; }
		object['~f_morph']=setTimeout('f_morph(\''+id+'\')',15);
		return;
	}



	if (object['~attribute']) { object['~attribute']=undefined; }
	if (object['~trigger']) { object['~trigger']=undefined; }
	if (typeof(trigger)=='function') { trigger(); }
	else if (typeof(trigger)=='string') { eval(trigger); }
}



function f_paint(grey) {
	if (!grey) { return 'rgb('+f_rand(0,255)+','+f_rand(0,255)+','+f_rand(0,255)+')'; }



	var color=f_rand(0,255);
	return 'rgb('+color+','+color+','+color+')';
}



function f_rgb(data) {
	data=f_var(data,'S');
	if (!data) { return; }



	data=(data.substr(0,4)=='rgb(')?data.substr(4).replace(')',''):data.replace('#','');
	var color=(data.indexOf(',')!=-1)?data.split(','):[parseInt(data.substr(0,2),16),parseInt(data.substr(2,2),16),
	parseInt(data.substr(4,2),16)];



	color[0]=Math.min(255,f_var(color[0],'N'));
	color[1]=Math.min(255,f_var(color[1],'N'));
	color[2]=Math.min(255,f_var(color[2],'N'));
	return color;
}



function f_color(begin,end) {
	begin=f_var(begin,'S');
	end=f_var(end,'S');
	if ((!begin) || (!end)) { return ''; }



	var color1=f_rgb(begin);
	var color2=f_rgb(end);



	for (var i=0; i<3; i++) {
		if (color2[i]>color1[i]) { color1[i]=(color1[i]+5>=color2[i])?color2[i]:color1[i]+5; }
		else { color1[i]=(color1[i]-5<=color2[i])?color2[i]:color1[i]-5; }
	}
	return ((color1[0]!=color2[0]) || (color1[1]!=color2[1]) || (color1[2]!=color2[2]))?'rgb('+color1[0]+','+color1[1]+','+color1[2]+')':'';
}



function f_dom(id) {
	id=f_var(id,'S');
	if (!id) { return ''; }



	if (document.getElementById(id)) { return document.getElementById(id); }
}
