
/* 
	Traveller's Aid Society Access Terminal

	     by Perry Horner 2001
	  

  The Traveller game in all forms is owned by Far Future Enterprises. 
  Copyright 1977 - 2007 Far Future Enterprises. Traveller is a registered 
  trademark of Far Future Enterprises. Far Future permits web sites and 
  fanzines for this game, provided it contains this notice, that Far Future 
  is notified, and subject to a withdrawal of permission on 90 days notice. 
  The use of this program is for personal, non-commercial use only. 
  Any use of Far Future Enterprises's copyrighted material or trademarks 
  anywhere in this program and its files should not be viewed as a challenge 
  to those copyrights or trademarks. In addition, any program/ article/ file 
  cannot be republished or distributed without the consent of the author who 
  contributed it. 
  

   The bulk of the code is by Perry Horner (firetaste@yahoo.com)


 
*/


int checkmouseboundsAccounts()
{  
	
	int txtcounter=0;
	

	//check to see if selection is on the grid
	if (mouse_position.X<1) return ACCOUNTSERVICEWINDOW;
	if (mouse_position.Y<1) return ACCOUNTSERVICEWINDOW;
	
	//BANKING
	if ((mouse_position.X>294) && (mouse_position.X<691) && (mouse_position.Y>233) && (mouse_position.Y<282)) {

		//Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound
		/*
		addtoaccount = 0;
		displaybalance = 0;
		tempaccount[0] = '\0';
		
		TASWindow=BANKINGWINDOW;
		TASCurrentMenuWindow=ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
		*/
	}

	//LOANS
	if ((mouse_position.X>294) && (mouse_position.X<691) && (mouse_position.Y>356) && (mouse_position.Y<403)) {

		//Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound
		/*
		TASWindow = LOANWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return LOANWINDOW;
		*/
	}

	//PERSONAL
	if ((mouse_position.X>294) && (mouse_position.X<691) && (mouse_position.Y>473) && (mouse_position.Y<522)) {

		//Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound
		/*
		TASWindow = PERSONALWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return PERSONALWINDOW;
		*/
	}

	//return to MAIN WINDOW MENU
	if ((mouse_position.X>854) && (mouse_position.X<1015) && (mouse_position.Y>745) && (mouse_position.Y<760)) {

		//Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		newsdatacounter=0;
		TASWindow=MAINMENUWINDOW;
        TASCurrentMenuWindow=MAINMENUWINDOW;
		//clear bitmaps to save memmory
		//ClearAccounts();
		backsurf = MainMenuBackground;
		driver->draw2DImage(backsurf, core::position2d<s32>(0, 0), core::rect<s32>(0, 0, 1024, 768), 0, video::SColor(255, 255, 255, 255), true);
		return MAINMENUWINDOW;
	} 
	
	
	return ACCOUNTSERVICEWINDOW;

}



