/*
 *	jscript functions
 *	v2.2
 *
 *	Author: Carl Fretwell
 *	Copyright (c) 1999 - 2004, All Rights Reserved
 *
 *	Usage: functionName(functionVariables,...);
 *
 */


/*
 *	Hide or show many html elements
 *
 */
	function tierElement(s_trId){
		var myElement1 = document.getElementById(s_trId);
		if(myElement1.style.display == 'none'){
			myElement1.style.display = '';
		}
		else{
			myElement1.style.display = 'none';
		}
	}
	
/*
 *	Hide many html elements
 *
 */
	function tierElement_HIDE(s_trId){
		var myElement1 = document.getElementById(s_trId);
		myElement1.style.display = 'none';
	}


/*
 *	Show many html elements
 *
 */
	function tierElement_SHOW(s_trId){
		var myElement1 = document.getElementById(s_trId);
		myElement1.style.display = '';
	}

// Popup window
	function WINDOW_open(strURL, intWidth, intHeight) {
		var day = new Date();
		var id = day.getTime();
		eval("page" + id + " = window.open(strURL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=' + intWidth + ',height=' + intHeight + ', left=100, top=100');");
	}

/*
 *	Countup COUNTER variables
 *
 */
	var COUNTERID = 0;
	var tHours = 00;
	var tsHours = '00';
	var tMinutes = 00;
	var tsMinutes = '00';
	var tSeconds = 00;
	var tsSeconds = '00';
	var tStartTimeSet = false;
	var tStartTime = '00:00:00';


/*
 *	Updates the COUNTER
 *
 */
	function COUNTER_update() {
	   if(COUNTERID) {
	      clearTimeout(COUNTERID);
	      clockID  = 0;
	   }
	   
	   tSeconds = (Math.round(tSeconds) + 1);
	   tsSeconds = '' + tSeconds;
	   
	   if(tSeconds == 60){
	   	tSeconds = 00;
	   	tsSeconds = '00';
	   	tMinutes = (Math.round(tMinutes) + 1);
	   	tsMinutes = '' + tMinutes;
		}
		
		if(tMinutes == 60){
			tMinutes = 00;
			tsMinutes = '00';
			tHours = (Math.round(tHours) + 1);
			tsHours = '' + tHours;
		}
		
	   if(tsHours.length == 1){
	   	 tsHours = '0' + tHours;
		}
		else if(tsMinutes.length == 1){
	   	 tsMinutes = '0' + tMinutes;
		}
		else if(tsSeconds.length == 1){
	   	 tsSeconds = '0' + tSeconds;
		}
		
		document.frmHeader.txtCounter.value = '' + tsHours + ':' + tsMinutes + ':' + tsSeconds;
	   COUNTERID = setTimeout("COUNTER_update()", 1000);
	}


/*
 *	Starts the COUNTER
 *
 */
	function COUNTER_start(){
		
		if(!COUNTERID){
			if(!tStartTimeSet){
				tStartTimeSet = true;
				/*
				tHours = parent.fraAccountHeader.document.frmHeader.txtCounter.value.substr(0,2);
				tsHours = parent.fraAccountHeader.document.frmHeader.txtCounter.value.substr(0,2);
				
				tMinutes = parent.fraAccountHeader.document.frmHeader.txtCounter.value.substr(3,2);
				tsMinutes = parent.fraAccountHeader.document.frmHeader.txtCounter.value.substr(3,2);
			
				tSeconds = parent.fraAccountHeader.document.frmHeader.txtCounter.value.substr(6,5);
				tsSeconds = parent.fraAccountHeader.document.frmHeader.txtCounter.value.substr(6,5);
				*/
			}
			document.frmHeader.txtCounter.value = '' + tsHours + ':' + tsMinutes + ':' + tsSeconds;
			COUNTERID  = setTimeout("COUNTER_update()", 1000);
		}
		else{
			clearTimeout(COUNTERID);
	      COUNTERID = 0;
	      COUNTER_reset();
		}
	}


