//
// By Kim A.A. 
// cook: Navn
// val : værdi
// pos : position i indeks
// deep: dybde i Indeks Array 
//
function SetCookInArray( cook, val, pos ,deep ,Cpath ,dage ,boolean )
{
 var strtmp="",expdato;
  expdato = CreatCookieDate( dage );
  strtmp=getCookie(cook);
    CookArray = new Array(deep);
  Load_array( strtmp ,CookArray ,CookArray.length ,',');
    CookArray[pos] = val;
  setCookie(cook ,CookArray ,expdato ,Cpath);
   if( boolean == true ) alert( getCookie(cook) );
}

//
// By Kim A.A. 
// Husk at Opret Global Array  "CookArr" på den side der bruger : GetAllCookiesInArray(cookName ,debug)
// eks: CookArr = new Array(10);
//
function GetAllCookiesInArray( cookName ,debug )
{
 var strtmp="";
   strtmp = getCookie(cookName);
    
   strtmp = Udskift_Karakter_i_Streng(strtmp, " ", "+"); // Fjerner "+" 
        
   Load_array( strtmp ,CookArr ,CookArr.length ,',');
   // TEST for(i=0; i<CookArr.length; i++) alert("CookArr["+i+"]: " + CookArr[i]);
  if(debug == true) alert( cookName+ ": " + strtmp );
}

// By Kim A.A. 
// Kopier Sep. streng til Array()
// ny = new Array(3)
// eks.  str = "en,to,tre"  Efter  // ny[0] = "en" , ny[1] = "to" , osv.
// Kopier Sep. streng til Array()
//
function Load_array( S1,  Sarray ,LCount ,Sep)
{
 var i=0 ,j=0 ,ch="" ,tmp="";
 
 if(S1==null) return-1;
 
 for (j=0; LCount-1;)
 {
   tmp="";
   
   do {
      ch = S1.substr(i,1);
      // alert("ch != Sep : " + ch + " != " + Sep + "\ni: " +i+ "\nS1.length: " + S1.length);       // alert("ch: " + ch + "<br>");
        
      if( ch != 34 && ch != Sep && ch != 13 ) {
        tmp = tmp + ch;
        //alert("tmp: " + tmp ); // document.write ("tmp: " + tmp + "<br>");
      } 
       //
      if( ch == Sep ) {
          tmp = Udskift_Karakter_i_Streng(tmp, ' ' ,'_');
         Sarray[j] = tmp;
         // alert("Sarray["+j+"]: " + Sarray[j] );
      }
      i++;
    
     if(i >= S1.length ) return(1);
   }while( ch != Sep && i <= S1.length)  
  
  ch="";
  j++;
 } 
 // 
} 

//
// Udskifter alle karaktere med Ny karakter i Streng
//
function Udskift_Karakter_i_Streng(Str1, Nych, Oldch)
{
 var i, tmp="" ,ch;
  if(Str1 == "" || Str1 == null ) return Str1;
  
 for( i=0; i< Str1.length;)
 {
   ch  = Str1.substr(i,1);
    if( Oldch == ch) ch=Nych;
     // alert("Oldch: " + Oldch + "\n Nych: " + Nych );
   tmp = tmp + ch;
  i++; 
 }
 return tmp;
} 


var En_dag=1,dato="";

//
//  Siste nye getUTCDate()   By Kim A.A.
//
function getUTCDate()
{
  var d, s = ""; 
  d = new Date();
  s += (d.getUTCMonth() + 1) + "-";  s += d.getUTCDate() + "-";
  s += d.getUTCFullYear();  return(s);
}

