// JavaScript Document
				
						
						
/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  &&                                                                                  &&
  &&                                                                                  &&
  &&             functions to insert characters or delete characters                  &&
  &&                                                                                  &&
  &&                                                                                  &&
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
 

//function is called to insert a char in a string when the ins function is being used
//function is called from runCalc(a) from enterDigits.js
function insertChar(a)
{
	var tempSt = numberArray[0].stringValue;

	//this line inserts the digit in the cursor position
	//cursor position is determined by back_arrow_insert(tempSt) (this page)
	tempSt = tempSt.substring(0,numberArray[0].cursorPosition) + a + tempSt.substring(numberArray[0].cursorPosition);

	numberArray[0].stringValue = tempSt;	//string value is changed to the new value with inserted digit

	document.stackForm.rowX.value = numberArray[0].stringValue;		//displays string value in X register
	
	//what happens when a digit is being inserted in scientific notation mode?
	//17 oct 2009 5:58 - it works, just don't 'get it'
	numberArray[0].decimalValue = parseFloat(numberArray[0].stringValue);	//converts decimal value back to float
	
	numberArray[0].insertFlag = 'no';	//no longer in the insert mode
	
	numberArray[0].enterFlag = 'no';	//'enter' was not the last thing hit
 										//this was added on 17 oct 2009 06:06
}
 
 
/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  

//function is called to delete a single char in a string when the ins function is being used
//function is called from cleanIt() from enable_disable_reset_functions.js
function deleteChar()
{
	var tempSt = numberArray[0].stringValue;
	
	//this line deletes the digit in the cursor position
	//cursor position is determined by back_arrow_delete(tempSt) (this page)
	tempSt = tempSt.substring(0,(numberArray[0].cursorPosition - 1))  + tempSt.substring(numberArray[0].cursorPosition);

	numberArray[0].stringValue = tempSt;	//string value is changed to the new value with inserted digit

	document.stackForm.rowX.value = numberArray[0].stringValue;				//displays string value in X register
	
	//what happens when a digit is being deleted in scientific notation mode?
	//17 oct 2009 5:58 - it works, just don't 'get it'
	numberArray[0].decimalValue = parseFloat(numberArray[0].stringValue);	//converts decimal value back to float
	
	numberArray[0].deleteFlag = 'no';	//no longer in the delete mode
	numberArray[0].enterFlag = 'no';	//'enter' was not the last thing hit
}


/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/ 


function back_arrow_insert(tempSt)
{
	tempSt = tempSt.substring(0, (numberArray[0].cursorPosition - 1)) + "_" + tempSt.substring((numberArray[0].cursorPosition - 1))

	document.stackForm.rowX.value = tempSt; 
	numberArray[0].cursorPosition -= 1;

	//if statement deletes the cursor from the front of the string
	if(numberArray[0].cursorPosition == -1)
	{
		document.stackForm.rowX.value = numberArray[0].stringValue;
		numberArray[0].insertFlag = 'no';
	}//end if	
}


/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  
  
function back_arrow_delete(tempSt)
{
	tempSt = tempSt.substring(0, (numberArray[0].cursorPosition - 1)) + "_" + tempSt.substring((numberArray[0].cursorPosition - 1))

	document.stackForm.rowX.value = tempSt; 
	numberArray[0].cursorPosition -= 1;

	//if statement deletes the cursor from the front of the string
	if(numberArray[0].cursorPosition == 0)
	{
		document.stackForm.rowX.value = numberArray[0].stringValue;
		numberArray[0].deleteFlag = 'no';
	}//end if			
}


/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  
  
function back_arrow()
{
	numberArray[0].stringValue = numberArray[0].stringValue.substring(0, numberArray[0].stringValue.length -1);	
	
	if(numberArray[0].stringValue.length == 0)
	{
		numberArray[0].decimalValue = 0;
		numberArray[0].stringValue = 0;
		
		numberArray[0].enterFlag = 'yes';	//the computer thinks enter is last key entered so that when another
							//number is entered the '0' will dissappear
	}//end if
	
	numberArray[0].decimalValue = numberArray[0].stringValue * 1;
	
	document.stackForm.rowX.value = numberArray[0].stringValue;
}


/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  
  
//function 'enters' number after 'enter' key is hit
function backUp()
{
	var tempstring = numberArray[0].stringValue;

	//first if works back arrow for insert
	if(numberArray[0].insertFlag == 'yes' && numberArray[0].cursorPosition != -1)
	{
		back_arrow_insert(tempstring);
	}//end if
	else//works back arrow for delete
	{
		if(numberArray[0].deleteFlag == 'yes' && numberArray[0].cursorPosition != -1)
		{
			back_arrow_delete(tempstring);	
		}//end if
		else//works back arrow for consecutive delete
		{
			if(numberArray[0].singleOp != "yes" && numberArray[0].enterFlag != 'yes')
			{
				back_arrow();
			}//end if
		}//end else
	}//end else

}//end function


/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  
  
function deleteIt()
{
	if(numberArray[0].deleteFlag == 'yes')
	{ 
		document.stackForm.rowX.value = numberArray[0].stringValue;
		numberArray[0].deleteFlag = 'no'; 
	}
	else
	{
	  	numberArray[0].cursorPosition = numberArray[0].stringValue.length;

	  	numberArray[0].deleteFlag = 'yes';

	  	backUp();
	}	
}
						
						
/*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
  
   
function insert()
{
	if(numberArray[0].insertFlag == 'yes')
	{ 
		document.stackForm.rowX.value = numberArray[0].stringValue;
		numberArray[0].insertFlag = 'no'; 
		
	}
	else
	{
	  	numberArray[0].cursorPosition = numberArray[0].stringValue.length;

	  	numberArray[0].insertFlag = 'yes';
		
		backUp();

	}
}



