function IntroForm(uid, type, sid, url){
  //alert("IntroForm");
  //alert(uid+", "+ type+", "+ sid+", "+ url);
  this.userID = uid;
  this.typeCode = type;
  this.sessionID = sid;
  this.popup = null;
  this.ajaxHelper = new net.ContentLoader(this, url, "POST", []);
  this.interactiveFlashObj = window.interactiveFlash;

}

IntroForm.prototype = {

  downloadDoc: function(filepath) {
    //alert(filepath);
    //document.getElementById("dlWindow").src = filepath;
    //window.open("downloadpage.jsp?filepath="+filepath);
    location.href = "servlet/filedownload?filename="+filepath;
  },
  
  displayManual: function(manual) {
    var url='usermanual.jsp';
    
    if(manual == "TEBS")
    { url=url+"?FLASHPATH=TEBS_Intro1&USERNAME="+this.userID+"&TYPECODE="+this.typeCode+"&SESSIONID="+this.sessionID;
      this.popup = window.open(url, 'UserManual', 'width=808,height=615,resizable=yes,scrollbars=yes,top='+top);
    }else if(manual == "Project Portal")
    { url=url+"?FLASHPATH=Project_Intro2&USERNAME="+this.userID+"&TYPECODE="+this.typeCode+"&SESSIONID="+this.sessionID;
      this.popup = window.open(url, 'UserManual', 'width=808,height=615,resizable=yes,scrollbars=yes,top='+top);
    }else if(manual == "Client Management")
    { url=url+"?FLASHPATH=Client_Intro2&USERNAME="+this.userID+"&TYPECODE="+this.typeCode+"&SESSIONID="+this.sessionID;
      this.popup = window.open(url, 'UserManual', 'width=808,height=615,resizable=yes,scrollbars=yes,top='+top);
    }
    else if(manual == "Sales Portal")
    { url=url+"?FLASHPATH=Sales_Intro1&USERNAME="+this.userID+"&TYPECODE="+this.typeCode+"&SESSIONID="+this.sessionID;
      this.popup = window.open(url, 'UserManual', 'width=808,height=615,resizable=yes,scrollbars=yes,top='+top);
    }else if(manual == "Executive Info")
    { url=url+"?FLASHPATH=Executive_Intro1&USERNAME="+this.userID+"&TYPECODE="+this.typeCode+"&SESSIONID="+this.sessionID;
      this.popup = window.open(url, 'UserManual', 'width=808,height=615,resizable=yes,scrollbars=yes,top='+top);
    }else
    { alert("User Manual "+manual+" Not Exist!");
    }
  },
  
  closeWindow: function() {
    window.close();
  },
  
  openWindow: function(url) {
    //alert(url);
    var newWindow = window.open(url);
    
  },
  
  gotoPage: function(page_url) {
    //alert(page_url+":"+portalname+":"+formname);
    window.location.replace(page_url);
  },
  
  iniInteractiveForm: function() {
    this.ajaxHelper.sendRequest('action=retrivePrjAndApp&uid=' + this.userID);
  },
  
  displayForm: function(displayForm) {
    
    document.getElementById(displayForm).style.display = 'block';
  },
  
  hideForm: function(hideForm) {
    document.getElementById(hideForm).style.display = 'none';
  },
  /*
  gotoForm:function(flashId, formName) {
    document.getElementById(flashId).gotoForm(formName);
  },*/
  
  ajaxUpdate: function(request) {
  
    var ajaxResponse = request.responseXML.documentElement;
  // alert(ajaxResponse);
    this.root=ajaxResponse;
   //alert(request.responseText);

    var text = request.responseText;
    //alert(text);
    var methodName = "";
    if(text.indexOf('<MethodName>') >= 0)
    { //alert("Got Method Name");
      methodName = ajaxResponse.getElementsByTagName('MethodName')[0].text;
    }
    
    
    if (text.indexOf('<availarray>')>=0)
    {
    var start = text.indexOf('<availarray>') + 12;
    var end = text.indexOf('</availarray>');

    var result = text.substring(start, end).replace(/^\s+|\s+$/g,"");
   // alert(result);
    
    var appNotAllowed=true;

    //alert(request.responseText);
    
    if(result != ""){
      eval("apps = " + result);
      //alert("array length = " + addresses.length);
      
      //clear any existing results
     
      for(var a=0; a<apps.length; a++){
      
        var apps_split = apps[a].split(":");
      
         //alert(apps_split[0]);
         
         if (apps_split[0].indexOf(this.AppName)>=0)
         {
            this.AppID=apps_split[1];
            appNotAllowed=false;
            break;
         }
       
      }
    }
    
    if (appNotAllowed==true)
    {
        alert('You are not allowed to have access to this applicatioin');
        logoutObj.logout();
    }
   }
    
   if(methodName == "retrivePrjAndApp")
   {  var prjArray = new Array();
      var prj_counter = (ajaxResponse.getElementsByTagName('PROJECT_COUNTER')[0].text).valueOf();
      var appArray = new Array();
      var app_counter = (ajaxResponse.getElementsByTagName('APP_COUNTER')[0].text).valueOf();
      
      if(prj_counter == 0 && app_counter == 0)
      { alert("You haven't been assign to any Project/Application yet!");
        return 0;
      }
      
      //Projects
      for(var i=0;i<prj_counter;i++)
      { tempArray = new Array(2);     
        tempArray[0] = ajaxResponse.getElementsByTagName('PROJECT_ID')[i].text;
        tempArray[1] = ajaxResponse.getElementsByTagName('PROJECT_NAME')[i].text;
        
        //alert(companyStr);  
        prjArray[i] = tempArray;
      }
      
      //Applications
      for(var i=0;i<app_counter;i++)
      { tempArray = new Array(3);     
        tempArray[0] = ajaxResponse.getElementsByTagName('APP_ID')[i].text;
        tempArray[1] = ajaxResponse.getElementsByTagName('APP_NAME')[i].text;
        tempArray[2] = ajaxResponse.getElementsByTagName('WEBURL')[i].text;
        //alert(companyStr);  
        appArray[i] = tempArray;
      }      
    
      //alert(prjArray.length+":"+appArray.length);
      this.interactiveFlashObj.displayPrjApp(prjArray, appArray);
      
      //Give Alert Msg
      if(prj_counter == 0)
      { alert("You haven't been assign to any Project yet!");
      }else if(prj_counter == 0)
      { alert("You haven't been assign to any Application yet!");
      }
   }
   
  },
  
  handleError: function(request) {
    alert("ERROR: " + request.responseText);
  }


};



