var info = new Array();
var publications = new Array();



function getDate(dates, dateType) {
   publi = "";
   
   switch (dateType){	
    	case "0": publi = dates.substr(6,2)+ "/" + dates.substr(4,2) + "/" + dates.substr(0,4);
               break; //dd/mm
     	case "1": publi = dates.substr(4,2)+ "/" + dates.substr(6,2) + "/" + dates.substr(0,4);
               break;  //mm/dd
     	case "2": publi = dates.substring(4, dates.length)+ " " + dates.substr(0,4);
               break;
     	default:  publi = dates;
               break;
   }
   return publi;
}

function makeInfo(type,publication,credit,FromDate,ToDate) {
   this.type = type;
   this.publication = publication;
   this.credit = credit
   this.FromDate = FromDate;
   this.ToDate = ToDate;
   return this;
}

function displayTerms(dateType){
   
   var pubid= document.getElementById("pubs").options[document.getElementById("pubs").selectedIndex].value;   
   if(info[pubid].type == "PERIOD"){
      document.getElementById("pterms").innerText=getDate(info[pubid].FromDate, dateType) + " - " + getDate(info[pubid].ToDate, dateType);
      document.getElementById("cterms").innerText="";
   }else{
      document.getElementById("cterms").innerText=info[pubid].credit;
      document.getElementById("pterms").innerText="";
   }
}


function openPaper(paper,pSetup, dir) {
   var edStart="";
   if(document.getElementById("pubs")){
      edStart= document.getElementById("pubs").options[document.getElementById("pubs").selectedIndex].text
   }
   
   if(edStart=="")
      win = window.open("/ee/"+dir+"/default.php?pSetup="+pSetup+"", "", "resizable=yes,toolbar=no,menubar=no,location=no,status=no,height=" + (screen.availHeight-30) + ",width=" + screen.availWidth);
   else
      win = window.open("/ee/"+dir+"/default.php?pSetup="+pSetup+"&editionStart="+encodeURIComponent(edStart)+"", "", "resizable=yes,toolbar=no,menubar=no,location=no,status=no,height=" + (screen.availHeight-30) + ",width=" + screen.availWidth);
    
   if(win) win.moveTo(0,0);
}

function logOut(){
   
   document.udb_api.TYPE.value='LOGOUT';
   document.udb_api.submit();
   
}

