
/*************** SFEvent object (methods that are used to attach handlers to DOM element events) *************/
function RegNameSpace(name){ eval("window." + name + " = new Object();"); }

RegNameSpace("SFEvent");
SFEvent = {
    addHandler : function(oElement, oParams){
	    if(!oElement.attachEvent) {
		    oElement.attachEvent = function(e, f) { return this.addEventListener(e.substr(2), f, false); }
	    }
	    for(var i in oParams) { oElement.attachEvent(i, oParams[i]); }
    },
    removeHandler : function(){
        if(!oElement.detachEvent) {
            oElement.detachEvent = function(e, f) { return this.removeEventListener(e.substr(2), f, false); }
        }
        for(var i in oParams) { oElement.detachEvent(i, oParams[i]); }
    },
    createDelegate : function(instance, method){
	    return function() { return method.apply(instance, arguments); }
    },
    stopPropagation : function(evt){
        if (evt.preventDefault) { evt.preventDefault(); evt.stopPropagation(); }
        else { evt.returnValue = false; evt.cancelBubble = true; }
    },
    getEvent : function(evt){
        return (evt) ? evt : ((window.event) ? window.event : null);
    },
    getSender : function(evt){
        var obj = new Object(); 
	    obj.evt = this.getEvent(evt);
	    obj.target = (evt.target) ? evt.target : evt.srcElement;
	    return obj;
    },
	getKey : function(evt)
	{
		evt = this.getEvent(evt);
		return (evt.which) ? evt.which : evt.keyCode;
	}    
};
/*************************************************************************************************************/

