
function openWindow(url, w, h, win, x, y) {
	var win_name = win ? win : 'popup';
	if (! x) x = 0;
	if (! y) y = 0;
	if (! w) w = 600;
	if (! h) h = 600;
	var new_win = window.open(url, win_name, 'left='+x+',top='+y+'width='+w+',height='+h+',menubar=no,toolbar=no,location=no,scrollbars=yes,resizable=yes,status=yes');
	new_win.moveTo(x, y);
	new_win.resizeTo(w, h);
	new_win.focus();
}

function submitform()
{
  document.login.submit();
}

function regform(lang)
{
  document.register_form.submit();
}

function CheckEmailAddress(a){
	var re = /^[A-Za-z0-9_\-\.]+@[A-Za-z0-9\-\.]+\.[A-Za-z]+$/
	if (re.exec(a)) return true
	else return false
}

function Trim(s) {
	var tmp = new String(s);
	while (tmp.substr(0, 1) == ' ') tmp = tmp.substr(1);
	while (tmp.substr(tmp.length-1) == ' ') tmp = tmp.substr(0, tmp.length-1);
	return tmp;
}

function check_admin_form() {
	document.prop_frm.rn.value == Trim(document.prop_frm.rn.value);
	if (document.prop_frm.rn.value == '') {
		document.prop_frm.rn.focus();
		alert("Please enter Ref. Number");
		return false;
	}
	document.prop_frm.title.value == Trim(document.prop_frm.title.value);
	if (document.prop_frm.title.value == '') {
		document.prop_frm.title.focus();
		alert("Please enter title");
		return false;
	}
	if (document.prop_frm.type.selectedIndex < 1) {
		document.prop_frm.type.focus();
		alert("Please select type");
		return false;
	}
	if (document.prop_frm.location.selectedIndex < 1) {
		document.prop_frm.location.focus();
		alert("Please select location");
		return false;
	}
	if (document.prop_frm.region.selectedIndex < 1) {
		document.prop_frm.region.focus();
		alert("Please select region");
		return false;
	}
	document.prop_frm.livingarea.value == Trim(document.prop_frm.livingarea.value);
	if (document.prop_frm.livingarea.value == '') {
		document.prop_frm.livingarea.focus();
		alert("Please enter living area");
		return false;
	}
	if (document.prop_frm.landarea.selectedIndex < 1) {
		document.prop_frm.landarea.focus();
		alert("Please select land area");
		return false;
	}
	document.prop_frm.price.value == Trim(document.prop_frm.price.value);
	if (document.prop_frm.price.value == '') {
		document.prop_frm.price.focus();
		alert("Please enter price");
		return false;
	}
	if (isNaN(parseInt(document.prop_frm.price.value))) {
		document.prop_frm.price.focus();
		alert("Please enter a numeric value for the price");
		return false;
	}
	if (document.prop_frm.topoffer.selectedIndex < 1) {
		document.prop_frm.topoffer.focus();
		alert("Please select top offer");
		return false;
	}
	document.prop_frm.text.value == Trim(document.prop_frm.text.value);
	if (document.prop_frm.text.value == '') {
		document.prop_frm.text.focus();
		alert("Please enter description");
		return false;
	}
	return true;
}

function del_img(id, file) {
	if (confirm("Confirm deletion!")) {
		location.href='del_img.php?id='+id+'&file='+file;
	}
}

function check_sure() {
// by deletion of multiple entries from the list
	if (confirm("Confirm deletion!")) {
		document.list.submit();
	}
}

function checkPass() {
	if (document.getElementById('pass').value == '') {
		alert('Please enter new password!');
		document.getElementById('pass').focus();
		return false;
	}
	if (document.getElementById('repass').value == '') {
		alert('Please re-enter the password!');
		document.getElementById('repass').focus();
		return false;
	}
	if (document.getElementById('pass').value != document.getElementById('repass').value) {
		alert('The passwords do not match!');
		document.getElementById('pass').value = '';
		document.getElementById('repass').value = '';
		return false;
	}
	return true;
}

function check_register() {
	if (document.register_form.firstname.value == '') {
		document.register_form.firstname.focus();
		alert("Please enter the firstname");
		return false;	
	}

	if (document.register_form.lastname.value == '') {
		document.register_form.lastname.focus();
		alert("Please enter the lastname");
		return false;	
	}

	if (document.register_form.email.value == '') {
		document.register_form.email.focus();
		alert("Please enter the email adress");
		return false;	
	}
	
	return true;
	
}


function check_form() {
	
	document.p_autumn.ident.value == Trim(document.p_autumn.ident.value);
	if (document.p_autumn.ident.value == '') {
		document.p_autumn.ident.focus();
		alert("Please enter the ident number");
		return false;	
	} 
	if (document.p_autumn.title.value == '') {
		document.p_autumn.title.focus();
		alert("Please enter the title");
		return false;	
	}
	if (document.p_autumn.price.value == '') {
		document.p_autumn.price.focus();
		alert("Please enter the price");
		return false;	
	}
	if (isNaN(parseInt(document.p_autumn.price.value))) {
		document.p_autumn.price.focus();
		alert("Please enter a numeric value for the price");
		return false;
	}
	
	if (document.p_autumn.metal.value == '') {
		document.p_autumn.metal.focus();
		alert("Please enter the metal");
		return false;	
	}
	if (document.p_autumn.description.value == '') {
		document.p_autumn.description.focus();
		alert("Please enter the description text");
		return false;	
	}
	
	return true;
	
}

function search_form() {
	document.searchform.rn.value = Trim(document.searchform.rn.value);
	document.searchform.ab_price.value = Trim(document.searchform.ab_price.value);
	document.searchform.up_price.value = Trim(document.searchform.up_price.value);

	if (document.searchform.ab_price.value != '') {
		if (isNaN(parseInt(document.searchform.ab_price.value))) {
			document.searchform.ab_price.focus();
			alert("Please enter a numeric value for the price");
			return false;
		}
	}

	if (document.searchform.up_price.value != '') {
		if (isNaN(parseInt(document.searchform.up_price.value))) {
			document.searchform.up_price.focus();
			alert("Please enter a numeric value for the price");
			return false;
		}
	}
	return true;
}


