//(function(){
	var submit_form, validForm, isExists, ErrBox, __doPostBack;
	var form = 'form1';
	
	window.addEvent('domready', function(){
	
		//if ( $('forget') ) {+
		$$('.forget').each(function(el){
			var forget = new Forget(el, {
				closeBx: true,
				size: {width:256, height:146}, 
				titleTxt: 'To get your password, please enter your sign in email to the box below.',
				url: 'forgetForm.php'
			});
		});
		
		ErrBox = new ErrorBox({ closeBx:true });
		if ( $('singinBtn') ) {
			$('singinBtn').addEvent('click', submit_form);
		}
		
		if ( $('singinBtn2') ) {
			$('singinBtn2').addEvent('click', submit_form2);
		}
	});
	
	function submit_form(){
		if ( validForm() ) {
			isExists();
		}
	}
	
	function submit_form2(){
		if ( validForm2() ) {
			isExists2();
		}
	}
			
	function validForm(){
		var error = "";
		var f = document.form1;
		if(f.username.value == "")
			error += '<span class="error">Please enter your e-mail</span>';
		else{
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
			if (!filter.test(f.username.value)) 
				error += '<span class="error">e-mail format incorrect (Ex: example@example.com)</span>';
		}
		
		if(f.password.value == "")
			error += '<span class="error">Please enter your password</span>';
			
		if(error!=""){
			ErrBox.start( error.replace(/\n/g, '<br />') );
			return false;
		}
		
		return true;
	}
	
	function validForm2(){
		var error = "";
		var f = document.formSignIn;
		if(f.username.value == "")
			error += '<span class="error">Please enter your e-mail</span>';
		else{
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
			if (!filter.test(f.username.value)) 
				error += '<span class="error">e-mail format incorrect (Ex: example@example.com)</span>';
		}
		
		if(f.password.value == "")
			error += '<span class="error">Please enter your password</span>';
			
		if(error!=""){
			ErrBox.start( error.replace(/\n/g, '<br />') );
			return false;
		}
		return true;
	}
	
	function isExists(){
		new Request({
			url: '_ajax/existsMember.php',
			onSuccess: function(html) {
				if(html <= 0)
					__doPostBack('singinBtn$Click', '', form);
				else{
					ErrBox.start( html ); 
					return false; 
				}
			}, 
			
			onFailer: function(){
				ErrBox.start( 'Error Code. Please contact to web developer.' );	
			}
		}).send( 'sign=1&email=' + document.form1.username.value + '&pass=' + document.form1.password.value );	
	}
	
	function isExists2(){
		new Request({
			url: '_ajax/existsMember.php',
			onSuccess: function(html) {
				if(html <= 0)
					__doPostBack('singinBtn$Click', '', 'formSignIn');
				else{
					ErrBox.start( html ); 
					return false; 
				}
			}, 
			
			onFailer: function(){
				ErrBox.start( 'Error Code. Please contact to web developer.' );	
			}
		}).send( 'sign=1&email=' + document.formSignIn.username.value + '&pass=' + document.formSignIn.password.value );	
	}
	
//})();