function ShowPopupCSS(idObjData, idObjDataDefault, rbCustomCSS , saveButton , cancelButton)
{	
	var containID = idObjDataDefault;
	
	var defaultCSS = "&defaultCSS=1";
	if(document.getElementById(rbCustomCSS) != null)
	{
		if(document.getElementById(rbCustomCSS).checked)
		{
			defaultCSS = "&defaultCSS=0";
			containID = idObjData;
		}	
	}
	
	var w = 670;
	var h = 540;
	if(screen.width)
	{
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}
	else
	{
		winl = 0;wint =0;
	}
	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;	
	
	var props = 'top='+wint+',left='+winl+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,width='+w+',height='+h;		
	window.open("wpresources/Bamboo.CalendarViewExtended/BambooPopupCSS.html?ContainID=" + escape(containID) + defaultCSS + "&saveButton=" + escape(saveButton) + "&cancelButton=" + escape(cancelButton) ,'FullScreen', props);
}

var timeout = 5000;//1/1000 of minutes
var viewport = {
  getWinWidth: function () {
    this.width = 0;
    if (window.innerWidth) this.width = window.innerWidth - 18;
    else if (document.documentElement && document.documentElement.clientWidth) 
  		this.width = document.documentElement.clientWidth;
    else if (document.body && document.body.clientWidth) 
  		this.width = document.body.clientWidth;
  },
  
  getWinHeight: function () {
    this.height = 0;
    if (window.innerHeight) this.height = window.innerHeight - 18;
  	else if (document.documentElement && document.documentElement.clientHeight) 
  		this.height = document.documentElement.clientHeight;
  	else if (document.body && document.body.clientHeight) 
  		this.height = document.body.clientHeight;
  },
  
  getScrollX: function () {
    this.scrollX = 0;
  	if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;
  	else if (document.documentElement && document.documentElement.scrollLeft)
  		this.scrollX = document.documentElement.scrollLeft;
  	else if (document.body && document.body.scrollLeft) 
  		this.scrollX = document.body.scrollLeft; 
  	else if (window.scrollX) this.scrollX = window.scrollX;
  },
  
  getScrollY: function () {
    this.scrollY = 0;    
    if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop)
  		this.scrollY = document.documentElement.scrollTop;
  	else if (document.body && document.body.scrollTop) 
  		this.scrollY = document.body.scrollTop; 
  	else if (window.scrollY) this.scrollY = window.scrollY;
  },
  
  getAll: function () {
    this.getWinWidth(); this.getWinHeight();
    this.getScrollX();  this.getScrollY();
  }
  
}

var RollTip = {
    offX: 12,
    offY: 12,
    ID: "rolltipDiv",
    aniLen: 300,
    ready: false,
    t1: null,
    t2: null,
    tip: null,

    init: function(idRollTip) {
        if (document.createElement && document.body && typeof document.body.appendChild != "undefined" && !window.opera) {
            this.ID = idRollTip;
            var el = document.createElement("DIV");
            el.className = "rolltip"; el.id = this.ID;
            document.body.appendChild(el);
            this.mult = el.offsetWidth / this.aniLen / this.aniLen;
            el.style.clip = "rect(0, 0, 0, 0)";
            el.style.visibility = "visible";
            this.ready = true;
        }
    },

    reveal: function(msg, e) {
        if (this.t1) clearTimeout(this.t1); if (this.t2) clearTimeout(this.t2);
        this.tip = document.getElementById(this.ID);
        this.writeTip(msg);
        viewport.getAll();
        this.w = this.tip.offsetWidth; this.h = this.tip.offsetHeight;
        this.startTime = (new Date()).getTime();
        this.positionTip(e);
        this.t1 = setInterval("RollTip.rollOut()", 10);
    },

    rollOut: function() {
        var elapsed = (new Date()).getTime() - this.startTime;
        if (elapsed < this.aniLen) {
            var cv = this.w - Math.round(Math.pow(this.aniLen - elapsed, 2) * this.mult);
            this.clipTo(0, cv, this.h, 0);
        } else {
            this.clipTo(0, this.w, this.h, 0);
            clearInterval(this.t1);
        }
    },

    conceal: function() {
        if (this.t1) clearInterval(this.t1); if (this.t2) clearInterval(this.t2);
        this.startTime = (new Date()).getTime();
        this.t2 = setInterval("RollTip.rollUp()", 10);
    },

    rollUp: function() {
        var elapsed = (new Date()).getTime() - this.startTime;
        if (elapsed < this.aniLen) {
            var cv = Math.round(Math.pow(this.aniLen - elapsed, 2) * this.mult);
            this.clipTo(0, cv, this.h, 0);
        } else {
            this.clipTo(0, 0, this.h, 0);
            clearInterval(this.t2);
            this.tip = null;
        }
    },

    writeTip: function(msg) {
        if (this.tip && typeof this.tip.innerHTML != "undefined") {
            msg = msg.replace(/\\u0025/g, "%").replace(/\\u0026/g, "&").replace(/\\u0028/g, "(").replace(/\\u0029/g, ")").replace(/\\u0022/g, "\"");
            msg = msg.replace(/\\u002b/g, "+").replace(/\\u002f/g, "/").replace(/\\u0027/g, "'").replace(/\\u003c/g, "<").replace(/\\u003e/g, ">");
            msg = msg.replace(/\\\\/g, "\\").replace("<div>", "").replace("</div>", "");
            this.tip.innerHTML = msg;
        }
    },

    clipTo: function(top, rt, btm, lft) {
        this.tip.style.clip = "rect(" + top + "px, " + rt + "px, " + btm + "px, " + lft + "px)";
    },

    positionTip: function(e) {
        var x = e.pageX ? e.pageX : e.clientX + viewport.scrollX;
        var y = e.pageY ? e.pageY : e.clientY + viewport.scrollY;
        if (x + this.tip.offsetWidth + this.offX > viewport.width + viewport.scrollX)
            x = x - this.tip.offsetWidth - this.offX;
        else x = x + this.offX;

        if (y + this.tip.offsetHeight + this.offY > viewport.height + viewport.scrollY)
            y = (y - this.tip.offsetHeight - this.offY > viewport.scrollY) ? y - this.tip.offsetHeight - this.offY : viewport.height + viewport.scrollY - this.tip.offsetHeight;
        else y = y + this.offY;

        this.tip.style.left = x + "px"; this.tip.style.top = y + "px";
    }

}

var imageHandler = { 
  imgs:[], path:"", preload:function() { for(var i=0;arguments[i];i++) {
    var img=new Image(); img.src=this.path+arguments[i]; this.imgs[this.imgs.length]=img;}}
}
var	timer = 0; 
var flag = true;
/*function BambooShowRollTip(msg, e) { 
  RollTip.init();
  if ( typeof RollTip == "undefined" || !RollTip.ready ) return;
  RollTip.reveal(msg, e);
  flag = true;  
  clearTimeout(0);
  timer = setTimeout("BambooHideRollTip()", timeout);
}*/
function BambooHideRollTip() {
  if(flag)  	
  {
  	if ( typeof RollTip == "undefined" || !RollTip.ready ) return;
  	RollTip.conceal();
  	flag = false;
  	clearTimeout(timer);
  }
}
//end Tooltip

function AutoSelectColors(id,sHiddenControlId,startColor)
{   
   var arrColor = new Array("#FFFFFF","#F0F8FF","#FAEBD7","#00FFFF","#7FFFD4","#F0FFFF","#F5F5DC","#FFE4C4","#FFEBCD","#0000FF","#8A2BE2","#A52A2A","#DEB887","#5F9EA0","#7FFF00","#D2691E","#FF7F50","#6495ED","#FFF8DC","#DC143C","#00008B","#008B8B","#B8860B","#A9A9A9","#006400","#BDB76B","#8B008B","#556B2F","#FF8C00","#9932CC","#8B0000","#E9967A","#8FBC8B","#1E90FF","#228B22","#848484","#008200","#CD5C5C","#E6E6FA","#FFFACD","#D3D3D3","#20B2AA","#00FF00","#FF00FF","#840000","#7B68EE","#000080","#FFA500","#FF0000","#FA8072","#C6C6C6","#6A5ACD","#008284","#FFFF00","#9ACD32");
   /*var startIndexColor = 0;
   for (var i = 0; i < arrColor.length; i++) 
   {
	  if(arrColor[i] == startColor)
	  {
	    startIndexColor = i;
		break;
	  }		
   }  */
   var tempColor = "";
   var numColor = arrColor.length;
   var firstTimes = true;
   //var indexOld =  startIndexColor;
   var separator1 = ";";
   var separator2 = ",";
   try
   {
		var arrayOfStrings1 = id.split(separator1);
		for (var i = 0; i < arrayOfStrings1.length; i++) 
		{
			if(arrayOfStrings1[i] != "")
			{
				var arrayOfStrings2 = arrayOfStrings1[i].split(separator2);
				if(arrayOfStrings2.length > 1 && arrayOfStrings2[0] != "" && arrayOfStrings2[1] != "")
				{	
					var numRandom = GetRandomNumber(numColor);
					while(IsDuplicateColor(tempColor, arrColor[numRandom]))
					{
						numRandom = GetRandomNumber(numColor);
					}
					tempColor = tempColor + arrColor[numRandom] +  "," ;
					if(i >= (numColor - 2) && firstTimes)
					{
						tempColor = "";
						firstTimes = false;
					}
					var dropDownList = document.getElementById(arrayOfStrings2[1] + "_Select");					
					for(var indexValue = 0; indexValue < dropDownList.options.length; indexValue ++)
					{						    
						if(dropDownList.options[indexValue].value == arrColor[numRandom])
						{
							dropDownList.options[indexValue].selected = true;
							document.getElementById(arrayOfStrings2[0]).value = arrColor[numRandom];																
							UpDateHiddenControl(arrayOfStrings2[1] , sHiddenControlId , arrColor[numRandom]);
							break;
						}
					}		
						/*
				    if(startIndexColor == arrColor.length)  
					{
						startIndexColor = 1;
					}
					if(startIndexColor < arrColor.length)
					{
						var dropDownList = document.getElementById(arrayOfStrings2[1] + "_Select");					
						for(var j=0; j < dropDownList.options.length; j++)
						{						    
							if(dropDownList.options[j].value == arrColor[startIndexColor])
							{
								dropDownList.options[j].selected = true;
								document.getElementById(arrayOfStrings2[0]).value = arrColor[startIndexColor];																
								UpDateHiddenControl(arrayOfStrings2[1] , sHiddenControlId , arrColor[startIndexColor]);
								startIndexColor++ ;	
								break;
							}
						}		
					}
					else
					{
					    startIndexColor = indexOld
					}*/
				}
			}
		}
	}	
	catch(err)
	{
		alert("AutoSelect:" + err.message );
	}
}