function buildInfo(paper, pSetup, dir, lang, dateType) {
   //0=english 1=italian 2=german 3=french 4=dutch 5=spanish
	var pub = "";
	var cred = "";
	var buttonS = "";
	var toComp=parseInt(lang,10);
	
	switch(toComp){
		case 1: uname="Username"; 
		         cred = "Crediti";
		         pub = "Pubblicazione";
		         buttonS = "Click to View";
		         break;
		case 5: uname="Username"; 	
		         cred = "Credit(s)";
					pub = "Publication";
					buttonS = "Click to View";
					break;
		case 2: uname="Benutzer";  
		         cred = "Kredit";
		         pub = "Ausgabe:";
		         buttonS = "Click to View";
		         break;
		case 4: uname="Username"; 	
		         cred = "Kredit";
					pub = "Publikation:";
					buttonS = "Click to View";
					break;
		case 3: uname="Username"; 
		         cred = "Crédits";
					pub = "Publication:";
					buttonS = "Navigue";
					break;
		case 0:
		default:	uname="Username"; 
		         cred = "Credit(s)";
					pub = "Publication";
					buttonS = "Click to View";
					break;
	}

   //toW = "<table style=\"border-left: 6px solid #4682B4\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
   toW = "<tr class=\"grid-default\">";
   toW += "<td nowrap class=\"grid-cell\"><b>"+pub+"</b></td>";
   
   if(publications.length == 1){
      for (var i=0;i<publications.length;i++) {
         //toW += "<td class=\"grid-cell\" valign=\"middle\"><div class=\"right\"><input class=\"submit\" value=\"&Ouml;ffnen\" type=\"Button\" onclick=\"openPaper(" + paper + ", \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></div>" + publications[i] + "</td>";
         toW += "<td class=\"grid-cell\" valign=\"middle\"><div class=\"right\"><input class=\"submit\" value=\"" + buttonS + "\" type=\"Button\" onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></div>" + publications[i] + "</td>";
      }

      toW += "</tr>";
      toW += "<tr class=\"grid-alternating\">";
      toW += "<td nowrap class=\"grid-cell\"><b>Period:</b></td><td>&nbsp;</td></tr>";
      for(var i=0;i<info.length;i++) {
         if (info[i].type == "PERIOD") {
            toW += "<td class=\"grid-cell\">"+ getDate(info[i].FromDate, dateType) + " - " + getDate(info[i].ToDate, dateType) + "</td>";
   
         }else{
				toW += "<td class=\"grid-cell\">&nbsp;</td>";
			}
      }
      toW += "</tr>";
      
      
      toW += "<tr class=\"grid-default\">";
      toW += "<td nowrap class=\"grid-cell\"><b>"+cred+":</b></td>";
      for(var i=0;i<info.length;i++) {
         if (info[i].type == "CREDIT") {
            //toW += "<tr><td>&nbsp;</td><td align='right' class=\"testo\">" + info[i].credit + "</td></tr>";
				toW += "<td align='right' class=\"testo\">" + info[i].credit + "</td>";
         }else{
				toW += "<td class=\"grid-cell\">&nbsp;</td>";
			}
      }   
      toW += "</tr>";
   }else{
			
		if(info.length==1){
         toW += "<td class=\"grid-cell\" valign=\"middle\">"+info[0].publication+"&nbsp;&nbsp;&nbsp;&nbsp;<input class=\"submit\" value=\"" + buttonS + "\" type=\"Button\" onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></td>";         
      }else{
         toW +="<td><select class='pulldown2' id='pubs' name='pubs' onChange='displayTerms(\""+ dateType +"\");'>";
         for (var i=0;i<info.length;i++) {      
            toW +="<option value='"+i+"'>"+info[i].publication+"</option>";
         }
         toW +="</select>&nbsp;&nbsp;<input class=\"submit\" value=\"" + buttonS + "\" type=\"Button\" onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></td>";      
      }
      
      toW += "</tr>";
      
      toW += "<tr class=\"grid-alternating\">";
      toW += "<td nowrap class=\"grid-cell\"><b>Userinfo:</b></td>";
      toW += "<td id='pterms' name='pterms' class=\"grid-cell\">";
      if (info[0].type == "PERIOD") {
         toW += getDate(info[0].FromDate, dateType) + " - " + getDate(info[0].ToDate, dateType);
      }
      toW += "</td>";
      toW += "</tr>";
      
      toW += "<tr class=\"grid-default\">";
      toW += "<td nowrap class=\"grid-cell\"><b>"+cred+"</b></td>";
      toW += "<td id='cterms' name='cterms' class=\"grid-cell\">";
      if (info[0].type == "CREDIT") {
         //toW += "<tr><td>&nbsp;</td><td align='right' class=\"testo\">" + info[0].credit + "</td></tr>";
			toW += info[0].credit;
      }
      toW += "</td>";     
      toW += "</tr>";   
   }   
   
   toW += "</table>";
   
   //toW += "<textarea>" + toW+ "</textarea>";
   document.write(toW);
}