/*
 *	Pauses the COUNTER
 *
 */
	function COUNTER_pause() {
	   if(COUNTERID) {
	      clearTimeout(COUNTERID);
	      COUNTERID = 0;
	   }
	}


/*
 *	Resets the COUNTER to hh:mm:ss
 *
 */
	function child_COUNTER_reset(){
		tHours = 00;
		tsHours = '00';
		tMinutes = 00;
		tsMinutes = '00';
		tSeconds = -1;
		tsSeconds = '-1';
		frmHeader.txtCounter.value = '00:00:00';
	}
	
	function COUNTER_continue(hour,minutes,seconds){
		tHours = hour;
		tsHours = '' + hour;
		tMinutes = minutes;
		tsMinutes = '' + minutes;
		tSeconds = seconds;
		tsSeconds = '' + seconds;
		document.frmHeader.txtCounter.value = '' + tsHours + ':' + tsMinutes + ':' + tsSeconds;
	}
	


	//	Remove all dropdown options from 'OptionList'
		function ClearOptions(OptionList) {
		   for(x = OptionList.length; x >= 0; x--) {
		      OptionList[x] = null;
		   }
		}

	//	Add a dropdown option to 'OptionList'
		function AddOptions(OptionList, OptionValue, OptionText) {
	   	// Add option to the bottom of the list
	   	OptionList[OptionList.length] = new Option(OptionText, OptionValue);
		}
		
		
//
//	Display the calendar
//
	function CALENDAR_display(){
		//window.open('calendar.html', 'page_calendar', 'toolbar=0,scrollbars=0,location=0,status=0,menubar=0,resizable=0,width=250,height=150,left=262,top=134');
		//document.getElementById('divCalendar').style.visibility='visible';
		
		if(document.getElementById('div_calendar').style.visibility == 'visible'){
			document.getElementById('div_calendar').style.visibility = 'hidden';
			document.getElementById('div_calendar').style.display = 'none';
		}
		else{
			document.getElementById('div_calendar').style.visibility = 'visible';
			document.getElementById('div_calendar').style.display = 'inline';
			//document.body.clientHeight+sT
			//document.getElementById('div_calendar').style.left = 88;//(document.body.clientHeight+88);
		}
	}

	



//
//	The user as choosen a different client
//
	function CLIENT_onchange(){
		tierElement_HIDE('tr_InsertNewProject');
		tierElement_HIDE('tr_InsertNewActivity');
		tierElement_HIDE('tr_InsertNew');
		
		//	document.getElementById('div_client_other').style.visibility = 'hidden';
		//	document.getElementById('div_client_other').style.display = '';
		
		ClearOptions(document.frmInput.cmbProjects_REQ_);
		AddOptions(document.frmInput.cmbProjects_REQ_, '', '-');
		
		if(document.frmInput.cmbClients_REQ_.value == 'INSERT_NEW'){
			tierElement_SHOW('tr_InsertNew');
			//document.getElementById('div_client_other').style.visibility = 'visible';
			//document.getElementById('div_client_other').style.display = 'inline';
			document.frmInput.btnGo.disabled = true;
		}
		else{
			PROJECTS_populate(document.frmInput.cmbClients_REQ_.value);
			document.frmInput.btnGo.disabled = false;
		}
		
		if(document.frmInput.cmbProjects_REQ_.value == 'INSERT_NEW'){
			document.frmInput.cmbProjects_REQ_.value = '';
		}

		if(document.frmInput.cmbActivities_REQ_.value == 'INSERT_OTHER'){
			document.frmInput.cmbActivities_REQ_.value = '';
		}
	}
	