function GetRandomNumber(numColor)
{
	var newNumber = 1;
	while(1) 
	{
		newNumber = Math.floor(Math.random()*(numColor));
		if(newNumber == 0 || newNumber == numColor)
		{
			continue;
		}
		else 
		{
			break;
		}
	}
	return newNumber;
}

function IsDuplicateColor(tempColor, hexColor)
{
	if(tempColor != "")
	{
		var pos = tempColor.indexOf(hexColor);
		if(pos != -1)
		{
			return true;
		}
	}
	return false;
}

//*if (!document.layers&&!document.all&&!document.getElementById)
//event="test"
function UseTrustConnection(ID1,ID2)
{
	try
	{
		var obj = document.getElementById(ID1);
		var obj1 = document.getElementById(ID2);
		if(obj.checked == true)
		{
			obj1.style.display = "None";
		}
		else
		{
			obj1.style.display = "Block";
		}
	}
	catch(err)
	{
		alert("UseTrustConnection Error:: " + err.message );
	}
}



function showtip(current,e,text)
{
	try
	{
		if (document.all||document.getElementById)
		{
			thetitle=text.split('<br>')
			if (thetitle.length>1)
			{
				thetitles=''
				for (i=0;i<thetitle.length;i++)
				thetitles+=thetitle[i]
				current.title=thetitles
			}
			else
				current.title=text
		}
		else if (document.layers)
		{
			document.tooltip.document.write('<layer bgColor="white" style="border:1px solid black;font-size:12px;">'+text+'</layer>')
			document.tooltip.document.close()
			document.tooltip.left=e.pageX+5
			document.tooltip.top=e.pageY+5
			document.tooltip.visibility="show"
		}
	}
	catch(err)
	{
		alert("showtip Error:: " + err.message );
	} 
}

function hidetip()
{
	if (document.layers)
	document.tooltip.visibility="hidden"
}

function UseTrustConnection(ID1,ID2)
{
	try
	{
		var obj = document.getElementById(ID1);
		var obj1 = document.getElementById(ID2);
		if(obj.checked == true)
		{
			obj1.style.display = "None";
		}
		else
		{
			obj1.style.display = "Block";
		}
	}
	catch(err)
	{
		alert("UseTrustConnection Error:: " + err.message );
	}
}

function UpDateSelect(sSelectId, sHexColor)
{
	try
	{
		var bFlag = true;
		var oSelectElement =  document.getElementById(sSelectId);
		var oColorCollection = oSelectElement.options;
		var intCollectionLength = oColorCollection.length;
		for(i=0; i < intCollectionLength; i++)
		{
			if(oColorCollection[i].selected = true && oColorCollection[i].value != sHexColor)
				oColorCollection[i].selected = false;
			
			if(oColorCollection[i].value == sHexColor)
			{
				oColorCollection[i].selected = true;
				bFlag = false;
				break;	
			}
		}
		if(bFlag)
		{
			var oLastOption = oColorCollection[intCollectionLength-1];
			oLastOption.selected = true;
		}
	}
	catch(err)
	{
		alert("UpDateSelect Error:: " + err.message );
	} 
	
}


function UpDateColorFromTextBox(sChoiceName, sTextBoxId, sHiddenControlId, sSelectId, sDivId)
{
	try
	{
		var oTextBoxElment =  document.getElementById(sTextBoxId);
		var oDivElment =  document.getElementById(sDivId);
		var sHexColor = oTextBoxElment.value;
		oDivElment.style.backgroundColor = sHexColor;
		UpDateHiddenControl(sChoiceName, sHiddenControlId, sHexColor)
		UpDateSelect(sSelectId, sHexColor)
		
	}
	catch(err)
	{
		var sMessage = err.message;
		if(sMessage == "Invalid property value.")
		{
			sMessage = "Invalid color code for choice:: " + sChoiceName;
		}
		alert("UpDateColorFromTextBox Error:: " + sMessage );
	} 
	
}
function UpDateHiddenControl(sChoiceName, sHiddenControlId, sHexColor)
{
	try
	{
		var oHiddenControl =  document.getElementById(sHiddenControlId);
		if(oHiddenControl.value!='')
		{
			 var intChoiceIndex = oHiddenControl.value.indexOf(sChoiceName+"|");
			 if(intChoiceIndex>=0)
			 {
				var substr1 = oHiddenControl.value.substr(0, intChoiceIndex + sChoiceName.length) + '|' + sHexColor;
				
				var lastChoiceName = "";
				var s = oHiddenControl.value.substr(0, intChoiceIndex + sChoiceName.length);
				lastChoiceName = s.substr(s.lastIndexOf("~")+1, s.length - s.lastIndexOf("~") -1);
				if(lastChoiceName != sChoiceName)
				{
				    oHiddenControl.value += sChoiceName + '|' + sHexColor + '~';
				}
				else
				{
				    var substr2 = '';
				    if(oHiddenControl.value.length > substr1.length)
					    substr2 = oHiddenControl.value.substr(substr1.length,oHiddenControl.value.length-substr1.length);
					oHiddenControl.value = substr1 + substr2;
				}
			}
			else
			{
				oHiddenControl.value += sChoiceName + '|' + sHexColor + '~';
			}
		}
		else
		{
			oHiddenControl.value += sChoiceName + '|' + sHexColor + '~';
		}
	}
	catch(err)
	{
		alert("UpDateHiddenControl Error:: " + err.message );
	}
	
}
function UpDateColor(sChoiceName, sTextBoxId, sHiddenControlId)
{
	try
	{
		var oSelectElement =  event.srcElement;
		var oTextBoxElment =  document.getElementById(sTextBoxId);
		var sHexColor = oSelectElement.options[oSelectElement.selectedIndex].value;
		oTextBoxElment.value =  sHexColor;
		UpDateHiddenControl(sChoiceName, sHiddenControlId, sHexColor)
		
		
	}
	catch(err)
	{
		alert("UpDateColor Error:: " + err.message );
	} 
	
}
function UpDateHolidayColor(sTextBoxId, sHiddenControlId)
{
	try
	{
		var oSelectElement =  event.srcElement;
		var oTextBoxElment =  document.getElementById(sTextBoxId);
		var sHexColor = oSelectElement.options[oSelectElement.selectedIndex].value;
		oTextBoxElment.value =  sHexColor;
		var oHiddenControl =  document.getElementById(sHiddenControlId);
		oHiddenControl.value = sHexColor;
	}
	catch(err)
	{
		alert("UpDateHolidayColor Error:: " + err.message );
	} 
}

function UpDateHolidayColorFromTextBox(sTextBoxId, sHiddenControlId, sSelectId, sDivId)
{
	try
	{
		var oTextBoxElment =  document.getElementById(sTextBoxId);
		var oHiddenControl =  document.getElementById(sHiddenControlId);
		var oDivElment =  document.getElementById(sDivId);
		var sHolidayColor = oTextBoxElment.value;
		oDivElment.style.backgroundColor = sHolidayColor;
		oHiddenControl.value = sHolidayColor;
		UpDateSelect(sSelectId, sHolidayColor)
	}
	catch(err)
	{
		var sMessage = err.message;
		if(sMessage == "Invalid property value.")
		{
			sMessage = "Invalid color code for holiday."
		}
		alert("UpDateColorFromTextBox Error:: " + sMessage );
	} 
	
}


/////Gantt View
function Bamboo_ExpCollGroup1(groupName, imgName, resPath)
{
	try
	{	
		if (browseris.nav)
			return;
		viewTable = document.getElementById("Main"+groupName).parentNode;
		tbodyTags = viewTable.getElementsByTagName("TBODY");
		numElts = tbodyTags.length;
		len = groupName.length;
		img = document.getElementById(imgName);
		srcPath = img.src;
		index = srcPath.lastIndexOf("/");
		imgName = srcPath.slice(index+1);
		if (imgName =='plus.gif')
		{
			fOpen = true;			
			displayStr = "";
			img.src = resPath + '/minus.gif';
		}
		else
		{
			fOpen = false;				
			displayStr = "none";
			img.src = resPath + '/plus.gif';
		}
		for(var i=0;i<numElts;i++)
		{    
			var childObj = tbodyTags[i];               
			if ( (childObj.id != null)                   
                    &&(childObj.id.indexOf("tbod" + groupName) != -1))
			{			
			   childObj.style.display = "none";            																						
			}
			
			if ( (childObj.id !=null)                   
                    &&(childObj.id.indexOf("titl" + groupName) != -1) )
			{			
				childObj.style.display = displayStr; 		
				if (fOpen)
				{
				    imgTags = childObj.getElementsByTagName("img");  
					imgObj = imgTags[0];
					imgObj.src = resPath + '/plus.gif';					    					    
				}
			}
		}
    }
    catch(err)
	{
		alert("Bamboo_ExpCollGroup1 Error:: " + err.message );
	}
}

function Bamboo_ExpCollGroup2(group1,group2, imgName, resPath)
{
	try
	{	
		if (browseris.nav)
			return;  
		var groupName = group1 + group2;
		viewTable = document.getElementById("titl"+groupName).parentNode;
		tbodyTags = viewTable.getElementsByTagName("TBODY");
		numElts = tbodyTags.length;
		len = groupName.length;
		img = document.getElementById(imgName);
		srcPath = img.src;
		index = srcPath.lastIndexOf("/");
		imgName = srcPath.slice(index+1);
		if (imgName =='plus.gif')
		{
			fOpen = true;
			displayStr = "";
			img.src = resPath + '/minus.gif';
		}
		else
		{
			fOpen = false;
			displayStr = "none";
			img.src = resPath + '/plus.gif';
		}
		for(var i=0;i<numElts;i++)
		{    
			var childObj = tbodyTags[i];               
			if ( (childObj.id !=null)                   
                    && ("tbod" + groupName == childObj.id) )
			{			
				childObj.style.display = displayStr;            
				if (fOpen && childObj.id.substr(0,4) == "titl")
				{
					imgObj = document.getElementById("img_" + groupName);
					imgObj.src = resPath + '/plus.gif';
				}
			}
		}
    }
    catch(err)
	{
		alert("Bamboo_ExpCollGroup2 Error:: " + err.message );
	}
}

