

// TODO: Het is nu nog specefiek voor de comments. Moet wat algemender worden.
// TODO: Hoe kunnen we erros bij b.v. inloggen weergeven?


jQuery(document).ready(function() {

	if ( jQuery("#sbs_comment_status_open").length != 0 ) {
		
		var redirect_to = jQuery("#sbs_comment_status_open #redirect_to").val();
		var clear = jQuery("#sbs_comment_status_open #clear").val();
		var site = jQuery("#sbs_comment_status_open #site").val();
		var l_out = jQuery("#sbs_comment_status_open #l-out").val();
		var comment_post_ID = jQuery("#sbs_comment_status_open #comment_post_ID").val();
		var comment_parent = jQuery("#sbs_comment_status_open #comment_parent").val();
		var _wp_unfiltered_html_comment = jQuery("#sbs_comment_status_open #_wp_unfiltered_html_comment").val();
		var cancel_comment_reply_link = jQuery("#cancel_wrapper").html();
		var user_login = "";

		
		
		jQuery.ajax({
            type: "GET",
            url: "/wp-content/sbs-user-xml/sbs-user-xml.php",
            dataType: "xml",
            success: function(xml) {

				jQuery(xml).find('user').each(function(){
                    user_login = jQuery(this).find('user_login').text()
                    if ( user_login.length != 0 ){
	                    jQuery('#sbs_comment_status_open').append(user_login);
		                    
	                    // load het comment form
	            		try {
		                    jQuery("#sbs_comment_status_open").load("/wp-content/presentation/sbs.nl/elements/comments_form_ajax.php" ,"", load_form_value);
	            		} catch (e){
	            		}
	                    
		                    
	                 } else {

	                   	// load het login form
	            		try {
		                    jQuery("#sbs_comment_status_open").load("/wp-content/presentation/sbs.nl/elements/sbs_loginbox_for_ajax.php" ,"", load_login_value);
	            		} catch (e){
	            		}

	                 }

	                    
				}); //close each(
            }
        }); //close $.ajax(

	} // end if

	
	function load_login_value(responseText, textStatus, XMLHttpRequest){
//	jQuery("#sbs_loginbox_small_ajax").attr("action","/login/?redirect_to=" + redirect_to);
		jQuery("#redirect_to_form").val(redirect_to);
	}
	
	function load_form_value(responseText, textStatus, XMLHttpRequest){
//		jQuery("#sbs_loginbox_small_ajax").attr("action",redirect_to + "?redirect_to=" + redirect_to);
		jQuery("#clear_form").val(clear);
		jQuery("#redirect_to_form").val(redirect_to);
		jQuery("#logout_link").attr("href",l_out);
		jQuery("#user_login").text(user_login);
		jQuery("#comment_post_ID").val(comment_post_ID);
		jQuery("#comment_parent").val(comment_parent);
		jQuery("#_wp_unfiltered_html_comment").val(_wp_unfiltered_html_comment);
		
		if (comment_parent != 0){
			jQuery("#comment_form_header").text('Reactie op eerder bericht');
			jQuery("#comment_form_reply").html(cancel_comment_reply_link);
		}
		
	}
	
	
	
});		

