/* ************************************************************************ *\

	* signup.js
	* By Jianhua Zhu, lostartchina{at}yahoo.cn
	* http://www.lostartchina.com
	 
	#    #   ## ###  #  ##  ###      ## # # ### ###  #  
	#   # # #    #  # # # #  #      #   # #  #  # # # # 
	#   # #  #   #  ### ##   #      #   ###  #  # # ### 
	#   # #   #  #  # # # #  #      #   # #  #  # # # # 
	###  #  ##   #  # # # #  #       ## # # ### # # # # 
				
  	* Please do not remove this credits		
				
/* ************************************************************************ */

var ETW = {
	start: function() {
		var pre_image = '<img src="images/loader.gif" alt="" width="16" height="16" />';
		
		//Select Elements
		ETW.title = $('title');
		ETW.contacter = $('contacter');
		ETW.telephone = $('telephone');
		ETW.fax = $('fax');
		ETW.email = $('email');
		ETW.address = $('address');
		ETW.content = $('content');
		ETW.url = $('url');
		ETW.usernameid = $('usernameid');
		ETW.yanzhengma = $('yanzhengma');
		ETW.Submit = $('button');
		ETW.Status = $('setform');
		ETW.Form = $('form1');
		
		//ETW.Submit.addEvent('click', ETW.Register);
		
		ETW.Form.addEvent('submit', function(e) {
			new Event(e).stop();
			var pars = "title=" + encodeURIComponent(ETW.title.value) + "&contacter=" + encodeURIComponent(ETW.contacter.value) + "&telephone=" + encodeURIComponent(ETW.telephone.value) + "&fax=" + encodeURIComponent(ETW.fax.value) + "&email=" + encodeURIComponent(ETW.email.value) + "&address=" + encodeURIComponent(ETW.address.value) + "&content=" + encodeURIComponent(ETW.content.value) + "&url=" + encodeURIComponent(ETW.url.value);
			ETW.Status.setStyles({'color':'#e11801', 'font-weight':'bold'}).setHTML(pre_image + " Just a moment, we are processing your information...");
			ETW.Submit.disabled = true;
			new XHR({
				method: 'get',
				onSuccess: function(){
					ETW.Status.empty();
					//window.location = '/internship/?l=0&user='+ ETW.mail.value;
					//window.location = 'http://192.168.1.219:8065';
				}
				}).send('online.aspx', pars);
		});		
		
		/*ETW.Ver.addEvent('focus', function() {
			if($('vcode_txt') != null) {
				$('vcode_txt').effect('opacity',{duration: 800, transition: Fx.Transitions.linear, wait:false}).start(0.9,0).chain(function(){
					$('vcode_txt').remove();
				})
			}
		});
		
	},
	
	chk_code:function(ele) {
		if($(ele).value == '' || $(ele).value != getCookie('securitycode')) {
			var div = new Element('span');
			div.injectAfter(ele);
			div.setProperties({'id':'vcode_txt','class':'etw_err etw_pwnote'}).setHTML('Security code doesn\'t match!');
			div.effect('opacity',{duration: 400, transition: Fx.Transitions.linear, wait:false}).start(0,1);
			return false;
		} else {
			return true;
		}
	},
	
	changeImage:function() {
		var img = $("vcode");
		img.src = img.src + "?";
	}
	
	Register:function() {
		var pars = "f=" + encodeURIComponent(ETW.f.value) + "&ln=" + encodeURIComponent(ETW.ln.value) + "&gender=" + encodeURIComponent(ETW.gender.value) + "&age=" + encodeURIComponent(ETW.age.value) + "&major=" + encodeURIComponent(ETW.major.value) + "&pw=" + encodeURIComponent(ETW.pw.value) + "&mail=" + encodeURIComponent(ETW.mail.value) + "&tel=" + encodeURIComponent(ETW.tel.value) + "&city=" + encodeURIComponent(ETW.city.value) + "&pays=" + encodeURIComponent(ETW.pays.value) + "&ads=" + encodeURIComponent(ETW.ads.value);
		var url = "/signup/signup.aspx";
		new Ajax(url, {
				method: 'get',
				data: pars,
				update: 'e_status',
				onload: $('e_status').setStyles({'color':'#e11801', 'font-weight':'bold'}).setHTML("Just a sec, we are sending your data..."),
				onComplete: window.location = "/internship/?test",
				onFailure: $('e_status').setStyles({'color':'#e11801', 'font-weight':'bold'}).setHTML("There is something error during the process, please try again later!")
			}).request();
	}*/	
	
}
};

window.addEvent('domready', function(){
	var exValidatorA = new fValidator("form1");
});

window.addEvent('load', ETW.start);