function Bamboo_GanttView_UpDateHolidayColorFromTextBox(sTextBoxId, sHiddenControlId, sSelectId)//, sDivId)
{
	try
	{
		var oTextBoxElment =  document.getElementById(sTextBoxId);
		var oHiddenControl =  document.getElementById(sHiddenControlId);
		//var oDivElment =  document.getElementById(sDivId);
		var sHolidayColor = oTextBoxElment.value;
		//oDivElment.style.backgroundColor = sHolidayColor;
		oHiddenControl.value = sHolidayColor;
		Bamboo_GanttView_UpDateSelect(sSelectId, sHolidayColor)
	}
	catch(err)
	{
		var sMessage = err.message;
		if(sMessage == "Invalid property value.")
		{
			sMessage = "Invalid color code for holiday."
		}
		alert("UpDateColorFromTextBox Error:: " + sMessage );
	} 
}

function Bamboo_GanttView_UpDateSelect(sSelectId, sHexColor)
{
	try
	{
		var bFlag = true;
		var oSelectElement =  document.getElementById(sSelectId);
		var oColorCollection = oSelectElement.options;
		var intCollectionLength = oColorCollection.length;
		for(i=0; i < intCollectionLength; i++)
		{
			if(oColorCollection[i].selected = true && oColorCollection[i].value != sHexColor)
				oColorCollection[i].selected = false;
			
			if(oColorCollection[i].value == sHexColor)
			{
				oColorCollection[i].selected = true;
				bFlag = false;
				break;	
			}
		}
		if(bFlag)
		{
			var oLastOption = oColorCollection[intCollectionLength-1];
			oLastOption.selected = true;
		}
	}
	catch(err)
	{
		alert("UpDateSelect Error:: " + err.message );
	} 
	
}

function Bamboo_GanttView_UpDateHolidayColor(sHiddenControlId)
{
	try
	{
		var oSelectElement =  event.srcElement;		
		var sHexColor = oSelectElement.options[oSelectElement.selectedIndex].value;		
		var oHiddenControl =  document.getElementById(sHiddenControlId);
		oHiddenControl.value = sHexColor;		
	}
	catch(err)
	{
		alert("Bamboo_GanttView_UpDateHolidayColor Error:: " + err.message );
	} 
}
//end Gantt View








//region Ajax
//for ajax ================================

function utf8(wide) {
  var c, s;
  var enc = "";
  var i = 0;
  while(i<wide.length) {
    c= wide.charCodeAt(i++);
    // handle UTF-16 surrogates
    if (c>=0xDC00 && c<0xE000) continue;
    if (c>=0xD800 && c<0xDC00) {
      if (i>=wide.length) continue;
      s= wide.charCodeAt(i++);
      if (s<0xDC00 || c>=0xDE00) continue;
      c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
    }
    // output value
    if (c<0x80) enc += String.fromCharCode(c);
    else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
    else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
    else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
  }
  return enc;
}

var hexchars = "0123456789ABCDEF";

function toHex(n) {
  return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
}

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

function encodeURIComponentNew(s) {
  var s = utf8(s);
  var c;
  var enc = "";
  for (var i= 0; i<s.length; i++) {
    if (okURIchars.indexOf(s.charAt(i))==-1)
      enc += "%"+toHex(s.charCodeAt(i));
    else
      enc += s.charAt(i);
  }
  return enc;
}

function Bamboo_Encode(s){
	if (typeof encodeURIComponent == "function") {
		// Use JavaScript built-in function
		// IE 5.5+ and Netscape 6+ and Mozilla
		return encodeURIComponent(s);
	} else {
		// Need to mimic the JavaScript version
		// Netscape 4 and IE 4 and IE 5.0
		return encodeURIComponentNew(s);
	}
}

function Bamboo_AddEvent(obj, evType, fn, useCapture) {
	if (obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent) {
		var r = obj.attachEvent("on" + evType, fn);
		return r;
	} else {
		alert("Bamboo_AddEvent could not add event!");
	}
}

function Bamboo_GetXMLHttpRequest() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	} else {
		if (window.Bamboo_XMLHttpRequestProgID) {
			return new ActiveXObject(window.Bamboo_XMLHttpRequestProgID);
		} else {
			var progIDs = ["Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
			for (var i = 0; i < progIDs.length; ++i) {
				var progID = progIDs[i];
				try {
					var x = new ActiveXObject(progID);
					window.Bamboo_XMLHttpRequestProgID = progID;
					return x;
				} catch (e) {
				}
			}
		}
	}
	return null;
}

function Bamboo_CallBack(url, target, id, method, args, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack) {
    
	if (window.Bamboo_PreCallBack) {
		var preCallBackResult = Bamboo_PreCallBack();
		if (!(typeof preCallBackResult == "undefined" || preCallBackResult)) {
			if (window.Bamboo_CallBackCancelled) {
				Bamboo_CallBackCancelled();
			}
			return null;
		}
	}
	var x = Bamboo_GetXMLHttpRequest();
	var result = null;
	if (!x) {
		result = { "value": null, "error": "NOXMLHTTP" };
		Bamboo_DebugError(result.error);
		if (window.Bamboo_Error) {
			Bamboo_Error(result);
		}
		if (clientCallBack) {
			clientCallBack(result, clientCallBackArg);
		}
		return result;
	}
	x.open("POST", url ? url : Bamboo_DefaultURL, clientCallBack ? true : false);
	x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
	x.setRequestHeader("Accept-Encoding", "gzip, deflate");
	if (clientCallBack) {
		x.onreadystatechange = function() {
			if (x.readyState != 4) {
				return;
			}
			Bamboo_DebugResponseText(x.responseText);
			result = Bamboo_GetResult(x);
			if (result.error) {
				Bamboo_DebugError(result.error);
				if (window.Bamboo_Error) {
					Bamboo_Error(result);
				}
			}
			if (updatePageAfterCallBack) {
				Bamboo_UpdatePage(result);
			}
			Bamboo_EvalClientSideScript(result);
			clientCallBack(result, clientCallBackArg);
			x = null;
			if (window.Bamboo_PostCallBack) {
				Bamboo_PostCallBack();
			}
		}
	}
    var encodedData = "";
    if (target == "Page") {
        encodedData += "&Bamboo_PageMethod=" + method;
    } else if (target == "MasterPage") {
        encodedData += "&Bamboo_MasterPageMethod=" + method;
    } else if (target == "Control") {
        encodedData += "&Bamboo_ControlID=" + id.split(":").join("_");
        encodedData += "&Bamboo_ControlMethod=" + method;
    }
	if (args) {
		for (var argsIndex = 0; argsIndex < args.length; ++argsIndex) {
			if (args[argsIndex] instanceof Array) {
				for (var i = 0; i < args[argsIndex].length; ++i) {
					encodedData += "&Bamboo_CallBackArgument" + argsIndex + "=" + Bamboo_Encode(args[argsIndex][i]);
				}
			} else {
				encodedData += "&Bamboo_CallBackArgument" + argsIndex + "=" + Bamboo_Encode(args[argsIndex]);
			}
		}
	}
	if (updatePageAfterCallBack) {
		encodedData += "&Bamboo_UpdatePage=true";
	}
	if (includeControlValuesWithCallBack) {
		var form = document.getElementById(Bamboo_FormID);
		if (form != null) {
			for (var elementIndex = 0; elementIndex < form.length; ++elementIndex) {
				var element = form.elements[elementIndex];
				if (element.name) {
					var elementValue = null;
					if (element.nodeName.toUpperCase() == "INPUT") {
						var inputType = element.getAttribute("type").toUpperCase();
						if (inputType == "TEXT" || inputType == "PASSWORD" || inputType == "HIDDEN") {
							elementValue = element.value;
						} else if (inputType == "CHECKBOX" || inputType == "RADIO") {
							if (element.checked) {
								elementValue = element.value;
							}
						}
					} else if (element.nodeName.toUpperCase() == "SELECT") {
						if (element.multiple) {
							elementValue = [];
							for (var i = 0; i < element.length; ++i) {
								if (element.options[i].selected) {
									elementValue.push(element.options[i].value);
								}
							}
						} else if (element.length == 0) {
						    elementValue = null;
						} else {
							elementValue = element.value;
						}
					} else if (element.nodeName.toUpperCase() == "TEXTAREA") {
						elementValue = element.value;
					}
					if (elementValue instanceof Array) {
						for (var i = 0; i < elementValue.length; ++i) {
							encodedData += "&" + element.name + "=" + Bamboo_Encode(elementValue[i]);
						}
					} else if (elementValue != null) {
						encodedData += "&" + element.name + "=" + Bamboo_Encode(elementValue);
					}
				}
			}
			// ASP.NET 1.1 won't fire any events if neither of the following
			// two parameters are not in the request so make sure they're
			// always in the request.
			if (typeof form.__VIEWSTATE == "undefined") {
				encodedData += "&__VIEWSTATE=";
			}
			if (typeof form.__EVENTTARGET == "undefined") {
				encodedData += "&__EVENTTARGET=";
			}
		}
	}
	Bamboo_DebugRequestText(encodedData.split("&").join("\n&"));
	x.send(encodedData);
	if (!clientCallBack) {
		Bamboo_DebugResponseText(x.responseText);
		result = Bamboo_GetResult(x);
		if (result.error) {
			Bamboo_DebugError(result.error);
			if (window.Bamboo_Error) {
				Bamboo_Error(result);
			}
		}
		if (updatePageAfterCallBack) {
			Bamboo_UpdatePage(result);
		}
		Bamboo_EvalClientSideScript(result);
		if (window.Bamboo_PostCallBack) {
			Bamboo_PostCallBack();
		}
	}
	return result;
}

function Bamboo_GetResult(x) {
	var result = { "value": null, "error": null };
	var responseText = x.responseText;
	try {
		result = eval("(" + responseText + ")");
	} catch (e) {
		if (responseText.length == 0) {
			result.error = "NORESPONSE";
		} else {
			result.error = "BADRESPONSE";
			result.responseText = responseText;
		}
	}
	return result;
}

function Bamboo_SetHiddenInputValue(form, name, value) {
    var input = null;
    if (form[name]) {
        input = form[name];
    } else {
        input = document.createElement("input");
        input.setAttribute("name", name);
        input.setAttribute("type", "hidden");
    }
    input.setAttribute("value", value);
    var parentElement = input.parentElement ? input.parentElement : input.parentNode;
    if (parentElement == null) {
        form.appendChild(input);
        form[name] = input;
    }
}

function Bamboo_RemoveHiddenInput(form, name) {
    var input = form[name];
    var parentElement = input.parentElement ? input.parentElement : input.parentNode;
    if (input && parentElement == form) {
        form[name] = null;
        form.removeChild(input);
    }
}