int checkmouseboundsBank()
{  
	/*
	int xlookup=0,ylookup=0,templines=0;
	char tempname[81];
	char tempfile[255]; //filename for message
	FILE  *fd1=NULL;

	//displaybalance - display account balance on 1, add to balance on 2, withdraw on 3
	//tempacount - temporary value added (character);

   SDL_GetMouseState(&xlookup, &ylookup);

    xlookup=xlookup-100;
	ylookup=ylookup-120;

	//check to see if selection is on the grid
	if (xlookup<1) return BANKINGWINDOW;
	if (ylookup<1) return BANKINGWINDOW;

	
	//Display ACCOUNT BALANCE
	if ((xlookup+100>531)&&(xlookup+100<729)&&(ylookup+120>391)&&(ylookup+120<438)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		displaybalance = 1;
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}

	//Add to BALANCE
	if ((xlookup + 100>531) && (xlookup + 100<729) && (ylookup + 120>482) && (ylookup + 120<527)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		displaybalance = 2;
		addtoaccount = 0;
		withdrawaccount = 0;
		keypresscount = 0;
		sprintf(tempaccount, "0\0");
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}

	//Withdraw from BALANCE
	if ((xlookup + 100>531) && (xlookup + 100<729) && (ylookup + 120>568) && (ylookup + 120<616)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		displaybalance = 3;
		withdrawaccount = 0;
		addtoaccount = 0;
		keypresscount = 0;
		sprintf(tempaccount, "0\0");
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}

	//return to ACCOUNT SERVICES window
	if ((xlookup+100>854)&&(xlookup+100<1015)&&(ylookup+120>745)&&(ylookup+120<760)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		TASWindow = ACCOUNTSERVICEWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		//clear bitmaps to save memmory
		return ACCOUNTSERVICEWINDOW;
	} 

	//Keypad 1
	if ((xlookup + 100>101) && (xlookup + 100<207) && (ylookup + 120>166) && (ylookup + 120<276) && ((displaybalance==2)||(displaybalance==3)) && (keypresscount<21)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		SDL_Delay(50);
		strncat(tempaccount, "1", sizeof(char));
		keypresscount++;
		addtoaccount = 1;
		withdrawaccount = 1;
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	//Keypad 2
	if ((xlookup + 100>224) && (xlookup + 100<327) && (ylookup + 120>166) && (ylookup + 120<276) && ((displaybalance == 2) || (displaybalance == 3)) && (keypresscount<21)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		SDL_Delay(50);
		strncat(tempaccount, "2", sizeof(char));
		keypresscount++;
		addtoaccount = 1;
		withdrawaccount = 1;
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	//Keypad 3
	if ((xlookup + 100>346) && (xlookup + 100<449) && (ylookup + 120 > 166) && (ylookup + 120 < 276) && ((displaybalance == 2) || (displaybalance == 3)) && (keypresscount<21)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		SDL_Delay(50);
		strncat(tempaccount, "3", sizeof(char));
		keypresscount++;
		addtoaccount = 1;
		withdrawaccount = 1;
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	//Keypad 4
	if ((xlookup + 100>101) && (xlookup + 100<207) && (ylookup + 120>293) && (ylookup + 120<396) && ((displaybalance == 2) || (displaybalance == 3)) && (keypresscount<21)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		SDL_Delay(50);
		strncat(tempaccount, "4", sizeof(char));
		keypresscount++;
		addtoaccount = 1;
		withdrawaccount = 1;
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	//Keypad 5
	if ((xlookup + 100>224) && (xlookup + 100<327) && (ylookup + 120>293) && (ylookup + 120<396) && ((displaybalance == 2) || (displaybalance == 3)) && (keypresscount<21)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		SDL_Delay(50);
		strncat(tempaccount, "5", sizeof(char));
		keypresscount++;
		addtoaccount = 1;
		withdrawaccount = 1;
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	//Keypad 6
	if ((xlookup + 100>346) && (xlookup + 100<449) && (ylookup + 120 > 293) && (ylookup + 120 < 396) && ((displaybalance == 2) || (displaybalance == 3)) && (keypresscount<21)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		SDL_Delay(50);
		strncat(tempaccount, "6", sizeof(char));
		keypresscount++;
		addtoaccount = 1;
		withdrawaccount = 1;
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	//Keypad 7
	if ((xlookup + 100>101) && (xlookup + 100<207) && (ylookup + 120>415) && (ylookup + 120<523) && ((displaybalance == 2) || (displaybalance == 3)) && (keypresscount<21)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		SDL_Delay(50);
		strncat(tempaccount, "7", sizeof(char));
		keypresscount++;
		addtoaccount = 1;
		withdrawaccount = 1;
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	//Keypad 8
	if ((xlookup + 100>224) && (xlookup + 100<327) && (ylookup + 120>415) && (ylookup + 120<523) && ((displaybalance == 2) || (displaybalance == 3)) && (keypresscount<21)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		SDL_Delay(50);
		strncat(tempaccount, "8", sizeof(char));
		keypresscount++;
		addtoaccount = 1;
		withdrawaccount = 1;
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	//Keypad 9
	if ((xlookup + 100>346) && (xlookup + 100<449) && (ylookup + 120 > 415) && (ylookup + 120 < 523) && ((displaybalance == 2) || (displaybalance == 3)) && (keypresscount<21)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		SDL_Delay(50);
		strncat(tempaccount, "9", sizeof(char));
		keypresscount++;
		addtoaccount = 1;
		withdrawaccount = 1;
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	//Keypad 0
	if ((xlookup + 100>224) && (xlookup + 100<327) && (ylookup + 120>544) && (ylookup + 120<650) && ((displaybalance == 2) || (displaybalance == 3)) && (keypresscount<21)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		SDL_Delay(50);
		strncat(tempaccount, "0", sizeof(char));
		keypresscount++;
		addtoaccount = 1;
		withdrawaccount = 1;
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	//Keypad CANCEL
	if ((xlookup + 100>101) && (xlookup + 100<207) && (ylookup + 120>544) && (ylookup + 120<650) && ((displaybalance == 2) || (displaybalance == 3))) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		displaybalance = 0;
		addtoaccount = 0;
		withdrawaccount = 0;
		keypresscount = 0;
		strcpy(tempaccount, "\0");
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	//Keypad ENTER
	if ((xlookup + 100>346) && (xlookup + 100<449) && (ylookup + 120 > 544) && (ylookup + 120 < 650) && ((displaybalance == 2) || (displaybalance == 3))) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		if (displaybalance == 2){
			//add to account balance
			addtoaccount = accountbalance + atoi(tempaccount);
			if ((addtoaccount <= 2000000000) && (addtoaccount >= 0)){

				//send mail message with statement
				fd1 = NULL;
				sprintf(tempfile, "communications/messages/waiting/%d.msg", MemberNumber);
				fd1 = fopen(tempfile, "a+");
				fprintf(fd1, "%s\n", uName); //message recipient TO: (TAS member number or other name)
				fprintf(fd1, "\n", xbdestination); //message destination system or world
				fprintf(fd1, "%s\n", currentdate); //current send date
				fprintf(fd1, "Bank Account\n"); //sender username
				fprintf(fd1, "\n"); //sender TAS member number
				fprintf(fd1, "BANK ACCOUNT DEPOSIT\n");
				fprintf(fd1, "Previous balance:%d\n", accountbalance);
				fprintf(fd1, "Deposit amount:%d\n", atoi(tempaccount));
				fprintf(fd1, "\n");
				fprintf(fd1, "Ending balance:%d\n", addtoaccount);
				for (templines = 4; templines <= 19; templines++){
					fprintf(fd1, "\n");
				}
				fprintf(fd1, "~~~~\n");
				fclose(fd1);

				//send mail message to administrator with statement
				fd1 = NULL;
				sprintf(tempfile, "communications/messages/waiting/GENERIC.msg");
				fd1 = fopen(tempfile, "a+");
				fprintf(fd1, "Administrator\n"); //message recipient TO: (TAS member number or other name)
				fprintf(fd1, "\n", xbdestination); //message destination system or world
				fprintf(fd1, "%s\n", currentdate); //current send date
				fprintf(fd1, "Bank Account\n"); //sender username
				fprintf(fd1, "\n"); //sender TAS member number
				fprintf(fd1, "BANK ACCOUNT DEPOSIT for %s\n", uName);
				fprintf(fd1, "Previous balance:%d\n", accountbalance);
				fprintf(fd1, "Deposit amount:%d\n", atoi(tempaccount));
				fprintf(fd1, "\n");
				fprintf(fd1, "Ending balance:%d\n", addtoaccount);
				for (templines = 4; templines <= 19; templines++){
					fprintf(fd1, "\n");
				}
				fprintf(fd1, "~~~~\n");
				fclose(fd1);

				accountbalance = accountbalance + atoi(tempaccount);
			}
			SDL_BlitSurface(banking, NULL, backsurf, NULL);
			SDL_BlitSurface(backsurf, NULL, primsurf, NULL);
			SDL_UpdateRect(primsurf, 0, 0, 0, 0);
			PutString(backsurf, 552, 200, "Deposit Complete");
			SDL_BlitSurface(backsurf, NULL, primsurf, NULL);
			SDL_UpdateRect(primsurf, 0, 0, 0, 0);
			SDL_Delay(1000);
			SDL_BlitSurface(banking, NULL, primsurf, NULL);
			SDL_UpdateRect(primsurf, 0, 0, 0, 0);

			//write account balance
			sprintf(tempname, "accounts/bank/%d.txt", MemberNumber);
			fd1 = NULL;
			fd1 = fopen(tempname, "w");
				if (fd1){
					fprintf(fd1, "%d\n", accountbalance);
				}
			fclose(fd1);

		} //end if displaybalance = 2 deposit

		if (displaybalance == 3){
			//withdraw from account balance
			withdrawaccount = accountbalance;
			accountbalance = accountbalance - atoi(tempaccount);
		
			if (accountbalance < 0){
				accountbalance = withdrawaccount;
				SDL_BlitSurface(banking, NULL, backsurf, NULL);
				SDL_BlitSurface(backsurf, NULL, primsurf, NULL);
				SDL_UpdateRect(primsurf, 0, 0, 0, 0);
				PutString(backsurf, 552, 190, "Negative: Cancelled");
				SDL_BlitSurface(backsurf, NULL, primsurf, NULL);
				SDL_UpdateRect(primsurf, 0, 0, 0, 0);
				SDL_Delay(1000);
			}
			else {
				//send mail message with statement
				fd1 = NULL;
				sprintf(tempfile, "communications/messages/waiting/%d.msg", MemberNumber);
				fd1 = fopen(tempfile, "a+");
				fprintf(fd1, "%s\n", uName); //message recipient TO: (TAS member number or other name)
				fprintf(fd1, "\n", xbdestination); //message destination system or world
				fprintf(fd1, "%s\n", currentdate); //current send date
				fprintf(fd1, "Bank Account\n"); //sender username
				fprintf(fd1, "\n"); //sender TAS member number
				fprintf(fd1, "BANK ACCOUNT WITHDRAWL\n");
				fprintf(fd1, "Previous balance:%d\n", withdrawaccount);
				fprintf(fd1, "Withdrawl amount:%d\n", atoi(tempaccount));
				fprintf(fd1, "\n");
				fprintf(fd1, "Ending balance:%d\n", accountbalance);
					for (templines = 4; templines <= 19; templines++){
						fprintf(fd1, "\n");
					}
				fprintf(fd1, "~~~~\n");
				fclose(fd1);

				//send mail message to administrator with statement
				fd1 = NULL;
				sprintf(tempfile, "communications/messages/waiting/GENERIC.msg");
				fd1 = fopen(tempfile, "a+");
				fprintf(fd1, "Administrator\n"); //message recipient TO: (TAS member number or other name)
				fprintf(fd1, "\n", xbdestination); //message destination system or world
				fprintf(fd1, "%s\n", currentdate); //current send date
				fprintf(fd1, "Bank Account\n"); //sender username
				fprintf(fd1, "\n"); //sender TAS member number
				fprintf(fd1, "BANK ACCOUNT WITHDRAWL for %s\n", uName);
				fprintf(fd1, "Previous balance:%d\n", withdrawaccount);
				fprintf(fd1, "Withdrawl amount:%d\n", atoi(tempaccount));
				fprintf(fd1, "\n");
				fprintf(fd1, "Ending balance:%d\n", accountbalance);
					for (templines = 4; templines <= 19; templines++){
						fprintf(fd1, "\n");
					}
				fprintf(fd1, "~~~~\n");
				fclose(fd1);

				SDL_BlitSurface(banking, NULL, backsurf, NULL);
				SDL_BlitSurface(backsurf, NULL, primsurf, NULL);
				SDL_UpdateRect(primsurf, 0, 0, 0, 0);
				PutString(backsurf, 552, 200, "Withdrawl Complete");
				SDL_BlitSurface(backsurf, NULL, primsurf, NULL);
				SDL_UpdateRect(primsurf, 0, 0, 0, 0);
				SDL_Delay(1000);
				SDL_BlitSurface(banking, NULL, primsurf, NULL);
				SDL_UpdateRect(primsurf, 0, 0, 0, 0);
			}

			//write account balance
			sprintf(tempname, "accounts/bank/%d.txt", MemberNumber);
			fd1 = NULL;
			fd1 = fopen(tempname, "w");
			if (fd1){
				fprintf(fd1, "%d\n",accountbalance);
			}
			fclose(fd1);
		} //end if displaybalance= 3 withdrawl


		//free variables
		sprintf(characcountbalance, "%d\0", accountbalance);
		addtoaccount = 0;
		withdrawaccount = 0;
		displaybalance = 0;
		keypresscount = 0;
		strcpy(tempaccount, "\0");
		TASWindow = BANKINGWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		return BANKINGWINDOW;
	}
	*/
	return BANKINGWINDOW;
	
}



