// NameValueCollectionConverter
if(typeof Ajax == "undefined") Ajax={};
if(typeof Ajax.Web == "undefined") Ajax.Web={};

Ajax.Web.NameValueCollection = function(items) {
	this.__type = "System.Collections.Specialized.NameValueCollection";
	this.keys = [];
	this.values = [];

	if(items != null && !isNaN(items.length)) {
		for(var i=0; i<items.length; i++)
			this.add(items[i][0], items[i][1]);
	}
}
Object.extend(Ajax.Web.NameValueCollection.prototype, {
	add: function(k, v) {
		if(k == null || k.constructor != String || v == null || v.constructor != String)
			return -1;
		this.keys.push(k);
		this.values.push(v);
		return this.values.length -1;
	},
	containsKey: function(key) {
		for(var i=0; i<this.keys.length; i++)
			if(this.keys[i] == key) return true;
		return false;
	},
	getKeys: function() {
		return this.keys;
	},
	getValue: function(k) {
		for(var i=0; i<this.keys.length && i<this.values.length; i++)
			if(this.keys[i] == k) return this.values[i];
		return null;
	},
	setValue: function(k, v) {
		if(k == null || k.constructor != String || v == null || v.constructor != String)
			return -1;
		for(var i=0; i<this.keys.length && i<this.values.length; i++) {
			if(this.keys[i] == k) this.values[i] = v;
			return i;
		}
		return this.add(k, v);
	},
	toJSON: function() {
		return AjaxPro.toJSON({__type:this.__type,keys:this.keys,values:this.values});
	}
}, true);

// DataSetConverter
if(typeof Ajax == "undefined") Ajax={};
if(typeof Ajax.Web == "undefined") Ajax.Web={};

Ajax.Web.DataSet = function(t) {
	this.__type = "System.Data.DataSet,System.Data";
	this.Tables = [];
	this.addTable = function(t) {
		this.Tables.push(t);
	}
	if(t != null) {
		for(var i=0; i<t.length; i++) {
			this.addTable(t[i]);
		}
	}
}

// DataTableConverter
if(typeof Ajax == "undefined") Ajax={};
if(typeof Ajax.Web == "undefined") Ajax.Web={};

Ajax.Web.DataTable = function(c, r) {
	this.__type = "System.Data.DataTable,System.Data";
	this.Columns = [];
	this.Rows = [];
	this.addColumn = function(name, type) {
		this.Columns.push({Name:name,__type:type});
	}
	this.toJSON = function() {
		var dt = {};
		dt.Columns = [];
		for(var i=0; i<this.Columns.length; i++)
			dt.Columns.push([this.Columns[i].Name, this.Columns[i].__type]);
		dt.Rows = [];
		for(var i=0; i<this.Rows.length; i++) {
			var row = [];
			for(var j=0; j<this.Columns.length; j++)
				row.push(this.Rows[i][this.Columns[j].Name]);
			dt.Rows.push(row);
		}
		return AjaxPro.toJSON(dt);
	}
	this.addRow = function(row) {
		this.Rows.push(row);
	}
	if(c != null) {
		for(var i=0; i<c.length; i++)
			this.addColumn(c[i][0], c[i][1]);
	}
	if(r != null) {
		for(var i=0; i<r.length; i++) {
			var row = {};
			for(var c=0; c<this.Columns.length && c<r[i].length; c++)
				row[this.Columns[c].Name] = r[i][c];
			this.addRow(row);
		}
	}
}

// ProfileBaseConverter
if(typeof Ajax == "undefined") Ajax={};
if(typeof Ajax.Web == "undefined") Ajax.Web={};

Ajax.Web.Profile = function() {
	this.toJSON = function() {
		throw "Ajax.Web.Profile cannot be converted to JSON format.";
	}
	this.setProperty_callback = function(res) {
	}
	this.setProperty = function(name, object) {
		this[name] = object;
		AjaxPro.Services.Profile.SetProfile({name:o}, this.setProperty_callback.bind(this));
	}
}

// IDictionaryConverter
if(typeof Ajax == "undefined") Ajax={};
if(typeof Ajax.Web == "undefined") Ajax.Web={};

