// correctly handle PNG transparency in Win IE 5.5 & 6.
function correctPNG()
{
   var arVersion = navigator.appVersion.split("MSIE")
   var version = parseFloat(arVersion[1])
   if ((version >= 5.5) && (document.body.filters))
   {
      for(var i=0; i<document.images.length; i++)
      {
         var img = document.images[i]
         var imgName = img.src.toUpperCase()
         if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
         {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
            img.outerHTML = strNewHTML
            i = i-1
         }
      }
   }
}
//hide selects on page

function hideFormSelects(action) {
	if (action != 'visible') {
		action = 'hidden';
	}
	if (navigator.appName.indexOf("MSIE")) {
		for (var S = 0; S < document.forms.length; S++) {
			for (var R = 0; R < document.forms[S].length; R++) {
				if (document.forms[S].elements[R].options) {
					document.forms[S].elements[R].style.visibility = action;
				}
			}
		}
	}
}
/**
 * 
 * @param {Object} selectObj
 */
function getSelected(selectObj){
  return selectObj.options[selectObj.selectedIndex].value;
}
function getTimestampAsParam(){
	return '&timestamp=' + (new Date()).getTime();
}
function rightClick(e) {
	var msg ="Right click disabled on images!";
	
	if (navigator.appName == 'Netscape' && e.which == 3) {
		
		return false;
	}
	if (navigator.appName == 'Microsoft Internet Explorer' && event.button==2) {
		alert(msg);
		return false;
	}
	else 
		return true;
}

function disableImagesRightClick() {
}

function disableContextMenu(element) {
    element.oncontextmenu = function() {
        return false;
    }
}
if(!window.DateUtil){
	var DateUtil = {};
	Date._DAYS = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
	Date._MONTHS = ["January", "February", "March", "April", "May", "June", "July","August", "September", "October", "November", "December"];
	/**
	 * An array of days in each month.  The second entry (February) will be modified to 29 days if
	 * it is a leap year when the date is queried.
	 * @private
	 */
	Date._DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	/**
	 * Gets the number of days in the month, takes into account leap years.
	 * 
	 */
	DateUtil.getDaysInMonth = function(year, month)
	{
		var mn = month;

		if ((Date._MONTHS[mn] == "February") && DateUtil.isLeapYear(year))
		{
			return 29;
		}
		else
		{
			return Date._DAYS_IN_MONTH[mn];
		}
	};
	/**
	 * Returns true if the date specified is a leap year.
	 * 
	 */
	DateUtil.isLeapYear = function(yr)
	{
		var dif = 29;

		if (yr % 4 != 0) { dif = 28; }
		else if (yr % 400 == 0) { dif = 29; }
		else if (yr % 100 == 0) { dif = 28; }
		return (dif == 29);
	};
	
	/**
	 * 
	 * 
	 */
	DateUtil.getDayName = function(day, month, year)
	{
		var date =new Date();
		date.setFullYear(year,month,day);
		return Date._DAYS[date.getDay()];
	};
	
	/**
	 * 
	 * 
	 */
	DateUtil.getMonthName = function(month)
	{
		return Date._MONTHS[month];
	};
}
/**
* EasyDrag 1.3 - Drag & Drop jQuery Plug-in
*
* For usage instructions please visit http://fromvega.com
*
* Copyright (c) 2007 fromvega
*/

(function($){

	// to track if the mouse button is pressed
	var isMouseDown    = false;

	// to track the current element being dragged
	var currentElement = null;

	// callback holders
	var dropCallbacks = {};
	var dragCallbacks = {};

	// global position records
	var lastMouseX;
	var lastMouseY;
	var lastElemTop;
	var lastElemLeft;

	// returns the mouse (cursor) current position
	$.getMousePosition = function(e){
		var posx = 0;
		var posy = 0;

		if (!e) var e = window.event;

		if (e.pageX || e.pageY) {
			posx = e.pageX;
			posy = e.pageY;
		}
		else if (e.clientX || e.clientY) {
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop  + document.documentElement.scrollTop;
		}

		return { 'x': posx, 'y': posy };
	}

	// updates the position of the current element being dragged
	$.updatePosition = function(e) {
		var pos = $.getMousePosition(e);

		var spanX = (pos.x - lastMouseX);
		var spanY = (pos.y - lastMouseY);

		$(currentElement).css("top",  (lastElemTop + spanY));
		$(currentElement).css("left", (lastElemLeft + spanX));
	}

	// when the mouse is moved while the mouse button is pressed
	$(document).mousemove(function(e){
		if(isMouseDown){
			// update the position and call the registered function
			$.updatePosition(e);
			if(dragCallbacks[currentElement.id] != undefined){
				dragCallbacks[currentElement.id](e);
			}

			return false;
		}
	});

	// when the mouse button is released
	$(document).mouseup(function(e){
		if(isMouseDown){
			isMouseDown = false;
			if(dropCallbacks[currentElement.id] != undefined){
				dropCallbacks[currentElement.id](e);
			}

			return false;
		}
	});

	// register the function to be called while an element is being dragged
	$.fn.ondrag = function(callback){
		return this.each(function(){
			dragCallbacks[this.id] = callback;
		});
	}

	// register the function to be called when an element is dropped
	$.fn.ondrop = function(callback){
		return this.each(function(){
			dropCallbacks[this.id] = callback;
		});
	}

	// set an element as draggable - allowBubbling enables/disables event bubbling
	$.fn.easydrag = function(allowBubbling){

		return this.each(function(){

			// if no id is defined assign a unique one
			if(undefined == this.id) this.id = 'easydrag'+time();

			// change the mouse pointer
			$(this).css("cursor", "move");

			// when an element receives a mouse press
			$(this).mousedown(function(e){			

				// set it as absolute positioned
				$(this).css("position", "absolute");

				// set z-index
				$(this).css("z-index", "10000");

				// update track variables
				isMouseDown    = true;
				currentElement = this;

				// retrieve positioning properties
				var pos    = $.getMousePosition(e);
				lastMouseX = pos.x;
				lastMouseY = pos.y;

				lastElemTop  = this.offsetTop;
				lastElemLeft = this.offsetLeft;

				$.updatePosition(e);

				return allowBubbling ? true : false;
			});
		});
	}

})(jQuery);