function jfSetNieuwFocus(field)	
	{	
	document.frmMatches.field.focus();
	}

function jfUpdatePlayer(matID, matLid)	
	{	
	document.frmMatches.txtAction.value= "UP"	;
	document.frmMatches.txtMatID.value= matID	;
	document.frmMatches.txtMatLid.value= matLid;
		
	document.frmMatches.submit() ;	
	}

function jfUpdateIngedeeld(matID, matLid)	
	{	
	document.frmMatches.txtAction.value= "UI"	;
	document.frmMatches.txtMatID.value= matID	;
	document.frmMatches.txtMatLid.value= matLid;
		
	document.frmMatches.submit() ;	
	}
function jfUpdateBevestigd(matID, matLid, matValue)	
	{	
	if (matValue == 0) document.frmMatches.txtAction.value= "UB0"	;
	if (matValue == 1) document.frmMatches.txtAction.value= "UB1"	;

	document.frmMatches.txtMatID.value= matID	;
	document.frmMatches.txtMatLid.value= matLid;
		
	document.frmMatches.submit() ;	
	}

function jfReLogin(url)  	
  	{ 
	if (url=="" || url.length ==0 ||  url.substring(url.length, url.length - 1) == "?" )
	window.location.href='login.asp';
	else
	window.location.href='login.asp?' + url;
	}

function jfChangePassword(url)  	
  	{
	if (url=="" || url.length ==0 ||  url.substring(url.length, url.length - 1) == "?" )
	window.location.href='changepasswordzamigolid.asp';
	else
	window.location.href='changepasswordzamigolid.asp?' + url;
	}
	
function jfLogUsers(lang)  	
  	{
	if (lang == "UK")
	window.location.href='users.asp?lang=UK';
	else
	window.location.href='users.asp';
	}

function jfEditMatches()  	
  	{
 
	document.frmMatches.txtAction.value= "M"	;
	document.frmMatches.hSort.value= ""	;
	document.frmMatches.submit() ;
	}
	
function jfEditPlayers()  	
  	{
	document.frmMatches.txtAction.value= "P"	;
	document.frmMatches.hSort.value= ""	;
	document.frmMatches.txtSelectMatID.value= ""	;
	document.frmMatches.txtSelectLidID.value= "";
	document.frmMatches.txtSelectStatusID.value= "";
	document.frmMatches.txtSelectIngedeeldID.value= "";
	document.frmMatches.txtSelectBevestigdID.value= "";
	document.frmMatches.submit() ;
	}
function jfUpdateMatch(matID, matAction)  	
  	{
  	tDatum="txtWedDatum_" + matID;	
	tTegenstander="txtWedTegenstander_" + matID;	
	tVenue="txtWedVenue_" + matID;
	tOpen="ddWedOpen_" + matID;

	if (document.frmMatches.elements[tDatum].value.length == 0 || document.frmMatches.elements[tTegenstander].value.length == 0 || document.frmMatches.elements[tVenue].value.length == 0)
		{
			alert ("Not all fields are filled in");
		}
		else
		{			
		if (isDate(document.frmMatches.elements[tDatum].value))
			{
			document.frmMatches.txtAction.value= matAction	;
			document.frmMatches.txtMatID.value= matID	;
			document.frmMatches.submit() ;
			}
			else
			{
			document.frmMatches.elements[tDatum].focus();
			}
		}
	}

function jfOpstelling(matID)  	
  	{
	document.frmMatches.txtAction.value = "O";
	document.frmMatches.txtOpstelling.value = matID;
	document.frmMatches.submit() ;
	}
	
function jfInsertNewMatch()  	
  	{
  	tDatum="txtNewWedDatum" ;
	tTegenstander="txtNewWedTegenstander";
	tVenue="txtNewWedVenue" ;
 
	
	if (document.frmMatches.txtNewWedDatum.value.length == 0 || document.frmMatches.txtNewWedTegenstander.value.length == 0 || document.frmMatches.txtNewWedVenue.value.length == 0)
		{
			alert ("Not all fields are filled in");
		}
		else
		{
		if (isDate(document.frmMatches.txtNewWedDatum.value))
			{
			document.frmMatches.txtAction.value= "IM"	;
			document.frmMatches.submit() ;
			}
			else
			{
			document.frmMatches.txtNewWedDatum.focus();
			}
		}
	}
	
function jfClearNewMatch()  	
  	{
	document.frmMatches.txtNewWedDatum.value = "" ;
	document.frmMatches.txtNewWedTegenstander.value = "" ;
	document.frmMatches.txtNewWedVenue.value = "" ;
	}
	
function jfClearZoek()  	
  	{
 	document.frmMatches.ddKiesSpeler.value = "" ;
	document.frmMatches.ddKiesWedstrijd.value = "" ;
	document.frmMatches.txtUpdateAfter.value= "" ; 
	document.frmMatches.ddKiesStatus.value = "" ;
	document.frmMatches.ddKiesIngedeeld.value = "" ;
	document.frmMatches.ddKiesBevestigd.value = "" ;

	document.frmMatches.txtSelectLidID.value = "" ;
	document.frmMatches.txtSelectMatID.value = "" ;
	document.frmMatches.txtSelectStatusID.value = "" ;
	document.frmMatches.txtSelectIngedeeldID.value = "" ;
	document.frmMatches.txtSelectBevestigdID.value = "" ;
	document.frmMatches.txtUpdate.value = "" ;

	document.frmMatches.submit() ;
	}
	
	
