
function showProjects(){
	$('#projectLibrary .client'+$('#client').val()).clone().appendTo($('#project').empty().append("<option value='NULL' class='all'>---Select---</option>"));
	if($('#project').get(0).options.length == 2)
			$('project').selectedIndex = 1;
	showDeliverables();
}
function showProjectsT(){
	$('#projectLibrary .client'+$('#client').val()).clone().appendTo($('#project').empty().append("<option value='all' class='all'>All Projects</option>"));
	if($('#project').get(0).options.length == 2)
			$('#project').get(0).selectedIndex = 1;
	showDeliverablesT();
}
function showProjectsB(){
	$('#projectLibrary .client'+$('#client').val()).clone().appendTo($('#project').empty().append("<option value='NULL' class='all'>No Change</option>"));

	if($('#project').get(0).options.length == 2)
			$('#project').get(0).selectedIndex = 1;
	showDeliverablesB();
}


function showDeliverables(){
	$('#deliverableLibrary .project'+$('#project').val()).clone().appendTo($('#deliverable').empty().append("<option value='NULL' class='all'>---Select---</option>"));
try{
	if($('#deliverable').get(0).options.length == 2)
			$('#deliverable').get(0).selectedIndex = 1;
	}catch(e){}

}
function showDeliverablesT(){
	$('#deliverableLibrary .project'+$('#project').val()).clone().appendTo($('#deliverable').empty().append("<option value='all' class='all'>All Deliverables</option>"));
try{
	if($('#deliverable').options.length == 2)
			$('#deliverable').get(0).selectedIndex = 1;
	}catch(e){}
		

}
function showDeliverablesB(){
	$('#deliverableLibrary .project'+$('#project').val()).clone().appendTo($('#deliverable').empty().append("<option value='NULL' class='all'>No Change</option>"));
try{
	if($('#deliverable').get(0).options.length == 2)
			$('#deliverable').get(0).selectedIndex = 1;
	}catch(e){}

}


function calculateDur()	{
	
	var startTime = (($('#shour').val() != 12 )? parseInt($('#shour').val()) + ($('#sam').val()*12): ( ($('#sam').val()==1)? 12:0)) + ($('#sminute').val() / 60);
	var endTime   = (($('#ehour').val() != 12 )? parseInt($('#ehour').val()) + ($('#eam').val()*12): ( ($('#eam').val()==1)? 12:0)) + ($('#eminute').val() / 60);
	var duration = Math.round((endTime - startTime)*100)/100;
	
	if ( duration > 0 )
		$('#duration').val( duration);
	
	if ( duration < 0 ){
	
		if($('#ehour').val() == $('#shour').val() && $('#sam').val() == $('#eam').val() && $('#shour').val() < 12 )
			$('#ehour').val( parseInt($('#ehour').val()) + 1);
			
		else if( $('#eam').val()==0 )
			$('#eam').val(1);
			
		else{
			
			$('#ehour').val( $('#shour').val());
			$('#eminute').val( $('#sminute').val());
			$('#eam').val( $('#sam').val());
		}
		calculateDur();
	}
}
function checkScope(rate){

//window.alert(rate);

	if (rate == 0 ){
		$('#ClientBillable').get(0).style.display = 'none';
		$('#idnBillable').get(0).style.display = 'none';
		$('#Internal').get(0).style.display = 'block';
		$('#intern').get(0).click();
	}else{
		$('#ClientBillable').get(0).style.display = 'block';
		$('#idnBillable').get(0).style.display = 'block';
		$('#Internal').get(0).style.display = 'none';
		if ($('#intern').get(0).checked)
			$('#insco').get(0).click();
	}
}
function checkScopeB(rate){
	if (rate == 0 ){
		$('#nochangebillable').get(0).style.display = 'none';
		$('#ClientBillable').get(0).style.display = 'none';
		$('#idnBillable').get(0).style.display = 'none';
		$('#Internal').get(0).style.display = 'block';
		$('#intern').get(0).click();
	}else{
		$('#nochangebillable').get(0).style.display = 'block';
		$('#ClientBillable').get(0).style.display = 'block';
		$('#idnBillable').get(0).style.display = 'block';
		$('#Internal').get(0).style.display = 'none';
		if (!($('#outsco').get(0).checked || $('#insco').checked))
			$('#bilnoch').get(0).click();
	}
}

function sortBy(order){
	$('#orderby').val(order);
	$('#chooseReport').get(0).submit();
	
}

weekdays = Array( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
function showDayOfWeek(weekday,day,month,year){
	
	var currentDate = new Date();
	
	currentDate.setFullYear( $('#'+year).val(), $('#'+month).val()-1,$('#'+day).val() );
//	currentDate.setMonth( $(month).value);
//	currentDate.setDate( $(day).value );
	
	$('#'+weekday).get(0).innerHTML = weekdays[currentDate.getDay()];
	
	$('#'+year).val( currentDate.getFullYear());
	$('#'+month).val( currentDate.getMonth()+1); 
	$('#'+day).val( currentDate.getDate());

}
function populate(client,project,deliverable,phase,rate){
	  		
	if(client || client === 0) 	$('#client').val(client);
	else		$('#client').val('NULL');
	showProjects();
	
	if(project || project === 0) $('#project').val(project);
	else 		$('#project').val('NULL');
	showDeliverables();

	if(phase || phase === 0) $('#phase').val(phase);
	else 			$('#phase').val('NULL');

	
	if(deliverable || deliverable === 0) $('#deliverable').val(deliverable);
	else 			$('#deliverable').val('NULL');
	
	
	if(rate || rate === 0) 	$('#rate').val(rate);
	else	 	$('#rate').val('NULL');
	checkScope($('#rate').val());
	
	

}
