function NewsLetterHandler() {
	this.ah = "newsletter";
	
	this.view = function() {
		this.set("at", "view");
		return this.request();
	}
}
NewsLetterHandler.prototype = new HiveHandler;

var newsLetterHandler = new NewsLetterHandler();


function ActionInfo() {
	this.activeX = null;
	this.param = [];

	this.put = function(name, value) {
		this.param[name] = value;
		return this;
	}
	
	this.get = function(name) {
		return this.param[name];
	}
	
	this.clear = function() {
		this.param = {};
		this.count = 0;
	}
	
	this.toParams = function() {
		var params = [];
		for(var name in this.param) {
			var value = this.param[name];
			if (isEmpty(value))
				value = "";
			params[params.length] = name + "=" + encodeURIComponent(value);
		}
		return params.length?params.join("&"):null;
	}
	
	this.client = function() {
		if (!this.activeX)
			this.activeX = new ActiveXObject("Hiverion.ActionInfo");
		return this.activeX;
	}
	
	this.clientValue = function(name) {
		return this.client().ClientValue(name);
	}
	
	this.newRequest = function() {
		return this.client().Request();
	}
	
	this.callClient = function() {
		for(var name in this.param) {
			var value = this.param[name];
			if (isEmpty(value))
				value = "";
			this.client().put(name, value);
		}
		this.client().callClient();
	}
}

function request(actionType) {
	if (actionType)
		setActionType(actionType);
	if (theForm().method.match(/GET/i)) {
		var els = theForm().getElementsByTagName("TEXTAREA");
		for(var i = 0; i < els.length; i++)
			els[i].disabled = true;
		els = theForm().getElementsByTagName("INPUT");
		for(var i = 0; i < els.length; i++)
			if (els[i].type == "file")
				els[i].disabled = true;
	}
	try {
		var em = theForm()["tagValue"];
		if( em.value==resourceManager.getString('input-search-word') ) em.disabled = true;
	} catch(e) { }
	theForm().submit();
}

function HiveContext(ctxID,siteIDx) {
	if( !ctxID ) {
		this.ctxID = undefined;
		return this;
	}
	if( ctxID.charAt(0)=='/' ) {
		idx = thisCtx.substr(8).lastIndexOf('/');
		if( idx==-1 )
			this.ctxID = thisCtx+ctxID;
		else
			this.ctxID = thisCtx.substr(0,idx+8)+ctxID;
	} else {
		this.ctxID = ctxID;
	}
	if( siteIDx )
		this.actSite = siteIDx;
	return this;
}

function HiveToURL(wsID) {
	if( isEmpty(this.ctxID) )
		this.ctxID = thisCtx;
	if (isEmpty(wsID) && this.actSite )
		wsID = this.actSite;
	if (isEmpty(wsID))
		wsID = siteID();

	var rUrl = this.ctxID + "/" + wsID + "/" + this.ah;
	this.ctxID = null;
	this.actSite = null;
	return rUrl;
}

function HiveGetParams() {
		var params = this.actionInfo.toParams();
		if (this.full)
			params = this.toURL(this.siteID) + "?" + params;

		if (this.range) {
			for (var name in this.range) {
				var range = this.range[name],
					start = range[0],
					end = range[1];
				params += "&" + name + "Start=" + start + "&" + name + "End=" + end;
			}
		}
		if (this.uri)
			params += "&dest=" + encodeURIComponent(this.uri);
		this.actionInfo.clear();
		this.range = this.actionInfo = null;
		this.full = this.siteID = this.uri = null;
		this.ctxID = this.actSite = null;
		return params;
	}

function HiveSetSourceSite(srcSite) {
	this.set("srcSite", srcSite);
}

accessHandler.context =
memberHandler.context =
sectionHandler.context =
boxHandler.context =
documentHandler.context =
memoHandler.context =
pollHandler.context =
urlHandler.context =
popupHandler.context =
fileHandler.context =
//messageHandler.context =
pageHandler.context =
skinHandler.context =
userHandler.context =
statHandler.context =
newsLetterHandler.context =
websiteHandler.context = HiveContext;

accessHandler.toURL =
memberHandler.toURL =
sectionHandler.toURL =
boxHandler.toURL =
documentHandler.toURL =
memoHandler.toURL =
pollHandler.toURL =
urlHandler.toURL =
popupHandler.toURL =
fileHandler.toURL =
//messageHandler.toURL =
pageHandler.toURL =
skinHandler.toURL =
userHandler.toURL =
statHandler.toURL =
newsLetterHandler.toURL =
websiteHandler.toURL = HiveToURL;

accessHandler.setSourceSite =
memberHandler.setSourceSite =
sectionHandler.setSourceSite =
boxHandler.setSourceSite =
documentHandler.setSourceSite =
memoHandler.setSourceSite =
pollHandler.setSourceSite =
urlHandler.setSourceSite =
popupHandler.setSourceSite =
fileHandler.setSourceSite =
//messageHandler.setSourceSite =
pageHandler.setSourceSite =
skinHandler.setSourceSite =
userHandler.setSourceSite =
statHandler.setSourceSite =
newsLetterHandler.setSourceSite =
websiteHandler.setSourceSite = HiveSetSourceSite;

accessHandler.getParams =
memberHandler.getParams =
sectionHandler.getParams =
boxHandler.getParams =
documentHandler.getParams =
memoHandler.getParams =
pollHandler.getParams =
urlHandler.getParams =
popupHandler.getParams =
fileHandler.getParams =
//messageHandler.getParams =
pageHandler.getParams =
skinHandler.getParams =
userHandler.getParams =
statHandler.getParams =
newsLetterHandler.getParams =
websiteHandler.getParams = HiveGetParams;



function attachDataSet(ds) {
	ds.form = function(name) { return elm(this.name+name); }
}

function emptyAlert(eid,msg,fcs) {
	var elem = elm(eid);
	if( elem && isEmpty(elem.value) ) {
		alert( msg );
		if( fcs ) elem = fcs;
		elem.focus();
		return true;
	}
	return false;
}

checkedValues = function(checkboxes,isName) {
	var rl = [];
	var es = checkboxes;
	if( isName ) es = elms(checkboxes);
	for(var i=0;i<es.length;i++)
		if( es[i].checked ) rl[rl.length] = es[i].value;
	return rl.join(",");
}
