
//***************************************************************************************************************//
function AccessApp(mySessionId, myApp) {
	//myApp = 1 = Sprint Online && Addressbook
	//myApp = 2  = T&T
	var SessionId = CrypterDecrypter(mySessionId, 'D');
	var pos1;
	var rst;
	var mydata=SessionId;
	var aDescFirstNode = new Array();
	var FirstNode;
	var ObjFirstNode;
	var aArrayData = new Array();

	pos1 = mydata.indexOf('&USERSO=',0);
	pos1= pos1+ 8;
	// Open Xml Doc
	var mypage= SessionId + '&REQTOCALL=S2011&';
	var XMLString = ExecuteRequest1('SocketPgm', mypage, 'AccessApp-Lan', ' ');

	//********************//
	//SetDefaultsXML();/
	// Code for IE
	if (window.ActiveXObject) {
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
		}
		// code for Mozilla, Firefox, Opera, etc.
		else if (document.implementation && document.implementation.createDocument)  	{
				xmlDoc=document.implementation.createDocument("","",null);
				}
			else 		{
				alert('Your browser cannot handle this script');
				}
	//*******************//
	//LoadXMLFile(FileName);
	xmlDoc.async=false;
	xmlDoc.loadXML(XMLString);
	if (xmlDoc.parseError.errorCode != 0) {
		var myErr = xmlDoc.parseError;
		alert("You have error " + myErr.reason);
		return;
		}
	//******************************//
	
	var aArrayFields = new Array('TIER', 'SOAC', 'TTAC', 'VAAC', 'LAAC','EBIL');
	for (var i=0;i<aArrayFields.length;i++)  	{
		aArrayData[i]= xmlDoc.getElementsByTagName(aArrayFields[i]);
		}


	FirstNode = aArrayData[0];
	var DoYouHaveAcces='N';
	for (var j=0;j<FirstNode.length;j++)	{
		for (var k=0;k<aArrayFields.length;k++)		{
			ObjFirstNode  = aArrayData[k];
			//AG 2707  =>  set default to blanks  to avoid error message
			if (!ObjFirstNode[j].childNodes[0]) {	aDescFirstNode[k]=" "};
			else  {		aDescFirstNode[k] = ObjFirstNode[j].childNodes[0].nodeValue;}
			}
		if (aDescFirstNode[myApp]=='Y'){DoYouHaveAcces='Y'; return true;}
		}
	return false;

}


function CrypterDecrypter(myString, myAction){
	var Rslt=' ';
	var Char2Compare1='  ';
	var ArrayCript =new Array('01', '02' ,'03', '04', '05','06', '07' ,'08', '09', '10','11', '12' ,'13', '14', '15',
								'16', '17' ,'18', '19', '20','21', '22' ,'23', '24', '25','26', '27' ,'28', '29', '30',
								'31', '32' ,'33', '34', '35','36', '37' ,'38');
	var ArrayDeCript = new Array('&', '=', '0', '1', '2','3', '4', '5', '6', '7','8', '9', 'A', 'B', 'C',
									'D', 'E', 'F', 'G', 'H','I', 'J', 'K', 'L', 'M','N', 'O', 'P', 'Q', 'R',
									'S', 'T', 'U', 'V', 'W','X', 'Y', 'Z');
	switch(myAction) {
		case 'C' :
			for(var i=0;i<myString.length;i++){
				Char2Compare1 = myString.substring(i,i+1);
				for(var j=0; j<ArrayDeCript.length;j++){
					if (Char2Compare1==ArrayDeCript[j]){	Rslt+= ArrayCript[j];	}
				}
			}
			break;
		case 'D' :
			for(var i=0;i<myString.length;i++){
				Char2Compare1 = myString.substring(i,i+2);
				i++;
				for(var j=0; j<ArrayCript.length;j++){
					if (Char2Compare1==ArrayCript[j]){			Rslt+= ArrayDeCript[j];				}
				}
			}
			break;
		default:
			break;
		}
	return Rslt;
}

var minDOM="";
var srchData = getSearchAsArray();

function getSearchAsArray() {
	// Browser-sniffing variables.
	var minNav3 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) >= 3);
	var minIE4 = (navigator.appName.indexOf("Microsoft") >= 0 && parseInt(navigator.appVersion) >= 4);
	// Baseline DOM required for this function
	minDOM = minNav3 || minIE4 ;
	// Initialize array to be returned.
	var results = new Array();
	if (minDOM) {
		// Unescape and strip away leading question mark.
		var input = unescape(location.search.substring(1));
		if (input) {
			// Divide long string into array of name/value pairs.
			var srchArray = input.split("&");
			var tempArray = new Array();
			for (i = 0; i < srchArray.length; i++) {
				// Divide each name/value pair temporarily into a two-entry array.
				tempArray = srchArray[i].split("=");
				// Use temp array values as index identifier and value.
				results[tempArray[0]] = tempArray[1];
			}
		}
	}
	return results
}

	// ************ returns name of document including directory just beneath language choice