function Bamboo_FireEvent(eventTarget, eventArgument, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack) {
	var form = document.getElementById(Bamboo_FormID);
	Bamboo_SetHiddenInputValue(form, "__EVENTTARGET", eventTarget);
	Bamboo_SetHiddenInputValue(form, "__EVENTARGUMENT", eventArgument);
	Bamboo_CallBack(null, null, null, null, null, clientCallBack, clientCallBackArg, includeControlValuesWithCallBack, updatePageAfterCallBack);
	form.__EVENTTARGET.value = "";
	form.__EVENTARGUMENT.value = "";
}

function Bamboo_UpdatePage(result) {
	var form = document.getElementById(Bamboo_FormID);
	if (result.viewState) {
		Bamboo_SetHiddenInputValue(form, "__VIEWSTATE", result.viewState);
	}
	if (result.viewStateEncrypted) {
		Bamboo_SetHiddenInputValue(form, "__VIEWSTATEENCRYPTED", result.viewStateEncrypted);
	}
	if (result.eventValidation) {
		Bamboo_SetHiddenInputValue(form, "__EVENTVALIDATION", result.eventValidation);
	}
	if (result.controls) {
		for (var controlID in result.controls) {
			var containerID = "Bamboo_" + controlID.split("$").join("_") + "__";
			var control = document.getElementById(containerID);
			if (control) {
				control.innerHTML = result.controls[controlID];
				if (result.controls[controlID] == "") {
					control.style.display = "none";
				} else {
					control.style.display = "block";
				}
			}
		}
	}
	if (result.pagescript) {
	    Bamboo_LoadPageScript(result, 0);
	}
}

// Load each script in order and wait for each one to load before proceeding
function Bamboo_LoadPageScript(result, index) {
    if (index < result.pagescript.length) {
		try {
		    var script = document.createElement('script');
		    script.type = 'text/javascript';
		    if (result.pagescript[index].indexOf('src=') == 0) {
		        script.src = result.pagescript[index].substring(4);
		    } else {
		        if (script.canHaveChildren ) {
		            script.appendChild(document.createTextNode(result.pagescript[index]));
		        } else {
		            script.text = result.pagescript[index];
		        }
		    }
	        document.getElementsByTagName('head')[0].appendChild(script);
	        if (typeof script.readyState != "undefined") {
	            script.onreadystatechange = function() {
	                if (script.readyState != "complete" && script.readyState != "loaded") {
	                    return;
	                } else {
	                    Bamboo_LoadPageScript(result, index + 1);
	                }
	            }
	        } else {
                Bamboo_LoadPageScript(result, index + 1);
	        }
		} catch (e) {
		    Bamboo_DebugError("Error adding page script to head. " + e.name + ": " + e.message);
		}
	}
}

function Bamboo_EvalClientSideScript(result) {
	if (result.script) {
		for (var i = 0; i < result.script.length; ++i) {
			try {
				eval(result.script[i]);
			} catch (e) {
				alert("Error evaluating client-side script!\n\nScript: " + result.script[i] + "\n\nException: " + e);
			}
		}
	}
}

function Bamboo_DebugRequestText(text) {
}

function Bamboo_DebugResponseText(text) {
}

function Bamboo_DebugError(text) {
}

//Fix for bug #1429412, "Reponse callback returns previous response after file push".
//see http://sourceforge.net/tracker/index.php?func=detail&aid=1429412&group_id=151897&atid=782464
function Bamboo_Clear__EVENTTARGET() {
	var form = document.getElementById(Bamboo_FormID);
	Bamboo_SetHiddenInputValue(form, "__EVENTTARGET", "");
}

function Bamboo_InvokePageMethod(methodName, args, clientCallBack, clientCallBackArg) {
	Bamboo_Clear__EVENTTARGET(); // fix for bug #1429412
    return Bamboo_CallBack(null, "Page", null, methodName, args, clientCallBack, clientCallBackArg, true, true);
}

function Bamboo_InvokeMasterPageMethod(methodName, args, clientCallBack, clientCallBackArg) {
	Bamboo_Clear__EVENTTARGET(); // fix for bug #1429412
    return Bamboo_CallBack(null, "MasterPage", null, methodName, args, clientCallBack, clientCallBackArg, true, true);
}

function Bamboo_InvokeControlMethod(id, methodName, args, clientCallBack, clientCallBackArg) {
	Bamboo_Clear__EVENTTARGET(); // fix for bug #1429412
    return Bamboo_CallBack(null, "Control", id, methodName, args, clientCallBack, clientCallBackArg, true, true);
}

function Bamboo_PreProcessCallBack(
    control,
    e,
    eventTarget,
    causesValidation, 
    validationGroup, 
    imageUrlDuringCallBack, 
    textDuringCallBack, 
    enabledDuringCallBack,
    preCallBackFunction,
    callBackCancelledFunction,
    preProcessOut
) {
	preProcessOut.Enabled = !control.disabled;
	var preCallBackResult = true;
	if (preCallBackFunction) {
		preCallBackResult = preCallBackFunction(control);
	}
	if (typeof preCallBackResult == "undefined" || preCallBackResult) {
		var valid = true;
		if (causesValidation && typeof Page_ClientValidate == "function") {
			valid = Page_ClientValidate(validationGroup);
		}
		if (valid) {
			var inputType = control.getAttribute("type");
			inputType = (inputType == null) ? '' : inputType.toUpperCase();
			if (inputType == "IMAGE" && e != null) {
                var form = document.getElementById(Bamboo_FormID);
                if (e.offsetX) {
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".x", e.offsetX);
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".y", e.offsetY);
                } else {
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".x", e.clientX - control.offsetLeft + 1);
                    Bamboo_SetHiddenInputValue(form, eventTarget + ".y", e.clientY - control.offsetTop + 1);
                }
			}
			preProcessOut.OriginalText = control.innerHTML;
			if (imageUrlDuringCallBack || textDuringCallBack) {
			    if (control.nodeName.toUpperCase() == "INPUT") {
			        if (inputType == "CHECKBOX" || inputType == "RADIO" || inputType == "TEXT") {
			            preProcessOut.OriginalText = GetLabelText(control.id);
			            SetLabelText(control.id, textDuringCallBack);
			        } else if (inputType == "IMAGE") {
			            if (imageUrlDuringCallBack) {
			                preProcessOut.OriginalText = control.src;
			                control.src = imageUrlDuringCallBack;
			            } else {
			                preProcessOut.ParentElement = control.parentElement ? control.parentElement : control.parentNode;
			                if (preProcessOut.ParentElement) {
			                    preProcessOut.OriginalText = preProcessOut.ParentElement.innerHTML;
			                    preProcessOut.ParentElement.innerHTML = textDuringCallBack;
			                }
			            }
			        } else if (inputType == "SUBMIT") {
			            preProcessOut.OriginalText = control.value;
			            control.value = textDuringCallBack;
			        }
			    } else if (control.nodeName.toUpperCase() == "SELECT") {
			        preProcessOut.OriginalText = GetLabelText(control.id);
			        SetLabelText(control.id, textDuringCallBack);
			    } else {
				    control.innerHTML = textDuringCallBack;
				}
			}
			control.disabled = (typeof enabledDuringCallBack == "undefined") ? false : !enabledDuringCallBack;
			return true;
        } else {
            return false;
        }
	} else {
	    if (callBackCancelledFunction) {
		    callBackCancelledFunction(control);
		}
		return false;
	}
}

function Bamboo_PreProcessCallBackOut() {
    // Fields
    this.ParentElement = null;
    this.OriginalText = '';
    this.Enabled = true;
}

function Bamboo_PostProcessCallBack(
    result, 
    control,
    eventTarget, 
    clientCallBack, 
    clientCallBackArg, 
    imageUrlDuringCallBack, 
    textDuringCallBack, 
    postCallBackFunction, 
    preProcessOut
) {
    if (postCallBackFunction) {
        postCallBackFunction(control);
    }
	control.disabled = !preProcessOut.Enabled;
    var inputType = control.getAttribute("type");
    inputType = (inputType == null) ? '' : inputType.toUpperCase();
	if (inputType == "IMAGE") {
	    var form = document.getElementById(Bamboo_FormID);
        Bamboo_RemoveHiddenInput(form, eventTarget + ".x");
        Bamboo_RemoveHiddenInput(form, eventTarget + ".y");
	}
	if (imageUrlDuringCallBack || textDuringCallBack) {
	    if (control.nodeName.toUpperCase() == "INPUT") {
	        if (inputType == "CHECKBOX" || inputType == "RADIO" || inputType == "TEXT") {
	            SetLabelText(control.id, preProcessOut.OriginalText);
	        } else if (inputType == "IMAGE") {
	            if (imageUrlDuringCallBack) {
	                control.src = preProcessOut.OriginalText;
	            } else {
	                preProcessOut.ParentElement.innerHTML = preProcessOut.OriginalText;
	            }
	        } else if (inputType == "SUBMIT") {
	            control.value = preProcessOut.OriginalText;
	        }
	    } else if (control.nodeName.toUpperCase() == "SELECT") {
	        SetLabelText(control.id, preProcessOut.OriginalText);
	    } else {
	        control.innerHTML = preProcessOut.OriginalText;
	    }
	}
	if (clientCallBack) {
	    clientCallBack(result, clientCallBackArg);
	}
}

function Bamboo_FireCallBackEvent(
	control,
	e,
	eventTarget,
	eventArgument,
	causesValidation,
	validationGroup,
	imageUrlDuringCallBack,
	textDuringCallBack,
	enabledDuringCallBack,
	preCallBackFunction,
	postCallBackFunction,
	callBackCancelledFunction,
	includeControlValuesWithCallBack,
	updatePageAfterCallBack
) {
// if (control.type == "radio") {
//     Bamboo_GetValueControl(control.id);
//     }
	var preProcessOut = new Bamboo_PreProcessCallBackOut();
	var preProcessResult = Bamboo_PreProcessCallBack(
	    control, 
	    e, 
	    eventTarget,
	    causesValidation, 
	    validationGroup, 
	    imageUrlDuringCallBack, 
	    textDuringCallBack, 
	    enabledDuringCallBack, 
	    preCallBackFunction, 
	    callBackCancelledFunction, 
	    preProcessOut
	);
    if (preProcessResult) {
	    Bamboo_FireEvent(
		    eventTarget,
		    eventArgument,
		    function(result) {
                Bamboo_PostProcessCallBack(
                    result, 
                    control, 
                    eventTarget,
                    null, 
                    null, 
                    imageUrlDuringCallBack, 
                    textDuringCallBack, 
                    postCallBackFunction, 
                    preProcessOut
                );
		    },
		    null,
		    includeControlValuesWithCallBack,
		    updatePageAfterCallBack
	    );
    }
}