function buildInfoKicker(paper, pSetup, dir, lang, dateType) {
   //0=english 1=italian 2=german 3=french 4=dutch 5=spanish
	var pub = "";
	var cred = "";
	var buttonS = "";
	var toComp=parseInt(lang,10);
	
	switch(toComp){
		case 1: uname="Username"; 
		         cred = "Crediti";
		         pub = "Pubblicazione";
		         buttonS = "Click to View";
		         break;
		case 5: uname="Username"; 	
		         cred = "Credit(s)";
					pub = "Publication";
					buttonS = "Click to View";
					break;
		case 2: uname="Benutzer";  
		         cred = "Kredit";
		         pub = "Ausgabe:";
		         buttonS = "Click to View";
		         break;
		case 4: uname="Username"; 	
		         cred = "Kredit";
					pub = "Publikation:";
					buttonS = "Click to View";
					break;
		case 3: uname="Username"; 
		         cred = "Crédits";
					pub = "Publication:";
					buttonS = "Navigue";
					break;
		case 0:
		default:	uname="Username"; 
		         cred = "Credit(s)";
					pub = "Publication";
					buttonS = "Click to View";
					break;
	}

   //toW = "<table style=\"border-left: 6px solid #4682B4\" cellpadding=\"0\" cellspacing=\"0\" border=\"2\">";
   toW = "<tr class=\"grid-default\">";
   toW += "<td nowrap class=\"grid-cell\"><b>"+pub+"</b></td>";
   
   if(publications.length == 1){
      for (var i=0;i<publications.length;i++) {
         //toW += "<td class=\"grid-cell\" valign=\"middle\"><div class=\"right\"><input class=\"submit\" value=\"&Ouml;ffnen\" type=\"Button\" onclick=\"openPaper(" + paper + ", \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></div>" + publications[i] + "</td>";
         toW += "<td class=\"grid-cell\" valign=\"middle\"><div class=\"right\"><input class=\"submit\" value=\"" + buttonS + "\" type=\"Button\" onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></div>" + publications[i] + "</td>";
      }

      toW += "</tr>";
      toW += "<tr class=\"grid-alternating\">";
      toW += "<td nowrap class=\"grid-cell\"><b>Period:</b></td>";
      for(var i=0;i<info.length;i++) {
         if (info[i].type == "PERIOD") {
            if (i > 0) {
               toW += "<tr><td>&nbsp;</td>";
            }
            toW += "<td class=\"grid-cell\">"+ getDate(info[i].FromDate, dateType) + " - " + getDate(info[i].ToDate, dateType) + "</td></tr>";
   
         }else{
				toW += "<td class=\"grid-cell\">&nbsp;</td></tr>";
			}
      }
      
      
      toW += "<tr class=\"grid-default\">";
      toW += "<td nowrap class=\"grid-cell\"><b>"+cred+":</b></td>";
      for(var i=0;i<info.length;i++) {
         if (info[i].type == "CREDIT") {
            //toW += "<tr><td>&nbsp;</td><td align='right' class=\"testo\">" + info[i].credit + "</td></tr>";
				toW += "<td align='right' class=\"testo\">" + info[i].credit + "</td>";
         }else{
				toW += "<td class=\"grid-cell\">&nbsp;</td>";
			}
      }   
      toW += "</tr>";
   }else{
			
		if(info.length==1){
         toW += "<td class=\"grid-cell\" valign=\"middle\">"+info[0].publication+"&nbsp;&nbsp;&nbsp;&nbsp;<input class=\"submit\" value=\"" + buttonS + "\" type=\"Button\" onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></td>";         
      }else{
         toW +="<td><select class='pulldown2' id='pubs' name='pubs' onChange='displayTerms(\""+ dateType +"\");'>";
         for (var i=0;i<info.length;i++) {      
            toW +="<option value='"+i+"'>"+info[i].publication+"</option>";
         }
         toW +="</select>&nbsp;&nbsp;<input class=\"submit\" value=\"" + buttonS + "\" type=\"Button\" onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></td>";      
      }
      
      toW += "</tr>";
      
      toW += "<tr class=\"grid-alternating\">";
      toW += "<td nowrap class=\"grid-cell\"><b>Userinfo:</b></td>";
      toW += "<td id='pterms' name='pterms' class=\"grid-cell\">";
      if (info[0].type == "PERIOD") {
         toW += getDate(info[0].FromDate, dateType) + " - " + getDate(info[0].ToDate, dateType);
      }
      toW += "</td>";
      toW += "</tr>";
      
      toW += "<tr class=\"grid-default\">";
      toW += "<td nowrap class=\"grid-cell\"><b>"+cred+"</b></td>";
      toW += "<td id='cterms' name='cterms' class=\"grid-cell\">";
      if (info[0].type == "CREDIT") {
         //toW += "<tr><td>&nbsp;</td><td align='right' class=\"testo\">" + info[0].credit + "</td></tr>";
			toW += info[0].credit;
      }
      toW += "</td>";     
      toW += "</tr>";   
   }   
   
   toW += "</table>";
   
   //toW += "<textarea>" + toW+ "</textarea>";
   document.write(toW);
}