int checkmouseboundsLoan()
{
	/*
	int xlookup = 0, ylookup = 0, templines=0;
	char tempfile[80];
	SDL_Rect rect;
	FILE *fd1;

	rect.x = 0;
	rect.y = 0;
	rect.w = 1024;
	rect.h = 768;

	SDL_GetMouseState(&xlookup, &ylookup);

	xlookup = xlookup - 100;
	ylookup = ylookup - 120;

	//check to see if selection is on the grid
	if (xlookup<1) return LOANWINDOW;
	if (ylookup<1) return LOANWINDOW;

	
	//START Loan Button
	if ((xlookup + 100>711) && (xlookup + 100<847) && (ylookup + 120>587) && (ylookup + 120<624) && (loansubmit == 0)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		loanrequest = (char *)calloc((unsigned)strlen("            "), sizeof(char));
		UpdateTheScreen=1;
		loanborrow=1; //flag - 0 no borrow, 1 borrow amount submitted
		loanselection = 0;


		SDL_BlitSurface(loancredit, &rect, primsurf, &rect);
		SDL_BlitSurface(loancredit, &rect, backsurf, &rect);
		InitFont(arial_36_mac_green);
		SDL_UpdateRect(primsurf , 0 , 0 , 0 , 0 );
		
		SFont_Input(primsurf, 169, 615, 400, loanrequest);
		if (strlen(loanrequest)<1) {
			UpdateTheScreen=1;
			loanborrow=0; //flag - 0 no borrow, 1 borrow amount submitted
			TASWindow = LOANWINDOW;
			return LOANWINDOW;
		}
		if (atoi(loanrequest)>1000000000){
			loanborrow = 0;
		}
		if (loanborrow == 1){

			//calculate various interest and loan rates
			if (accountbalance < (int)(.1*atoi(loanrequest))) ratelevel = 0;
			if (accountbalance >= (int)(.1*atoi(loanrequest))) ratelevel = 10;
			if (accountbalance >= (int)(.2*atoi(loanrequest))) ratelevel = 20;
			if (accountbalance >= (int)(.3*atoi(loanrequest))) ratelevel = 30;
			if (accountbalance >= (int)(.5*atoi(loanrequest))) ratelevel = 50;
			if (accountbalance >= (int)(.7*atoi(loanrequest))) ratelevel = 70;
			if (accountbalance >= (int)(.8*atoi(loanrequest))) ratelevel = 80;
		}
		
	} //loan request

	//Bank selection
	if ((xlookup + 100 > 205) && (xlookup + 100<221) && (ylookup + 120 > 218) && (ylookup + 120<230) && (loanborrow == 1)&& (loansubmit==0)) {
		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound
		loanselection = 1;
	}
	if ((xlookup + 100 > 205) && (xlookup + 100<221) && (ylookup + 120 > 278) && (ylookup + 120<289) && (loanborrow == 1) && (loansubmit == 0)) {
		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound
		loanselection = 2;
	}
	if ((xlookup + 100 > 205) && (xlookup + 100<221) && (ylookup + 120 > 336) && (ylookup + 120<348) && (loanborrow == 1) && (loansubmit == 0)) {
		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound
		loanselection = 3;
	}
	if ((xlookup + 100 > 205) && (xlookup + 100<221) && (ylookup + 120 > 395) && (ylookup + 120<405) && (loanborrow == 1) && (loansubmit == 0)) {
		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound
		loanselection = 4;
	}

	//SUBMIT loan
	if ((xlookup + 100 > 720) && (xlookup + 100<835) && (ylookup + 120 > 660) && (ylookup + 120<695) && (loanborrow == 1) && (loansubmit == 0) &&(loanselection>0)) {
		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound
		loansubmit = 1;
		if (loanselection == 1){
			if (loanform) SDL_FreeSurface(loanform);
			loanform = NULL;
			compatible_image = NULL;
			compatible_image = SDL_LoadBMP("bmaps/accounts/loanform1.bmp");//bank 1
			if (compatible_image == NULL)
			{
				ERR = fopen("error.txt", "a");
				fprintf(ERR, "Could not load bmaps/accounts/loanform1.bmp\n");
				fclose(ERR);
				CleanUp();
				SDL_Quit();
			}
			// re-format the image to display bpp
			loanform = SDL_DisplayFormat(compatible_image);
			// destroy the old picture
			SDL_FreeSurface(compatible_image);
		}
		if (loanselection == 2){
			if (loanform) SDL_FreeSurface(loanform);
			loanform = NULL;
			compatible_image = NULL;
			compatible_image = SDL_LoadBMP("bmaps/accounts/loanform2.bmp");//bank 2
			if (compatible_image == NULL)
			{
				ERR = fopen("error.txt", "a");
				fprintf(ERR, "Could not load bmaps/accounts/loanform2.bmp\n");
				fclose(ERR);
				CleanUp();
				SDL_Quit();
			}
			// re-format the image to display bpp
			loanform = SDL_DisplayFormat(compatible_image);
			// destroy the old picture
			SDL_FreeSurface(compatible_image);
		}
		if (loanselection == 3){
			if (loanform) SDL_FreeSurface(loanform);
			loanform = NULL;
			compatible_image = NULL;
			compatible_image = SDL_LoadBMP("bmaps/accounts/loanform3.bmp");//bank 3
			if (compatible_image == NULL)
			{
				ERR = fopen("error.txt", "a");
				fprintf(ERR, "Could not load bmaps/accounts/loanform3.bmp\n");
				fclose(ERR);
				CleanUp();
				SDL_Quit();
			}
			// re-format the image to display bpp
			loanform = SDL_DisplayFormat(compatible_image);
			// destroy the old picture
			SDL_FreeSurface(compatible_image);
		}
		if (loanselection == 4){
			if (loanform) SDL_FreeSurface(loanform);
			loanform = NULL;
			compatible_image = NULL;
			compatible_image = SDL_LoadBMP("bmaps/accounts/loanform4.bmp");//bank 4
			if (compatible_image == NULL)
			{
				ERR = fopen("error.txt", "a");
				fprintf(ERR, "Could not load bmaps/accounts/loanform4.bmp\n");
				fclose(ERR);
				CleanUp();
				SDL_Quit();
			}
			// re-format the image to display bpp
			loanform = SDL_DisplayFormat(compatible_image);
			// destroy the old picture
			SDL_FreeSurface(compatible_image);
		}
	}

	//return to ACCOUNT SERVICES window
	if ((xlookup + 100>854) && (xlookup + 100<1015) && (ylookup + 120>745) && (ylookup + 120<760)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		//save form to saved/account
		//CREDIT / LOAN
			// 1 Spinward credit union
			// 2 Sternmetal Financial
			// 3 Bank of Sylea
			// 4 Imperial Loans
		if (loansubmit == 1){
			if (loanselection == 1){
				sprintf(tempsubfname, "saved/account/%s%s_SpinwardLoan%d.bmp", uName, UPP, (rand() % 100000)+1);
				Screenshot(tempsubfname, backsurf, LOANWINDOW);
			}
			if (loanselection == 2){
				sprintf(tempsubfname, "saved/account/%s%s_SM_Loan%d.bmp", uName, UPP, (rand() % 100000) + 1);
				Screenshot(tempsubfname, backsurf, LOANWINDOW);
			}
			if (loanselection == 3){
				sprintf(tempsubfname, "saved/account/%s%s_SyleaLoan%d.bmp", uName, UPP, (rand() % 100000) + 1);
				Screenshot(tempsubfname, backsurf, LOANWINDOW);
			}
			if (loanselection == 4){
				sprintf(tempsubfname, "saved/account/%s%s_ImperialLoan%d.bmp", uName, UPP, (rand() % 100000) + 1);
				Screenshot(tempsubfname, backsurf, LOANWINDOW);
			}
			fd1 = NULL;
			sprintf(tempfile, "communications/messages/waiting/%d.msg", MemberNumber);
			fd1 = fopen(tempfile, "a+");
			fprintf(fd1, "%s\n", uName); //message recipient TO: (TAS member number or other name)
			fprintf(fd1, "\n", xbdestination); //message destination system or world
			fprintf(fd1, "%s\n", currentdate); //current send date
			fprintf(fd1, "Loan Administration\n"); //sender username
			fprintf(fd1, "\n"); //sender TAS member number
			if (loanselection == 1) fprintf(fd1, "Spinward Credit Union LOAN APPLICATION Approved\n");
			if (loanselection == 2) fprintf(fd1, "SternMetal Financial LOAN APPLICATION Approved\n");
			if (loanselection == 3) fprintf(fd1, "Bank of Sylea LOAN APPLICATION Approved\n");
			if (loanselection == 4) fprintf(fd1, "Imperial Loans LOAN APPLICATION Approved\n");
			fprintf(fd1, "Loan Amount: %s credits\n", loanrequest);
			if (loanselection == 1) fprintf(fd1, "Interest Rate: %.1f %%\n", interestgenerated1);
			if (loanselection == 2) fprintf(fd1, "Interest Rate: %.1f %%\n", interestgenerated2);
			if (loanselection == 3) fprintf(fd1, "Interest Rate: %.1f %%\n", interestgenerated3);
			if (loanselection == 4) fprintf(fd1, "Interest Rate: %.1f %%\n", interestgenerated4);
			fprintf(fd1, "\n");
			fprintf(fd1, "Interest rate is annual");
			for (templines = 4; templines <= 19; templines++){
				fprintf(fd1, "\n");
			}
			fprintf(fd1, "~~~~\n");
			fclose(fd1);

			//send mail message to administrator with statement
			fd1 = NULL;
			sprintf(tempfile, "communications/messages/waiting/GENERIC.msg");
			fd1 = fopen(tempfile, "a+");
			fprintf(fd1, "Administrator\n"); //message recipient TO: (TAS member number or other name)
			fprintf(fd1, "\n", xbdestination); //message destination system or world
			fprintf(fd1, "%s\n", currentdate); //current send date
			fprintf(fd1, "%s\n", uName); //sender username
			fprintf(fd1, "%d\n", MemberNumber); //sender TAS member number
			if (loanselection == 1) fprintf(fd1, "Spinward Credit Union LOAN APPLICATION Approved\n");
			if (loanselection == 2) fprintf(fd1, "SternMetal Financial LOAN APPLICATION Approved\n");
			if (loanselection == 3) fprintf(fd1, "Bank of Sylea LOAN APPLICATION Approved\n");
			if (loanselection == 4) fprintf(fd1, "Imperial Loans LOAN APPLICATION Approved\n");
			fprintf(fd1, "Loan Amount: %s credits\n", loanrequest);
			if (loanselection == 1) fprintf(fd1, "Interest Rate:%.1f %%\n", interestgenerated1);
			if (loanselection == 2) fprintf(fd1, "Interest Rate:%.1f %%\n", interestgenerated2);
			if (loanselection == 3) fprintf(fd1, "Interest Rate:%.1f %%\n", interestgenerated3);
			if (loanselection == 4) fprintf(fd1, "Interest Rate:%.1f %%\n", interestgenerated4);
			fprintf(fd1, "\n");
			fprintf(fd1, "Interest rate is annual");
			fprintf(fd1, "***Loan application picture saved to %s ***\n", tempsubfname);
			for (templines = 5; templines <= 19; templines++){
				fprintf(fd1, "\n");
			}
			fprintf(fd1, "~~~~\n");
			fclose(fd1);
			
		} //end saving loan form
		TASWindow = ACCOUNTSERVICEWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		loanborrow = 0; //flag - 0 no borrow, 1 borrow amount submitted
		loanselection = 0;
		loansubmit = 0;
		loanrequest = NULL;
		totalloan = NULL;
		//clear bitmaps to save memmory
		return ACCOUNTSERVICEWINDOW;
	} //exit
	*/

	return LOANWINDOW;


}


