// Preload Images
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
$(document).ready(function(){

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

// When the form is submitted
$("#status > form").submit(function(){  
									

// Hide 'Submit' Button
$('#submit').hide();

// Show Gif Spinning Rotator
$('#ajax_loading').show();

// 'this' refers to the current submitted form  
var str = $(this).serialize();  

// -- Start AJAX Call --

$.ajax({  
    type: "POST",
    url: '/',  // Send the login info to this page
    data: str,  
    success: function(msg){  
   
$("#status").ajaxComplete(function(event, request, settings){  
 
 // Show 'Submit' Button
$('#submit').show();

// Hide Gif Spinning Rotator
$('#ajax_loading').hide();  

 if(msg == 'OK') // LOGIN OK?
 {  
 var login_response = '<div id="logged_in">' +
	 '<div style="width: 350px; float: left; margin-left: 70px;">' + 
	 '<div style="width: 40px; 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: 300px;">'+ 
	 "Вход выполнен!</div></div>";  

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

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

// After 3 seconds redirect the 
setTimeout('go_to_private_page();',2000); 
 }  
 else // ERROR?
 {  
 var login_response = msg;
 $('#login_response').html(login_response);
 }  
      
 });  
   
 }  
   
  });  
  
// -- End AJAX Call --

return false;

}); // end submit event login Form

});

function go_to_private_page()
{
window.location =document.URL; // Members Area
}

function f_submit(form)
{
	form.country_send.value=form.country_l.value;
	var str = $("form").serialize();  
// Hide 'Submit' Button
$('#inpt_region').hide();

// Show Gif Spinning Rotator
$('#ajax_loading2').show();
// -- Start AJAX Call --

$.ajax({  
    type: "POST",
    url: '/',  // Send the login info to this page
    data: str,  
    success: function(msg){  
   
$("#status2").ajaxComplete(function(event, request, settings){  
 $('#inpt_region').show();

// Show Gif Spinning Rotator
$('#ajax_loading2').hide();

 if(msg) // LOGIN OK?
 {  
 var form_response = '<label class="lab_login">Город</label><select class="inpt_login"  name="city_l"  id="siti_l"  style="width:140px; ">'+msg+'</select>';  
$("#form_response").show();

 
 $("#form_response").html(form_response); // Refers to 'status'

// After 3 seconds redirect the 
//setTimeout('go_to_private_page();',2000); 
 }  
 else // ERROR?
 {  
$("#form_response").hide();
 }  

 });  
    }  
   
  });  
  
// -- End AJAX Call --
form.country_send.value='';
return false;
}

$("#inpt_region").click(function(){
$("#actin").val('');					
								 document.ch_cont.submit();
});
//_________________
function chek_submit()
{

	var str = $("form").serialize();  

var j=0;
var i=0;
$('#ready').hide();

// Show Gif Spinning Rotator
$('#ajax_load').show();

$.ajax({  
    type: "POST",
    url: '/modules/shop/recalculate.php',  // Send the login info to this page
    cache: false,
    data: str,  
    success: function(msg){  

//alert(msg);

update = msg.split('|');
 if(update[1]) // LOGIN OK?
 {  
 
 $("#country").val(update[1])
 $("#price").html(update[2]); 
 $("#price_dok").html(update[3]); 
  $("#pricetotal").html(update[4]); 
  $("#city").val(update[5]); 
   var list_station = '<select id="state_sel" name="state_sel" onchange="javascript: checkform(form);"  >'+update[0]+'</select>'; 
   $("#siti_l_sam").hide();
 $("#sitil").show();
 $("#sitil").html(list_station); // Refers to 'status'

// After 3 seconds redirect the 
//setTimeout('go_to_private_page();',2000); 
 }  
 else if(!update[1]) // ERROR?
 {  
  $("#country").val('')
 $("#price").html(update[2]); 
 $("#price_dok").html(update[3]); 
  $("#pricetotal").html(update[4]); 

 
 
 	 $("#city").val('');
$("#country_b").hide();
$("#sitil").hide();
$("#country_sam").show();
$("#siti_l_sam").show();
 }  
 $('#ready').show();

// Show Gif Spinning Rotator
$('#ajax_load').hide();
}
  });  
// -- End AJAX Call --


return false;
}

$("#inpt_region").click(function(){
$("#actin").val('');					
								 document.ch_cont.submit();
});