//
//  Siste nye By Kim A.A.
//  Retunere ASP Cookies
//
function GetAspCookie( gruppe ,name) {  
  var pos=0 ,GrStr="";
  var dc = document.cookie; 
  var prefix = gruppe + "=";
    
  name = name.toUpperCase();
  
  // alert( "Gruppe :" + GrStr );
  
// Find Cookie gruppe.
  pos = dc.indexOf(prefix,0);  
  if( pos == -1) return "";
  
// Gruppe streng.
  GrStr = dc.substring(pos , dc.length ); 
  // alert( "Gruppe :" + GrStr );
 
// Find Cookie i Gruppe.
  var begin = GrStr.indexOf( name ,0);  
  if( begin == -1) return "";
  else begin = begin + name.length+1;
  
 //  alert("name: " + name + "\nbegin: " + begin + "\nGruppe :" + GrStr );

  var end = GrStr.indexOf("&", begin)
  if( end == -1)  end = GrStr.indexOf(";", begin);  
  if( end == -1) return "";
            
  GrStr = GrStr.substring(begin , end );
   
// Fjerner  Karakter "+"
  while( GrStr.indexOf("+",0) != -1 ) { GrStr = GrStr.replace("+"," ");  }
 return unescape( GrStr );
}





//
// Under opbygning. Tjekker Cookie tilladelse.
//	 
function  TESTCookieAccess() {
  var  res;
  res = window.clientInformation.cookieEnabled;
  if( res == false) {
   alert( "This Application most use Cookies.\n" +
          "you have to set Allow Cookies in your Internet-Browser. In: " + 
          "Advanced or in Security option " );
    return -1;
   } 
 return 1;
} 


//
// Opreter Expires Dato.
//
function CreatCookieDate( days )
{
 now = new  Date();
 now.setTime(now.getTime() + days * 24 * 60 * 60 * 1000);
 return now;
}


// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) 
{
 if(name == "" || value == "" ) return -1;
 // expires=CreatCookieDate(1);
  // alert("expires: " + expires + "\n expires: " + expires.toGMTString() );
   
  var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "" ) + 
  ((path) ? "; path=" + path : "") + 
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : ""); 
  document.cookie = curCookie;
}
// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {  
  var dc = document.cookie; 
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  
  if (begin == -1)
  {
    begin = dc.indexOf(prefix);  
    if (begin != 0) return null; 
  } else
    begin += 2;  var end = document.cookie.indexOf(";", begin); 
  if (end == -1)
   end = dc.length; 
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) { 
 if (getCookie(name))
 {
  document.cookie = name + "=" + ((path) ? "; path=" + path : "")+ ((domain) ? "; domain=" + domain : "") +  "; expires=Thu, 01-Jan-70 00:00:01 GMT"; 
  
 }
}
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date)
{
 var base = new Date(0); 
 var skew = base.getTime();
 if (skew > 0)  date.setTime(date.getTime() - skew);
}


var nam="";

//
//  objnr = Object Der skal vises i.
//  Vises Best i TextArea
// 
function Vis_Forms_objecter(objnr)
{
 var i, Elements_count, str;
 
 str="";
 frm1.TEXTAREA.value="";
 
 
 Elements_count = document.forms(0).length;
 
 for(i=0; i<Elements_count;)  {
  str += "Object Nr: " + (i+1) + "\t" +document.forms(0).item(i).name + ":\t" +document.forms(0).item(i).value +  "\n";
  i++;
 }
// alert("str.length : " + str.length +"\nfrm1.TEXTAREA.value.length : " + frm1.TEXTAREA.value.length);
 
   frm1.TEXTAREA.value = str;
  //document.forms(0).item(objnr-1).value = str
}

function GetScriptEngineInfo(){ 
 var s;
  s = ""; // Build string with necessary info.
  s += ScriptEngine()+ " Version ";
  s += ScriptEngineMajorVersion() + ".";
  s += ScriptEngineMinorVersion() + ".";
  s += ScriptEngineBuildVersion();
 return(s);
}

//
function GemCookie() {
 indx = document.cookie.indexOf(" End;");
 nam = document.cookie.substring(0,indx+1);
  
//  document.cookie = frm.txtCokName.value + "=" + frm1.txtCokvalue.value + " End;";
 setCookie(frm.txtCokName.value, frm1.txtCokvalue.value, "Tuesday, 31-Dec-99" );
 // document.cookie += " Expires=Tuesday, 31-Dec-99 23:59:00 GMT"
  
 frm1.TEXTAREA.value = document.cookie;
  // alert("pause");
 
}

//
function VisCookie(Navn,value)
{
 var str ="";
  
  GemCookie();
  document.frm.txtCokvalue.value = getCookie(Navn);
  
   frm1.TEXTAREA.value = document.cookie;
 // frm1.submit();
}

