function DateFormat(vDateName, vDateValue, e) {
    var dateFormat = "mm-dd-yyyy";
    var strSeperator = "-";
    var separatorIdx1 = dateFormat.indexOf(strSeperator);
    var separatorIdx2 = dateFormat.lastIndexOf(strSeperator);
    var whichCode = (window.Event) ? e.which : e.keyCode;
    // Check to see if a seperator is already present.
    // bypass the date if a seperator is present and the length greater than 8

    //Eliminate all the ASCII codes that are not valid
    var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-";
    if (alphaCheck.indexOf(vDateValue) >= 1) {
        vDateName.value = vDateName.value.substr(0, (vDateValue.length - 1));
        return false;
    }

    if (whichCode == 8) {
        return true;//backspace
    }

    //Create numeric string values for 0123456789/
    //The codes provided include both keyboard and keypad values
    var strCheck = '47,48,49,50,51,52,53,54,55,56,57,58,59,95,96,97,98,99,100,101,102,103,104,105';
    if (strCheck.indexOf(whichCode) != -1) {
        // Reformat date to format that can be validated. mm/dd/yyyy
        if (vDateValue.length == separatorIdx1) {
            vDateName.value = vDateValue + strSeperator;
        }
        if (vDateValue.length == separatorIdx2) {
            vDateName.value = vDateValue + strSeperator;
        }
    }
    return true;
}

//-------------------------------------------- focus object by its tabindex (must be defined!)
function FocusObjectByTabIndex(nr)
{
	obj = document.getElementsByTagName("*");
	for (i=0; i < obj.length; i++)
	{
		if (obj[i].tabIndex >= nr && obj[i].disabled == false)
		{               
            obj[i].focus();
            objonfocus(obj[i]);
			break;
		};
	};
};

function setFocus(parentElementId){
    $("#"+parentElementId).focus();
}


//-------------------------------------------- attach event handlers
function AssignDefaultEvents(defaultEnterFunctionality)
{
	function processCollection(obj)
	{
		for (i=0; i < obj.length; i++)
		{
            //obj[i].onmouseover = function() { objonmouseover(this); };
            //obj[i].onfocus = function() { objonfocus(this); };
            //obj[i].onmouseout = function() { objonmouseout(this); };
            //obj[i].onblur = function() { objonblur(this); };

            var oldonmouseover = obj[i].onmouseover;

            obj[i].onmouseover = function() {
                if(oldonmouseover) {
                    oldonmouseover();
                }
                objonmouseover(this);
            };

			var oldonfocus = obj[i].onfocus;

            obj[i].onfocus = function() {
                if(oldonfocus) {
                    oldonfocus();
                }
                objonfocus(this);
            };

            var oldonmouseout = obj[i].onmouseout;

            obj[i].onmouseout = function() {
                if(oldonmouseout) {
                    oldonmouseout();
                }
                objonmouseout(this);
            };

            var oldonblur = obj[i].onblur;

            obj[i].onblur = function() {
                if(oldonblur) {
                    oldonblur();
                }
                objonblur(this);
            };

			if(!defaultEnterFunctionality){
                obj[i].onkeypress = onEnterKey;
            }

		};
	};

	//---process our form elements
	for (j=0; j < document.forms.length; j++)
	{
		myForm = document.forms[j];
		obj = myForm.elements;
        myForm.reset();
		processCollection(obj);
	};
};

//-------------------------------------------- user mouseover object
function objonmouseover(obj)
{
	obj.OldClassName = obj.className;
	obj.className = "_over";
};

//-------------------------------------------- user mouseout object
function objonmouseout(obj)
{
	status.innerText = obj.IsSelected;
    //obj.className = obj.OldClassName;
	//if (obj.IsSelected) obj.className = obj.OldClassName
	//else obj.className = "";

    if(obj.IsSelected) {
        obj.className = "_sel";
    } else {
        obj.className = "";
    }
};

//-------------------------------------------- user click object and set focus
function objonfocus(obj)
{
	if (obj.type == "radio" || obj.type == "checkbox")
	{
		obj.parentNode.className = "_sel";
		obj.parentNode.IsSelected = true;
	}
	else
	{
		obj.className = "_sel";
		obj.IsSelected = true;
	};
};