function BambooListControl_OnClick(
    e,
	causesValidation,
	validationGroup,
	textDuringCallBack,
	enabledDuringCallBack,
	preCallBackFunction,
	postCallBackFunction,
	callBackCancelledFunction,
	includeControlValuesWithCallBack,
	updatePageAfterCallBack
) {
	var target = e.target || e.srcElement;
	if (target.nodeName.toUpperCase() == "LABEL" && target.htmlFor != '')
	    return;
	var eventTarget = target.id.split("_").join("$");
	Bamboo_FireCallBackEvent(
	    target, 
	    e,
	    eventTarget, 
	    '', 
	    causesValidation, 
	    validationGroup, 
	    '',
	    textDuringCallBack, 
	    enabledDuringCallBack, 
	    preCallBackFunction, 
	    postCallBackFunction, 
	    callBackCancelledFunction, 
	    true, 
	    true
	);
}

function GetLabelText(id) {
    var labels = document.getElementsByTagName('label');
    for (var i = 0; i < labels.length; i++) {
        if (labels[i].htmlFor == id) {
            return labels[i].innerHTML;
        }
    }
    return null;
}

function SetLabelText(id, text) {
    var labels = document.getElementsByTagName('label');
    for (var i = 0; i < labels.length; i++) {
        if (labels[i].htmlFor == id) {
            labels[i].innerHTML = text;
            return;
        }
    }
}

function Bamboo_SetCursor()
{
	document.body.style.cursor="wait";	
}
function Bamboo_RemoveCursor()
{
	document.body.style.cursor = "auto";	
}
//end Ajax

//-------------- start New Calendar --------------------------------------
// _lcid="1033" _version="12.0.4017"
// _localBinding
// Version: "12.0.4017"
// Copyright (c) Microsoft Corporation.  All rights reserved.
var UTF8_1ST_OF_2=0xc0   ;
var UTF8_1ST_OF_3=0xe0   ;
var UTF8_1ST_OF_4=0xf0   ;
var UTF8_TRAIL=0x80   ;
var HIGH_SURROGATE_BITS=0xD800 ;
var LOW_SURROGATE_BITS=0xDC00 ;
var SURROGATE_6_BIT=0xFC00 ;
var SURROGATE_ID_BITS=0xF800 ;
var SURROGATE_OFFSET=0x10000;
function escapeProperlyCoreCore(str, bAsUrl, bForFilterQuery, bForCallback)
{
	var strOut="";
	var strByte="";
	var ix=0;
	var strEscaped=" \"%<>\'&";
	for (ix=0; ix < str.length; ix++)
	{
		var charCode=str.charCodeAt(ix);
		var curChar=str.charAt(ix);
		if(bAsUrl && (curChar=='#' || curChar=='?') )
		{
			strOut+=str.substr(ix);
			break;
		}
		if (bForFilterQuery && curChar=='&')
		{
			strOut+=curChar;
			continue;
		}
		if (charCode <=0x7f)
		{
			if (bForCallback)
			{
				strOut+=curChar;
			}
			else
			{
				if ( (charCode >=97 && charCode <=122) ||
					 (charCode >=65 && charCode <=90) ||
					 (charCode >=48 && charCode <=57) ||
					 (bAsUrl && (charCode >=32 && charCode <=95) && strEscaped.indexOf(curChar) < 0))
				{
					strOut+=curChar;
				}
				else if (charCode <=0x0f)
				{
					strOut+="%0"+charCode.toString(16).toUpperCase();
				}
				else if (charCode <=0x7f)
				{
					strOut+="%"+charCode.toString(16).toUpperCase();
				}
			}
		}
		else if (charCode <=0x07ff)
		{
			strByte=UTF8_1ST_OF_2 | (charCode >> 6);
			strOut+="%"+strByte.toString(16).toUpperCase() ;
			strByte=UTF8_TRAIL | (charCode & 0x003f);
			strOut+="%"+strByte.toString(16).toUpperCase();
		}
		else if ((charCode & SURROGATE_6_BIT) !=HIGH_SURROGATE_BITS)
		{
			strByte=UTF8_1ST_OF_3 | (charCode >> 12);
			strOut+="%"+strByte.toString(16).toUpperCase();
			strByte=UTF8_TRAIL | ((charCode & 0x0fc0) >> 6);
			strOut+="%"+strByte.toString(16).toUpperCase();
			strByte=UTF8_TRAIL | (charCode & 0x003f);
			strOut+="%"+strByte.toString(16).toUpperCase();
		}
		else if (ix < str.length - 1)
		{
			var charCode=(charCode & 0x03FF) << 10;
			ix++;
			var nextCharCode=str.charCodeAt(ix);
			charCode |=nextCharCode & 0x03FF;
			charCode+=SURROGATE_OFFSET;
			strByte=UTF8_1ST_OF_4 | (charCode >> 18);
			strOut+="%"+strByte.toString(16).toUpperCase();
			strByte=UTF8_TRAIL | ((charCode & 0x3f000) >> 12);
			strOut+="%"+strByte.toString(16).toUpperCase();
			strByte=UTF8_TRAIL | ((charCode & 0x0fc0) >> 6);
			strOut+="%"+strByte.toString(16).toUpperCase();
			strByte=UTF8_TRAIL | (charCode & 0x003f);
			strOut+="%"+strByte.toString(16).toUpperCase();
		}
	}
	return strOut;
}
function escapeProperly(str)
{
	return escapeProperlyCoreCore(str, false, false, false);
}
function escapeProperlyCore(str, bAsUrl)
{
	return escapeProperlyCoreCore(str, bAsUrl, false, false);
}
function escapeUrlForCallback(str)
{
	var iPound=str.indexOf("#");
	var iQues=str.indexOf("?");
	if ((iPound > 0) && ((iQues==-1) || (iPound < iQues)))
	{
		var strNew=str.substr(0, iPound);
		if (iQues > 0)
		{
			strNew+=str.substr(iQues);
		}
		str=strNew;
	}
	return escapeProperlyCoreCore(str, true, false, true);
}
function PageUrlValidation(url)
{
	if (url.substr(0, 4) !="http" && url.substr(0,1) !="/")
	{
		var L_InvalidPageUrl_Text="Invalid page URL: ";
		alert(L_InvalidPageUrl_Text+url);
		return "";
	}
	else
		return url;
}
var g_currentID;
var g_strDatePickerFrameID="DatePickerFrame";
var g_strDatePickerImageID="DatePickerImage";
var g_strDatePickerRangeValidatorID="DatePickerRangeValidator";
var g_warnonce=1;
var g_scrollLeft;
var g_scrollTop;
function WindowPosition(elt)
{
	var pos=new Object;
	pos.x=0;
	pos.y=0;
	while (elt.offsetParent !=null && elt.id.search('WebPart') !=0
		&& !(elt.tagName=="DIV" && (elt.style.overflow=="auto" ||
		elt.style.overflowX=="auto" || elt.style.overflowY=="auto")))
	{
		pos.x+=elt.offsetLeft -elt.scrollLeft;
		pos.y+=elt.offsetTop -elt.scrollTop;
		elt=elt.offsetParent;
	}
	return pos;
}
function getDate(field,serverDate)
{
	if (field.value !=null)
		return field.value;
	else
		return serverDate;
}
function HLD(elt)
{
	HL(elt,"ms-dphighlightedday");
}
function HLM(elt)
{
	HL(elt,"ms-dphighlightedmonth");
}
function HL(elt,classname)
{
	if (elt.classSave !=null)
	{
		elt.className=elt.classSave;
		elt.classSave=null;
	}
	else
	{
		elt.classSave=elt.className;
		elt.className=classname;
	}
}
function PositionFrame(thediv)
{
	var elt=document.getElementById(thediv);
	var ifrm=document.parentWindow.frameElement;
	if (ifrm==null)
		return;
	if (!this.bDidAlign)
	{
		this.bDidAlign=true;
		ifrm.style.pixelWidth=elt.offsetWidth - 100;
		ifrm.style.pixelWidth=elt.offsetWidth - 100;
	}
	ifrm.style.pixelWidth=elt.offsetWidth;
	ifrm.style.pixelHeight=elt.offsetHeight;
	if (ifrm.currentStyle.direction=="rtl")
	{
		var cxBody=document.parentWindow.parent.document.body.offsetWidth+document.parentWindow.parent.document.body.scrollLeft;
		ifrm.style.pixelRight=cxBody - ifrm.style.pixelRight;
		ifrm.style.pixelLeft=ifrm.style.pixelRight - elt.offsetWidth;
	}
	else
	{
		ifrm.style.pixelLeft=ifrm.style.pixelRight - elt.offsetWidth;
		if (ifrm.style.pixelLeft < 0)
		{
			ifrm.style.pixelLeft=ifrm.style.pixelRight;
			ifrm.style.pixelRight+=elt.offsetWidth;
		}
	}
	return;
}
function HideUnhide(nhide,nunhide, id)
{
	var eltHide=document.getElementById(nhide);
	if (eltHide !=null)
		eltHide.style.display="none";
	var eltUnhide=document.getElementById(nunhide);
	if (eltUnhide !=null)
		eltUnhide.style.display="block";
	PositionFrame(nunhide);
	g_currentID=id;
}
function datereplace(ourl,pattern,newstr)
{
  var str=new String(ourl);
  var res=str.indexOf(pattern);
  if (res !=-1)
  {
	 var resString=str.substring(0,res);
  	 resString+=newstr;
	 var resapp=str.indexOf("&",res);
	 if (resapp !=-1)
	 {
		resString+=str.substr(resapp+1);
	 }		
	return resString;
  }
  else
  {
	var q=str.indexOf("?");
	if (q==-1) str+="?";
	if (str.charAt(str.length-1) !='&') str+="&";
	str+=newstr;
	return str;
  }
}
function MoveToDate(dt)
{
  var ourl=document.location.href;
  var pattern="date=";
  ourl=datereplace(ourl,pattern,"date="+escapeProperly(dt)+"&");
  document.location=ourl;
  return true;
}
function OnKeyDown(elem)
{
	var evtSource=elem.document.parentWindow.event;
	var nKeyCode=evtSource.keyCode;
	switch (nKeyCode)
		{
	case 27:
		evtSource.returnValue=false;
		ClosePicker();
		break;
	case 38:
		evtSource.returnValue=false;
		MoveDays(-7);
		break;
	case 40:
		evtSource.returnValue=false;
		MoveDays(7);
		break;
	case 37:
		evtSource.returnValue=false;
		MoveDays(-1);
		break;
	case 39:
		evtSource.returnValue=false;
		MoveDays(1);
		break;
		}
}
function ClosePicker()
{
	var ifrm=document.parentWindow.frameElement;
	if (ifrm==null)
	{
		return;
	}
	ifrm.resultfunc();
	ifrm.style.display="none";
	ifrm=null;
}
function MoveDays(iday)
{
	var stNextID;
	if (g_currentID==null || g_currentID.length < 6)
		return;
	var yr=g_currentID.substr(0, 4) - 0;
	var mon=g_currentID.substr(4, 2) - 0;
	var day=g_currentID.substr(6, 2) - 0;
	if (day+iday < 1)
	{
		return;
	}
	else
	{
		stNextID=g_currentID.substr(0, 6)+St2Digits(day+iday);
		var elm=document.getElementById(stNextID);
		if (elm==null)
			return;
		g_currentID=stNextID;
		elm.focus();
	}
}
function St2Digits(w)
{
	var st="";
	if (w < 0)
		return st;
	if (w < 10)
		st+="0";
	st+=w;
	return st;
}
function clickBambooCalendarPlusDatePicker(field, imageID, frameID, src, datestr)
{
    var date;
    var objField=document.getElementById(field);  
    var fieldid;
    if (event !=null)
    event.cancelBubble=true;
    if(field==null && this.Picker !=null)
    {
        this.Picker.style.display="none";
        this.Picker=null;
    }
    else if (objField !=null)
    {
        var fieldelm=document.getElementById(field);
        if(fieldelm !=null && fieldelm.isDisabled)
        return;
        date=getDate(objField, datestr);
        fieldid=objField.id;  
        var objDatePickerImage = document.getElementById(imageID);
        clickDatePickerHelper(fieldid, frameID, objDatePickerImage, date, src, OnSelectDate, OnPickerFinish);
        document.body.onclick=OnPickerFinish;
    }
}
function clickDatePickerHelper(textboxid, iframeid, objImage, datestr, iframesrc, OnSelectDateCallback, onpickerfinishcallback)
{
	var strCurrentResultFieldId="";
	if (this.Picker !=null)
	{
		this.Picker.style.display="none";
		strCurrentResultFieldId=this.Picker.resultfield.id;
		if (this.Picker.resultfunc !=null)
		{
			this.Picker.resultfunc();
		}
		this.Picker=null;
	}
	if (strCurrentResultFieldId==textboxid)
	{
		return;
	}
	if (textboxid !=null)
	{
		this.Picker=document.getElementById(iframeid);
 		if (this.Picker==null)
 			return;
		g_scrollLeft=document.body.scrollLeft;
		g_scrollTop=document.body.scrollTop;
		this.Picker.attachEvent("onreadystatechange", OnIframeLoadFinish);
 		this.Picker.resultfield=document.getElementById(textboxid);
 		this.Picker.OnSelectDateCallback=OnSelectDateCallback;
 		this.Picker.resultfunc=onpickerfinishcallback;
 		var strNewPickerSrc=PageUrlValidation(iframesrc)+escapeProperly(datestr);
		if (L_Language_Text !=null && L_Language_Text !="undefined")
			strNewPickerSrc=strNewPickerSrc+"&langid="+L_Language_Text;
		this.Picker.src=strNewPickerSrc;
		var pos=WindowPosition(objImage);
		this.Picker.style.pixelTop=pos.y+objImage.offsetHeight+1;
		this.Picker.style.pixelRight=pos.x+objImage.offsetWidth+1;
	}
}
function ClickDay(date)
{
	var ifrm=document.parentWindow.frameElement;
	if (ifrm==null)
	{
		return MoveToDate(date);
	}
	var eltValidator=document.parentWindow.parent.document.all(ifrm.resultfield.id+g_strDatePickerRangeValidatorID);
	if (eltValidator !=null)
	{
		eltValidator.style.display="none";
	}
	var OnSelectDateCallback=ifrm.OnSelectDateCallback;
	OnSelectDateCallback(ifrm.resultfield, date);
	var resultfunc=ifrm.resultfunc;
	resultfunc(ifrm.resultfield);
	return true;
}
function OnPickerFinish(resultfield)
{
    clickBambooCalendarPlusDatePicker(null, "", "");
}
function OnSelectDate(resultfield, date)
{
	var autoPostBack=resultfield.attributes.getNamedItem("AutoPostBack");
	var shouldPostBack=(autoPostBack!=null && autoPostBack.value=="1" && resultfield.value !=date);
	var shouldNotifyChange=(resultfield.value !=date);
	resultfield.value=date;
	if ( (shouldNotifyChange) && (resultfield.onvaluesetfrompicker) && (!shouldPostBack))
	{
		if (typeof(resultfield.onvaluesetfrompicker)=='function')
		{
			resultfield.onvaluesetfrompicker();
		}
		else
		{
			eval(resultfield.onvaluesetfrompicker);
		}
	}
	if (shouldPostBack) window.setTimeout("__doPostBack('"+resultfield.id+"','')",0);
}
function ChangeDateTimeControlState(id, disable)
{
	var elmDate=document.getElementById(g_strDateTimeControlIDs[id]);
	if (elmDate !=null)
		elmDate.disabled=disable;
	var elmHours=document.getElementById(g_strDateTimeControlIDs[id]+"Hours");
	if (elmHours !=null)
		elmHours.disabled=disable;
	var elmMinutes=document.getElementById(g_strDateTimeControlIDs[id]+"Minutes");
	if (elmMinutes !=null)
		elmMinutes.disabled=disable;
	var elmImage=document.getElementById(g_strDateTimeControlIDs[id]+"DatePickerImage");
	if (elmImage !=null)
	   {
		   if (disable)
			   elmImage.src="/_layouts/images/calendar_grey.gif";
		   else
			   elmImage.src="/_layouts/images/calendar.gif";
	   }
}
function EnableDateTimeControl(id)
{
	ChangeDateTimeControlState(id, false);
}
function DisableDateTimeControl(id)
{
	ChangeDateTimeControlState(id, true);
}
function OnIframeLoadFinish(state)
{
	if(this.Picker !=null &&
		this.Picker.readyState !=null &&
		this.Picker.readyState=="complete")
	{
		document.body.scrollLeft=g_scrollLeft;
		document.body.scrollTop=g_scrollTop;
		PositionFrame('DatePickerDiv');
		this.Picker.style.display="block";
//		document.frames(this.Picker.id).focus();
	}
}
function RecurPatternType_ShowDiv(bShow)
{
  var item=document.getElementById("recurCustomDiv");
  if (item !=null) { item.style.display=bShow?'block':'none'; }
}
function RecurPatternType_ShowRecurType(id)
{
var key ;var item;
var a=new Array('recurDailyDiv', 'recurWeeklyDiv', 'recurMonthlyDiv' ,'recurYearlyDiv');
for (key in a)
{
  item=document.getElementById(a[key]);
  if (item !=null)
	{ item.style.display='none';}
}
  var itemID=document.getElementById(id);
  item=document.getElementById(a[itemID.value-2]);
  if (item !=null) { item.style.display='block'; }
  RecurPatternType_ShowDiv((itemID.value==6)?false:true);
  if (itemID.value !=6 &&  g_warnonce==0 )
  {
	alert(L_WarnkOnce_text);
	g_warnonce++;
  }
}
function RecurType_SetRadioButton1(id)
{
  var itemID=document.getElementById(id);
  if (itemID !=null) { item.checked=true; }
}
function RecurType_SetRadioButton(trobj, idValue)
{
  if (trobj==null)   return;
  var childtd1=trobj.firstChild;
  if (childtd1.nodeType==1)
  {
	var str=childtd1.innerHTML;
	str=str.substr(str.indexOf("id=")+3);
	str=str.substr(0,str.indexOf(" "));
	if(str.indexOf(idValue)>0)
	{
	  var itemID=document.getElementById(str);
	  if (itemID !=null) { itemID.checked=true; }
	}
  }
}