int checkmouseboundsPersonal()
{
	/*
	int xlookup=0,ylookup=0;


	SDL_GetMouseState(&xlookup, &ylookup);

	xlookup=xlookup-100;
	ylookup=ylookup-120;

	//check to see if selection is on the grid
	if (xlookup<1) return PERSONALWINDOW;
	if (ylookup<1) return PERSONALWINDOW;

	//return to ACCOUNT SERVICES window
	if ((xlookup + 100>854) && (xlookup + 100<1015) && (ylookup + 120>745) && (ylookup + 120<760)) {

		Mix_PlayChannel(-1, SoundButtonClick, 0); //do button click sound

		TASWindow = ACCOUNTSERVICEWINDOW;
		TASCurrentMenuWindow = ACCOUNTSERVICEWINDOW;
		//clear bitmaps to save memmory
		return ACCOUNTSERVICEWINDOW;
	}
	*/
	return PERSONALWINDOW;

}

void DisplayAccountServices(void)
{
	

	if (backsurf != accountsvcs){

		backsurf = accountsvcs;
		driver->draw2DImage(backsurf, core::position2d<s32>(0, 0), core::rect<s32>(0, 0, 1024, 768), 0, video::SColor(255, 255, 255, 255), true);
	}

		displaybalance = 0;

}

