	var Service = new ATB_DataService();  //See ATBWeb.js for details    
	/**
	* Login - wrapper function for the ATB_DataService.Login function
	*/
	function Login(username, password){ 
		try{  
			User = Service.Login(username,password);
		    
			if(User.IsAuthenticated){
				updateFlash();
				UpdateUserDisplay();
			}

			return User.IsAuthenticated;
		}catch(ex){
			User.ErrorCode = ex.message;
			return false;
			}
	}
	
	function Logout(){
	try{
	Service.LogoutUser();
	}catch(ex) {
	alert("Logout error: "+ex.message);
	}
	}
   

   function updateFlash(){
       try{
       var sCompletedCode = User.CompletedCode;
       var iLen = String(sCompletedCode).length;
       if (iLen > 0)
           User.CompletedCode = String(sCompletedCode).substring(iLen, iLen - 25);
		  //var f = getFlash("flashApp");
		  if(window["flashApp"]) window["flashApp"].updateUserData(User);
	    } catch(e){
			alert("flashApp updateFlash issue "+e);
		}
       try{
		  //var f = getFlash("belt");
		  //if(f!= null) f.updateUserData(User);
		  if(window["belt"]) window["belt"].updateUserData(User);
	    } catch(e){
			alert("belt updateFlash issue "+e);
		}
   }
    function updateFlash2(User2){
       try{
		  //var f = getFlash("flashApp");
		  if(window["flashApp"]) window["flashApp"].updateUserData(User2);
	    } catch(e){
			alert("flashApp updateFlash issue "+e);
		}
       try{
		  //var f = getFlash("belt");
		  //if(f!= null) f.updateUserData(User);
		  if(window["belt"]) window["belt"].updateUserData(User2);
	    } catch(e){
			alert("belt updateFlash issue "+e);
		}
   }
 
	function getFlash(val){
		if (navigator.appName.indexOf("Microsoft") != -1) {
			return window[val];
		} else {
		if(document[val].length != undefined){
			return document[val][1];
			}
			return document[val];
		}
		return null;
	}
    
    function getUserProperty(s){
        
        if(User.IsAuthenticated){
            switch(s.toLowerCase()){
                case "username":
		            return User.UserName;
		        case "bucks":
		            return User.Bucks;
		        case "email":
		            return User.Email;
		     }     
		} else {
		    return null;
		}
	}	   	   
    
	function trace(msg){
		alert("trace::"+msg);
	}

	/**
	* SaveUser - wrapper function for the ATB_DataService.UpdateUser function
	*
	*/
	function SaveUser(){
		 try{
			Service.UpdateUser(User);
			UpdateUserDisplay();
		 }catch(ex){
			alert("Save user error: "+ex.message);
		 } 
	}
	 
    /**
 	* wrapper function for flash to call to only add bucks to usewr bucks amount
 	*/      
      function addBucksToUser(val){
	      try
	      {
				if(User.IsAuthenticated){
					User.Bucks = parseInt(User.Bucks)+parseInt(val); 
					Service.UpdateUserProgress(User);
					UpdateUserDisplay();
				} else {
				
				}
	   	} catch(e){
		  	   //alert("addBucksToUser error: "+e.message);
	 		}
      }
      
 	/**
 	* wrapper function for flash to call to set the completion status and bucks in one call
 	* only called from the endgame sequence
 	*/     
      function UpdateUserProgress(bucks,intID,aID){
	      try
	      {
		   	   if(User.IsAuthenticated){
			   		User.SetCompletedStatus(intID,aID);
					User.Bucks = parseInt(User.Bucks)+parseInt(bucks);
					var msg = Service.UpdateUserProgress(User);
					
					
			   	   	updateFlash2(Service.Login(User.UserName, User.Password));
					UpdateUserDisplay();
		   	   } else {
			   		// alert("UpdateUserProgress error: User is not Authenticated "+bucks+", "+intID+", "+aID);
		   	   }
	   		} catch(e){
		  	   alert("UpdateUserProgress error: "+e.message);
	 		}  	   
      }
    
	function getUserData(){
		return User;
	}


 	/**
 	* wrapper function for flash to call to get the completion status
 	*/
      function getCompletionStatus(intID,aID){
		try
	      {
		   	   if(User.IsAuthenticated){
				   var f = User.CheckCompletedStatus(intID,aID);
			   		return f;
		   	   } else {
			   	   //alert("getCompletionStatus error::  User not Authenticated");
		   	   }
			   
	   		} catch(e){
		  	  alert("getCompletionStatus error:: intID="+intID+",aID="+aID+" || "+e.message);
	 		}  	   
	  }
      
	   function getInterstitialStatus(intID){
		try
	      {
		   	   if(User.IsAuthenticated){
				   return User.CompletedCode.substr(parseInt(intID)-1,1);
		   	   } else {
			   	   //alert("getCompletionStatus error::  User not Authenticated");
		   	   }
	   		} catch(e){
		  	   alert("getInterstitialStatus error:: intID="+intID+" || "+e.message);
	 		}  	   
	  }
      // wrapper function for flash to check to see if a user is logged in or not
      function checkLoginStatus(){
	      return User.IsAuthenticated;
    	}
      
      function CreateClientUser(username, password, email)
      {
         var userName;
         var userFirstName;
         var userPassword;
         var userEmail;
         var isValid = true;
         var message = "";

         try{  
            if(isValid){
               //Submit the User Data. First Param is First name, second is Last Name
               User = Service.CreateUser("Dummy", "AlsoDummy", username, email, password);
                              
               if(User.IsAuthenticated){                  
                  UpdateUserDisplay();
                  return true;
               }else{
                  //alert("CreateClientUser User error: "+User.ErrorMessage);
                  return false;
               }
            }else{
               return false;
            }
         }catch(ex){
            alert("CreateClientUser error: "+ex.message);
         }
      }