﻿
var Sysmo = {
	convert: {
		toInt: function(value,defaultValue) {
			return (parseInt(value).toString() == 'NaN') ? defaultValue : parseInt(value);
		}
	},
	dom: {
		appendChild: function(node,parent) {
			parent.appendChild(node);
		},
		insertBefore: function(node,sibling) {
			sibling.parentNode.insertBefore(node,sibling);
		},
		insertChildAt: function(node,parent,index) {
			var children = Sysmo.dom.getChildren(node);
			if (index < 0 || index > children.length)
				return;
			if (index != children.length)
				Sysmo.dom.appendChild(node,parent);
			else
				Sysmo.dom.insertBefore(node,children[index]);
		},
		removeChildren: function(node) {
			while (node.hasChildNodes())
			{
				node.removeChild(node.firstChild);
			}
		},
		getFirstChild: function(node) {
			//"nodeType" attribute: 1=element, 3=whitespace
			for (var i=0;i<node.childNodes.length;i++)
			{
				if (node.childNodes[i].nodeType == 1)
					return node.childNodes[i];
			}
			return null;
		},
		getLastChild: function(node) {
			//"nodeType" attribute: 1=element, 3=whitespace
			for (var i=node.childNodes.length-1;i>=0;i--)
			{
				if (node.childNodes[i].nodeType == 1)
					return node.childNodes[i];
			}
			return null;
		},
		getChildren: function(node) {
			var children = new Array();
			//"nodeType" attribute: 1=element, 3=whitespace
			for (var i=0;i<node.childNodes.length;i++)
			{
				if (node.childNodes[i].nodeType == 1)
					children[children.length] = node.childNodes[i];
			}
			return children;
		},
		getInnerText: function(node) {
			return node.innerText || node.textContent || '';
		},
		setInnerText: function(node,value) {
			if (node==null) return;
			if (typeof node.innerText!='undefined')
				node.innerText = value;
			else if (typeof node.textContent!='undefined')
				node.textContent = value;
		},
		getOuterHTML: function(obj){
			if (!obj) return null;
			if (!Prototype.Browser.IE)
			{
				var d=document.createElement('DIV');
				d.appendChild(obj.cloneNode(true));
				var h=d.innerHTML;
				d.innerHTML='';
				d=null;
				return h;
			}
			else return obj.outerHTML;
		},
		contains: function(parent,child) {
			if (parent==null||child==null) return false;
			if (parent.contains) return parent.contains(child);
 			while(child && (parent!=child) && (child!=null))
				child = child.parentNode;
			return parent == child;
		},
		getPosition: function(obj) {
			var l = t = 0;
			if (obj.offsetParent) {
				do {
					l += obj.offsetLeft;
					t += obj.offsetTop;
				} while (obj = obj.offsetParent);
			}
			return [l,t];
		}
	},
	dates: {
		now: function() {
			return (Date.now) ? Date.now() : (new Date().getTime());
		},
		monthNames: ['January','February','March','April','May','June','July',
						'August','September','October','November','December'],
		daysInMonth: function(monthDate) {
			var date = new Date(monthDate.getFullYear(), monthDate.getMonth()+1, 0);
			return date.getDate();
		},
		firstDayInMonth: function(monthDate) {
			var date = new Date(monthDate.getFullYear(), monthDate.getMonth(), 1);
			return date.getDay();
		},
		getMonthName: function(monthDate) {
			return Sysmo.dates.monthNames[monthDate.getMonth()];
		},
		copy: function(date) {
			var tmp = new Date();
			tmp.setTime(date.valueOf());
			return tmp;
		},
		copyWithoutTime: function(date) {
			return new Date(date.getFullYear(),date.getMonth(),date.getDate());
		},
		addMonths: function(date,num) {
			date.setMonth(date.getMonth() + num);
		},
		addDays: function(date,num) {
			date.setDate(date.getDate()+num);
		},
		setToLastDay: function(date) {
			date.setDate(Sysmo.dates.daysInMonth(date));
		},
		getDateString: function(date) {
			return date.toDateString();//(date.getMonth()+1)+'/'+date.getDate()+'/'+date.getFullYear();
		}
	}
}

var __OpenWindows = new Array();

//MM_openBrWindow('popup.aspx','popupWindow','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600')
function MM_openBrWindow(theURL,winName,features) { //v2.0
  return window.open(theURL,winName,features);
}

function OpenWindow(url,height,width)
{
	var win=__OpenWindows[url];
	if (win==null||win.closed)
	{
		win=MM_openBrWindow(url,escape(url),'height='+height+',width='+width+',scrollbars=yes,resizable=yes');
		__OpenWindows[url]=win;
	}
	win.focus();
	return win;
}

Date.prototype.copy = function(date) {
	return Sysmo.dates.copy(date);
}