void DisplayBankServices(void)
{
	/*
	SDL_Rect rectform;
	SDL_Rect rect;



	rectform.x = 0;
	rectform.y = 0;
	rectform.w = 1024;
	rectform.h = 768;


	rect.x = 0;
	rect.y = 0;
	rect.w = 1024;
	rect.h = 768;



	SDL_BlitSurface(banking, &rectform, backsurf, &rect);

	if (displaybalance == 1){
		InitFont(arial_36_mac_green);
		PutString(backsurf, 552, 200, characcountbalance);
	}
	if (displaybalance == 2){
		InitFont(arial_36_mac_green);
		if (addtoaccount == 0) {
			PutString(backsurf, 552, 190, "ADD: Use keypad");
			PutString(backsurf, 552, 240, "then ENTER");
		}
		if (atoi(tempaccount) > 0) PutString(backsurf, 530, 210, tempaccount);
	}
	if (displaybalance == 3){
		InitFont(arial_36_mac_green);
		if (withdrawaccount == 0) {
			PutString(backsurf, 552, 190, "WD: Use keypad");
			PutString(backsurf, 552, 240, "then ENTER");
		}
		if (atoi(tempaccount) > 0) PutString(backsurf, 530, 210, tempaccount);
	}
	*/
}

void DisplayLoanServices(void)
{
	/*
	SDL_Rect rectform;
	SDL_Rect rect;
	SDL_Rect loanstar1,loanstar2,loanstar3,loanstar4;
	char *tempstor = NULL;
	char tempdate[9];

	
	totalloannumber=0;
	totalloan = NULL;

	rectform.x = 0;
	rectform.y = 0;
	rectform.w = 1024;
	rectform.h = 768;


	rect.x = 0;
	rect.y = 0;
	rect.w = 1024;
	rect.h = 768;

	//loan company star location
	loanstar1.x = 205;
	loanstar1.y = 216;
	loanstar1.w = 19;
	loanstar1.h = 19;

	loanstar2.x = 205;
	loanstar2.y = 274;
	loanstar2.w = 19;
	loanstar2.h = 19;

	loanstar3.x = 206;
	loanstar3.y = 334;
	loanstar3.w = 19;
	loanstar3.h = 19;

	loanstar4.x = 206;
	loanstar4.y = 392;
	loanstar4.w = 19;
	loanstar4.h = 19;

	sprintf(tempdate, "%d-%d", TASDay, TASYear);

	//paint the background
	SDL_BlitSurface(loancredit, &rectform, backsurf, &rect);

	if (loanselection == 1){
		SDL_BlitSurface(bluestar, NULL, backsurf, &loanstar1); //bank 1
	}
	if (loanselection == 2){
		SDL_BlitSurface(bluestar, NULL, backsurf, &loanstar2); //bank 2
	}
	if (loanselection == 3){
		SDL_BlitSurface(bluestar, NULL, backsurf, &loanstar3); //bank 3
	}
	if (loanselection == 4){
		SDL_BlitSurface(bluestar, NULL, backsurf, &loanstar4); //bank 4
	}
	//if a loan request entered
	if (loanborrow == 1){
		InitFont(arial_36_mac_green);
		PutString(backsurf, 700, 95, loanrequest);
		InitFont(Optima18White);
		tempstor = (char *)calloc((unsigned)strlen("       "), sizeof(char));
		totalloan = (char *)calloc((unsigned)strlen("                    "), sizeof(char));
		if (ratelevel == 0){
			interestgenerated1 = (float)(b1interestoffset0 + 19.1);
			interestgenerated2 = (float)(b2interestoffset0 + 19.1);
			interestgenerated3 = (float)(b3interestoffset0 + 19.1);
			interestgenerated4 = (float)(b4interestoffset0 + 19.1);
		} // rate 0

		if (ratelevel == 10){
			interestgenerated1 = (float)(b1interestoffset10 + 11.1);
			interestgenerated2 = (float)(b2interestoffset10 + 11.1);
			interestgenerated3 = (float)(b3interestoffset10 + 11.1);
			interestgenerated4 = (float)(b4interestoffset10 + 11.1);
		} // rate 10
		if (ratelevel == 20){
			interestgenerated1 = (float)(b1interestoffset20 + 6.2);
			interestgenerated2 = (float)(b2interestoffset20 + 6.2);
			interestgenerated3 = (float)(b3interestoffset20 + 6.2);
			interestgenerated4 = (float)(b4interestoffset20 + 6.2);
		} // rate 20
		if (ratelevel == 30){
			interestgenerated1 = (float)(b1interestoffset30 + 3.3);
			interestgenerated2 = (float)(b2interestoffset30 + 3.3);
			interestgenerated3 = (float)(b3interestoffset30 + 3.3);
			interestgenerated4 = (float)(b4interestoffset30 + 3.3);
		} // rate 30
		if (ratelevel == 50){
			interestgenerated1 = (float)(b1interestoffset50 + 1.8);
			interestgenerated2 = (float)(b2interestoffset50 + 1.8);
			interestgenerated3 = (float)(b3interestoffset50 + 1.8);
			interestgenerated4 = (float)(b4interestoffset50 + 1.8);
		} // rate 50
		if (ratelevel == 70){
			interestgenerated1 = (float)(b1interestoffset70 + .9);
			interestgenerated2 = (float)(b2interestoffset70 + .9);
			interestgenerated3 = (float)(b3interestoffset70 + .9);
			interestgenerated4 = (float)(b4interestoffset70 + .9);
		} // rate 70
		if (ratelevel == 80){
			interestgenerated1 = (float)(b1interestoffset70 + .2);
			interestgenerated2 = (float)(b2interestoffset70 + .2);
			interestgenerated3 = (float)(b3interestoffset70 + .2);
			interestgenerated4 = (float)(b4interestoffset70 + .2);
		} // rate 80
		if (loansubmit == 0){
			//************Display Rates***********************
			//bank 1
			totalloannumber = (int)((atoi(loanrequest) + (atoi(loanrequest)*(interestgenerated1*.01))));
			sprintf(tempstor, "%.1f\0", interestgenerated1);
			PutString(backsurf, 708, 200, tempstor);
			sprintf(totalloan, "%d cr\0", totalloannumber);
			PutString(backsurf, 826, 200, totalloan);
			//bank 2
			totalloannumber = (int)((atoi(loanrequest) + (atoi(loanrequest)*(interestgenerated2*.01))));
			sprintf(tempstor, "%.1f\0", interestgenerated2);
			PutString(backsurf, 708, 265, tempstor);
			sprintf(totalloan, "%d cr\0", totalloannumber);
			PutString(backsurf, 826, 265, totalloan);
			//bank 3
			totalloannumber = (int)((atoi(loanrequest) + (atoi(loanrequest)*(interestgenerated3*.01))));
			sprintf(tempstor, "%.1f\0", interestgenerated3);
			PutString(backsurf, 708, 325, tempstor);
			sprintf(totalloan, "%d cr\0", totalloannumber);
			PutString(backsurf, 826, 325, totalloan);
			//bank 4
			totalloannumber = (int)((atoi(loanrequest) + (atoi(loanrequest)*(interestgenerated4*.01))));
			sprintf(tempstor, "%.1f\0", interestgenerated4);
			PutString(backsurf, 708, 385, tempstor);
			sprintf(totalloan, "%d cr\0", totalloannumber);
			PutString(backsurf, 826, 385, totalloan);
		} //end if loansubmit=0
		if (loansubmit == 1){
			//paint the background
			InitFont(Courier10Black);


			if (loanselection == 1){

				SDL_BlitSurface(loanform, NULL, backsurf, &rectform);
				PutString(backsurf, 305, 220, uName); //player's name
				PutString(backsurf, 305, 250, loanrequest); //amount of loan less interest
				sprintf(tempstor, "%.1f\0", interestgenerated1);
				PutString(backsurf, 305, 280, tempstor); // interest rate
				PutString(backsurf, 305, 425, tempdate); // date
			}
			if (loanselection == 2){
				SDL_BlitSurface(loanform, NULL, backsurf, &rectform);
				PutString(backsurf, 175, 195, uName); //player's name
				PutString(backsurf, 596, 225, loanrequest); //amount of loan less interest
				sprintf(tempstor, "%.1f\0", interestgenerated2);
				PutString(backsurf, 570, 315, tempstor); // interest rate
				PutString(backsurf, 210, 620, tempdate); // date
			}
			if (loanselection == 3){

				SDL_BlitSurface(loanform, NULL, backsurf, &rectform);
				PutString(backsurf, 330, 160, uName); //player's name
				PutString(backsurf, 330, 190, loanrequest); //amount of loan less interest
				sprintf(tempstor, "%.1f\0", interestgenerated3);
				PutString(backsurf, 330, 215, tempstor); // interest rate
				PutString(backsurf, 330, 330, tempdate); // date
			}
			if (loanselection == 4){

				SDL_BlitSurface(loanform, NULL, backsurf, &rectform);
				PutString(backsurf, 300, 270, uName); //player's name
				PutString(backsurf, 310, 360, loanrequest); //amount of loan less interest
				sprintf(tempstor, "%.1f\0", interestgenerated4);
				PutString(backsurf, 275, 450, tempstor); // interest rate
				PutString(backsurf, 100, 180, tempdate); // date
			}


		} //end if loansubmit =1 
	}

	tempstor = NULL;
	totalloan = NULL;
	*/
}


