// SECTOR SECTION PK
var sel;
var ftxt_sector, ftxt_club, ftxt_work;
ftxt_sector ="";
function btnBack()
{
   history.back();
}

function getObject(fObject)
{
   return document.getElementById(fObject);
}

function setOptions(fID, oID, oValue, oText, oTitle)
{
   var myOption = getObject(fID);
   myOption.options[oID] =new Option();
   myOption.options[oID].value=oValue;
   myOption.options[oID].text=oText;
   myOption.options[oID].title=oTitle;
}

function setOptionsEmpty(fID, oID, oTrue, oLength)
{
   var myOption = getObject(fID);
   myOption.options[oID].options[oID]=new Option('','');
   myOption.options[oID].disabled=oTrue;
   myOption.options[oID].options.length= oLength;
}

function selSector()
{
   var sstart,ssel,send,i2;
   i2 = 0;
   for(i=0;i<=cSector;i++)
   {
      if(mySector[i][0] == "999999999")
      {
         setOptions('csector', i2, mySector[i][0], mySector[i][1], mySector[i][3]);
         sel = i2;
         i2 = i2+1;
      }
      else
      {
         setOptions('csector', i2, mySector[i][0], mySector[i][1], mySector[i][3]);
         i2 = i2+1;
      }
   }
   document.getElementById("grund").style.display = "none";
}

function getSectorSub(fText)
{
   var div_sub = document.getElementById("subtext");
   for(i=0;i<=cSector;i++)
   {
      if(mySector[i][0] == fText)
      {
         div_sub.innerHTML = mySector[i][2];
      }
   }
}

function getSectorSub2(fText)
{
   var div_sub = document.getElementById("subtext");
   var inp_subtitle = document.getElementById("sectorsubtitle");
   var s;
   var reg1 = new RegExp('<SUB_TITLE>','gi');
   var reg2 = new RegExp('</SUB_TITLE>','gi');
   for(i=0;i<=cSector;i++)
   {
      if(mySector[i][0] == fText)
      {
         s = mySector[i][2];
         var result = s.replace(reg1,'').replace(reg2,'').replace(/\&aelig;/,'æ').replace(/\&oslash;/,'ø').replace(/\&aring;/,'å');
         div_sub.innerHTML = result;
         result = result.substring(5,6).toUpperCase()+result.substring(6);
         inp_subtitle.value = result;
      }
   }
}

function SectorChange(fVar)
{
    
   var my_sub =document.getElementById("csector").options[document.getElementById("csector").selectedIndex].value;
/* ftxt_sector = document.getElementById("csector").options[document.getElementById("csector").selectedIndex].title; */
   getSectorSub(my_sub);
   if(fVar !='')
   {
      document.getElementById("cclub").disabled = false;
      selClub(fVar);
      document.getElementById("cworkfunction").options.length=0;
      document.getElementById("sector").value = document.getElementById("csector").value;

      document.getElementById("arb").style.display = "inline";
      document.getElementById("grund").style.display = "none";
 
      if(document.getElementById("csector").options[document.getElementById("csector").selectedIndex].value == 8)
      {
         document.getElementById("jobstatus").value ="";
         document.getElementById("jobstatustext").value ="";
         document.getElementById("cjobstatus").selectedIndex = 0;
         document.getElementById("trjobstatus1").style.visibility = "visible";
         document.getElementById("trjobstatus1").style.position = "relative";
         document.getElementById("workfunctiontr").style.visibility = "visible";
         document.getElementById("workfunctiontr").style.position = "relative";
         document.getElementById("ortr").style.visibility = "visible";
         document.getElementById("ortr").style.position = "relative";
      }
      else
      {
         document.getElementById("trjobstatus1").style.visibility = "visible";
         document.getElementById("trjobstatus1").style.position = "relative";
         document.getElementById("arb").style.display = "inline";
         document.getElementById("grund").style.display = "none";
      }
      
      if(document.getElementById("csector").options[document.getElementById("csector").selectedIndex].value == 9)
      {
         document.getElementById("cjobstatus").selectedIndex = 0;
         document.getElementById("workfunctiontr").style.visibility = "hidden";
         document.getElementById("workfunctiontr").style.position = "absolute";
         document.getElementById("ortr").style.visibility = "hidden";
         document.getElementById("ortr").style.position = "absolute";  
         document.getElementById("trjobstatus1").style.visibility = "hidden";
         document.getElementById("trjobstatus1").style.position = "absolute";
         document.getElementById("arb").style.display = "none";
         document.getElementById("grund").style.display = "inline";

      }
      else
      {
         document.getElementById("workfunctiontr").style.visibility = "visible";
         document.getElementById("workfunctiontr").style.position = "relative";
         document.getElementById("ortr").style.visibility = "visible";
         document.getElementById("ortr").style.position = "relative";
         document.getElementById("trjobstatus1").style.visibility = "visible";
         document.getElementById("trjobstatus1").style.position = "relative";
         document.getElementById("arb").style.display = "inline";
        document.getElementById("grund").style.display = "none";

      }

/*      alert("Club id :"+document.getElementById("cclub").options[document.getElementById("cclub").selectedIndex].value); */

      selWorkFunction(document.getElementById("cclub").options[document.getElementById("cclub").selectedIndex].value);
      
   }
   else
   {
      setOptionsEmpty('cclub', 0, true, 0);
      setOptionsEmpty('cworkfunction', 0, true, 0);
   }
}