Ajax.Web.Dictionary = function(type,items) {
	this.__type = type;
	this.keys = [];
	this.values = [];

	if(items != null && !isNaN(items.length)) {
		for(var i=0; i<items.length; i++)
			this.add(items[i][0], items[i][1]);
	}
}
Object.extend(Ajax.Web.Dictionary.prototype, {
	add: function(k, v) {
		this.keys.push(k);
		this.values.push(v);
		return this.values.length -1;
	},
	containsKey: function(key) {
		for(var i=0; i<this.keys.length; i++)
			if(this.keys[i] == key) return true;
		return false;
	},
	getKeys: function() {
		return this.keys;
	},
	getValue: function(key) {
		for(var i=0; i<this.keys.length && i<this.values.length; i++)
			if(this.keys[i] == key) return this.values[i];
		return null;
	},
	setValue: function(k, v) {
		for(var i=0; i<this.keys.length && i<this.values.length; i++) {
			if(this.keys[i] == k) this.values[i] = v;
			return i;
		}
		return this.add(k, v);
	},
	toJSON: function() {
		return AjaxPro.toJSON({__type:this.__type,keys:this.keys,values:this.values});
	}
}, true);

// SNAccountConverter
var nsParts = 'Newman.BLL'.split('.');
		var root = window;
		for(var i=0; i<nsParts.length; i++) {
			if(typeof root[nsParts[i]] == 'undefined')
				root[nsParts[i]] = {};
			root = root[nsParts[i]];
		}
Newman.BLL.SNAccount=function(SNID,Username,IsTemporary) {this.SNID=SNID;this.Username=Username;this.IsTemporary=IsTemporary;}
// EmailConverter
if(typeof Newman == "undefined") Newman={};
if(typeof Newman.BLL == "undefined") Newman.BLL={};

Newman.BLL.Email = function(MailID,UserID,FolderID,Subject,ReceiveTime,From,To,Size,HasAttachments,LastAction,Unread,SpamProbability,Envelope) {
	this.__type = "Newman.BLL.Email, Newman.BLL";
    var flds='MailID,UserID,FolderID,Subject,ReceiveTime,From,To,Size,HasAttachments,LastAction,Unread,SpamProbability,Envelope'.split(',');
    var fld; 
    for(var i=0;fld=flds[i];i++) {
        eval('this.'+fld+'='+fld);
    }
}
Newman.BLL.Email.prototype.Get=function(key,defval,fn){
        if (isobj(key)) {key=key.key;def=key.def;fn=key.fn;}
        var val=this[key];
        if (def(val)) {
            if (isnotnull(fn)) return fn(val)
            else return val; 
        }
        else return defval;
}

// FolderConverter
if(typeof Newman == 'undefined') Newman={};
if(typeof Newman.BLL == 'undefined') Newman.BLL={};
Newman.BLL.Folder = function(fid,name,readItemCount,unreadItemCount) {
	this.__type = 'Newman.BLL.Folder, Newman.BLL';
    this.Name=name;
    this.FolderID=fid;
    this.ReadItemCount=readItemCount;
    this.UnreadItemCount=unreadItemCount;
    this.ItemCount=readItemCount+unreadItemCount;
}

// UserConverter
var nsParts = 'Newman.BLL'.split('.');
		var root = window;
		for(var i=0; i<nsParts.length; i++) {
			if(typeof root[nsParts[i]] == 'undefined')
				root[nsParts[i]] = {};
			root = root[nsParts[i]];
		}
Newman.BLL.User=function(UserID,Name,UserName,DisplayName,LastLogin,Headline,SecondaryEmail,HasPhoto,PhotoURL,PhotoLastModified,HasLayout,IsAutoDefaultLayoutEnabled,DefaultExtMailAcct) {this.UserID=UserID;this.Name=Name;this.UserName=UserName;this.DisplayName=DisplayName;this.LastLogin=LastLogin;this.Headline=Headline;this.SecondaryEmail=SecondaryEmail;this.HasPhoto=HasPhoto;this.PhotoURL=PhotoURL;this.PhotoLastModified=PhotoLastModified;this.HasLayout=HasLayout;this.IsAutoDefaultLayoutEnabled=IsAutoDefaultLayoutEnabled;this.DefaultExtMailAcct=DefaultExtMailAcct;}
// BasicContactConverter
var nsParts = 'Newman.BLL'.split('.');
		var root = window;
		for(var i=0; i<nsParts.length; i++) {
			if(typeof root[nsParts[i]] == 'undefined')
				root[nsParts[i]] = {};
			root = root[nsParts[i]];
		}
