// Execute a program or open a file
function Execute(path){
	var folder = path.substr(0, path.lastIndexOf('\\'));
	var objShell = new ActiveXObject("Shell.Application");
	objShell.ShellExecute(path, '', folder, 'open', 1);
}


// Opens Explorer in the specified directory
function Explore(directory){ 
	var objShell = new ActiveXObject("Shell.Application"); 
	objShell.ShellExecute('explorer', '/n,/e,' + directory, directory, 'open', 1); 
} 


// Opens a specified file in EditPlus
function EditPlus(path){
	var objShell = new ActiveXObject("Shell.Application");
	objShell.ShellExecute('C:\\Program Files\\EditPlus 2\\editplus.exe', path, 'C:\\Program Files\\EditPlus 2\\', 'open', 1);
}


// Return the contents of a specified file
function readFile(path){
	myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
	file = myActiveXObject.OpenTextFile(path, 1);
	var content = file.ReadAll();
	file.Close();
	return content;
}


// Write the specifed content to the specified file
function writeFile(path, content){
	myActiveXObject = new ActiveXObject("Scripting.FileSystemObject");
	file = myActiveXObject.CreateTextFile(path, true);
	file.Write(content);
	file.Close();
}


// Eject DVD/CD tray 
function openDrive(driveNumber){
	var oWMP = new ActiveXObject("WMPlayer.OCX"); 
	oWMP.cdromCollection.Item(driveNumber).Eject();
}


function writeCalendar(){
	var day_of_week		= new Array('S','M','T','W','T','F','S');
	var month_of_year	= new Array('January','February','March','April','May','June','July','August','September','October','November','December');

	var Calendar = new Date();

	var year	= Calendar.getYear();	// Returns year
	var month	= Calendar.getMonth();  // Returns month (0-11)
	var today	= Calendar.getDate();   // Returns day (1-31)
	var weekday = Calendar.getDay();    // Returns day (1-31)

	var cal;					// Used for printing

	Calendar.setDate(1);			// Start the calendar day at '1'
	Calendar.setMonth(month);		// Start the calendar month at now

	cal = '<h1>' + month_of_year[month]  + ' ' + year + '</h1>';

	for(index = 0; index < 7; index++){
		cal += '<span class="day"';
		if(weekday == index)
			cal += ' id="today"';
		cal += '>' + day_of_week[index] + '</span>';
	}

	cal += '<br />';

	for(index = 0; index < Calendar.getDay(); index++)
		cal += '<span class="date" id="blank"></span>';

	for(index = 0; index < 31; index++){
		if(Calendar.getDate() > index ){
			week_day = Calendar.getDay();
			if(week_day == 0)
				cal += '<br />';
			if(week_day != 7){
				var day  = Calendar.getDate();
				cal += '<span class="date"';
				if(today == Calendar.getDate())
					cal += ' id="now"';
				cal += ' title="' + day + "/" + (month+1) + "/" + year + '">' + day + '</span>';
			}
		}
		Calendar.setDate(Calendar.getDate()+1);
	}

	document.write(cal);
}


// block any JavaScript errors
function blockError(){return true;}

window.onerror = blockError;