//---------End new Calendar ------------------------------------------

function ShowHideTableSize(obj, clientID, calendarSizeName, status)
{
    var div = document.getElementById(clientID + "_" + calendarSizeName);
    if(div)
    {
        if(obj.checked && status == 1) //status = 1 , specify calendar size
        {
            div.style.display = '';
        }
        else if(obj.checked && status == 0) //status = 1 , specify calendar size 
        {
            div.style.display = 'none';
        }
    }
}


function ShowHideRuntimeFiltering(obj, clientID , runtimeFilteringID)
{
    var objField = document.getElementById(clientID + "_" + runtimeFilteringID);
    if(objField)
    {
        if(obj.checked)
        {
            objField.style.display = 'block';
        }
        else
        {
            objField.style.display = 'none';
        }
    }
}
/////////////////////////Use for Mediachase //////////////////////////////////////

var beforeOver1 = ""; // className
var beforeOver2 = "";// className

function OverMouseOnDayView(obj,classCSSName)
{
    beforeOver1 = obj.className;
    obj.className = classCSSName;
    if (obj.parentNode.nextSibling)
    {
        if(obj.parentNode.nextSibling.cells)
        {
            if(obj.parentNode.nextSibling.cells[1])
            {
                beforeOver2 = obj.parentNode.nextSibling.cells[1].className;
                obj.parentNode.nextSibling.cells[1].className = classCSSName;
            }
        }
    }
}

function OutMouseOnDayView(obj,classCSSName)
{
    if(beforeOver1.indexOf("CalendarPlus-DefaultCell") || beforeOver1.indexOf("CalendarPlus-OtherCell") || beforeOver1.indexOf("CalendarPlus-HightLightCell"))
    {
        obj.className = beforeOver1;
        beforeOver1 = "";
    }
    else 
    {
        obj.className = classCSSName;
        beforeOver1 = "";
    }
    if (obj.parentNode.nextSibling)
    {
        if(obj.parentNode.nextSibling.cells)
        {
            if(obj.parentNode.nextSibling.cells[1])
            {
                if(beforeOver2.indexOf("CalendarPlus-DefaultCell") || beforeOver2.indexOf("CalendarPlus-OtherCell") || beforeOver2.indexOf("CalendarPlus-HightLightCell"))
                {
                    obj.parentNode.nextSibling.cells[1].className = beforeOver2;
                    beforeOver2 = "";
                }
                else 
                {
                    obj.parentNode.nextSibling.cells[1].className = classCSSName;
                    beforeOver2 = "";
                }
            }
        }    
    }
}

function OverMouseOnWorkView(obj,classCSSName)
{
    beforeOver1 = obj.className;
    obj.className = classCSSName;
    var objPos = GetPosition(obj);
    if(objPos == -1) return;
    if (obj.parentNode.nextSibling)
    {
        if(obj.parentNode.nextSibling.cells)
        {
            if(obj.parentNode.nextSibling.cells[objPos])
            {
                beforeOver2 = obj.parentNode.nextSibling.cells[objPos].className;
                obj.parentNode.nextSibling.cells[objPos].className = classCSSName;
            }
        }
    }
}