Newman.BLL.BasicContact=function(ContactID,UserID,Name,Email,ContactUserID,Headline,HasPhoto,HasContactPhoto,HasUserPhoto,UseContactPhoto,UserPhotoURLParams,PhotoURLParams,ContactPhotoURLParams,PhotoLastModified,PhotoInvitationSent) {this.ContactID=ContactID;this.UserID=UserID;this.Name=Name;this.Email=Email;this.ContactUserID=ContactUserID;this.Headline=Headline;this.HasPhoto=HasPhoto;this.HasContactPhoto=HasContactPhoto;this.HasUserPhoto=HasUserPhoto;this.UseContactPhoto=UseContactPhoto;this.UserPhotoURLParams=UserPhotoURLParams;this.PhotoURLParams=PhotoURLParams;this.ContactPhotoURLParams=ContactPhotoURLParams;this.PhotoLastModified=PhotoLastModified;this.PhotoInvitationSent=PhotoInvitationSent;}
// ContactConverter
var nsParts = 'Newman.BLL'.split('.');
		var root = window;
		for(var i=0; i<nsParts.length; i++) {
			if(typeof root[nsParts[i]] == 'undefined')
				root[nsParts[i]] = {};
			root = root[nsParts[i]];
		}
Newman.BLL.Contact=function(LastUse,UseCount,HomePhone,WorkPhone,MobilePhone,Notes,ContactID,UserID,ContactUserID,Name,Email,Headline,HasPhoto,PhotoLastModified,HasContactPhoto,HasUserPhoto,UseContactPhoto,PhotoURLParams,ContactPhotoLastModified,ContactPhotoURLParams,UserPhotoLastModified,UserPhotoPath,UserPhotoURLParams,PhotoLastModified,PhotoInvitationSent) {this.LastUse=LastUse;this.UseCount=UseCount;this.HomePhone=HomePhone;this.WorkPhone=WorkPhone;this.MobilePhone=MobilePhone;this.Notes=Notes;this.ContactID=ContactID;this.UserID=UserID;this.ContactUserID=ContactUserID;this.Name=Name;this.Email=Email;this.Headline=Headline;this.HasPhoto=HasPhoto;this.PhotoLastModified=PhotoLastModified;this.HasContactPhoto=HasContactPhoto;this.HasUserPhoto=HasUserPhoto;this.UseContactPhoto=UseContactPhoto;this.PhotoURLParams=PhotoURLParams;this.ContactPhotoLastModified=ContactPhotoLastModified;this.ContactPhotoURLParams=ContactPhotoURLParams;this.UserPhotoLastModified=UserPhotoLastModified;this.UserPhotoPath=UserPhotoPath;this.UserPhotoURLParams=UserPhotoURLParams;this.PhotoLastModified=PhotoLastModified;this.PhotoInvitationSent=PhotoInvitationSent;}
// MailMessageConverter
var nsParts = 'Newman.BLL'.split('.');
		var root = window;
		for(var i=0; i<nsParts.length; i++) {
			if(typeof root[nsParts[i]] == 'undefined')
				root[nsParts[i]] = {};
			root = root[nsParts[i]];
		}
Newman.BLL.MailMessage=function(Attachments,Subject,From,To,Cc,Bcc,ReplyTo,SentTime,ContentType,BodyCharset,IsHtml) {this.Attachments=Attachments;this.Subject=Subject;this.From=From;this.To=To;this.Cc=Cc;this.Bcc=Bcc;this.ReplyTo=ReplyTo;this.SentTime=SentTime;this.ContentType=ContentType;this.BodyCharset=BodyCharset;this.IsHtml=IsHtml;}
// SnippetCategoryConverter
var nsParts = 'Newman.BLL'.split('.');
		var root = window;
		for(var i=0; i<nsParts.length; i++) {
			if(typeof root[nsParts[i]] == 'undefined')
				root[nsParts[i]] = {};
			root = root[nsParts[i]];
		}
Newman.BLL.SnippetCategory=function(CategoryID,CategoryName,IconUrl,ItemsToShow,Links) {this.CategoryID=CategoryID;this.CategoryName=CategoryName;this.IconUrl=IconUrl;this.ItemsToShow=ItemsToShow;this.Links=Links;}
