// JavaScript Document
$(document).ready(function(){
	$("input[@name=buy]").each(function(){
		$(this).mouseover(function(){
			$(this).attr("src","/images/buynow2.gif");
		});
		$(this).mouseout(function(){
			$(this).attr("src","/images/index_buy_now.gif");
		});
		$(this).click(function(){
		$(this).attr("src","/images/ajax-loader.gif");
		$.ajax({
			type: "post", 
			url : "/index.php?controller=Ajax&action=CartAddExam",
			dataType:'json',
			data: 'exam_id='+$(this).attr("value"), 
			error: function(msg){
					//alert("error"+msg);
					$(this).attr("src","/images/index_buy_now.gif");
				},
			success: function(json){
				//alert("succeed"+json);
				switch (json.flag){
					case 1:
						window.location.href="/index.php?Controller=ShopCart";return false;
						break;

					default:
						$(this).attr("src","/images/index_buy_now.gif");
						break;
				}
			}  
		});
		});
	});

//------------------------
	$("a[@name=logout]").click(function(){
	$.ajax({
		type: "post", 
		url : "/index.php?controller=Ajax&action=islogin",
		dataType:'json',
		data: '', 
		error: function(msg){
				//alert("error"+msg);
				$('#loginloadding').hide();
				$('#user_info').hide();
				$('#login').show();
			},
		success: function(json){
			//alert("succeed"+json);
			switch (json.flag){
				case 1:
					$('#loginloadding').hide();
					$('#user_info').hide();
					$('#login').show();
					$('#email').val(json.email);
					break;
				case 2:
					$('#loginloadding').hide();
					$('#login').hide();
					$("#userfirstandlastname").html(json.username);
					$('#user_info').show();
					break;
				default:
					$('#loginloadding').hide();
					$('#user_info').hide();
					$('#login').show();
					break;
			}
		}  
	});
	});




//------------------------
});