var company=Jade.$GET('c');
var user=Jade.$GET('u');
var pass=Jade.$GET('p');
var section=(typeof(Jade.$GET('s'))=="undefined")?"resume":Jade.$GET('s');

if(typeof(Jade.$GET('l'))!="undefined"){
	Jade.Lang.SetLanguage(Jade.$GET('l'));
}

var lblError=Jade.Objects.Text();
lblError.Location(25,25,350,20);
lblError.Add();

if(typeof(company)=="undefined" || typeof(user)=="undefined" || typeof(pass)=="undefined" ){
	lblError.SetText('Some required parameters are missing');
}
else{
	$.AjaxDB("SELECT * FROM users WHERE namehash='"+user+"' AND pass='"+pass+"' AND ((root=0 AND companyId='"+company+"') OR root=1)", Ajax.Dontwait).oncomplete=function(){
		if(this.json.row.length>0){
			$.sajax("lib/php/login.php", {company: company, user: Jade.Encrypt.Decrypt(this.json.row[0].name), pass: pass, hash: true}).oncomplete=function(){
				if(!this.json.error && this.json.logged){
					Jade.Redirect('?'+section);
				}
				else{
					lblError.SetText('Username or password is incorrect');
				}
			}
		}
		else{ lblError.SetText('Username or password is incorrect'); }
	}
}