// JavaScript Document

function MouseOver(obj){
	obj = document.getElementById(obj)
	if (obj){
		if (obj.src.indexOf('_on') > -1){
			obj.src = obj.src.replace('_on.gif','.gif')
		}else{
			obj.src = obj.src.replace('.gif','_on.gif')
		}
	}
}


function enterTournooi(e) {
	
	var aantalballen,prijsperbal,subtotaal,totaal,opbrengsten,diverse;
	
	aantalballen = Number(document.getElementById('aantalballen').value);
	prijsperbal = Number(document.getElementById('prijsperbal').value);
	opbrengsten = Number(document.getElementById('opbrengsten').value);
	diverse = Number(document.getElementById('diverse').value);
	
	subtotaal = aantalballen * prijsperbal
	totaal = (subtotaal+opbrengsten+diverse)
	
	document.getElementById('subtotaal').value = Math.round(subtotaal*100)/100;
	document.getElementById('totaal').value = Math.round(totaal*100)/100;	
	

	//var totaal = (ronde1 * tarief1)+(ronde2 * tarief2)+(ronde3 * tarief3)+(ronde4 * tarief4)+(ronde5 * tarief5);
	
	//document.getElementById('totaal').value = Math.round(totaal*100)/100;
}

function editVan() {
	if(document.getElementById('tot').selectedIndex < document.getElementById('van').selectedIndex){
		document.getElementById('tot').selectedIndex = document.getElementById('van').selectedIndex+1
	};
}

function editTot() {
	if(document.getElementById('van').selectedIndex > document.getElementById('tot').selectedIndex){
		document.getElementById('van').selectedIndex = document.getElementById('tot').selectedIndex 
	};
}	

function initSIFR() {
	if(typeof sIFR == "function"){
		// header big, black
		sIFR.replaceElement(named( {
			sSelector:"h1",
			sFlashSrc: application.projectURL + "flash/h1.swf",
			sColor:"#11cb0c",
			sWmode:"transparent",
			nPaddingTop:0,
			nPaddingBottom:0,
			sFlashVars:"textalign=left&offsetTop=0"
			}
		));
		sIFR.replaceElement(named( {
			sSelector:"h2",
			sFlashSrc: application.projectURL + "flash/h1.swf",
			sColor:"#FFFFFF",
			sWmode:"transparent",
			nPaddingTop:0,
			nPaddingBottom:0,
			sFlashVars:"textalign=left&offsetTop=0"
			}
		));
	};
}

/*
function isNumberKey(e) {
	var k;
	document.all ? k = e.keyCode : k = e.which;
	return ((k > 47 && k < 58));
}
*/

function EditText(id1,id2,content, defaultValue) {
	document.getElementById(id1).innerHTML = (defaultValue)?(content!="")?content:defaultValue:content;
	document.getElementById(id2).innerHTML = (defaultValue)?(content!="")?content:defaultValue:content;
}
function changeTextFieldValue(frm, fld, changeVal, setVal)
{
	var formField = document.forms(frm)[fld];
	formField.value = (formField.value==changeVal)?setVal:formField.value;
}

function showNumberField(val)
{
	
	var textFieldTD = document.getElementById("td_account");
    var textField = document.getElementById("account");
    
    textFieldTD.style.display = (val=="machtiging")?'inline':'none';
    textField.title = (val=="machtiging")?'Bank- of gironummer':'';

}

function printme() {
	var objOut = document.getElementById("output");
	var out = objOut.innerHTML;
		
	var objFooter = document.getElementById("output_footer")
	var footer
	if(objFooter) footer = objFooter.innerHTML;
    else footer = ""
		
	var wh = window.open("","wh","width=460px,height=380px,scrollbars=yes");
	wh.document.open();
	var output = '<link href="css/popup.css" rel="stylesheet" type="text/css">';
	output += '<'+'script type="text/javascript">';
	output += 'window.print();';	
	output += '</'+'script>';
	output = '<html><head>'+output+'</head><body>'+out+footer+'</body></html>';
	wh.document.writeln(output);
	wh.document.close();
}

