var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function clearInfo(){
document.getElementById('loginandhintreturninfo').innerHTML=  ""  // account desk return
document.getElementById('loginreturninfo').innerHTML=""    // login return
document.getElementById('helpreturninfo').innerHTML=""    // login return
}
function portalLogin(){
   clearInfo()
   var loginid=document.getElementById('loginid').value
   var pwd = document.getElementById('pwd').value
   document.getElementById('plbutton').style.display = "none"

   // remove leading and trailing spaces
   loginid=loginid.split(' ').join('');
   pwd = pwd.split(' ').join('');
   var response=""   
   if (!pwd) {
  		alertstmt = "Please enter your password "+pwd;
	       document.getElementById('loginreturninfo').innerHTML=alertstmt;
              document.getElementById('plbutton').style.display = "inline"   
   		return false;
    } //pwd
    if (!loginid) {
	       alertstmt = "Please enter your username! " + loginid;
		document.getElementById('loginreturninfo').innerHTML=alertstmt;
document.getElementById('plbutton').style.display = "inline"
		return false;
    }//loginid
//  alert ("in portallogin.js")
    //     alert (document.location.href)

   AjaxRequest.get(
       {
       'url':'/cgi-bin/wwiz/wwiz.asp?wwizmstr=WEB.PORTAL.LOGIN.AJX'
       ,'parameters':{'loginid':loginid,'pwd':pwd}
       ,'onSuccess':function(req) {document.getElementById('loginreturninfo').innerHTML="Login Submitted!";response=req.responseText;
       var st = response.indexOf("&portalid=");
       if (st > '0'){
            //clear out the data in the input boxes
            document.getElementById('loginid').value=""
            document.getElementById('pwd').value=""
            st=st+10  // len("&portalid=")
            // length is 18
            var  portalid = response.substr(st,18)
            //document.getElementById('loginreturninfo').innerHTML='';
       //    alert (document.location.href)
             if ( (document.location.href.indexOf('10.1.42.1')>0)  || (document.location.href.indexOf('wnccms') > 0 ) ) {
//                     alert (document.location.href)
                      if  (document.location.href.indexOf('10.1.42.1')>0 ) {
                           var url = 'https://10.1.42.1/portal'}
                      else{
                           var url='https://testwebserver.wnccms.net/portal'

                       }
                    wherestmt="You are in the live testserver account "+url
//                     wherestmt="You are in the live testserver account 10.1.42.1 !"
//                      var url='https://10.1.42.1/portal'
                     } else {
	                  if (document.location.href.indexOf('test')> 0 ) {
                        wherestmt="You are in the Test Account!"
                      var url='https://test.wncc.net/cgi-bin/wwiz/wwiz.asp?wwizmstr=WEB.PORTAL&portal='+portalid;   
                      //var url='https://www.wncc.net/portal'
                  }else{
                      wherestmt="You are in the Live Account!"
                      //var url='https://www.wncc.net/cgi-bin/wwiz/wwiz.asp?wwizmstr=WEB.PORTAL&portal='+portalid;
                       var url='https://www.wncc.net/portal'
     
                 }
             } // if test2 etc
             document.getElementById('loginreturninfo').innerHTML= wherestmt+'<br>Loading your Portal...';
             //create a cookie indicating I started at the login page
             var expires = "";
             var name = 'portallogin';
             var value = 'ok'  
             document.cookie = name+"="+value+expires+"; path=/";
             var newWin = window.open(url);
             if (newWin && newWin.top) {
                        document.getElementById('loginreturninfo').innerHTML= wherestmt+'<br>Your Portal has loaded';
document.getElementById('plbutton').style.display = "inline"
             } else {
                        link = wherestmt+"<br> BUT you have a popup blocker! I can't open the Portal for you!<br>"
                        ref="<a href="+url+" target = '_blank' >Click here to load</a>";
                        //document.getElementById('loginreturninfo').innerHTML=link+ref;
    //                    alert ("You have a popup blocker set on your browser!")
                        window.location=url
             }// if newwin
       
   
      }else {   // if st
        document.getElementById('loginreturninfo').innerHTML="I cannot find that login/password combination...perhaps you misstyped?<br>Please try again!"
document.getElementById('plbutton').style.display = "inline"

       }
      }// end of onsuccess
       }// end of request.get curlies
       ) //get argument list
     // alert (response)
     
}//function

// used only in portal login...
function forceSubmit(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,13,16,17,18,37,38,39,40,46];
if ( (keyCode==9 || keyCode == 13)   &&   document.getElementById('loginid').value !="" &&    document.getElementById('pwd').value != "" && document.getElementById('plbutton').style.display != "none")
{
      portalLogin();
 } 

if(input.value.length >= len && !containsElement(filter,keyCode)) {
   input.value = input.value.slice(0, len);
   input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
   var found = false, index = 0;
   while(!found && index < arr.length)
   if(arr[index] == ele)
   found = true;
else
   index++;
   return found;
}
function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}

