
// pre-submit callback 
function validate(formData, jqForm, options) { 
	for (var i=0; i < formData.length; i++) { 
        if (! formData[i].value && formData[i].name == 'Login_Name') { 
			$('#error_Login_Name').show("slow");
			$("#" + formData[i].name).addClass("highlight"); 
			$("#" + formData[i].name).focus();
			return false; 
        } 
        else if (! formData[i].value && formData[i].name == 'Password') { 
			$('#error_Password').show("slow");
			$("#" + formData[i].name).addClass("highlight"); 
			$("#" + formData[i].name).focus();
			return false; 
        } 
    } 
 
    return true; 
} 
// post-submit callback 
function showResponse(responseText, statusText)  { 

	if(responseText == ''){ 
		window.location = "/bxaf5/r_index.php";
	}
	else if(responseText == 'guest'){
												  
		$('#div_results').html("<h2>Welcome to bioinfoman.com!</h2> <p>Notice that, <strong>guest account has limitations</strong>. Please check <a href='Javascript: void(0);' onClick=\"$('.bioinfoman_compare_trigger').click();\" style='color: #03F'><strong><u>Comparison of Accounts</u></strong></a>.</p> <p><strong>Why <a href='register.php' style='color: #03F'>sign up</a>?</strong> With your own accounts you can do a lot more: </p> <ul> <li><strong>Full data privacy and daily data backup.</strong></li> <li><strong>Use your own data without being interrupted.</strong></li> <li><strong>Ready to convert to paid account for daily researches and data sharing.</strong></li> </ul>  <p><strong>Why <a href='index_pay.php' style='color: #03F'>pay subscription</a>?</strong> As a paid customer, you can do even more: </p> <ul> <li><strong>Full support with daily data backup.</strong></li> <li><strong>No account expiration.</strong></li> <li><strong>Share data among team members.</strong></li>  <li><strong>Affordable: starting at $9/month.</strong></li> </ul> <a style='color: #03F; font-weight:bold; ' href='register.php'><img src='/bxaf5/images/arrow_red.gif' border=0 align='absmiddle' /> Sign Up Now</a>  - <a style='color: #03F; font-weight:bold;' href='index_pay.php'><img src='/bxaf5/images/arrow_red.gif' border=0 align='absmiddle' /> Pay Subscription Now</a>    <br /><em>Pressing the <strong>Continue</strong> button will lead to the intranet website with links to all applications. Enjoy.</em>");
		$('#div_results').dialog('open');
		$('#div_results').dialog({ 
			title: '<b><font color=white>BioInfoMan - Guest Account</font></b>', 
			resizable: true,
			bgiframe: true, 
			width: 850, 
			height: 'auto', 
			position:'center', 
			buttons: {'Continue': function() { $('#div_results').dialog('close'); window.location = "/bxaf5/r_index.php"; } }, 
			modal: true 
		}); 
	
		
	}
	else if(responseText == 'trial'){
												  
		$('#div_results').html("<h2>Welcome to bioinfoman.com!</h2> <p>With  <strong>trial account </strong>, you can access all applications. However, there are some <strong>limitations</strong>. For example, you cannot share any data among your group members. Please check <a tabindex='-1' href='Javascript: void(0);' onClick=\"$('.bioinfoman_compare_trigger').click();\" style='color: #03F'><strong><u>Comparison of Accounts</u></strong></a>.</p> <p><strong>Why <a tabindex='-1' href='index_pay.php' style='color: #03F'>pay subscription</a>?</strong> As a paid customer, you can enjoy the full power: </p> <ul> <li><strong>Full support with daily data backup.</strong></li> <li><strong>No account expiration.</strong></li> <li><strong>Share data among team members.</strong></li>  <li><strong>Affordable: starting at $9/month.</strong></li> </ul>  <a tabindex='-1' style='color: #03F; font-weight:bold;' href='index_pay.php'><img src='/bxaf5/images/arrow_red.gif' border=0 align='absmiddle' /> Pay Subscription Now</a>    <p><em>Pressing the <strong>Continue</strong> will lead to the intranet website with links to all applications. Enjoy.</em></p>");
		$('#div_results').dialog('open');
		$('#div_results').dialog({ 
			title: '<b><font color=white>BioInfoMan - Trial Account</font></b>', 
			resizable: true,
			bgiframe: true, 
			width: 750, 
			height: 'auto', 
			position:'center', 
			buttons: {'Continue': function() { window.location = "/bxaf5/r_index.php"; } }, 
			close: function(ev, ui) { window.location = "/bxaf5/r_index.php"; },
			modal: true 
		}); 
	
		
	}
	else {
		$('#Login_Name').val('');
		$('#Password').val('');
		
		$("#Login_Name").addClass("highlight"); 
		$("#Password").addClass("highlight"); 

		$('#error_Login_Name').hide();
		$('#error_Password').hide();
												  
		$('#div_results1').html('<h2>Login Failed!</h2>Click the "Try Again" button to close this popup window and try to login the system again.');
		$('#div_results1').dialog('open');
		$('#div_results1').dialog({ 
			title: '<b><font color=white>BioInfoMan - Login Message</font></b>', 
			resizable: true,
			bgiframe: true, 
			width: 650, 
			height: 'auto', 
			position:'center', 
			buttons: {'Try Again': function() { $('#div_results1').dialog('close'); $('#Login_Name').focus(); } }, 
			modal: true 
		}); 
	
		
	}
} 