function buildInfoNNBOld(paper, pSetup, dir, lang, dateType) {
   //0=english 1=italian 2=german 3=french 4=dutch 5=spanish
	var pub = "";
	var cred = "";
	var buttonS = "";
   var toComp=parseInt(lang,10);
		
	switch(toComp){
		case 1: uname="Username"; 
		         cred = "Crediti";
		         pub = "Pubblicazione";
		         buttonS = "Browse";
		         break;
		case 5: uname="Username"; 	
		         cred = "Credit(s)";
					pub = "Publication";
					buttonS = "Browse";
					break;
		case 2: uname="Benutzer";  
		         cred = "Kredit";
		         pub = "Ausgabe:";
		         buttonS = "Start";
		         break;
		case 4: uname="Username"; 	
		         cred = "Kredit";
					pub = "Publikation:";
					buttonS = "Browse";
					break;
		case 3: uname="Username"; 
		         cred = "Crédits";
					pub = "Publication:";
					buttonS = "Navigue";
					break;
		case 0:
		default:	uname="Username"; 
		         cred = "Credit(s)";
					pub = "Publication";
					buttonS = "Browse";
					break;
	}

   //toW = "<table style=\"border-left: 6px solid #4682B4\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
   toW = "<tr class=\"grid-default\">";
   toW += "<td nowrap class=\"grid-cell\"><b>"+pub+"</b></td>";
   
   if(publications.length == 1){
      for (var i=0;i<publications.length;i++) {
         //toW += "<td class=\"grid-cell\" valign=\"middle\"><div class=\"right\"><input class=\"submit\" value=\"&Ouml;ffnen\" type=\"Button\" onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></div>" + publications[i] + "</td>";
         toW += "<td class=\"grid-cell\" valign=\"middle\"><div class=\"right\"><input class=\"submit\" value=\"" + buttonS + "\" type=\"Button\" onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></div>" + publications[i] + "</td>";
      }

      toW += "</tr>";
      toW += "<tr class=\"grid-alternating\">";
      toW += "<td nowrap class=\"grid-cell\"><b>Userinfo:</b></td>";
      for(var i=0;i<info.length;i++) {
         if (info[i].type == "PERIOD") {
            toW += "<td class=\"grid-cell\">"+ getDate(info[i].FromDate, dateType) + " - " + getDate(info[i].ToDate, dateType) + "</td>";
   
         }
      }
      toW += "</tr>";
      
      
      toW += "<tr class=\"grid-default\">";
      toW += "<td nowrap class=\"grid-cell\"><b>"+cred+"</b></td>";
      for(var i=0;i<info.length;i++) {
         if (info[i].type == "CREDIT") {
            toW += "<tr><td>&nbsp;</td><td align='right' class=\"testo\">" + info[i].credit + "</td></tr>";
            toW += "<td class=\"grid-cell\">" + info[i].credit + "</td>";
         }
      }   
      toW += "</tr>";
   }else{
      if(info.length==1){
         toW += "<td class=\"grid-cell\" valign=\"middle\">"+info[0].publication+"&nbsp;&nbsp;&nbsp;&nbsp;<input class=\"submit\" value=\"" + buttonS + "\" type=\"Button\" onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></td>";         
      }else{
         toW +="<td><select class='pulldown2' id='pubs' name='pubs'>";
         for (var i=0;i<info.length;i++) {      
            toW +="<option value='"+i+"'>"+info[i].publication+"</option>";
         }
         toW +="</select>&nbsp;&nbsp;<input class=\"submit\" value=\"" + buttonS + "\" type=\"Button\" onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></td>";      
      }
      
      toW += "</tr>";
      
      /*
      toW += "<tr class=\"grid-alternating\">";
      toW += "<td nowrap class=\"grid-cell\"><b>Userinfo:</b></td>";
      toW += "<td id='pterms' name='pterms' class=\"grid-cell\">";
      if (info[0].type == "PERIOD") {
         toW += getDate(info[0].FromDate, dateType) + " - " + getDate(info[0].ToDate, dateType);
      }
      toW += "</td>";
      toW += "</tr>";
      
      toW += "<tr class=\"grid-default\">";
      toW += "<td nowrap class=\"grid-cell\"><b>"+cred+"</b></td>";
      toW += "<td id='cterms' name='cterms' class=\"grid-cell\">";
      if (info[0].type == "CREDIT") {
         //toW += "<tr><td>&nbsp;</td><td align='right' class=\"testo\">" + info[0].credit + "</td></tr>";
         toW += info[0].credit;
      }
      toW += "</td>";     
      toW += "</tr>"; 
      */  
   }   
   
   toW += "<tr class=\"grid-alternating\">";
   toW += "<td colspan=2 class=\"grid-cell\" valign=\"middle\">&nbsp;</td>"; 
   toW += "</tr>";

   toW += "<tr class=\"grid-default\">";
   toW += "<td colspan=2 class=\"grid-cell\" valign=\"middle\"><input class=\"submit\" value=\"Log Out\" type=\"Button\" onclick=\"logOut();return false;\"></td>"; 
   toW += "</tr>";
   
   toW += "</table>";
   
   //toW += "<textarea>" + toW+ "</textarea>";
   document.write(toW);
}