//-------------------------------------------- object loose focus
function objonblur(obj)
{
	if (obj.type == "radio" || obj.type == "checkbox")
	{
		obj.parentNode.className = "";
		obj.parentNode.IsSelected = false;
	}
	else
	{
		obj.className = "";
		obj.IsSelected = false;
	};
	//if (obj.tabIndex >= lastTabindex) FocusObjectByTabIndex(1);
};

//-------------------------------------------------
function objonkeyup(obj)
{

};

//-------------------------------------------- user press ENTER
function onEnterKey(e)
{
    var key;

    if (window.event) key = window.event.keyCode //---IE
    else key = e.which; //---FF
    if (key == 13)
	{
		FocusObjectByTabIndex(this.tabIndex + 1);
		return false;
	}
    else return true;
};


//--------------------------------------------someone "mouseover" typical table row
function row_over(tag_uid)
{
	tag_uid.className = tag_uid.className + " row_ovr";
};


//--------------------------------------------someone "mouseout" typical table row
function row_out(tag_uid, c_name)
{
	tag_uid.className = c_name;
};



////////////////////////////////////////ROUNDED/////////////////////////////////////////

// Contributors
// Ilkka Huotari at http://www.editsite.net
// Mathieu 'p01' HENRI at http://www.p01.org/
// http://seky.nahory.net/2005/04/rounded-corners/
// Steven Wittens at http://www.acko.net/anti-aliased-nifty-corners
// Original Nifty Corners by Alessandro Fulciniti at http://pro.html.it/esempio/nifty/
function NiftyCheck() {
  if(!document.getElementById || !document.createElement) {
    return false;
  }
  var b = navigator.userAgent.toLowerCase();
  if (b.indexOf("msie 5") > 0 && b.indexOf("opera") == -1) {
    return false;
  }
  return true;
}

function Rounded(className, sizex, sizey, sizex_b, sizey_b) {
	var bk;
	if (!NiftyCheck()) return;
	if (typeof(sizex_b) == 'undefined')
		sizex_b = sizex;
	if (typeof(sizey_b) == 'undefined')
		sizey_b = sizey;
	var v = getElements(className);
	var l = v.length;
	for (var i = 0; i < l; i++) {
		color = get_current_style(v[i],"background-color","transparent");
		bk = get_current_style(v[i].parentNode,"background-color","transparent");
		AddRounded(v[i], bk, color, sizex, sizey, true);
		AddRounded(v[i], bk, color, sizex_b, sizey_b, false);
	}
}

Math.sqr = function (x) {
  return x*x;
};

function Blend(a, b, alpha) {

  var ca = Array(
    parseInt('0x' + a.substring(1, 3)),
    parseInt('0x' + a.substring(3, 5)),
    parseInt('0x' + a.substring(5, 7))
  );
  var cb = Array(
    parseInt('0x' + b.substring(1, 3)),
    parseInt('0x' + b.substring(3, 5)),
    parseInt('0x' + b.substring(5, 7))
  );
  return '#' + ('0'+Math.round(ca[0] + (cb[0] - ca[0])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[1] + (cb[1] - ca[1])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[2] + (cb[2] - ca[2])*alpha).toString(16)).slice(-2).toString(16);

  return '#' + ('0'+Math.round(ca[0] + (cb[0] - ca[0])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[1] + (cb[1] - ca[1])*alpha).toString(16)).slice(-2).toString(16)
             + ('0'+Math.round(ca[2] + (cb[2] - ca[2])*alpha).toString(16)).slice(-2).toString(16);
}