function docpathname(input) {
	startname="/";
	var counter=0;
	var remember;
	var splitArray = input.split("/");
	for (i = 1; i < splitArray.length; i++) {
		switch (splitArray[i]) {
			case "N":
			case "n":
				remember=i+1;
				break;
			case "F":
			case "f":
				remember=i+1;
				break;
			case "E":
			case "e":
				remember=i+1;
				break;
			case "pgm":
			case "PGM":
				 pgmindic="PGM"
				remember=i+1;
				break;
			case "edifiles":
			case "EDIFILES":
				remember=i+1;
				break;
			default:
				// ******* only starts from of language indicator
				counter++;
		}
	}
	for (i = remember; i < splitArray.length; i++) {
		startname+=splitArray[i];
		if (i  < splitArray.length-1) {startname+="/"};
	}
	return startname;
}


	// ************ returns name of document including directory just beneath language choice
function getComboValues(input,which) {
	var splitArray = input.split("&");
	var tempArray = new Array();
	var results = new Array();
	for (i = 0; i < splitArray.length; i++) {
		// Divide each name/value pair temporarily into a two-entry array.
		tempArray = splitArray[i].split("=");
		// Use temp array values as index identifier and value.
		results[tempArray[0]] = tempArray[1];
	}
	var result=results[which];
	return result;
}

var backtit='Back';
var backalt='Back';
var hometit='Home';
var homealt='Home';

switch(docdir) {
    case "E" :
         backtit='Back';
         backalt='Back';
//         hometit='Language choice';
         hometit='[ Close ] ';
//         homealt='Home';
         homealt='[ Close ] ';
         break;
    case "F" :
         backtit='Page précédente';
         backalt='Page précédente';
//         hometit='Choix de langue';
         hometit='[ Fermer ] ';
//         homealt='Accueil';
         homealt='[ Fermer ] ';
         break;
    case "N" :
         backtit='Vorige Pagina';
         backalt='Vorige Pagina';
//         hometit='Taalkeuze';
         hometit='[ Sluiten ] ';
//         homealt='Startpagina';
         homealt='[ Sluiten ] ';
         break;
    default :
         break;
}

var startname="";
var KeyID = "10101010101" ;
var ExternalID="";
var keuze='';
var orderpage;
var openaccept="no";
var ebilchoice
var ebilchoicetit2='Authentication through your billing document';
var ebilchoicetit='Display your billing documents online';


var pgmindic;

if (srchData["SESSIONID"]) { KeyID = srchData["SESSIONID"] ;  }        ;
if (srchData["SERVIES"]) { orderpage = srchData["SERVIES"] ;  }        ;
if (srchData["newlogin"]) { openaccept = srchData["newlogin"] ;  }        ;
if (srchData["optbill"]) { ebilchoice = srchData["optbill"] ;  }        ;

if (srchData["lingua"]) {        docdir = srchData["lingua"] ;    }        ;

switch(docdir) {
	case "E" :
		switch(ebilchoice) {
			case "showbill" :
				 ebilchoicetit='Display your billing documents online';
				 break;
			case "reqacces" :
				 ebilchoicetit='Request access to your billing documents online';
				 break;
			case "reqemail" :
				 ebilchoicetit='Receive notification of billing documents by email';
				 break;
			case "reqdomicil" :
				 ebilchoicetit='Direct Debit for your account';
				 break;
		 }
		 break;
	 case "F" :
		switch(ebilchoice) {
			case "showbill" :
				 ebilchoicetit='Affichez une image de vos factures ';
				 break;
			case "reqacces" :
				 ebilchoicetit='Demandez un accès en ligne à toutes vos factures ';
				 break;
			case "reqemail" :
				 ebilchoicetit='Recevez vos nouvelles factures par e-mail ';
				 break;
			case "reqdomicil" :
				 ebilchoicetit='Paiement automatique par domiciliation de votre compte ';
				 break;
		 }
		 break;
    case "N" :
		switch(ebilchoice) {
			case "showbill" :
				 ebilchoicetit='Toon online uw facturen ';
				 break;
			case "reqacces" :
				 ebilchoicetit='Toegang aanvragen tot online facturen ';
				 break;
			case "reqemail" :
				 ebilchoicetit='Ontvang uw facturen via e-mail ';
				 break;
			case "reqdomicil" :
				 ebilchoicetit='Onmiddellijk debiteren van uw rekening ';
				 break;
		 }
		 break;
    default :
		 ebilchoicetit='Display your billing documents online';
         break;
}