function buildInfoNNB(paper, pSetup, dir, lang, dateType) {
   //0=english 1=italian 2=german 3=french 4=dutch 5=spanish
	var pub = "";
	var cred = "";
	var buttonS = "";
   var toComp=parseInt(lang,10);
		
	switch(toComp){
		case 1: uname="Username"; 
		         cred = "Crediti";
		         pub = "Pubblicazione";
		         buttonS = "Browse";
		         break;
		case 5: uname="Username"; 	
		         cred = "Credit(s)";
					pub = "Publication";
					buttonS = "Browse";
					break;
		case 2: uname="Benutzer - Name";  
		         cred = "Kredit";
		         pub = "Ausgabe:";
		         buttonS = "hier";
		         break;
		case 4: uname="Username"; 	
		         cred = "Kredit";
					pub = "Publikation:";
					buttonS = "Browse";
					break;
		case 3: uname="Username"; 
		         cred = "Crédits";
					pub = "Publication:";
					buttonS = "Navigue";
					break;
		case 0:
		default:	uname="Username"; 
		         cred = "Credit(s)";
					pub = "Publication";
					buttonS = "Browse";
					break;
	}

   //toW = "<table style=\"border-left: 6px solid #4682B4\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
   toW = "<tr class=\"grid-default\">";
   toW += "<td colspan=2 class=\"grid-cell\"><span class='medium-txt'><br>Sie sind bereits eingeloggt!<br>Ihr Zeitungs-Fenster hat sich nicht geöffnet? Dann klicken Sie bitte </span><a href='#' class='medium-txt' onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"><b>"+buttonS+"!</b></a></td>";
   toW += "</tr>";
            
  // toW += "<tr class=\"grid-alternating\">";
  // toW += "<td colspan=2 class=\"grid-cell\" align='center' valign=\"middle\"><input class=\"submit\" value=\"" + buttonS + "\" type=\"Button\" onclick=\"openPaper('" + paper + "', \'"+ pSetup+ "\', \'"+ dir+"\');return false;\"></td>";         
  // toW += "</tr>";
         
   toW += "</table>";
   
   //toW += "<textarea>" + toW+ "</textarea>";
   document.write(toW);
}

function buildInfoOld() {
   toW = "<table width='100%' bgcolor=\"white\" align=\"right\" border=\"0\">";
   toW += "<tr><td colspan='2' class=\"testogiallo\">PUBLICATIONS</td></tr>";
   for (var i=0;i<publications.length;i++) {
      toW += "<tr><td class=\"testo\">" + publications[i] + "</td><td align='right'><input class=\"bottonebianco\" type=\"button\" value=\"browse\" onclick=\"openPaper();return false;\"></td></tr>";
   }

   toW += "<tr><td></td></tr>";   
   toW += "<tr _bgcolor=\"#FF9A00\"><td colspan='2' class=\"testogiallo\">USER INFO</td></tr>";
   for(var i=0;i<info.length;i++) {
      if (info[i].type == "PERIOD") {
         toW += "<tr><td class=\"testo\">" + info[i].publication + "</td><td align='right' class=\"testosmall\">" + getDate(info[i].ToDate) + "</td></tr>";
      }
   }

   toW += "<tr><td></td></tr>";   
   toW += "<tr _bgcolor=\"#FF9A00\"><td colspan='2' class=\"testogiallo\">CREDIT</td></tr>";   
   for(var i=0;i<info.length;i++) {
      if (info[i].type == "CREDIT") {
         toW += "<tr><td>&nbsp;</td><td align='right' class=\"testo\">" + info[i].credit + "</td></tr>";
      }
   }   
   
   toW += "</table>";
   document.write(toW);
}