// ********************
// Begin Popup Calendar
// ********************
RegNameSpace("CalPopup");
CalPopup = {
    popup : null,    
    isOpened : false,
    isSetDate : false,
    lastSender : null,
    dstFld : null,    
    dstFmt : null,
    months : null,
    days : null,
    today : null,
    close : null,
    title : null,
    firstDayWeek : null,
    temp : null,    
    // ******************************        
    // Expected params:
    // [0] Event
    // [1] Destination Field
    // [2] Short Date Format
    // [3] Month Names
    // [4] Day Names
    // [5] Localized Today string
    // [6] Localized Close string
    // [7] Window Title
    // [8] First Day of Week
    // ******************************
    show : function(){
	    var sender = SFEvent.getSender(arguments[0]);
	    if(sender.target == null)
		    return;

	    //  Create calendar if it hasn't been created yet.
	    if(this.popup == null){
		    this.popup = document.createElement("div");
		    this.popup.id = "calPopup";
		    this.popup.className = "calPopup";
		    SFEvent.addHandler(this.popup, { "onclick" : CalPopup.popupClick });
		    document.body.appendChild(this.popup);		
	    }
    	
        if(this.lastSender != sender.target){
		    //debugger;			//remove slashes to activate debugging in Visual Studio
            var tmpDate         = new Date();
            var tmpString       = "";
            var tmpNum          = 0;
            var tmpDateVal;

            //  Check for the right number of arguments
            if (arguments.length < 2)
            {
	            alert("CalPopup.show(): Wrong number of arguments.");
	            return void(0);
            }
            //  Get the command line arguments - Localization is optional
            this.dstFld = arguments[1];            
            this.dstFmt = arguments[2];       // Localized Short Date Format String
            this.months = arguments[3];       // Localized Month Names String
            this.days = arguments[4];         // Localized Day Names String
            this.today = arguments[5];        // Localized Today string
            this.close = arguments[6];        // Localized Close string
            this.title = arguments[7];        // Window Title
            this.firstDayWeek = arguments[8]; // First Day of Week
            this.temp = arguments[1];

            //  Check destination field name.
            if (this.dstFld !== "")
              this.dstFld = document.getElementById(this.dstFld);

            //  Ddefault localized short date format if not provided.
            if (this.dstFmt === "")
              this.dstFmt = "m/d/yyyy";

            //  Default localized months string if not provided.
            if (this.months === "")
              this.months = "January,February,March,April,May,June,July,August,September,October,November,December";

            //  Default localized months string if not provided.
            if (this.days === "")
              this.days = "Sun,Mon,Tue,Wed,Thu,Fri,Sat";

            //  Default localized today string if not provided.
            if (this.today === "" || typeof(this.today) === "undefined")
              this.today = "Today";

            //  Default localized close string if not provided.
            if (this.close === "" || typeof(this.close) === "undefined")
              this.close = "Close";

            //  Default window title if not provided.
            if (this.title === "" || typeof(this.title) === "undefined")
              this.title = "Calendar";

            tmpString = new String(this.dstFld.value);  
            //  If tmpString is empty (meaning that the field is empty) use todays date as the starting point
            if(tmpString === "")
	            tmpDateVal = new Date();
            else
            {
	            // Make sure the century is included, if it isn't, add this century to the value that was in the field
	            tmpNum = tmpString.lastIndexOf( "/" );
	            if ( (tmpString.length - tmpNum) === 3 )
	            {
		            tmpString = tmpString.substring(0,tmpNum + 1) + "20" + tmpString.substr(tmpNum+1);
		            tmpDateVal = new Date(tmpString);
	            }
	            else
	            {
		            //  Localized date support:
		            //  If we got to this point, it means the field that was passed 
		            //  in has no slashes in it. Use an extra function to build the date 
		            //  according to supplied date formatstring.
		            tmpDateVal = this.getDateFromFormat(tmpString, this.dstFmt);
	            }
            }

            //  Make sure the date is a valid date.  Set it to today if it is invalid "NaN" is the return value for an invalid date.
            if(tmpDateVal === 0 || tmpDateVal.toString() === "NaN" )
            {
	            tmpDateVal = new Date();
	            this.dstFld.value = "";
            }
            		
            //  Set the base date to midnight of the first day of the specified month, this makes things easier?
            var dateString = String(tmpDateVal.getMonth()+1) + "/" + String(tmpDateVal.getDate()) + "/" + String(tmpDateVal.getFullYear());
            
            //  Call the routine to draw the initial calendar
            this.isOpened = true;
            this.isSetDate = false;
		    this.lastSender = sender.target;
    		
		    var x = 0;
		    var y = 0;
		    var yPlus = sender.target.offsetHeight;
		    while (sender.target){
			    x += sender.target.offsetLeft;
			    y += sender.target.offsetTop;
			    sender.target = sender.target.offsetParent;
		    }
    		
		    this.popup.style.visibility = "visible";
		    this.popup.style.left = x;
		    this.popup.style.top = y + yPlus;		
    		
            this.reload(dateString);
	    }
    	
	    return void(0);
    },
    //  [0]dateString
    reload : function(){
	    var tmpDate = new Date(arguments[0]);
	    if (tmpDate.toString() === "Invalid Date")
	        tmpDate = new Date();
	    tmpDate.setDate(1);

	    //  Get the calendar data.
	    var popCalData = this.setData(tmpDate, arguments[1]);
	    calPopup.innerHTML = popCalData;
    	
	    return void(1);
    },
    setData : function(firstDay, dstWindowName){
	    var popCalData = "";
        var lastDate = 0;
	    var fnt = new Array( "<font size=\"1\">", "<b><font size=\"2\">", "<font size=\"2\" color=\"#EF741D\"><b>");
	    var dtToday = new Date();
	    var thisMonth = firstDay.getMonth();
	    var thisYear = firstDay.getFullYear();
	    var nPrevMonth = (thisMonth === 0 ) ? 11 : (thisMonth - 1);
	    var nNextMonth = (thisMonth === 11 ) ? 0 : (thisMonth + 1);
	    var nPrevMonthYear = (nPrevMonth === 11) ? (thisYear - 1): thisYear;
	    var nNextMonthYear = (nNextMonth === 0) ? (thisYear + 1): thisYear;
	    var sToday = String((dtToday.getMonth()+1) + "/01/" + dtToday.getFullYear());
	    var sPrevMonth = String((nPrevMonth+1) + "/01/" + nPrevMonthYear);
	    var sNextMonth = String((nNextMonth+1) + "/01/" + nNextMonthYear);
	    var sPrevYear1 = String((thisMonth+1) + "/01/" + (thisYear - 1));
	    var sNextYear1 = String((thisMonth+1) + "/01/" + (thisYear + 1));
 	    var tmpDate = new Date( sNextMonth );	
    	
	    tmpDate = new Date( tmpDate.valueOf() - 1001 );
	    lastDate = tmpDate.getDate();

	    if (this.months.split) // javascript 1.1 defensive code
	    {
		    var monthNames = this.months.split(",");
		    var dayNames = this.days.split(",");
	    }
	    else  // Need to build a js 1.0 split algorithm, default English for now
	    {
		    var monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
		    var dayNames = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
	    }
    	
	    var cellAttribs = "align=\"center\" bgcolor=\"#F1F1F1\" onMouseOver=\"CalPopup.temp=this.style.backgroundColor; this.style.backgroundColor='#CCCCCC';\" onMouseOut=\"this.style.backgroundColor=CalPopup.temp;\"";
	    var todayAnchor = "<a class=\"nav\" href=\"javascript:void(0);\" onClick=\"CalPopup.reload('"+sToday+"','"+dstWindowName+"');\">"+this.today+"</a>";
	    var prevMonthAnchor = "<a class=\"nav\" href=\"javascript:void(0);\" onClick=\"CalPopup.reload('"+sPrevMonth+"','"+dstWindowName+"');\">" + monthNames[nPrevMonth] + "</a>";
	    var nextMonthAnchor = "<a class=\"nav\" href=\"javascript:void(0);\" onClick=\"CalPopup.reload('"+sNextMonth+"','"+dstWindowName+"');\">" + monthNames[nNextMonth] + "</a>";
	    var prevYear1Anchor = "<a class=\"nav\" href=\"javascript:void(0);\" onClick=\"CalPopup.reload('"+sPrevYear1+"','"+dstWindowName+"');\">"+(thisYear-1)+"</a>";
	    var nextYear1Anchor = "<a class=\"nav\" href=\"javascript:void(0);\" onClick=\"CalPopup.reload('"+sNextYear1+"','"+dstWindowName+"');\">"+(thisYear+1)+"</a>";

        popCalData += "<div align=\"right\"><a class=\"close\" href=\"javascript:void(0);\" isClose=\"true\"></a></div>";
	    popCalData += ("<center>");
	    popCalData += ("<table class=\"tblNav1\" border=\"0\" cellspacing=\"0\" callpadding=\"0\"><tr><td width=\"45\">&nbsp</td>");
	    popCalData += ("<td width=\"45\" align=\"center\" >" + prevYear1Anchor +"</td>");
	    popCalData += ("<td width=\"70\" align=\"center\" >" + todayAnchor + "</td>");
	    popCalData += ("<td width=\"45\" align=\"center\" >" + nextYear1Anchor + "</td>");
	    popCalData += ("<td width=\"45\">&nbsp</td></tr></table>");
    	
	    popCalData += ("<table class=\"tblNav2\" border=\"0\" cellspacing=\"0\" callpadding=\"0\">");          
	    popCalData += ("<tr><td width=\"55\" align=\"center\" >" + prevMonthAnchor + "</td>");
	    popCalData += ("<td width=\"140\" align=\"center\" >&nbsp;&nbsp;<span class=\"monthCurr\">"+ monthNames[thisMonth] + ", " + thisYear + "</span>&nbsp;&nbsp;</td>");
	    popCalData += ("<td width=\"55\" align=\"center\" >" + nextMonthAnchor + "</td></tr></table>");       
    	
	    popCalData += ("<table class=\"tblDays\" border=\"0\" cellspacing=\"2\" cellpadding=\"1\"><tr>");	
	    var xday = 0;
	    for (xday = 0; xday < 7; xday++)
		    popCalData += ("<td width=\"35\" align=\"center\" ><span class=\"header\" >" + dayNames[(xday+this.firstDayWeek)%7] + "</span></td>");
	    popCalData += ("</tr>");

	    var calDay = 0;
	    var monthDate = 1;
	    var weekDay = firstDay.getDay();
	    do
	    {
		    popCalData += ("<tr>");
		    for (calDay = 0; calDay < 7; calDay++ )
		    {
			    if(((weekDay+7-this.firstDayWeek)%7 != calDay) || (monthDate > lastDate))
			    {
				    popCalData += ("<td width=\"35\">"+fnt[1]+"&nbsp;</font></td>");
				    continue;
			    }
			    else
			    {
				    anchorVal = "<a href=\"javascript:void(0);\" ";
				    jsVal = "javascript:CalPopup.setDate(CalPopup.dstFld,'" + this.constructDate(monthDate,thisMonth+1,thisYear) + "');";
				    popCalData += ("<td width=\"35\" "+cellAttribs+" onClick=\""+jsVal+"\" >");
    				
				    if ((firstDay.getMonth() === dtToday.getMonth()) && (monthDate === dtToday.getDate()) && (thisYear === dtToday.getFullYear()) )
					    popCalData += (anchorVal + "class=\"dayCurr\" >" + monthDate + "</a></td>");
				    else
					    popCalData += (anchorVal + "class=\"day\" >" + monthDate + "</a></td>");
    				
				    weekDay++;
				    monthDate++;
			    }
		    }
		    weekDay = this.firstDayWeek;
		    popCalData += ("</tr>");
	    } while( monthDate <= lastDate );
    	
	    popCalData += ("</table></center>"); 

	    return  popCalData;
    },
    popupClick : function(evt){
        var sender = SFEvent.getSender(evt);
        
        var isClose = (sender.target ? sender.target.getAttribute("isClose") : null);
        CalPopup.isOpened = ((CalPopup.isSetDate || isClose) ? false : true);
    },
    hidden : function(){
        if(CalPopup.isOpened)
            CalPopup.isOpened = false;
        else if(CalPopup.popup != null){
		    CalPopup.lastSender = null;
		    CalPopup.popup.style.visibility = "hidden";
	    }
    },
    setDate : function()
    {
	    CalPopup.setDate.arguments[0].value = CalPopup.setDate.arguments[1];
	    CalPopup.isSetDate = true;
    },
    // utility function
    padZero : function(num){
      return ((num <= 9) ? ("0" + num) : num);
    },
    // Format short date
    constructDate : function(d,m,y){
      var fmtDate = this.dstFmt
      fmtDate = fmtDate.replace ('dd', this.padZero(d))
      fmtDate = fmtDate.replace ('d', d)
      fmtDate = fmtDate.replace ('MM', this.padZero(m))
      fmtDate = fmtDate.replace ('M', m)
      fmtDate = fmtDate.replace ('yyyy', y)
      fmtDate = fmtDate.replace ('yy', this.padZero(y%100))
      return fmtDate;
    },
    // ------------------------------------------------------------------
    // Utility functions for parsing in getDateFromFormat()
    // ------------------------------------------------------------------
    _isInteger : function(val){
	    var digits="1234567890";
	    for (var i=0; i < val.length; i++){
		    if (digits.indexOf(val.charAt(i)) === -1) { return false; }
		}
	    return true;
    },
    _getInt : function(str,i,minlength,maxlength){
	    for (var x=maxlength; x>=minlength; x--){
		    var token=str.substring(i,i+x);
		    if (token.length < minlength) { return null; }
		    if (this._isInteger(token)) { return token; }
		}
	    return null;
	},    	
    // ------------------------------------------------------------------
    // getDateFromFormat( date_string , format_string )
    //
    // This function takes a date string and a format string. It matches
    // If the date string matches the format string, it returns the 
    // getTime() of the date. If it does not match, it returns 0.
    // ------------------------------------------------------------------
    getDateFromFormat : function(val, format) {
	    val=val+"";
	    format=format+"";
	    var i_val=0;
	    var i_format=0;
	    var c="";
	    var token="";
	    var x,y;
	    var now=new Date();
	    var year=now.getYear();
	    var month=now.getMonth()+1;
	    var date=1;
    		
	    while (i_format < format.length) {
		    // Get next token from format string
		    c=format.charAt(i_format);
		    token = "";
		    while ((format.charAt(i_format) === c) && (i_format < format.length)){
			    token += format.charAt(i_format++);
            }
		    // Extract contents of value based on format token
		    if (token === "yyyy" || token === "yy" || token === "y") {
			    if (token === "yyyy") { x=4; y=4; }
			    if (token === "yy")   { x=2; y=2; }
			    if (token === "y")    { x=2; y=4; }
			    year = this._getInt(val, i_val, x, y);
			    if (year == null) { return 0; }
			    i_val += year.length;
			    if (year.length === 2){
				    if (year > 70) { year = 1900+(year-0); }
				    else { year = 2000+(year-0); }
			    }
			}
		    else if (token === "MM"||token === "M"){
			    month = this._getInt(val, i_val, token.length, 2);
			    if(month == null || (month<1) || (month>12)){return 0;}
			    i_val += month.length;
            }
		    else if (token === "dd" || token === "d"){
			    date = this._getInt(val, i_val, token.length, 2);
			    if(date == null || (date<1) || (date>31)){return 0;}
			    i_val += date.length;
            }
		    else{
			    if (val.substring(i_val, i_val + token.length) != token) {return 0;}
			    else {i_val += token.length;}
            }
        }
	    // If there are any trailing characters left in the value, it doesn't match
	    if (i_val != val.length) { return 0; }
	    // Is date valid for month?
	    if (month==2) {
		    // Check for leap year
		    if ( ( (year%4 === 0) && (year%100 !== 0) ) || (year%400 === 0) ) { // leap year
			    if (date > 29){ return 0; }
			}
		    else { if (date > 28) { return 0; } }
        }
	    if ((month === 4)||(month === 6)||(month === 9)||(month === 11)){
		    if (date > 30) { return 0; }
        }
	    var newdate=new Date(year, month-1, date);
	    
	    return newdate;
    }
};
// ******************
// End Popup Calendar
// ******************

