var nomad = (function () {
//------------

// function max (x, y) {
//     if (x < y) {
//         return y;
//     }
//     return x;
// }

$(function () {
    $('#nav a').add('a.scroll').click(function () {
        var target = $(this.hash);
        var hash = this.hash;
        // $target = $target.length && $target
        // || $('[name=' + this.hash.slice(1) +']');
        if (target.length) {
            var targetOffset = target.offset().top;
            $('html,body').animate({scrollTop: targetOffset}, 600);
            return false;
		}
	});
		
    // IE (6 & 7)
	var nav = $('#nav');
	nav.css({'position': 'absolute'});
	
	/*
	 * SCROLLING NAV
	 */
	var topmost_point = nav.offset().top;
    var left_point = $('#container').offset().left;
	var PADDING_TOP = 0; // MAGIC NUMBER
    var REAL_TOP = topmost_point - PADDING_TOP;
	var the_window = $(window);
	var NAV_IS_FIXED = (nav.css('position') == 'fixed');
	the_window.scroll(function () {
        if (the_window.scrollTop() > REAL_TOP) {
            if ($.browser.msie && $.browser.version == "6.0") {
                nav.css('top', the_window.scrollTop() + PADDING_TOP);
            } else if (!NAV_IS_FIXED) {
        	    nav.css({
                    left: left_point,
        	        top: PADDING_TOP,
        	        position: 'fixed'
        	    });
        	    NAV_IS_FIXED = true;
        	}
        } else {
            if (NAV_IS_FIXED) {
                nav.css({
                    position: 'absolute',
                    top: topmost_point,
                    left: ''
                });
                NAV_IS_FIXED = false;
            }
        }
	});
	
	the_window.resize(function () {
	    left_point = $('#container').offset().left;
	    if (NAV_IS_FIXED) {
    	    nav.css('left', left_point);	        
	    }
	});
});


//---
    
})();

//Validate registration form
function validateRegistration()
{
		var email = document.getElementById("email").value;			
		var password = document.getElementById("password").value;
		var retype_password = document.getElementById("retypePassword").value;
		var name = document.getElementById("name").value;
		var telephone = document.getElementById("telephone").value;
		var country = document.getElementById("countryID");

		//Validation Rules
		var alpha = /^[A-Za-z ]+$/;
		var numeric = /^[0-9]+$/;
		var emailRegex = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

		//Must be filled
		if (email == '' || password == '' || retype_password == '' || name == '' || telephone == ''){
			 alert("Please fill in all details.");
			 return false;
		}
		else if (password != retype_password){
			alert("Your password and retype password doesn't match.");
			return false;
		}
		else if (!name.match(alpha)){
			alert("Please enter alphabet character only for name");
			return false;
		}
		else if (!email.match(emailRegex)){
			alert("Please enter a valid email");
			return false;
		}
		else if (!telephone.match(numeric)){
			alert("Please enter numeric character only for telephone");
			return false;
		}else if (country.selectedIndex == 0){
			alert("Please select your country");
			return false;
        }

		return true;		
}