function jfSelectMatchPlayer()
	{
	document.frmMatches.txtAction.value= "";
	document.frmMatches.txtSelectMatID.value= document.frmMatches.ddKiesWedstrijd.value	;
	document.frmMatches.txtSelectLidID.value= document.frmMatches.ddKiesSpeler.value	;  
	document.frmMatches.txtSelectStatusID.value= document.frmMatches.ddKiesStatus.value	;  
	document.frmMatches.txtSelectIngedeeldID.value= document.frmMatches.ddKiesIngedeeld.value	;  
	document.frmMatches.txtSelectBevestigdID.value= document.frmMatches.ddKiesBevestigd.value	;
	
	if (document.frmMatches.txtUpdateAfter.value.length != 0)
		{
		if (isDate(document.frmMatches.txtUpdateAfter.value))
			{
			document.frmMatches.txtUpdate.value = (document.frmMatches.txtUpdateAfter.value);
			}
			else
			{
			document.frmMatches.txtUpdate.value = "";
			}
		}	
	document.frmMatches.submit() ;
	}
	
function jfSubmit()
	{
	document.forms[0].submit() ;
	}
	
var dtCh= "-";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function stripSpaces(s){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a space, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (c != " " ) returnString += c;
    }
    return returnString;    
}

function sReplace(s,olds,news){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is olds, replace with news and add to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (c == olds) 
        	{returnString += news;}
        	else
        	{returnString += c;}
    }
    return returnString;
}
    
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	dtStr=stripSpaces(dtStr)
	dtStr=sReplace(dtStr,"/","-")
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)

	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd-mm-yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert(dtStr+"Please enter a valid date")
		return false
	}
return true
}



function ChangDateNLUS(dtStr){
	dtStr=stripSpaces(dtStr)
	dtStr=sReplace(dtStr,"/","-")
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)

	return (month+"-"+day+"-"+year)
}	

function ChangDateUSNL(dtStr){

dtStr=stripSpaces(dtStr)
	dtStr=sReplace(dtStr,"/","-")
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)

	return (day+"-"+month+"-"+year)
}

function jfSort(x)
{

if (x == "GewijzigdOp") 
	{
	if (document.forms[0].hSort.value == "MatGewijzigd") 
	{document.forms[0].hSort.value = "MatGewijzigd DESC";}
	else
	{document.forms[0].hSort.value = "MatGewijzigd";}
	};
if (x == "GewijzigdDoor") 
	{
	if (document.forms[0].hSort.value == "MatGewijzigdDoor") 
	{document.forms[0].hSort.value = "MatGewijzigdDoor DESC";}
	else
	{document.forms[0].hSort.value = "MatGewijzigdDoor";}
	};
if (x == "Datum") 
	{
	if (document.forms[0].hSort.value == "wedDatum") 
	{document.forms[0].hSort.value = "wedDatum DESC";}
	else
	{document.forms[0].hSort.value = "wedDatum";}
	};
if (x == "LidNR") 
	{
	if (document.forms[0].hSort.value == "matLid") 
	{document.forms[0].hSort.value = "matLid DESC";}
	else
	{document.forms[0].hSort.value = "matLid";}
	};
if (x == "Achternaam") 
	{
	if (document.forms[0].hSort.value == "ACHTERNAAM") 
	{document.forms[0].hSort.value = "ACHTERNAAM DESC";}
	else
	{document.forms[0].hSort.value = "ACHTERNAAM";}
	};
if (x == "Voornaam") 
	{
	if (document.forms[0].hSort.value == "VOORNAAM") 
	{document.forms[0].hSort.value = "VOORNAAM DESC";}
	else
	{document.forms[0].hSort.value = "VOORNAAM";}
	};
if (x == "ID") 
	{
	if (document.forms[0].hSort.value == "wedID") 
	{document.forms[0].hSort.value = "wedID DESC";}
	else
	{document.forms[0].hSort.value = "wedID";}
	};
if (x == "Tegenstander") 
	{
	if (document.forms[0].hSort.value == "wedTegenstander") 
	{document.forms[0].hSort.value = "wedTegenstander DESC";}
	else
	{document.forms[0].hSort.value = "wedTegenstander";}
	};
if (x == "Lokatie") 
	{
	if (document.forms[0].hSort.value == "wedVenue") 
	{document.forms[0].hSort.value = "wedVenue DESC";}
	else
	{document.forms[0].hSort.value = "wedVenue";}
	};
if (x == "Ingedeeld") 
	{
	if (document.forms[0].hSort.value == "matIngedeeld") 
	{document.forms[0].hSort.value = "matIngedeeld DESC";}
	else
	{document.forms[0].hSort.value = "matIngedeeld";}
	};
if (x == "Bevestigd") 
	{
	if (document.forms[0].hSort.value == "MatBevestigd") 
	{document.forms[0].hSort.value = "MatBevestigd DESC";}
	else
	{document.forms[0].hSort.value = "MatBevestigd ";}
	};
if (x == "Status") 
	{
	if (document.forms[0].hSort.value == "wedOpen") 
	{document.forms[0].hSort.value = "wedOpen DESC";}
	else
	{document.forms[0].hSort.value = "wedOpen";}
	};
if (x == "SStatus") 
	{
	if (document.forms[0].hSort.value == "matStatus") 
	{document.forms[0].hSort.value = "matStatus DESC";}
	else
	{document.forms[0].hSort.value = "matStatus";}
	};
	
document.forms[0].submit();
}
	
function jfExport(varinput) {
	if (varinput =="4x") alert('If the next page doesnt show, allow pop-ups! \n\n If it shows, to export, in the next page\n Select File-Save As \n\n Save the following file as an ".XLS-"-file!');
	document.forms[0].action="matches_xml.asp?export=" + varinput;
	document.forms[0].target="_blank";
	document.forms[0].submit()
	}
