var company = {

	create: function (intCompanyId)	{
		intCompanyId = typeof intCompanyId != 'undefined' ? intCompanyId : false;
		jQuery.post(doc_root + "includes/ajax/company.create.php", {
			intCompanyId : intCompanyId
		}, function (data, status) {
//				intCompanyId = objData.responseText;
				core.menu.get();
				company.get(data, 'edit');
		});

	}, // end create
	
	Delete: function (intCompanyId)	{
		if(intCompanyId)	{
			var strPostData = "intCompanyId=" + intCompanyId;
			var strUrl = core.config('root') + "includes/ajax/company.delete.php";
			
			if(confirm(gt.gettext("Wollen Sie wirklich?")))	{
				var request = YAHOO.util.Connect.asyncRequest('POST', strUrl, {
					success: function(objData)	{
						core.menu.get();
					}
				}, strPostData);
			}
		}
	
	}, // end delete
	
	get: function (intCompanyId, strPageMode, tabViewActiveIndex)	{

		tabViewActiveIndex = (typeof tabViewActiveIndex == "undefined") ? 0 : tabViewActiveIndex;
	
		if (typeof intCompanyId != undefined)	{
			core.config('strType','company');
			core.config('intCompanyId',intCompanyId);
			
			jQuery.post(doc_root + "includes/ajax/company.get.php", {
				intCompanyId: intCompanyId,
				strPageMode: strPageMode			
			}, function(data, status) {
				jQuery('#view').html(data);
				
//				var dtmCurrent = new Date();
//				var objData = { month: { numb:dtmCurrent.getMonth() }, year: dtmCurrent.getFullYear() };
//				
//					calendar.get( objData, 'Register' );
				jQuery("#dtmRegister").datepicker({
					defaultDate: new Date(),
					altField: '#Register',
					altFormat: 'yy-mm-dd',
					changeMonth: true,
					changeYear: true
				});
				
				util.initTabs();
			});
		}
	}, // end get
	update:	{
	
		image: function(){
			jQuery('#formImage').ajaxSubmit({
				url: doc_root  + 'includes/ajax/user.update.image.php',
				clearFrom: true,
				resetForm: true,
				success: function(data, status) {
					jQuery('#project-picture').html('<img id="projectRoomImage" class="userPic" width="140" alt="Projektbild" ' +
							'src="' + doc_root + 'includes/ajax/getfile.php?filename='+ data + '"/>');
					jQuery('#profileImage').attr('src', doc_root + 'includes/ajax/getfile.php?filename=' + data);
				}
			});			
		} // end image
	
	}, // end update
	element:	{
	
		edit: function(strId){

			var divViewName = 'div' + strId + 'View';
			var divEditName = 'div' + strId + 'Edit';
			
			document.getElementById(divViewName).style.display = 'none';
			document.getElementById(divEditName).style.display = 'block';
		
		}, // end edit
		
		reset: function (strId, objDefaultList){

			for(var strKey in objDefaultList)	{
				document.getElementsByName(strKey)[0].value = objDefaultList[strKey];
			}
			
			var divViewName = 'div' + strId + 'View';
			var divEditName = 'div' + strId + 'Edit';
			
			document.getElementById(divViewName).style.display = 'block';
			document.getElementById(divEditName).style.display = 'none';
			
		}, // end reset
		
		save: function(strId, intCompanyId, objData)	{
					
			var objData = objData != undefined ? objData : false; 
		
			var strUrl = '';
			var strView = '';
			
			var divViewName = 'div' + strId + 'View';
			var divEditName = 'div' + strId + 'Edit';
			
			var strPTag = document.getElementById(divViewName).getElementsByTagName('p')[0];
			
			var arrInputValues = document.getElementById('form' + strId).getElementsByTagName('input');
			var arrSelectValues = document.getElementById('form' + strId).getElementsByTagName('select');	
			
			
			if(objData !== false)	{
				strUrl += objData.strKey + '=' + objData.strValue + '&';
				strView += objData.strValue + '&nbsp;';
			}
			
			for(var intCount = 0; intCount < arrInputValues.length; intCount++)	{
				strUrl += arrInputValues[intCount].name + '=' + arrInputValues[intCount].value + '&';
				if(arrInputValues[intCount].name == "strMail")	{
					strView += '<a href="mailto:' + arrInputValues[intCount].value + '">' + arrInputValues[intCount].value + '</a>&nbsp;';
				}
				else if(arrInputValues[intCount].name == "strUrl")	{
					strView += '<a href="' + arrInputValues[intCount].value + '">' + arrInputValues[intCount].value + '</a>&nbsp;';
				}
				else	{
					strView += arrInputValues[intCount].value + '&nbsp;';
				}
			}
			
			
			for(var intCount = 0; intCount < arrSelectValues.length; intCount++)	{
				var strValue = arrSelectValues[0].value;
				strUrl += arrSelectValues[intCount].name + '=' + strValue + '&';
				strView += strValue + '&nbsp;';
			}
			
			strUrl += "intCompanyId=" + intCompanyId;
			strView += '<a href=\"javascript:;\" onclick=\"editCompanyElement(\'' + strId + '\');\">' + gt.gettext("Bearbeiten") + '</a>';
//			alert(strUrl);
			YAHOO.util.Connect.asyncRequest('POST', core.config('root') + "includes/ajax/company.update.php", {
				success: function(objData)	{
					core.menu.get();
				}
			}, strUrl);
			
			strPTag.innerHTML = strView;
			
			document.getElementById(divViewName).style.display = 'block';
			document.getElementById(divEditName).style.display = 'none';
			
			company.get(intCompanyId);
			core.menu.get();
			
		} // end save
	
	}, // end element
	application: {
	
		Delete:	function (intId){
			
			var objDroppable = document.getElementById(intId);
			objDroppable.style.display = 'none';
			
			var objDroppable = objDroppable.parentNode.parentNode;
			objDroppable.style.display = 'none';
			for(var intCount = 0; intCount < objDroppable.getElementsByTagName('li').length; intCount++)	{
				if(objDroppable.getElementsByTagName('li')[intCount].style.display == 'block')	{
					objDroppable.style.display = 'block';
				}
			}
			
			var objDroppable = objDroppable.parentNode.parentNode;
			objDroppable.style.display = 'none';
			for(var intCount = 0; intCount < objDroppable.getElementsByTagName('li').length; intCount++)	{
				if(objDroppable.getElementsByTagName('li')[intCount].style.display == 'block')	{
					objDroppable.style.display = 'block';
				}
			}
			
			var objDroppable = objDroppable.parentNode.parentNode;
			objDroppable.style.display = 'none';
			for(var intCount = 0; intCount < objDroppable.getElementsByTagName('li').length; intCount++)	{
				if(objDroppable.getElementsByTagName('li')[intCount].style.display == 'block')	{
					objDroppable.style.display = 'block';
				}
			}
			
			var arrIdList = intId.split("_");
			
			var strUrl = core.config('root') + 'includes/ajax/box.application.delete.php?intId=' + arrIdList[1];
			if(core.config('strType') == 'user')	{
				strUrl += '&intUserId=' + core.config('intUserId');
			}
			else if(core.config('strType') == 'company')	{
				strUrl += '&intCompanyId=' + core.config('intCompanyId');
			}
			
			YAHOO.util.Connect.asyncRequest('GET', strUrl, {
				success: function(objData)	{
					if(core.config('strType') == 'user')	{
						user.get(core.config('intUserId'), 'edit', 1);
					}
					else if(core.config('strType') == 'company')	{
						company.get(core.config('intCompanyId'), 'edit', 1);
					}
				}
			});
			
		}, // end delete
		checkbox: function(strPrefix, intCurrentCount)	{
	
			var arrPrefix = strPrefix.split('_');
			
			if(core.config('strType') == 'user')	{
				var strUrl = core.config('root') + 'includes/ajax/user.box.application.rating.php?';
				strUrl += 'intApplicationId=' + arrPrefix[1] + '&intRating=' + intCurrentCount + '';
				strUrl += '&intUserId=' + core.config('intUserId');
			}
			else if(core.config('strType') == 'company')	{
				var strUrl = core.config('root') + 'includes/ajax/company.box.application.rating.php?';
				strUrl += 'intApplicationId=' + arrPrefix[1] + '&intRating=' + intCurrentCount + '';
				strUrl += '&intCompanyId=' + core.config('intCompanyId');
			}
			
			intCurrentCount++;
		
			for(var intCount = 1; intCount < 6; intCount++)	{
				document.getElementById(strPrefix + intCount).src = '/tmg/misc/icons/checkbox.jpg';
			}
		
			for(var intCount = 1; intCount < intCurrentCount; intCount++)	{
				document.getElementById(strPrefix + intCount).src = '/tmg/misc/icons/checkbox_checked.jpg';
			}
			
			var objRequest = YAHOO.util.Connect.asyncRequest('GET', strUrl, {
				success: function(objData)	{
				
				}
			});
		
		} // end checkbox
	
	}, // end technology
	technology: {
	
		Delete:	function (intId){
			
			var objDroppable = document.getElementById(intId);
			objDroppable.style.display = 'none';
			
			var objDroppable = objDroppable.parentNode.parentNode;
			objDroppable.style.display = 'none';
			for(var intCount = 0; intCount < objDroppable.getElementsByTagName('li').length; intCount++)	{
				if(objDroppable.getElementsByTagName('li')[intCount].style.display == 'block')	{
					objDroppable.style.display = 'block';
				}
			}
			
			var objDroppable = objDroppable.parentNode.parentNode;
			objDroppable.style.display = 'none';
			for(var intCount = 0; intCount < objDroppable.getElementsByTagName('li').length; intCount++)	{
				if(objDroppable.getElementsByTagName('li')[intCount].style.display == 'block')	{
					objDroppable.style.display = 'block';
				}
			}
			
			var objDroppable = objDroppable.parentNode.parentNode;
			objDroppable.style.display = 'none';
			for(var intCount = 0; intCount < objDroppable.getElementsByTagName('li').length; intCount++)	{
				if(objDroppable.getElementsByTagName('li')[intCount].style.display == 'block')	{
					objDroppable.style.display = 'block';
				}
			}
			
			var arrIdList = intId.split("_");
			
			var strUrl = core.config('root') + 'includes/ajax/user.box.technology.delete.php?intId=' + arrIdList[1];
			if(core.config('strType') == 'user')	{
				strUrl += '&intUserId=' + core.config('intUserId');
			}
			else if(core.config('strType') == 'company')	{
				strUrl += '&intCompanyId=' + core.config('intCompanyId');
			}
			
			YAHOO.util.Connect.asyncRequest('GET', strUrl, {
				success: function(objData)	{
					if(core.config('strType') == 'user')	{
						user.get(core.config('intUserId'), 'edit', 1);
					}
					else if(core.config('strType') == 'company')	{
						company.get(core.config('intCompanyId'), 'edit', 1);
					}
				}
			});
			
		}, // end delete
		checkbox: function(strPrefix, intCurrentCount)	{
	
			var arrPrefix = strPrefix.split('_');
			
			if(core.config('strType') == 'user')	{
				var strUrl = core.config('root') + 'includes/ajax/user.box.technology.rating.php?';
				strUrl += 'intTechnologyId=' + arrPrefix[1] + '&intRating=' + intCurrentCount + '';
				strUrl += '&intUserId=' + core.config('intUserId');
			}
			else if(core.config('strType') == 'company')	{
				var strUrl = core.config('root') + 'includes/ajax/company.box.technology.rating.php?';
				strUrl += 'intTechnologyId=' + arrPrefix[1] + '&intRating=' + intCurrentCount + '';
				strUrl += '&intCompanyId=' + core.config('intCompanyId');
			}
			
			intCurrentCount++;
		
			for(var intCount = 1; intCount < 6; intCount++)	{
				document.getElementById(strPrefix + intCount).src = '/tmg/misc/icons/checkbox.jpg';
			}
		
			for(var intCount = 1; intCount < intCurrentCount; intCount++)	{
				document.getElementById(strPrefix + intCount).src = '/tmg/misc/icons/checkbox_checked.jpg';
			}
			
			var objRequest = YAHOO.util.Connect.asyncRequest('GET', strUrl, {
				success: function(objData)	{
				
				}
			});
		
		} // end checkbox
	
	}, // end technology
	save:	function(objElementList)	{
					
		var intCompanyId = core.config('intCompanyId');
		var strUrl = '';

		for(var intOuterCount = 0; intOuterCount < objElementList.length; intOuterCount++)	{
		
			var strId = objElementList[intOuterCount];
		
			var divViewName = 'div' + strId + 'View';
			var divEditName = 'div' + strId + 'Edit';
			
			var strPTag = document.getElementById(divViewName).getElementsByTagName('p')[0];
			
			var arrInputValues = document.getElementById('form' + strId).getElementsByTagName('input');
			var arrSelectValues = document.getElementById('form' + strId).getElementsByTagName('select');
			var arrTextareaValues = document.getElementById('form' + strId).getElementsByTagName('textarea');
					
			for(var intCount = 0; intCount < arrInputValues.length; intCount++)	{
				strUrl += arrInputValues[intCount].name + '=' + arrInputValues[intCount].value + '&';
			}
			
			for(var intCount = 0; intCount < arrTextareaValues.length; intCount++)	{
				strUrl += arrTextareaValues[intCount].name + '=' + arrTextareaValues[intCount].value + '&';
			}
			
			for(var intCount = 0; intCount < arrSelectValues.length; intCount++)	{
				var strValue = arrSelectValues[0].value;
				strUrl += arrSelectValues[intCount].name + '=' + strValue + '&';
			}
		
		}
		
		strUrl += "intCompanyId=" + intCompanyId;
		jQuery.post(doc_root + "includes/ajax/company.element.save.php?" + strUrl, {}, function(data, status) {
			core.menu.get();			
			company.get(intCompanyId);
		});

	} // end save

};