//functie voor setten van checkboxen
function check(v,id,input) {
	var obj = document.getElementById(input)
	var rest
	if(obj.value.indexOf(','+v+',')==-1){
		if(obj.value==''){
			obj.value=','
		}
		if(obj.value!=''){
			obj.value=obj.value+v+',';
		}
		document.getElementById(id).src = document.getElementById(id).src.replace('.gif','_o.gif')
	}else{
		obj.value = obj.value.replace(','+v+',',',')
		if(obj.value.length==1) obj.value=''
		document.getElementById(id).src = document.getElementById(id).src.replace('_o.gif','.gif')
	}
}

function printSelection(node,title){
	var content=node.innerHTML
	var pwin=window.open('','print_content','width=715,height=700');
	pwin.document.open();
	pwin.document.write(title);
	pwin.document.write('<html><body onLoad="window.print()">'+content+'</body></html>');
	pwin.document.close(); 
	setTimeout(function(){pwin.close();},1000);
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function addAviWeekNumbers(obj,WeekNr){
	
	try{
	 // title,value, position
	 obj.add(new Option(WeekNr, WeekNr), null) //add new option to end of "sample"
	}
	catch(e){ //in IE, try the below version instead of add()
	 obj.add(new Option(WeekNr, WeekNr)) //add new option to end of 'sample'
	}
}

function getLastAviItem(maxWeekNumber,selectedvalue,selectedindex){
	selectBoX_van=document.getElementById("van")
	var selectBoX_tot=document.getElementById("tot")
	selectBoX_tot.options.length = 0;
	
	var count = 0;
	var sval = parseInt(selectedvalue);
	var iInt = 0;
		
	for (i=0;i<=(maxWeekNumber-sval);i++)
	{
		iInt = parseInt(i);
		count = (sval+iInt);
		
		//alert(selectBoX_van.options[i+selectedindex].value+"&count"+count);//+"="+count);
			if(selectBoX_van.options[i+selectedindex].value==count){
				addAviWeekNumbers(selectBoX_tot,selectBoX_van.options[i+selectedindex].value)
			}else{
				break;
			}
		iInt = 0
		count = 0
	}	
}

function object(o) {
  function F () { };
  F.prototype = o;
  return new F();
}


var ParsedURL = (function() {
  var nature, rexParseURL;

  // taken from RFC 3986
  // http://tools.ietf.org/html/rfc3986#page-50
  rexParseURL = /^(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
  //               12            3    4           5       6  7        8 9

  rexParseURLParts = {
    "scheme": 2,
    "authority": 4,
    "path": 5,
    "query": 7,
    "fragment": 9
  }


  nature = {
    parse: function(url) {
      var key, val, matches = rexParseURL.exec(url);
      for (key in rexParseURLParts) {
				if (rexParseURLParts.hasOwnProperty(key)) {
					val = matches[rexParseURLParts[key]];
					if (val) {
						this[key] = val;
					}
				}
      }
    },
		toString: function() {
			var s = "";
			if (this.scheme !== undefined) 			{ s += this.scheme + ":" ; }
			if (this.authority !== undefined) 	{ s += "//" + this.authority; }
			s += this.path;
			if (this.query !== undefined) 			{ s += "?" + this.query; }
			if (this.fragment !== undefined) 		{ s += "#" + this.fragment; }
			return s;
		}
  }

  return function(url) {
    var o = object(nature);
    o.parse(url);
    return o;
  }
} ());

if (!Array.prototype.filter)   
{   
  Array.prototype.filter = function(fun /*, thisp*/)   
  {   
    var len = this.length >>> 0;   
    if (typeof fun != "function")   
      throw new TypeError();   
  
    var res = [];   
    var thisp = arguments[1];   
    for (var i = 0; i < len; i++)   
    {   
      if (i in this)   
      {   
        var val = this[i]; // in case fun mutates this   
        if (fun.call(thisp, val, i, this))   
          res.push(val);   
      }   
    }   
  
    return res;   
  };   
} 