SFEvent.addHandler(document, { "onclick" : CalPopup.hidden });

//// ********************
//// Begin Popup Calendar
//// ********************
//var calPopup = null;
//var calPopupDstFld = null;
//var calPopupOpening = false;
//var calPopupIsSetDate = false;
//var calPopupLastSender = null;
//var calPopupTemp;

//// ******************************
//// Expected params:
//// [0] Event
//// [1] Destination Field
//// [2] Short Date Format
//// [3] Month Names
//// [4] Day Names
//// [5] Localized Today string
//// [6] Localized Close string
//// [7] Window Title
//// [8] First Day of Week
//// ******************************
//function popupCal()
//{
//	var sender = SFEvent.getSender(popupCal.arguments[0]);
//	if(sender.target == null)
//		return;

//	//  Create calendar if it hasn't been created yet.
//	if(calPopup == null){
//		calPopup = document.createElement("div");
//		calPopup.id = "calPopup";
//		calPopup.className = "calPopup";
//		SFEvent.addHandler(calPopup, { "onclick" : calPopupClick });
//		document.body.appendChild(calPopup);		
//	}
//	
//    if(calPopupLastSender != sender.target){
//		//debugger;			//remove slashes to activate debugging in Visual Studio
//        var tmpDate         = new Date();
//        var tmpString       = "";
//        var tmpNum          = 0;
//        var popCalDateVal;

