function open_popup(URL) {
     day = new Date();
     id = day.getTime();
     eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=850,height=520,left = 390,top = 282');");
}

function flex_isIE() {
     return $.browser.msie;
}

var terms = {
     open: function() {
          this.newPopup('/pages/terms');
     },
     newPopup: function(URL) {
          day = new Date();
          id = day.getTime();
          eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=460,left = 390,top = 282');");
     }
}

var login = {
     newPopup: function(URL) {
          windowWidth = 1000;
          windowHeight = 738; //746;
          xpos = (screen.width - windowWidth)/2;
          ypos = (screen.height - windowHeight)/2;  
          day = new Date();
          id = day.getTime();
          eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=" +windowWidth+",height="+windowHeight+",left="+xpos+",top="+ ypos +"');");          
     }
}

var SOA = {
     initialize: function(clientId,name) {
          if(!clientId || clientId == 0) {
               alert("The Specified ClientId is Invalid! Unable to start the Application.");
               window.close();
               return;
          }
                         
          $('#modalOverlay').show();
          $('#loading-wrapper').show();
          $('#loadingProgress').center();
          
          $.get("/rpc-data/load-session/id/"+clientId+'/name/'+name,
               function(data){ 
                    if(data == '{"type":"message","payload":"loaded-session"}') {
                         location.href = "/decimal/welcome";
                    } else {
                         alert("There was a problem initiating the session. The application is not available. Please try again later. ");
                    }
               }
          );
     }
}

var Session = {
     start: function(z,p,a,c) {
          // name, age, gender, salary
          $('#modalOverlay').show();
          $('#loading-wrapper').show();
          $('#loadingProgress').center();
          
          var qs = "_g=1&age=" + p + "&gender=" + a + "&salary=" + c + '&name=' + z;
          
          $.get("/decimal/populate?"+qs,
               function(data){ 
                    if(data == "<span class='response'>ok</span>") {
                         location.href = "/decimal/welcome";
                    } else {
                         alert("There was a problem initiating the session. The application is not available. Please try again later.");
                    }
               });
     },
     startJA: function(z,p,a,c,d,e) {
         // name, age, gender, salary, super, email
         $('#modalOverlay').show();
         $('#loading-wrapper').show();
         $('#loadingProgress').center();
         
         var qs = "_g=1&age=" + p + "&gender=" + a + "&salary=" + c + "&superval=" + d + '&name=' + z + '&email=' + e;
         
         $.get("/decimal/populate?"+qs,
              function(data){ 
                   if(data == "<span class='response'>ok</span>") {
                        location.href = "/decimal/welcome";
                   } else {
                        alert("There was a problem initiating the session. The application is not available. Please try again later.");
                   }
              });
    }, 
     load: function(name, clientid) {
          $('#modalOverlay').show();
          $('#loading-wrapper').show();
          $('#loadingProgress').center();
     }
}


function openPopupWindow(url, name, width, height, returnWindow)
{
     var horizontalOffset, verticalOffset, offsetAmount, windowToReturn, closethiswindow;
          
     offsetAmount = 0;
     
     if(width == -1)
     {
     
       if ((screen.Height >= 0) && (screen.Width >= 0)) {
                width = screen.Width - 10;
       }
       else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
                 width = screen.availWidth - 10;
       }
     }     
     
     if(height == -1)
     {
     if ((screen.Height >= 0) && (screen.Width >= 0)) {
                height = screen.Height - 75;
    }
       else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
                 height = screen.availHeight - 45;
    }
     }
     
     if(navigator.appName == "Microsoft Internet Explorer")
     {
          horizontalOffset = window.screenLeft + offsetAmount;
          verticalOffset = window.screenTop + offsetAmount;
     }
     else
     {
          horizontalOffset = window.screenX + offsetAmount;
          verticalOffset = window.screenY + offsetAmount;
     }
     
     if(horizontalOffset + width > screen.availWidth || verticalOffset + height > screen.availHeight)
     {
          horizontalOffset = 0;
          verticalOffset = 0;
     }
          
     windowToReturn = window.open(url, name, "toolbar=0,location=0,directories=0,status=yes,menubar=no,scrollbars=1,resizable=yes,screenX=" + horizontalOffset + ",screenY=" + verticalOffset + ",left=" + horizontalOffset + ",top=" + verticalOffset + ",width=" + width + ",height=" + height);
     //Please do not publish with the return window statement
     //if(returnWindow)
     //{
     //     return(windowToReturn);
     //}
}