//
//	The user as choosen a different project
//
	function PROJECT_onchange(){
		tierElement_HIDE('tr_InsertNew');
		tierElement_HIDE('tr_InsertNewActivity');
		tierElement_HIDE('tr_InsertNewProject');
		
		if(document.frmInput.cmbProjects_REQ_.value == 'INSERT_NEW'){
			tierElement_SHOW('tr_InsertNewProject');
			document.frmInput.btnGo.disabled = true;
		}
		else{
			document.frmInput.btnGo.disabled =false;
		}
		
		if(document.frmInput.cmbClients_REQ_.value == 'INSERT_NEW'){
			document.frmInput.cmbClients_REQ_.value = '';
			document.frmInput.cmbProjects_REQ_.value = '';
		}
		
		if(document.frmInput.cmbActivities_REQ_.value == 'INSERT_OTHER'){
			document.frmInput.cmbActivities_REQ_.value = '';
		}
	}
	

//
//	The user as choosen a different activity
//
	function ACTIVITY_onchange(){
		tierElement_HIDE('tr_InsertNew');
		tierElement_HIDE('tr_InsertNewProject');
		tierElement_HIDE('tr_InsertNewActivity');
		
		if(document.frmInput.cmbActivities_REQ_.value == 'INSERT_OTHER'){
			tierElement_SHOW('tr_InsertNewActivity');
			document.frmInput.btnGo.disabled = true;
		}
		else{
			document.frmInput.btnGo.disabled =false;
		}
		
		if(document.frmInput.cmbProjects_REQ_.value=='INSERT_NEW'){
			document.frmInput.cmbProjects_REQ_.value = '';
			document.frmInput.cmbClients_REQ_.value = '';
		}
		
		if(document.frmInput.cmbClients_REQ_.value=='INSERT_NEW'){
			document.frmInput.cmbProjects_REQ_.value = '';
			document.frmInput.cmbClients_REQ_.value = '';
		}		
	}
	

	function inCell(cell, newcolor){
		if(!cell.contains(event.fromElement)){
			cell.bgColor = newcolor;
		}
	}
	
	function outCell(cell, newcolor){
		if(!cell.contains(event.toElement)){
			cell.bgColor = newcolor;
		}
	}
	
// The input form was submitted
	function INPUT_form_submit(){
		document.frmInput.txtHiddenCounter.value = parent.fraAccountHeader.document.frmHeader.txtCounter.value;
		document.frmInput.txtPageLoad.value = parent.fraAccountHeader.document.frmHeader.txtPageLoad.value;
		document.frmInput.txtPageLoadNoSeconds.value = parent.fraAccountHeader.document.frmHeader.txtPageLoadNoSeconds.value;
		document.frmInput.txtPageLoadTimestamp.value = parent.fraAccountHeader.document.frmHeader.txtPageLoadTimestamp.value;
		return true;
	}

	



//
//	Display the expanded details box
//
	function DETAILS_hide(){
		document.frmInput.txtInput.style.overflow = 'hidden';
		document.frmInput.txtInput.style.height = '16px';
	}

	function DETAILS_show(){
		document.frmInput.txtInput.style.overflow = '';
		document.frmInput.txtInput.style.height = '88px';
	}
	
	
	var DETAILS_updated = false;
	function DETAILS_update(){
		if(DETAILS_updated == false){
			document.frmInput.txtDetailsExpanded.value = document.frmInput.txtInput.value;
			DETAILS_updated = true;
		}
	}


	function timesheetSetValues(varDate, varClient, varChargeable, varProject, varActivity, varDetails){
		document.frmInput.txtDate_REQ_.value = varDate;
		document.frmInput.cmbClients_REQ_.value = varClient;
		CLIENT_onchange();
		document.frmInput.optChargeable_REQ_[(varChargeable == 0) ? 1 : 0].checked = true;
		document.frmInput.cmbProjects_REQ_.value = varProject;
		document.frmInput.cmbActivities_REQ_.value = varActivity;
		document.frmInput.txtInput.value = varDetails;
	}