function udb_submitForm() {
   var toret = false;
   var datepc = new Date();
   var whatToSave = 0;
   var pSetup = "";
   if (parent.contents && parent.contents.pSetup){
      pSetup = parent.contents.pSetup;
   }
   
   if (document.udb_api.challenge) {
      if (document.login.TYPE.value == "LOGIN") {
      
         var username = document.login.username.value;
         if(username=="")
         	return false;
         document.udb_api.username.value = document.login.username.value;
         document.udb_api.time.value = datepc.getTime() / 1000;
         var challenge = document.udb_api.challenge.value;
         
         
         
         var passwd = document.login.password.value;
         if(window.lowerCasePass && window.lowerCasePass != 0) passwd = passwd.toLowerCase();
         
         //alert("PASSWD: "+passwd);
         //alert("CHALLENGE: "+challenge);
         
         var hash = "";
         if(passwd == "*******"){
         	//saved in cookie
         	passwdEncrypted = cookie_get(pSetup+'_eePass');
         	//alert("PW"+passwdEncrypted);
         	if(challenge==0)
         	   hash = passwdEncrypted;
         	else
         	   hash = hex_md5(passwdEncrypted + challenge);
         }
         else if (challenge==0) {
         	hash=passwd; // do not encript on return
         } 
         else {
         	
         	//alert("IN FINAL ELSE");
	         	if(parent.contents && parent.contents.thirdPartyXOR){
			      	//alert("INTHIRDPARTY");
			      	challengeMD5 = hex_md5(challenge);
		      		challengeDec = parseInt(challengeMD5,16);
			      	passMD5 = hex_md5(passwd);
			      	passMD5Dec = parseInt(passMD5,16);
			      	XORRESULT = passMD5Dec ^ challengeDec;
		      		XORRESULTHEX = XORRESULT.toString(16);
			      	hash = hex_md5(XORRESULTHEX);
			      	document.udb_api.challenge.value = challengeMD5;
         		}else{
         			hash = hex_md5(hex_md5(passwd) +  challenge);
	         	}
         }

         //alert("HASH: "+hash);
         
         document.udb_api.password.value = hash;
         //alert(document.udb_api.username.value + " " + document.udb_api.password.value + " " + document.udb_api.challenge.value + " " + document.udb_api.action);
         document.udb_api.submit();
      } else { // LOGOUT
         var toret = true;
      }
   }
   

   //check if UserName and/or Password should be saved
	uName = document.login.username.value;
	
	//alert(document.login.password.value);
	if (challenge==0)
	   pWord = document.login.password.value;
	else
	   pWord = hex_md5(document.login.password.value);
	
	//alert("PWORD: "+pWord);
	
	if(document.login.preference){ //radio button for preferences
   
	   checkGrp = document.login.preference;
	   for(i=0; i<checkGrp.length; i++){
		   if(checkGrp[i].checked){
			   whatToSave = checkGrp[i].value;
		   }	
	   }
		
	   var expdate = new Date();
      expdate.setTime(expdate.getTime() + (86400 * 1000 * 2000)); 
	   //path = currentPath.substring(0,currentPath.lastIndexOf("/")+1);
      path = '/';
	   switch(whatToSave){
		   case "0": 
				   cookie_delete(pSetup+'_eePass');
				   cookie_delete(pSetup+'_eeUserName');
				   cookie_set(pSetup+'_eePref',whatToSave,expdate,path);
				   break;
		   case "1": 
					cookie_delete(pSetup+'_eePass');
				   //set usrename cookie
				   cookie_set(pSetup+'_eeUserName',uName,expdate,path);
				   //set preference cookie to 1
				   cookie_set(pSetup+'_eePref',whatToSave,expdate,path);
				   break;
		   case "2": 
					//set password cookie
				  if(!cookie_get(pSetup+'_eePass')) //set the cookie only the first time
				      cookie_set(pSetup+'_eePass',pWord,expdate,path);
				   //set usrename cookie
				   cookie_set(pSetup+'_eeUserName',uName,expdate,path);
				   //set preference cookie to 2
				   cookie_set(pSetup+'_eePref',whatToSave,expdate,path);
				   break;
	   } 
	} //end radio button preferences
	
   return toret;
}

