
function pop(url, w, h)
{
	window.open(url,'popup','width='+w+',height='+h+',scrollbars=yes,resizable=yes,toolbar=no,location=no,top=10, left=10');
}
function trace(eID, pswd)
{
	window.open('/trace.php?ID='+eID+'&passwd='+pswd,'popup','width=680,height=500,scrollbars=yes,resizable=yes,toolbar=no,location=no,top=10,left=10');
}
function thehistory(eID, pswd){
	window.open('/check_history.php?ID='+eID+'&passwd='+pswd,'popup','width=680,height=500,scrollbars=yes,resizable=yes,toolbar=no,location=no,top=10,left=10');
}

function askCheck(eQuestion, eUrl)
{
	res = 	window.confirm(eQuestion);
	if(res)	document.location.href=eUrl;
}
function showHide(eID){
	if(document.getElementById(eID).style.display=='none')	
	{
		document.getElementById(eID).style.display='block';
	}
	else
	{
		document.getElementById(eID).style.display='none';
	}
}

function show(eID){
	document.getElementById(eID).style.display='block';
}
function hide(eID){
	document.getElementById(eID).style.display='none';
}
function asksCheck(eQuestion, eForm){
	res = 	window.confirm(eQuestion);
	if(res)	eForm.submit();
}

function selectAll(containing, self){
	var x = document.getElementsByTagName('INPUT');
	for (var i=0;i<x.length;i++) {
		if(x[i].id.indexOf(containing)!=-1){
			x[i].checked = self.checked;
		}
	}
}
function selectAllMulti(){
	var x = document.getElementsByTagName('INPUT');
	for (var i=0;i<x.length;i++) {
		if(x[i].id.indexOf('printlabel_')!=-1){
			x[i].checked = document.getElementById('select_all').checked;
		}
	}
}

function doMultiWagen(){
	document.multiPrint.action='/';
	document.multiPrint.target='_self';
	if(document.multiPrint.wagenID.value!=0)
	{
		document.multiPrint.toDo.value='select_get_cars';
		document.multiPrint.submit()
	}
	else alert('U moet wel een wagen selecteren.');
}

function doMultiMoveToGather(){
	document.multiPrint.action='/';
	document.multiPrint.target='_self';
	document.multiPrint.toDo.value='move_package_to_gather';
	document.multiPrint.submit()
}

function downloadFile(eUrl){
	window.open(eUrl);
}
function doMultiPrint(){
	document.multiPrint.toDo.value='print';
	document.multiPrint.submit()
}
function doImportDelete(){
	document.multiPrint.action='/';
	document.multiPrint.target='_self';
	document.multiPrint.toDo.value='importDelete';
	document.multiPrint.submit()
}
function doImportIncheck(){
	document.multiPrint.action='/';
	document.multiPrint.target='_self';
	document.multiPrint.toDo.value='importIncheck';
	document.multiPrint.submit()
}
function doMultiIncheck(){
	document.multiPrint.action='/';
	document.multiPrint.target='_self';
	document.multiPrint.toDo.value='multiIncheck';
	document.multiPrint.submit();
}

function doMultiDelete(){
	document.multiPrint.action='/';
	document.multiPrint.target='_self';
	document.multiPrint.toDo.value='multiDelete';
	document.multiPrint.submit()
}


function doMultiFile(){
	document.multiPrint.toDo.value='file';
	document.multiPrint.submit()
}
function printEtiket(eID, passwd){
	window.open('/label/'+eID+'/'+passwd+'/label.pdf','Label','width=640,height=480,scrollbars=no,toolbar=no,location=no,top=10, left=10');
}

function changeHalen(eID){
	if(eID=='post') {
		document.getElementById('table_post').style.display	= 'block';
		document.getElementById('table_get').style.display	= 'none';
	}
	else if(eID=='get'){
		document.getElementById('table_get').style.display	= 'block';
		document.getElementById('table_post').style.display	= 'none';
	}
}
function check_add_adress_to()
{
	if(document.form_add_adresboek_to.company.value=='') 			alert('Niet ingevuld : Bedrijfsnaam');
	else if(document.form_add_adresboek_to.street.value=='') 		alert('Niet ingevuld : Straat');
	else if(document.form_add_adresboek_to.number.value=='') 		alert('Niet ingevuld : Nummer');
	else if(document.form_add_adresboek_to.zip.value=='') 			alert('Niet ingevuld : Postcode');
	else if(document.form_add_adresboek_to.city.value=='') 			alert('Niet ingevuld : Plaats');
	else 															return true;
	return 	false;
}

function check_form_aanmelden(){
	if(document.form_aanmelden.company.value=='') 			alert('Niet ingevuld : Bedrijfsnaam');
	else if(document.form_aanmelden.contact.value=='') 		alert('Niet ingevuld : Contact persoon');
	else if(document.form_aanmelden.street.value=='') 		alert('Niet ingevuld : Straat');
	else if(document.form_aanmelden.zip.value=='') 			alert('Niet ingevuld : Postcode');
	else if(document.form_aanmelden.city.value=='') 		alert('Niet ingevuld : Plaats');
	else if(document.form_aanmelden.phone.value=='') 		alert('Niet ingevuld : Telefoon');
	else if(document.form_aanmelden.email.value=='') 		alert('Niet ingevuld : E-mail');
	else if(document.form_aanmelden.password1.value=='') 	alert('Niet ingevuld : Wachtwoord');
	else if(document.form_aanmelden.password1.value!=document.form_aanmelden.password2.value)	alert('Let op: Wachtwoord en Wachtwoord Controle zijn niet gelijk');
	else 													return true;
	return false;
}

function check_form_admin_add_customer(){
	if(document.form_add_customer.company.value=='') 			alert('Niet ingevuld : Bedrijfsnaam');
	else 													return true;
	return false;
}

function emailCheck (emailStr) {
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("Ths username contains invalid characters.");
			return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
	   }
	}
	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
		   }
		}
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
		if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			return false;
	   }
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
		alert("The address must end in a well-known domain or two letter " + "country.");
		return false;
	}
	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}
	return true;
}