function SectorChange2(fVar) 
{
   var my_sub =document.getElementById("csector").options[document.getElementById("csector").selectedIndex].value;
   //ftxt_sector = document.getElementById("csector").options[document.getElementById("csector").selectedIndex].title;
   getSectorSub2(my_sub);
   if(fVar !='')
   {
      document.getElementById("cclub").disabled = false;
      selClub(fVar);
      document.getElementById("cworkfunction").options.length = 0;
      document.getElementById("sector").value = document.getElementById("csector").value;
      if(document.getElementById("csector").options[document.getElementById("csector").selectedIndex].value == 8)
      {
         document.getElementById("jobstatus").value ="";
         document.getElementById("jobstatustext").value ="";
         document.getElementById("cjobstatus").selectedIndex = 0;
         document.getElementById("workfunctiontr").style.visibility = "visible";
         document.getElementById("workfunctiontr").style.position = "relative";
         document.getElementById("ortr").style.visibility = "visible";
         document.getElementById("ortr").style.position = "relative";
         document.getElementById("trjobstatus1").style.visibility = "visible";
         document.getElementById("trjobstatus1").style.position = "relative";
      }
      if(document.getElementById("csector").options[document.getElementById("csector").selectedIndex].value == 9)
      {
         document.getElementById("cjobstatus").selectedIndex = 0;
         document.getElementById("workfunctiontr").style.visibility = "hidden";
         document.getElementById("workfunctiontr").style.position = "absolute";
         document.getElementById("ortr").style.visibility = "hidden";
         document.getElementById("ortr").style.position = "absolute";
         document.getElementById("trjobstatus1").style.visibility = "hidden";
         document.getElementById("trjobstatus1").style.position = "absolute";
      }
      else
      {
         document.getElementById("workfunctiontr").style.visibility = "visible";
         document.getElementById("workfunctiontr").style.position = "relative";
         document.getElementById("ortr").style.visibility = "visible";
         document.getElementById("ortr").style.position = "relative";
         document.getElementById("trjobstatus1").style.visibility = "visible";
         document.getElementById("trjobstatus1").style.position = "relative";
      }
   }
   else
   {
      setOptionsEmpty('cclub', 0, true, 0);
      setOptionsEmpty('cworkfunction', 0, true, 0);
   }
}
// END SECTOR SECTION

function f_sortClub()
{
   var s = 0;
   for(i=0;i<myClub.length;i++)
   {
      if(myClub[i][0] =="999999999")
      {
         sortClub[s] = myClub[i];
      }
    }
    for(i=0;i<myClub.length;i++)
    {
       if(myClub[i][0] =="999999999")
       {}
       else if(myClub[i][1] =="")
       {}
       else
       {
          s = s+1;
          sortClub[s] = myClub[i];
       }
   }
}

function selClubDefault()
{
   var i2;
   i2 = 0;
   f_sortClub();
   document.getElementById("cclub").options.length = 0;
   try
   {
      for(i=0;i<sortClub.length;i++)
      {
         if(sortClub[i][2] == "999999999")
         {
            if(sortClub[i][0] == "999999999")
            {
               setOptions('cclub', i2, sortClub[i][0], sortClub[i][1], sortClub[i][3]);
               sel = i2;i2 = i2+1;
            }
            else
            {
               setOptions('cclub', i2, sortClub[i][0], sortClub[i][1], sortClub[i][3]);
               i2 = i2+1;
            }
         }
      }
   }
   catch(e)
   {}
}