function showBody(what){
clearInfo()
//var bodies=new Array("whatisportal","portallogin","accountdesk","webct","webmailinfo","webmaillogin","groupwise","helpsystem");
var bodies=new Array("whatisportal","portallogin","accountdesk","helpsystem");
// shut them all down'
for (i=0;i<bodies.length;i++){
     document.getElementById(bodies[i]).style.display = 'none';
    }
    document.getElementById(what).style.display = 'inline';
}



function getLoginandHint(reset)   // getlogininfo and getloginalertcontents
  {
   clearInfo()
   var response=""
   var firstname=document.getElementById('first').value;
   var lastname=document.getElementById('last').value;
   var ssnum=document.getElementById('ss').value;
   var bd=document.getElementById('bd').value;
var alertstmt="";
document.getElementById('sswarn').innerHTML=alertstmt;
document.getElementById('firstwarn').innerHTML=alertstmt;
document.getElementById('lastwarn').innerHTML=alertstmt;
document.getElementById('bdwarn').innerHTML=alertstmt;
document.getElementById('getloginreturninfo').innerHTML='';
if (!ssnum && !bd) {
   alertstmt ='Please enter a your Social Security number or your birthdate'
   document.getElementById('sswarn').innerHTML=alertstmt;
   document.getElementById('bdwarn').innerHTML=alertstmt;
}
if (!firstname) {
  alertstmt = "Please enter your first name!";
  document.getElementById('firstwarn').innerHTML=alertstmt;
}
if (!lastname) {
  alertstmt = "Please enter your last name!";
  document.getElementById('lastwarn').innerHTML=alertstmt;
}
if (alertstmt ){
  return false;
}
// ajax now
//http_request.send("&ssnum="+ssnum+"&last="+lastname+"&first="+firstname+"&bd="+bd+"&reset="+reset);
var note=""
if (reset) {note+="Resetting your password to the default<br>"}
if (bd) {note+="Looking up your information using your birth date (this takes longer!)<br>"}
AjaxRequest.get(
       {
       'onLoading':function() {document.getElementById('getloginreturninfo').innerHTML=note+"Processing your request";}
       ,'onLoaded':function() {document.getElementById('getloginreturninfo').innerHTML+="......";}
       ,'onInteractive':function() {document.getElementById('getloginreturninfo').innerHTML+="......";}
       ,'onComplete':function() {document.getElementById('getloginreturninfo').innerHTML+="<br>Done!";}
       ,'url':'/cgi-bin/wwiz/wwiz.asp?wwizmstr=WEB.GLI.AJX.NEW'
       ,'parameters':{'ssnum':ssnum,'last':lastname,'first':firstname,'bd':bd,'reset':reset}
       ,'onSuccess':function(req) {document.getElementById('loginandhintreturninfo').innerHTML=req.responseText;if(req.responseText ==""){               document.getElementById('loginandhintreturninfo').innerHTML="Please resubmit your request!"}}
       }
       )
}
function postHelp()  //posthelp
 
            {
clearInfo()

             //var url='/cgi-bin/wwiz/wwiz.asp?wwizmstr=WEB.HELP.REQ.AJX';
             var username=document.getElementById("helpusername").value;
             var firstname=document.getElementById("helpfirst").value;
             var lastname=document.getElementById("helplast").value;
             var email=document.getElementById("helpemail").value;
             var system=document.getElementById("helpsystem").value;
             var phone=document.getElementById("helpphone").value;
             var time=document.getElementById("helptime").value;
             var details=document.getElementById("helpdetails").value;
             //this replaces all /n with "|" so wwiz can  parse it
              rExp = /\n/g;
             details = details.replace(rExp, "|")
             //  
             var alertstmt="";
             document.getElementById('helpreturninfo').innerHTML=alertstmt;
if (!firstname) {
  alertstmt = "Please enter your first name!";
  document.getElementById('helpreturninfo').innerHTML=alertstmt;
}
if (!lastname) {
  alertstmt = "Please enter your last name!";
  document.getElementById('helpreturninfo').innerHTML=alertstmt;
}
if (alertstmt ){
  return false;
}
AjaxRequest.get(
       {
       'onLoading':function() {document.getElementById('helpreturninfo').innerHTML=note+"Processing your request";}
       ,'onLoaded':function() {document.getElementById('helpreturninfo').innerHTML+="......";}
       ,'onInteractive':function() {document.getElementById('helpreturninfo').innerHTML+="......";}
       ,'onComplete':function() {document.getElementById('helpreturninfo').innerHTML+="<br>Done!";}
       ,'url':'/cgi-bin/wwiz/wwiz.asp?wwizmstr=WEB.HELP.REQ.AJX'
       ,'parameters':  {'phone':phone,'time':time,'details':details,'username':username,'email':email,'last':lastname,'first':firstname,'system':system}
       ,'onSuccess':function(req) {document.getElementById('helpreturninfo').innerHTML=req.responseText;if(req.responseText ==""){             document.getElementById('helpreturninfo').innerHTML="Please resubmit your request!"}}
       }
       )
} //end of function



function clearPageIndicator(){   // on onload from wncc2 index
             var expires = "";
             var name = 'portallogin';
             var value = ''  
             document.cookie = name+"="+value+expires+"; path=/";
}