function GetPosition(obj)
{
    var parent = obj.parentNode;
    if(parent)
    {
        for(var index = 0; index < parent.childNodes.length; index ++ )
        {
            if(parent.childNodes[index] == obj)
            {
                return index;
            }
        }
    }
    return -1;
}

function OutMouseOnWorkView(obj,classCSSName)
{
    if(beforeOver1.indexOf("CalendarPlus-DefaultCell") || beforeOver1.indexOf("CalendarPlus-OtherCell") || beforeOver1.indexOf("CalendarPlus-HightLightCell"))
    {
        obj.className = beforeOver1;
        beforeOver1 = "";
    }
    else 
    {
        obj.className = classCSSName;
        beforeOver1 = "";
    }
    
    var objPos = GetPosition(obj);
    if(objPos == -1) return;
    if (obj.parentNode.nextSibling)
    {
        if(obj.parentNode.nextSibling.cells)
        {
            if(obj.parentNode.nextSibling.cells[objPos])
            {
                if(beforeOver2.indexOf("CalendarPlus-DefaultCell") || beforeOver2.indexOf("CalendarPlus-OtherCell") || beforeOver2.indexOf("CalendarPlus-HightLightCell"))
                {
                    obj.parentNode.nextSibling.cells[objPos].className = beforeOver2;
                    beforeOver2 = "";
                }
                else 
                {
                    obj.parentNode.nextSibling.cells[objPos].className = classCSSName;
                    beforeOver2 = "";
                }
            }
        }
    }
}

function GetArrayColspan(obj)
{
    var o = new Object();
    var arrIndex = new Array();
    var arr = new Array();
    var i = 0;
    var j = 0;
    for(var index = 0 ; index < obj.cells.length; index ++)
    {
        if(obj.cells[index].colSpan <= 1)
        {
            arr[i++] = 0; // 0 : colspan = 1  and 1 : colspan > 1;
            arrIndex[j++] = index ;
        }
        else 
        {
            var col = obj.cells[index].colSpan;
            for(var iCol = 1; iCol <= col ; iCol ++)
            {
                arr[i++] = 1;
                arrIndex[j++] = index ;
            }
        }
    }
    o.arr = arr;
    o.arrIndex = arrIndex;
    return o;
}

function GetIndex(arrIndex,cellIndex)
{
    for(var index = 0; index < arrIndex.length; index ++)
    {
        if(arrIndex[index] == cellIndex )
        {
            return index;
        }
    }
    return 0;
}    

var offX = "";
function GetPositionMouse(arrIndex, obj)
{
    var colspan = obj.colSpan;
    if(colspan > 1)
    {
        var offWidth = obj.offsetWidth; // width of td which have coloumn span
        var session = Math.round(offWidth/colspan); //width of one td
        if(offX == "")
        {
            offX = event.clientX; 
        }
        var tempX = Math.round(offX/session); //get position mouse with td 
        var cIndex = GetIndex(arrIndex, obj.cellIndex); // get cell index of td when mouse over on it 
        var num = 0;
        if(tempX <= 1) 
        {
            num = -1;
        }
        else if( tempX > 1 && tempX <= 2)
        {
            num = 0;
        }
        else if( tempX > 2 && tempX <= 3)
        {
            num = 1;
        }
        else if( tempX > 3 && tempX <= 4)
        {
            num = 2;
        }
        else if( tempX > 4 && tempX <= 5)
        {
            num = 3;
        }
        else if( tempX > 5 && tempX <= 6)
        {
            num = 4;
        }
        else if( tempX > 6 && tempX <= 7)
        {
           num = 5;
        }
        else 
        {
           num = 6;
        }
        //check array which have contain position of td . 
        for(var index = 0; index < arrIndex.length; index ++)        
        {
            if(arrIndex[index] == cIndex)
            {
                return cIndex + (num - cIndex);
            }
        }
    }
    else 
    {
        return GetIndex(arrIndex, obj.cellIndex);
    }
}

var beforeClassName = "";

