function CreateAccount(func) {
	if (check_required_fields('NEW_ACCOUNT')) {
		var messageBox=el('messageBox');
		var mdl=document.new_account.mdl.value;
		if(mdl.indexOf('login.mdl')!=-1) mdl="jobcenter/main.mdl";
		document.new_account.mdl.value="quick_login/create.aj";
		document.new_account.next_mdl.value=mdl;
		func=func.replace('go_on','login_form');
		ajaxFormFunction("new_account",function(sc,st,rt,rxml) {
			if(getTagValue(rxml,'status')=="okay") {
				if(el('quicklogin_email')) el('quicklogin_email').value=getTagValue(rxml,'email');
				if(el('quicklogin_passwd')) el('quicklogin_passwd').value=getTagValue(rxml,'password');
				if(func==null||func=="") {
					document.login_form.mdl.value=document.login_form.next_mdl.value;
					document.login_form.user_Email.value=getTagValue(rxml,'email');
					document.login_form.user_Passwd.value=getTagValue(rxml,'password');
					document.login_form.submit();
				} else {
					if(func.indexOf('login_form.submit')!=-1) {
						document.login_form.mdl.value=document.login_form.next_mdl.value;
						document.login_form.user_Email.value=getTagValue(rxml,'email');
						document.login_form.user_Passwd.value=getTagValue(rxml,'password');
					}
					eval(func);
				}
			} else if(getTagValue(rxml,'status')=="waiting") {
				messageBox.className="message-create";
				messageBox.innerHTML="Thank you! Your account has been created and has been submitted for approval.";
				show('messageBox');
			} else {
				messageBox.className="message-warning";
				messageBox.innerHTML="We're sorry... an account already exists for this email address. Enter another email address, or click '<a href='#' id='sforgotPWLink'>Forgot Your Password?</a>' to have your password emailed to you.";
				show('messageBox');
				el('forgotPWLink').onclick=new Function("hide('LogInForm');show('PasswordForm');document.pw_send.user_Email.value=document.new_account.CONTACT_Email.value;return false");
			}
		},"ajax.iml");
	}
}
function LogIn(func) {
	if (check_required_fields('LOGIN')) {
		var messageBox=el('messageBox');
		var mdl=document.login_form.mdl.value;
		if(mdl.indexOf('login.mdl')!=-1) mdl="jobcenter/main.mdl";
		document.login_form.mdl.value="quick_login/login.aj";
		document.login_form.next_mdl.value = mdl;
		func=func.replace('go_on','login_form');
		ajaxFormFunction("login_form",function(sc,st,rt,rxml) {
			if(getTagValue(rxml,'status')=="okay") {
				if(el('quicklogin_email')) el('quicklogin_email').value=getTagValue(rxml,'email');
				if(el('quicklogin_passwd')) el('quicklogin_passwd').value=getTagValue(rxml,'password');
				if(func==null||func=="") {
					document.login_form.mdl.value=document.login_form.next_mdl.value;
					document.login_form.submit();
				} else {
					if(func.indexOf('login_form.submit')!=-1) document.login_form.mdl.value=document.login_form.next_mdl.value;
					eval(func);
				}
			} else {
				messageBox.className="message-warning";
				messageBox.innerHTML="We're sorry... the email address and/or password you entered is not correct. Please double-check your entries and try again.<br>If you have forgotten your password, click '<a id='forgotPWLink' href='#'>Forgot Your Password?</a>' to have it emailed to you.";
				show('messageBox');
				el('forgotPWLink').onclick=new Function("hide('LogInForm');show('PasswordForm');document.pw_send.user_Email.value=document.login_form.user_Email.value;return false");
			}
		},"ajax.iml");
	}
}
function SendPassword() {
	if (check_required_fields('REMIND')) {
		var messageBox=el('messageBox');
		var email=document.pw_send.user_Email.value;
		document.pw_send.mdl.value="quick_login/sendPassword.aj";
		ajaxFormFunction("pw_send",function(sc,st,rt,rxml) {
			if(getTagValue(rxml,'status')=="okay") {
				messageBox.className="message-create";
				messageBox.innerHTML="Great news! Your password is on the way! It was just sent to "+email+". Please check your email and then login.";
				hide('PasswordForm');show('LogInForm');show('messageBox');
				document.login_form.user_Email.value=document.pw_send.user_Email.value;
			} else {
				messageBox.className="message-warning";
				messageBox.innerHTML="We're sorry... we did not find your email address in our system. Please double-check your address and try again, or create a new account below.";
				show('messageBox');
			}
		},"ajax.iml");
	}
}
function CheckAcctInputs(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if (keycode == 13) return false;
else return true;
}
function CheckLoginInputs(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if (keycode == 13) LogIn();
else return true;
}
function CheckForgotInputs(e) {
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
if (keycode == 13) SendPassword();
else return true;
}

