// Preload Images
img1 = new Image(16, 16);  
img1.src="/images/spinner.gif";

img2 = new Image(220, 19);  
img2.src="/images/ajax-loader.gif";
var $j = jQuery.noConflict();
// When DOM is ready
$j(document).ready(function(){

// Launch MODAL BOX if the Login Link is clicked
$j('.login_link').click(function(){
	$j('#login_form').modal();

});


$j('.login_link2').click(function(){
    $j.modal.impl.close();
	$j('#login_form').modal();

});


// Launch MODAL BOX if Split is clicked
$j('.split_link').click(function(){
       var patternID = $j(this).attr('id');
	var itermID = patternID.split(' ');
	split_qty = itermID[2];
	$j('#yds-to-split').html(split_qty);
	$j('#split_titleh1').val('Split Item '+itermID[0]);
	$j('#patternIDSKU').val(itermID[0]);
	$j('#order_type').val(itermID[1]);
	$j('#lots_select').change();
	$j('#split_form').modal({containerId:'split_container'});
});


// Launch MODAL BOX if the Login Link is clicked
$j('.register_link').click(function(){
	$j('#register_form').modal({containerId:'register_container'});
});


// Launch MODAL BOX if the Add to Cart is clicked
$j('.add_sku_link').click(function(){
	$j('#add_sku_form').modal({containerId:'add_sku_container'});
});

$j("#login").keypress(function(e){
    if (e.which == 13) {
 

$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: "/do-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" style="border:0px solid red;">' +
	 '<div style="margin-top:30px;">' +
	 '<div style="width: 40px; margin-left: 170px; ">' +
	 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="/images/ajax-loader.gif">' +
	 '</div>' +
	 '<div style="margin: 20px 0px 0px 5px; text-align:left;">'+
	 "You are successfully logged in! <br /> Please wait while you're redirected...</div></div>";  

$j('a.modalCloseImg').hide();

$j('#simplemodal-container').css("width","450px");
$j('#simplemodal-container').css("height","385px");
 
 $j(this).html(login_response); // Refers to 'status'

// After 3 seconds redirect the 
setTimeout('go_to_private_page()', 3000);
 } 
 else if  (msg == 'FORCE'){

      var login_response = '<div id="logged_in">' +
	 '<div style="margin-top:30px;">' +
	 '<div style="margin: 20px 0px 0px 5px;  text-align:left;">'+
         '<div style="width: 40px; margin-left: 170px; ">' +
	 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="/images/ajax-loader.gif">' +
	 '</div>' +
	 '<h1>ATTENTION!</h1><br /><br /><span style="font-size: 15px;font-weight:bold;">You are required to open a new account with this new site!</span><br /><br /> Please wait while you are redirected...</div></div>';

      $j('a.modalCloseImg').hide();
      $j('#simplemodal-container').css("width","450px");
      $j('#simplemodal-container').css("height","385px");

      $j(this).html(login_response); // Refers to 'status'
      setTimeout('go_to_private_page2()', 7000);
 }
 else // ERROR?
 {  
 var login_response = msg;
 $j('#login_response').html(login_response);
 }  
      
 });  
   
 }  
   
  });  
  
// -- End AJAX Call --

return false;





 }
});


// When the 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: "/do-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" style="border:0px solid red;">' +
	 '<div style="margin-top:30px;">' +
	 '<div style="width: 40px; margin-left: 170px; ">' +
	 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="/images/ajax-loader.gif">' +
	 '</div>' +
	 '<div style="margin: 20px 0px 0px 5px; text-align:left;">'+
	 "You are successfully logged in! <br /> Please wait while you're redirected...</div></div>";  

$j('a.modalCloseImg').hide();

$j('#simplemodal-container').css("width","450px");
$j('#simplemodal-container').css("height","385px");
 
 $j(this).html(login_response); // Refers to 'status'

// After 3 seconds redirect the 
setTimeout('go_to_private_page()', 3000);
 } 
 else if  (msg == 'FORCE'){

      var login_response = '<div id="logged_in">' +
	 '<div style="margin-top:30px;">' +
	 '<div style="margin: 20px 0px 0px 5px;  text-align:left;">'+
         '<div style="width: 40px; margin-left: 170px; ">' +
	 '<img style="margin: 10px 0px 10px 0px;" align="absmiddle" src="/images/ajax-loader.gif">' +
	 '</div>' +
	 '<h1>ATTENTION!</h1><br /><br /><span style="font-size: 15px;font-weight:bold;">You are required to open a new account with this new site!</span><br /><br /> Please wait while you are redirected...</div></div>';

      $j('a.modalCloseImg').hide();
      $j('#simplemodal-container').css("width","450px");
      $j('#simplemodal-container').css("height","385px");

      $j(this).html(login_response); // Refers to 'status'
      setTimeout('go_to_private_page2()', 7000);
 }
 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 = '/private.php'; // Members Area
}


function go_to_private_page2()
{
window.location = '/private2.php'; // Members Area
}