//        //  Check for the right number of arguments
//        if (arguments.length < 2)
//        {
//	        alert("popupCal(): Wrong number of arguments.");
//	        return void(0);
//        }
//        //  Get the command line arguments - Localization is optional
//        calPopupDstFld = popupCal.arguments[1];
//        calPopupTemp = popupCal.arguments[1];
//        popCalDstFmt = popupCal.arguments[2]; //Localized Short Date Format String
//        popCalMonths = popupCal.arguments[3]; //Localized Month Names String
//        popCalDays = popupCal.arguments[4];   //Localized Day Names String
//        popCalToday = popupCal.arguments[5];  //Localized Today string
//        popCalClose = popupCal.arguments[6];  //Localized Close string
//        popCalTitle = popupCal.arguments[7];  //Window Title
//        popCalFirstDayWeek = popupCal.arguments[8];  //First Day of Week

//        //check destination field name
//        if (calPopupDstFld != "")
//          calPopupDstFld = document.getElementById(calPopupDstFld);

//        //default localized short date format if not provided
//        if (popCalDstFmt == "")
//          popCalDstFmt = "m/d/yyyy";

//        //default localized months string if not provided
//        if (popCalMonths == "")
//          popCalMonths = "January,February,March,April,May,June,July,August,September,October,November,December";

