var uri = "http://www.ozisale.com/";
// Preload Images
img1 = new Image(16, 16);  
img1.src=uri+"images/spinner.gif";

img2 = new Image(220, 19);  
img2.src=uri+"images/ajax-loader.gif";

img3 = new Image(32, 32);
img3.src = uri+"images/ring32.gif";

// When DOM is ready
$(document).ready(function(){

// Launch MODAL BOX if the Login Link is clicked
$("#login_link").click(function(){
$('#login_form').modal(
	{onOpen: function (dialog) {
		dialog.overlay.fadeIn(200, function () {
			dialog.data.hide();
			dialog.container.fadeIn(400, function () {
				dialog.data.slideDown(200);
			});
		});
	},
	onClose: function (dialog) {
	dialog.data.fadeOut(200, function () {
		dialog.container.hide(200, function () {
			dialog.overlay.fadeOut(200, function () {$.modal.close();});
		});
	});
	}, overlayClose:true
	}
);
});


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

//Hide the previous error messages if any
$('#login_response').hide();

// 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: uri +"Admin/loginResultForModal",  // 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();  
//echo "msg=|" . msg . "|";
 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="http://www.ozisale.com/images/ring32.gif">' +
	 '</div>' +
	 '<div style="margin: 10px 0px 0px 10px; float: right; width: 300px;">'+ 
	 "You are successfully logged in! <br /> Please wait while you're redirected...</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()', 1500); 
 }  
 else // ERROR?
 {  
 $('#login_response').show();
 var login_response = msg;
 $('#login_response').html(login_response);
 }  
      
 });  
   
 }  
   
  });  
  
// -- End AJAX Call --

return false;

}); // end submit event

//});


//$(document).ready(function(){
		$("#ContactUs_link").click(function(){
		//alert("jij");
		$('#ContactUsForm').modal(
			{onOpen: function (dialog) {
				dialog.overlay.fadeIn(200, function () {
					dialog.data.hide();
					dialog.container.fadeIn(400, function () {
						dialog.data.slideDown(200);
					});
				});
			},
			//onShow: function(){$("#FirstLastNames").focus();}, 
			onClose: function (dialog) {
			dialog.data.fadeOut(200, function () {
				dialog.container.hide(200, function () {
					dialog.overlay.fadeOut(200, function () {$.modal.close();});
				});
			});
			}, opacity:50, overlayCss: {backgroundColor:"#69c"}, 	containerCss:{  color:"#369", borderColor:"#004a7f", height:320, padding:15, width:560}, overlayClose:true
			}
		);
		});

$("#ContactUs_status > form").submit(function(){
				//Hide the previous errors if any
				$("#ContactUs_response").hide();
				//Hide submit button
				$("#Cont_submit").attr("disabled", true);
				// 'this' refers to the current submitted form  
				var str = $(this).serialize();
				//disable all fields in the form
				$("#FirstLastNames").attr("disabled", true);
				$("	#EmailFrom").attr("disabled", true);
				$("#Subject").attr("disabled", true);
				$("#Message").attr("disabled", true);
				//show please wait gif file
				$("#contactus_ajax_loading").html("<img align=\"absmiddle\" src=\"images/ajax-loader.gif\">&nbsp; . . . S e n d i n g . . .");
				$("#contactus_ajax_loading").show();

									// -- Start AJAX Call --
									$.ajax({  
										type: "POST",
										url: uri+"ozi_main/SendEmailThroughContactUs",
										data: str,  
										success: function(msg){  
									$("#ContactUs_status").ajaxComplete(function(event, request, settings){  
									 // Show 'Submit' Button
												if (msg.indexOf('Error')>0) //which is a system error
												{
													$("#contactus_ajax_loading").html('Error Encountered for unknown reason');
													$("#Cont_submit").attr("disabled", false);
													$("#Cont_submit").attr("value", "re-send");
												}
												else{
													$("#contactus_ajax_loading").html(msg);
													$("#Cont_submit").attr("value", "Thank You");
												}
											});  
										}  
									  });  
									  
									// -- End AJAX Call --
				return false;
});

		$("#ForgotPass_link").click(function(){
		//alert("jij");
		$('#ForgotPassFormDiv').modal(
			{onOpen: function (dialog) {
				dialog.overlay.fadeIn(200, function () {
					dialog.data.hide();
					dialog.container.fadeIn(400, function () {
						dialog.data.slideDown(200);
					});
				});
			},
			//onShow: function(){$("#FirstLastNames").focus();}, 
			onClose: function (dialog) {
			dialog.data.fadeOut(200, function () {
				dialog.container.hide(200, function () {
					dialog.overlay.fadeOut(200, function () {$.modal.close();});
				});
			});
			}, opacity:50, overlayCss: {backgroundColor:"#ffcc66"}, 	containerCss:{ backgroundColor:"#ffcc66", borderColor:"#000", height:300, padding:15, width:360}, overlayClose:true
			}
		);
		});

		$('#ForgotPassFormDiv > form').submit(function(e){
		e.preventDefault();
		var str = $(this).serialize();
		
		
			$.ajax({
							type: "POST",
							cache: false,
							url: uri+"Admin/PasswordReset", //this.attr('action'), 
							data: str,
							beforeSend: function(){$("#FP_ajax_loading").show();}, //show loading just when link is clicked
							complete: function(){ $("#FP_ajax_loading").hide();}, //stop showing loading when the process is complete
							success: function(msg){ //so, if data is retrieved, store it in html
							//$("#ControlPanelMainDiv").slideDown("slow"); //animation
								if(msg.indexOf('Error')<0){ $("#PasswordReset_response").html(msg); $("#CancelResetBtn").attr('value', 'Thank you'); $("#FP_sbm_btn").attr('disabled', true);}
								else{ $("#PasswordReset_response").html(msg); }
							},
							error: function(html){
								$("#PasswordReset_response").show("slow");
								$("#PasswordReset_response").html("Apologies, ... , error encountered.!");
							}
				 }); //close $.ajax(
				 

		});

});



function go_to_private_page()
{
window.location = uri+'Admin/'; // Members Area
}

