window.load = init();


function openSubMenu(sid,pid){
  new Ajax.Updater('submenu', 'getsubmenu.php?selid='+sid+'&pid='+pid, {onComplete: expandMenu, asynchronous:true, evalScripts:true});
}

function ShowHideChildItems(listItem, state){

  if(listItem){
    if(listItem.tagName == "LI"){
      var item_id = listItem.id.substr(4);
      var child_ul = document.getElementById('subnavigatie'+item_id);
      var current_li = '';
      
      //collapse all items in corresponding menu
      var parent_node = listItem.parentNode;
      for(i=0;i<=parent_node.childNodes.length-1;i++){
        current_li = parent_node.childNodes[i];        
        //console.log(current_li.className)     
        if(current_li.className == 'nav_item_open') current_li.className = 'nav_item_has_si'   
        for(j=0;j<=current_li.childNodes.length-1;j++){
          //console.log(current_li.childNodes[j].tagName);
          if(current_li.childNodes[j].tagName == "UL"){
            current_li.childNodes[j].style.display = 'none'
          }
        }
      }
      
      
      
      if(typeof state != 'undefined'){
        if(state == 'block' || state == 'none'){
        if(child_ul){
          child_ul.style.display = state;
            if(state == 'block'){
              listItem.className = 'nav_item_open'
            }
          }
        }
      }else{
        if(child_ul.style.display == '' || child_ul.style.display == 'block'){
          child_ul.style.display = 'none';
          listItem.className = 'nav_item_has_si'
          return;
        }else{
          child_ul.style.display = 'block';
          listItem.className = 'nav_item_open'
          return;
        }
      }
    }
  }
}


/*
function ShowHideChildItems(listItemId, close){



//console.log(listItemId) 
if(close == true){
  closeAllMenus();
}
listItem = document.getElementById(listItemId);
//console.log(listItem) 
  if(listItem){
    
    var item_id = listItem.id.substr(4);
    
    childsdisplay = document.getElementById('childs'+item_id) 
    if(childsdisplay.style.display == 'block'){
      childsdisplay.style.display = 'none';
      listItem.className = 'nav_item_has_si'
    }else{
      childsdisplay.style.display = 'block';    
      listItem.className = 'nav_item_open'
      openParents(listItem);
    }
    //console.log(listItem.style.backgroundImage)
    //console.log(document.getElementById('childs'+item_id).style.display )
    Childs = document.getElementById('childs'+item_id).getElementsByTagName('div');
    //console.log(Childs.length);
    
    
    document.getElementById('childs'+item_id).style.height = ((Childs.length * 27)- getChilds('childs'+item_id))+'px'
    //console.log(document.getElementById('childs'+item_id).style.height);
  }

}
*/

function getChilds(parent){

  parent = document.getElementById(parent)
  console.log(parent)
  minus = 0;
  Childs = parent.getElementsByTagName('div')
 
  for(i = 0;i <= Childs.length;i++){
  
    if(Childs[i]){
      console.log(Childs[i].className.substr(0,5));
      if(Childs[i].className.substr(0,6) == 'childs'){   
        console.log('er is een child');
        childChilds = document.getElementById(Childs[i].id).getElementsByTagName('div')        
        minus +=  (childChilds.length + 1) * 27;
      } 
    }
  }
  console.log(minus)
  return minus;
}

function openParents(geopendItem){
  
  //console.log('geopend:'+geopendItem.id)
  
  menuitems = document.getElementById('navigatie').getElementsByTagName('div');

  for(i = 0;i <= menuitems.length;i++){
    
    if(menuitems[i]){
      
      if(menuitems[i].className == 'childs'){
       //menuitems[i].style.display = 'none';
       //console.log(menuitems[i])
       var item_id = menuitems[i].id.substr(6);
       //console.log(item_id)
       //listItem = document.getElementById('item'+item_id);
       //listItem.className = 'nav_item_has_si'
       
      }
    }
  }
}


function closeAllMenus(){

  menuitems = document.getElementById('navigatie').getElementsByTagName('div');

  for(i = 0;i <= menuitems.length;i++){
    
    if(menuitems[i]){
      
      if(menuitems[i].className == 'childs'){
       menuitems[i].style.display = 'none';
       //console.log(menuitems[i])
       var item_id = menuitems[i].id.substr(6);
       //console.log(item_id)
       listItem = document.getElementById('item'+item_id);
       listItem.className = 'nav_item_has_si'
       
      }
    }
  }
}

function Siferize(){

  
 
  
  var gill = {
    //src: 'http://www.3point7designs.com/blog/aharoni.swf'
    src: 'sifr/flash/sifr.swf'
    //src: 'sifr/demo/cochin.swf'
  };


  sIFR.debugMode = true;
  // sIFR.domains = ['novemberborn.net'] // Don't check for domains in this demo
  sIFR.prefetch(gill);
  sIFR.activate();
  
  
  sIFR.replace(gill, {
    selector: '#menutop',
    wmode: 'transparent',
    css: [
      '.sIFR-root { text-align: right; font-size: 16px; color: #063f2e; list-style: none }'
      ,'a { color: #063f2e; text-decoration: none }'
      ,'a:hover { color: #063f2e; text-decoration: underline }'

    ]
  });
  
    sIFR.replace(gill, {
    selector: 'div.contactheader',
    wmode: 'transparent',
    leading: '5',
    css: [
      '.sIFR-root { font-size: 14px; color: #063e2c; }'
      ,'a { color: #063e2c; text-decoration: none }'
      ,'a:hover { color: #063e2c; text-decoration: underline }'
    ]
  });
  
  

    sIFR.replace(gill, {
    selector: 'div#paginaTitel',
    wmode: 'transparent',
    leading: '5',
    css: [
      '.sIFR-root { font-weight: bold; font-size: 16px; color: #063e2c; }'
      ,'a { color: #063e2c; text-decoration: none }'
      ,'a:hover { color: #063e2c; text-decoration: underline }'
    ]
  });  
  
  
  
}