//        //default localized months string if not provided
//        if (popCalDays == "")
//          popCalDays = "Sun,Mon,Tue,Wed,Thu,Fri,Sat";

//        //default localized today string if not provided
//        if (popCalToday == "" || typeof popCalToday == "undefined")
//          popCalToday = "Today";

//        //default localized close string if not provided
//        if (popCalClose == "" || typeof popCalClose == "undefined")
//          popCalClose = "Close";

//        //default window title if not provided
//        if (popCalTitle == "" || typeof popCalTitle == "undefined")
//          popCalTitle = "Calendar";

//        tmpString = new String(calPopupDstFld.value);  
//        //If tmpString is empty (meaning that the field is empty) 
//        //use todays date as the starting point
//        if(tmpString == "")
//	        popCalDateVal = new Date()
//        else
//        {
//	        //Make sure the century is included, if it isn't, add this 
//	        //century to the value that was in the field
//	        tmpNum = tmpString.lastIndexOf( "/" );
//	        if ( (tmpString.length - tmpNum) == 3 )
//	        {
//		        tmpString = tmpString.substring(0,tmpNum + 1)+"20"+tmpString.substr(tmpNum+1);
//		        popCalDateVal = new Date(tmpString);
//	        }
//	        else
//	        {
//		        //localized date support:
//		        //If we got to this point, it means the field that was passed 
//		        //in has no slashes in it. Use an extra function to build the date 
//		        //according to supplied date formatstring.
//		        popCalDateVal = getDateFromFormat(tmpString,popCalDstFmt);
//	        }
//        }

