// Copyright (c) 1998-2010 Netsential.com
function nsCalmakeArray0() {
    for (i = 0; i<nsCalmakeArray0.arguments.length; i++)
        this[i] = nsCalmakeArray0.arguments[i];
}
function nsCalpadout(number) { return (number < 10) ? '0' + number : number; }
function nsCaly2k(number)    { return (number < 30) ? number + 2000 : (number < 1000) ? number + 1900 : number; }
var nsCalnames = new nsCalmakeArray0('','January','February','March','April','May','June','July','August','September','October','November','December');
var nsCaldays  = new nsCalmakeArray0(0,31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var nsCaldow   = new nsCalmakeArray0('S','M','T','W','T','F','S');
var cal_today = new Date();
var cal_day   = cal_today.getDate();
var cal_month = cal_today.getMonth()+1;
var cal_year  = nsCaly2k(cal_today.getYear());
var oCallerField;
var	oMyCal=document.getElementById("Mycal");

function cal_gettoday() {
	cal_day   = cal_today.getDate();
	cal_month = cal_today.getMonth()+1;
	cal_year  = nsCaly2k(cal_today.getYear());
	oMyCal.innerHTML = myCalendar(cal_month,cal_year)
}

function changeDay(day) {
    var newdate= nsCalpadout(cal_month) + '/' + nsCalpadout(day) + '/' + cal_year;
	oCallerField.value=newdate;
	try{oCallerField.focus();}catch(e){};
	if(oCallerField.onchange) oCallerField.onchange();
	oMyCal.style.display="none";
}
function changeMonthbycount(iCount){
	cal_month = (cal_month*1) + iCount;
	while (cal_month <  1) {cal_year--; cal_month+=12;}
	while (cal_month > 12) {cal_year++; cal_month-=12;}
	oMyCal.innerHTML = myCalendar(cal_month,cal_year)
}
function changeMonth(oSelect) {
    cal_month = oSelect.options[oSelect.selectedIndex].value + '';
	oMyCal.innerHTML = myCalendar(cal_month,cal_year)
}
function changeYear(oInput) {
    cal_year = parseInt(oInput.value) + '';
	oMyCal.innerHTML = myCalendar(cal_month,cal_year)
}
function showcalendar(mycaller_field) {
	oCallerField=document.getElementById(mycaller_field);
	oMyCal=document.getElementById("Mycal");
 var x = oCallerField.offsetLeft, y = oCallerField.offsetTop, p = oCallerField.offsetParent;
 while (p && (p!=p.offsetParent)) { x += p.offsetLeft; y += p.offsetTop; p = p.offsetParent; };
	if(typeof(oMyCal.style.posLeft)=='undefined'){ //netscape
		oMyCal.style.left=x + oCallerField.offsetWidth;
		oMyCal.style.top=y;
	}else{
		oMyCal.style.posLeft = x + oCallerField.offsetWidth;
		oMyCal.style.posTop=y;
		var iOffset =oCallerField.offsetTop;
		var oElement=oCallerField
		while (oElement = oElement.offsetParent) iOffset = iOffset + oElement.offsetTop;
		iOffset += 181; //oMyCal.clientHeight;
		iOffset -= document.body.clientHeight;
		iOffset -= document.body.scrollTop;
		if ( iOffset> 0) oMyCal.style.posTop -=iOffset;
	}
	oMyCal.style.display="";
	var d=oCallerField.value;
	if(d != "")
	{
		d = d.split('/');
		if(d.length == 3) {
			cal_month = d[0]; cal_day = d[1]; cal_year = d[2];
			if(cal_day.length > 2 || isNaN(cal_day)) cal_day = cal_today.getDate();
			if(cal_month.length > 2 || isNaN(cal_month)) cal_month = cal_today.getMonth()+1;
			if(cal_year.length > 4 || isNaN(cal_year)) cal_year = nsCaly2k(cal_today.getYear());
			cal_year = nsCaly2k(Number(cal_year));
			cal_month = Number(cal_month);
			cal_day = Number(cal_day);
			if(cal_month < 1 || cal_month > 12) cal_month = cal_today.getMonth()+1;
			if(cal_day < 1 || cal_day > 31) cal_day = cal_today.getDate();
		}
	}
	oMyCal.innerHTML = myCalendar(cal_month,cal_year)
}
function cal_keydown(pthis) {
	if (event.keyCode == 13) pthis.onchange();
	else return false;
}

function myCalendar(Month,Year) {
    var output = '';
    output += '<table border=0 cellpadding="0" cellspacing=2 class="CalOuterColor"><tr><td>';
    output += '<table border=0 cellpadding="0" cellspacing=2 class="CalInnerColor" width="100%"><tr><td>';
    output += '<table border=0 cellpadding="0" cellspacing="0" class="CalOuterColor" width="100%">';
    output += '<tr><td class="CalHeaderText">Calendar</td>';
	output += '<td class="CalHeaderText" align="right"><a class="CalHeaderText" href="javascript:;" onclick="oMyCal.style.display=\'none\'">x</a></td></tr></table>';
    output += '<table border=0 cellpadding="0" cellspacing="0" class="CalInnerColor" width="100%">';
    output += '<tr><td class="CalNavigationText" align="center" ><form name="mycalform">';
    output += '<select name="nsCalMonthSel" onchange="changeMonth(mycalform.nsCalMonthSel);">';
    for (m=1; m<=12; m++) {
        if (m == Month) output += '<option value="' + m + '" selected>' + nsCalnames[m] + '<\/OPTION>';
        else            output += '<option value="' + m + '">'          + nsCalnames[m] + '<\/OPTION>';
    }
    output += '<\/SELECT>';
    output += '<input type="text" value="'+Year+'" size=4 maxlength=4 onchange="changeYear(this);" name="nsCalMynewyear" onkeydown="cal_keydown(this);"><br/><a  class="CalNavigationText" href="javascript:;" onclick="changeMonthbycount(-1);">&lt;&lt;</a>  <a class="CalNavigationText" href="javascript:;" onclick="cal_gettoday();">TODAY</a> <a  class="CalNavigationText" href="javascript:;" onclick="changeMonthbycount(1);">&gt;&gt;</a></td></form>';
    output += '<td class="CalNavigationText"><a  class="CalNavigationText" href="javascript:;" onclick="changeMonthbycount(12);">+ year</a><br/><a  class="CalNavigationText" href="javascript:;" onclick="changeMonthbycount(-12);">- year</a></td></tr></table>';
    output += '</td></tr></table>';

    firstDay = new Date(Year,Month-1,1);
    startDay = firstDay.getDay();
    if (((Year % 4 == 0) && (Year % 100 != 0)) || (Year % 400 == 0))
         nsCaldays[2] = 29;
    else
         nsCaldays[2] = 28;
    output += '<table border=1 cellpadding="0" cellspacing=1 bgcolor="#FFFFFF"><tr>';
    for (i=0; i<7; i++)
        output += '<td  class="CalDateHeaderText" width=25>' + nsCaldow[i] +'</td>';
    output += '<\/TR><tr>';
    var column = 0;
    var lastMonth = Month - 1;
    if (lastMonth == 0) lastMonth = 12;
    for (i=0; i<startDay; i++, column++)
        output += '<td class='+(column==0?'CalWeekendGrey':'CalWeekdayGrey')+'>&nbsp;<\/TD>';
    for (i=1; i<=nsCaldays[Month]; i++, column++) {
        output += '<td class='+((column==0)||(column==6)?'CalWeekendText':'CalWeekdayText')+'>' + '<a class='+((column==0)||(column==6)?(i==cal_day?'CalWeekendTodayText':'CalWeekendText'):(i==cal_day?'CalTodayText':'CalWeekdayText'))+' HREF="javascript:changeDay(' + i + ')">' + i + '<\/A>' +'<\/TD>';
        if (column == 6) {
            output += '<\/TR><tr>';
            column = -1;
        }
    }
    if (column > 0) {
        for (i=1; column<7; i++, column++)
	        output += '<td class='+(column==6?'CalWeekendGrey':'CalWeekdayGrey')+'>' + i + '<\/TD>';
    }
    output += '<\/TR><\/TABLE>';
    output += '<\/TD><\/TR><\/table>';
    return output;
}

document.write( '<style type="text/css">');
document.write( '.CalOuterColor { background:#4C467E }');
document.write( '.CalInnerColor { background:#8888AA }');
document.write( '.CalHeaderText { font-size: 10pt;Font-Family: verdana; color:white;Font-Weight: bold  }');
document.write( 'A.CalHeaderText {color:#FFFFFF; text-decoration:none}');
document.write( 'A.CalHeaderText:hover {color:#FFFFFF ; text-decoration: underline}');
document.write( 'A.CalHeaderText:active {color:#FFFFFF ; text-decoration: none}');
document.write( '.CalNavigationText { font-size: 10pt;Font-Family: verdana; color:#000000  }');
document.write( 'A.CalNavigationText {color:#FFFFFF; text-decoration:none}');
document.write( 'A.CalNavigationText:hover {color:#FF0000 ; text-decoration: underline}');
document.write( 'A.CalNavigationText:active {color:#FFFFFF ; text-decoration: none; Text-Transform : None ;}');
document.write( '.CalDateHeaderText { font-size: 10pt;Font-Family: verdana; color:#00008b;background:#FFFFFF;Font-Weight: bold ;text-align:center  }');
document.write( '.CalWeekdayText { font-size: 10pt;Font-Family: verdana; color:#00008b;background:#FFFFFF;text-align:center }');
document.write( 'A.CalWeekdayText {color:#00008b; text-decoration:none}');
document.write( 'A.CalWeekdayText:hover {color:#FF0000 ; text-decoration: underline}');
document.write( 'A.CalWeekdayText:active {color:#00008b ; text-decoration: none}');
document.write( '.CalWeekendText { font-size: 10pt;Font-Family: verdana; color:#00008b;background:#E0E0E0;text-align:center }');
document.write( 'A.CalWeekendText {color:#00008b; text-decoration:none}');
document.write( 'A.CalWeekendText:hover {color:#FF0000 ; text-decoration: underline}');
document.write( 'A.CalWeekendText:active {color:#00008b ; text-decoration: none}');
document.write( '.CalTodayText { font-size: 10pt;Font-Family: verdana; color:#FF0000;background:#FFFFFF;text-align:center; Font-Weight: bold ;}');
document.write( 'A.CalTodayText {color:#00008b; text-decoration:none}');
document.write( 'A.CalTodayText:hover {color:#FF0000 ; text-decoration: underline}');
document.write( 'A.CalTodayText:active {color:#00008b ; text-decoration: none}');
document.write( '.CalWeekendTodayText { font-size: 10pt;Font-Family: verdana; color:#FF0000;background:#E0E0E0;text-align:center; Font-Weight: bold ;}');
document.write( 'A.CalWeekendTodayText {color:#00008b; text-decoration:none}');
document.write( 'A.CalWeekendTodayText:hover {color:#FF0000 ; text-decoration: underline}');
document.write( 'A.CalWeekendTodayText:active {color:#00008b ; text-decoration: none}');
document.write( '.CalWeekdayGrey { font-size: 10pt;Font-Family: verdana; color:#808080;background:#FFFFFF;text-align:center }');
document.write( '.CalWeekendGrey { font-size: 10pt;Font-Family: verdana; color:#808080;background:#E0E0E0;text-align:center }');
document.write( '</style>');
document.write( '<div id=Mycal style="position:absolute;display:none;z-index: 10;">');
document.write(myCalendar(cal_month,cal_year));
document.write( '</div>');