function AddRounded(el, bk, color, sizex, sizey, top) {
  if (!sizex && !sizey)
	return;
  var i, j;
  var d = document.createElement("div");
  d.style.backgroundColor = bk;
  var lastarc = 0;
  for (i = 1; i <= sizey; i++) {
    var coverage, arc2, arc3;
    // Find intersection of arc with bottom of pixel row
    arc = Math.sqrt(1.0 - Math.sqr(1.0 - i / sizey)) * sizex;
    // Calculate how many pixels are bg, fg and blended.
    var n_bg = sizex - Math.ceil(arc);
    var n_fg = Math.floor(lastarc);
    var n_aa = sizex - n_bg - n_fg;
    // Create pixel row wrapper
    var x = document.createElement("div");
    var y = d;
    x.style.margin = "0px " + n_bg + "px";
	x.style.height='1px';
	x.style.overflow='hidden';
    // Make a wrapper per anti-aliased pixel (at least one)
    for (j = 1; j <= n_aa; j++) {
      // Calculate coverage per pixel
      // (approximates circle by a line within the pixel)
      if (j == 1) {
        if (j == n_aa) {
          // Single pixel
          coverage = ((arc + lastarc) * .5) - n_fg;
        }
        else {
          // First in a run
          arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
          coverage = (arc2 - (sizey - i)) * (arc - n_fg - n_aa + 1) * .5;
          // Coverage is incorrect. Why?
          coverage = 0;
        }
      }
      else if (j == n_aa) {
        // Last in a run
        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
        coverage = 1.0 - (1.0 - (arc2 - (sizey - i))) * (1.0 - (lastarc - n_fg)) * .5;
      }
      else {
        // Middle of a run
        arc3 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j) / sizex)) * sizey;
        arc2 = Math.sqrt(1.0 - Math.sqr((sizex - n_bg - j + 1) / sizex)) * sizey;
        coverage = ((arc2 + arc3) * .5) - (sizey - i);
      }

      x.style.backgroundColor = Blend(bk, color, coverage);
	  if (top)
	      y.appendChild(x);
      else
	      y.insertBefore(x, y.firstChild);
      y = x;
      var x = document.createElement("div");
		x.style.height='1px';
		x.style.overflow='hidden';
      x.style.margin = "0px 1px";
    }
    x.style.backgroundColor = color;
    if (top)
	    y.appendChild(x);
    else
		y.insertBefore(x, y.firstChild);
    lastarc = arc;
  }
  if (top)
	  el.insertBefore(d, el.firstChild);
  else
	  el.appendChild(d);
}

function getElements(className) {
	var elements = [];
	var el = document.getElementsByTagName('DIV');
	var regexp=new RegExp("\\b"+className+"\\b");
	for (var i = 0; i < el.length; i++)
	{
		if (regexp.test(el[i].className))
			elements.push(el[i]);
	}
	return elements;
}

function get_current_style(element,property,not_accepted)
{
  var ee,i,val,apr;
  try
  {
    var cs=document.defaultView.getComputedStyle(element,'');
    val=cs.getPropertyValue(property);
  }
  catch(ee)
  {
    if(element.currentStyle)
  	{
	    apr=property.split("-");
	    for(i=1;i<apr.length;i++) apr[i]=apr[i].toUpperCase();
	    apr=apr.join("");
	    val=element.currentStyle.getAttribute(apr);
   }
  }
  if((val.indexOf("rgba") > -1 || val==not_accepted) && element.parentNode)
  {
	 if(element.parentNode != document)
		 val=get_current_style(element.parentNode,property,not_accepted);
	 else
		 val = '#FFFFFF';
  }
  if (val.indexOf("rgb") > -1 && val.indexOf("rgba") == -1)
	  val = rgb2hex(val);
  if (val.length == 4)
	  val = '#'+val.substring(1,1)+val.substring(1,1)+val.substring(2,1)+val.substring(2,1)+val.substring(3,1)+val.substring(3,1);
  return val;
}

