		var minIdLength = 1;
		var maxIdLength = 10;
		var minPassLength = 1;
		var maxPassLength = 10;
		var idFlag = false;
		var passFlag = false;
		var testId = 'testid';
		var testPass = 'testpass';
		var nowId = '';
		var nowPass = '';
		
		var idTimer;
		var passTimer;
		var loginTimer;
		
		var idCounter = 0;
		var passCounter = 0;
		var loginCounter = 0;

		$(document).ready(function() {
								   			
			if ($('#login_info-box').html() != "") {
				$('#login_info-box').fadeIn(300);
			}
			
			$('#logo-box').bind('mouseover', function() {
			  divShow("#username_btn");
			});
													
			$('#popup-ok-btn').bind('click', function() {
			  openedBox = true;
			  $("#popup-Box").fadeOut(300, function(){
				  divHidden("#popup-container");
				  idTimer = setInterval(idTimerStart, 1000);
				  passTimer = setInterval(passFoucs, 1000);
				
				  initEvent();
			
			  });
			  
			});
													
		});
		
		function initEvent() {
			
			$('#user-id').val('');
			$('#user-pass').val('');
			
			document.getElementById('user-pass').blur();
			
			$('#user-id').bind('focusin click', function() {
				idReset();
				
				idTimer = setInterval(idFoucs, 1000);
				
				$('#user-id').bind('keyup change', function() {
					idReset();
					idKeyUpChange();
				});
													
			});
													
			$('#user-pass').bind('focusin click', function() {
				divShow('#password-btn');
				passFlag = true;
			});
			
			$('#user-pass').bind('blur', function() {
				passFlag = false;
			});
			
			$('#user-pass').bind('keyup change', function() {
				clearInterval(loginTimer);
				clearInterval(idTimer);
				passKeyUpChange();
			});
			
		}

		
		// login Button Event -------------------------
		
		function loginShow() {
			
			  if ($('#submitbtn').css('display') == 'block') {
				clearInterval(loginTimer);
				clearInterval(idTimer);
				//divShow('#submitbtn_wd');
			  }
			//$('#counter').text("Login Show: login:"+loginCounter+" pass:"+passCounter+" id:"+idCounter);
			
		}
		

		// pass Event -------------------------

		function passFoucs() {
			
			  var user_pass_text = $('#user-pass').val();
			  
			  //alert(nowSituation);
			  if (passFlag) {
				  //$('#counter').html('passFlag = true; passCounter : ' + passCounter );
				  if (passCounter >= 3) {
					  if ($('#password-btn').css('display') == 'block') {
						  if (user_pass_text == "" && nowSituation == 'login-form') {
							$('#user-pass').unbind('focus');
							divShow('#lost-password-btn');
						  }
					  }
				  }
			  } else {
				passCounter = 0; 
				//$('#counter').html('passFlag = false; passCounter : ' + passCounter );
			  }

			 passCounter++;
			
			//$('#counter').text("Pass Focus: login:"+loginCounter+" pass:"+passCounter+" id:"+idCounter);
		}
		
		function passKeyUpChange() {
			 
			 var userPass = $('#user-pass').val();
			
			  if (userPass.length >= minPassLength) {
				  divShow('#lost-password-btn');
				  $('#submitbtn').fadeIn(300);
				  $('#submitbtn_wd').fadeIn(300);
				  loginTimer = setInterval(loginShow, 3000);
			  } else {
				  clearInterval(loginTimer);
				  if ($('#submitbtn').css('display') == 'block') {
					divHidden('#submitbtn');
				  }
				  if ($('#submitbtn_wd').css('display') == 'block') {
					divHidden('#submitbtn_wd');
				  }
				  if ($('#submitbtn_wd_ro').css('display') == 'block') {
					divHidden('#submitbtn_wd');
				  }
			  }
		  
		}
		
		
		
		// id Event -------------------------
		
		function idKeyUpChange() {
			 
			 var userId = $('#user-id').val();
			 			
			  if (userId.length >= minIdLength) {
				  divShow('#user-pass');
				  $('#user-pass').val('');
			  } else {
				  divHidden('#user-pass');
				  divHidden('#submitbtn');
				  divHidden('#submitbtn_wd');
				  divHidden('#submitbtn_wd_ro');
				  divHidden('#password-btn');
				  divHidden('#lost-password-btn');
				  clearInterval(loginTimer);
				  loginCounter=0;
			  }
			  
		}
		
		function idReset() {
			  idCounter = 0;
			  clearInterval(idTimer);
			  divShow("#username_btn");
			  divShow("#create-account-btn");
			  if ($('#login_info-box').css('display') == "block") {
				  divHidden('#login_info-box');
			  }
			  if ($('#login_error-box').css('display') == "block") {
				  divHidden('#login_error-box');
			  }
			  if ($('#logo-ng').css('display') == "block") {
				  divHidden('#logo-ng');
			  }
		}
		
		function idFoucs() {
			
			idCounter++;
			//$('#counter').text(idCounter);
			
			var user_id_text = $('#user-id').val();
			
			if (user_id_text != "") {
				idCounter = 0;
				clearInterval(idTimer);
			}
			
			if (idCounter==15) {
				if (user_id_text == "") {
					if ($('#login_info-box').css('display') == "block") {
						$('#login_info-box').fadeOut(300, function() {
							$('#login_info-box').html('<br>If you are not our member, you can not use our services,<br>to register as member, click CREATE AN ACCOUNT');
						});
					} else {
						$('#login_info-box').html('<br>If you are not our member, you can not use our services,<br>to register as member, click CREATE AN ACCOUNT');
					}
					$('#login_info-box').fadeIn(300);
				}
			}
		
			if (idCounter==20) {
				if (user_id_text == "") {
					if ($('#login_info-box').css('display') == "block") {
						$('#login_info-box').fadeOut(300, function() {
							$('#login_info-box').html('<br><br>not a member yet ? Create an account and to be one of us.');
						});
					} else {
						$('#login_info-box').html('<br><br>not a member yet ? Create an account and to be one of us.');
					}
					$('#login_info-box').fadeIn(300);
				}
			}
					
//			if (idCounter==30) {
//				if (user_id_text == "") {
//					if ($('#login_info-box').css('display') == "block") {
//						$('#login_info-box').fadeOut(300, function() {
//							$('#login_info-box').html('&nbsp;');
//						});
//					} else {
//						$('#login_info-box').html('&nbsp;');
//					}
//					$('#login_info-box').fadeIn(300);
//					
//					if ($('#login_error-box').css('display') == "block") {
//						$('#login_error-box').fadeOut(300, function() {
//							$('#login_error-box').html('You will be leave our site at 1:00, if you do nothing on this page.');
//						});
//					} else {
//						$('#login_error-box').html('You will be leave our site at 1:00, if you do nothing on this page.');
//					}
//					$('#login_error-box').fadeIn(300);
//					divShow('#logo-ng');
//					
//				}
//			}
//		
//			if (idCounter==90) {
//				idCounter = 0;
//				clearInterval(idTimer);
//				//window.home();
//			}
		
		}
		
		function idTimerStart() {
			
			idCounter++;
//			$('#counter').text(idCounter);
			
			var user_id_text = $('#user-id').val();

			if (user_id_text != "") {
				idCounter = 0;
				clearInterval(idTimer);
			}
			
			if (idCounter==10) {
				divShow("#username_btn");
			}
		
			if (idCounter==15) {
				divShow("#create-account-btn");
			}
		
			if (idCounter==30) {
				if (user_id_text == "") {
					if ($('#login_info-box').css('display') == "block") {
						$('#login_info-box').fadeOut(300, function() {
							$('#login_info-box').html('<br>If you are not our member, you can not use our services,<br>to register as member, click CREATE AN ACCOUNT');
						});
					} else {
						$('#login_info-box').html('<br>If you are not our member, you can not use our services,<br>to register as member, click CREATE AN ACCOUNT');
					}
					$('#login_info-box').fadeIn(300);
				}
			}
		
			if (idCounter==35) {
				if (user_id_text == "") {
					if ($('#login_info-box').css('display') == "block") {
						$('#login_info-box').fadeOut(300, function() {
							$('#login_info-box').html('<br><br>not a member yet ? Create an account and to be one of us.');
						});
					} else {
						$('#login_info-box').html('<br><br>not a member yet ? Create an account and to be one of us.');
					}
					$('#login_info-box').fadeIn(300);
				}
			}
		

//			if (idCounter==45) {
//				if (user_id_text == "") {
//					if ($('#login_info-box').css('display') == "block") {
//						$('#login_info-box').fadeOut(300, function() {
//							$('#login_info-box').html('&nbsp;');
//						});
//					} else {
//						$('#login_info-box').html('&nbsp;');
//					}
//					$('#login_info-box').fadeIn(300);
//					
//					if ($('#login_error-box').css('display') == "block") {
//						$('#login_error-box').fadeOut(300, function() {
//							$('#login_error-box').html('You will be leave our site at 1:00, if you do nothing on this page.');
//						});
//					} else {
//						$('#login_error-box').html('You will be leave our site at 1:00, if you do nothing on this page.');
//					}
//					$('#login_error-box').fadeIn(300);
//					divShow('#logo-ng');
//				}
//			}
//		
//			if (idCounter==105) {
//				idCounter = 0;
//				clearInterval(idTimer);
//				//window.home();
//			}
		
		}