//        //Make sure the date is a valid date.  Set it to today if it is invalid
//        //"NaN" is the return value for an invalid date
//        if(popCalDateVal == 0 || popCalDateVal.toString() == "NaN" )
//        {
//	        popCalDateVal = new Date();
//	        calPopupDstFld.value = "";
//        }
//        		
//        //  Set the base date to midnight of the first day of the specified month, this makes things easier?
//        var dateString = String(popCalDateVal.getMonth()+1) + "/" + String(popCalDateVal.getDate()) + "/" + String(popCalDateVal.getFullYear());
//        
//        //  Call the routine to draw the initial calendar
//        calPopupOpening = true;
//        calPopupIsSetDate = false;
//		calPopupLastSender = sender.target;
//		
//		var x = 0;
//		var y = 0;
//		var yPlus = sender.target.offsetHeight;
//		while (sender.target){
//			x += sender.target.offsetLeft;
//			y += sender.target.offsetTop;
//			sender.target = sender.target.offsetParent;
//		}
//		
//		calPopup.style.visibility = "visible";
//		calPopup.style.left = x;
//		calPopup.style.top = y + yPlus;		
//		
//        reloadCalPopup(dateString);
//	}
//	
//	return void(0);
//}

//function reloadCalPopup() //[0]dateString
//{
//	var tmpDate = new Date(reloadCalPopup.arguments[0]);	
//	if (tmpDate.toString() == "Invalid Date")
//	    tmpDate = new Date();	
//	tmpDate.setDate(1);

//	//  Get the calendar data.
//	var popCalData = calPopupSetData(tmpDate, reloadCalPopup.arguments[1]);
//	calPopup.innerHTML = popCalData;
//	
//	return void(1);
//}

//function calPopupSetData(firstDay, dstWindowName)
//{
//	var popCalData = "";
//    var lastDate = 0;
//	var fnt = new Array( "<font size=\"1\">", "<b><font size=\"2\">", "<font size=\"2\" color=\"#EF741D\"><b>");
//	var dtToday = new Date();
//	var thisMonth = firstDay.getMonth();
//	var thisYear = firstDay.getFullYear();
//	var nPrevMonth = (thisMonth == 0 ) ? 11 : (thisMonth - 1);
//	var nNextMonth = (thisMonth == 11 ) ? 0 : (thisMonth + 1);
//	var nPrevMonthYear = (nPrevMonth == 11) ? (thisYear - 1): thisYear;
//	var nNextMonthYear = (nNextMonth == 0) ? (thisYear + 1): thisYear;
//	var sToday = String((dtToday.getMonth()+1) + "/01/" + dtToday.getFullYear());
//	var sPrevMonth = String((nPrevMonth+1) + "/01/" + nPrevMonthYear);
//	var sNextMonth = String((nNextMonth+1) + "/01/" + nNextMonthYear);
//	var sPrevYear1 = String((thisMonth+1) + "/01/" + (thisYear - 1));
//	var sNextYear1 = String((thisMonth+1) + "/01/" + (thisYear + 1));
// 	var tmpDate = new Date( sNextMonth );	
//	
//	tmpDate = new Date( tmpDate.valueOf() - 1001 );
//	lastDate = tmpDate.getDate();

//	if (this.popCalMonths.split) // javascript 1.1 defensive code
//	{
//		var monthNames = this.popCalMonths.split(",");
//		var dayNames = this.popCalDays.split(",");
//	}
//	else  // Need to build a js 1.0 split algorithm, default English for now
//	{
//		var monthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
//		var dayNames = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
//	}
//	
//	var cellAttribs = "align=\"center\" bgcolor=\"#F1F1F1\" onMouseOver=\"calPopupTemp=this.style.backgroundColor; this.style.backgroundColor='#CCCCCC';\" onMouseOut=\"this.style.backgroundColor=calPopupTemp;\"";
//	var todayAnchor = "<a class=\"nav\" href=\"javascript:void(0);\" onClick=\"reloadCalPopup('"+sToday+"','"+dstWindowName+"');\">"+popCalToday+"</a>";
//	var prevMonthAnchor = "<a class=\"nav\" href=\"javascript:void(0);\" onClick=\"reloadCalPopup('"+sPrevMonth+"','"+dstWindowName+"');\">" + monthNames[nPrevMonth] + "</a>";
//	var nextMonthAnchor = "<a class=\"nav\" href=\"javascript:void(0);\" onClick=\"reloadCalPopup('"+sNextMonth+"','"+dstWindowName+"');\">" + monthNames[nNextMonth] + "</a>";
//	var prevYear1Anchor = "<a class=\"nav\" href=\"javascript:void(0);\" onClick=\"reloadCalPopup('"+sPrevYear1+"','"+dstWindowName+"');\">"+(thisYear-1)+"</a>";
//	var nextYear1Anchor = "<a class=\"nav\" href=\"javascript:void(0);\" onClick=\"reloadCalPopup('"+sNextYear1+"','"+dstWindowName+"');\">"+(thisYear+1)+"</a>";