function selClub(fID)
{
   var i2,sID;
   i2 = 0;
   ssel = "";
   f_sortClub();
   sID = parseInt(fID);
   //alert("SID:"+sID);
   document.getElementById("cclub").options.length = 0;
   try
   {
      // document.getElementById("cclub").options[0] = new Option('','');
      i2 = 0; // i2 + 1 with emty first line; 
      for(i=0;i<sortClub.length;i++)
      {
         if(sID == sortClub[i][2])
         {
            setOptions('cclub', i2, sortClub[i][0], sortClub[i][1], sortClub[i][3]);
            i2 = i2+1;
         }
      }
   }
   catch(e)
   {
      alert("Fejl: "+e.expression);
   }
   // ClubChange(document.getElementById("cclub").options[0].value);
}

function workSelAll()
{
   var i2;
   i2 = 0;
   var s;
   sortWork.length =0;
   s = 0;
   for(i=0;i<myWorkfunction.length;i++)
   {
      var test = false;
      for(j=0;j<sortWork.length;j++)
      {
         if((myWorkfunction[i][0] == sortWork[j][0]))
         {
            test = true;
            break;
         }
      }
      if(test == false)
      {
         if((myWorkfunction[i][0] ==""))
         {
         }
         else
         {
            var len = sortWork.length;
            sortWork[len] = myWorkfunction[i];
         }
      }
   }
   document.getElementById("cworkfunction").options.length = 0;
   for(i=0;i<sortWork.length;i++)
   {
      setOptions('cworkfunction', i2, sortWork[i][0], sortWork[i][1], sortWork[i][3]);
      i2 = i2+1;
   }
   i2 = 0;
   document.getElementById("cworkfunction2").options.length = 0;
   for(i=0;i<sortWork.length;i++)
   {
      setOptions('cworkfunction2', i2, sortWork[i][0], sortWork[i][0], sortWork[i][3]);
      i2 = i2+1;
   }
}

function ClubChange(fVar)
{
   if(fVar !='')
   {
      document.getElementById("cworkfunction").disabled = false;
      selWorkFunction(fVar);
   }
   else
   {}
}

function ChangeWork(fID,fcombo)
{
   if(fcombo =="1")
   {
      document.getElementById("cworkfunction2").selectedIndex = fID;
   }
   else
   {
      document.getElementById("cworkfunction").selectedIndex = fID;
   }
}

/* Select option for WorkFunction field */
function selWorkFunction(fID)
{
   var i2,sID;
   i2 = 0;
   ssel = "";
   sID = parseInt(fID);
   document.getElementById("cworkfunction").options.length = 0;
   try
   {
      for(i=0;i<=cWorkfucktion;i++)
      {
         if(sID == myWorkfunction[i][2])
         {
            setOptions('cworkfunction', i2, myWorkfunction[i][0], myWorkfunction[i][1], myWorkfunction[i][3]);
            i2 = i2+1;
         }
      }
   }
   catch(e)
   {}
   selWorkFunction2(fID);
}

function selWorkFunction2(fID)
{
   var i2,sID;
   i2 = 0;
   ssel = "";
   sID = parseInt(fID);
   document.getElementById("cworkfunction2").options.length = 0;
   try
   {
      for(i=0;i<=cWorkfucktion;i++)
      {
         if(sID == myWorkfunction[i][2])
         {
            setOptions('cworkfunction2', i2, myWorkfunction[i][0], myWorkfunction[i][0], myWorkfunction[i][3]);
            i2 = i2+1;
         }
      }
   }
   catch(e)
   {}
}

function selDefaultWFunction()
{
   var i2;
   i2 = 0;
   document.getElementById("cworkfunction").options.length = 0;
   try
   {
      for(i=0;i<=cWorkfucktion;i++)
      {
         if(myWorkfunction[i][2] == "999999999")
         {
            if(myWorkfunction[i][0] == "999999999")
            {
               setOptions('cworkfunction', i2, myWorkfunction[i][0], myWorkfunction[i][1], myWorkfunction[i][3]);
               sel = i2;
               i2 = i2+1;
            }
            else
            {
               setOptions('cworkfunction', i2, myWorkfunction[i][0], myWorkfunction[i][1], myWorkfunction[i][3]);
               i2 = i2+1;
            }
         }
      }
   }
   catch(e)
   {
      //alert("Fejl: "+e.expression);
   }
   selDefaultWFunction2();
}

function selDefaultWFunction2()
{
   var i2;
   i2 = 0;
   document.getElementById("cworkfunction2").options.length = 0;
   try
   {
      for(i=0;i<=cWorkfucktion;i++)
      {
         if(myWorkfunction[i][2] == "999999999")
         {
            if(myWorkfunction[i][0] == "999999999")
            {
               setOptions('cworkfunction2', i2, myWorkfunction[i][0], myWorkfunction[i][0], myWorkfunction[i][3]);
               sel = i2;
               i2 = i2+1;
            }
            else
            {
               setOptions('cworkfunction2', i2, myWorkfunction[i][0], myWorkfunction[i][0], myWorkfunction[i][3]);
               i2 = i2+1;
            }
         }
      }
   }
   catch(e)
   {}
}

