var type = "IE";

function BrowserSniffer() {
	if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";		//Opera
	else if (document.all) type="IE";														//Internet Explorer e.g. IE4 upwards
	else if (document.layers) type="NN";													//Netscape Communicator 4
	else if (!document.all && document.getElementById) type="MO";							//Mozila e.g. Netscape 6 upwards
	else type = "IE";
}

BrowserSniffer();

function GetValue(id){
	if (type=="IE") return document.all[id].value;
	if (type=="NN") return document.layer['id'].value;
	if (type=="MO" || type=="OP") return document.getElementById(id).value;
}

function SetValue(id,sVal){
	if (type=="IE") document.all[id].value = sVal;
	if (type=="NN") document.layer['id'].value = sVal;
	if (type=="MO" || type=="OP") document.getElementById(id).value = sVal;
}

function hidesb(){
	window.status=''
	return true
}

function IsValidEmail(emailStr){
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(emailStr);
}

function validateLogin() {
	var userid = GetValue("userid");
	var userpass = GetValue("userpass");
	if (userid == "" || userpass == "") {
		alert("Please enter your Username and Password");
	}else{
		document.loginform.submit();
	}
}

function JoinLeaveMailing() {
	var email = GetValue("nieuwsemail");
	var retto = location.href;
	var selstr = "e="+email+"&r="+retto;
	if (email == "" || !IsValidEmail(email)) {
		alert("Please enter a valid email address");
	}else{
		location.href = "joinmailinglist.asp?"+selstr;
	}
}

function redir(url) {
	if (url != "") {
		location.href = url;
	}
}

function uploadPhoto(uid) {
	NewWindow("uploadbaby.asp?id="+uid,370,135,"no","center");
}
var win=null;
function NewWindow(targetpage,w,h,scroll,pos){
	LeftPosition = (screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(targetpage,"",settings);
}

function validateRegistration() {
	var bay = GetValue("bay");
	var bam = GetValue("bam");
	var bname = GetValue("bname");
	var email = GetValue("emailaddress");
	var babyage;
	var failedon = "";
	if (email == "") {
		failedon = "Please enter your Email address";
	}else if (GetValue("password") == "") {
		failedon = "Please enter a Password";
	}else if (GetValue("initials") == "") {
		failedon = "Please enter your Initials";
	}else if (GetValue("surname") == "") {
		failedon = "Please enter your Surname";
	}else if (GetValue("address1") == "" && GetValue("address2") == "") {
		failedon = "Please enter your Address";
	}else if (GetValue("city") == "") {
		failedon = "Please enter your City";
	}else if (GetValue("postcode") == "") {
		failedon = "Please enter your Post code";
	}else if (GetValue("country") == "") {
		failedon = "Please enter your Country";
	}else if (GetValue("telephone") == "") {
		failedon = "Please enter your Telephone number";
	}else if (bname == "") {
		failedon = "Please enter your Baby's name";
	}else if (bay == "" && bam == "") {
		failedon = "Please enter the Baby's age in Years and Months";
	}else if (bay != "" && !isInteger(bay)) {
		failedon = "Please enter the Baby's age in Years using a number";
	}else if (bam != "" && !isInteger(bam)) {
		failedon = "Please enter the Baby's age in Months using a number";
	}else if (!IsValidEmail(email)) {
		failedon = "Please enter a valid Email address";
	}else if (GetValue("password") != GetValue("passwordc")) {
		failedon = "The confirmation password does not match the password you entered";
	}
	if (failedon != "") {
		alert(failedon);
	} else {
		document.frmReg.submit();
	}
}

function validateAgreement() {
	var agreed = document.forms[0].chkAgree.checked;
	if (agreed != 1) {
		alert("In order to make use of the services on this site\nyou must Agree to the Terms & Conditions");
	} else {
		location.href = "register.asp";
	}
}

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 HideandUNhideObj(ThisObj){
	nav = document.getElementById(ThisObj).style
	if(nav.display=="none"){
		nav.display='block';
	}else{
		nav.display='none';
	}
}


if (document.layers) 
	document.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT)
	document.onmouseover=hidesb
	document.onmouseout=hidesb