function menuclick(documents,typdoc,optie) {
	var docname=documents;
	if (ExternalID=="Y") {  KeyID="0101010101"};
	if (docname=="login") {		location.href=startHref;	}
	else	{
		if (docname=="logout") {
			location.href=logoutHref;
			window.close();
		}
		else {
			var setlocation="/";
			setlocation+=docdir;
			setlocation+="/";
			setlocation+=docname;
			setlocation+=".htm?SESSIONID=" + KeyID;
			switch(typdoc) {
				case "ebil" :
					setlocation+="&optbill=" + optie;
					break;
				default:
			};
			if (typdoc) {  //nothing yet 
					};
			//AG2707  add always timestmp
			setlocation+="&tmpstmp="+_aTimeStmp;
			document.location.href=setlocation;
		}  //end if else if  else
	}  //end if else
}

function homeclick(lang) {   //used homeclick for this was the old name and function in all pages, now closes the window
	if (!lang) {lang=docdir};
	window.close();
}

// function homeclick(lang) {
//          if (!lang) {lang=docdir};
// 	var setlocation="/";
// 	if (ExternalID=="Y") KeyId="1001001001";
// 	setlocation+="onlinetools.htm?SESSIONID=" + KeyID + "&lingua=";
//         setlocation+=lang;
// 	document.location.href=setlocation;
//  }


// function languageclick(lang) {
// 	var doclocation=docpathname(document.location.href);
// 	var setlocation="/";
// 	setlocation+=lang;
// 	setlocation+=doclocation ;
// 	document.location.href=setlocation;}
//



function chlang(lang) {

	var doclocation=docpathname(document.location.href);
	var setlocation="/";
	var linkdoct= doclocation.split("?");
	var linkdoc=linkdoct[0];
	var docsearch=linkdoct[1];
	var tochange = unescape(docsearch);

	if (pgmindic=="PGM") {	setlocation+=pgmindic;}
	else {
		if ((typeof doktype != "undefined")&& (doktype.toUpperCase()=="EDI"))   {
		//	a;
			setlocation+="EDIFILES/";
			//stringObject.lastIndexOf(searchvalue,fromindex);
			var tosearch=".";
			var llength= linkdoc.length;
			var linkToKeep=linkdoc.lastIndexOf(tosearch,llength);
			linkToKeep-=2;
			var linkdok=linkdoc.substring(1,linkToKeep);
			var langdok;
			switch (lang) {
				case "E" :
					langdok="EN";
					break;
				case "F" :
					langdok="FR";
					break;
				case "N" :
					langdok="NL";
					break;
			}
			linkdok+=langdok + '.htm';
			linkdoc=linkdok;
		}
		else {	setlocation+=lang; }
	}
	if(tochange=="undefined") {  setlocation+=linkdoc + "?pag=ext"; 	  }
	else {
		var tabel = new Array();
		var Arrea = tochange.split("&");
		var tempArray = new Array();
		for (i = 0; i < Arrea.length; i++) {
			tempArray = Arrea[i].split("=");
			switch (tempArray[0]) {
				case "lang" :
				case "LANG" :
				case "lingua" :
				case "LINGUA" :
				case "LANGSO" :
				case "Langue" :
				case "LANGUE" :
					 tempArray[1]=lang;
					 break;
			}
			if ((tempArray[0]!="tmpstmp")&&(tempArray[0]!="Tmstmp")&&(tempArray[0]!="NoFlag")&&(Arrea[i]!="undefined=undefined")) {
				tabel[i] = tempArray[0]+"="+tempArray[1];
			}
		}
		setlocation+=linkdoc + "?";
		setlocation+= tabel[0] ;
		for (i = 1; i < tabel.length; i++) {			setlocation+="&" + tabel[i] ;		}
	};
	//AG2707  add always timestmp
	if (typeof ntimestamp == "undefined") { var ndat=new Date();  var ntimestamp  = ndat.getTime() };
	setlocation+="&tmpstmp="+ntimestamp;
	//keep choosen language
	setlocation+='&NoFlag=Y';
	document.location.href=setlocation;
}