function getVar(name)
         {
         get_string = document.location.search;         
         return_value = '';
         
         do { //This loop is made to catch all instances of any get variable.
            name_index = get_string.indexOf(name + '=');
            
            if(name_index != -1)
              {
              get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
              
              end_of_value = get_string.indexOf('&');
              if(end_of_value != -1)                
                value = get_string.substr(0, end_of_value);                
              else                
                value = get_string;                
                
              if(return_value == '' || value == '')
                 return_value += value;
              else
                 return_value += ', ' + value;
              }
            } while(name_index != -1)
            
         //Restores all the blank spaces.
         space = return_value.indexOf('+');
         while(space != -1)
              { 
              return_value = return_value.substr(0, space) + ' ' + 
              return_value.substr(space + 1, return_value.length);
							 
              space = return_value.indexOf('+');
              }
          
         return(return_value);        
         }


function DetectFlash(){
var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

// Check to see if the version meets the requirements for playback
if (!hasReqestedVersion) {

  var pid = getVar('pid');
  if(pid == ''){
    window.location = window.location +"?pid="+115+"&setmenu=noflash";
  }
}

}

function init(){
  DetectFlash();
  Siferize(); 
  //ShowHideChildItems('item'+getVar('pid'))
}

function calcPhcp(ehcp, par, sr, cr)
{
	phcp = (ehcp * sr / 113) + cr - par;
	return phcp;
}

function calcPhcp9h(ehcp, par, sr, cr)
{
	phcp = (ehcp * sr / 113 + cr - (par * 2)) / 2;
	return phcp;
}

function calculate()
{
	// haal Exact handicap op
	tmp_ehcp = document.getElementById('ehcp').value;
	
  
  hbt = Array();
  hmt = Array();
  hft = Array();
  
  dbt = Array();
  dmt = Array();
  dft = Array();
  
	
	tmp_s = tmp_ehcp.replace(',','.');
	ehcp = new Number(tmp_s);
	
	// berekenen playing handicap
	hbt[0] = Math.round(calcPhcp(ehcp, 72.0, 132, 72.8));
	hmt[0] = Math.round(calcPhcp(ehcp, 72.0, 126, 70.9));
	hft[0] = Math.round(calcPhcp(ehcp, 72.0, 123, 68.8));

	dbt[0] = Math.round(calcPhcp(ehcp, 72.0, 128, 72.9));
	dmt[0] = Math.round(calcPhcp(ehcp, 72.0, 122, 71.4));
	dft[0] = Math.round(calcPhcp(ehcp, 72.0, 113, 72.0));


	hbt[1] = Math.round(calcPhcp9h(ehcp, 36.0, 131, 71.5));
	hmt[1] = Math.round(calcPhcp9h(ehcp, 36.0, 128, 69.6));
	hft[1] = Math.round(calcPhcp9h(ehcp, 36.0, 123, 68.6));

	dbt[1] = Math.round(calcPhcp9h(ehcp, 36.0, 124, 71.9));
	dmt[1] = Math.round(calcPhcp9h(ehcp, 36.0, 120, 70.2));
	dft[1] = Math.round(calcPhcp9h(ehcp, 36.0, 0, 0));


	hbt[2] = Math.round(calcPhcp9h(ehcp, 36.0, 134, 74.0));
	hmt[2] = Math.round(calcPhcp9h(ehcp, 36.0, 125, 72.1));
	hft[2] = Math.round(calcPhcp9h(ehcp, 36.0, 123, 68.9));

	dbt[2] = Math.round(calcPhcp9h(ehcp, 36.0, 131, 73.9));
	dmt[2] = Math.round(calcPhcp9h(ehcp, 36.0, 125, 72.5));
	dft[2] = Math.round(calcPhcp9h(ehcp, 36.0, 0, 0));


 
  if(document.getElementById('geslM').checked == true){
    geslacht = 'male'
    result_bt = hbt;
    result_mt = hmt;
    result_ft = hft;
  }else if(document.getElementById('geslV').checked == true){
    geslacht = 'female'
    result_bt = dbt;
    result_mt = dmt;
    result_ft = dft;
  }
  
  resultaat = '<br><h3>Aantal slagen</h3><hr><br><b>18 holes</b><br>playing hcp medaltees:'+ result_mt[0] +'<br>playing hcp backtees:'+ result_bt[0] +'<br>playing hcp forwardtees:'+ result_ft[0] +'<br><br><b>1ste 9 holes</b><br>playing hcp medaltees:'+ result_mt[1] +'<br>playing hcp backtees:'+ result_bt[1] +'<br>playing hcp forwardtees:'+ result_ft[1] +'<br><br><b>2de 9-holes</b><br>playing hcp medaltees:'+ result_mt[2] +'<br>playing hcp backtees:'+ result_bt[2] +'<br>playing hcp forwardtees:'+ result_ft[2] +'<br>';
  document.getElementById('result').innerHTML = resultaat;	
}



