//Ajax Scripts for IFN
//Created by Chris Richards

//check_email_ajax
//
//This gets the users reset question from the database
function check_email_ajax( $id ){
	//Call the old check
	//if( check_email( $id ) ) {
		//Now lets send this back to the server
    $.post("recover.aspx?ajax=true", { "email": $("#" + $id).val() }, function(xml) {
        //Make it an object
        $elm = $(xml);

        //Was the email valid?
        if ($elm.attr("valid") == "true") {
            //It's True! Unlock the Submit Button!
            $("#btnreset").attr("disabled", "");
            //Unlock the response input
            $("#answer").attr("disabled", "");
            $("#answer").focus();
        }

        //Let fill in the question


        $("#quest").html($elm.html());
    });
	//}
	
}

//Load_NewUser
//
//This Simply loads the NewUser Page
function Load_NewUser() {
	//Use Ajax to get the new user page
	$("#form").load( "newuser.aspx" );
	
}
	 
//Load_Confirm
//
//This Simply loads the Confirm Page
function Load_Confirm() {
	$("#form").load( "confirm.aspx" );
}


//These Three Functions create the Company Dropdown to help users
//
function CheckCompany(){
   
	//Get the Company name
	var $company = $( "#company" ).val();
	
	//AJAX is our friend!!
	$.post( "newuser.aspx?ajax=true", { "company": $company }, CheckCompany_PostBack );
	
}

function CheckCompany_PostBack( msg ){
	//Did we get a message back?
	if( msg != "" ) {
		//Add our list, Show the list
		$("#clist")
			.html("")                   /*Clear the list*/
			.css( "height", "auto" )     /*Clear the old Height */
			.append( msg )              /*Put in our AJAX Result*/
			.append( "<a class=\"closebtn\" onclick=\"Close_Optlist()\">Close</a>" )   /*Add a Close Button */
			.slideDown( "slow" );       /*Show it as a slide down*/
		;
		
		//Now lets add events to all those links
		$( "#clist a" ).not(".closebtn")
			.click( function() { 
				//Lets change the value of our company box
				$("#company").val( $(this).html() ).addClass( "ok" ).removeClass("error");
				//And close the popup
				Close_Optlist();
			} 
		);
		
	} else {
		$("#company").addClass( "ok" );
	}
}

function Close_Optlist() {
	//hide it
	$("#clist").slideUp( "slow" );
	
}




