// JavaScript Document
//process initial Login form

function validateLoginForm(){
	var iLoginForm = dijit.byId("iLogin");
	var firstInvalidWidget=null;
	
	dojo.every(iLoginForm.getDescendants(), function(widget){
        firstInvalidWidget = widget;
        return !widget.isValid || widget.isValid();
    });
    
	if (firstInvalidWidget != null) {
      // set focus to first field with an error
      firstInvalidWidget.focus();
    }else {
        iLoginForm.submit();
    }	
}

function validatePasswordResetForm(){
	var pForm = dijit.byId("pReset");
	var firstInvalidWidget=null;
	
	dojo.every(pForm.getDescendants(), function(widget){
        firstInvalidWidget = widget;
        return !widget.isValid || widget.isValid();
    });
    
	if (firstInvalidWidget != null) {
      // set focus to first field with an error
      firstInvalidWidget.focus();	  
    }else{
		return true;
	}	
}

function acceptRequest(){
	   //console.log('called');
	   var params=dojo.formToQuery("pReset");
                        dojo.xhrGet( {
                            url: "./password_reset/a_reset_form.php?id=1" + params,
                            handleAs: "text",
							preventCache: true,
							timeout: 60000,
                            load: function(response) {	
							   var ar=response.split("|");
                               document.getElementById("captcha_image").innerHTML = ar[0];
							   document.getElementById("message").innerHTML =ar[1];
							   return response;						   
                            },
							error: function(response) {
                                         //console.log("failed xhrGet");	
										 document.getElementById("message").innerHTML ="Error.";									 
                                         return response; //always return the response back
                            }
                         });	
}