function selJobstatus()
{
   var i2;
   i2 = 0;
   for(i=1;i<=cJobstatus;i++)
   {
      setOptions('cjobstatus', i2, myJobstatus[i][0], myJobstatus[i][1], myJobstatus[i][2]);
      i2 = i2+1;
   }
}

function checkSelectInputs()
{
   var fsector, fclub, fwork, fjob;
   var selIndex = -1;
   s = "";
   fsector = document.getElementById("csector");
   fclub = document.getElementById("cclub");
   fwork = document.getElementById("cworkfunction");
   fjob = document.getElementById("cjobstatus");
   s = s+"Sector: "+fsector.value+"\n";
   s = s+"Club: "+fclub.value+"\n";
   s = s+"Work: "+fwork.value+"\n";
   s = s+"Job: "+fjob.value
   if((fsector.value=="") || (fclub.value=="") || (fwork.value==""))
   {
      alert("Husk at udfylde alle felter");
      return false;
   }
   else
   {
      s ="";
      try
      {
         selIndex = fsector.selectedIndex;
         document.getElementById("sector").value = fsector.value;
         document.getElementById("sectortext").value = fsector.options[selIndex].title;
         selIndex = fclub.selectedIndex;
         document.getElementById("club").value = fclub.value;
         document.getElementById("clubtext").value = fclub.options[selIndex].title;

         selIndex = fwork.selectedIndex;
         document.getElementById("workfunction").value = fwork.value;
         document.getElementById("workfunctiontext").value = fwork.options[selIndex].title;

         selIndex = fjob.selectedIndex;
         document.getElementById("jobstatus").value = fjob.value;
         document.getElementById("jobstatustext").value = fjob.options[selIndex].title;

         s = s+"Club: "+document.getElementById("club").value+"\n";
         s = s+"Sector: "+document.getElementById("sector").value+"\n";
         s = s+"Work: "+document.getElementById("workfunction").value+"\n";

         return true;
      }
      catch(e)
      {
         return false;
         alert(e.expression);
      }
      s = s+"Job: "+document.getElementById("jobstatus").value+"\n.:: End ::.";
   }
}

function TestVal()
{
   if(checkSelectInputs()==true)
   {
     document.forms['salary1'].submit();
   }
}

function TestValEnough()
{
   if(checkSelectInputs()==true)
   {
      document.forms['salary_enough'].submit();
   }
}

function OpenHelp(fText, fWidth, fHeight)
{
   var setTop, setLeft;
   if((fWidth==null)||(fWidth=="")) fWidth = 550;
   if((fHeight==null)||(fHeight=="")) fHeight = 350;
   setTop = (parseInt(screen.height)/2)-(fHeight/2);
   setLeft = (parseInt(screen.width)/2)-(fWidth/2);
   help_txt = "";
   help_txt = fText;
   if(newWindow!=null)
      newWindow.close();
   //newWindow = openWin(help_p, fWidth, fHeight, setTop, setLeft);
   newWindow = window.open(help_p, "Help", "top="+setTop+",left="+setLeft+",width="+fWidth+",height="+fHeight+",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=0,resizable=0");
   newWindow.focus();
}

function setText()
{
   newWindow.document.getElementById('thisWinContent').innerHTML = help_txt;
}

function OpenHelpPrint(fText, fWidth, fHeight)
{
   var setTop, setLeft;
   if((fWidth==null)||(fWidth=="")) fWidth = 580;
   if((fHeight==null)||(fHeight=="")) fHeight = 350;
   setTop = (parseInt(screen.height)/2)-(fHeight/2);
   setLeft = (parseInt(screen.width)/2)-(fWidth/2);
   help_txt = "";
   help_txt = fText;
   if(newWindow!=null)
      newWindow.close();
   //newWindow = openWin(help_p, fWidth, fHeight, setTop, setLeft);
   newWindow = window.open(help_p_print, "Help", "top="+setTop+",left="+setLeft+",width="+fWidth+",height="+fHeight+",toolbar=0,location=0,directories=0,status=0,menuBar=0,scrollBars=1,resizable=1"); 
   //setTimeout("setText()",500);
   newWindow.focus();
}

function submitenter(myfield,e)
{
   var keycode;
   if (window.event) keycode = window.event.keyCode;
   else if (e) keycode = e.which;
   else return true;
   if (keycode == 13)
   {
      document.getElementById('salary_enough').submit();
      return false;
   }
   else
      return true;
}