//    popCalData += "<div align=\"right\"><a class=\"close\" href=\"javascript:void(0);\" isClose=\"true\"></a></div>";
//	popCalData += ("<center>");
//	popCalData += ("<table class=\"tblNav1\" border=\"0\" cellspacing=\"0\" callpadding=\"0\"><tr><td width=\"45\">&nbsp</td>");
//	popCalData += ("<td width=\"45\" align=\"center\" >" + prevYear1Anchor +"</td>");
//	popCalData += ("<td width=\"70\" align=\"center\" >" + todayAnchor + "</td>");
//	popCalData += ("<td width=\"45\" align=\"center\" >" + nextYear1Anchor + "</td>");
//	popCalData += ("<td width=\"45\">&nbsp</td></tr></table>");
//	
//	popCalData += ("<table class=\"tblNav2\" border=\"0\" cellspacing=\"0\" callpadding=\"0\">");          
//	popCalData += ("<tr><td width=\"55\" align=\"center\" >" + prevMonthAnchor + "</td>");
//	popCalData += ("<td width=\"140\" align=\"center\" >&nbsp;&nbsp;<span class=\"monthCurr\">"+ monthNames[thisMonth] + ", " + thisYear + "</span>&nbsp;&nbsp;</td>");
//	popCalData += ("<td width=\"55\" align=\"center\" >" + nextMonthAnchor + "</td></tr></table>");       
//	
//	popCalData += ("<table class=\"tblDays\" border=\"0\" cellspacing=\"2\" cellpadding=\"1\"><tr>");	
//	var xday = 0;
//	for (xday = 0; xday < 7; xday++)
//		popCalData += ("<td width=\"35\" align=\"center\" ><span class=\"header\" >" + dayNames[(xday+popCalFirstDayWeek)%7] + "</span></td>");
//	popCalData += ("</tr>");

//	var calDay = 0;
//	var monthDate = 1;
//	var weekDay = firstDay.getDay();
//	do
//	{
//		popCalData += ("<tr>");
//		for (calDay = 0; calDay < 7; calDay++ )
//		{
//			if(((weekDay+7-popCalFirstDayWeek)%7 != calDay) || (monthDate > lastDate))
//			{
//				popCalData += ("<td width=\"35\">"+fnt[1]+"&nbsp;</font></td>");
//				continue;
//			}
//			else
//			{
//				anchorVal = "<a href=\"javascript:void(0);\" ";
//				jsVal = "javascript:calPopupSetDate(calPopupDstFld,'" + constructDate(monthDate,thisMonth+1,thisYear) + "');";
//				popCalData += ("<td width=\"35\" "+cellAttribs+" onClick=\""+jsVal+"\" >");
//				
//				if ((firstDay.getMonth() == dtToday.getMonth()) && (monthDate == dtToday.getDate()) && (thisYear == dtToday.getFullYear()) )
//					popCalData += (anchorVal + "class=\"dayCurr\" >" + monthDate + "</a></td>");
//				else
//					popCalData += (anchorVal + "class=\"day\" >" + monthDate + "</a></td>");
//				
//				weekDay++;
//				monthDate++;
//			}
//		}
//		weekDay = popCalFirstDayWeek;
//		popCalData += ("</tr>");
//	} while( monthDate <= lastDate );
//	
//	popCalData += ("</table></center>"); 

//	return  popCalData;
//}

