
function init()
{
	var body = createContainer(document.body,'body');
	var headbar = createContainer(body,'headbar');
	createContainer(headbar,'logo');
	menu(headbar);
	createImage(body,'loading','','images/loading.gif');
	
	// searchbar
	var search  = createContainer(body,'searchbar');
	createInput(search,'search','text','search','',true);
	createText(search,'Ok','link_searchSend','link');
	createContainer(search,'info');

	// content
	var content = createContainer(body,'frame');
	
	// footer
	var footer = createContainer(body,'footer');
	createText(footer,'(c) 2008 material-db.com | All rights reserved |','footer_txt');
	createText(footer,'','userCount');
	createText(footer,' |');
	createText(footer,'','materialCount');
	
	// history object and start site
	if ($.browser.mozilla){
		dhtmlHistory.initialize();
		dhtmlHistory.create();
		dhtmlHistory.addListener(showHistory);
		showHistory(dhtmlHistory.getCurrentLocation());
	}
	else show();
	
	// cookie logon
	if (withCookie) var logonArray = getCookie(Array('user','pass'));
	if (logonArray.length > 1) sendJson('logon',object('user',logonArray[0],'password',descrypePassword(logonArray[1])));
	//logonSend(logonArray[0],descrypePassword(logonArray[1]));	
}
function click(evt,element)
{	
	if (!evt) evt = event; // for internet explorer
	if (!element) element = this;
	var idArray = element.id.split('_');
	action = idArray[0];
	
	// normal click
	if (evt.type == 'click') {
	
		switch (action)
		{
			case 'show':		show(idArray[1]);				break;
			case 'link': 		window[idArray[1]](idArray); 	break;
			case 'popup':		window['create'+firstBig(idArray[1])](getObject(idArray[1])); break;
			case 'download':	window.location.href = element.id.slice(action.length+1); break;
			case 'display':		display(idArray[1]); break;
			case 'linkD':		window.location.href = idArray[2];
			case 'radioDisplay':radioDisplay(idArray[1],idArray[2]); break;
		}
	}
	// change
	else if (evt.type == 'change'){		
		if (action == 'link') window[idArray[1]](idArray);	
	}	
	// after leaving the element
	else if (evt.type == 'blur'){		
		if (action == 'link') window[idArray[1]](idArray);
	}
	//else if (evt.type == 'keypress' && evt.keyCode == '13'){
	return true; // so a href won't be called
}
function menu(parentObj)
{
	var menu = createContainer(parentObj,'topmenu');
	var list = createList(menu,'menulist');
	createMenuButton(list,'show_intro','menu','intro');	
	createMenuButton(list,'show_docs','menu','docs');
	createMenuButton(list,'show_materials','menu','materials');
	createMenuButton(list,'show_partners','menu','partners');
	createMenuButton(list,'show_downloads','menu','downlaods');
	
	// logon / registration
	var usrmenu = createContainer(parentObj,'usrmenu');
	var logon = createContainer(usrmenu,'logonContainer',name);
	//createText(logon,'user','','logonLabel');
	createInput(logon,'user','text','logonUser','input',true);
	createBreak(logon);
	//createText(logon,'password','','logonLabel');
	createInput(logon,'password','password','logonPassword','input',true);
	createText(logon,'log in','link_logonValidate','link');
	createText(logon,'register','show_reg','link');
	createInput(logon,'','checkbox','withCookie');
	createText(logon,' remember me');
	createText(logon,'forgot password?','link_password','link');
	createText(logon,'resend validation code','link_validation','link');		
	
	// logout
	var logout = createContainer(usrmenu,'logoutContainer',name,true);
	createContainer(logout,'hello');
	createText(logout,'Properties','show_prop','link');
	//createText(logout,'Logout','link_logout','link');
	createLink(logout,'logout','Logout','sendEvt','logout');
}
function showHistory(newLocation,historyData) 
{
	if (newLocation) show(newLocation.substr(5));
	else show();                     
}
function show(container)
{
	if (!container) container = 'intro';
	else if (container == 'upload' && !user) return;
	else dhtmlHistory.add('show:'+container);
	
	var parentObj = getObject('frame');
	removeChildren(parentObj);
	
	var buttons = getObject('menulist').childNodes;
	for (var i=0; i<buttons.length; i++) {
		buttons[i].className = 'menu';
	};
	getObject('show_'+container).parentNode.className = 'menu_over';
	current = container; // remember the container
	
	var left = createContainer(parentObj,'left');
	var middle = createContainer(parentObj,'content');
	var right = createContainer(parentObj,'right');
	
	if (container == 'intro'){		
		showText(left,'intro');
		showNews(middle);	
		showFrame('right','ad');
	}
	else if (container == 'upload'){		
		showUserList(left);
		showUpload(middle);		
	}
	else if (container == 'materials'){		
		showUserList(left);
		showCategoryList(middle);
		showLatest(right);		
	}
	else if (container == 'docs'){		
		showText(left,'docsAnchor');
		showFrame('content','docs');		
	}
	else if (container == 'downloads'){		
		showText(left,'downloadsAnchor');
		showFrame('content','downloads');	
	}
	else if (container == 'partners'){		
		showText(left,'partnersAnchor');
		showFrame('content','partners');		
	}
	else if (container == 'prop'){	
		propLoad();
	}
	else window['show'+firstBig(container)](middle);
}
function showUser(param) // bsp. link_showUser_Benutzername
{
	parentObj = getObject('content'); // middle
	removeChildren(parentObj);	
	var cont = createContainer(parentObj,'bgUserView','leftborder');	
	createText(cont,param[2],'','container_txt');
	createContainer(cont,'userDetail');
	getData('userView_userDetail','user',Array('country','city','branch','joinDate'),Array('name'),Array(param[2]),true,false,false,true);
	getData('fillGallery_bgUserView*100*5','materials',Array('user','category','id'),Array('user'),Array(param[2]),'true',Array('date'),'DESC');
}
function userView(param,detail)
{
	var parentObj = getObject(detail);
	var dbTitle = param[3].split('*');
	var userDetail = param[4].split('*');
	
	for (var i=0; i<dbTitle.length; i++){	
		
		if (!userDetail[i]) continue;
		createText(parentObj,dbTitle[i],dbTitle[i],'label');
		createText(parentObj,userDetail[i],'','user_detail');
		createBreak(parentObj);
	}	
}
function showMaterial(param,detail) // bsp. link_showMaterial_test_cat2_58
{
	if (detail == 'refresh') param = materialView;
	parentObj = getObject('content'); // middle
	removeChildren(parentObj);	
	var cont = createContainer(parentObj,'bgMaterial','leftborder');
	var path = createContainer(cont,'path','container_txt');
	showPath(path,param[3],param[4]);
	createContainer(cont,'materialFrame');
	
	// material
	var data = new Object();
	data.user = param[2];
	data.category = param[3];
	data.id = param[4];
	sendJson('material',data);
	
	// change right
	showCategory(Array('','','right',param[3]));
	
	// change left	
	parentObj = getObject('left');
	removeChildren(parentObj);
	createContainer(parentObj,'bgRelated','leftborder');
	
	// for refresh
	materialView = param;
}
function uploadSingleMaterialAnswer()
{
	for (var i=0; i<tools.length; i++){	
	var id = 'display_'+tools[i]+'Cont';
		if (!cValue(id)) continue;
		obj(id).disabled = true;
		$('#'+tools[i]+'Cont').hide();
	}
	alert('Thank you for uploading the additional file!');
}
function uploadMaterialAnswer()
{	
	alert('Thank you for uploading! The file(s) will be reviewed shortly.');
	show('materials');
}
function createMaterialText(parentObj,field,text)
{
	if (!text) return;
	createText(parentObj,field,'','label');
	if (field == 'user') createText(parentObj,text,'link_showUser_'+text,'userlink');
	else if (field == 'category') createText(parentObj,categoryLabels[text],'','material_detail');
	else createText(parentObj,text,'','material_detail');
	createBreak(parentObj);
}
function material(answer)
{
	var fields = Array('user','date','name','category','size','titeable','description','render','system','keywords');
	var parentObj = getObject('materialFrame');
	var material = answer.material;
	var address = uploadpath + '/' + material.user + '/' + material.category + '/' + material.id;
	var addressDown = uploadpath + '/' + material.user + '/' + material.category + '/' + material.name.replace(/ /g,'_') + material.id;	
	
	// path material
	getObject('pathMaterial').innerHTML = material.name;	
	
	// material text	
	var cont = createContainer(parentObj,'materialView');
	for (var i=0; i<fields.length; i++) createMaterialText(cont,fields[i],material[fields[i]]); 
	
	// logged in or enough downloads available?
	if (answer.logged == 'false') createText(cont,'','materialDownload2');
	else if (answer.download == 'false') createText(cont,'','materialDownload3');
	else{
		createText(cont,'','materialDownload');
		var form = createFormular(cont,'uploadMaterial','uploadForm');
		createInput(form,material.id,'hidden','id');
		createInput(form,material.user,'hidden','user');
		createInput(form,material.category,'hidden','category');
		
		// new tool array
		var tools2 = new Array();
		tools2 = tools2.concat(tools);
		tools2.push('texture');	
		
		for (var i=0; i<tools2.length; i++) {	
			var id = tools2[i];	
			
			 // to download			
			if (material[tools2[i]]){		
				if (id == 'texture') var addressDown2 = addressDown+'.zip';
				else var addressDown2 = addressDown+'.'+id;
				createTextNew(form,'','download_link',id,Array('materialLink','infoTip','infoTipDelete'),Array('click','mouseover','mouseout'),object('materialLink',Array(addressDown2,material.id),'infoTip',material[id+'_descr']));
				var checkbox = createInput(form,'true','checkbox','','',true);
				checkbox.disabled = true;
			} 
			
			// to upload
			else { 
				createText(form,id,'','download_link');	
				createInput(form,'','checkbox','display_'+id+'Cont','',true);					
				var cont2 = createContainer(form,id+'Cont','',true);
				createBreak(cont2);	
				createUploadField(cont2,'',id+'Up','upload',true);
				createTextarea(cont2,'description',id+'_descr','upload',true);
				createLink(cont2,'','upload','submit',form);
			}
			createBreak(form);
		};
	} 
	
	// right
	var cont = createContainer(parentObj,'materialRight');	
	createPopupImage(cont,'','thumbnail_2',address+'_middle.jpg',address+'_big.jpg'); // preview 1	
	createBreak(cont);
	// rating
	if (answer.rating == 'true'){		
		var voting = createContainer(cont,'ratingVote');
		createChoiceBox(voting,'rating',Array('1','2','3','4','5','6','7','8','9','10'),'link_ratingSave_'+material.id,'',true);
	}
	createImage(cont,'ratingStars','','images/stars'+material.stars+'.png');
	if (answer.preview2 == 'true') createPopupImage(cont,'','thumbnail_3',address+'b_small.jpg',address+'b_big.jpg'); // preview 2
	
	// related
	showRelated(parentObj,answer);
}
function materialLink(element,data)
{
	document.location.href = data[0];
	sendJson('materialDownload',object('id',data[1]));
}
function materialDownload(answer)
{
	if (!answer.success) return;
	var field = obj('downloadInfo');
	field.innerHTML = field.innerHTML - 1;
}
function showRelated(parentObj,answer)
{
	var container = getObject('bgRelated');
	createText(container,'related','toplist','container_txt');
	//createChoiceBox(container,'',Array(Array('date','word1?'),Array('rating','word2?')),'link_changeGallery');
	//createBreak(container);
	if (answer.related){
		var related = createContainer(container,'related');
		gallery(related,answer.related,answer.related_length);
	}
}
function ratingSave(idArray)
{
	var element = getObject(idArray.join('_'));
	var rating = getSelected(element);
	sendJson('rating',object('rating',rating,'id',idArray[2]));
}
function rating(answer)
{
	if (!answer.success) return;
	//alert('successful');
	$('#ratingVote').remove();
	getObject('ratingStars').src = 'images/stars'+answer.stars+'.png';
}
function validation()
{
	var mail = prompt('E-Mail');
	if (!check(mail,'mail')) write('no regular e-mail');
	else sendJson('validationSend',object('mail',mail));
}
function password()
{
	var mail = prompt('E-Mail');
	if (!check(mail,'mail')) write('no regular e-mail');
	else sendJson('passwordSend',object('mail',mail));
}
function searchSend(param)
{
	var data = new Object();
	data.search = getValue('search');
	sendJson('searcher',data);
}
function searcher(answer)
{
	parentObj = getObject('content');
	removeChildren(parentObj);
		
	var cont = createContainer(parentObj,'bgSearchlist','leftborder');
	gallery(cont,answer.search,answer.search_length);
}
function showUpload(parentObj)
{
	var container = createContainer(parentObj,'bgUpload','leftborder');
	var form = createFormular(container,'uploadMaterial','uploadForm');
	createTextfield(form,'Name','name','upload',true);
	getData('fillChoiceBox_category','categories',Array('category','title'),Array(),Array(),'true',Array('title'),'');
	createChoiceBox(form,'Kategorie',Array(''),'category','upload',true); createText(form,'help','category_help','help'); createBreak(form);
	createTextfield(form,'Größe','size','upload',true);
	createText(form,'tileable','tileable','upload_txt');
	createText(form,'x','x_txt','upload'); createInput(form,'','checkbox','x','upload'); 
	createText(form,'y','y_txt','upload'); createInput(form,'','checkbox','y','upload'); 
	createText(form,'help','tile_help','help'); createBreak(form);
	createTextarea(form,'Beschreibung','description','upload',true);
	createTextfield(form,'Renderzeit','render','upload',true);
	createTextfield(form,'System','system','upload',true);
	createTextarea(form,'Keywords','keywords','upload',true);
	//createRadio(form,'Included',new Array('lxp','mxm','Vismat'),'included','upload',true);
	createUploadField(form,'preview','pre_up','upload',true);
	createUploadField(form,'preview2','pre_up2','upload',true);
	//createImageUpload(form,'Screenshot 2','up_shot2','upload',true);
	//createImageUpload(form,'Screenshot 3','up_shot3','upload',true);
	for (var i=0; i<tools.length; i++) {	
		var id = tools[i];
		createText(form,id,id+'_txt');
		createInput(form,'','checkbox','display_'+id+'cont','',true);
		createBreak(form);
		var lxp_cont = createContainer(form,id+'cont','',true);
		createUploadField(lxp_cont,'',id+'Up','upload',true);
		createTextarea(lxp_cont,'description',id+'_descr','upload',true);
	};
	createRadio(form,'',Array('notexture','procedural','texture'),'radioDisplay_textureUp_texture','upload',false,true);
	var field = createUploadField(form,'','textureUp','upload');
	field.style.display = 'none';
	createBreak(form);
	createInputNew(form,'materialUpbutton','','upload','button','uploadMaterial','click');
}
function uploadMaterial(idArray)
{
	var withMaterial = false;
	for (var i=0; i<tools.length; i++) if (value(tools[i]+'Up')) withMaterial = true;
	if (!withMaterial) alert('material is missing');
	else if (!value('name')) alert('name is missing');	
	else if (sValue('category') == '') alert('category is missing');
	else if (!value('description')) alert('description is missing');
	else if (!value('keywords')) alert('keywords are missing');
	else if (!value('pre_up')) alert('preview one is missing');
	else if (getObject('texture').checked && !getObject('textureUp').value) alert('texture is missing');
	else getObject('uploadMaterial').submit();
}
function showText(parentObj,type)
{
	var cont = createContainer(parentObj,'bg'+firstBig(type),'leftborder');
	createText(cont,type,type,'','longtext');
}
function showFrame(id,type)
{
	parentObj = getObject(id);
	removeChildren(parentObj);
	createIFrame(parentObj,'frames/'+type+'.html',type,'html');
}
function showNews(parentObj)
{
	var cont = createContainer(parentObj,'bgNews','leftborder');	
	var box = createContainer(cont,'gallerybox','box');
	sendJson('latest',object('limit',5),box);
	for (var i=0; i<3; i++) {
		var box = createContainer(cont,'newsbox'+i,'box');
		createText(box,'newsbox'+i,'newsbox'+i+'txt','box','longtext');
	};
}
function latest(answer,parentObj)
{
	gallery(parentObj,answer.latest,answer.latest_length)
}
function showLatest(parentObj)
{	
	var container = createContainer(parentObj,'bgLatest','leftborder');
	createText(container,'Topliste','toplist','container_txt');
	createChoiceBox(container,'',Array(Array('date','date'),Array('rating','rating')),'link_changeGallery');
	createBreak(container);
	var box = createContainer(container,'topGallery');
	sendJson('latest',object('limit',20),box);
}
function changeGallery()
{
	var select = getObject('link_changeGallery');
	var sort = select.options[select.selectedIndex].value;
	removeChildren(getObject('topGallery'));
	sendJson('latest',object('limit',20,'sort',sort),getObject('topGallery'));
}
function showUserList(parentObj)
{
	var container = createContainer(parentObj,'bgUsers','leftborder');
	createText(container,'userlist','userlist_txt','container_txt');	
	var fields = Array(Array('name_ASC','name - A..Z'),Array('name_DESC','name - Z..A'),Array('joinDate_ASC','date of join - first'),Array('joinDate_DESC','date of join - latest',Array('rating','ratings')));
	createChoiceBox(container,'',fields,'link_userListChange');
	createBreak(container);
	createList(container,'userlist');
	sendJson('userList',object('materialCount','true')); // with count of materials
}
function userList(answer)
{	
	var user = answer.user;
	var list = getObject('userlist');
	var cont = obj('bgUsers');
	
	// index
	$('#userIndex').remove();	
	//for (var i=0; i<answer.userCount; i+=userAmount) createLink(index,'','['+(i/userAmount)+']','sendEvt',Array('userListSwop',object('start',i)));
	var values = new Array();
	for (var i=0; i<answer.userCount; i+=userAmount) values.push(i);
	createSelectbox(cont,'userIndex',values,0,'userListSwopSend','change')
	
	// list
	for (var i=0; i<userAmount; i++) if (user[i]) createListElement(list,user[i]['name'],'link_showUser_'+user[i]['name'],'link');
	
	// footer info
	$('#userCount').html('usercount: '+answer.userCount);
	if (answer.materialCount) $('#materialCount').html('materialcount: '+answer.materialCount);
}
function userListSwopSend()
{
	sendJson('userListSwop',object('start',sValue('userIndex')));
}
function userListSwop(answer,index)
{
	if (!index) index = 0;
	var user = answer.user;
	var list = getObject('userlist');
	removeChildren(list);
	for (var i=index; i<index+userAmount; i++) if (user[i]) createListElement(list,user[i]['name'],'link_showUser_'+user[i]['name'],'link');
}
function userListChange() // sort and stuff
{
	var select = getObject('link_userListChange');
	var sort = select.options[select.selectedIndex].value;
	removeChildren(getObject('userlist'));
	sendJson('userList',object('sort',sort));
}
function showCategoryList(parentObj)
{
	sendJson('categoryList');
	category(parentObj);
}
function showCategory(param) // param[2] = container; param[3] = category
{	
	var parentObj = getObject(param[2]);
	removeChildren(parentObj);
	var data = new Object();
	data.category = param[3];
	sendJson('categoryList',data);
	category(parentObj,param[3]);
}
function category(parentObj,category) // for single category and category list
{
	var cont = createContainer(parentObj,'bgCategory','leftborder');
	var path = createContainer(cont,'path','container_txt');
	if (category) showPath(path,category); // single category
	else showPath(path); // category list
	
	// filter
	createText(cont,'show only ','filter_txt');
	createContainer(cont,'filter');
	for (var i=0; i<tools.length; i++) {
		if (category) var id = 'link_categoryListFilter_'+tools[i]+'_'+category;
		else var id = 'link_categoryListFilter_'+tools[i];
		createInput(cont,'true','checkbox',id);
		createText(cont,tools[i],'cat_'+tools[i]+'_txt','checkbox_txt');
	};
	createList(cont,'catlist','container');
}
function categoryListFilter(param)
{
	removeChildren(getObject('catlist'));
	var category = param[3];
	var data = new Object();
	var checked = false;	
	for (var i=0; i<tools.length; i++){
		if (category) var id = 'link_categoryListFilter_'+tools[i]+'_'+category;
		else var id = 'link_categoryListFilter_'+tools[i];
		if (getObject(id).checked){
			data[tools[i]] = 'x';
			checked = true;
		} 
	} 
	if (!checked){ write('at least one type has to be checked'); return;} 
	data.filter = 'true';
	
	// get category list
	if (category) data.category = category;
	sendJson('categoryList',data);
}
function showPath(parentObj,category,material)
{
	if (!category) createText(parentObj,'home','','pathEnd');
	else {
		createText(parentObj,'home','show_materials','link');
		createText(parentObj,'/','','slash');
		
		if (!material) createText(parentObj,categoryLabels[category],'','pathEnd');
		else {
			createText(parentObj,categoryLabels[category],'link_showCategory_content_'+category,'link');	// categoryLabels: to be changed
			createText(parentObj,'/','','slash');
			createText(parentObj,material,'pathMaterial','pathEnd');
		}
	}
}
function categoryList(answer)
{
	var cont = getObject('catlist');
	
	// category list
	$.each(answer.categoryList,function(catId,category){
			
		var catElement = createListElement(cont,'',catId);		
		if (!answer.category) var catLabel = createText(catElement,category.title,'link_showCategory_content_'+catId,'link');
		if (answer.category) var counter = categoryGallery(catElement,catId,category);
		else  var counter = categoryGallery(catElement,catId,category,4);	
		if (!answer.category) catLabel.innerHTML += ' ('+counter+')';
	});	
}
function categoryGallery(catElement,catId,category,maxNumber)
{
	var counter = 0;
	$.each(category,function(matId,material){
		
		if (!isArray(material)) return; // not the normal attributes of category
		counter++;		
		if (!maxNumber|| counter < maxNumber || answer.category){ // normal list just 3 but single category all
			var address = uploadpath + '/' + material.user + '/' + catId + '/' + matId + '_small.jpg';
			var imageId = 'link_showMaterial_' + material.user + '_' + catId + '_' + matId;
			createImage(catElement,imageId,'thumbnail_1',address,material.name);	
		}
	});
	return counter;
}
function fillGallery(param,detail)
{
	var detailArray = detail.split('*');
	var gallery = getObject(detailArray[0]);
	var maxNumber = detailArray[1];
	var rowNumber = detailArray[2];
	//var images = gallery.childNodes;
	
	for (var i=0; i<param[2]; i++){	
		
		if (i == maxNumber) break;
			
		var address = param[3+i].split('*');
		// materials\test\cat2\test_shot1.jpg - user-category-name
		var src = uploadpath + '/' + address[0] + '/' + address[1] + '/' + address[2] + '_small.jpg';
		var id = 'link_showMaterial_' + address[0] + '_' + address[1] + '_' + address[2];
		var alt = address[2];	
		createImage(gallery,id,'thumbnail_1',src,alt);
		
		var full = (i+1)/rowNumber;
		var integer = Math.floor(full);
		if (full == integer && i != maxNumber) createBreak(gallery);
	} 
}
function gallery(parentObj,objAll,length)
{	
	for (var i=0; i<length; i++){	
		
		var obj = objAll[i];
		var cont = createContainer(parentObj,'','latestBox');
		var src = uploadpath + '/' + obj.user + '/' + obj.category + '/' + obj.id + '_small.jpg';
		var id = 'link_showMaterial_' + obj.user + '_' + obj.category + '_' + obj.id;
		createImage(cont,id,'thumbnail_1',src,obj.name); createBreak(cont);
		if (obj.date) createText(cont,obj.date,'','latestDate');
	} 
}
function fillChoiceBox(param,detail)
{
	var element = getObject(detail);
	for (var i=0; i<param[2]; i++) createChoiceBoxElement(element,param[3+i].split('*'));
}
function afterImageUpload(address,id)
{
	var image = document.getElementById(id);
	image.src = address;
	image.style.display = 'inline';
	//image.parentNode.removeChild(image.previousSibling);	
}
function logonValidate(idArray)
{
	if (!checkInput('logonUser','text')) return;
	if (!checkInput('logonPassword','password')) return;
	var user = getValue('logonUser');
	var password = getValue('logonPassword');
	sendJson('logon',object('user',user,'password',password));
}
function logon(answer)
{
	if (cValue('withCookie')) setCookie(Array('user','pass'),Array(value('logonUser'),encrypePassword(value('logonPassword')))); 
	
	user = answer.user;
	write('Hello '+user+'. Welcome back.');
	var cont = getObject('hello');
	createText(cont,'Logged in as '+user); createBreak(cont);
	
	var download = answer.uploads*5+5-answer.downloads;
	if (download > 0){
		createText(cont,'downloads left: ','downloadInfo1','downloadInfo');
		createText(cont,download,'downloadInfo','downloadInfo'); createBreak(cont);
		createText(cont,'see docs for details','downloadInfo2','downloadInfo');
	} 
	else createText(cont,'please upload first','downloadInfo','downloadInfo');	
	getObject('logonContainer').style.display = 'none';
	getObject('logoutContainer').style.display = 'inline';	

	var menu = getObject('menulist');
	createMenuButton(menu,'show_upload','menu','upload');
}
function logout(answer)
{
	deleteCookie();
	user = false;
	getObject('logoutContainer').style.display = 'none';
	getObject('logonContainer').style.display = 'inline';
	getObject('hello').innerHTML = '';
	
	var button = getObject('show_upload').parentNode;
	button.parentNode.removeChild(button);
	
	write('You logged out successfully.');
	window.location = url;
}
function propLoad()
{
	getData('showProp','user',Array('name','mail','country','city','branch','birthDate'),Array('name'),Array(user));
}
function showProp(param)
{
	var parentObj = getObject('content');
	var cont = createContainer(parentObj,'prop');
	createBreak(cont);	
	var user = createLabeledInput(cont,'Username*','propUser','input','text',param[3]);
	user.disabled = 'true';
	createLabeledInput(cont,'New passwort*','propPassword1','input','password');
	createLabeledInput(cont,'New passwort*','propPassword2','input','password');
	createLabeledInput(cont,'E-Mail*','propMail1','input','mail',param[4]);
	createLabeledInput(cont,'E-Mail*','propMail2','input','mail',param[4]);
	createLabeledInput(cont,'Country','propCountry','input','text',param[5]);
	createLabeledInput(cont,'City','propCity','input','text',param[6]);
	createLabeledInput(cont,'Branch','propBranch','input','text',param[7]);
	createLabeledInput(cont,'Date of Birth','propBirth','input','text',param[8]);
	createBreak(cont);
	createText(cont,'change properties','link_propSend','link');
	createDoubleBreak(cont);
	createText(cont,'','propError','small');
}
function propSend()
{
	if (!checkInput('propUser')) return;
	if (!checkInput('propPassword1','password',true)) return;
	if (!checkInput('propPassword2','password',true)) return;
	if (!checkInput('propMail1','mail')) return;
	if (!checkInput('propMail2','mail')) return;
	if (!checkInput('propCountry','text',true)) return;
	if (!checkInput('propBranch','text',true)) return;
	if (!checkInput('propBirth','text',true)) return;
	
	if (getValue('propPassword1') != getValue('propPassword2')){
		write('passwords are different');
		return;
	}
	if (getValue('propMail1') != getValue('propMail2')){
		write('e-mails are different');
		return;
	}
	
	var userFields = Array('name','mail','country','branch','birthDate');
	var values = Array(getValue('propUser'),getValue('propMail1'),getValue('propCountry'),getValue('propBranch'),getValue('propBirth'))
	
	var password = getValue('propPassword1');
	if (password){
		userFields.push('password');
		values.push(password);
	} 
	
	submitForm('','prop');
	//changeData('propAnswer','user',userFields,values,Array('name'),Array(user));
}
function prop(answer)
{
	if (!answer.success){ write('error while changing the properties'); return; } 
	removeChildren(getObject('prop'));	
	write('properties changed successfully');
}
function showReg(parentObj)
{
	var bgcont = createContainer(parentObj,'bgRegistration','leftborder'); createBreak(parentObj);	
	var cont = createContainer(bgcont,'reg','leftborder');
	createLabeledInput(cont,'Username*','regUser','input');
	createLabeledInput(cont,'Passwort*','regPassword1','input','password');
	createLabeledInput(cont,'Passwort*','regPassword2','input','password');
	createLabeledInput(cont,'E-Mail*','regMail1','input','mail');
	createLabeledInput(cont,'E-Mail*','regMail2','input','mail');
	createLabeledInput(cont,'Country','regCountry','input');
	createLabeledInput(cont,'City','regCity','input');
	createLabeledInput(cont,'Branch','regBranch','input');
	createLabeledInput(cont,'Date of Birth','regBirth','input'); createBreak(cont);
	createInput(cont,'','checkbox','regTerms','link');
	createText(cont,' agree conditions','link_terms','link'); createBreak(cont); createBreak(cont);
	createInput(cont,'Register','button','link_regSend'); createBreak(cont);
	createText(cont,'*these fields have to be filled out');	createDoubleBreak(cont);
	createText(cont,'','regError','small');
}
function terms()
{
	showFrame('right','terms');
}
function regSend()
{	
	if (!checkInput('regUser')) return;
	if (!checkInput('regPassword1','password')) return;
	if (!checkInput('regPassword2','password')) return;
	if (!checkInput('regMail1','mail')) return;
	if (!checkInput('regMail2','mail')) return;
	if (!checkInput('regCountry','text',true)) return;
	if (!checkInput('regBranch','text',true)) return;
	if (!checkInput('regBirth','text',true)) return;
	if (!cValue('regTerms')){ $('#regError').html('please agree the conditions'); return;}
	
	if (getValue('regPassword1') != getValue('regPassword2')){
		write('passwords are different');
		return;
	}
	if (getValue('regMail1') != getValue('regMail2')){
		write('e-mails are different');
		return;
	}
	
	submitForm('','reg');
}
function reg(answer) // reg complete
{
	if (answer.info) getObject('regError').innerHTML = answer.info;
	else{		
		var cont = getObject('bgRegistration');		
		var text = 'To verify the registration check your mails under the following address ' + getValue('regMail1') + '.';
		removeChildren(cont);
		createText(cont,text);
	}
}
