
if (typeof(CM_WEBCOMPONENT_HEADER) == 'undefined') (function() { // #ifndef

CM_WEBCOMPONENT_HEADER = function (strName) {
	this.strName = strName;
	this.arrOnShowEvent = new Array();
	this.arrOnHideEvent = new Array();
	this.arrOnRequireRegisterEvent = new Array();
	this.arrOnConfirmRegistrationEvent = new Array();
	this.oJson = new DHL.FORMAT.JSON();
	this.objSendDataHttpRequest = new DHL.NET.HTTPREQUEST();
	this.blnSending = false;
	this.ptCallbackFunction = "";
	this.blnPrivate = false;
	this.objWCRating = null;
	this.strCurrentSearch = "";
}

var PUBLIC = CM_WEBCOMPONENT_HEADER.prototype;
var PRIVATE = CM_WEBCOMPONENT_HEADER.prototype;
var STATIC = CM_WEBCOMPONENT_HEADER;
var SELF = CM_WEBCOMPONENT_HEADER;

PUBLIC.setRating = function setRating(objRating) {
	this.objWCRating = objRating;
}
PUBLIC.setAllowPrivate = function setAllowPrivate(blnPrivate) {
	this.blnPrivate = blnPrivate;
}

PUBLIC.addOnShowSearch = function addOnShowSearch(ptFunction) {
	this.arrOnShowEvent.push(ptFunction);
}
PUBLIC.addOnHideSearch = function addOnHideSearch(ptFunction) {
	this.arrOnHideEvent.push(ptFunction);
}
PUBLIC.addOnRequireRegister = function addOnRequireRegister(ptFunction) {
	this.arrOnRequireRegisterEvent.push(ptFunction);
}
PUBLIC.addOnConfirmRegistration = function addOnConfirmRegistration(ptFunction) {
	this.arrOnConfirmRegistrationEvent.push(ptFunction);
}

PUBLIC.onShowSearch = function onShowSearch() {
	for(var intI = 0; intI < this.arrOnShowEvent.length; intI++) {
		this.arrOnShowEvent[intI]();
	}
}
PUBLIC.onHideSearch = function onHideSearch() {
	for(var intI = 0; intI < this.arrOnHideEvent.length; intI++) {
		this.arrOnHideEvent[intI]();
	}
}
PUBLIC.onRequireRegister = function onRequireRegister(strForm, strUrl, strAccess) {
	for(var intI = 0; intI < this.arrOnRequireRegisterEvent.length; intI++) {
		this.arrOnRequireRegisterEvent[intI](strForm, strUrl, strAccess);
	}
}
PUBLIC.onConfirmRegistration = function onConfirmRegistration() {
	for(var intI = 0; intI < this.arrOnConfirmRegistrationEvent.length; intI++) {
		this.arrOnConfirmRegistrationEvent[intI]();
	}
}

PUBLIC.search = function search(objInput, intSearchType) {
	if (objInput.value.length > 1) {
		if(!this.blnSending) {
			this.blnSending = true;
			this.strCurrentSearch = objInput.value;

			var objUrlToSend = new DHL.NET.URL.getCurrent();
			document.getElementById('input_search' + this.strName).disabled = true;

			strAttributes = '';
			if (intSearchType == 1) {
				strValue = objInput.value;
				strAttributes = 'search'+this.strName+'nickName='+strValue;
			}
			
			this.objSendDataHttpRequest.open('POST', objUrlToSend, true);
	
			this.objSendDataHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			this.objSendDataHttpRequest.setRequestHeader('Content-length', strAttributes.length);
			this.objSendDataHttpRequest.setRequestHeader('Connection', 'close');
	
			var me = this;
			this.objSendDataHttpRequest.onreadystatechange(function() {
				me.onReceiveData();
			});
			this.objSendDataHttpRequest.send(strAttributes);
			this.ptCallbackFunction = this.callbackSearch;
			
		}
	}
}

PUBLIC.onReceiveData = function onReceiveData() {
	if(this.objSendDataHttpRequest.getReadyState() == 4) {
		//response has been received
		this.blnSending = false;
		document.getElementById('input_search' + this.strName).disabled = false;
		if(
			this.objSendDataHttpRequest.getStatus() == 200 && 
			this.ptCallbackFunction
		) {
			this.ptCallbackFunction(this.objSendDataHttpRequest.getResponseText());
		}
	}
}

PUBLIC.callbackSearch = function callbackSearch(strResponseText) {
	if(strResponseText == 0) {
		alert('Sorry, no match were found for you search');
	} else if (strResponseText.length < 100) {
		var objUrl = new DHL.NET.URL(strResponseText);
		document.location.href = objUrl.toString();
	} else {
		eval("var objRsModellist = " + strResponseText + ";");
		if (typeof objRsModellist == 'object') {
			
			var objPostUrl = new CM_URL("/search");
			objPostUrl.setSpecialAttribute('nickname', this.strCurrentSearch);
			document.location.href = objPostUrl.toString();
			/*
			var objModelListsearch = new CM_WEBCOMPONENT_MODELLIST(this.strName + "search");
			objModelListsearch.setModelRs(objRsModellist);
			objModelListsearch.setRatingObject(this.objWCRating);
			objModelListsearch.setMaxModel(6);
			objModelListsearch.displayOnlineFlag(true);
			if(this.blnPrivate) {
				objModelListsearch.allowPrivate(true);
			}

			switch(objRsModellist.getRecordCount()) {
				case 7:
					document.getElementById('search-box-link' + this.strName).style.display = 'inline';
				case 6:
				case 5:
					document.getElementById('camsters_searchresult').style.height = "385px";
				break;
				case 4:
				case 3:
					document.getElementById('camsters_searchresult').style.height = "250px";
				break;
				case 2:
				case 1:
					document.getElementById('camsters_searchresult').style.height = "140px";
				break;
			}
			
			document.getElementById('camsters_searchresult').style.display = 'block';
			document.getElementById('divBackground' + this.strName).style.display = "block";
			document.getElementById('divBackground' + this.strName).onclick=function() {
				me.closeSearch();
			}
			
			var strSearchValue = objModelListsearch.render();
			
			strSearchValue = strSearchValue.replace(/%/g,'');
			
			objSearchUrl = new DHL.NET.URL("/search.htm");
			objSearchUrl.setAttribute('search',strSearchValue);
			document.getElementById('search-box-link' + this.strName).href = objSearchUrl.toString();

			this.onShowSearch();
			*/
		}
	}
}

PUBLIC.closeSearch = function closeSearch() {
	document.getElementById('camsters_searchresult').style.display = 'none';
	document.getElementById('divBackground' + this.strName).style.display = "none";
	this.onHideSearch();
}

})();