function validateForm(){
  if(!check_required_fields('ORDER_')) return false;  
 
 
  if(!LOGGED_IN){
    //myLoginForm.showForm('new',function(){LOGGED_IN=true;validateForm();});
    hide("FORM_SUBMIT_B");
	show("AJAX_LOGIN");

    return false;
  }
  show("FORM_SUBMIT_B");hide("FORM_SUBMIT_P");
 
  if(check_file_upload_fields('ORDER_')) progress();
  show("FORM_SUBMIT_P");hide("FORM_SUBMIT_B");
  if(FileUploadUtilityList){
    for(var i=0; i<FileUploadUtilityList.length; i++){
      FileUploadUtilityList[i].closeOut();
    }  
    for(var i=0; i<FileUploadUtilityList.length; i++){
      if(FileUploadUtilityList[i].sending||FileUploadUtilityList[i].waitingToSend){
        FileUploadUtilityNextAction=function(){validateForm();};
        return false;
      }
    }
  }
 
  document.FormCheck.update_mdl.value="Form_Builder2/create_job_ticket.mdl";
  if(el("messageBox")) hide("messageBox");       
  document.FormCheck.submit();
  return false;  
}

if(el('new_account')&&el('login_form')&&el('pw_send')) {
	var acctInputs=el('new_account').getElementsByTagName('input');
	var loginInputs=el('login_form').getElementsByTagName('input');
	var forgotInputs=el('pw_send').getElementsByTagName('input');
	for (i=0;i<acctInputs.length;i++) {	acctInputs[i].onkeypress = function() { CheckAcctInputs; } }
	for (i=0;i<loginInputs.length;i++) { loginInputs[i].onkeypress = function() { CheckLoginInputs; } }
	for (i=0;i<forgotInputs.length;i++) { forgotInputs[i].onkeypress = function() { CheckForgotInputs; } }
}

if(el('quicklogin_box')&&typeof(myLoginForm)!="undefined") {
	var newDiv=document.createElement('div');
	newDiv.id="PlaceHolderDiv";
	if(el('FORM_DIV')) el('FORM_DIV').appendChild(newDiv);
	else if(el('orderview')) el('orderview').appendChild(newDiv);
	else if(document.go_on) document.go_on.parentNode.insertBefore(newDiv,document.go_on);
	if(el('PlaceHolderDiv')) {
		window.setTimeout("el('quicklogin_box').innerHTML='';",2000);
		if(myLoginForm.onLogin) var onLog=myLoginForm.onLogin.toString();
		else var onLog=null;
/*		var gInputs=null;
		if(onLog!=null) {
			if(onLog.indexOf('go_on.submit')!=-1) {
				var goInputs=document.go_on.getElementsByTagName('input');
				var goOns=new Array();
				var goCount=0;
				for(i=0;i<goInputs.length;i++) {
					if(goInputs[i].type=="hidden"&&goInputs.id=="") {
						goOns[goCount]=goInputs.name+"|"+goInputs.value;
						goCount++;
					}
				}
				gInputs=goOns.join();
			}
		}*/
		if(onLog==null&&document.FormCheck) onLog="function(){LOGGED_IN=true;validateForm();}";
		if(onLog!=null) {
			onLog=onLog.replace(/\n/g,"");
			onLog=onLog.replace(/\r/g,"");
			if(onLog.split('{ ')[1]) onLog=onLog.split('{ ')[1];
			if(onLog.split('{')[1]) onLog=onLog.split('{')[1];
			onLog=onLog.split(' }')[0];
			onLog=onLog.split('}')[0];
		}
		var params="mdl="+template_name+"/login.aj&this_mdl="+this_mdl+"&next_mdl="+next_mdl+"&iefix="+Math.random();
//		if(gInputs!=""&&gInputs!=null) params+="&gInputs="+gInputs;
		if(onLog!=""&&onLog!=null) params+="&onLog="+onLog;
		PlaceText("ajax.iml?",params,"PlaceHolderDiv","var fields=el('PlaceHolderDiv').getElementsByTagName('input');var drops=el('PlaceHolderDiv').getElementsByTagName('select');for(i=0;i<fields.length;i++) { if(fields[i].getAttribute('scriptdata')&&fields[i].getAttribute('scriptdata')!='') eval(fields[i].getAttribute('scriptdata')); } for(i=0;i<drops.length;i++) { if(drops[i].getAttribute('scriptdata')&&drops[i].getAttribute('scriptdata')!='') eval(drops[i].getAttribute('scriptdata')); }");
	}
	
}