//function calPopupClick(evt){
//    var sender = SFEvent.getSender(evt);
//    
//    var isClose = (sender.target ? sender.target.getAttribute("isClose") : null);
//    calPopupOpening = ((calPopupIsSetDate || isClose) ? false : true);
//}
//function calPopupHidden(){
//    if(calPopupOpening)
//        calPopupOpening = false;
//    else if(calPopup != null){
//		calPopupLastSender = null;
//		calPopup.style.visibility = "hidden";
//	}
//}

//function calPopupSetDate()
//{
//	calPopupSetDate.arguments[0].value = calPopupSetDate.arguments[1];
//	calPopupIsSetDate = true;
//}

//// utility function
//function padZero(num)
//{
//  return ((num <= 9) ? ("0" + num) : num);
//}

//// Format short date
//function constructDate(d,m,y)
//{
//  var fmtDate = this.popCalDstFmt
//  fmtDate = fmtDate.replace ('dd', padZero(d))
//  fmtDate = fmtDate.replace ('d', d)
//  fmtDate = fmtDate.replace ('MM', padZero(m))
//  fmtDate = fmtDate.replace ('M', m)
//  fmtDate = fmtDate.replace ('yyyy', y)
//  fmtDate = fmtDate.replace ('yy', padZero(y%100))
//  return fmtDate;
//}

//// ------------------------------------------------------------------
//// Utility functions for parsing in getDateFromFormat()
//// ------------------------------------------------------------------
//function _isInteger(val) {
//	var digits="1234567890";
//	for (var i=0; i < val.length; i++) {
//		if (digits.indexOf(val.charAt(i))==-1) { return false; }
//		}
//	return true;
//	}
//function _getInt(str,i,minlength,maxlength) {
//	for (var x=maxlength; x>=minlength; x--) {
//		var token=str.substring(i,i+x);
//		if (token.length < minlength) { return null; }
//		if (_isInteger(token)) { return token; }
//		}
//	return null;
//	}
//	
//// ------------------------------------------------------------------
//// getDateFromFormat( date_string , format_string )
////
//// This function takes a date string and a format string. It matches
//// If the date string matches the format string, it returns the 
//// getTime() of the date. If it does not match, it returns 0.
//// ------------------------------------------------------------------
//function getDateFromFormat(val,format) {
//	val=val+"";
//	format=format+"";
//	var i_val=0;
//	var i_format=0;
//	var c="";
//	var token="";
//	var x,y;
//	var now=new Date();
//	var year=now.getYear();
//	var month=now.getMonth()+1;
//	var date=1;
//		
//	while (i_format < format.length) {
//		// Get next token from format string
//		c=format.charAt(i_format);
//		token="";
//		while ((format.charAt(i_format)==c) && (i_format < format.length)) {
//			token += format.charAt(i_format++);
//			}
//		// Extract contents of value based on format token
//		if (token=="yyyy" || token=="yy" || token=="y") {
//			if (token=="yyyy") { x=4;y=4; }
//			if (token=="yy")   { x=2;y=2; }
//			if (token=="y")    { x=2;y=4; }
//			year=_getInt(val,i_val,x,y);
//			if (year==null) { return 0; }
//			i_val += year.length;
//			if (year.length==2) {
//				if (year > 70) { year=1900+(year-0); }
//				else { year=2000+(year-0); }
//				}
//			}
//		else if (token=="MM"||token=="M") {
//			month=_getInt(val,i_val,token.length,2);
//			if(month==null||(month<1)||(month>12)){return 0;}
//			i_val+=month.length;}
//		else if (token=="dd"||token=="d") {
//			date=_getInt(val,i_val,token.length,2);
//			if(date==null||(date<1)||(date>31)){return 0;}
//			i_val+=date.length;}
//		else {
//			if (val.substring(i_val,i_val+token.length)!=token) {return 0;}
//			else {i_val+=token.length;}
//			}
//		}
//	// If there are any trailing characters left in the value, it doesn't match
//	if (i_val != val.length) { return 0; }
//	// Is date valid for month?
//	if (month==2) {
//		// Check for leap year
//		if ( ( (year%4==0)&&(year%100 != 0) ) || (year%400==0) ) { // leap year
//			if (date > 29){ return 0; }
//			}
//		else { if (date > 28) { return 0; } }
//		}
//	if ((month==4)||(month==6)||(month==9)||(month==11)) {
//		if (date > 30) { return 0; }
//		}
//	var newdate=new Date(year,month-1,date);
//	return newdate;
//	}

//// ******************
//// End Popup Calendar
//// ******************

//SFEvent.addHandler(document, { "onclick" : calPopupHidden });