function rgb2hex(value)
{
	var x = 255;
	var hex = '';
	var i;
	var regexp=/([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/;
	var array=regexp.exec(value);
	for(i=1;i<4;i++) hex += ('0'+parseInt(array[i]).toString(16)).slice(-2);
	return '#'+hex;
}

////////////////////////////////////////ROUNDED END/////////////////////////////////////////


///////////////////////////////////SWEET TILES/////////////////////////////////////////
/*
Sweet Titles (c) Creative Commons 2005
http://creativecommons.org/licenses/by-sa/2.5/
Author: Dustin Diaz | http://www.dustindiaz.com
Edited by Johannes Fahrenkrug. The script now honors the showtooltip attribute
*/
var sweetTitles = {
	xCord : 0,			// @Number: x pixel value of current cursor position
	yCord : 0,			// @Number: y pixel value of current cursor position
	tipElements : ['input', 'td', 'tr', 'textarea', 'select', 'span', 'div', 'a','abbr','acronym', 'img'],
                                        // @Array: Allowable elements that can have the toolTip
	obj : Object,		        // @Element: That of which you're hovering over
	tip : Object,			// @Element: The actual toolTip itself
	active : 0,			// @Number: 0: Not Active || 1: Active
	init : function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		this.tip.style.top = '0';
		this.tip.style.visibility = 'hidden';
		var tipLen = this.tipElements.length;
		for ( i=0; i<tipLen; i++ ) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			var curLen = current.length;
			for ( j=0; j<curLen; j++ ) {
			  if (current[j].getAttribute('showtooltip') == 'true') {
				  addEvent(current[j],'mouseover',this.tipOver);
				  addEvent(current[j],'mouseout',this.tipOut);
                  if(current[j].title){
                    current[j].setAttribute('titleBackup',current[j].title);
                    current[j].removeAttribute('title');
                  }

                  current[j].setAttribute('tip',current[j].getAttribute('titleBackup'));

				}
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
			sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function() {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		sweetTitles.tip.style.visibility = 'hidden';
	},
	checkNode : function() {
		var trueObj = this.obj;
		if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		sweetTitles.obj = this;
		tID = window.setTimeout("sweetTitles.tipShow()",200);
		sweetTitles.updateXY(e);
	},
	tipShow : function() {
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);
		var anch = this.checkNode();
		var addy = '';
		var access = '';
		if ( anch.nodeName.toLowerCase() == 'a' ) {
			addy = (anch.href.length > 25 ?
                                anch.href.toString().substring(0,25)+"..."
                                : anch.href);
			var access = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
		} else if (anch.firstChild){
			addy = anch.firstChild.nodeValue;
		} else {
		  addy = '';
		}
		this.tip.innerHTML = "<p>"+anch.getAttribute('tip')+"<em>"+access+addy+"</em></p>";
		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) <
                    parseInt(this.tip.offsetWidth+lt) ) {
			this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
		} else {
			this.tip.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) <
                    parseInt(this.tip.offsetHeight+tp) ) {
			this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
		} else {
			this.tip.style.top = tp+'px';
		}
		this.tip.style.visibility = 'visible';
		this.tip.style.opacity = '.1';
		this.tipFade(10);
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 80 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"')",20);
		}
		else {
			this.tip.style.opacity = '.80';
			this.tip.style.filter = "alpha(opacity:80)";
		}
	}
};
function pageLoader() {
	sweetTitles.init();
}
//addEvent(window,'load',pageLoader);

Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

function addEvent( obj, type, fn ) {
	if (obj.addEventListener) {
		obj.addEventListener( type, fn, false );
		EventCache.add(obj, type, fn);
	}
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
		EventCache.add(obj, type, fn);
	}
	else {
		obj["on"+type] = obj["e"+type+fn];
	}
}

var EventCache = function(){
	var listEvents = [];
	return {
		listEvents : listEvents,
		add : function(node, sEventName, fHandler){
			listEvents.push(arguments);
		},
		flush : function(){
			var i, item;
			for(i = listEvents.length - 1; i >= 0; i = i - 1){
				item = listEvents[i];
				if(item[0].removeEventListener){
					item[0].removeEventListener(item[1], item[2], item[3]);
				};
				if(item[1].substring(0, 2) != "on"){
					item[1] = "on" + item[1];
				};
				if(item[0].detachEvent){
					item[0].detachEvent(item[1], item[2]);
				};
				item[0][item[1]] = null;
			};
		}
	};
}();
addEvent(window,'unload',EventCache.flush);

/////////////////////////////////SWEET TILES END//////////////////////////////////////