
 function popup(name,url) {
        newWindow1 = window.open(url,name,"height=520,width=620,scrollbars,resizable");
        newWindow1.focus();
 }

// Sets cookie values. 
// Expiration date is optional
 
 function setCookie(name, value, expire) 
 {          
     document.cookie = name + "=" + escape(encrypt(value))          
     + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
 }


 function getCookie(Name) 
 {          
     var search = Name + "="          
     
    
     if ( document.cookie != null )
     {
        if( document.cookie.length > 0) 
        { 
           offset = document.cookie.indexOf(search)                     
           if (offset != -1) 
           { 
                offset += search.length                            
                end = document.cookie.indexOf(";", offset)                    
                
                if (end == -1)                                         
                    end = document.cookie.length                                 
                    
                   return unescape(document.cookie.substring(offset, end))   
                               
           } else {

                return null;

           }
        }
     }
 }

 function deleteCookie (name) 
 {  
     
    var exp = new Date(); 
    exp.setTime (exp.getTime() - 1);  
    var cook = getCookie(name);

   
    if ( cook != null) 
    {
        var cval = unEncrypt( getCookie(name) );    
        document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();


    }

 }

 var arrStartValues = new Array();
 arrStartValues[0] = "Home";
 arrStartValues[1] = "Inbox";
 arrStartValues[2] = "Tracked Opportunities";
 arrStartValues[3] = "Newstand";
 arrStartValues[4] = "Resource Center";
 arrStartValues[5] = "BDPro";
 arrStartValues[6] = "Pipeline Profiles";

 function setForAutoLogin() 
 {           
     var today = new Date()          
     var expires = new Date() 

     var company    = document.login.txfCompanyAlias.value;
     var user       = document.login.txfUserName.value;
     var password   = document.login.txfPassword.value;
     var start      = "";
     
     switch(document.login.selStartPage.selectedIndex)
  	 {
  	 	case 0:
  	 		start = arrStartValues[0];
  	 		break;
      	case 1:
      		start = arrStartValues[1];
  	 		break;
      	case 2:
      		start = arrStartValues[2];
  	 		break;
      	case 3:
      		start = arrStartValues[3];
  	 		break;
      	case 4:
      		start = arrStartValues[4];
  	 		break;
      	case 5:
      		start = arrStartValues[5];
  	 		break;
      	case 6:
      		start = arrStartValues[6];
  	 		break;
   }

     
     
     // cookie expres in ten years...

     expires.setTime(today.getTime() + (60*60*24*365*1000))          
     
     setCookie("epipeAutoLoginCompany", company,  expires)
     setCookie("epipeAutoLoginUser",    user,     expires)
     setCookie("epipeAutoLoginPass",    password, expires)
	 setCookie("epipeAutoLoginStart",   start, 	  expires)

 }


 function checkForCookie()
 {
   var company = getCookie( "epipeAutoLoginCompany" );
   var user    = getCookie( "epipeAutoLoginUser" );
   var pass    = getCookie( "epipeAutoLoginPass" );
   var start   = getCookie( "epipeAutoLoginStart" );



   if ( company != null) 
   {
        document.login.txfCompanyAlias.value = unEncrypt( company );
        document.login.txfUserName.value     = unEncrypt( user );
        document.login.txfPassword.value     = unEncrypt( pass );
        start = unEncrypt( start );
        
        if (start == arrStartValues[0])
        {
        	document.login.selStartPage.selectedIndex = 0;
        }        
        if (start == arrStartValues[1])
        {
        	document.login.selStartPage.selectedIndex = 1;
        }
        if (start == arrStartValues[2])
        {
        	document.login.selStartPage.selectedIndex = 2;
        }
        if (start == arrStartValues[3])
        {
        	document.login.selStartPage.selectedIndex = 3;
        }
        if (start == arrStartValues[4])
        {
        	document.login.selStartPage.selectedIndex = 4;
        }
        if (start == arrStartValues[5])
        {
        	document.login.selStartPage.selectedIndex = 5;
        }
        if (start == arrStartValues[6])
        {
        	document.login.selStartPage.selectedIndex = 6;
        }  
        
        
        document.login.cbRememberMe.checked  = true;
   }

 }

// submit the form, if it is checked then lets make sure we set the cookies
// if it is not checked then lets eliminat those cookies, they may not have
// exsisted but you have to do it this way.
//

function submitThisForm()
{
  if( document.login.cbRememberMe.checked )
  {
    
      setForAutoLogin();  
  
  } else {

      deleteCookie("epipeAutoLoginCompany" );
      deleteCookie("epipeAutoLoginUser" );
      deleteCookie("epipeAutoLoginPass" );
      deleteCookie("epipeAutoLoginStart" );
  }

  document.login.submit();
}


