// Preload Images
  var $j = jQuery.noConflict();
img1 = new Image(16, 16);  
img1.src="images/spinner.gif";

img2 = new Image(220, 19);  
img2.src="images/ajax-loader.gif";

// When DOM is ready
$j(document).ready(function(){
// Launch MODAL BOX if the Login Link is clicked
$j("#login_link").click(function(){
$j('#ajax_loading').hide();
$j('#login_form').modal();
$j('#simplemodal-container').css("width","320px");
$j('#simplemodal-container').css("height","205px");
$j('#simplemodal-container').css("margin-left","170px");
$j('#simplemodal-container').css("margin-top","50px");
});

//when element with class login_check clicked
$j(".login_check").click(function(){
$j('#ajax_loading').hide();
$j('#login_form').modal();
$j('#simplemodal-container').css("width","320px");
$j('#simplemodal-container').css("height","205px");
$j('#simplemodal-container').css("margin-left","170px");
$j('#simplemodal-container').css("margin-top","50px");
});

//when element with class legend clicked
$j(".legend").click(function(){
$j('#legend').modal();
$j('#simplemodal-container').css("width","650px");
$j('#simplemodal-container').css("height","400px");
$j('#simplemodal-container').css("margin-left","-10px");
$j('#simplemodal-container').css("margin-top","-80px");
$j('#simplemodal-container').css("margin-bottom","10px");

});


// Launch MODAL BOX if the Feedback Link is clicked
$j("#feedback_link").click(function(){
$j('#ajax_loading').hide();
$j('#feedback_form').modal();
});


//feedback code begins

// When the feedback form is submitted
$j("#feedback_status > form").submit(function(){

// Hide 'Submit' Button
$j('#feedback').hide();

// Show Gif Spinning Rotator
$j('#ajax_loading').show();

// 'this' refers to the current submitted form
var str = $j(this).serialize();

// -- Start AJAX Call --

$j.ajax({
    type: "POST",
    url: "process_feedback.php",  // Send the feedback info to this page
    data: str,
    success: function(msg){

$j("#feedback_status").ajaxComplete(function(event, request, settings){

 // Show 'Submit' Button
$j('#feedback').show();

// Hide Gif Spinning Rotator
$j('#ajax_loading').hide();

 if(msg == 'OK') // Feedback Mail Sent?
 {
 var feedback_response = '<div id="feedback_sent">' +
	 '<div style=" text-align:left; float: left; margin: 20px;margin-top:40px;">' +
	 "<font color=#000000><center>Thank you for submitting your feedback.</center><br>While we value your comments and suggestions, please note that we will not be able to respond directly to suggestions.</font></div></div>";

//$j('a.modalCloseImg').hide();

$j(this).html(feedback_response); // Refers to 'status'

// After 3 seconds redirect the
//setTimeout('go_to_private_page()', 3000);
 }
 else // ERROR?
 {
 var feedback_response = msg;
 $j('#feedback_response').html(feedback_response);
 }

 });

 }

  });

// -- End AJAX Call --

return false;

}); // end submit event

//feedback code ends



// When the login form is submitted
$j("#status > form").submit(function(){

// Hide 'Submit' Button
$j('#submit').hide();

// Show Gif Spinning Rotator
$j('#ajax_loading').show();

// 'this' refers to the current submitted form  
var str = $j(this).serialize();

// -- Start AJAX Call --

$j.ajax({
    type: "POST",
    url: "process_login.php",  // Send the login info to this page
    data: str,  
    success: function(msg){  
   
$j("#status").ajaxComplete(function(event, request, settings){
 
 // Show 'Submit' Button
$j('#submit').show();

// Hide Gif Spinning Rotator
$j('#ajax_loading').hide();

 if(msg == 'OK') // LOGIN OK?
 {  
 var login_response = '<div id="logged_in">' +
	 '<div style="width: 290px; float: left; margin-left: 0px;">' + 
	 '<div style="width: 290px; float: left;">' +
	 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="images/ajax-loader.gif">' +
	 '</div>' +
	 '<div style="margin: 10px 0px 0px 10px; float: right; width: 290px;">'+ 
	 "You are successfully logged in! <br /> Please wait while you're redirected...</div></div>";  

$j('a.modalCloseImg').hide();

$j('#simplemodal-container').css("width","300px");
$j('#simplemodal-container').css("height","180px");
$j('#simplemodal-container').css("margin-left","170px");
$j('#simplemodal-container').css("margin-top","50px");
 
 $j(this).html(login_response); // Refers to 'status'

// After 3 seconds redirect the 
setTimeout('go_to_private_page()', 3000); 
 }  
 else // ERROR?
 {  
 var login_response = msg;
 $j('#login_response').html(login_response);
 }  
      
 });  
   
 }  
   
  });  
  
// -- End AJAX Call --

return false;

}); // end submit event

});

function go_to_private_page()
{
window.location = 'index.php?select_context=' + $j('#select_context').val() + '&symbol=' + $j('#symbol').val() + '&category=' + $j('#category').val() + '&subcategory=' + $j('#subcategory').val();  // Members Area
}