function fillValues(){
	pref = 0;
	pass = "";
	user = "";
   var pSetup = "";
   
   if (parent.contents && parent.contents.pSetup){
      pSetup = parent.contents.pSetup;
   }
   /********* TO BE REMOVED AT A LATER DATE ONLY FOR MOVE OF PAPERS FROM ES1  Jim **********/
   //if data is in old cookie format then retrieve and write into new cookie format 
   var expdate = new Date();
   expdate.setTime(expdate.getTime() + (86400 * 1000 * 2000)); 
   path = '/';
   
   if (!cookie_get(pSetup+'_eePref')){
      eePref_cookie = cookie_get('eePref');
      if(eePref_cookie){
         cookie_delete('eePref');
         cookie_set(pSetup+'_eePref',eePref_cookie,expdate,path);
      }
      eePass_cookie = cookie_get('eePass');
      if(eePass_cookie){
         cookie_delete('eePass');
         cookie_set(pSetup+'_eePass',eePass_cookie,expdate,path);
      }
      eeUserName_cookie = cookie_get('eeUserName');
      if(eeUserName_cookie){
         cookie_delete('eeUserName');
         cookie_set(pSetup+'_eeUserName',eeUserName_cookie,expdate,path);
      }
   }
   //end of code to convert data from old cookies to new cookies  
   
	pref = cookie_get(pSetup+'_eePref');
	preferencesExists = false;
	if(document.login && document.login.preference){ //radio button for preferences
		preferencesExists = true;
	}
	if(!cookie_get(pSetup+'_eePref') || pref == 0 || !preferencesExists){
		pref = 0;
	}else{
		if(pref == 1){
			user = cookie_get(pSetup+'_eeUserName');
		}else{
			pass = "*******";
			user = cookie_get(pSetup+'_eeUserName');
			//alert("PASS: "+pass);
			//alert("USERNA"+user);
		}
	}
	if(document.login){
		document.login.username.value = user;
		document.login.password.value = pass;
		if(preferencesExists){
   		checkGrp = document.login.preference;
   		for(i=0; i<checkGrp.length; i++){
   			if(checkGrp[i].value == pref){
   				checkGrp[i].checked = true;
   			}	
   		}
		}
      if(pref == 1) document.login.password.focus();
	}
	
}


function cookieNotSet(){
 	var toret = '';
 	switch(parent.contents.Lang){
 		case 1:	toret = "No ci sono COOKIES";//italian
 				   break;
 		case 2:	toret = "Sie haben die Einstellung 'Cookies annehmen' in Ihrem Browser nicht aktiviert. ";
 					toret += "Bitte aktivieren Sie diese Einstellung. Ohne Cookies funktioniert diese Anwendung nicht korrekt.";      //german
 					break;
 		case 3:  //french
 		        toret = "Les Cookies semblent ne pas être acceptés sur votre Browser.  Page non visible sans cookies. ";
 					toret += "Activez les cookies et rappelez la page.";
 					break;

 		case 4:  //dutch
 		case 5:  //spanish
 		case 0:
 		default: toret = "It seems that cookies are disabled on your browser.  You cannot view the page without cookies. ";
 					toret += "Please enable cookies and reload the page";
 					break;
 	}
 	
 	return toret;
}


function udb_checkCookie() {
   //alert('check cookie');
   var toret = false;
   //alert(cookie_get("MACHINEID"));
   if (!(cookie_get("MACHINEID"))) {
      /*
      var msg = "Sie haben die Einstellung 'Cookies annehmen' in Ihrem Browser nicht aktiviert. ";
      msg += "Bitte aktivieren Sie diese Einstellung. Ohne Cookies funktioniert diese Anwendung nicht korrekt.";      
      */
      //english
   	//alert("INSIDE");
      var msg = "It seems that 3rd Party cookies or All Cookies are disabled on your browser. ";
      msg += "The system needs these cookies enabled to work. You may be asked to Login again";      

      document.write("<table width=\"100%\"><tr><td class=\"softerror\"><ul><li>" + msg + "</li></ul></td></tr></table>");
      
   } else {
      toret = true;
   }
   return toret;

}