$(document).ready(function(){
/*	
	//Test browser
	var userAgent = navigator.userAgent.toLowerCase();
	$.browser = {
		version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
		safari: /webkit/.test( userAgent ),
		opera: /opera/.test( userAgent ),
		msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
		mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
	};
//	if($.browser.msie){ }
*/	
	$('#Login_Name').focus(); 
	$('#account_types').corner();
	
	var options = { 
		url: "/index_files/index_exe.php?action=login",
 		type: 'post',
        beforeSubmit: validate,
		success: showResponse
    }; 
	$('#form_login').ajaxForm(options); 

		
	$('.login_as_guest').click(function(){
		$.ajax({
			type: "post",
			url: "/index_files/index_exe.php?action=login&account=guest",
        	success: showResponse
		});
	}); 


	$('.bioinfoman_limited_offer_trigger').click(function (){
		$.ajax({
			type: "get",
			url: "/index_files/index_offer.php?action=get",
			success: function(responseText, statusText) { 
//alert(responseText);

				$('#bioinfoman_limited_offer').html(responseText);
														  
				$('#bioinfoman_limited_offer').dialog('open');
				$('#bioinfoman_limited_offer').dialog({ 
					title: '<b><font color=white>BioInfoMan - Limited Time Offer</font></b>', 
					resizable: true,
					bgiframe: false, 
					width: 750, 
					height: 'auto', 
					position:'center', 
					buttons: {'Close': function() { $('#bioinfoman_limited_offer').dialog('close'); $('#Login_Name').focus(); } }, 
					modal: false 
				}); 
			
				

			
			}
		});
	}); 


	$('.bioinfoman_refer_a_friend_trigger').click(function (){
		$.ajax({
			type: "get",
			url: "/index_files/index_refer.php?action=get",
			success: function(responseText, statusText) { 
//alert(responseText);

				$('#bioinfoman_refer_a_friend').html(responseText);
														  
				$('#bioinfoman_refer_a_friend').dialog('open');
				$('#bioinfoman_refer_a_friend').dialog({ 
					title: '<b><font color=white>BioInfoMan - Refer A Friend</font></b>', 
					resizable: true,
					bgiframe: true, 
					width: 750, 
					height: 'auto', 
					position:'center', 
					buttons: {'Close': function() { $('#bioinfoman_refer_a_friend').dialog('close'); $('#Login_Name').focus(); } }, 
					modal: true 
				}); 
			
				

			
			}
		});
	}); 


	$('.bioinfoman_compare_trigger').click(function (){
		$.ajax({
			type: "get",
			url: "/index_files/index_compare.php?action=get",
			success: function(responseText, statusText) { 

				$('#bioinfoman_compare').html(responseText);
														  
				$('#bioinfoman_compare').dialog('open');
				$('#bioinfoman_compare').dialog({ 
					title: '<b><font color=white>BioInfoMan - Compare Accounts</font></b>', 
					resizable: true,
					bgiframe: true, 
					width: 850, 
					height: 'auto', 
					position:'center', 
					buttons: {'Close': function() { $('#bioinfoman_compare').dialog('close'); $('#Login_Name').focus(); } }, 
					modal: true 
				}); 
			
			}
		});
	}); 

	$('.index_product_trigger').mouseover(function(){ this.style.cursor="pointer"; }); 
	$('.index_product_trigger').click(function(){
		var tr = $(this).attr('id').substring(11);  //e.g. trigger_tr_mlims
		if($("#trigger_image_" + tr).attr('src') == 'index_files/expand.gif') $("#trigger_image_" + tr).attr('src', 'index_files/collapse.gif'); 
		else $("#trigger_image_" + tr).attr('src', 'index_files/expand.gif'); 
		$("#div_details_" + tr).toggle();
	}); 

	
});
