function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
$(document).ready(function() {
	
	$("#register_form").validate( {
		rules : {
			fname: {required:true},
			lname: {required:true},
			email: {required:true, email:true},
			hwcode: {required: "#serialyes:unchecked"},
			serial: {required: "#serialyes:checked"},
			model: {required: true}
		},
		messages:{
			fname:"required",
			lname:"required",
			email:"must be valid email",
			hwcode:"this or serial must be filled",
			serial:"this or hardware code must be filled",
			model:"model must be selected"
		}
	});
	
	$("#login_form").validate( {
		rules : {
			username:{required:true},
			password:{required:true},
			model:{required:true}
		},
		messages:{
			username:"required",
			password:"required",
			model:"required"
		}
	});
	

	
	$("#serial").blur(function() {
		$("#hwcode").valid();
	});

	$("#hwcode").blur(function() {
		$("#serial").valid();
	});
	
	$("#register_form").hide();
	$("#login_form").hide();
	

	$("#loginHeader").click(function() {
		$("#login_form").slideDown();
		$("#register_form").slideUp();
	});

	$("#registerHeader").click(function() {
		$("#register_form").slideDown();
		$("#snfield").hide();
		$("#login_form").slideUp();
	});
	
	$("#serialyes").click(function(){
		$("#snfield").toggle();
		$("#hwfield").toggle();
		$("#serial").value = "";
		$("#hwcode").value = "";
	});
	
	$("#login").click(function(){
		if($("#login_form").valid()){
			var dataString = 'username='+ $("input#username").val() + '&password=' + $("input#password").val() + '&model=' + $("#login_form input:radio:checked").val();
			$.ajax({
				type: "POST",
				url: "tloginvalidate.php",
				data: dataString,
				success: function(msg) {
					if(msg=="invalidlogin"){
						$('#responsetab').html("<div id='message'></div>");
							$('#message').html("<h2>Login Failed</h2>")
								.append("Cannot confirm email and/or serial/hardware code")
								.hide().fadeIn(1500, function() {
									$('#message').append("<img id='checkmark' src='images/unchecked.gif' />");
								});
					//add model numsel
					}else if(msg=='a800'){
						$('#responsetab').html("<div id='message'></div>");
						//urlplaceholder
						$('#message').html("<h2>Login Successful</h2>HOW TO INSTALL a800 UPDATE<br>Click the image for the link to the software upgrade <br> <a href='http://www.datagrafix.com/AVT-updates/A800_14b.rar'><img style='width: 415px; height: 532px;' alt='howto' src='images/carnav/av-howto.jpg'/></a>")
							.hide().fadeIn(1500, function() {
								$('#message').append("<img id='checkmark' src='images/checked.gif' />");
							});
					}else if(msg=='p820'){
						$('#responsetab').html("<div id='message'></div>");
						$('#message').html("<h2>Login Successful</h2>HOW TO INSTALL p820 UPDATE<br>Click the image for the link to the software upgrade <br> <a href='http://www.datagrafix.com/AVT-updates/P820_14b.rar'><img style='width: 415px; height: 532px;' alt='howto' src='images/carnav/av-howto.jpg'/></a>")
							.hide().fadeIn(1500, function() {
								$('#message').append("<img id='checkmark' src='images/checked.gif' />");
							});
					}else if(msg=='p900'){
						$('#responsetab').html("<div id='message'></div>");
						$('#message').html("<h2>Login Successful</h2>HOW TO INSTALL p900 UPDATE<br>Click the image for the link to the software upgrade <br> <a href='http://www.datagrafix.com/AVT-updates/P900_14b.rar'><img style='width: 415px; height: 532px;' alt='howto' src='images/carnav/av-howto.jpg'/></a>")
							.hide().fadeIn(1500, function() {
								$('#message').append("<img id='checkmark' src='images/checked.gif' />");
							});
					}
				}
			});
		}
	});
	
	$("#register").click(function(){
		if($("#register_form").valid()){
			var dataString = 'fname='+ $("input#fname").val() + '&mname=' + $("input#mname").val() + '&lname=' + $("input#lname").val() +
							'&company=' + $("input#company").val() + '&address=' + $("input#address").val() + '&city=' + $("input#city").val() +
							'&zip=' + $("input#zip").val() + '&phone=' + $("input#phone").val() + '&fax=' + $("input#fax").val() +
							'&email=' + $("input#email").val() + '&hwcode=' + $("input#hwcode").val() + '&serial=' + $("input#serial").val()+
							'&model=' + $("#register_form input:radio:checked").val();
			$.ajax({
				type: "POST",
				url: "tregistervalidate.php",
				data: dataString,
				success: function(msg) {
					if(msg=="invalidserial"){
						$('#responsetab').html("<div id='message'></div>");
							$('#message').html("<h2>Registration Failed</h2>")
								.append("Invalid Serial/hardware number")
								.hide().fadeIn(1500, function() {
									$('#message').append("<img id='checkmark' src='images/unchecked.gif' />");
								});
					}else if(msg=="registeredserial"){
						$('#responsetab').html("<div id='message'></div>");
							$('#message').html("<h2>Registration Failed</h2>")
								.append("Serial number or Hardware number already registered")
								.hide().fadeIn(1500, function() {
									$('#message').append("<img id='checkmark' src='images/unchecked.gif' />");
								});
					}else if(msg=="mailfaila800"){
						$('#responsetab').html("<div id='message'></div>");
						$('#message').html("<h2>Login Successful</h2>")
							.append("<h3>HOWEVER: mail confirmation not sent.</h3> <a href=\"http://www.datagrafix.com/AVT-updates/A800_14b.rar\">Click here </a>  for the link to the software upgrade<br><center>HOW TO INSTALL<br><img style='width: 415px; height: 532px;' alt='howto' src='images/carnav/av-howto.jpg'/><center>")
							.hide().fadeIn(1500, function() {
								$('#message').append("<img id='checkmark' src='images/unchecked.gif' />");
							});
					}else if(msg=="mailfailp820"){
						$('#responsetab').html("<div id='message'></div>");
						$('#message').html("<h2>Login Successful</h2>")
							.append("<h3>HOWEVER: mail confirmation not sent.</h3> <a href=\"http://www.datagrafix.com/AVT-updates/P820_14b.rar\">Click here </a>  for the link to the software upgrade<br><center>HOW TO INSTALL<br><img style='width: 415px; height: 532px;' alt='howto' src='images/carnav/av-howto.jpg'/><center>")
							.hide().fadeIn(1500, function() {
								$('#message').append("<img id='checkmark' src='images/unchecked.gif' />");
							});
					}else if(msg=="mailsuccessa800"){
						$('#responsetab').html("<div id='message'></div>");
						$('#message').html("<h2>Login Successful</h2>")
							.append("<a href=\"http://www.datagrafix.com/AVT-updates/A800_14b.rar\">Click here </a> for the link to the software upgrade for A800 <br><center>HOW TO INSTALL<br><img style='width: 415px; height: 532px;' alt='howto' src='images/carnav/av-howto.jpg'/><center>")
							.hide().fadeIn(1500, function() {
								$('#message').append("<img id='checkmark' src='images/checked.gif' />");
							});
					}else if(msg=="mailsuccessp820"){
						$('#responsetab').html("<div id='message'></div>");
						$('#message').html("<h2>Login Successful</h2>")
							.append("<a href=\"http://www.datagrafix.com/AVT-updates/P820_14b.rar\">Click here </a> for the link to the software upgrade for P820 <br><center>HOW TO INSTALL<br><img style='width: 415px; height: 532px;' alt='howto' src='images/carnav/av-howto.jpg'/><center>")
							.hide().fadeIn(1500, function() {
								$('#message').append("<img id='checkmark' src='images/checked.gif' />");
							});
					}
					else if(msg=="mailsuccessp900"){
						$('#responsetab').html("<div id='message'></div>");
						$('#message').html("<h2>Login Successful</h2>")
							.append("<a href=\"http://www.datagrafix.com/AVT-updates/P900_14b.rar\">Click here </a> for the link to the software upgrade for P820 <br><center>HOW TO INSTALL<br><img style='width: 415px; height: 532px;' alt='howto' src='images/carnav/av-howto.jpg'/><center>")
							.hide().fadeIn(1500, function() {
								$('#message').append("<img id='checkmark' src='images/checked.gif' />");
							});
					}else if(msg=="mailfailp900"){
						$('#responsetab').html("<div id='message'></div>");
						$('#message').html("<h2>Login Successful</h2>")
							.append("<h3>HOWEVER: mail confirmation not sent.</h3> <a href=\"http://www.datagrafix.com/AVT-updates/P900_14b.rar\">Click here </a>  for the link to the software upgrade<br><center>HOW TO INSTALL<br><img style='width: 415px; height: 532px;' alt='howto' src='images/carnav/av-howto.jpg'/><center>")
							.hide().fadeIn(1500, function() {
								$('#message').append("<img id='checkmark' src='images/unchecked.gif' />");
							});
					}
				}
			});
		}
	});
	
	
	$(".jqnavbar").click(function() {
			$("#content").load($(this).attr("href"), function(){
				$("#content").hide().fadeIn("normal");
			});
			$("#notcontent").hide();
	});
	$(".jqnavbarwlf").click(function() {
			$("#content").load($(this).attr("href"), function(){
				$("#content").hide().fadeIn("normal");
				$("#notcontent").fadeIn("normal");
			});
	});	
	$(".jqnavbarwl").click(function() {
			$("#notcontent").hide().fadeIn("normal");
			$("#content").hide();
	});

});