// function to put the focus on the first field
function putFocus(formInst, elementInst) {
	if (document.forms.length > 0) {
		document.forms[formInst].elements[elementInst].focus();
	}
}

function toon() {
	for (var i = 0; i < document.forms.length; i++) {
		alert('form: ' + document.forms[i].name);
		alert('aantal: ' + document.forms[i].elements.length);
		for (var j = 0; j < document.forms[i].elements.length; j++) {
			if (document.forms[i].elements[j].name == 'advt_rub') {
				alert('element: ' + document.forms[i].elements[j].name);
				alert('val: ' + document.forms[i].elements[j].options[0].value);
				document.forms[i].elements[j].options[0].focus();
			}
		}
	}
}

function hopeloos() {
	var i;
	URL=window.location.href ;
}

//function breakOut() {
	//if (window != top) top.location.href = location.href;
	//if (parent.frames.length > 0) { parent.location.href = location.href; }
	//parent.location.href = top.frames['a6-14633'].location.href ('message.jsp');
	//alert(parent.peer.document.location)
	//top.frames['a6-14633'].location.href ('message.jsp');
//	if (parent.location != self.location && parent.location !=top.location) { top.frames['a6-14633'].location.href ('message.jsp'); }
//}


function DisablingBackFunctionality() {
	var URL;
	var i ;
	var QryStrValue;
	URL=window.location.href ;
	i=URL.indexOf("?");
	QryStrValue=URL.substring(i+1);
	if (QryStrValue!='X') {
		window.location=URL + "?X";
	}
}

function openWindowInParentFrame(url) {
	popupWin = parent.location.replace(url);
}

function textCounter(field, countfield, maxlimit, errormessage) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
		countfield.value = 0;
		alert(errormessage);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}

// ajax met jquery script: ophalen woonplaats op basis van een Nederlandse postcode
function getDutchCityName(zipCode, city, streetName, errorMessage) {
	//alert(zipCode);
	//alert("waardennnnn: " + $("input#" + zipCode).val());
	if ($("input#" + zipCode).val() == '') {
		$("input#" + zipCode).next().text('Postcode is verplicht');
		$("input#" + city).val('');
		$("input#" + streetName).val('');
	} else {
		$.get("remote.jsp?rpc=getDutchCityName&zipCode=" + $("input#" + zipCode).val(),
			function(data){
				//alert("Data Loaded: " + data);
				if (data=='') {
					//alert('geen data');
					$("input#" + zipCode).next().text(errorMessage);	
				} else {
					$("input#" + zipCode).next().text('');
				}	
				$("input#" + city).val(data);
			}
		);
	}
}

//ajax met jquery script: ophalen straatnaam op basis van een Nederlandse postcode en huisnummer
function getDutchStreetName(houseNumber, zipCode, streetName, errorMessage) {
	if ($("input#" + houseNumber).val() == '') {
		$("input#" + houseNumber).next().text('Huisnummer is verplicht');	
		$("input#" + streetName).val('');
	} else {
		$.get("remote.jsp?rpc=getDutchStreetName&zipcode=" + $("input#" + zipCode).val() + "&houseNumber=" + $("input#" + houseNumber).val(),
			function(data){
				//alert("Data Loaded: " + data);
				if (data=='') {
					//alert('geen data');
					$("input#" + houseNumber).next().text(errorMessage);	
				} else {
					$("input#" + houseNumber).next().text('');
				}	
				$("input#" + streetName).val(data);
			}
		);
	}
}