function OverMouseOnMonthView(obj, position , rowIndex, eventsOnDay, className)
{
    //rowIndex : vi tri cua item dc add vao cell 
    beforeClassName = obj.className;
    if(position == 'top')
    {
        obj.className = className;       
        var table = obj.childNodes[0];
        if(table)
        {
            if(table.tagName == "TABLE")
            {
                if(table.rows[0].cells)
                {
                    table.rows[0].cells[0].className = className;
                    table.rows[0].cells[1].className = className;
                }
            }
        }
        
        var objNext = obj.parentNode;
        if(eventsOnDay == 0)
        {
            objNext = obj.parentNode.nextSibling;
            if (objNext.tagName == "!") {
                objNext = obj.parentNode.nextSibling.nextSibling;
                objNext.cells[obj.cellIndex].className = className;
            }
        }
        
        for(var index = 0; index <= eventsOnDay && eventsOnDay > 0; index ++)
        {
            if(objNext)
            {
                if(objNext.cells)
                {
                    var o = GetArrayColspan(objNext);
                    var arr = o.arr;
                    var arrIndex = o.arrIndex;
                    var hasCol = arr[obj.cellIndex];
                    if(hasCol == 0) {
                        if (objNext.cells.length > 0) {
                            objNext.cells[arrIndex[obj.cellIndex]].className = className;
                        }
                    }
                    objNext = objNext.nextSibling;
                }
            }
        }
        
        if (eventsOnDay > 0) {
            for(var indexTr = 0; indexTr < 2; indexTr ++)
            {
                objNext = objNext.nextSibling;
                if (objNext.cells) {
                    if (beforeClassName == "") {
                        if (objNext.cells.length > 0) {
                            beforeClassName = objNext.cells[obj.cellIndex].className;
                        }
                    }
                    if (objNext.cells.length > 0) {
                        objNext.cells[obj.cellIndex].className = className;
                    }
                }
            }
        }
    }
    else if(position == 'middle')
    {
        var object = GetArrayColspan(obj.parentNode);
        var arrindex = object.arrIndex;
        var cindex = GetPositionMouse(arrindex, obj);
        var objTop = GetTopObject(obj, rowIndex);
        if(objTop)
        {
            if(objTop.cells)
            {
                obj = objTop.cells[cindex]
                if(obj)
                {
                    beforeClassName = obj.className;
                    obj.className = className;       
                    var table = obj.childNodes[0];
                    if(table)
                    {
                        if(table.tagName == "TABLE")
                        {
                            table.rows[0].cells[0].className = className;
                            table.rows[0].cells[1].className = className;
                        }
                    }
                    var objNext = obj.parentNode;
                    if(eventsOnDay == 0)
                    {
                        objNext = objNext.nextSibling;
                    }
                    
                    for(var index = 0; index <= eventsOnDay && eventsOnDay > 0; index ++)
                    {
                        if(objNext)
                        {
                            if(objNext.cells)
                            {
                                var o = GetArrayColspan(objNext);
                                var arr = o.arr;
                                var arrIndex = o.arrIndex;
                                var hasCol = arr[obj.cellIndex];
                                if(hasCol == 0) {
                                    if (objNext.cells.length > 0) {
                                        objNext.cells[arrIndex[obj.cellIndex]].className = className;
                                    }
                                }
                                objNext = objNext.nextSibling;
                            }
                        }
                    }

                    if (eventsOnDay > 0) {
                        for (var indexTr = 0; indexTr < 2; indexTr++) {
                            objNext = objNext.nextSibling;
                            if (objNext.cells) {
                                if (beforeClassName == "") {
                                    if (objNext.cells.length > 0) {
                                        beforeClassName = objNext.cells[obj.cellIndex].className;
                                    }
                                }
                                if (objNext.cells.length > 0) {
                                    objNext.cells[obj.cellIndex].className = className;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    else if(position == 'bottom')
    {
        if(beforeClassName == "")
        {
            beforeClassName = obj.className;
        }
        obj.className = className;
        var objparent = obj.parentNode;//tr
        var objNext = objparent.nextSibling;
        var objPre = objparent.previousSibling;
        if (objNext.tagName == "!" && objPre.tagName == "!") // ! == #comment
        {
            objNext = objparent.previousSibling.previousSibling; //tr
            if (objNext.cells.length == 0) {
                objNext = objparent.previousSibling.previousSibling.previousSibling;
            }
        }
        
        for(var index = 0; index <= eventsOnDay && eventsOnDay > 0; index ++)
        {
            if(objNext)
            {                      
               if(objNext.cells)
                {
                    var o = GetArrayColspan(objNext);
                    var arr = o.arr;
                    var arrIndex = o.arrIndex;
                    var hasCol = arr[obj.cellIndex];
                    if(hasCol == 0) {
                        if (objNext.cells.length > 0) {
                            var td = objNext.cells[arrIndex[obj.cellIndex]];
                            var childNode = td.childNodes[0];
                            if (childNode) {
                                if (childNode.tagName != "SPAN") {
                                    objNext.cells[arrIndex[obj.cellIndex]].className = className;
                                }
                                else {
                                    objNext = objNext.nextSibling;
                                    break;
                                }
                            }
                            else {
                                objNext.cells[arrIndex[obj.cellIndex]].className = className;
                            }
                        }
                    }
                    objNext = objNext.previousSibling;
                }
            }
        }
        if (objNext.tagName == "!") {
            objNext = objNext.nextSibling;
        }
        
        if(objNext.cells)
        {
            var td = objNext.cells[obj.cellIndex];
            if(td)
            {
                var table = td.childNodes[0];
                if(table)
                {
                    if (table.tagName == "TABLE") {
                        td.className = className;
                        table.rows[0].cells[0].className = className;
                        table.rows[0].cells[1].className = className;
                    }
                    else if (table.tagName == "SPAN") {
                        var tr = table.parentNode.parentNode;
                        tr = tr.nextSibling;
                        var td = tr.cells[obj.cellIndex];
                        if (td) {
                            var table = td.childNodes[0];
                            if (table) {
                                if (table.tagName == "TABLE") {
                                    td.className = className;
                                    table.rows[0].cells[0].className = className;
                                    table.rows[0].cells[1].className = className;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

function GetTopObject(obj, rowIndex)
{
    var objTop = obj.parentNode; //parentNode
    for(var index = rowIndex; index >= 0; index --)
    {
        if(objTop.previousSibling) //
        {
            objTop = objTop.previousSibling;
        }
    }
    return objTop;
}

function OutMouseOnMonthView(obj, position, rowIndex, eventsOnDay)
{
    if(position == 'top')
    {
        obj.className = beforeClassName;
        var table = obj.childNodes[0];
        if(table.tagName == "TABLE")
        {
            table.rows[0].cells[0].className = beforeClassName;
            table.rows[0].cells[1].className = beforeClassName;
        }
        var objNext = obj.parentNode;
        if(eventsOnDay == 0)
        {
            objNext = obj.parentNode.nextSibling;
            if (objNext.tagName == "!") {
                objNext = obj.parentNode.nextSibling.nextSibling;
                objNext.cells[obj.cellIndex].className = beforeClassName;
            }
        }
        for(var index = 0; index <= eventsOnDay && eventsOnDay > 0; index ++)
        {
            if(objNext)
            {
               if(objNext.cells)
                {
                    var o = GetArrayColspan(objNext);
                    var arr = o.arr;
                    var arrIndex = o.arrIndex;
                    var hasCol = arr[obj.cellIndex];
                    if(hasCol == 0) {
                        if (objNext.cells.length > 0) {
                            objNext.cells[arrIndex[obj.cellIndex]].className = beforeClassName;
                        }
                    }
                    objNext = objNext.nextSibling;
                }
            }
        }
        if (eventsOnDay > 0) {
            for (var indexTr = 0; indexTr < 2; indexTr++) {
                objNext = objNext.nextSibling;
                if (objNext.cells) {
                    if (beforeClassName == "") {
                        if (objNext.cells.length > 0) {
                            objNext.cells[obj.cellIndex].className = beforeClassName;
                        }
                    }
                    if (objNext.cells.length > 0) {
                        objNext.cells[obj.cellIndex].className = beforeClassName;
                    }
                }
            }
        }
    } 
    else if(position == 'middle')
    {
        var object = GetArrayColspan(obj.parentNode);
        var arrindex = object.arrIndex;
        var cindex = GetPositionMouse(arrindex, obj);
        offX = "";
        var objTop = GetTopObject(obj, rowIndex);
        if(objTop)
        {
            if(objTop.cells)
            {
                obj = objTop.cells[cindex]
                if(obj)
                {
                    obj.className = beforeClassName;
                    var table = obj.childNodes[0];
                    if(table.tagName == "TABLE")
                    {
                        table.rows[0].cells[0].className = beforeClassName;
                        table.rows[0].cells[1].className = beforeClassName;
                    }
                    var objNext = obj.parentNode;
                    if(eventsOnDay == 0)
                    {
                        objNext = objNext.nextSibling;
                    }
                    for(var index = 0; index <= eventsOnDay && eventsOnDay > 0; index ++)
                    {
                        if(objNext)
                        {
                            if(objNext.cells)
                            {
                               if(objNext.cells)
                                {
                                    var o = GetArrayColspan(objNext);
                                    var arr = o.arr;
                                    var arrIndex = o.arrIndex;
                                    var hasCol = arr[obj.cellIndex];
                                    if (objNext.cells.length > 0) {
                                        objNext.cells[arrIndex[obj.cellIndex]].className = beforeClassName;
                                    }
                                    objNext = objNext.nextSibling;
                                }
                            }
                        }
                    }

                    if (eventsOnDay > 0) {
                        for (var indexTr = 0; indexTr < 2; indexTr++) {
                            objNext = objNext.nextSibling;
                            if (objNext.cells) {
                                if (beforeClassName == "") {
                                    if (objNext.cells.length > 0) {
                                        objNext.cells[obj.cellIndex].className = beforeClassName;
                                    }
                                }
                                if (objNext.cells.length > 0) {
                                    objNext.cells[obj.cellIndex].className = beforeClassName;
                                }
                            }
                        }
                    }
                }
            } 
        }
    }
    else if(position == 'bottom')
    {
        obj.className = beforeClassName;
        var objparent = obj.parentNode; //tr
        var objNext = objparent.nextSibling;
        var objPre = objparent.previousSibling;
        if (objNext.tagName == "!" && objPre.tagName == "!") // ! == #comment
        {
            objNext = objparent.previousSibling.previousSibling; //tr
            if (objNext.cells.length == 0) {
                objNext = objparent.previousSibling.previousSibling.previousSibling;
            }
        }
        
        for(var index = 0; index <= eventsOnDay && eventsOnDay > 0; index ++)
        {
            if(objNext)
            {
                if(objNext.cells)
                {
                    var o = GetArrayColspan(objNext);
                    var arr = o.arr;
                    var arrIndex = o.arrIndex;
                    var hasCol = arr[obj.cellIndex];
                    if(hasCol == 0) {
                        if (objNext.cells.length > 0) {
                            var td = objNext.cells[arrIndex[obj.cellIndex]];
                            var childNode = td.childNodes[0];
                            if (childNode) {
                                if (childNode.tagName != "SPAN") {
                                    objNext.cells[arrIndex[obj.cellIndex]].className = beforeClassName;
                                }
                                else {
                                    objNext = objNext.nextSibling;
                                    break;
                                }
                            }
                            else {
                                objNext.cells[arrIndex[obj.cellIndex]].className = beforeClassName;
                            }
                        }
                    }
                    objNext = objNext.previousSibling;
                }
            }
        }

        if (objNext.tagName == "!") {
            objNext = objNext.nextSibling;
        }

        if (objNext.cells) {
            var td = objNext.cells[obj.cellIndex];
            if (td) {
                var table = td.childNodes[0];
                if (table) {
                    if (table.tagName == "TABLE") {
                        td.className = beforeClassName;
                        table.rows[0].cells[0].className = beforeClassName;
                        table.rows[0].cells[1].className = beforeClassName;
                    }
                    else if (table.tagName == "SPAN") {
                        var tr = table.parentNode.parentNode;
                        tr = tr.nextSibling;
                        var td = tr.cells[obj.cellIndex];
                        if (td) {
                            var table = td.childNodes[0];
                            if (table) {
                                if (table.tagName == "TABLE") {
                                    td.className = beforeClassName;
                                    table.rows[0].cells[0].className = beforeClassName;
                                    table.rows[0].cells[1].className = beforeClassName;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    beforeClassName = "";
}

//Show and Hide paging on Gantt and Task View
function ShowHidePagingGanttandTask(rowNumberOfRecordID, isPaging) // isPaging == 1 : show and other hide
{
    var obj = document.getElementById(rowNumberOfRecordID);
    if (obj) {
        if (isPaging == 1) {
            obj.style.display = "block";
        }
        else {
            obj.style.display = "none";
        }
    }
}

//Calendar Plus 3.5
function ClearValueHiddenField(hiddenFieldID, idcss) {
    var hidden = document.getElementById(hiddenFieldID);
    if (hidden != null && hidden != "undefined") {
        hidden.value = "";
    }

    var hiddenInput = document.getElementsByTagName("input");
    if (hiddenInput != null && hiddenInput != "undefined") {
        for (var index = 0; index < hiddenInput.length; index++) {
            var obj = hiddenInput[index];
            if (obj.type != null && obj.type != "undefined") {
                if (obj.type == "hidden") {
                    if (obj.id != null && obj.id != "undefined") {
                        if (obj.id.indexOf("hiddenFieldGanttView" + idcss) != -1) {
                            obj.value = "";
                            break;
                        }
                    }
                }
            }
        }
    }
}

function SetValueHiddenField(hiddenFieldID, startDateID, endDateID, idcss) {
    var hidden = document.getElementById(hiddenFieldID);
    if (hidden != null && hidden != "undefined") {
        hidden.value = "true;";
        var startDate = document.getElementById(startDateID);
        if (startDate != null && startDate != "undefined") {
            var temp = startDate.options[startDate.selectedIndex].value;
            hidden.value += temp + ";";
        }
        var endDate = document.getElementById(endDateID);
        if (endDate != null && endDate != "undefined") {
            var temp = endDate.options[endDate.selectedIndex].value;
            hidden.value += temp;
        }

        var hiddenInput = document.getElementsByTagName("input");
        if (hiddenInput != null && hiddenInput != "undefined") {
            for (var index = 0; index < hiddenInput.length; index++) {
                var obj = hiddenInput[index];
                if (obj.type != null && obj.type != "undefined") {
                    if (obj.type == "hidden") {
                        if (obj.id != null && obj.id != "undefined") {
                            if (obj.id.indexOf("hiddenFieldGanttView" + idcss) != -1) {
                                obj.value = hidden.value;
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
}
//for Mediachase
function NewItemInTask(url, obj, e, day, month, year, lcid, locallcid) {
    var cell = GetCell(e);
    var date = new Object();
    date = AddDays(month, day, year, cell);
    if (lcid == 1031 && locallcid == 1031) {
        window.location.href = url + date.day + "%2E" + date.month + "%2E" + date.year;
    }
    else {
        window.location.href = url + date.month + "%2F" + date.day + "%2F" + date.year;
    }
}

function GetCell(e) {
    var posX = e.offsetX;
    var cell = 0;
    if (posX > 17 && posX <= 34) {
        cell = 1;
    }
    else if (posX > 34 && posX <= 51) {
        cell = 2;
    }
    else if (posX > 51 && posX <= 68) {
        cell = 3;
    }
    else if (posX > 68 && posX <= 85) {
        cell = 4;
    }
    return cell;
}

function LeapYear(year) { //nam nhuan
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? true : false);
}

function AddDays(month, day, year, days) {
    day = day + days;
    if (month == 4 || month == 6 || month == 9 || month == 11) {
        if (day > 30) {
            day = day - 30;
            month += 1;
        }
    }
    else if (month == 2) {
        if (LeapYear(year)) {
            if (day > 29) {
                day -= 29;
                month += 1;
            }
        }
        else {
            if (day > 28) {
                day -= 28;
                month += 1;
            }
        }
    }
    else {
        if (month == 12) {
            if (day > 31) {
                day -= 31;
                month = 1;
                year += 1;
            }
        }
        else {
            if (day > 31) {
                day -= 31;
                month += 1;
            }
        }
    }
    var obj = new Object();
    obj.day = day;
    obj.month = month;
    obj.year = year;
    return obj;
}

function MouseOverWeekView(obj, className) {
    var parent = obj.parentNode;
    if (parent != null || parent != "undefined") {
        if (parent.tagName.toLowerCase() == "tr") {
            var childCount = parent.childNodes.length;
            for (var index = 1; index < childCount; index++) {
                parent.childNodes[index].className = className;
            }
        }
    }
}

function MouseOutWeekView(obj, className) {
    var parent = obj.parentNode;
    if (parent != null || parent != "undefined") {
        if (parent.tagName.toLowerCase() == "tr") {
            var childCount = parent.childNodes.length;
            for (var index = 1; index < childCount; index++) {
                parent.childNodes[index].className = className;
            }
        }
    }
}