function pgmclick(lingua,service) {
	if (!lingua) {		lingua=docdir		};
	var langu=lingua;
	var sos= service;
	if (!sos) {
		sos = "book" ; // default online booking  ;
		if (document.forms[0].FLDI02) {  sos="track";           };
	};
	var setlocation="/" + langu + "/pgm/";
	switch (sos) {
		case "track" :
		case "TRACK" :
			setlocation+="WWWSELENVC.PGM";
			//Temporally until 12-10-2009
            openwin('tthelp','480','480','100','100');
			//
			if (!AccessApp(KeyID,2)) {alert(notaccess);
			return;}
			break;
		case "parc" :
		case "fr8" :
		case "xprs" :
		case "PARC" :
		case "FR8" :
		case "XPRS" :
			setlocation = "/"+langu+"/orderview.htm";
			if (!AccessApp(KeyID,1)) {alert(notaccess); return;}
			break;
		case "newtrack" :
		case "NEWTRACK" :
			setlocation = "/"+langu+"/ttselect.htm";
//			if (!AccessApp(KeyID,1)) {alert(notaccess); return;}
			//Temporally until 11-01-2009
//             openwin('tthelp2','480','480','100','100');
			break;
		case "EOD" :
		case "EODPARC" :
		case "EODFR8" :
		case "EODXPRS" :
		case "book" :
		case "BOOK" :
			setlocation="/"+langu+"/ordervieweod.htm";
			if (!AccessApp(KeyID,1)) {alert(notaccess); return;}
			break;
		case "deal" :
		case "DEAL" :
			setlocation="/"+langu+"/orderview_DealerCode.htm";
			if (!AccessApp(KeyID,1)) {alert(notaccess); return;}
			break;
		case "deac" :
		case "DEAC" :
			setlocation="/"+langu+"/DealerCodeCorrect.htm";
			if (!AccessApp(KeyID,1)) {alert(notaccess); return;}
			break;
		case "shim" :
		case "SHIM" :
			setlocation="/"+langu+"/ImpShipment.htm";
			if (!AccessApp(KeyID,1)) {alert(notaccess); return;}
			break;
		case "bill" :
		case "BILL" :
			setlocation="/"+langu+"/orderviewEBilling.htm";
//			if (!AccessApp(KeyID,5)) {alert(notaccess); return;}
			break;
		case "billemail":
		case "BILLEMAIL" :
			setlocation="/"+langu+"/eb_emaildomi.htm";
			break;
		case "billdomi":
		case "BILLDOMI" :
  			 window.open("domicilling.pdf");
  			 return;
             //setlocation="/"+langu+"/domicilling.pdf";
			break;
		case "otbi" :
		case "OTBI" :
			setlocation="/"+langu+"/EBilling.htm";
//			if (!AccessApp(KeyID,5)) {alert(notaccess); return;}
			break;
		case "logs" :
		case "LOGS" :
			setlocation="/"+langu+"/AdminLogs.htm";
			if (!AccessApp(KeyID,1)) {alert(notaccess); return;}
			break;
		case "log1s" :
		case "LOGS1" :
			setlocation="/"+langu+"/SetupByUser.htm";
			if (!AccessApp(KeyID,1)) {alert(notaccess); return;}
			break;
		default:
	};
	keuze="&SERVIES="+sos.toUpperCase() + countryIndicator;  //set in Functionsportal
	if (typeof ntimestamp == "undefined") {		var ndate=new Date(); var ntimestamp  = ndate.getTime();		};
	//EBILLING
	if(sos=='OTBI' || sos=='otbi'){setlocation+="?tmpstmp=" + ntimestamp; window.open(setlocation);}
	else		{
		setlocation+="?SESSIONID="+KeyID+"&Langue="+langu + keuze;
		setlocation+="&tmpstmp=" + ntimestamp;
		document.location.href=setlocation;
	}
}

function openwin(docname,wi,hi,le,to) {
         var setlocation='';
         var w='640';
         var l='100';
         var t='100';
         var h='560';
//		because quickref = pdf, no dimensions for open window
         if (docname=="quickrefsos") {wi="none"};
         if (wi=='none'){    //no dimensions on open win
            var nodim=true;
         }
         else {
             if (wi) w=wi;
             if (hi) h=hi;
             if (le) l=le;
             if (to) t=to;
         }       ;
        if (hi!='nodirec') {   //only possible with nodim
        	setlocation+="/";
        	setlocation+=docdir;
	};
	var tmstmp= new Date().getTime();
	setlocation+="/";
	setlocation+=docname;
	setlocation+=".htm?"+ tmstmp;
        if (nodim) { var winopen=window.open(setlocation,docname);  }
        else {     var winopen=window.open(setlocation,docname,'channelmode=no,directories=no,fullscreen=no,width='+w+',left='+l+',top='+t+',height='+h+',location=no,menubar=no,resizable=no,scrollbars=yes,status=no,titlebar=no,toolbar=no','true');  }
        winopen.focus()  ;
        }