void DisplayPersonalServices(void)
{
	/*
	SDL_Rect rectform;
	SDL_Rect rect;
	char temp[12];


	rectform.x = 0;
	rectform.y = 0;
	rectform.w = 1024;
	rectform.h = 768;


	rect.x = 0;
	rect.y = 0;
	rect.w = 1024;
	rect.h = 768;


	SDL_BlitSurface(acctinfo, &rectform, backsurf, &rect);
	sprintf(temp, "%d\0", MemberNumber);
	InitFont(Optima18White);
	PutString(backsurf, 266, 126, temp); //TAS Membership number
	PutString(backsurf, 266, 161, uName); //player's name
	PutString(backsurf, 266, 189, UPP); //UPP

	if (uAccessLevel > 0){
		InitFont(arial_24_yellow_blackout_bevel);
		PutString(backsurf, 266, 244, charAccessLevel); //Access level

		InitFont(arial_24_red_blackout_bevel);
		if (uAccessLevel == 1){
			PutString(backsurf, 290, 244, "  [TAS Charter Member]"); //Access level membership
		}
		if ((uAccessLevel > 1) && (uAccessLevel <= 3)){
			PutString(backsurf, 290, 244, "  [TAS Bronze Member]"); //Access level membership
		}
		if ((uAccessLevel > 3) && (uAccessLevel <= 7)){
			PutString(backsurf, 290, 244, "  [TAS Silver Member]"); //Access level membership
		}
		if ((uAccessLevel == 8)){
			PutString(backsurf, 290, 244, "  [TAS Gold Member]"); //Access level membership
		}
		if ((uAccessLevel == 9)){
			PutString(backsurf, 290, 244, "  [TAS Lananum Member]"); //Access level membership
		}
		if ((uAccessLevel == 10)){
			PutString(backsurf, 290, 244, "  [TAS Administrator]"); //Access level membership
		}
	}
	else 	{
		PutString(backsurf, 266, 237, charAccessLevel); //Access level
	}
	//Social standing
	InitFont(Optima18White);
	if ((UPP[5] == 'B') || (UPP[5] == 'b')) PutString(backsurf, 266, 285, "Knight");
	if ((UPP[5] == 'C') || (UPP[5] == 'c')) PutString(backsurf, 266, 285, "Baron");
	if ((UPP[5] == 'D') || (UPP[5] == 'd')) PutString(backsurf, 266, 285, "Marquis");
	if ((UPP[5] == 'E') || (UPP[5] == 'e')) PutString(backsurf, 266, 285, "Count");
	if ((UPP[5] == 'F') || (UPP[5] == 'f')) PutString(backsurf, 266, 285, "Duke");
	if ((UPP[5] == 'G') || (UPP[5] == 'g')) PutString(backsurf, 266, 285, "Sector Duke");
	if ((UPP[5] == 'H') || (UPP[5] == 'h')) PutString(backsurf, 266, 285, "Arch Duke");
	if ((UPP[5] == 'I') || (UPP[5] == 'i')) PutString(backsurf, 266, 285, "Emperor");
	if ((UPP[5] == 'J') || (UPP[5] == 'j')) PutString(backsurf, 266, 285, "Emperor");

	
	PutString(backsurf, 266, 320, uHomeWorld); //player's Homeworld
	PutString(backsurf, 266, 350, uRace); //player's Race
	*/
}