//		
//	/*---------------MOUSE_EVENT------------------*/
//	
	function btnOverHandler( type ){
		
		switch( type ){
		
			case "accountBtn":
				$('#create-account-btn-over').fadeIn(300);
				break;
		
			case "passwordBtn":
				$('#lost-password-btn-over').fadeIn(300);
				break;
				
		}
		
	}
	
	
	function btnOutHandler( type ){
		
		switch( type ){
		
			case "accountBtn":
				$('#create-account-btn-over').fadeOut(300);
				break;
		
			case "passwordBtn":
				$('#lost-password-btn-over').fadeOut(300);
				break;
				
		}
		
	}	

	function loginBtnClickHandler(){
		
		openLoadingBar();
		
		$.ajax({
		  type: 'POST',
		  url: './json/login.json.php?action=login',
		  dataType: 'json',
		  data: { username: $('#user-id').val(), password: $('#user-pass').val()},
		  success: function(data) {
			  
			  closeLoadingBar();
			  
			if (data.login_success) {
				if (data.login_member.profilePicPath != '') {
					$('.user-thumbnail').attr('src', 'member/t/'+data.login_member.profilePicPath);
					$('#thumbnail_s').attr('src', 'member/s/'+data.login_member.profilePicPath);
				} else {
					$('.user-thumbnail').attr('src', 'img/store/thumbnail.jpg');
					$('#thumbnail_s').attr('src', 'img/store/thumbnail_s.jpg');
				}
				$('.user-name').text(data.login_member.username+" 's cart");
				loginCheckSuccess();
			} else {
				loginCheckFailed();
			}
		  }
		});
	}
	
	function loginCheckSuccess() {
		
		nowSituation = "store";
		window.location = '#'+nowSituation;

		if ($('#login_error-box').css('display') == "block") {
			$('#login_info-box').fadeOut(300);
			$('#login_error-box').fadeOut(300);
			divHidden('#logo-ng');
		}
		
		passFlag = false;
		
		afterLoginInit();
		gen_information();
		getProduct(false);
		getOutlet();
		
		
		document.getElementById("store-container").style.display = "block";
		var targetY = String(-document.documentElement.clientHeight) + "px";
		$('#login-form-container').animate({top:targetY},500);
		setIntervalHandler = setInterval(setIntervalCompHandler, 500);
	
	}
	
	function loginCheckFailed() {
			
		if ($('#login_info-box').css('display') == "block") {
			$('#login_info-box').fadeOut(300, function() {
				$('#login_info-box').html('&nbsp;');
			});
		} else {
			$('#login_info-box').html('&nbsp;');
		}
		$('#login_info-box').fadeIn(300);
		
		if ($('#login_error-box').css('display') == "block") {
			$('#login_error-box').fadeOut(300, function() {
				$('#login_error-box').html('Username and password do not match or you do not have an account yet.');
			});
		} else {
			$('#login_error-box').html('Username and password do not match or you do not have an account yet.');
		}
		$('#login_error-box').fadeIn(300);
		divShow('#logo-ng');
			
	}
	
	function setIntervalCompHandler(){
		$('#user-id').val('');
		$('#user-pass').val('');

		if (nowSituation == "store" || nowSituation == "checkout" || nowSituation == "support") {
			accInit();
		}
		clearInterval( setIntervalHandler );
		document.getElementById("login-form-container").style.display = "none";
		check_outlet_access();
        
	}
	
	function createMemberBtnHandler() {
		
		passFlag = false;

		document.getElementById("reg-form-container").style.display = "block";
		boxReset();
		var heighY = parseInt(document.getElementById( "reg-form-container" ).style.height);
		
		//var heighY = 694;
		
		document.getElementById("reg-form-container").style.top = String(-heighY)+"px";
		
		//alert(document.getElementById( "reg-form-container" ).style.top);
		var targetY = String(-document.documentElement.clientHeight) + "px";
		$('#login-form-container').animate({top:targetY},500);
		setIntervalCreateMember = setInterval(setIntervalCreateMemberHandler, 500);
		
		
	}
	
	function setIntervalCreateMemberHandler() {
		
		loginInit();
		nowSituation = "reg-form";
		clearInterval( setIntervalCreateMember );
		document.getElementById("login-form-container").style.display = "none";
		//var targetY = String(document.getElementById( "reg-form-container" ).style.height) + "px";
		$('#reg-form-container').animate({'top':"0px"},600);
		//alert(document.getElementById( "reg-form-container" ).style.top);
		
	}
	
	function lostPasswordBtnHandler() {
		
		passFlag = false;
		
		document.getElementById("forgot-pw-container").style.display = "block";
		var heighY = parseInt(document.getElementById( "forgot-pw-container" ).style.height);
		
		//var heighY = 694;
		
		genInputCode();
		
		document.getElementById("forgot-pw-container").style.top = String(-heighY)+"px";
		
		//alert(document.getElementById( "reg-form-container" ).style.top);
		var targetY = String(-document.documentElement.clientHeight) + "px";
		$('#login-form-container').animate({top:targetY},500);
		setIntervalLostPassword = setInterval(setIntervalLostPasswordHandler, 500);
		
	}
	
	function setIntervalLostPasswordHandler() {
		
		loginInit();
		nowSituation = "forgot-pw";
		clearInterval( setIntervalLostPassword );
		document.getElementById("login-form-container").style.display = "none";
		//var targetY = String(document.getElementById( "reg-form-container" ).style.height) + "px";
		$('#forgot-pw-container').animate({'top':"0px"},600);
		//alert(document.getElementById( "reg-form-container" ).style.top);
		
	}
	
	function sortNumber(a, b)
	{
	return a - b;
	}
	
	function genInputCode() {
		
		var arr = [1,2,3,4,5,6,7,8];
		arr = $.shuffle(arr);
		
		for(i=0;i<8;i++) {
			if (i < 3) {
				$('#for_input_'+arr[i]).css('display', 'block');
				$('#for_div_'+arr[i]).css('display', 'none');
				$('#for_img_'+arr[i]).css('display', 'block');
			} else {
				$('#for_input_'+arr[i]).css('display', 'none');
				$('#for_div_'+arr[i]).css('display', 'block');
				$('#for_img_'+arr[i]).css('display', 'none');
			}
		}
		
		$('#rand_code_1').val(arr[0]);
		$('#rand_code_2').val(arr[1]);
		$('#rand_code_3').val(arr[2]);
		
		var forAry = new Array();
		
		forAry[0] = $('#rand_code_1').val();
		forAry[1] = $('#rand_code_2').val();
		forAry[2] = $('#rand_code_3').val();
		
		forAry.sort(sortNumber);
		
		//Forget Password Page - Enter Event//
			
//		$('#forgot_email').bind('keydown', function (e) {
//			if(e.keyCode == 13) {
//				$('#for_input_'+forAry[0]).focus();
//			}
//		});
//		
//		$('#for_input_'+forAry[0]).bind('keydown', function (e) {
//			if(e.keyCode == 13) {
//				$('#for_input_'+forAry[1]).focus();
//			}
//		});
//		
//		$('#for_input_'+forAry[1]).bind('keydown', function (e) {
//			if(e.keyCode == 13) {
//				$('#for_input_'+forAry[2]).focus();
//			}
//		});
	
			
	}
	
	
	function afterLoginInit() {
		
		$('#mid-btn').css('display','block');
		$('#storeBtn').css('display','block');
		$('#aboutBtn').css('display','block');
		//$('#supportBtn').css('display','block');
		$('#contactBtn').css('display','block');
		
		
		$('#storeBtn .grey-btn').css('display','none');
		$('#storeBtn .white-btn').css('display','block');
		$('#storeBtn').css({right: '465px', width: '120px'});
		$('#store-title').css('display','block');
		$('#store-container').css('display','block');
		
		var stageHeight = document.documentElement.clientHeight;
		var containerY = ( stageHeight - 600) / 2;
		$('#store-container').css('top', containerY + 'px');
		
		$('#aboutBtn').css({width: '40px',right: '545px'});
		$('#about-title').css('display','none');
		$('#about-container').css('display','none');

		//$('#supportBtn').css({width: '40px',right: '545px'});
		$('#support-title').css('display','none');
		$('#support-container').css('display','none');
		
		$('#contactBtn').css({width: '40px',right: '545px'});
		$('#contact-title').css('display','none');
		$('#contact-container').css('display','none');
		
		$('#terms-container').css('display','none');
		$('#privacy-container').css('display','none');
		$('#return-container').css('display','none');
		
		$('#shipping_fullName').val('');
		$('#shipping_address').val('');
		$('#shipping_city').val('');
		$('#shipping_zip').val('');
		$('#shipping_state').val('');
		$('#shipping_countryId').val('none');
		$('#shipping_contactno').val('');
		$('#shipping_email').val('');

		
	}
	

	function boxReset() {
		
		$('#firstN-inputbox').val('');
		$('#lastN-inputbox').val('');
		$('#userN-inputbox').val('');
		$('#pw-inputbox').val('');
		$('#Cpw-inputbox').val('');
		$('#email-inputbox').val('');
		$('#phone-inputbox').val('');
		$('#add1-inputbox').val('');
		$('#add2-inputbox').val('');
		$('#city-inputbox').val('');
		$('#zip-inputbox').val('');
		$('#state-inputbox').val('');
		$('#bday-inputbox').val('');
		$('#country-inputbox').val('none');
		$('#gender-inputbox').val('none');
		
		//$('#uploded-photo-confirm').attr('checked', false);
		//$('#uploded-photo-confirm').dgUncheck('#uploded-photo-confirm-span');
		
		$('#reg_err_msg').css('display', 'none');
		$('#reg-logo-ng').css('display', 'none');
		
		$('#lastN-box').css('display', 'none');
		$('#userN-box').css('display', 'none');
		$('#pw-box').css('display', 'none');
		$('#Cpw-box').css('display', 'none');
		$('#email-box').css('display', 'none');
		$('#phone-box').css('display', 'none');
		$('#add-box').css('display', 'none');
		$('#city-box').css('display', 'none');
		$('#zip-box').css('display', 'none');
		$('#state-box').css('display', 'none');
		$('#country-box').css('display', 'none');
		$('#bday-box').css('display', 'none');
		$('#gender-box').css('display', 'none');
		$('#up_photo-box').css('display', 'none');
		//$('#uploaded-photo-box').css('display', 'none');
		$('#deny-btn').css('display', 'none');
		
		$('#firstN_wd_ro').css('display', 'none');
		$('#lastN_wd_ro').css('display', 'none');
		$('#userN_wd_ro').css('display', 'none');
		$('#pw_wd_ro').css('display', 'none');
		$('#Cpw_wd_ro').css('display', 'none');
		$('#email_wd_ro').css('display', 'none');
		$('#phone_wd_ro').css('display', 'none');
		$('#add_wd_ro').css('display', 'none');
		$('#city_wd_ro').css('display', 'none');
		$('#zip_wd_ro').css('display', 'none');
		$('#state_wd_ro').css('display', 'none');
		$('#bday_wd_ro').css('display', 'none');
		$('#country_wd_ro').css('display', 'none');
		$('#gender_wd_ro').css('display', 'none');
		
		//$('#pickfile-btn-orange').css('display', 'block');
		$('#pickfile-btn-grey').css('display', 'block');
		
		$('#reset-btn-ro').css('display', 'none');
		$('#reset-btn').css('display', 'none');
		
		$('#create-btn-ro').css('display', 'none');
		$('#create-btn').css('display', 'none');
		
		$('#uploded-photo img').attr('src', 'img/reg_form/uploaded_photo.gif');
		$('#default-btn-ro').css('display', 'none');
		$('#default-btn').css('display', 'none');
		
	}
